-
Notifications
You must be signed in to change notification settings - Fork 755
/
SmelteryBlock.java
306 lines (272 loc) · 8.95 KB
/
SmelteryBlock.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
package tconstruct.blocks;
import java.util.List;
import java.util.Random;
import mantle.blocks.abstracts.InventoryBlock;
import mantle.blocks.abstracts.MultiServantLogic;
import mantle.blocks.iface.IFacingLogic;
import mantle.blocks.iface.IMasterLogic;
import mantle.blocks.iface.IServantLogic;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tconstruct.TConstruct;
import tconstruct.blocks.logic.AdaptiveDrainLogic;
import tconstruct.blocks.logic.AdaptiveSmelteryLogic;
import tconstruct.blocks.logic.SmelteryDrainLogic;
import tconstruct.blocks.logic.SmelteryLogic;
import tconstruct.client.block.SmelteryRender;
import tconstruct.library.TConstructRegistry;
import tconstruct.util.config.PHConstruct;
public class SmelteryBlock extends InventoryBlock
{
Random rand;
String texturePrefix = "";
public SmelteryBlock()
{
super(Material.rock);
setHardness(3F);
setResistance(20F);
setStepSound(soundTypeMetal);
rand = new Random();
this.setCreativeTab(TConstructRegistry.blockTab);
this.setBlockName("tconstruct.Smeltery");
}
public SmelteryBlock(String prefix)
{
this();
texturePrefix = prefix;
}
/* Rendering */
@Override
public int getRenderType ()
{
return PHConstruct.newSmeltery ? 0 : SmelteryRender.smelteryModel;
}
@Override
public String[] getTextureNames ()
{
String[] textureNames = { "smeltery_side", "smeltery_inactive", "smeltery_active", "drain_side", "drain_out", "drain_basin", "searedbrick", "searedstone", "searedcobble", "searedpaver",
"searedbrickcracked", "searedroad", "searedbrickfancy", "searedbricksquare", "searedcreeper" };
if (!texturePrefix.equals(""))
for (int i = 0; i < textureNames.length; i++)
textureNames[i] = texturePrefix + "_" + textureNames[i];
return textureNames;
}
public IIcon getIcon (int side, int meta)
{
if (meta < 2)
{
int sideTex = side == 3 ? 1 : 0;
return icons[sideTex + meta * 3];
}
else if (meta == 2)
{
return icons[6];
}
else if (meta == 11)
{
if (side == 0 || side == 1)
return icons[9];
}
return icons[3 + meta];
}
public IIcon getIcon (IBlockAccess world, int x, int y, int z, int side)
{
TileEntity logic = world.getTileEntity(x, y, z);
short direction = (logic instanceof IFacingLogic) ? ((IFacingLogic) logic).getRenderDirection() : 0;
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0) // Smeltery
{
if (side == direction)
{
if (isActive(world, x, y, z))
{
return icons[2];
}
else
{
return icons[1];
}
}
else
{
return icons[0];
}
}
if (meta == 1) // Drain
{
if (side == direction)
return icons[5];
else if (side / 2 == direction / 2)
return icons[4];
else
return icons[3];
}
else if (meta == 2)
{
return icons[6];
}
else if (meta == 11)
{
if (side == 0 || side == 1)
return icons[9];
}
return icons[3 + meta];
}
/*
* @Override public int getRenderBlockPass() { return 1; }
*/
public int damageDropped (int meta)
{
return meta;
}
public int quantityDropped (Random random)
{
return 1;
}
@Override
public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer)
{
// return -1;
return TConstruct.proxy.smelteryGuiID;
}
public void randomDisplayTick (World world, int x, int y, int z, Random random)
{
if (isActive(world, x, y, z))
{
TileEntity logic = world.getTileEntity(x, y, z);
byte face = 0;
if (logic instanceof IFacingLogic)
face = ((IFacingLogic) logic).getRenderDirection();
float f = (float) x + 0.5F;
float f1 = (float) y + 0.5F + (random.nextFloat() * 6F) / 16F;
float f2 = (float) z + 0.5F;
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
switch (face)
{
case 4:
world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
break;
case 5:
world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
break;
case 2:
world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
break;
case 3:
world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
break;
}
}
}
public int getLightValue (IBlockAccess world, int x, int y, int z)
{
return !isActive(world, x, y, z) ? 0 : 9;
}
@Override
public Object getModInstance ()
{
return TConstruct.instance;
}
@Override
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int side, float clickX, float clickY, float clickZ)
{
if (player.isSneaking() || world.getBlockMetadata(x, y, z) != 0)
return false;
Integer integer = getGui(world, x, y, z, player);
if (integer == null || integer == -1)
{
return false;
}
else
{
// world.markBlockForUpdate(x, y, z);
player.openGui(getModInstance(), integer, world, x, y, z);
return true;
}
}
@Override
public TileEntity createNewTileEntity (World world, int metadata)
{
switch (metadata)
{
case 0:
if (PHConstruct.newSmeltery)
return new AdaptiveSmelteryLogic();
else
return new SmelteryLogic();
case 1:
if (PHConstruct.newSmeltery)
return new AdaptiveDrainLogic();
else
return new SmelteryDrainLogic();
case 3:
return null; // Furnace
}
return new MultiServantLogic();
}
@Override
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack stack)
{
super.onBlockPlacedBy(world, x, y, z, entityliving, stack);
if (world.getBlockMetadata(x, y, z) == 0 && !PHConstruct.newSmeltery)
onBlockPlacedElsewhere(world, x, y, z, entityliving);
}
public void onBlockPlacedElsewhere (World world, int x, int y, int z, EntityLivingBase entityliving)
{
SmelteryLogic logic = (SmelteryLogic) world.getTileEntity(x, y, z);
logic.checkValidPlacement();
}
/*
* @Override public void breakBlock (World world, int x, int y, int z, int
* par5, int par6) //Don't drop inventory { world.removeBlockTileEntity(x,
* y, z); }
*/
@Override
public void getSubBlocks (Item id, CreativeTabs tab, List list)
{
for (int iter = 0; iter < 12; iter++)
{
if (iter != 3)
list.add(new ItemStack(id, 1, iter));
}
}
/* Updating */
@Override
public void onNeighborBlockChange (World world, int x, int y, int z, Block nBlockID)
{
// System.out.println("Neighbor changed");
TileEntity logic = world.getTileEntity(x, y, z);
if (logic instanceof IServantLogic)
{
((IServantLogic) logic).notifyMasterOfChange();
}
else if (logic instanceof IMasterLogic)
{
((IMasterLogic) logic).notifyChange(null, x, y, z);
}
}
@Override
public void breakBlock (World world, int x, int y, int z, Block blockID, int meta)
{
TileEntity logic = world.getTileEntity(x, y, z);
if (logic instanceof IServantLogic)
{
((IServantLogic) logic).notifyMasterOfChange();
}
super.breakBlock(world, x, y, z, blockID, meta);
}
}