-
Notifications
You must be signed in to change notification settings - Fork 754
/
SearedBlock.java
393 lines (352 loc) · 11.7 KB
/
SearedBlock.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
package tconstruct.smeltery.blocks;
import cpw.mods.fml.relauncher.*;
import java.util.List;
import mantle.blocks.abstracts.InventoryBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.*;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.world.*;
import net.minecraftforge.common.MinecraftForge;
import tconstruct.TConstruct;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.event.SmelteryEvent;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.smeltery.logic.*;
import tconstruct.smeltery.model.CastingBlockRender;
public class SearedBlock extends InventoryBlock
{
public SearedBlock()
{
super(Material.rock);
this.setCreativeTab(TConstructRegistry.blockTab);
setHardness(3F);
setResistance(20F);
setStepSound(soundTypeMetal);
}
public SearedBlock(String texture)
{
this();
this.texturePrefix = texture;
}
@Override
public TileEntity createTileEntity (World world, int metadata)
{
switch (metadata)
{
case 0:
return new CastingTableLogic();
case 1:
return new FaucetLogic();
case 2:
return new CastingBasinLogic();
default:
return null;
}
}
@Override
public int getRenderBlockPass ()
{
return 0;
}
@Override
public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer)
{
return null;
}
@Override
public Object getModInstance ()
{
return TConstruct.instance;
}
/* Activation */
@Override
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int side, float clickX, float clickY, float clickZ)
{
int md = world.getBlockMetadata(x, y, z);
if (md == 0)
{
return activateCastingTable(world, x, y, z, player);
}
if (md == 2)
{
return activateCastingBasin(world, x, y, z, player);
}
else if (md == 1)
{
if (player.isSneaking())
return false;
FaucetLogic logic = (FaucetLogic) world.getTileEntity(x, y, z);
logic.setActive(true);
return true;
}
else
return super.onBlockActivated(world, x, y, z, player, side, clickX, clickY, clickZ);
}
boolean activateCastingTable (World world, int x, int y, int z, EntityPlayer player)
{
if (!world.isRemote)
{
CastingTableLogic logic = (CastingTableLogic) world.getTileEntity(x, y, z);
if (logic.liquid != null)
return true;
if (!logic.isStackInSlot(0) && !logic.isStackInSlot(1))
{
ItemStack stack = player.getCurrentEquippedItem();
stack = player.inventory.decrStackSize(player.inventory.currentItem, 1);
logic.setInventorySlotContents(0, stack);
MinecraftForge.EVENT_BUS.post(new SmelteryEvent.ItemInsertedIntoCasting(logic, x, y, z, stack, player));
}
else
{
if (logic.isStackInSlot(1))
{
MinecraftForge.EVENT_BUS.post(new SmelteryEvent.ItemRemovedFromCasting(logic, x, y, z, logic.getStackInSlot(1), player));
ItemStack stack = logic.decrStackSize(1, 1);
if (stack != null)
addItemToInventory(player, world, x, y, z, stack);
}
else if (logic.isStackInSlot(0))
{
MinecraftForge.EVENT_BUS.post(new SmelteryEvent.ItemRemovedFromCasting(logic, x, y, z, logic.getStackInSlot(0), player));
ItemStack stack = logic.decrStackSize(0, 1);
if (stack != null)
addItemToInventory(player, world, x, y, z, stack);
}
}
world.markBlockForUpdate(x, y, z);
}
return true;
}
boolean activateCastingBasin (World world, int x, int y, int z, EntityPlayer player)
{
if (!world.isRemote)
{
CastingBasinLogic logic = (CastingBasinLogic) world.getTileEntity(x, y, z);
if (logic.liquid != null)
return true;
if (!logic.isStackInSlot(0) && !logic.isStackInSlot(1))
{
ItemStack stack = player.getCurrentEquippedItem();
stack = player.inventory.decrStackSize(player.inventory.currentItem, 1);
logic.setInventorySlotContents(0, stack);
MinecraftForge.EVENT_BUS.post(new SmelteryEvent.ItemInsertedIntoCasting(logic, x, y, z, stack, player));
}
else
{
if (logic.isStackInSlot(1))
{
MinecraftForge.EVENT_BUS.post(new SmelteryEvent.ItemRemovedFromCasting(logic, x, y, z, logic.getStackInSlot(1), player));
ItemStack stack = logic.decrStackSize(1, 1);
if (stack != null)
addItemToInventory(player, world, x, y, z, stack);
}
else if (logic.isStackInSlot(0))
{
MinecraftForge.EVENT_BUS.post(new SmelteryEvent.ItemRemovedFromCasting(logic, x, y, z, logic.getStackInSlot(0), player));
ItemStack stack = logic.decrStackSize(0, 1);
if (stack != null)
addItemToInventory(player, world, x, y, z, stack);
}
}
world.markBlockForUpdate(x, y, z);
}
return true;
}
public void addItemToInventory (EntityPlayer player, World world, int x, int y, int z, ItemStack stack)
{
AbilityHelper.spawnItemAtPlayer(player, stack);
/*if (!world.isRemote)
{
EntityItem entityitem = new EntityItem(world, (double) x + 0.5D, (double) y + 0.9325D, (double) z + 0.5D, stack);
world.spawnEntityInWorld(entityitem);
entityitem.onCollideWithPlayer(player);
}*/
}
/* Rendering */
@Override
public int getRenderType ()
{
return CastingBlockRender.searedModel;
}
String texturePrefix = "";
@Override
public String[] getTextureNames ()
{
String[] textureNames = { "castingtable_top", "castingtable_side", "castingtable_bottom", "faucet", "blockcast_top", "blockcast_side", "blockcast_bottom" };
if (!texturePrefix.equals(""))
for (int i = 0; i < textureNames.length; i++)
textureNames[i] = texturePrefix + "_" + textureNames[i];
return textureNames;
}
@Override
public String getTextureDomain (int textureNameIndex)
{
return "tinker";
}
// TODO getIcon
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon (int side, int meta)
{
if (meta == 0)
return icons[getTextureIndex(side)];
else if (meta == 2)
return icons[getTextureIndex(side) + 4];
else
return icons[3];
}
public int getTextureIndex (int side)
{
if (side == 0)
return 2;
if (side == 1)
return 0;
return 1;
}
@Override
public boolean renderAsNormalBlock ()
{
return false;
}
@Override
public boolean isOpaqueCube ()
{
return false;
}
@Override
public boolean shouldSideBeRendered (IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
return true;
}
@Override
public void getSubBlocks (Item id, CreativeTabs tab, List list)
{
for (int iter = 0; iter < 3; iter++)
{
list.add(new ItemStack(id, 1, iter));
}
}
@Override
public void setBlockBoundsBasedOnState (IBlockAccess world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta != 1)
{
this.setBlockBounds(0, 0, 0, 1, 1, 1);
}
else
{
TileEntity te = world.getTileEntity(x, y, z);
float xMin = 0.25F;
float xMax = 0.75F;
float zMin = 0.25F;
float zMax = 0.75F;
if (te instanceof FaucetLogic)
{
FaucetLogic logic = (FaucetLogic) te;
switch (logic.getRenderDirection())
{
case 2:
zMin = 0.625F;
zMax = 1.0F;
break;
case 3:
zMax = 0.375F;
zMin = 0F;
break;
case 4:
xMin = 0.625F;
xMax = 1.0F;
break;
case 5:
xMax = 0.375F;
xMin = 0F;
break;
}
}
this.setBlockBounds(xMin, 0.25F, zMin, xMax, 0.625F, zMax);
}
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool (World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta != 1)
{
return AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1);
}
else
{
TileEntity tile = world.getTileEntity(x, y, z);
if (tile != null && tile instanceof FaucetLogic)
{
FaucetLogic logic = (FaucetLogic) tile;
float xMin = 0.25F;
float xMax = 0.75F;
float zMin = 0.25F;
float zMax = 0.75F;
switch (logic.getRenderDirection())
{
case 2:
zMin = 0.625F;
zMax = 1.0F;
break;
case 3:
zMax = 0.375F;
zMin = 0F;
break;
case 4:
xMin = 0.625F;
xMax = 1.0F;
break;
case 5:
xMax = 0.375F;
xMin = 0F;
break;
}
return AxisAlignedBB.getBoundingBox((double) ((float) x + xMin), (double) y + 0.25, (double) ((float) z + zMin), (double) ((float) x + xMax), (double) y + 0.625, (double) ((float) z + zMax));
}
}
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
/* Redstone */
@Override
public boolean canConnectRedstone (IBlockAccess world, int x, int y, int z, int side)
{
return world.getBlockMetadata(x, y, z) == 1;
}
private boolean wasPowered = false;
@Override
public void onNeighborBlockChange (World world, int x, int y, int z, Block neighborBlockID)
{
if (world.getBlockMetadata(x, y, z) == 1)
{
boolean isPowered = world.isBlockIndirectlyGettingPowered(x, y, z);
if (!wasPowered && isPowered)
{
FaucetLogic logic = (FaucetLogic) world.getTileEntity(x, y, z);
logic.setActive(true);
}
wasPowered = isPowered;
}
}
@Override
public TileEntity createNewTileEntity (World world, int metadata)
{
switch (metadata)
{
case 0:
return new CastingTableLogic();
case 1:
return new FaucetLogic();
case 2:
return new CastingBasinLogic();
default:
return null;
}
}
}