-
Notifications
You must be signed in to change notification settings - Fork 755
/
AdaptiveSmelteryLogic.java
226 lines (190 loc) · 5.56 KB
/
AdaptiveSmelteryLogic.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package tconstruct.blocks.logic;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import tconstruct.TConstruct;
import tconstruct.blocks.component.SmelteryComponent;
import tconstruct.blocks.component.SmelteryScan;
import tconstruct.common.TContent;
import tconstruct.library.blocks.AdaptiveInventoryLogic;
import tconstruct.library.component.IComponentHolder;
import tconstruct.library.component.LogicComponent;
import tconstruct.library.component.MultiFluidTank;
import tconstruct.library.util.IActiveLogic;
import tconstruct.library.util.IMasterLogic;
import tconstruct.library.util.IServantLogic;
public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IActiveLogic, IMasterLogic, IComponentHolder
{
byte direction;
SmelteryScan structure = new SmelteryScan(this, TContent.smeltery, TContent.lavaTank);
MultiFluidTank multitank = new MultiFluidTank();
SmelteryComponent smeltery = new SmelteryComponent(this, structure, multitank, 800);
int tick = 0;
public void updateEntity ()
{
tick++;
if (tick % 4 == 0)
smeltery.heatItems();
if (tick % 20 == 0)
{
if (!structure.isComplete())
{
structure.checkValidStructure();
if (structure.isComplete())
{
smeltery.adjustSize(structure.getAirSize(), true);
multitank.setCapacity(structure.getAirSize() * (TConstruct.ingotLiquidValue * 18));
}
}
else
{
smeltery.update();
}
}
if (tick == 60)
{
tick = 0;
}
}
@Override
public void setWorldObj (World world)
{
super.setWorldObj(world);
structure.setWorld(world);
smeltery.setWorld(world);
}
@Override
public byte getRenderDirection ()
{
return direction;
}
@Override
public ForgeDirection getForgeDirection ()
{
return ForgeDirection.VALID_DIRECTIONS[direction];
}
@Override
public void setDirection (int side)
{
}
@Override
public void setDirection (float yaw, float pitch, EntityLivingBase player)
{
int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3;
switch (facing)
{
case 0:
direction = 2;
break;
case 1:
direction = 5;
break;
case 2:
direction = 3;
break;
case 3:
direction = 4;
break;
}
}
@Override
public boolean getActive ()
{
return structure.isComplete();
}
@Override
public void setActive (boolean flag)
{
}
@Override
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
{
return null;
}
@Override
public String getDefaultName ()
{
return "crafters.Smeltery";
}
@Override
public List<LogicComponent> getComponents ()
{
ArrayList<LogicComponent> ret = new ArrayList<LogicComponent>(3);
ret.add(structure);
ret.add(multitank);
ret.add(smeltery);
return ret;
}
@Override
public void notifyChange (IServantLogic servant, int x, int y, int z)
{
}
@Override
public void placeBlock (EntityLivingBase entity, ItemStack itemstack)
{
structure.checkValidStructure();
if (structure.isComplete())
{
smeltery.adjustSize(structure.getAirSize(), true);
multitank.setCapacity(structure.getAirSize() * (TConstruct.ingotLiquidValue * 18));
}
}
@Override
public void removeBlock ()
{
structure.cleanup();
}
@Override
public void readFromNBT (NBTTagCompound tags)
{
super.readFromNBT(tags);
structure.readFromNBT(tags);
multitank.readFromNBT(tags);
smeltery.readFromNBT(tags);
}
@Override
public void writeToNBT (NBTTagCompound tags)
{
super.writeToNBT(tags);
structure.writeToNBT(tags);
multitank.writeToNBT(tags);
smeltery.writeToNBT(tags);
}
public void readNetworkNBT (NBTTagCompound tags)
{
direction = tags.getByte("Direction");
structure.readNetworkNBT(tags);
multitank.readNetworkNBT(tags);
smeltery.readNetworkNBT(tags);
}
public void writeNetworkNBT (NBTTagCompound tags)
{
tags.setByte("Direction", direction);
structure.writeNetworkNBT(tags);
multitank.writeNetworkNBT(tags);
smeltery.writeNetworkNBT(tags);
}
@Override
public void onDataPacket (INetworkManager net, Packet132TileEntityData packet)
{
readNetworkNBT(packet.data);
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
}
@Override
public Packet getDescriptionPacket ()
{
NBTTagCompound tag = new NBTTagCompound();
writeNetworkNBT(tag);
return new Packet132TileEntityData(xCoord, yCoord, zCoord, 1, tag);
}
}