-
Notifications
You must be signed in to change notification settings - Fork 497
/
TileBuildCraft.java
115 lines (87 loc) · 2.93 KB
/
TileBuildCraft.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core;
import java.util.HashMap;
import java.util.Map;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.core.network.ISynchronizedTile;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketTileUpdate;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
public abstract class TileBuildCraft extends TileEntity implements ISynchronizedTile {
@SuppressWarnings("rawtypes")
private static Map<Class, TilePacketWrapper> updateWrappers = new HashMap<Class, TilePacketWrapper>();
@SuppressWarnings("rawtypes")
private static Map<Class, TilePacketWrapper> descriptionWrappers = new HashMap<Class, TilePacketWrapper>();
private final TilePacketWrapper descriptionPacket;
private final TilePacketWrapper updatePacket;
private boolean init = false;
public TileBuildCraft() {
if (!updateWrappers.containsKey(this.getClass()))
updateWrappers.put(this.getClass(), new TilePacketWrapper(this.getClass()));
if (!descriptionWrappers.containsKey(this.getClass()))
descriptionWrappers.put(this.getClass(), new TilePacketWrapper(this.getClass()));
updatePacket = updateWrappers.get(this.getClass());
descriptionPacket = descriptionWrappers.get(this.getClass());
}
@Override
public void updateEntity() {
if (!init && !isInvalid()) {
initialize();
init = true;
}
if (this instanceof IPowerReceptor) {
IPowerReceptor receptor = ((IPowerReceptor) this);
receptor.getPowerProvider().update(receptor);
}
}
@Override
public void invalidate()
{
init = false;
super.invalidate();
}
public void initialize() {
Utils.handleBufferedDescription(this);
}
public void destroy() {
}
public void sendNetworkUpdate() {
if(CoreProxy.proxy.isSimulating(worldObj))
CoreProxy.proxy.sendToPlayers(getUpdatePacket(), worldObj, xCoord, yCoord, zCoord, DefaultProps.NETWORK_UPDATE_RANGE);
}
@Override
public Packet getDescriptionPacket() {
return new PacketTileUpdate(this).getPacket();
}
@Override
public PacketPayload getPacketPayload() {
return updatePacket.toPayload(this);
}
@Override
public Packet getUpdatePacket() {
return new PacketTileUpdate(this).getPacket();
}
@Override
public void handleDescriptionPacket(PacketUpdate packet) {
descriptionPacket.fromPayload(this, packet.payload);
}
@Override
public void handleUpdatePacket(PacketUpdate packet) {
updatePacket.fromPayload(this, packet.payload);
}
@Override
public void postPacketHandling(PacketUpdate packet) {
}
}