-
Notifications
You must be signed in to change notification settings - Fork 754
/
DryingRack.java
310 lines (278 loc) · 8.94 KB
/
DryingRack.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
package tconstruct.blocks;
import java.util.List;
import mantle.blocks.abstracts.InventoryBlock;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tconstruct.TConstruct;
import tconstruct.blocks.logic.DryingRackLogic;
import tconstruct.client.block.DryingRackRender;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.AbilityHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class DryingRack extends InventoryBlock
{
public DryingRack()
{
super(Material.wood);
this.setCreativeTab(TConstructRegistry.blockTab);
setHardness(2.0f);
stepSound = soundTypeMetal;
}
@Override
public TileEntity createNewTileEntity (World world, int metadata)
{
return new DryingRackLogic();
}
@Override
public int getRenderBlockPass ()
{
return 1;
}
@Override
public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer)
{
return null;
}
@Override
public Object getModInstance ()
{
return TConstruct.instance;
}
@Override
public int onBlockPlaced (World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int meta)
{
if (side > 1)
return side;
return meta;
}
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLiving living, ItemStack stack)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0)
{
int l = MathHelper.floor_double((double) (living.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int direction = l % 2;
if (direction == 1)
world.setBlockMetadataWithNotify(x, y, z, 1, 2);
}
}
/* Activation */
@Override
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int side, float clickX, float clickY, float clickZ)
{
return activateDryingRack(world, x, y, z, player);
}
boolean activateDryingRack (World world, int x, int y, int z, EntityPlayer player)
{
if (!world.isRemote)
{
DryingRackLogic logic = (DryingRackLogic) world.getTileEntity(x, y, z);
if (!logic.isStackInSlot(0))
{
ItemStack stack = player.getCurrentEquippedItem();
if (stack != null)
{
stack = player.inventory.decrStackSize(player.inventory.currentItem, 1);
logic.setInventorySlotContents(0, stack);
}
}
else
{
if (logic.isStackInSlot(0))
{
ItemStack decrStack = logic.decrStackSize(0, 1);
if (decrStack != null)
addItemToInventory(player, world, x, y, z, decrStack);
}
}
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);
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool (World world, int x, int y, int z)
{
int metadata = world.getBlockMetadata(x, y, z);
float xMin = 0F;
float yMin = 0F;
float zMin = 0F;
float xMax = 1F;
float yMax = 1F;
float zMax = 1F;
switch (metadata)
{
case 0:
zMin = 0.375F;
yMax = 0.25F;
zMax = 0.625F;
break;
case 1:
xMin = 0.375F;
yMax = 0.25F;
xMax = 0.625F;
break;
case 2:
zMin = 0.75F;
yMin = 0.75F;
break;
case 3:
zMax = 0.25F;
yMin = 0.75F;
break;
case 4:
xMin = 0.75F;
yMin = 0.75F;
break;
case 5:
xMax = 0.25F;
yMin = 0.75F;
break;
}
return AxisAlignedBB.getAABBPool().getAABB((double) x + xMin, (double) y + yMin, (double) z + zMin, (double) x + xMax, (double) y + yMax, (double) z + zMax);
}
@Override
public void setBlockBoundsBasedOnState (IBlockAccess world, int x, int y, int z)
{
int metadata = world.getBlockMetadata(x, y, z);
float xMin = 0F;
float yMin = 0F;
float zMin = 0F;
float xMax = 1F;
float yMax = 1F;
float zMax = 1F;
switch (metadata)
{
case 0:
zMin = 0.375F;
yMax = 0.25F;
zMax = 0.625F;
break;
case 1:
xMin = 0.375F;
yMax = 0.25F;
xMax = 0.625F;
break;
case 2:
zMin = 0.75F;
yMin = 0.75F;
break;
case 3:
zMax = 0.25F;
yMin = 0.75F;
break;
case 4:
xMin = 0.75F;
yMin = 0.75F;
break;
case 5:
xMax = 0.25F;
yMin = 0.75F;
break;
}
this.setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax);
}
@Override
public void addCollisionBoxesToList (World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity)
{
this.setBlockBoundsBasedOnState(world, x, y, z);
super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
}
/* Rendering */
@Override
public int getRenderType ()
{
return DryingRackRender.model;
}
@Override
public String[] getTextureNames ()
{
String[] textureNames = { "castingtable_top", "castingtable_side", "castingtable_bottom", "faucet", "blockcast_top", "blockcast_side", "blockcast_bottom" };
return textureNames;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon (int side, int meta)
{
return Blocks.planks.getIcon(side, 0);
}
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 TileEntity createTileEntity (World world, int metadata)
{
return new DryingRackLogic();
}
/*
* @Override public boolean shouldSideBeRendered (IBlockAccess
* par1IBlockAccess, int par2, int par3, int par4, int par5) { return true;
* }
*/
/*
* @Override public void getSubBlocks (int 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 { FaucetLogic logic
* = (FaucetLogic) world.getBlockTileEntity(x, y, z); 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; }
*
* 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.getAABBPool().getAABB(x, y, z, x +
* 1, y + 1, z + 1); } else { FaucetLogic logic = (FaucetLogic)
* world.getBlockTileEntity(x, y, z); if (logic != null) { 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.getAABBPool().getAABB((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 */
}