diff options
author | Antifluxfield <lyj_299792458@163.com> | 2017-09-22 01:34:10 +0800 |
---|---|---|
committer | Antifluxfield <lyj_299792458@163.com> | 2017-09-22 01:34:10 +0800 |
commit | e725c455b3d9025caeebdbf12cc9d25f238f74bb (patch) | |
tree | 4a583cb9eaed9af625dad1af0890e9470ea73259 /src/main/java/gregtech/common/tileentities/machines/multi | |
parent | 9d8ac82535b0099ef70e8995bca51f62f39f9f94 (diff) | |
download | GT5-Unofficial-e725c455b3d9025caeebdbf12cc9d25f238f74bb.tar.gz GT5-Unofficial-e725c455b3d9025caeebdbf12cc9d25f238f74bb.tar.bz2 GT5-Unofficial-e725c455b3d9025caeebdbf12cc9d25f238f74bb.zip |
Adding Fake Player for all drills and pumps
Diffstat (limited to 'src/main/java/gregtech/common/tileentities/machines/multi')
4 files changed, 83 insertions, 65 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java index 2f88d4465e..a285f13605 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java @@ -1,6 +1,5 @@ package gregtech.common.tileentities.machines.multi; -import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.VN; import gregtech.api.GregTech_API; @@ -92,15 +91,15 @@ public abstract class GT_MetaTileEntity_ConcreteBackfillerBase extends GT_MetaTi } private boolean isRefillableBlock(int aX, int aY, int aZ){ - if (getBaseMetaTileEntity().getTileEntity(aX, aY, aZ) != null) return false; - if (getBaseMetaTileEntity().getAir(aX, aY, aZ) || !getBaseMetaTileEntity().getBlock(aX, aY, aZ).getMaterial().isSolid()) - return true; - return false; + IGregTechTileEntity aBaseTile = getBaseMetaTileEntity(); + if (aBaseTile.getTileEntity(aX, aY, aZ) != null) return false; + if (!aBaseTile.getAir(aX, aY, aZ) && aBaseTile.getBlock(aX, aY, aZ).getMaterial().isSolid()) return false; + if (!GT_Utility.setBlockByFakePlayer(getFakePlayer(aBaseTile), aX, aY, aZ, GregTech_API.sBlockConcretes, 8, true)) return false; + return true; } private boolean tryRefillBlock(int aX, int aY, int aZ) { - if (!tryConsumeFluid()) - return false; + if (!tryConsumeFluid()) return false; getBaseMetaTileEntity().getWorld().setBlock(aX, aY, aZ, GregTech_API.sBlockConcretes, 8, 3); return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java index aa0bd0f1b1..7998d10285 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java @@ -23,6 +23,7 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.ForgeDirection; public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_MultiBlockBase { @@ -91,23 +92,30 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_Mu return false; } - protected boolean tryLowerPipe() { + /** + * @return 0 for succeeded, 1 for invalid block, 2 for not having mining pipes, 3 for event canceled. + */ + protected int tryLowerPipe() { return tryLowerPipe(false); } - protected boolean tryLowerPipe(boolean isSimulating) { - if (!isHasMiningPipes()) return false; - - if (yHead <= 0) return false; - if (!canLowerPipe()) return false; - + /** + * @return 0 for succeeded, 1 for invalid block, 2 for not having mining pipes, 3 for event canceled. + */ + protected int tryLowerPipe(boolean isSimulating) { + if (!isHasMiningPipes()) return 2; + switch (canLowerPipe()) { + case 1: return 1; + case 2: return 3; + } + + if (!GT_Utility.setBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), xPipe, yHead - 1, zPipe, miningPipeTipBlock, 0, isSimulating)) return 3; if (!isSimulating) { - getBaseMetaTileEntity().getWorld().setBlock(xPipe, yHead - 1, zPipe, miningPipeTipBlock); if (yHead != yDrill) getBaseMetaTileEntity().getWorld().setBlock(xPipe, yHead, zPipe, miningPipeBlock); - getBaseMetaTileEntity().decrStackSize(1, 1); } - return true; + + return 0; } private void putMiningPipesFromInputsInController() { @@ -140,8 +148,19 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_Mu return true; } - protected boolean canLowerPipe(){ - return yHead > 0 && !checkBlockAndMeta(xPipe, yHead - 1, zPipe, Blocks.bedrock, W); + /** + * @return 0 for available, 1 for invalid block, 2 for event canceled. + */ + protected int canLowerPipe(){ + IGregTechTileEntity aBaseTile = getBaseMetaTileEntity(); + if (yHead > 0 && GT_Utility.getBlockHardnessAt(aBaseTile.getWorld(), xPipe, yHead - 1, zPipe) >= 0) { + return GT_Utility.eraseBlockByFakePlayer(getFakePlayer(aBaseTile), xPipe, yHead - 1, zPipe, true) ? 0 : 2; + } + return 1; + } + + protected boolean reachingVoidOrBedrock() { + return yHead <= 0 || checkBlockAndMeta(xPipe, yHead - 1, zPipe, Blocks.bedrock, 0); } private boolean isHasMiningPipes() { @@ -163,19 +182,19 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_Mu } protected boolean workingDownward(ItemStack aStack, int xDrill, int yDrill, int zDrill, int xPipe, int zPipe, int yHead, int oldYHead) { - if(!tryLowerPipe()) { - if(waitForPipes()) return false; - workState = STATE_AT_BOTTOM; + switch (tryLowerPipe()) { + case 2: mMaxProgresstime = 0; return false; + case 3: workState = STATE_UPWARD; return true; + case 1: workState = STATE_AT_BOTTOM; return true; + default: return true; } - return true; } protected boolean workingAtBottom(ItemStack aStack, int xDrill, int yDrill, int zDrill, int xPipe, int zPipe, int yHead, int oldYHead) { - if(tryLowerPipe(true)) - workState = STATE_DOWNWARD; - else - workState = STATE_UPWARD; - return true; + switch (tryLowerPipe(true)) { + case 0: workState = STATE_DOWNWARD; return true; + default: workState = STATE_UPWARD; return true; + } } protected boolean workingUpward(ItemStack aStack, int xDrill, int yDrill, int zDrill, int xPipe, int zPipe, int yHead, int oldYHead) { @@ -278,13 +297,13 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_Mu return (meta == W || getBaseMetaTileEntity().getMetaID(x, y, z) == meta) && getBaseMetaTileEntity().getBlock(x, y, z) == block; } - - protected boolean waitForPipes(){ - if (canLowerPipe()) { - mMaxProgresstime = 0; - return true; - } - return false; + + private FakePlayer mFakePlayer = null; + + protected FakePlayer getFakePlayer(IGregTechTileEntity aBaseTile) { + if (mFakePlayer == null) mFakePlayer = GT_Utility.getFakePlayer(aBaseTile); + mFakePlayer.setPosition(aBaseTile.getXCoord(), aBaseTile.getYCoord(), aBaseTile.getZCoord()); + return mFakePlayer; } @Override @@ -311,8 +330,6 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_Mu public boolean explodesOnComponentBreak(ItemStack aStack) { return false; } - - public abstract Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity); protected abstract ItemList getCasingBlockItem(); @@ -371,7 +388,7 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_Mu IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); if (aMetaTileEntity == null) return false; if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_DataAccess) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; // TODO return mDataAccessHatches.add((GT_MetaTileEntity_Hatch_DataAccess) aMetaTileEntity); } return false; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java index 7d3b4678f0..068b09db58 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java @@ -1,5 +1,11 @@ package gregtech.common.tileentities.machines.multi;
+import static gregtech.api.enums.GT_Values.VN;
+import static gregtech.common.GT_UndergroundOil.undergroundOil;
+import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation;
+
+import java.util.ArrayList;
+
import gregtech.api.gui.GT_GUIContainer_MultiMachine;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GT_Utility;
@@ -10,13 +16,6 @@ import net.minecraft.world.chunk.Chunk; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
-import java.util.ArrayList;
-
-import static gregtech.api.enums.GT_Values.V;
-import static gregtech.api.enums.GT_Values.VN;
-import static gregtech.common.GT_UndergroundOil.undergroundOil;
-import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation;
-
public abstract class GT_MetaTileEntity_OilDrillBase extends GT_MetaTileEntity_DrillerBase {
private boolean completedCycle = false;
@@ -86,21 +85,20 @@ public abstract class GT_MetaTileEntity_OilDrillBase extends GT_MetaTileEntity_D @Override
protected boolean workingAtBottom(ItemStack aStack, int xDrill, int yDrill, int zDrill, int xPipe, int zPipe, int yHead, int oldYHead) {
- if(tryLowerPipe(true)) {
- workState = STATE_DOWNWARD;
- setElectricityStats();
+ switch (tryLowerPipe(true)) {
+ case 0: workState = STATE_DOWNWARD; setElectricityStats(); return true;
+ case 3: workState = STATE_UPWARD; return true;
}
- else {
- if (tryFillChunkList()) {
- float speed = .5F+(GT_Utility.getTier(getMaxInputVoltage()) - getMinTier()) *.25F;
- FluidStack tFluid = pumpOil(speed);
- if (tFluid != null && tFluid.amount > getTotalConfigValue()){
- this.mOutputFluids = new FluidStack[]{tFluid};
- return true;
- }
+
+ if (!reachingVoidOrBedrock() && tryFillChunkList()) {
+ float speed = .5F+(GT_Utility.getTier(getMaxInputVoltage()) - getMinTier()) *.25F;
+ FluidStack tFluid = pumpOil(speed);
+ if (tFluid != null && tFluid.amount > getTotalConfigValue()){
+ this.mOutputFluids = new FluidStack[]{tFluid};
+ return true;
}
- workState = STATE_UPWARD;
}
+ workState = STATE_UPWARD;
return true;
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java index bc523114bc..4e963d53ca 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java @@ -1,6 +1,6 @@ package gregtech.common.tileentities.machines.multi; -import static gregtech.api.enums.GT_Values.*; +import static gregtech.api.enums.GT_Values.VN; import java.util.ArrayList; @@ -46,11 +46,11 @@ public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTile fillMineListIfEmpty(xDrill, yDrill, zDrill, xPipe, zPipe, yHead); if (oreBlockPositions.isEmpty()) { - if (!tryLowerPipe()) { - if (waitForPipes()) return false; - workState = STATE_AT_BOTTOM; - return true; - } + switch (tryLowerPipe()) { + case 2: mMaxProgresstime = 0; return false; + case 3: workState = STATE_UPWARD; return true; + case 1: workState = STATE_AT_BOTTOM; return true; + } //new layer - fill again fillMineListIfEmpty(xDrill, yDrill, zDrill, xPipe, zPipe, yHead); } @@ -60,10 +60,14 @@ public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTile while ((oreBlock == null || oreBlock == Blocks.air) && !oreBlockPositions.isEmpty()) { oreBlockPos = oreBlockPositions.remove(0); - oreBlock = getBaseMetaTileEntity().getBlock(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + if (GT_Utility.eraseBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ, true)) + oreBlock = getBaseMetaTileEntity().getBlock(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); } - if (!tryConsumeDrillingFluid()) return false; + if (!tryConsumeDrillingFluid()) { + oreBlockPositions.add(0, oreBlockPos); + return false; + } if (oreBlock != null && oreBlock != Blocks.air) { ArrayList<ItemStack> oreBlockDrops = getBlockDrops(oreBlock, oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); getBaseMetaTileEntity().getWorld().setBlockToAir(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); |