-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecoBlockCompostBin.java
239 lines (204 loc) · 7.34 KB
/
DecoBlockCompostBin.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
package net.minecraft.src;
import java.util.Random;
public class DecoBlockCompostBin extends BlockContainer implements FCIBlockMechanical
{
private static int m_TickRate = 10;
private Icon m_IconBottom, m_IconSide, m_IconTop;
public static int currentState = 0;
public DecoBlockCompostBin(int id)
{
super(id, Material.wood);
this.setUnlocalizedName("decoBlockCompostBin");
this.setHardness(1.0F);
this.setTickRandomly(true);
this.setStepSound(soundWoodFootstep);
this.setCreativeTab(CreativeTabs.tabRedstone);
}
/**
* How many world ticks before ticking
*/
public int tickRate(World world)
{
return m_TickRate;
}
/**
* Ticks the block if it's been scheduled
*/
public void updateTick(World world, int x, int y, int z, Random random)
{
boolean var6 = this.IsInputtingMechanicalPower(world, x, y, z);
boolean var7 = this.IsBlockMechanicalOn(world, x, y, z);
if (var7 != var6)
{
this.SetMechanicalOn(world, x, y, z, var6);
}
}
public void RandomUpdateTick(World world, int x, int y, int z, Random random)
{
if (!this.IsCurrentStateValid(world, x, y, z) && !world.IsUpdateScheduledForBlock(x, y, z, this.blockID))
{
world.scheduleBlockUpdate(x, y, z, this.blockID, this.tickRate(world));
}
}
/**
* A randomly called display update to be able to add particles or other items for display
*/
public void randomDisplayTick(World world, int x, int y, int z, Random random)
{
if (this.IsBlockMechanicalOn(world, x, y, z) && this.currentState > 0)
{
for (int index = 0; index < 5; ++index)
{
float var7 = (float)x + random.nextFloat();
float var8 = (float)y + random.nextFloat() * 0.5F + 1.0F;
float var9 = (float)z + random.nextFloat();
world.spawnParticle("townaura", (double)var7, (double)var8, (double)var9, 0.0D, 0.0D, 0.0D);
}
}
}
/**
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
* their own) Args: x, y, z, neighbor blockID
*/
public void onNeighborBlockChange(World world, int x, int y, int z, int neighbourID)
{
if (!this.IsCurrentStateValid(world, x, y, z))
{
world.scheduleBlockUpdate(x, y, z, this.blockID, this.tickRate(world));
}
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
world.scheduleBlockUpdate(x, y, z, this.blockID, this.tickRate(world));
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
DecoTileEntityCompostBin entity = (DecoTileEntityCompostBin)world.getBlockTileEntity(x, y, z);
if (player instanceof EntityPlayerMP)
{
DecoContainerCompostBin container = new DecoContainerCompostBin(player.inventory, entity);
DecoUtilsPacketHandler.ServerOpenCustomInterface((EntityPlayerMP)player, container, DecoModuleMechanical.decoSubModuleCompostBin.decoContainerCompostBinID);
}
}
return true;
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World world)
{
return new DecoTileEntityCompostBin();
}
/**
* ejects contained items into the world, and notifies neighbours of an update, as appropriate
*/
public void breakBlock(World world, int x, int y, int z, int neighbourID, int flags)
{
FCUtilsInventory.EjectInventoryContents(world, x, y, z, (IInventory)world.getBlockTileEntity(x, y, z));
super.breakBlock(world, x, y, z, neighbourID, flags);
}
public boolean IsCurrentStateValid(World world, int x, int y, int z)
{
boolean var5 = this.IsInputtingMechanicalPower(world, x, y, z);
boolean var6 = this.IsBlockMechanicalOn(world, x, y, z);
return var6 == var5;
}
public boolean CanOutputMechanicalPower()
{
return false;
}
public boolean CanInputMechanicalPower()
{
return true;
}
public boolean IsInputtingMechanicalPower(World world, int x, int y, int z)
{
return FCUtilsMechPower.IsBlockPoweredByAxleToSide(world, x, y, z, 0);
}
public boolean CanInputAxlePowerToFacing(World world, int x, int y, int z, int side)
{
return side == 0;
}
public boolean IsOutputtingMechanicalPower(World world, int x, int y, int z)
{
return false;
}
public void Overpower(World world, int x, int y, int z)
{
this.BreakCompostBin(world, x, y, z);
}
public boolean IsBlockMechanicalOn(IBlockAccess bAccess, int x, int y, int z)
{
return (bAccess.getBlockMetadata(x, y, z) & 1) > 0;
}
public void SetMechanicalOn(World world, int x, int y, int z, boolean shouldUpdate)
{
int var6 = world.getBlockMetadata(x, y, z) & -2;
if (shouldUpdate)
var6 |= 1;
world.setBlockMetadataWithNotify(x, y, z, var6);
}
public int GetCurrentCompostingType(IBlockAccess bAccess, int x, int y, int z)
{
return this.GetCurrentCompostingTypeFromMetadata(bAccess.getBlockMetadata(x, y, z));
}
public void SetCurrentCompostingType(World world, int x, int y, int z, int var5)
{
int var6 = world.getBlockMetadata(x, y, z) & -7;
var6 |= var5 << 1;
world.setBlockMetadataWithClient(x, y, z, var6);
}
public int GetCurrentCompostingTypeFromMetadata(int var1)
{
return (var1 & 6) >> 1;
}
private void BreakCompostBin(World world, int x, int y, int z)
{
for (int index = 0; index < 8; ++index)
{
FCUtilsItem.EjectSingleItemWithRandomOffset(world, x, y, z, Block.wood.blockID, 0);
}
world.playAuxSFX(2235, x, y, z, 0);
world.setBlockWithNotify(x, y, z, 0);
}
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int side, int metadata)
{
switch (side)
{
case 0:
return this.m_IconBottom;
case 1:
return this.m_IconTop;
case 2:
case 3:
case 4:
case 5:
return this.m_IconSide;
default:
return this.blockIcon;
}
}
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister register)
{
this.blockIcon = register.registerIcon("wood");
this.m_IconBottom = register.registerIcon("decoBlockCompostBin_bottom");
this.m_IconTop = register.registerIcon("decoBlockCompostBin_top");
this.m_IconSide = register.registerIcon("decoBlockCompostBin_side");
}
}