Skip to content

Commit 9ed0563

Browse files
committed
* Updated adv miner 2 mechanics
Former-commit-id: 2ed91d3
1 parent 355e5a5 commit 9ed0563

1 file changed

Lines changed: 43 additions & 35 deletions

File tree

src/main/java/com/detrav/tileentities/Detrav_MetaTileEntity_AdvMiner2.java

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import net.minecraft.entity.player.InventoryPlayer;
2626
import net.minecraft.init.Blocks;
2727
import net.minecraft.item.ItemStack;
28+
import net.minecraft.nbt.NBTTagCompound;
2829
import net.minecraft.tileentity.TileEntity;
2930
import net.minecraft.world.ChunkPosition;
31+
import net.minecraft.world.World;
3032
import net.minecraft.world.chunk.Chunk;
3133
import net.minecraftforge.common.util.ForgeDirection;
3234
import net.minecraftforge.fluids.FluidStack;
@@ -49,7 +51,7 @@ public String[] getDescription() {
4951
return new String[]{
5052
"Controller Block for the Detrav Advanced Miner II",
5153
"Default size is one chunk, use circuit configuration",
52-
"to increase the size, {config}*2 + 1 chunks"
54+
"to increase the size, {config}*2 + 1 chunks",
5355
"Size(WxHxD): 3x7x3, Controller (Front middle bottom)",
5456
"3x1x3 Base of Solid Steel Casings",
5557
"1x3x1 Solid Steel Casing pillar (Center of base)",
@@ -95,12 +97,14 @@ public boolean checkRecipe(ItemStack aStack) {
9597
if (mMineList.isEmpty()) {
9698
int x = getXCurrent();
9799
int z = getZCurrent();
100+
World w = getBaseMetaTileEntity().getWorld();
101+
if(w==null) return false;
98102
for(int yLevel = getBaseMetaTileEntity().getYCoord() - 1; yLevel>1; yLevel --)
99103
{
100-
Block tBlock = c.getBlock(x,yLevel,z);
101-
int tMetaID = c.getBlockMetadata(x,yLevel,z);
104+
Block tBlock = w.getBlock(x,yLevel,z);
105+
int tMetaID = w.getBlockMetadata(x,yLevel,z);
102106
if (tBlock instanceof GT_Block_Ores_Abstract) {
103-
TileEntity tTileEntity = c.getTileEntityUnsafe(x,yLevel,z);
107+
TileEntity tTileEntity = w.getTileEntity(x,yLevel,z);
104108
if ((tTileEntity!=null)
105109
&& (tTileEntity instanceof GT_TileEntity_Ores)
106110
&& ((GT_TileEntity_Ores) tTileEntity).mNatural == true
@@ -111,7 +115,7 @@ public boolean checkRecipe(ItemStack aStack) {
111115
else {
112116
ItemData tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID));
113117
if ((tAssotiation != null) && (tAssotiation.mPrefix.toString().startsWith("ore"))) {
114-
ChunkPosition cp = new ChunkPosition(c.xPosition * 16 + x, yLevel, c.zPosition * 16 + z);
118+
ChunkPosition cp = new ChunkPosition(x, yLevel, z);
115119
if (!mMineList.contains(cp)) {
116120
mMineList.add(cp);
117121
}
@@ -210,6 +214,8 @@ private boolean moveFirst() {
210214
if (mInventory[1] == null && !mInventory[1].getUnlocalizedName().startsWith("gt.integrated_circuit")) return false;
211215

212216
circuit_config = mInventory[1].getItemDamage();
217+
218+
ItemStack aCircuit = mInventory[1];
213219

214220
circuit_config *= 2;
215221
circuit_config++;
@@ -218,38 +224,40 @@ private boolean moveFirst() {
218224

219225
NBTTagCompound aNBT = aCircuit.getTagCompound();
220226
if(aNBT == null) {
221-
aCircuit = new NBTTagCompound();
227+
aNBT = new NBTTagCompound();
222228
NBTTagCompound detravPosition = new NBTTagCompound();
223229
aNBT.setTag("DetravPosition", detravPosition);
224-
aStack.setTagCompound(aNBT);
230+
aCircuit.setTagCompound(aNBT);
225231
}
226232

227233
NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
228234
if (detravPosition == null ) {
229235
detravPosition = new NBTTagCompound();
230236
aNBT.setTag("DetravPosition", detravPosition);
231237
}
232-
configurated = detravPosition.hasKey("Configurated") && detravPosition.get("Configurated");
238+
configurated = detravPosition.hasKey("Configurated") && detravPosition.getBoolean("Configurated");
233239

234240
if(!configurated)
235241
{
236242
configurated = true;
237-
int x_from = getBaseMetaTileEntity().getXCoord() -circuit_config * 16;
238-
int x_to = getBaseMetaTileEntity().getXCoord() +circuit_config * 16;
243+
int x_from = ((getBaseMetaTileEntity().getXCoord() >> 4) - circuit_config+1) * 16;
244+
int x_to = ((getBaseMetaTileEntity().getXCoord() >> 4) + circuit_config) * 16;
239245
int x_current = x_from;
240-
int z_from = getBaseMetaTileEntity().getZCoord() - circuit_config * 16;
241-
int z_to = getBaseMetaTileEntity().getZCoord() + circuit_config * 16;
246+
int z_from = ((getBaseMetaTileEntity().getZCoord() >> 4) - circuit_config+1) * 16;
247+
int z_to = ((getBaseMetaTileEntity().getZCoord() >> 4) + circuit_config) * 16;
242248
int z_current = z_from;
243249

244-
detravPosition.set("XFrom",x_from);
245-
detravPosition.set("XTo",x_to);
246-
detravPosition.set("XCurrent",x_current);
247-
detravPosition.set("ZFrom",z_from);
248-
detravPosition.set("ZTo",z_to);
249-
detravPosition.set("ZCurrent",z_current);
250+
detravPosition.setInteger("XFrom",x_from);
251+
detravPosition.setInteger("XTo",x_to);
252+
detravPosition.setInteger("XCurrent",x_current);
253+
detravPosition.setInteger("ZFrom",z_from);
254+
detravPosition.setInteger("ZTo",z_to);
255+
detravPosition.setInteger("ZCurrent",z_current);
256+
257+
detravPosition.setBoolean("Configurated",configurated);
250258
}
251259
if(detravPosition.hasKey("Finished"))
252-
configurated = !detravPosition.get("Finished");
260+
configurated = !detravPosition.getBoolean("Finished");
253261
return configurated;
254262
}
255263

@@ -259,15 +267,15 @@ private int getXCurrent()
259267
if(mInventory[1] == null) return fakeResult;
260268
ItemStack aCircuit = mInventory[1];
261269
NBTTagCompound aNBT = aCircuit.getTagCompound();
262-
if(aNBT == null) return fakeResultfalse;
270+
if(aNBT == null) return fakeResult;
263271
NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
264272
if (detravPosition == null ) return fakeResult;
265273

266274
if(detravPosition.hasKey("Finished"))
267-
if(detravPosition.get("Finished"))
275+
if(detravPosition.getBoolean("Finished"))
268276
return fakeResult;
269277

270-
return detravPosition.get("XCurrent");
278+
return detravPosition.getInteger("XCurrent");
271279
}
272280

273281
private int getZCurrent()
@@ -276,15 +284,15 @@ private int getZCurrent()
276284
if(mInventory[1] == null) return fakeResult;
277285
ItemStack aCircuit = mInventory[1];
278286
NBTTagCompound aNBT = aCircuit.getTagCompound();
279-
if(aNBT == null) return fakeResultfalse;
287+
if(aNBT == null) return fakeResult;
280288
NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
281289
if (detravPosition == null ) return fakeResult;
282290

283291
if(detravPosition.hasKey("Finished"))
284-
if(detravPosition.get("Finished"))
292+
if(detravPosition.getBoolean("Finished"))
285293
return fakeResult;
286294

287-
return detravPosition.get("ZCurrent");
295+
return detravPosition.getInteger("ZCurrent");
288296
}
289297

290298

@@ -297,15 +305,15 @@ private boolean moveNext() {
297305
if (detravPosition == null ) return false;
298306

299307
if(detravPosition.hasKey("Finished"))
300-
if(detravPosition.get("Finished"))
308+
if(detravPosition.getBoolean("Finished"))
301309
return false;
302310

303-
int x_from = detravPosition.get("XFrom");
304-
int z_from = detravPosition.get("ZFrom");
305-
int x_to = detravPosition.get("XTo");
306-
int z_to = detravPosition.get("ZTo");
307-
int x_current = detravPosition.get("XCurrent");
308-
int z_current = detravPosition.get("ZCurrent");
311+
int x_from = detravPosition.getInteger("XFrom");
312+
int z_from = detravPosition.getInteger("ZFrom");
313+
int x_to = detravPosition.getInteger("XTo");
314+
int z_to = detravPosition.getInteger("ZTo");
315+
int x_current = detravPosition.getInteger("XCurrent");
316+
int z_current = detravPosition.getInteger("ZCurrent");
309317

310318
if(z_current < z_to)
311319
z_current++;
@@ -318,13 +326,13 @@ private boolean moveNext() {
318326
}
319327
else
320328
{
321-
detravPosition.set("Finished",true);
329+
detravPosition.setBoolean("Finished",true);
322330
return false;
323331
}
324332
}
325333

326-
detravPosition.set("XCurrent",x_current);
327-
detravPosition.get("ZCurrent",z_current);
334+
detravPosition.setInteger("XCurrent",x_current);
335+
detravPosition.setInteger("ZCurrent",z_current);
328336

329337
return true;
330338
}

0 commit comments

Comments
 (0)