From b3e0b41ee654daf6005d625db5d080a819701997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Sun, 11 Jun 2017 18:52:08 +0200 Subject: [PATCH] Changed the Primitive Blast Furnace so that it uses the new Recipe Map --- ..._MetaTileEntity_PrimitiveBlastFurnace.java | 544 +++++++++--------- 1 file changed, 271 insertions(+), 273 deletions(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java index 3d54ac0e..c036bf97 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java @@ -9,6 +9,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.XSTR; import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Pollution; import gregtech.common.gui.GT_Container_BronzeBlastFurnace; @@ -22,310 +23,307 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.ChunkPosition; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; -public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace - extends MetaTileEntity { - public int mMaxProgresstime = 0; - public int mUpdate = 5; - public int mProgresstime = 0; - public boolean mMachine = false; - public ItemStack mOutputItem1; - public ItemStack mOutputItem2; +public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace extends MetaTileEntity { + private static final int INPUT_SLOTS = 2, OUTPUT_SLOTS = 2; - public GT_MetaTileEntity_PrimitiveBlastFurnace(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional, 4); - } + public int mMaxProgresstime = 0; + public int mUpdate = 5; + public int mProgresstime = 0; + public boolean mMachine = false; - public GT_MetaTileEntity_PrimitiveBlastFurnace(String aName) { - super(aName, 4); - } + public ItemStack[] mOutputItems = new ItemStack[OUTPUT_SLOTS]; - public boolean isSteampowered() { - return false; - } + @Deprecated + public ItemStack mOutputItem1; + @Deprecated + public ItemStack mOutputItem2; - public boolean isElectric() { - return false; - } + public GT_MetaTileEntity_PrimitiveBlastFurnace(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, INPUT_SLOTS + OUTPUT_SLOTS); + } - public boolean isPneumatic() { - return false; - } + public GT_MetaTileEntity_PrimitiveBlastFurnace(String aName) { + super(aName, INPUT_SLOTS + OUTPUT_SLOTS); + } - public boolean isEnetInput() { - return false; - } + public boolean isSteampowered() { + return false; + } - public boolean isEnetOutput() { - return false; - } + public boolean isElectric() { + return false; + } - public boolean isInputFacing(byte aSide) { - return false; - } + public boolean isPneumatic() { + return false; + } - public boolean isOutputFacing(byte aSide) { - return false; - } + public boolean isEnetInput() { + return false; + } - public boolean isTeleporterCompatible() { - return false; - } + public boolean isEnetOutput() { + return false; + } - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; - } + public boolean isInputFacing(byte aSide) { + return false; + } - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } + public boolean isOutputFacing(byte aSide) { + return false; + } - public int getProgresstime() { - return this.mProgresstime; - } + public boolean isTeleporterCompatible() { + return false; + } - public int maxProgresstime() { - return this.mMaxProgresstime; - } + public boolean isFacingValid(byte aFacing) { + return aFacing > 1; + } - public int increaseProgress(int aProgress) { - this.mProgresstime += aProgress; - return this.mMaxProgresstime - this.mProgresstime; - } + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { - return (GregTech_API.getCoverBehavior(aCoverID.toStack()).isSimpleCover()) && (super.allowCoverOnSide(aSide, aCoverID)); - } + public int getProgresstime() { + return this.mProgresstime; + } - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_BronzeBlastFurnace(this.mName); - } + public int maxProgresstime() { + return this.mMaxProgresstime; + } - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mProgresstime", this.mProgresstime); - aNBT.setInteger("mMaxProgresstime", this.mMaxProgresstime); - if (this.mOutputItem1 != null) { - NBTTagCompound tNBT = new NBTTagCompound(); - this.mOutputItem1.writeToNBT(tNBT); - aNBT.setTag("mOutputItem1", tNBT); - } - if (this.mOutputItem2 != null) { - NBTTagCompound tNBT = new NBTTagCompound(); - this.mOutputItem2.writeToNBT(tNBT); - aNBT.setTag("mOutputItem2", tNBT); - } - } + public int increaseProgress(int aProgress) { + this.mProgresstime += aProgress; + return this.mMaxProgresstime - this.mProgresstime; + } - public void loadNBTData(NBTTagCompound aNBT) { - this.mUpdate = 5; - this.mProgresstime = aNBT.getInteger("mProgresstime"); - this.mMaxProgresstime = aNBT.getInteger("mMaxProgresstime"); - this.mOutputItem1 = GT_Utility.loadItem(aNBT, "mOutputItem1"); - this.mOutputItem2 = GT_Utility.loadItem(aNBT, "mOutputItem2"); - } + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { + return (GregTech_API.getCoverBehavior(aCoverID.toStack()).isSimpleCover()) && (super.allowCoverOnSide(aSide, aCoverID)); + } - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_BronzeBlastFurnace(this.mName); + } - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_BronzeBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); - } + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mProgresstime", this.mProgresstime); + aNBT.setInteger("mMaxProgresstime", this.mMaxProgresstime); + if (this.mOutputItems != null) { + for (int i = 0; i < mOutputItems.length; i++) { + if (this.mOutputItems[i] != null) { + NBTTagCompound tNBT = new NBTTagCompound(); + this.mOutputItems[i].writeToNBT(tNBT); + aNBT.setTag("mOutputItem" + i, tNBT); + } + } + } + } - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BronzeBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); - } + public void loadNBTData(NBTTagCompound aNBT) { + this.mUpdate = 5; + this.mProgresstime = aNBT.getInteger("mProgresstime"); + this.mMaxProgresstime = aNBT.getInteger("mMaxProgresstime"); + this.mOutputItems = new ItemStack[OUTPUT_SLOTS]; + for (int i = 0; i < OUTPUT_SLOTS; i++) { + this.mOutputItems[i] = GT_Utility.loadItem(aNBT, "mOutputItem" + i); + } + } - private boolean checkMachine() { - int xDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()).offsetZ; - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 3; j++) { - for (int k = -1; k < 2; k++) { - if ((xDir + i != 0) || (j != 0) || (zDir + k != 0)) { - if ((i != 0) || (j == -1) || (k != 0)) { - if (!isCorrectCasingBlock(getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k)) || !isCorrectCasingMetaID(getBaseMetaTileEntity().getMetaIDOffset(xDir + i, j, zDir + k))) { - return false; - } - } else if ((!GT_Utility.arrayContains(getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k), new Object[]{Blocks.lava, Blocks.flowing_lava, null})) && (!getBaseMetaTileEntity().getAirOffset(xDir + i, j, zDir + k))) { - return false; - } - } - } - } - } - return true; - } + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } - protected abstract boolean isCorrectCasingBlock(Block block); - - protected abstract boolean isCorrectCasingMetaID(int metaID); - - public void onMachineBlockUpdate() { - this.mUpdate = 5; - } + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_BronzeBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); + } - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if ((aBaseMetaTileEntity.isClientSide()) && - (aBaseMetaTileEntity.isActive())) { - aBaseMetaTileEntity.getWorld().spawnParticle("largesmoke", aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1) + (new XSTR()).nextFloat(), aBaseMetaTileEntity.getOffsetY(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1) + (new XSTR()).nextFloat(), 0.0D, 0.3D, 0.0D); - } - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mUpdate-- == 0) { - this.mMachine = checkMachine(); - } - if (this.mMachine) { - if (this.mMaxProgresstime > 0) { - if (++this.mProgresstime >= this.mMaxProgresstime) { - addOutputProducts(); - this.mOutputItem1 = null; - this.mOutputItem2 = null; - this.mProgresstime = 0; - this.mMaxProgresstime = 0; - GT_Mod.achievements.issueAchievement(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "steel"); - } - } else if (aBaseMetaTileEntity.isAllowedToWork()) { - checkRecipe(); - } - } - if(this.mMaxProgresstime>0 && (aTimer % 20L == 0L)){ - GT_Pollution.addPollution(this.getBaseMetaTileEntity().getWorld(), new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()), 50); - } - - aBaseMetaTileEntity.setActive((this.mMaxProgresstime > 0) && (this.mMachine)); - if (aBaseMetaTileEntity.isActive()) { - if (aBaseMetaTileEntity.getAir(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1))) { - aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), Blocks.lava, 1, 2); - this.mUpdate = 1; - } - if (aBaseMetaTileEntity.getAir(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1))) { - aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), Blocks.lava, 1, 2); - this.mUpdate = 1; - } - } else { - if (aBaseMetaTileEntity.getBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1)) == Blocks.lava) { - aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), Blocks.air, 0, 2); - this.mUpdate = 1; - } - if (aBaseMetaTileEntity.getBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1)) == Blocks.lava) { - aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), Blocks.air, 0, 2); - this.mUpdate = 1; - } - } - } - } + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_BronzeBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); + } - private void addOutputProducts() { - if (this.mOutputItem1 != null) { - if (this.mInventory[2] == null) { - this.mInventory[2] = GT_Utility.copy(new Object[]{this.mOutputItem1}); - } else if (GT_Utility.areStacksEqual(this.mInventory[2], this.mOutputItem1)) { - this.mInventory[2].stackSize = Math.min(this.mOutputItem1.getMaxStackSize(), this.mOutputItem1.stackSize + this.mInventory[2].stackSize); - } - } - if (this.mOutputItem2 != null) { - if (this.mInventory[3] == null) { - this.mInventory[3] = GT_Utility.copy(new Object[]{this.mOutputItem2}); - } else if (GT_Utility.areStacksEqual(this.mInventory[3], this.mOutputItem2)) { - this.mInventory[3].stackSize = Math.min(this.mOutputItem2.getMaxStackSize(), this.mOutputItem2.stackSize + this.mInventory[3].stackSize); - } - } - } + private boolean checkMachine() { + int xDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()).offsetZ; + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 3; j++) { + for (int k = -1; k < 2; k++) { + if ((xDir + i != 0) || (j != 0) || (zDir + k != 0)) { + if ((i != 0) || (j == -1) || (k != 0)) { + if (!isCorrectCasingBlock(getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k)) + || !isCorrectCasingMetaID(getBaseMetaTileEntity().getMetaIDOffset(xDir + i, j, zDir + k))) { + return false; + } + } else if ((!GT_Utility.arrayContains(getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k), + new Object[] { Blocks.lava, Blocks.flowing_lava, null })) + && (!getBaseMetaTileEntity().getAirOffset(xDir + i, j, zDir + k))) { + return false; + } + } + } + } + } + return true; + } - private boolean spaceForOutput(ItemStack aStack1, ItemStack aStack2) { - if (((this.mInventory[2] == null) || (aStack1 == null) || ((this.mInventory[2].stackSize + aStack1.stackSize <= this.mInventory[2].getMaxStackSize()) && (GT_Utility.areStacksEqual(this.mInventory[2], aStack1)))) && ( - (this.mInventory[3] == null) || (aStack2 == null) || ((this.mInventory[3].stackSize + aStack2.stackSize <= this.mInventory[3].getMaxStackSize()) && (GT_Utility.areStacksEqual(this.mInventory[3], aStack2))))) { - return true; - } - return false; - } + protected abstract boolean isCorrectCasingBlock(Block block); - private boolean checkRecipe() { - if (!this.mMachine) { - return false; - } - if ((this.mInventory[0] != null) && (this.mInventory[1] != null) && (this.mInventory[0].stackSize >= 1)) { - if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "dustIron")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "ingotIron"))) { - if ((this.mInventory[1].getItem() == Items.coal) && (this.mInventory[1].stackSize >= 4) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 4L)))) { - getBaseMetaTileEntity().decrStackSize(0, 1); - getBaseMetaTileEntity().decrStackSize(1, 4); - this.mMaxProgresstime = 7200; - return true; - } - if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 2) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 4L)))) { - getBaseMetaTileEntity().decrStackSize(0, 1); - getBaseMetaTileEntity().decrStackSize(1, 2); - this.mMaxProgresstime = 4800; - return true; - } - if ((this.mInventory[0].stackSize >= 9) && ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCoal")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCharcoal"))) && (this.mInventory[1].stackSize >= 4) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { - getBaseMetaTileEntity().decrStackSize(0, 9); - getBaseMetaTileEntity().decrStackSize(1, 4); - this.mMaxProgresstime = 64800; - return true; - } - } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "dustSteel")) { - if ((this.mInventory[1].getItem() == Items.coal) && (this.mInventory[1].stackSize >= 2) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 2L)))) { - getBaseMetaTileEntity().decrStackSize(0, 1); - getBaseMetaTileEntity().decrStackSize(1, 2); - this.mMaxProgresstime = 3600; - return true; - } - if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 1) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 2L)))) { - getBaseMetaTileEntity().decrStackSize(0, 1); - getBaseMetaTileEntity().decrStackSize(1, 1); - this.mMaxProgresstime = 2400; - return true; - } - if ((this.mInventory[0].stackSize >= 9) && ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCoal")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCharcoal"))) && (this.mInventory[1].stackSize >= 2) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 2L)))) { - getBaseMetaTileEntity().decrStackSize(0, 9); - getBaseMetaTileEntity().decrStackSize(1, 2); - this.mMaxProgresstime = 32400; - return true; - } - } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "blockIron")) { - if ((this.mInventory[1].getItem() == Items.coal) && (this.mInventory[1].stackSize >= 36) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { - getBaseMetaTileEntity().decrStackSize(0, 1); - getBaseMetaTileEntity().decrStackSize(1, 36); - this.mMaxProgresstime = 64800; - return true; - } - if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 18) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Ash, 4L)))) { - getBaseMetaTileEntity().decrStackSize(0, 1); - getBaseMetaTileEntity().decrStackSize(1, 18); - this.mMaxProgresstime = 43200; - return true; - } - if (((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCoal")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCharcoal"))) && (this.mInventory[1].stackSize >= 4) && (spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { - getBaseMetaTileEntity().decrStackSize(0, 1); - getBaseMetaTileEntity().decrStackSize(1, 4); - this.mMaxProgresstime = 64800; - return true; - } - } - } - this.mOutputItem1 = null; - this.mOutputItem2 = null; - return false; - } + protected abstract boolean isCorrectCasingMetaID(int metaID); - public boolean isGivingInformation() { - return false; - } + public void onMachineBlockUpdate() { + this.mUpdate = 5; + } - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aIndex > 1; - } + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { + aBaseMetaTileEntity.getWorld().spawnParticle("largesmoke", + aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1) + (new XSTR()).nextFloat(), + aBaseMetaTileEntity.getOffsetY(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1) + (new XSTR()).nextFloat(), 0.0D, 0.3D, 0.0D); + } + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate-- == 0) { + this.mMachine = checkMachine(); + } + if (this.mMachine) { + if (this.mMaxProgresstime > 0) { + if (++this.mProgresstime >= this.mMaxProgresstime) { + addOutputProducts(); + this.mOutputItems = null; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + GT_Mod.achievements.issueAchievement( + aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "steel"); + } + } else if (aBaseMetaTileEntity.isAllowedToWork()) { + checkRecipe(); + } + } + if (this.mMaxProgresstime > 0 && (aTimer % 20L == 0L)) { + GT_Pollution.addPollution(this.getBaseMetaTileEntity().getWorld(), + new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), + this.getBaseMetaTileEntity().getZCoord()), + 50); + } - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return !GT_Utility.areStacksEqual(aStack, this.mInventory[0]); - } + aBaseMetaTileEntity.setActive((this.mMaxProgresstime > 0) && (this.mMachine)); + if (aBaseMetaTileEntity.isActive()) { + if (aBaseMetaTileEntity.getAir(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1))) { + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), + Blocks.lava, 1, 2); + this.mUpdate = 1; + } + if (aBaseMetaTileEntity.getAir(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1))) { + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), + Blocks.lava, 1, 2); + this.mUpdate = 1; + } + } else { + if (aBaseMetaTileEntity.getBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getYCoord(), + aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1)) == Blocks.lava) { + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), + Blocks.air, 0, 2); + this.mUpdate = 1; + } + if (aBaseMetaTileEntity.getBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getYCoord() + 1, + aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1)) == Blocks.lava) { + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), + Blocks.air, 0, 2); + this.mUpdate = 1; + } + } + } + } - public byte getTileEntityBaseType() { - return 0; - } + private void addOutputProducts() { + if (this.mOutputItems == null) { + return; + } + int limit = Math.min(mOutputItems.length, OUTPUT_SLOTS); + for (int i = 0; i < limit; i++) { + int absi = INPUT_SLOTS + i; + if (this.mInventory[absi] == null) { + this.mInventory[absi] = GT_Utility.copy(this.mOutputItems[i]); + } else if (GT_Utility.areStacksEqual(this.mInventory[absi], this.mOutputItems[i])) { + this.mInventory[absi].stackSize = Math.min(this.mInventory[absi].getMaxStackSize(), + this.mInventory[absi].stackSize + this.mOutputItems[i].stackSize); + } + } + } + + private boolean spaceForOutput(ItemStack outputStack, int relativeOutputSlot) { + int absoluteSlot = relativeOutputSlot + INPUT_SLOTS; + if (this.mInventory[absoluteSlot] == null || outputStack == null) { + return true; + } + if (((this.mInventory[absoluteSlot].stackSize + outputStack.stackSize <= this.mInventory[absoluteSlot].getMaxStackSize()) + && (GT_Utility.areStacksEqual(this.mInventory[absoluteSlot], outputStack)))) { + return true; + } + return false; + } + + private boolean checkRecipe() { + if (!this.mMachine) { + return false; + } + ItemStack[] inputs = new ItemStack[INPUT_SLOTS]; + System.arraycopy(mInventory, 0, inputs, 0, INPUT_SLOTS); + GT_Recipe recipe = GT_Recipe.GT_Recipe_Map.sPrimitiveBlastRecipes.findRecipe(getBaseMetaTileEntity(), false, 0, null, inputs); + if (recipe == null) { + this.mOutputItems = null; + return false; + } + for (int i = 0; i < OUTPUT_SLOTS; i++) { + if (!spaceForOutput(recipe.getOutput(i), i)) { + this.mOutputItems = null; + return false; + } + } + + if (!recipe.isRecipeInputEqual(true, null, inputs)) { + this.mOutputItems = null; + return false; + } + for (int i = 0; i < INPUT_SLOTS; i++) { + if (mInventory[i] != null && mInventory[i].stackSize == 0) { + mInventory[i] = null; + } + } + + this.mMaxProgresstime = recipe.mDuration; + this.mOutputItems = recipe.mOutputs; + return true; + } + + public boolean isGivingInformation() { + return false; + } + + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aIndex > INPUT_SLOTS; + } + + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return !GT_Utility.areStacksEqual(aStack, this.mInventory[0]); + } + + public byte getTileEntityBaseType() { + return 0; + } } \ No newline at end of file