blob: c6acf1fda840557469506c49479f7e424a0bcd6c (
plain)
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
|
package binnie.core.machines;
import binnie.Binnie;
import binnie.core.machines.base.TileEntityMachineBase;
import binnie.core.machines.component.IInteraction.ChunkUnload;
import binnie.core.machines.component.IInteraction.Invalidation;
import binnie.core.network.INetworkedEntity;
import binnie.core.network.packet.PacketPayload;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
public class TileEntityMachine
extends TileEntityMachineBase
implements INetworkedEntity
{
private Machine machine;
public void updateEntity()
{
super.updateEntity();
if (this.machine != null) {
this.machine.onUpdate();
}
}
public boolean canUpdate()
{
return super.canUpdate();
}
public TileEntityMachine(MachinePackage pack)
{
setMachine(pack);
}
public TileEntityMachine() {}
public void setMachine(MachinePackage pack)
{
if (pack != null) {
this.machine = new Machine(pack, this);
}
}
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
String name = nbtTagCompound.getString("name");
String group = nbtTagCompound.getString("group");
MachinePackage pack = Binnie.Machine.getPackage(group, name);
if (pack == null)
{
invalidate();
return;
}
setMachine(pack);
getMachine().readFromNBT(nbtTagCompound);
}
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
super.writeToNBT(nbtTagCompound);
String name = this.machine.getPackage().getUID();
String group = this.machine.getPackage().getGroup().getUID();
nbtTagCompound.setString("group", group);
nbtTagCompound.setString("name", name);
getMachine().writeToNBT(nbtTagCompound);
}
public void writeToPacket(PacketPayload payload)
{
this.machine.writeToPacket(payload);
}
public void readFromPacket(PacketPayload payload)
{
this.machine.readFromPacket(payload);
}
public Machine getMachine()
{
return this.machine;
}
public void onBlockDestroy()
{
if (getMachine() != null) {
getMachine().onBlockDestroy();
}
}
public final Packet getDescriptionPacket()
{
return getMachine() != null ? getMachine().getDescriptionPacket() : null;
}
public void invalidate()
{
super.invalidate();
for (IInteraction.Invalidation c : getMachine().getInterfaces(IInteraction.Invalidation.class)) {
c.onInvalidation();
}
}
public void onChunkUnload()
{
super.onChunkUnload();
for (IInteraction.ChunkUnload c : getMachine().getInterfaces(IInteraction.ChunkUnload.class)) {
c.onChunkUnload();
}
}
}
|