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
|
package ihl.tunneling_shield;
import ic2.core.IC2;
import ic2.core.Ic2Items;
import ic2.core.audio.PositionSpec;
import ic2.core.item.tool.ItemToolWrench;
import ihl.IHLMod;
import java.util.ArrayList;
import java.util.Random;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class HorizontalMiningPipe extends Block {
public static ArrayList<DriverTileEntity> teList = new ArrayList<DriverTileEntity>();
public HorizontalMiningPipe() {
super(Material.iron);
this.setBlockBounds(0.1875F, 0.1875F, 0.1875F, 0.8125F, 0.8125F, 0.8125F);
}
public HorizontalMiningPipe(int meta) {
super(Material.iron);
this.setBlockBounds(0.1875F*meta, 0.1875F, 0.1875F*(1-meta), 0.8125F+0.1875F*(1-meta), 0.8125F, 0.8125F+0.1875F*meta);
}
@Override
public boolean canHarvestBlock(EntityPlayer player, int meta)
{
return true;
}
@Override
public Item getItem(World world, int x, int y, int z)
{
return Ic2Items.miningPipe.getItem();
}
@Override
public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
{
return Ic2Items.miningPipe.getItem();
}
@Override
public void dropBlockAsItemWithChance(World world, int x, int y, int z, int meta, float chance, int flag)
{
ItemStack result = Ic2Items.miningPipe;
result.stackSize=1;
this.dropBlockAsItem(world, x, y, z, result);
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("ic2:machine/blockMiningPipe");
}
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
return this.blockIcon;
}
/**
* The type of render function that is called for this block
*/
@Override
public int getRenderType()
{
return -2;
}
/**
* Is this block (a) opaque and (B) a full 1m cube? This determines whether or not to render the shared face of two
* adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
*/
@Override
public boolean isOpaqueCube()
{
return false;
}
/**
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
*/
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion)
{
super.onBlockDestroyedByExplosion(world, x, y, z, explosion);
this.checkIfMachinePart(world, x, y, z);
}
@Override
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta)
{
super.onBlockDestroyedByPlayer(world, x, y, z, meta);
this.checkIfMachinePart(world, x, y, z);
}
private void checkIfMachinePart(World world, int x, int y, int z)
{
if(teList.size()>0)
{
for (int i=0;i<teList.size();i++)
{
if(teList.get(i)!=null && !teList.get(i).isInvalid())
{
if(teList.get(i).isShaftCoord(x, y, z))
{
return;
}
}
else
{
teList.remove(i);
i--;
}
}
}
}
private void checkIfMachinePartNN(World world, int x, int y, int z)
{
boolean setToAir=true;
if(teList.size()>0)
{
for (int i=0;i<teList.size();i++)
{
if(teList.get(i)!=null)
{
if(teList.get(i).isShaftCoordNN(x, y, z) && teList.get(i).hasShield)
{
setToAir=false;
}
}
else
{
teList.remove(i);
i--;
}
}
}
if(setToAir)
{
world.setBlockToAir(x, y, z);
}
}
@Override
public void onBlockAdded(World world, int x, int y,int z)
{
world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world));
}
@Override
public void onNeighborBlockChange(World world, int x, int y,int z, Block block)
{
this.updateTick(world, x, y, z, world.rand);
}
@Override
public void updateTick(World world, int x, int y,int z, Random rand)
{
world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world));
this.checkIfMachinePartNN(world, x, y, z);
}
@Override
public int tickRate(World world)
{
return 200;
}
@Override
public boolean onBlockActivated(World world,int x,int y,int z,EntityPlayer entityPlayer,int i,float pos_x,float pos_y,float pos_z)
{
ItemStack currentIS = entityPlayer.inventory.getCurrentItem();
if(currentIS!=null)
{
if(currentIS.getItem() instanceof ItemToolWrench && entityPlayer.inventory.hasItem(Ic2Items.miningPipe.getItem()))
{
if(((ItemToolWrench)currentIS.getItem()).canTakeDamage(currentIS, 10))
{
if (IC2.platform.isRendering())
{
IC2.audioManager.playOnce(entityPlayer, PositionSpec.Hand, "Tools/wrench.ogg", true, 1.0F);
}
if(IC2.platform.isSimulating())
{
if(teList.size()>0)
{
for (int i3=0;i3<teList.size();i3++)
{
DriverTileEntity t = teList.get(i3);
if(t!=null)
{
if(t.isShaftCoordNN(x, y, z) && t.hasShield)
{
int xA=t.xCoord+t.shaftDestroyedAtA*t.mX();
int zA=t.zCoord+t.shaftDestroyedAtA*t.mZ();
int xB=t.xCoord+t.shaftDestroyedAtB*t.mX();
int zB=t.zCoord+t.shaftDestroyedAtB*t.mZ();
if(t.shaftDestroyedAtA!=0 && t.shaftDestroyedAtA==t.shaftDestroyedAtB)
{
if(Math.abs(x-xA+z-zA)==1)
{
if(world.setBlock(xA, y, zA, t.mX()!=0?IHLMod.horizontalMiningPipeZ:IHLMod.horizontalMiningPipeX))
{
t.shaftDestroyedAtA=t.shaftDestroyedAtB=0;
entityPlayer.inventory.consumeInventoryItem(Ic2Items.miningPipe.getItem());
entityPlayer.inventoryContainer.detectAndSendChanges();
return true;
}
}
}
else if(t.shaftDestroyedAtA!=0)
{
if(Math.abs(x-xA+z-zA)==1)
{
if(world.setBlock(xA, y, zA, t.mX()!=0?IHLMod.horizontalMiningPipeZ:IHLMod.horizontalMiningPipeX))
{
t.shaftDestroyedAtA++;
entityPlayer.inventory.consumeInventoryItem(Ic2Items.miningPipe.getItem());
entityPlayer.inventoryContainer.detectAndSendChanges();
return true;
}
}
if(Math.abs(x-xB+z-zB)==1)
{
if(world.setBlock(xB, y, zB, t.mX()!=0?IHLMod.horizontalMiningPipeZ:IHLMod.horizontalMiningPipeX))
{
t.shaftDestroyedAtB--;
entityPlayer.inventory.consumeInventoryItem(Ic2Items.miningPipe.getItem());
entityPlayer.inventoryContainer.detectAndSendChanges();
return true;
}
}
}
}
}
else
{
teList.remove(i);
i--;
}
}
}
((ItemToolWrench)currentIS.getItem()).damage(currentIS, 10, entityPlayer);
}
}
return true;
}
}
return false;
}
}
|