diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-29 16:04:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-29 16:04:28 +0200 |
commit | 7d1f51a8937e0a86486267437d444696e81e8aa0 (patch) | |
tree | a5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities | |
parent | 5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff) | |
download | GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2 GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip |
Buildscript + Spotless (#318)
* Convert AES.java to readable class
* Buildscript
* Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities')
125 files changed, 40697 insertions, 38462 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricAutoWorkbench.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricAutoWorkbench.java index 7b223f8245..79400b68e6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricAutoWorkbench.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricAutoWorkbench.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.automation; -import java.util.ArrayList; - import gregtech.api.enums.GT_Values; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.Textures; @@ -19,6 +17,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.automation.GT_Container_ElectricAutoWorkbench; import gtPlusPlus.xmod.gregtech.api.gui.automation.GT_GUIContainer_ElectricAutoWorkbench; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -26,747 +25,844 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.oredict.OreDictionary; public class GT_MetaTileEntity_ElectricAutoWorkbench extends GT_MetaTileEntity_BasicTank { - - public int mMode = 0, mCurrentSlot = 0, mThroughPut = 0, mTicksUntilNextUpdate = 20; - public boolean mLastCraftSuccessful = false; - protected String mLocalName; - - public GT_MetaTileEntity_ElectricAutoWorkbench(final int aID, final int aTier, final String aDescription) { - super(aID, "basicmachine.automation.autoworkbench.0"+aTier, "Auto Workbench ("+GT_Values.VN[aTier]+")", aTier, 30, aDescription); - mLocalName = "Auto Workbench ("+GT_Values.VN[aTier]+")"; - } - - public GT_MetaTileEntity_ElectricAutoWorkbench(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, 30, aDescription, aTextures); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_ElectricAutoWorkbench(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_ElectricAutoWorkbench(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public boolean isTransformerUpgradable() { - return true; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isValidSlot(int aIndex) { - return aIndex < 19; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isInputFacing(byte aSide) { - return !isOutputFacing(aSide); - } - - @Override - public boolean isOutputFacing(byte aSide) { - return aSide == getBaseMetaTileEntity().getBackFacing(); - } - - @Override - public boolean isTeleporterCompatible() { - return false; - } - - @Override - public long maxEUInput() { - return GT_Values.V[mTier]; - } - - @Override - public long maxEUOutput() { - return mThroughPut % 2 == 0 ? GT_Values.V[mTier] : 0; - } - - @Override - public long getMinimumStoredEU() { - return GT_Values.V[this.mTier]; - } - - @Override - public long maxEUStore() { - return GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier]); - } - - @Override - public int getSizeInventory() { - return 30; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_ElectricAutoWorkbench(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("mMode", mMode); - aNBT.setInteger("mThroughPut", mThroughPut); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - mMode = aNBT.getInteger("mMode"); - mThroughPut = aNBT.getInteger("mThroughPut"); - } - - @Override - public boolean doesFillContainers() { - return false; - } - - @Override - public boolean doesEmptyContainers() { - return false; - } - - @Override - public boolean canTankBeFilled() { - return true; - } - - @Override - public boolean canTankBeEmptied() { - return true; - } - - @Override - public boolean displaysItemStack() { - return false; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - return aSide != getBaseMetaTileEntity().getFrontFacing() && aSide != getBaseMetaTileEntity().getBackFacing(); - } - - private static final int MAX_MODES = 10; - - public void switchModeForward() { - mMode = (mMode + 1) % MAX_MODES; - switchMode(); - } - - public void switchModeBackward() { - mMode--; - if (mMode < 0) mMode = MAX_MODES-1; - switchMode(); - } - - private void switchMode() { - mInventory[28] = null; - } - - public void switchThrough() { - mThroughPut = (mThroughPut + 1) % 4; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide() && getBaseMetaTileEntity().getUniversalEnergyStored() >= (mMode==5||mMode==6?128:2048) && (getBaseMetaTileEntity().hasWorkJustBeenEnabled() || --mTicksUntilNextUpdate<1)) { - mTicksUntilNextUpdate = 32; - - for (byte i = 19; i < 28; i++) { - if (mInventory[i] != null && mInventory[i].isItemStackDamageable() && mInventory[i].getItem().hasContainerItem()) { - mInventory[i].setItemDamage(OreDictionary.WILDCARD_VALUE); - } - } - - if (mInventory[18] == null) { - for (byte i = 0; i < 18 && mFluid != null; i++) { - ItemStack tOutput = GT_Utility.fillFluidContainer(mFluid, mInventory[i], false, true); - if (tOutput != null) { - for (byte j = 0; j < 9; j++) { - if (mInventory[j] == null || (GT_Utility.areStacksEqual(tOutput, mInventory[j]) && mInventory[j].stackSize + tOutput.stackSize <= tOutput.getMaxStackSize())) { - mFluid.amount -= GT_Utility.getFluidForFilledItem(tOutput, true).amount * tOutput.stackSize; - getBaseMetaTileEntity().decrStackSize(i, 1); - if (mInventory[j] == null) { - mInventory[j] = tOutput; - } else { - mInventory[j].stackSize++; - } - if (mFluid.amount <= 0) mFluid = null; - break; - } - } - } - } - - ItemStack[] tRecipe = new ItemStack[9]; - ItemStack tTempStack = null, tOutput = null; - - if (mInventory[17] != null && mThroughPut < 2 && mMode != 0) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[17]; - mInventory[17] = null; - } - } else { - if (!mLastCraftSuccessful) { - mCurrentSlot = (mCurrentSlot+1)%18; - for (int i = 0; i < 17 && mInventory[mCurrentSlot] == null; i++) - mCurrentSlot = (mCurrentSlot+1)%18; - } - switch (mMode) { - case 0: - if (mInventory[mCurrentSlot] != null && !isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2 && mCurrentSlot < 8) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - for (int i = 0; i < 9; i++) { - tRecipe[i] = mInventory[i+19]; - if (tRecipe[i] != null) { - tRecipe[i] = GT_Utility.copy(tRecipe[i]); - tRecipe[i].stackSize = 1; - } - } - break; - case 1: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - tRecipe[0] = tTempStack; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - tRecipe[1] = tTempStack; - tRecipe[3] = tTempStack; - tRecipe[4] = tTempStack; - } else break; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - tRecipe[2] = tTempStack; - tRecipe[5] = tTempStack; - tRecipe[6] = tTempStack; - tRecipe[7] = tTempStack; - tRecipe[8] = tTempStack; - } else break; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - break; - case 2: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - tRecipe[0] = tTempStack; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - break; - case 3: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - tRecipe[0] = tTempStack; - tRecipe[1] = tTempStack; - tRecipe[3] = tTempStack; - tRecipe[4] = tTempStack; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - break; - case 4: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - tRecipe[0] = tTempStack; - tRecipe[1] = tTempStack; - tRecipe[2] = tTempStack; - tRecipe[3] = tTempStack; - tRecipe[4] = tTempStack; - tRecipe[5] = tTempStack; - tRecipe[6] = tTempStack; - tRecipe[7] = tTempStack; - tRecipe[8] = tTempStack; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - break; - case 5: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - tRecipe[0] = tTempStack; - - tOutput = GT_OreDictUnificator.get(true, tTempStack); - - if (tOutput != null && GT_Utility.areStacksEqual(tOutput, tTempStack)) tOutput = null; - - if (tOutput == null) { - tRecipe[0] = null; - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - } - break; - case 6: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } else if (OrePrefixes.dustSmall.contains(mInventory[mCurrentSlot])) { - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - tRecipe[0] = tTempStack; - tRecipe[1] = tTempStack; - tRecipe[3] = tTempStack; - tRecipe[4] = tTempStack; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - } else if (OrePrefixes.dustTiny.contains(mInventory[mCurrentSlot])) { - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - tRecipe[0] = tTempStack; - tRecipe[1] = tTempStack; - tRecipe[2] = tTempStack; - tRecipe[3] = tTempStack; - tRecipe[4] = tTempStack; - tRecipe[5] = tTempStack; - tRecipe[6] = tTempStack; - tRecipe[7] = tTempStack; - tRecipe[8] = tTempStack; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - } else { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - break; - case 7: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot]) || !OrePrefixes.nugget.contains(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - tRecipe[0] = tTempStack; - tRecipe[1] = tTempStack; - tRecipe[2] = tTempStack; - tRecipe[3] = tTempStack; - tRecipe[4] = tTempStack; - tRecipe[5] = tTempStack; - tRecipe[6] = tTempStack; - tRecipe[7] = tTempStack; - tRecipe[8] = tTempStack; - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - break; - case 8: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot]) || mInventory[mCurrentSlot].getItemDamage() <= 0 || !mInventory[mCurrentSlot].getItem().isRepairable()) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); - tTempStack.stackSize = 1; - for (int i = mCurrentSlot + 1; i < 18; i++) { - if (mInventory[i] != null && mInventory[i].getItem() == tTempStack.getItem() && mInventory[mCurrentSlot].getItemDamage()+mInventory[i].getItemDamage()>tTempStack.getMaxDamage()) { - tRecipe[0] = tTempStack; - tRecipe[1] = GT_Utility.copy(mInventory[i]); - if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { - if (mInventory[18] == null) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - } - break; - } - } - break; - case 9: - if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { - if (mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mCurrentSlot]; - mInventory[mCurrentSlot] = null; - mTicksUntilNextUpdate = 1; - } - break; - } - for (byte i = 0, j = 0; i < 18 && j < 9 && (j < 2 || GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null); i++) { - tRecipe[j] = mInventory[(mCurrentSlot+i)%18]; - if (tRecipe[j] != null) { - tRecipe[j] = GT_Utility.copy(tRecipe[j]); - tRecipe[j].stackSize = 1; - j++; - } - } - if (tRecipe[1] == null) tRecipe[0] = null; - break; - } - } - - if (tOutput == null) tOutput = GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe); - - if (tOutput != null || mMode == 0) mInventory[28] = tOutput; - - if (tOutput == null) { - mLastCraftSuccessful = false; - } else { - if ((tTempStack = GT_OreDictUnificator.get(true, tOutput)) != null) { - tTempStack.stackSize = tOutput.stackSize; - tOutput = tTempStack; - } - - mInventory[28] = GT_Utility.copy(tOutput); - ArrayList<ItemStack> tList = recipeContent(tRecipe), tContent = benchContent(); - if (tList.size() > 0 && tContent.size() > 0) { - - boolean success = (mMode==6||mMode==7||mInventory[17]==null); - for (byte i = 0; i < tList.size() && success; i++) { - success = false; - for (byte j = 0; j < tContent.size() && !success; j++) { - if (GT_Utility.areStacksEqual(tList.get(i), tContent.get(j))) { - if (tList.get(i).stackSize <= tContent.get(j).stackSize) { - success = true; - } - } - } - } - - if (success) { - mLastCraftSuccessful = true; - - for (byte i = 8; i > -1; i--) { - for (byte j = 17; j > -1; j--) { - if (tRecipe[i] != null && mInventory[j] != null) { - if (GT_Utility.areStacksEqual(tRecipe[i], mInventory[j])) { - ItemStack tStack = GT_Utility.getContainerItem(mInventory[j], true); - if (tStack != null) { - getBaseMetaTileEntity().decrStackSize(j, 1); - if (!tStack.isItemStackDamageable() || tStack.getItemDamage() < tStack.getMaxDamage()) { - for (byte k = 9; k < 18; k++) { - if (mInventory[k] == null) { - mInventory[k] = GT_Utility.copy(tStack); - break; - } else if (GT_Utility.areStacksEqual(mInventory[k], tStack) && mInventory[k].stackSize + tStack.stackSize <= tStack.getMaxStackSize()) { - mInventory[k].stackSize += tStack.stackSize; - break; - } - } - } - } else { - getBaseMetaTileEntity().decrStackSize(j, 1); - } - break; - } - } - } - } - - mInventory[18] = GT_Utility.copy(tOutput); - getBaseMetaTileEntity().decreaseStoredEnergyUnits(mMode==5||mMode==6||mMode==7?128:2048, true); - mTicksUntilNextUpdate = 1; - } else { - mLastCraftSuccessful = false; - if (mInventory[mMode==0?8:17] != null && mInventory[18] == null && mThroughPut < 2) { - mInventory[18] = mInventory[mMode==0?8:17]; - mInventory[mMode==0?8:17] = null; - mTicksUntilNextUpdate = 1; - } - } - } - - if (mInventory[18] == null && mThroughPut < 2) { - for (byte i = 0; i < 8; i++) { - for (byte j = i; ++j < 9;) { - if (GT_Utility.areStacksEqual(mInventory[i], mInventory[j]) && mInventory[i].getMaxStackSize() > 8) { - mInventory[18] = mInventory[j]; - mInventory[j] = null; - mTicksUntilNextUpdate = 1; - break; - } - } - } - } - } - } - - if (mThroughPut < 2) { - getBaseMetaTileEntity().decreaseStoredEnergyUnits(GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), getBaseMetaTileEntity().getIInventoryAtSide(getBaseMetaTileEntity().getBackFacing()), getBaseMetaTileEntity().getBackFacing(), getBaseMetaTileEntity().getFrontFacing(), null, false, (byte)64, (byte)1, (byte)64, (byte)1)*10, true); - } - } - } - - private boolean isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(ItemStack aStack) { - if (aStack == null) return true; - for (byte i = 19; i < 28; i++) { - if (mInventory[i] != null) { - if (GT_Utility.areStacksEqual(mInventory[i], aStack)) return true; - if (GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(mInventory[i], true), aStack)) return true; - } - } - return false; - } - - private ArrayList<ItemStack> recipeContent(ItemStack[] tRecipe) { - ArrayList<ItemStack> tList = new ArrayList<ItemStack>(); - for (byte i = 0; i < 9; i++) { - if (tRecipe[i] != null) { - boolean temp = false; - for (byte j = 0; j < tList.size(); j++) { - if (GT_Utility.areStacksEqual(tRecipe[i], tList.get(j))) { - tList.get(j).stackSize++; - temp = true; - break; - } - } - if (!temp) tList.add(GT_Utility.copy(1, tRecipe[i])); - } - } - return tList; - } - - private ArrayList<ItemStack> benchContent() { - ArrayList<ItemStack> tList = new ArrayList<ItemStack>(); - for (byte i = 0; i < 18; i++) { - if (mInventory[i] != null) { - boolean temp = false; - for (byte j = 0; j < tList.size(); j++) { - if (GT_Utility.areStacksEqual(mInventory[i], mInventory[j])) { - tList.get(j).stackSize += mInventory[i].stackSize; - temp = true; - break; - } - } - if (!temp) tList.add(GT_Utility.copy(mInventory[i])); - } - } - return tList; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return mMode==0?aIndex>=10:aIndex>=18; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return mMode==0?aIndex<9:aIndex<18; - } - - /*@Override - public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { - if (aSide == aFacing) - return 112; - if (GT_Utility.getOppositeSide(aSide) == aFacing) - return 113; - return 114; - }*/ - - @Override - public int getCapacity() { - return 16000; - } - - @Override - public int getTankPressure() { - return -100; - } - - @Override - public String[] getDescription() { - return new String[] { - "Automatic Crafting Table Mk III", - //this.mDescription, - CORE.GT_Tooltip }; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFront(i); - rTextures[6][i + 1] = this.getBack(i); - rTextures[7][i + 1] = this.getBottom(i); - rTextures[8][i + 1] = this.getTop(i); - rTextures[9][i + 1] = this.getSides(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == aFacing) { - return this.mTextures[0][aColorIndex + 1]; - } - else if (GT_Utility.getOppositeSide(aSide) == aFacing) { - return this.mTextures[1][aColorIndex + 1]; - } - else { - return this.mTextures[4][aColorIndex + 1]; - } - /*return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 - : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1];*/ - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay)}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE)}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], }; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) }; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay)}; - } + + public int mMode = 0, mCurrentSlot = 0, mThroughPut = 0, mTicksUntilNextUpdate = 20; + public boolean mLastCraftSuccessful = false; + protected String mLocalName; + + public GT_MetaTileEntity_ElectricAutoWorkbench(final int aID, final int aTier, final String aDescription) { + super( + aID, + "basicmachine.automation.autoworkbench.0" + aTier, + "Auto Workbench (" + GT_Values.VN[aTier] + ")", + aTier, + 30, + aDescription); + mLocalName = "Auto Workbench (" + GT_Values.VN[aTier] + ")"; + } + + public GT_MetaTileEntity_ElectricAutoWorkbench( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 30, aDescription, aTextures); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_ElectricAutoWorkbench(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_ElectricAutoWorkbench(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(int aIndex) { + return aIndex < 19; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isInputFacing(byte aSide) { + return !isOutputFacing(aSide); + } + + @Override + public boolean isOutputFacing(byte aSide) { + return aSide == getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long maxEUInput() { + return GT_Values.V[mTier]; + } + + @Override + public long maxEUOutput() { + return mThroughPut % 2 == 0 ? GT_Values.V[mTier] : 0; + } + + @Override + public long getMinimumStoredEU() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUStore() { + return GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier]); + } + + @Override + public int getSizeInventory() { + return 30; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_ElectricAutoWorkbench(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mMode", mMode); + aNBT.setInteger("mThroughPut", mThroughPut); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mMode = aNBT.getInteger("mMode"); + mThroughPut = aNBT.getInteger("mThroughPut"); + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return true; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return aSide != getBaseMetaTileEntity().getFrontFacing() + && aSide != getBaseMetaTileEntity().getBackFacing(); + } + + private static final int MAX_MODES = 10; + + public void switchModeForward() { + mMode = (mMode + 1) % MAX_MODES; + switchMode(); + } + + public void switchModeBackward() { + mMode--; + if (mMode < 0) mMode = MAX_MODES - 1; + switchMode(); + } + + private void switchMode() { + mInventory[28] = null; + } + + public void switchThrough() { + mThroughPut = (mThroughPut + 1) % 4; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (getBaseMetaTileEntity().isAllowedToWork() + && getBaseMetaTileEntity().isServerSide() + && getBaseMetaTileEntity().getUniversalEnergyStored() >= (mMode == 5 || mMode == 6 ? 128 : 2048) + && (getBaseMetaTileEntity().hasWorkJustBeenEnabled() || --mTicksUntilNextUpdate < 1)) { + mTicksUntilNextUpdate = 32; + + for (byte i = 19; i < 28; i++) { + if (mInventory[i] != null + && mInventory[i].isItemStackDamageable() + && mInventory[i].getItem().hasContainerItem()) { + mInventory[i].setItemDamage(OreDictionary.WILDCARD_VALUE); + } + } + + if (mInventory[18] == null) { + for (byte i = 0; i < 18 && mFluid != null; i++) { + ItemStack tOutput = GT_Utility.fillFluidContainer(mFluid, mInventory[i], false, true); + if (tOutput != null) { + for (byte j = 0; j < 9; j++) { + if (mInventory[j] == null + || (GT_Utility.areStacksEqual(tOutput, mInventory[j]) + && mInventory[j].stackSize + tOutput.stackSize + <= tOutput.getMaxStackSize())) { + mFluid.amount -= + GT_Utility.getFluidForFilledItem(tOutput, true).amount * tOutput.stackSize; + getBaseMetaTileEntity().decrStackSize(i, 1); + if (mInventory[j] == null) { + mInventory[j] = tOutput; + } else { + mInventory[j].stackSize++; + } + if (mFluid.amount <= 0) mFluid = null; + break; + } + } + } + } + + ItemStack[] tRecipe = new ItemStack[9]; + ItemStack tTempStack = null, tOutput = null; + + if (mInventory[17] != null && mThroughPut < 2 && mMode != 0) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[17]; + mInventory[17] = null; + } + } else { + if (!mLastCraftSuccessful) { + mCurrentSlot = (mCurrentSlot + 1) % 18; + for (int i = 0; i < 17 && mInventory[mCurrentSlot] == null; i++) + mCurrentSlot = (mCurrentSlot + 1) % 18; + } + switch (mMode) { + case 0: + if (mInventory[mCurrentSlot] != null + && !isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2 && mCurrentSlot < 8) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + for (int i = 0; i < 9; i++) { + tRecipe[i] = mInventory[i + 19]; + if (tRecipe[i] != null) { + tRecipe[i] = GT_Utility.copy(tRecipe[i]); + tRecipe[i].stackSize = 1; + } + } + break; + case 1: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + tRecipe[1] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + } else break; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + tRecipe[2] = tTempStack; + tRecipe[5] = tTempStack; + tRecipe[6] = tTempStack; + tRecipe[7] = tTempStack; + tRecipe[8] = tTempStack; + } else break; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + break; + case 2: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + break; + case 3: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + break; + case 4: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[2] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + tRecipe[5] = tTempStack; + tRecipe[6] = tTempStack; + tRecipe[7] = tTempStack; + tRecipe[8] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + break; + case 5: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + + tOutput = GT_OreDictUnificator.get(true, tTempStack); + + if (tOutput != null && GT_Utility.areStacksEqual(tOutput, tTempStack)) tOutput = null; + + if (tOutput == null) { + tRecipe[0] = null; + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + break; + case 6: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } else if (OrePrefixes.dustSmall.contains(mInventory[mCurrentSlot])) { + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + } else if (OrePrefixes.dustTiny.contains(mInventory[mCurrentSlot])) { + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[2] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + tRecipe[5] = tTempStack; + tRecipe[6] = tTempStack; + tRecipe[7] = tTempStack; + tRecipe[8] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + } else { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + break; + case 7: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot]) + || !OrePrefixes.nugget.contains(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[2] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + tRecipe[5] = tTempStack; + tRecipe[6] = tTempStack; + tRecipe[7] = tTempStack; + tRecipe[8] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + break; + case 8: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot]) + || mInventory[mCurrentSlot].getItemDamage() <= 0 + || !mInventory[mCurrentSlot].getItem().isRepairable()) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + for (int i = mCurrentSlot + 1; i < 18; i++) { + if (mInventory[i] != null + && mInventory[i].getItem() == tTempStack.getItem() + && mInventory[mCurrentSlot].getItemDamage() + mInventory[i].getItemDamage() + > tTempStack.getMaxDamage()) { + tRecipe[0] = tTempStack; + tRecipe[1] = GT_Utility.copy(mInventory[i]); + if (GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + break; + } + } + break; + case 9: + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + for (byte i = 0, j = 0; + i < 18 + && j < 9 + && (j < 2 + || GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity() + .getWorld(), + tRecipe) + == null); + i++) { + tRecipe[j] = mInventory[(mCurrentSlot + i) % 18]; + if (tRecipe[j] != null) { + tRecipe[j] = GT_Utility.copy(tRecipe[j]); + tRecipe[j].stackSize = 1; + j++; + } + } + if (tRecipe[1] == null) tRecipe[0] = null; + break; + } + } + + if (tOutput == null) + tOutput = GT_ModHandler.getAllRecipeOutput( + getBaseMetaTileEntity().getWorld(), tRecipe); + + if (tOutput != null || mMode == 0) mInventory[28] = tOutput; + + if (tOutput == null) { + mLastCraftSuccessful = false; + } else { + if ((tTempStack = GT_OreDictUnificator.get(true, tOutput)) != null) { + tTempStack.stackSize = tOutput.stackSize; + tOutput = tTempStack; + } + + mInventory[28] = GT_Utility.copy(tOutput); + ArrayList<ItemStack> tList = recipeContent(tRecipe), tContent = benchContent(); + if (tList.size() > 0 && tContent.size() > 0) { + + boolean success = (mMode == 6 || mMode == 7 || mInventory[17] == null); + for (byte i = 0; i < tList.size() && success; i++) { + success = false; + for (byte j = 0; j < tContent.size() && !success; j++) { + if (GT_Utility.areStacksEqual(tList.get(i), tContent.get(j))) { + if (tList.get(i).stackSize <= tContent.get(j).stackSize) { + success = true; + } + } + } + } + + if (success) { + mLastCraftSuccessful = true; + + for (byte i = 8; i > -1; i--) { + for (byte j = 17; j > -1; j--) { + if (tRecipe[i] != null && mInventory[j] != null) { + if (GT_Utility.areStacksEqual(tRecipe[i], mInventory[j])) { + ItemStack tStack = GT_Utility.getContainerItem(mInventory[j], true); + if (tStack != null) { + getBaseMetaTileEntity().decrStackSize(j, 1); + if (!tStack.isItemStackDamageable() + || tStack.getItemDamage() < tStack.getMaxDamage()) { + for (byte k = 9; k < 18; k++) { + if (mInventory[k] == null) { + mInventory[k] = GT_Utility.copy(tStack); + break; + } else if (GT_Utility.areStacksEqual(mInventory[k], tStack) + && mInventory[k].stackSize + tStack.stackSize + <= tStack.getMaxStackSize()) { + mInventory[k].stackSize += tStack.stackSize; + break; + } + } + } + } else { + getBaseMetaTileEntity().decrStackSize(j, 1); + } + break; + } + } + } + } + + mInventory[18] = GT_Utility.copy(tOutput); + getBaseMetaTileEntity() + .decreaseStoredEnergyUnits( + mMode == 5 || mMode == 6 || mMode == 7 ? 128 : 2048, true); + mTicksUntilNextUpdate = 1; + } else { + mLastCraftSuccessful = false; + if (mInventory[mMode == 0 ? 8 : 17] != null && mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mMode == 0 ? 8 : 17]; + mInventory[mMode == 0 ? 8 : 17] = null; + mTicksUntilNextUpdate = 1; + } + } + } + + if (mInventory[18] == null && mThroughPut < 2) { + for (byte i = 0; i < 8; i++) { + for (byte j = i; ++j < 9; ) { + if (GT_Utility.areStacksEqual(mInventory[i], mInventory[j]) + && mInventory[i].getMaxStackSize() > 8) { + mInventory[18] = mInventory[j]; + mInventory[j] = null; + mTicksUntilNextUpdate = 1; + break; + } + } + } + } + } + } + + if (mThroughPut < 2) { + getBaseMetaTileEntity() + .decreaseStoredEnergyUnits( + GT_Utility.moveOneItemStack( + getBaseMetaTileEntity(), + getBaseMetaTileEntity() + .getIInventoryAtSide(getBaseMetaTileEntity() + .getBackFacing()), + getBaseMetaTileEntity().getBackFacing(), + getBaseMetaTileEntity().getFrontFacing(), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1) + * 10, + true); + } + } + } + + private boolean isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(ItemStack aStack) { + if (aStack == null) return true; + for (byte i = 19; i < 28; i++) { + if (mInventory[i] != null) { + if (GT_Utility.areStacksEqual(mInventory[i], aStack)) return true; + if (GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(mInventory[i], true), aStack)) + return true; + } + } + return false; + } + + private ArrayList<ItemStack> recipeContent(ItemStack[] tRecipe) { + ArrayList<ItemStack> tList = new ArrayList<ItemStack>(); + for (byte i = 0; i < 9; i++) { + if (tRecipe[i] != null) { + boolean temp = false; + for (byte j = 0; j < tList.size(); j++) { + if (GT_Utility.areStacksEqual(tRecipe[i], tList.get(j))) { + tList.get(j).stackSize++; + temp = true; + break; + } + } + if (!temp) tList.add(GT_Utility.copy(1, tRecipe[i])); + } + } + return tList; + } + + private ArrayList<ItemStack> benchContent() { + ArrayList<ItemStack> tList = new ArrayList<ItemStack>(); + for (byte i = 0; i < 18; i++) { + if (mInventory[i] != null) { + boolean temp = false; + for (byte j = 0; j < tList.size(); j++) { + if (GT_Utility.areStacksEqual(mInventory[i], mInventory[j])) { + tList.get(j).stackSize += mInventory[i].stackSize; + temp = true; + break; + } + } + if (!temp) tList.add(GT_Utility.copy(mInventory[i])); + } + } + return tList; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return mMode == 0 ? aIndex >= 10 : aIndex >= 18; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return mMode == 0 ? aIndex < 9 : aIndex < 18; + } + + /*@Override + public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) + return 112; + if (GT_Utility.getOppositeSide(aSide) == aFacing) + return 113; + return 114; + }*/ + + @Override + public int getCapacity() { + return 16000; + } + + @Override + public int getTankPressure() { + return -100; + } + + @Override + public String[] getDescription() { + return new String[] { + "Automatic Crafting Table Mk III", + // this.mDescription, + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getBack(i); + rTextures[7][i + 1] = this.getBottom(i); + rTextures[8][i + 1] = this.getTop(i); + rTextures[9][i + 1] = this.getSides(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == aFacing) { + return this.mTextures[0][aColorIndex + 1]; + } else if (GT_Utility.getOppositeSide(aSide) == aFacing) { + return this.mTextures[1][aColorIndex + 1]; + } else { + return this.mTextures[4][aColorIndex + 1]; + } + /*return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1];*/ + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricInventoryManager.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricInventoryManager.java index 732996de71..ebce1fcec6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricInventoryManager.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricInventoryManager.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.automation; -import java.util.ArrayList; - import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -15,437 +13,591 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.automation.GT_Container_ElectricInventoryManager; import gtPlusPlus.xmod.gregtech.api.gui.automation.GT_GUIContainer_ElectricInventoryManager; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; public class GT_MetaTileEntity_ElectricInventoryManager extends GT_MetaTileEntity_TieredMachineBlock { - public int[] mSlotRange = new int[4]; - public boolean mWorkedLastTick = false; - protected String mLocalName; - - public GT_MetaTileEntity_ElectricInventoryManager(final int aID, final int aTier, final String aDescription) { - super(aID, "basicmachine.automation.inventorymanager.0" + aTier, "Electric Inventory Manager (" + GT_Values.VN[aTier] + ")", aTier, 16, aDescription); - mLocalName = "Auto Workbench (" + GT_Values.VN[aTier] + ")"; - } - - public GT_MetaTileEntity_ElectricInventoryManager(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, 16, aDescription, aTextures); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_ElectricInventoryManager(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_ElectricInventoryManager(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public boolean isTransformerUpgradable() { - return true; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public long maxEUInput() { - return GT_Values.V[mTier]; - } - - @Override - public long maxEUOutput() { - return GT_Values.V[mTier]; - } - - @Override - public long getMinimumStoredEU() { - return GT_Values.V[this.mTier]; - } - - @Override - public long maxEUStore() { - return GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier]); - } - - @Override - public long maxAmperesIn() { - return 4; - } - - @Override - public long maxAmperesOut() { - return 4; - } - - @Override - public boolean isValidSlot(int aIndex) { - return aIndex < 3; - } - - @Override - public boolean isInputFacing(byte aSide) { - return !isOutputFacing(aSide); - } - - @Override - public boolean isOutputFacing(byte aSide) { - for (int i = 0; i < mSlotRange.length; i++) { - if (aSide == getRangeDirection(i) && getRangeEnergy(i)) { - return true; - } - } - return false; - } - - @Override - public int getSizeInventory() { - return 16; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_ElectricInventoryManager(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mSlotRange0", mSlotRange[0]); - aNBT.setInteger("mSlotRange1", mSlotRange[1]); - aNBT.setInteger("mSlotRange2", mSlotRange[2]); - aNBT.setInteger("mSlotRange3", mSlotRange[3]); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mSlotRange[0] = aNBT.getInteger("mSlotRange0"); - mSlotRange[1] = aNBT.getInteger("mSlotRange1"); - mSlotRange[2] = aNBT.getInteger("mSlotRange2"); - mSlotRange[3] = aNBT.getInteger("mSlotRange3"); - } - - public void iterateRangeDirection(int aIndex) { - mSlotRange[aIndex] = (mSlotRange[aIndex] & ~7) | (((mSlotRange[aIndex] & 7) + 1) % 6); - } - - public void switchRangeEnergy(int aIndex) { - mSlotRange[aIndex] = (mSlotRange[aIndex] & ~8) | ((mSlotRange[aIndex] & 8) > 0 ? 0 : 8); - } - - public void iterateSlot1Direction(int aIndex) { - mSlotRange[aIndex] = (mSlotRange[aIndex] & ~112) | (((((mSlotRange[aIndex] & 112) >> 4) + 1) % 6) << 4); - } - - public void iterateSlot2Direction(int aIndex) { - mSlotRange[aIndex] = (mSlotRange[aIndex] & ~896) | (((((mSlotRange[aIndex] & 896) >> 7) + 1) % 6) << 7); - } - - public void iterateSlot3Direction(int aIndex) { - mSlotRange[aIndex] = (mSlotRange[aIndex] & ~7168) | (((((mSlotRange[aIndex] & 7168) >> 10) + 1) % 6) << 10); - } - - public void switchSlot1InOut(int aIndex) { - mSlotRange[aIndex] = (mSlotRange[aIndex] & ~8192) | ((mSlotRange[aIndex] & 8192) > 0 ? 0 : 8192); - } - - public void switchSlot2InOut(int aIndex) { - mSlotRange[aIndex] = (mSlotRange[aIndex] & ~16384) | ((mSlotRange[aIndex] & 16384) > 0 ? 0 : 16384); - } - - public void switchSlot3InOut(int aIndex) { - mSlotRange[aIndex] = (mSlotRange[aIndex] & ~32768) | ((mSlotRange[aIndex] & 32768) > 0 ? 0 : 32768); - } - - public byte getRangeDirection(int aIndex) { - return (byte) (mSlotRange[aIndex] & 7); - } - - public byte getSlot1Direction(int aIndex) { - return (byte) ((mSlotRange[aIndex] & 112) >> 4); - } - - public byte getSlot2Direction(int aIndex) { - return (byte) ((mSlotRange[aIndex] & 896) >> 7); - } - - public byte getSlot3Direction(int aIndex) { - return (byte) ((mSlotRange[aIndex] & 7168) >> 10); - } - - public boolean getRangeEnergy(int aIndex) { - return (mSlotRange[aIndex] & 8) > 0; - } - - public boolean getSlot1InOut(int aIndex) { - return (mSlotRange[aIndex] & 8192) > 0; - } - - public boolean getSlot2InOut(int aIndex) { - return (mSlotRange[aIndex] & 16384) > 0; - } - - public boolean getSlot3InOut(int aIndex) { - return (mSlotRange[aIndex] & 32768) > 0; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide() && getBaseMetaTileEntity().getUniversalEnergyStored() >= 5000 - && (getBaseMetaTileEntity().hasWorkJustBeenEnabled() || getBaseMetaTileEntity().getTimer() % 100 == 0 || mWorkedLastTick || getBaseMetaTileEntity().hasInventoryBeenModified())) { - mWorkedLastTick = false; - - IInventory[] tTileEntities = new IInventory[]{ - getBaseMetaTileEntity().getIInventoryAtSide((byte) 0), getBaseMetaTileEntity().getIInventoryAtSide((byte) 1), getBaseMetaTileEntity().getIInventoryAtSide((byte) 2), - getBaseMetaTileEntity().getIInventoryAtSide((byte) 3), getBaseMetaTileEntity().getIInventoryAtSide((byte) 4), getBaseMetaTileEntity().getIInventoryAtSide((byte) 5), null, null - }; - - int tCost = 0; - - for (int i = 0; i < 4; i++) { - if (tTileEntities[getRangeDirection(i)] != null) { - ArrayList<ItemStack> tList = new ArrayList<ItemStack>(); - ItemStack tStack; - tList.add(null); - - tStack = mInventory[3 + i * 3 + 0]; - if (tStack == null) { - if (getSlot1InOut(i)) - tCost += 5 - * GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), tTileEntities[getRangeDirection(i)], getSlot1Direction(i), getSlot1Direction(i), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - else - tCost += 5 - * GT_Utility.moveOneItemStack(tTileEntities[getRangeDirection(i)], getBaseMetaTileEntity(), getSlot1Direction(i), getSlot1Direction(i), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - else { - tList.set(0, tStack); - if (getSlot1InOut(i)) - tCost += 5 - * GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), tTileEntities[getRangeDirection(i)], getSlot1Direction(i), getSlot1Direction(i), tList, false, (byte) tStack.stackSize, (byte) 1, (byte) 64, (byte) 1); - else - tCost += 5 - * GT_Utility.moveOneItemStack(tTileEntities[getRangeDirection(i)], getBaseMetaTileEntity(), getSlot1Direction(i), getSlot1Direction(i), tList, false, (byte) tStack.stackSize, (byte) 1, (byte) 64, (byte) 1); - } - - tStack = mInventory[3 + i * 3 + 1]; - if (tStack == null) { - if (getSlot2InOut(i)) - tCost += 5 - * GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), tTileEntities[getRangeDirection(i)], getSlot2Direction(i), getSlot2Direction(i), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - else - tCost += 5 - * GT_Utility.moveOneItemStack(tTileEntities[getRangeDirection(i)], getBaseMetaTileEntity(), getSlot2Direction(i), getSlot2Direction(i), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - else { - tList.set(0, tStack); - if (getSlot2InOut(i)) - tCost += 5 - * GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), tTileEntities[getRangeDirection(i)], getSlot2Direction(i), getSlot2Direction(i), tList, false, (byte) tStack.stackSize, (byte) 1, (byte) 64, (byte) 1); - else - tCost += 5 - * GT_Utility.moveOneItemStack(tTileEntities[getRangeDirection(i)], getBaseMetaTileEntity(), getSlot2Direction(i), getSlot2Direction(i), tList, false, (byte) tStack.stackSize, (byte) 1, (byte) 64, (byte) 1); - } - - tStack = mInventory[3 + i * 3 + 2]; - if (tStack == null) { - if (getSlot3InOut(i)) - tCost += 5 - * GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), tTileEntities[getRangeDirection(i)], getSlot3Direction(i), getSlot3Direction(i), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - else - tCost += 5 - * GT_Utility.moveOneItemStack(tTileEntities[getRangeDirection(i)], getBaseMetaTileEntity(), getSlot3Direction(i), getSlot3Direction(i), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - else { - tList.set(0, tStack); - if (getSlot3InOut(i)) - tCost += 5 - * GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), tTileEntities[getRangeDirection(i)], getSlot3Direction(i), getSlot3Direction(i), tList, false, (byte) tStack.stackSize, (byte) 1, (byte) 64, (byte) 1); - else - tCost += 5 - * GT_Utility.moveOneItemStack(tTileEntities[getRangeDirection(i)], getBaseMetaTileEntity(), getSlot3Direction(i), getSlot3Direction(i), tList, false, (byte) tStack.stackSize, (byte) 1, (byte) 64, (byte) 1); - } - } - } - - if (tCost > 0) { - mWorkedLastTick = true; - getBaseMetaTileEntity().decreaseStoredEnergyUnits(tCost, true); - } - } - } - - @Override - public String[] getDescription() { - return new String[]{ - "It's simpler than you think. I promise.", this.mDescription, CORE.GT_Tooltip - }; - } - - /*@Override - public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { - switch (aSide) { - case 0: return 113 + (aRedstone?8:0); - case 1: return 112 + (aRedstone?8:0); - case 2: return 116 + (aRedstone?8:0); - case 3: return 213 + (aRedstone?8:0); - case 4: return 212 + (aRedstone?8:0); - case 5: return 117 + (aRedstone?8:0); - } - return 0; - }*/ - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - return false; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return true; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return true; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[16][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getBottom(i); - rTextures[1][i + 1] = this.getTop(i); - rTextures[2][i + 1] = this.getNegativeZ(i); - rTextures[3][i + 1] = this.getPositiveZ(i); - rTextures[4][i + 1] = this.getNegativeX(i); - rTextures[5][i + 1] = this.getPositiveX(i); - rTextures[6][i + 1] = this.getBottomRedstone(i); - rTextures[7][i + 1] = this.getTopRedstone(i); - rTextures[8][i + 1] = this.getNegativeZRedstone(i); - rTextures[9][i + 1] = this.getPositiveZRedstone(i); - rTextures[10][i + 1] = this.getNegativeXRedstone(i); - rTextures[11][i + 1] = this.getPositiveXRedstone(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[!aRedstone ? aSide : aSide + 6][aColorIndex < 0 ? 0 : aColorIndex]; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red) - }; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Green) - }; - } - - public ITexture[] getNegativeZ(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Blue) - }; - } - - public ITexture[] getPositiveZ(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Cyan) - }; - } - - public ITexture[] getNegativeX(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Purple) - }; - } - - public ITexture[] getPositiveX(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Yellow) - }; - } - - public ITexture[] getBottomRedstone(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red_Redstone) - }; - } - - public ITexture[] getTopRedstone(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Green_Redstone) - }; - } - - public ITexture[] getNegativeZRedstone(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Blue_Redstone) - }; - } - - public ITexture[] getPositiveZRedstone(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Cyan_Redstone) - }; - } - - public ITexture[] getNegativeXRedstone(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Purple_Redstone) - }; - } - - public ITexture[] getPositiveXRedstone(final byte aColor) { - return new ITexture[]{ - Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Yellow_Redstone) - }; - } - + public int[] mSlotRange = new int[4]; + public boolean mWorkedLastTick = false; + protected String mLocalName; + + public GT_MetaTileEntity_ElectricInventoryManager(final int aID, final int aTier, final String aDescription) { + super( + aID, + "basicmachine.automation.inventorymanager.0" + aTier, + "Electric Inventory Manager (" + GT_Values.VN[aTier] + ")", + aTier, + 16, + aDescription); + mLocalName = "Auto Workbench (" + GT_Values.VN[aTier] + ")"; + } + + public GT_MetaTileEntity_ElectricInventoryManager( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 16, aDescription, aTextures); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_ElectricInventoryManager(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_ElectricInventoryManager(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public long maxEUInput() { + return GT_Values.V[mTier]; + } + + @Override + public long maxEUOutput() { + return GT_Values.V[mTier]; + } + + @Override + public long getMinimumStoredEU() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUStore() { + return GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier]); + } + + @Override + public long maxAmperesIn() { + return 4; + } + + @Override + public long maxAmperesOut() { + return 4; + } + + @Override + public boolean isValidSlot(int aIndex) { + return aIndex < 3; + } + + @Override + public boolean isInputFacing(byte aSide) { + return !isOutputFacing(aSide); + } + + @Override + public boolean isOutputFacing(byte aSide) { + for (int i = 0; i < mSlotRange.length; i++) { + if (aSide == getRangeDirection(i) && getRangeEnergy(i)) { + return true; + } + } + return false; + } + + @Override + public int getSizeInventory() { + return 16; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_ElectricInventoryManager( + this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mSlotRange0", mSlotRange[0]); + aNBT.setInteger("mSlotRange1", mSlotRange[1]); + aNBT.setInteger("mSlotRange2", mSlotRange[2]); + aNBT.setInteger("mSlotRange3", mSlotRange[3]); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mSlotRange[0] = aNBT.getInteger("mSlotRange0"); + mSlotRange[1] = aNBT.getInteger("mSlotRange1"); + mSlotRange[2] = aNBT.getInteger("mSlotRange2"); + mSlotRange[3] = aNBT.getInteger("mSlotRange3"); + } + + public void iterateRangeDirection(int aIndex) { + mSlotRange[aIndex] = (mSlotRange[aIndex] & ~7) | (((mSlotRange[aIndex] & 7) + 1) % 6); + } + + public void switchRangeEnergy(int aIndex) { + mSlotRange[aIndex] = (mSlotRange[aIndex] & ~8) | ((mSlotRange[aIndex] & 8) > 0 ? 0 : 8); + } + + public void iterateSlot1Direction(int aIndex) { + mSlotRange[aIndex] = (mSlotRange[aIndex] & ~112) | (((((mSlotRange[aIndex] & 112) >> 4) + 1) % 6) << 4); + } + + public void iterateSlot2Direction(int aIndex) { + mSlotRange[aIndex] = (mSlotRange[aIndex] & ~896) | (((((mSlotRange[aIndex] & 896) >> 7) + 1) % 6) << 7); + } + + public void iterateSlot3Direction(int aIndex) { + mSlotRange[aIndex] = (mSlotRange[aIndex] & ~7168) | (((((mSlotRange[aIndex] & 7168) >> 10) + 1) % 6) << 10); + } + + public void switchSlot1InOut(int aIndex) { + mSlotRange[aIndex] = (mSlotRange[aIndex] & ~8192) | ((mSlotRange[aIndex] & 8192) > 0 ? 0 : 8192); + } + + public void switchSlot2InOut(int aIndex) { + mSlotRange[aIndex] = (mSlotRange[aIndex] & ~16384) | ((mSlotRange[aIndex] & 16384) > 0 ? 0 : 16384); + } + + public void switchSlot3InOut(int aIndex) { + mSlotRange[aIndex] = (mSlotRange[aIndex] & ~32768) | ((mSlotRange[aIndex] & 32768) > 0 ? 0 : 32768); + } + + public byte getRangeDirection(int aIndex) { + return (byte) (mSlotRange[aIndex] & 7); + } + + public byte getSlot1Direction(int aIndex) { + return (byte) ((mSlotRange[aIndex] & 112) >> 4); + } + + public byte getSlot2Direction(int aIndex) { + return (byte) ((mSlotRange[aIndex] & 896) >> 7); + } + + public byte getSlot3Direction(int aIndex) { + return (byte) ((mSlotRange[aIndex] & 7168) >> 10); + } + + public boolean getRangeEnergy(int aIndex) { + return (mSlotRange[aIndex] & 8) > 0; + } + + public boolean getSlot1InOut(int aIndex) { + return (mSlotRange[aIndex] & 8192) > 0; + } + + public boolean getSlot2InOut(int aIndex) { + return (mSlotRange[aIndex] & 16384) > 0; + } + + public boolean getSlot3InOut(int aIndex) { + return (mSlotRange[aIndex] & 32768) > 0; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (getBaseMetaTileEntity().isAllowedToWork() + && getBaseMetaTileEntity().isServerSide() + && getBaseMetaTileEntity().getUniversalEnergyStored() >= 5000 + && (getBaseMetaTileEntity().hasWorkJustBeenEnabled() + || getBaseMetaTileEntity().getTimer() % 100 == 0 + || mWorkedLastTick + || getBaseMetaTileEntity().hasInventoryBeenModified())) { + mWorkedLastTick = false; + + IInventory[] tTileEntities = new IInventory[] { + getBaseMetaTileEntity().getIInventoryAtSide((byte) 0), + getBaseMetaTileEntity().getIInventoryAtSide((byte) 1), + getBaseMetaTileEntity().getIInventoryAtSide((byte) 2), + getBaseMetaTileEntity().getIInventoryAtSide((byte) 3), + getBaseMetaTileEntity().getIInventoryAtSide((byte) 4), + getBaseMetaTileEntity().getIInventoryAtSide((byte) 5), + null, + null + }; + + int tCost = 0; + + for (int i = 0; i < 4; i++) { + if (tTileEntities[getRangeDirection(i)] != null) { + ArrayList<ItemStack> tList = new ArrayList<ItemStack>(); + ItemStack tStack; + tList.add(null); + + tStack = mInventory[3 + i * 3 + 0]; + if (tStack == null) { + if (getSlot1InOut(i)) + tCost += 5 + * GT_Utility.moveOneItemStack( + getBaseMetaTileEntity(), + tTileEntities[getRangeDirection(i)], + getSlot1Direction(i), + getSlot1Direction(i), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + else + tCost += 5 + * GT_Utility.moveOneItemStack( + tTileEntities[getRangeDirection(i)], + getBaseMetaTileEntity(), + getSlot1Direction(i), + getSlot1Direction(i), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } else { + tList.set(0, tStack); + if (getSlot1InOut(i)) + tCost += 5 + * GT_Utility.moveOneItemStack( + getBaseMetaTileEntity(), + tTileEntities[getRangeDirection(i)], + getSlot1Direction(i), + getSlot1Direction(i), + tList, + false, + (byte) tStack.stackSize, + (byte) 1, + (byte) 64, + (byte) 1); + else + tCost += 5 + * GT_Utility.moveOneItemStack( + tTileEntities[getRangeDirection(i)], + getBaseMetaTileEntity(), + getSlot1Direction(i), + getSlot1Direction(i), + tList, + false, + (byte) tStack.stackSize, + (byte) 1, + (byte) 64, + (byte) 1); + } + + tStack = mInventory[3 + i * 3 + 1]; + if (tStack == null) { + if (getSlot2InOut(i)) + tCost += 5 + * GT_Utility.moveOneItemStack( + getBaseMetaTileEntity(), + tTileEntities[getRangeDirection(i)], + getSlot2Direction(i), + getSlot2Direction(i), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + else + tCost += 5 + * GT_Utility.moveOneItemStack( + tTileEntities[getRangeDirection(i)], + getBaseMetaTileEntity(), + getSlot2Direction(i), + getSlot2Direction(i), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } else { + tList.set(0, tStack); + if (getSlot2InOut(i)) + tCost += 5 + * GT_Utility.moveOneItemStack( + getBaseMetaTileEntity(), + tTileEntities[getRangeDirection(i)], + getSlot2Direction(i), + getSlot2Direction(i), + tList, + false, + (byte) tStack.stackSize, + (byte) 1, + (byte) 64, + (byte) 1); + else + tCost += 5 + * GT_Utility.moveOneItemStack( + tTileEntities[getRangeDirection(i)], + getBaseMetaTileEntity(), + getSlot2Direction(i), + getSlot2Direction(i), + tList, + false, + (byte) tStack.stackSize, + (byte) 1, + (byte) 64, + (byte) 1); + } + + tStack = mInventory[3 + i * 3 + 2]; + if (tStack == null) { + if (getSlot3InOut(i)) + tCost += 5 + * GT_Utility.moveOneItemStack( + getBaseMetaTileEntity(), + tTileEntities[getRangeDirection(i)], + getSlot3Direction(i), + getSlot3Direction(i), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + else + tCost += 5 + * GT_Utility.moveOneItemStack( + tTileEntities[getRangeDirection(i)], + getBaseMetaTileEntity(), + getSlot3Direction(i), + getSlot3Direction(i), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } else { + tList.set(0, tStack); + if (getSlot3InOut(i)) + tCost += 5 + * GT_Utility.moveOneItemStack( + getBaseMetaTileEntity(), + tTileEntities[getRangeDirection(i)], + getSlot3Direction(i), + getSlot3Direction(i), + tList, + false, + (byte) tStack.stackSize, + (byte) 1, + (byte) 64, + (byte) 1); + else + tCost += 5 + * GT_Utility.moveOneItemStack( + tTileEntities[getRangeDirection(i)], + getBaseMetaTileEntity(), + getSlot3Direction(i), + getSlot3Direction(i), + tList, + false, + (byte) tStack.stackSize, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + } + + if (tCost > 0) { + mWorkedLastTick = true; + getBaseMetaTileEntity().decreaseStoredEnergyUnits(tCost, true); + } + } + } + + @Override + public String[] getDescription() { + return new String[] {"It's simpler than you think. I promise.", this.mDescription, CORE.GT_Tooltip}; + } + + /*@Override + public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { + switch (aSide) { + case 0: return 113 + (aRedstone?8:0); + case 1: return 112 + (aRedstone?8:0); + case 2: return 116 + (aRedstone?8:0); + case 3: return 213 + (aRedstone?8:0); + case 4: return 212 + (aRedstone?8:0); + case 5: return 117 + (aRedstone?8:0); + } + return 0; + }*/ + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return false; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return true; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return true; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[16][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getBottom(i); + rTextures[1][i + 1] = this.getTop(i); + rTextures[2][i + 1] = this.getNegativeZ(i); + rTextures[3][i + 1] = this.getPositiveZ(i); + rTextures[4][i + 1] = this.getNegativeX(i); + rTextures[5][i + 1] = this.getPositiveX(i); + rTextures[6][i + 1] = this.getBottomRedstone(i); + rTextures[7][i + 1] = this.getTopRedstone(i); + rTextures[8][i + 1] = this.getNegativeZRedstone(i); + rTextures[9][i + 1] = this.getPositiveZRedstone(i); + rTextures[10][i + 1] = this.getNegativeXRedstone(i); + rTextures[11][i + 1] = this.getPositiveXRedstone(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[!aRedstone ? aSide : aSide + 6][aColorIndex < 0 ? 0 : aColorIndex]; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red) + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Green) + }; + } + + public ITexture[] getNegativeZ(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Blue) + }; + } + + public ITexture[] getPositiveZ(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Cyan) + }; + } + + public ITexture[] getNegativeX(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Purple) + }; + } + + public ITexture[] getPositiveX(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Yellow) + }; + } + + public ITexture[] getBottomRedstone(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red_Redstone) + }; + } + + public ITexture[] getTopRedstone(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Green_Redstone) + }; + } + + public ITexture[] getNegativeZRedstone(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Blue_Redstone) + }; + } + + public ITexture[] getPositiveZRedstone(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Cyan_Redstone) + }; + } + + public ITexture[] getNegativeXRedstone(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Purple_Redstone) + }; + } + + public ITexture[] getPositiveXRedstone(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Yellow_Redstone) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractGenerator.java index 9c856840b0..b990e3c55e 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractGenerator.java @@ -2,17 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.automation; import static gtPlusPlus.core.lib.CORE.*; -import java.util.UUID; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IDigitalChest; @@ -23,708 +12,752 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Config; import gregtech.api.util.GT_Utility; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.helpers.tesseract.TesseractHelper; +import java.util.UUID; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.*; public class GT_MetaTileEntity_TesseractGenerator extends GT_MetaTileEntity_BasicTank { - public static int TESSERACT_ENERGY_COST_DIMENSIONAL = 512; - public static int TESSERACT_ENERGY_COST = 128; - public byte isWorking = 0; - public int oFrequency = 0; - public int mNeededEnergy = 0; - public int mFrequency = 0; - public UUID mOwner; - - public GT_MetaTileEntity_TesseractGenerator(final int aID, final String aName, final String aNameRegional, - final int aTier) { - super(aID, aName, aNameRegional, aTier, 3, ""); - } - - public GT_MetaTileEntity_TesseractGenerator(final String aName, final int aTier, final String aDescription, - final ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_TesseractGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public boolean isTransformerUpgradable() { - return true; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isFacingValid(final byte aFacing) { - return true; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isEnetOutput() { - return false; - } - - @Override - public boolean isInputFacing(final byte aSide) { - return true; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide == this.getBaseMetaTileEntity().getBackFacing(); - } - - @Override - public boolean isValidSlot(final int aIndex) { - return false; - } - - @Override - public long getMinimumStoredEU() { - return this.getBaseMetaTileEntity().getEUCapacity() / 2; - } - - @Override - public long maxEUInput() { - return 512; - } - - @Override - public long maxEUOutput() { - return 0; - } - - @Override - public long maxEUStore() { - return 512 * 32; - } - - @Override - public long maxSteamStore() { - return this.maxEUStore(); - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean ownerControl() { - return true; - } - - @Override - public int getProgresstime() { - return (TesseractHelper.getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), - this.mFrequency) == this) && (this.isWorking >= 20) ? 999 : 0; - } - - @Override - public int maxProgresstime() { - return 1000; - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setInteger("mFrequency", this.mFrequency); - if (mOwner != null) - aNBT.setString("mOwner", mOwner.toString()); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.mFrequency = aNBT.getInteger("mFrequency"); - try { - this.mOwner = UUID.fromString(aNBT.getString("mOnwer")); - } - catch (IllegalArgumentException i){ - - } - } - - @Override - public void onConfigLoad(final GT_Config aConfig) { - int J = 1; - if (CORE.GTNH) { - J = 4; - } - TESSERACT_ENERGY_COST = 128*J; - TESSERACT_ENERGY_COST_DIMENSIONAL = 512*J; - } - - @Override - public void onServerStart() { - sTesseractGeneratorOwnershipMap.clear(); - sTesseractTerminalOwnershipMap.clear(); - } - - public void onServerStop() { - sTesseractGeneratorOwnershipMap.clear(); - sTesseractTerminalOwnershipMap.clear(); - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer, - final byte aSide, final float aX, final float aY, final float aZ) { - - if (this.mOwner == null) { - if (this.getBaseMetaTileEntity().getOwnerName() != null - && !this.getBaseMetaTileEntity().getOwnerName().equals("")) { - if (this.getBaseMetaTileEntity().getOwnerName().toLowerCase() - .equals(aPlayer.getDisplayName().toLowerCase())) { - this.mOwner = PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); - } - } - } - - if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { - if (aPlayer.getUniqueID().compareTo(this.mOwner) == 0) { - final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); - switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { - case 0: - Logger.WARNING("Freq. -1 | " + this.mFrequency); - try { - CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency -= 1; - - break; - case 1: - Logger.WARNING("Freq. +1 | " + this.mFrequency); - try { - CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency += 1; - default: - // Utils.LOG_WARNING("Did not click the correct place."); - break; - } - if (getGeneratorEntity(this.mFrequency) != null && getGeneratorEntity(this.mFrequency) != this){ - GT_Utility.sendChatToPlayer(aPlayer, "Frequency: " + this.mFrequency + EnumChatFormatting.RED + " (Occupied)"); - } - else { - GT_Utility.sendChatToPlayer(aPlayer, "Frequency: " + this.mFrequency); - } - } else if (aPlayer.getUniqueID().compareTo(this.mOwner) != 0){ - GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Generator to configure."); - } - } - - return true; - } - - @Override - public void onScrewdriverRightClick(final byte aSide, final EntityPlayer aPlayer, final float aX, final float aY, - final float aZ) { - if (aPlayer.getUniqueID().compareTo(this.mOwner) == 0) { - if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { - final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); - switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { - case 0: - try { - CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency -= 64; - break; - case 1: - try { - CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency += 64; - break; - case 2: - try { - CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency -= 512; - break; - case 3: - try { - CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency += 512; - } - if (getGeneratorEntity(this.mFrequency) != null && getGeneratorEntity(this.mFrequency) != this){ - GT_Utility.sendChatToPlayer(aPlayer, "Frequency: " + this.mFrequency + EnumChatFormatting.RED + " (Occupied)"); - } - else { - GT_Utility.sendChatToPlayer(aPlayer, "Frequency: " + this.mFrequency); - } - } - } else { - GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Generator to configure."); - } - } - - public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { - return aSide != this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public String[] getInfoData() { - final TileEntity tTileEntity = this.getBaseMetaTileEntity() - .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity != null) && (this.getBaseMetaTileEntity().isAllowedToWork()) - && ((tTileEntity instanceof IGregTechDeviceInformation)) - && (((IGregTechDeviceInformation) tTileEntity).isGivingInformation())) { - return ((IGregTechDeviceInformation) tTileEntity).getInfoData(); - } - return new String[] { "Tesseract Generator", "Freqency:", "" + this.mFrequency, - (getGeneratorEntity() == this) && (this.isWorking >= 20) ? "Active" : "Inactive" }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - public boolean isSendingInformation() { - final TileEntity tTileEntity = this.getBaseMetaTileEntity() - .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity != null) && (this.getBaseMetaTileEntity().isAllowedToWork()) - && ((tTileEntity instanceof IGregTechDeviceInformation))) { - return ((IGregTechDeviceInformation) tTileEntity).isGivingInformation(); - } - return false; - } - - @Override - public boolean isDigitalChest() { - final TileEntity tTileEntity = this.getBaseMetaTileEntity() - .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity != null) && (this.getBaseMetaTileEntity().isAllowedToWork()) - && ((tTileEntity instanceof IDigitalChest))) { - return ((IDigitalChest) tTileEntity).isDigitalChest(); - } - return false; - } - - @Override - public ItemStack[] getStoredItemData() { - final TileEntity tTileEntity = this.getBaseMetaTileEntity() - .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity != null) && (this.getBaseMetaTileEntity().isAllowedToWork()) - && ((tTileEntity instanceof IDigitalChest))) { - return ((IDigitalChest) tTileEntity).getStoredItemData(); - } - return new ItemStack[] {}; - } - - @Override - public void setItemCount(final int aCount) { - final TileEntity tTileEntity = this.getBaseMetaTileEntity() - .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity != null) && (this.getBaseMetaTileEntity().isAllowedToWork()) - && ((tTileEntity instanceof IDigitalChest))) { - ((IDigitalChest) tTileEntity).setItemCount(aCount); - } - } - - @Override - public int getMaxItemCount() { - final TileEntity tTileEntity = this.getBaseMetaTileEntity() - .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity != null) && (this.getBaseMetaTileEntity().isAllowedToWork()) - && ((tTileEntity instanceof IDigitalChest))) { - return ((IDigitalChest) tTileEntity).getMaxItemCount(); - } - return 0; - } - - @Override - public boolean isItemValidForSlot(final int aIndex, final ItemStack aStack) { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.isItemValidForSlot(aIndex, aStack); - } - - @Override - public int[] getAccessibleSlotsFromSide(final int aSide) { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return new int[0]; - } - if ((tTileEntity instanceof ISidedInventory)) { - return ((ISidedInventory) tTileEntity).getAccessibleSlotsFromSide(aSide); - } - final int[] rArray = new int[this.getSizeInventory()]; - for (int i = 0; i < this.getSizeInventory(); i++) { - rArray[i] = i; - } - return rArray; - } - - @Override - public boolean canInsertItem(final int aIndex, final ItemStack aStack, final int aSide) { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - if ((tTileEntity instanceof ISidedInventory)) { - return ((ISidedInventory) tTileEntity).canInsertItem(aIndex, aStack, aSide); - } - return true; - } - - @Override - public boolean canExtractItem(final int aIndex, final ItemStack aStack, final int aSide) { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - if ((tTileEntity instanceof ISidedInventory)) { - return ((ISidedInventory) tTileEntity).canExtractItem(aIndex, aStack, aSide); - } - return true; - } - - @Override - public int getSizeInventory() { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return 0; - } - return tTileEntity.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(final int aIndex) { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.getStackInSlot(aIndex); - } - - @Override - public void setInventorySlotContents(final int aIndex, final ItemStack aStack) { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return; - } - tTileEntity.setInventorySlotContents(aIndex, aStack); - } - - @Override - public ItemStack decrStackSize(final int aIndex, final int aAmount) { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.decrStackSize(aIndex, aAmount); - } - - @Override - public String getInventoryName() { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return ""; - } - return tTileEntity.getInventoryName(); - } - - @Override - public int getInventoryStackLimit() { - final IInventory tTileEntity = this.getBaseMetaTileEntity() - .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return 0; - } - return tTileEntity.getInventoryStackLimit(); - } - - @Override - public boolean canFill(final ForgeDirection aSide, final Fluid aFluid) { - final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() - .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.canFill(aSide, aFluid); - } - - @Override - public boolean canDrain(final ForgeDirection aSide, final Fluid aFluid) { - final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() - .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.canDrain(aSide, aFluid); - } - - @Override - public FluidTankInfo[] getTankInfo(final ForgeDirection aSide) { - final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() - .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return new FluidTankInfo[0]; - } - return tTileEntity.getTankInfo(aSide); - } - - @Override - public int fill_default(final ForgeDirection aDirection, final FluidStack aFluid, final boolean doFill) { - final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() - .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return 0; - } - return tTileEntity.fill(aDirection, aFluid, doFill); - } - - @Override - public FluidStack drain(final ForgeDirection aDirection, final int maxDrain, final boolean doDrain) { - final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() - .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.drain(aDirection, maxDrain, doDrain); - } - - @Override - public FluidStack drain(final ForgeDirection aSide, final FluidStack aFluid, final boolean doDrain) { - final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() - .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.drain(aSide, aFluid, doDrain); - } - - public boolean addEnergyConsumption(final GT_MetaTileEntity_TesseractTerminal aTerminal) { - if (!this.getBaseMetaTileEntity().isAllowedToWork()) { - return false; - } - int J = (aTerminal.getBaseMetaTileEntity().getWorld() == this.getBaseMetaTileEntity().getWorld() - ? TESSERACT_ENERGY_COST : TESSERACT_ENERGY_COST_DIMENSIONAL); - - if (CORE.GTNH) { - J *= 4; - } - - this.mNeededEnergy += J; - - return true; - } - - public boolean isValidTesseractGenerator(final String aOwnerName, final boolean aWorkIrrelevant) { - return (this.getBaseMetaTileEntity() != null) && (!this.getBaseMetaTileEntity().isInvalidTileEntity()) - && (this.getBaseMetaTileEntity().isAllowedToWork()) - && ((aOwnerName == null) || (this.getBaseMetaTileEntity().getOwnerName().equals(aOwnerName))) - && ((aWorkIrrelevant) || (this.isWorking >= 20)); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - // TODO Auto-generated method stub - super.onPreTick(aBaseMetaTileEntity, aTick); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - //Utils.LOG_WARNING("Ticking Generator. 0"); - if (this.getBaseMetaTileEntity().isServerSide()) { - //Utils.LOG_WARNING("Ticking Generator."); - // Set owner - if (PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()) != null) { - if (this.mOwner == null) { - Logger.WARNING("Setting Generators Owner. 1"); - this.mOwner = PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); - } - } - - if (this.mFrequency != this.oFrequency) { - - Logger.WARNING("mFreq != oFreq"); - - if (getGeneratorEntity() == this) { - getGeneratorEntity(this.oFrequency); - this.getBaseMetaTileEntity().issueBlockUpdate(); - Logger.WARNING("this Gen == oFreq on map - do block update"); - } - Logger.WARNING("mFreq will be set to oFreq"); - this.oFrequency = this.mFrequency; - } - if ((this.getBaseMetaTileEntity().isAllowedToWork()) - && (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(this.mNeededEnergy, false))) { - //Utils.LOG_WARNING("Can Work & Has Energy"); - if ((getGeneratorEntity(Integer.valueOf(this.mFrequency)) == null) - || (!getGeneratorEntity(Integer.valueOf(this.mFrequency)).isValidTesseractGenerator(null, - true))) { - //Utils.LOG_WARNING("storing TE I think to mFreq map?"); - TesseractHelper.setGeneratorOwnershipByPlayer(PlayerUtils.getPlayerOnServerFromUUID(mOwner), - this.mFrequency, this); - } - } else { - if (getGeneratorEntity(Integer.valueOf(this.mFrequency)) == this) { - Logger.WARNING("this gen == mFreq on map - do block update"); - TesseractHelper.removeGenerator(PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency); - this.getBaseMetaTileEntity().issueBlockUpdate(); - } - this.isWorking = 0; - } - if (getGeneratorEntity(Integer.valueOf(this.mFrequency)) == this) { - //Utils.LOG_WARNING("mFreq == this - do work related things"); - if (this.isWorking < 20) { - this.isWorking = ((byte) (this.isWorking + 1)); - } - if (this.isWorking == 20) { - this.getBaseMetaTileEntity().issueBlockUpdate(); - this.isWorking = ((byte) (this.isWorking + 1)); - } - } else { - this.isWorking = 0; - } - this.mNeededEnergy = 0; - } - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override - public String[] getDescription() { - return new String[] { this.mDescription, - "Generates a Tesseract for the attached Inventory", - "Connect with pipes to insert items", - "Consumes "+TESSERACT_ENERGY_COST+"EU/t for same dimension transfers", - "Consumes "+TESSERACT_ENERGY_COST_DIMENSIONAL+"EU/t for cross dimensional transfers", - CORE.GT_Tooltip}; - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - return false; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - return new ITexture[0][0][0]; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return aSide == aFacing - ? new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), - new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) } - : new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), - new GT_RenderedTexture(Textures.BlockIcons.VOID) }; - } - - // To-Do? - @Override - public boolean doesFillContainers() { - return false; - } - - @Override - public boolean doesEmptyContainers() { - return false; - } - - @Override - public boolean canTankBeFilled() { - return false; - } - - @Override - public boolean canTankBeEmptied() { - return false; - } - - @Override - public boolean displaysItemStack() { - return false; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - private GT_MetaTileEntity_TesseractGenerator getGeneratorEntity() { - GT_MetaTileEntity_TesseractGenerator thisGenerator = TesseractHelper - .getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency); - if (thisGenerator != null) { - return thisGenerator; - } - return null; - } - - private GT_MetaTileEntity_TesseractGenerator getGeneratorEntity(int frequency) { - GT_MetaTileEntity_TesseractGenerator thisGenerator = TesseractHelper - .getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), frequency); - if (thisGenerator != null) { - return thisGenerator; - } - return null; - } - - @Override - public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { - if (this.getBaseMetaTileEntity().getOwnerName() != null - && !this.getBaseMetaTileEntity().getOwnerName().equals("")) { - this.mOwner = PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); - Logger.WARNING("Setting Generators Owner. 2"); - } - super.onCreated(aStack, aWorld, aPlayer); - } - - @Override - public void onRemoval() { - try { - CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - super.onRemoval(); - } + public static int TESSERACT_ENERGY_COST_DIMENSIONAL = 512; + public static int TESSERACT_ENERGY_COST = 128; + public byte isWorking = 0; + public int oFrequency = 0; + public int mNeededEnergy = 0; + public int mFrequency = 0; + public UUID mOwner; + + public GT_MetaTileEntity_TesseractGenerator( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier, 3, ""); + } + + public GT_MetaTileEntity_TesseractGenerator( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TesseractGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return true; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public long getMinimumStoredEU() { + return this.getBaseMetaTileEntity().getEUCapacity() / 2; + } + + @Override + public long maxEUInput() { + return 512; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxEUStore() { + return 512 * 32; + } + + @Override + public long maxSteamStore() { + return this.maxEUStore(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean ownerControl() { + return true; + } + + @Override + public int getProgresstime() { + return (TesseractHelper.getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency) + == this) + && (this.isWorking >= 20) + ? 999 + : 0; + } + + @Override + public int maxProgresstime() { + return 1000; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mFrequency", this.mFrequency); + if (mOwner != null) aNBT.setString("mOwner", mOwner.toString()); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mFrequency = aNBT.getInteger("mFrequency"); + try { + this.mOwner = UUID.fromString(aNBT.getString("mOnwer")); + } catch (IllegalArgumentException i) { + + } + } + + @Override + public void onConfigLoad(final GT_Config aConfig) { + int J = 1; + if (CORE.GTNH) { + J = 4; + } + TESSERACT_ENERGY_COST = 128 * J; + TESSERACT_ENERGY_COST_DIMENSIONAL = 512 * J; + } + + @Override + public void onServerStart() { + sTesseractGeneratorOwnershipMap.clear(); + sTesseractTerminalOwnershipMap.clear(); + } + + public void onServerStop() { + sTesseractGeneratorOwnershipMap.clear(); + sTesseractTerminalOwnershipMap.clear(); + } + + @Override + public boolean onRightclick( + final IGregTechTileEntity aBaseMetaTileEntity, + final EntityPlayer aPlayer, + final byte aSide, + final float aX, + final float aY, + final float aZ) { + + if (this.mOwner == null) { + if (this.getBaseMetaTileEntity().getOwnerName() != null + && !this.getBaseMetaTileEntity().getOwnerName().equals("")) { + if (this.getBaseMetaTileEntity() + .getOwnerName() + .toLowerCase() + .equals(aPlayer.getDisplayName().toLowerCase())) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity().getOwnerName()); + } + } + } + + if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { + if (aPlayer.getUniqueID().compareTo(this.mOwner) == 0) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0: + Logger.WARNING("Freq. -1 | " + this.mFrequency); + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency -= 1; + + break; + case 1: + Logger.WARNING("Freq. +1 | " + this.mFrequency); + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency += 1; + default: + // Utils.LOG_WARNING("Did not click the correct place."); + break; + } + if (getGeneratorEntity(this.mFrequency) != null && getGeneratorEntity(this.mFrequency) != this) { + GT_Utility.sendChatToPlayer( + aPlayer, "Frequency: " + this.mFrequency + EnumChatFormatting.RED + " (Occupied)"); + } else { + GT_Utility.sendChatToPlayer(aPlayer, "Frequency: " + this.mFrequency); + } + } else if (aPlayer.getUniqueID().compareTo(this.mOwner) != 0) { + GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Generator to configure."); + } + } + + return true; + } + + @Override + public void onScrewdriverRightClick( + final byte aSide, final EntityPlayer aPlayer, final float aX, final float aY, final float aZ) { + if (aPlayer.getUniqueID().compareTo(this.mOwner) == 0) { + if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0: + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency -= 64; + break; + case 1: + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency += 64; + break; + case 2: + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency -= 512; + break; + case 3: + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency += 512; + } + if (getGeneratorEntity(this.mFrequency) != null && getGeneratorEntity(this.mFrequency) != this) { + GT_Utility.sendChatToPlayer( + aPlayer, "Frequency: " + this.mFrequency + EnumChatFormatting.RED + " (Occupied)"); + } else { + GT_Utility.sendChatToPlayer(aPlayer, "Frequency: " + this.mFrequency); + } + } + } else { + GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Generator to configure."); + } + } + + public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public String[] getInfoData() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity != null) + && (this.getBaseMetaTileEntity().isAllowedToWork()) + && ((tTileEntity instanceof IGregTechDeviceInformation)) + && (((IGregTechDeviceInformation) tTileEntity).isGivingInformation())) { + return ((IGregTechDeviceInformation) tTileEntity).getInfoData(); + } + return new String[] { + "Tesseract Generator", + "Freqency:", + "" + this.mFrequency, + (getGeneratorEntity() == this) && (this.isWorking >= 20) ? "Active" : "Inactive" + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + public boolean isSendingInformation() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity != null) + && (this.getBaseMetaTileEntity().isAllowedToWork()) + && ((tTileEntity instanceof IGregTechDeviceInformation))) { + return ((IGregTechDeviceInformation) tTileEntity).isGivingInformation(); + } + return false; + } + + @Override + public boolean isDigitalChest() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity != null) + && (this.getBaseMetaTileEntity().isAllowedToWork()) + && ((tTileEntity instanceof IDigitalChest))) { + return ((IDigitalChest) tTileEntity).isDigitalChest(); + } + return false; + } + + @Override + public ItemStack[] getStoredItemData() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity != null) + && (this.getBaseMetaTileEntity().isAllowedToWork()) + && ((tTileEntity instanceof IDigitalChest))) { + return ((IDigitalChest) tTileEntity).getStoredItemData(); + } + return new ItemStack[] {}; + } + + @Override + public void setItemCount(final int aCount) { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity != null) + && (this.getBaseMetaTileEntity().isAllowedToWork()) + && ((tTileEntity instanceof IDigitalChest))) { + ((IDigitalChest) tTileEntity).setItemCount(aCount); + } + } + + @Override + public int getMaxItemCount() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity != null) + && (this.getBaseMetaTileEntity().isAllowedToWork()) + && ((tTileEntity instanceof IDigitalChest))) { + return ((IDigitalChest) tTileEntity).getMaxItemCount(); + } + return 0; + } + + @Override + public boolean isItemValidForSlot(final int aIndex, final ItemStack aStack) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.isItemValidForSlot(aIndex, aStack); + } + + @Override + public int[] getAccessibleSlotsFromSide(final int aSide) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return new int[0]; + } + if ((tTileEntity instanceof ISidedInventory)) { + return ((ISidedInventory) tTileEntity).getAccessibleSlotsFromSide(aSide); + } + final int[] rArray = new int[this.getSizeInventory()]; + for (int i = 0; i < this.getSizeInventory(); i++) { + rArray[i] = i; + } + return rArray; + } + + @Override + public boolean canInsertItem(final int aIndex, final ItemStack aStack, final int aSide) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + if ((tTileEntity instanceof ISidedInventory)) { + return ((ISidedInventory) tTileEntity).canInsertItem(aIndex, aStack, aSide); + } + return true; + } + + @Override + public boolean canExtractItem(final int aIndex, final ItemStack aStack, final int aSide) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + if ((tTileEntity instanceof ISidedInventory)) { + return ((ISidedInventory) tTileEntity).canExtractItem(aIndex, aStack, aSide); + } + return true; + } + + @Override + public int getSizeInventory() { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return 0; + } + return tTileEntity.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(final int aIndex) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.getStackInSlot(aIndex); + } + + @Override + public void setInventorySlotContents(final int aIndex, final ItemStack aStack) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return; + } + tTileEntity.setInventorySlotContents(aIndex, aStack); + } + + @Override + public ItemStack decrStackSize(final int aIndex, final int aAmount) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.decrStackSize(aIndex, aAmount); + } + + @Override + public String getInventoryName() { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return ""; + } + return tTileEntity.getInventoryName(); + } + + @Override + public int getInventoryStackLimit() { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return 0; + } + return tTileEntity.getInventoryStackLimit(); + } + + @Override + public boolean canFill(final ForgeDirection aSide, final Fluid aFluid) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.canFill(aSide, aFluid); + } + + @Override + public boolean canDrain(final ForgeDirection aSide, final Fluid aFluid) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.canDrain(aSide, aFluid); + } + + @Override + public FluidTankInfo[] getTankInfo(final ForgeDirection aSide) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return new FluidTankInfo[0]; + } + return tTileEntity.getTankInfo(aSide); + } + + @Override + public int fill_default(final ForgeDirection aDirection, final FluidStack aFluid, final boolean doFill) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return 0; + } + return tTileEntity.fill(aDirection, aFluid, doFill); + } + + @Override + public FluidStack drain(final ForgeDirection aDirection, final int maxDrain, final boolean doDrain) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.drain(aDirection, maxDrain, doDrain); + } + + @Override + public FluidStack drain(final ForgeDirection aSide, final FluidStack aFluid, final boolean doDrain) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.drain(aSide, aFluid, doDrain); + } + + public boolean addEnergyConsumption(final GT_MetaTileEntity_TesseractTerminal aTerminal) { + if (!this.getBaseMetaTileEntity().isAllowedToWork()) { + return false; + } + int J = (aTerminal.getBaseMetaTileEntity().getWorld() + == this.getBaseMetaTileEntity().getWorld() + ? TESSERACT_ENERGY_COST + : TESSERACT_ENERGY_COST_DIMENSIONAL); + + if (CORE.GTNH) { + J *= 4; + } + + this.mNeededEnergy += J; + + return true; + } + + public boolean isValidTesseractGenerator(final String aOwnerName, final boolean aWorkIrrelevant) { + return (this.getBaseMetaTileEntity() != null) + && (!this.getBaseMetaTileEntity().isInvalidTileEntity()) + && (this.getBaseMetaTileEntity().isAllowedToWork()) + && ((aOwnerName == null) + || (this.getBaseMetaTileEntity().getOwnerName().equals(aOwnerName))) + && ((aWorkIrrelevant) || (this.isWorking >= 20)); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // TODO Auto-generated method stub + super.onPreTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // Utils.LOG_WARNING("Ticking Generator. 0"); + if (this.getBaseMetaTileEntity().isServerSide()) { + // Utils.LOG_WARNING("Ticking Generator."); + // Set owner + if (PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()) != null) { + if (this.mOwner == null) { + Logger.WARNING("Setting Generators Owner. 1"); + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity().getOwnerName()); + } + } + + if (this.mFrequency != this.oFrequency) { + + Logger.WARNING("mFreq != oFreq"); + + if (getGeneratorEntity() == this) { + getGeneratorEntity(this.oFrequency); + this.getBaseMetaTileEntity().issueBlockUpdate(); + Logger.WARNING("this Gen == oFreq on map - do block update"); + } + Logger.WARNING("mFreq will be set to oFreq"); + this.oFrequency = this.mFrequency; + } + if ((this.getBaseMetaTileEntity().isAllowedToWork()) + && (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(this.mNeededEnergy, false))) { + // Utils.LOG_WARNING("Can Work & Has Energy"); + if ((getGeneratorEntity(Integer.valueOf(this.mFrequency)) == null) + || (!getGeneratorEntity(Integer.valueOf(this.mFrequency)) + .isValidTesseractGenerator(null, true))) { + // Utils.LOG_WARNING("storing TE I think to mFreq map?"); + TesseractHelper.setGeneratorOwnershipByPlayer( + PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency, this); + } + } else { + if (getGeneratorEntity(Integer.valueOf(this.mFrequency)) == this) { + Logger.WARNING("this gen == mFreq on map - do block update"); + TesseractHelper.removeGenerator(PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency); + this.getBaseMetaTileEntity().issueBlockUpdate(); + } + this.isWorking = 0; + } + if (getGeneratorEntity(Integer.valueOf(this.mFrequency)) == this) { + // Utils.LOG_WARNING("mFreq == this - do work related things"); + if (this.isWorking < 20) { + this.isWorking = ((byte) (this.isWorking + 1)); + } + if (this.isWorking == 20) { + this.getBaseMetaTileEntity().issueBlockUpdate(); + this.isWorking = ((byte) (this.isWorking + 1)); + } + } else { + this.isWorking = 0; + } + this.mNeededEnergy = 0; + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Generates a Tesseract for the attached Inventory", + "Connect with pipes to insert items", + "Consumes " + TESSERACT_ENERGY_COST + "EU/t for same dimension transfers", + "Consumes " + TESSERACT_ENERGY_COST_DIMENSIONAL + "EU/t for cross dimensional transfers", + CORE.GT_Tooltip + }; + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + return new ITexture[0][0][0]; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return aSide == aFacing + ? new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) + } + : new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(Textures.BlockIcons.VOID) + }; + } + + // To-Do? + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return false; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + private GT_MetaTileEntity_TesseractGenerator getGeneratorEntity() { + GT_MetaTileEntity_TesseractGenerator thisGenerator = + TesseractHelper.getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency); + if (thisGenerator != null) { + return thisGenerator; + } + return null; + } + + private GT_MetaTileEntity_TesseractGenerator getGeneratorEntity(int frequency) { + GT_MetaTileEntity_TesseractGenerator thisGenerator = + TesseractHelper.getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), frequency); + if (thisGenerator != null) { + return thisGenerator; + } + return null; + } + + @Override + public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + if (this.getBaseMetaTileEntity().getOwnerName() != null + && !this.getBaseMetaTileEntity().getOwnerName().equals("")) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity().getOwnerName()); + Logger.WARNING("Setting Generators Owner. 2"); + } + super.onCreated(aStack, aWorld, aPlayer); + } + + @Override + public void onRemoval() { + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + super.onRemoval(); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractTerminal.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractTerminal.java index 088a596410..5d2a9ae009 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractTerminal.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractTerminal.java @@ -1,13 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.automation; -import java.util.UUID; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -16,566 +8,605 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Config; import gregtech.api.util.GT_Utility; - import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.helpers.tesseract.TesseractHelper; +import java.util.UUID; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; public class GT_MetaTileEntity_TesseractTerminal extends GT_MetaTileEntity_BasicTank { - public int mFrequency = 0; - public UUID mOwner; - public boolean mDidWork = false; - public static boolean sInterDimensionalTesseractAllowed = true; - private static int TESSERACT_ENERGY_COST = 128; - private static int TESSERACT_ENERGY_COST_DIMENSIONAL = 512; - - public GT_MetaTileEntity_TesseractTerminal(final int aID, final String aName, final String aNameRegional, - final int aTier) { - super(aID, aName, aNameRegional, aTier, 3, ""); - } - - public GT_MetaTileEntity_TesseractTerminal(final String aName, final int aTier, final String aDescription, - final ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_TesseractTerminal(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public boolean isTransformerUpgradable() { - return false; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isFacingValid(final byte aFacing) { - return true; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide == this.getBaseMetaTileEntity().getBackFacing(); - } - - @Override - public boolean isValidSlot(final int aIndex) { - return false; - } - - @Override - public long getMinimumStoredEU() { - return (this.getBaseMetaTileEntity().getEUCapacity() / 100); - } - - @Override - public long maxEUInput() { - return TESSERACT_ENERGY_COST_DIMENSIONAL; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public long maxEUStore() { - return TESSERACT_ENERGY_COST_DIMENSIONAL * 8 * 32; - } - - @Override - public long maxSteamStore() { - return this.maxEUStore(); - } - - @Override - public boolean ownerControl() { - return true; - } - - @Override - public int getProgresstime() { - return this.getTesseract(this.mFrequency, false) != null ? 999 : 0; - } - - @Override - public int maxProgresstime() { - return 1000; - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setInteger("mFrequency", this.mFrequency); - aNBT.setString("mOwner", mOwner.toString()); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.mFrequency = aNBT.getInteger("mFrequency"); - this.mOwner = UUID.fromString(aNBT.getString("mOnwer")); - } - - @Override - public void onConfigLoad(final GT_Config aConfig) { - sInterDimensionalTesseractAllowed = true; - if (CORE.GTNH) { - TESSERACT_ENERGY_COST = 512; - TESSERACT_ENERGY_COST_DIMENSIONAL = 2048; - } - else { - TESSERACT_ENERGY_COST = 128; - TESSERACT_ENERGY_COST_DIMENSIONAL = 512; - } - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer, - final byte aSide, final float aX, final float aY, final float aZ) { - - if (this.mOwner == null) { - if (this.getBaseMetaTileEntity().getOwnerName() != null - && !this.getBaseMetaTileEntity().getOwnerName().equals("")) { - if (this.getBaseMetaTileEntity().getOwnerName().toLowerCase() - .equals(aPlayer.getDisplayName().toLowerCase())) { - this.mOwner = PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); - } - } - } - - if (aPlayer.getUniqueID().compareTo(this.mOwner) == 0) { - if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { - final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); - switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { - case 0: - //Utils.LOG_WARNING("Freq. -1 | " + this.mFrequency); - try { - CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency -= 1; - break; - case 1: - //Utils.LOG_WARNING("Freq. +1 | " + this.mFrequency); - try { - CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency += 1; - default: - // Utils.LOG_WARNING("Did not click the correct place."); - try { - CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - break; - } - PlayerUtils.messagePlayer(aPlayer, "Frequency: " + this.mFrequency); - if (this.getTesseract(this.mFrequency, false) != null) { - PlayerUtils.messagePlayer(aPlayer, - new StringBuilder().append(EnumChatFormatting.GREEN).append(" (Connected)").toString()); - } - } - } else if (aPlayer.getUniqueID().compareTo(this.mOwner) != 0){ - GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Terminal to configure."); - } - return true; - } - - @Override - public void onScrewdriverRightClick(final byte aSide, final EntityPlayer aPlayer, final float aX, final float aY, - final float aZ) { - if (aPlayer.getUniqueID().compareTo(this.mOwner) == 0) { - if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { - final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); - switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { - case 0: - try { - CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency -= 64; - break; - case 1: - try { - CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency += 64; - break; - case 2: - try { - CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency -= 512; - break; - case 3: - try { - CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - this.mFrequency += 512; - } - GT_Utility.sendChatToPlayer(aPlayer, - "Frequency: " + this.mFrequency - + (this.getTesseract(this.mFrequency, false) == null ? "" - : new StringBuilder().append(EnumChatFormatting.GREEN).append(" (Connected)") - .toString())); - } - } else if (aPlayer.getUniqueID().compareTo(this.mOwner) != 0){ - GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Terminal to configure."); - } - } - - public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { - return aSide != this.getBaseMetaTileEntity().getFrontFacing(); - } - - public GT_MetaTileEntity_TesseractGenerator getTesseract(final int aFrequency, final boolean aWorkIrrelevant) { - final GT_MetaTileEntity_TesseractGenerator rTesseract = TesseractHelper - .getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), aFrequency); - if (rTesseract == null) { - return null; - } - if (!TesseractHelper.isGeneratorOwnedByPlayer(PlayerUtils.getPlayerOnServerFromUUID(mOwner), rTesseract)) { - return null; - } - if (rTesseract.mFrequency != aFrequency) { - TesseractHelper.setTerminalOwnershipByPlayer(PlayerUtils.getPlayerOnServerFromUUID(mOwner), - Integer.valueOf(aFrequency), null); - return null; - } - if (!rTesseract.isValidTesseractGenerator(this.getBaseMetaTileEntity().getOwnerName(), aWorkIrrelevant)) { - return null; - } - if ((!sInterDimensionalTesseractAllowed) - && (rTesseract.getBaseMetaTileEntity().getWorld() != this.getBaseMetaTileEntity().getWorld())) { - return null; - } - return rTesseract; - } - - @Override - public String[] getInfoData() { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity != null) && (this.getBaseMetaTileEntity().isAllowedToWork()) - && (tTileEntity.isSendingInformation())) { - return tTileEntity.getInfoData(); - } - return new String[] { "Tesseract Generator", "Freqency:", "" + this.mFrequency, - this.getTesseract(this.mFrequency, false) != null ? "Active" : "Inactive" }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean isDigitalChest() { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.isDigitalChest(); - } - - @Override - public ItemStack[] getStoredItemData() { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.getStoredItemData(); - } - - @Override - public void setItemCount(final int aCount) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return; - } - tTileEntity.setItemCount(aCount); - } - - @Override - public int getMaxItemCount() { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return 0; - } - return tTileEntity.getMaxItemCount(); - } - - @Override - public boolean isItemValidForSlot(final int aIndex, final ItemStack aStack) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.isItemValidForSlot(aIndex, aStack); - } - - @Override - public int[] getAccessibleSlotsFromSide(final int aSide) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return new int[0]; - } - return tTileEntity.getAccessibleSlotsFromSide(aSide); - } - - @Override - public boolean canInsertItem(final int aIndex, final ItemStack aStack, final int aSide) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.canInsertItem(aIndex, aStack, aSide); - } - - @Override - public boolean canExtractItem(final int aIndex, final ItemStack aStack, final int aSide) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.canExtractItem(aIndex, aStack, aSide); - } - - @Override - public int getSizeInventory() { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return 0; - } - return tTileEntity.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(final int aIndex) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.getStackInSlot(aIndex); - } - - @Override - public void setInventorySlotContents(final int aIndex, final ItemStack aStack) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return; - } - tTileEntity.setInventorySlotContents(aIndex, aStack); - } - - @Override - public ItemStack decrStackSize(final int aIndex, final int aAmount) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.decrStackSize(aIndex, aAmount); - } - - @Override - public String getInventoryName() { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return ""; - } - return tTileEntity.getInventoryName(); - } - - @Override - public int getInventoryStackLimit() { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return 0; - } - return tTileEntity.getInventoryStackLimit(); - } - - @Override - public boolean canFill(final ForgeDirection aSide, final Fluid aFluid) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.canFill(aSide, aFluid); - } - - @Override - public boolean canDrain(final ForgeDirection aSide, final Fluid aFluid) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return false; - } - return tTileEntity.canDrain(aSide, aFluid); - } - - @Override - public FluidTankInfo[] getTankInfo(final ForgeDirection aSide) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return new FluidTankInfo[0]; - } - return tTileEntity.getTankInfo(aSide); - } - - @Override - public int fill_default(final ForgeDirection aDirection, final FluidStack aFluid, final boolean doFill) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return 0; - } - return tTileEntity.fill(aDirection, aFluid, doFill); - } - - @Override - public FluidStack drain(final ForgeDirection aDirection, final int maxDrain, final boolean doDrain) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.drain(aDirection, maxDrain, doDrain); - } - - @Override - public FluidStack drain(final ForgeDirection aSide, final FluidStack aFluid, final boolean doDrain) { - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); - if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { - return null; - } - return tTileEntity.drain(aSide, aFluid, doDrain); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if ((this.getBaseMetaTileEntity().isServerSide()) && (this.getBaseMetaTileEntity().isAllowedToWork())) { - // Set owner - if (PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()) != null) { - if (this.mOwner == null) { - this.mOwner = PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); - } - } - final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, true); - if (tTileEntity != null) { - tTileEntity.addEnergyConsumption(this); - if ((!this.mDidWork) && (this.getTesseract(this.mFrequency, false) != null)) { - this.mDidWork = true; - this.getBaseMetaTileEntity().issueBlockUpdate(); - this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(128, false); - } - } else if (this.mDidWork == true) { - this.mDidWork = false; - this.getBaseMetaTileEntity().issueBlockUpdate(); - } - } - } - - @Override - public String[] getDescription() { - return new String[] { this.mDescription, - "Accesses Tesseract Generators remotely", - "Connect with pipes to extract items or fluids", - "Outputs from the back face", - "Consumes "+TESSERACT_ENERGY_COST+"EU/t for same dimension transfers", - "Consumes "+TESSERACT_ENERGY_COST_DIMENSIONAL+"EU/t for cross dimensional transfers", - CORE.GT_Tooltip}; - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - return false; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - return new ITexture[0][0][0]; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return aSide == aFacing - ? new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), - new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) } - : new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), - new GT_RenderedTexture(Textures.BlockIcons.VOID) }; - } - - // To-Do? - @Override - public boolean doesFillContainers() { - return false; - } - - @Override - public boolean doesEmptyContainers() { - return false; - } - - @Override - public boolean canTankBeFilled() { - return false; - } - - @Override - public boolean canTankBeEmptied() { - return false; - } - - @Override - public boolean displaysItemStack() { - return false; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - @Override - public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { - if (this.getBaseMetaTileEntity().getOwnerName() != null - && !this.getBaseMetaTileEntity().getOwnerName().equals("")) { - this.mOwner = PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); - } - super.onCreated(aStack, aWorld, aPlayer); - } - - @Override - public void onRemoval() { - try { - CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); - } catch (Throwable t) { - } - super.onRemoval(); - } - + public int mFrequency = 0; + public UUID mOwner; + public boolean mDidWork = false; + public static boolean sInterDimensionalTesseractAllowed = true; + private static int TESSERACT_ENERGY_COST = 128; + private static int TESSERACT_ENERGY_COST_DIMENSIONAL = 512; + + public GT_MetaTileEntity_TesseractTerminal( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier, 3, ""); + } + + public GT_MetaTileEntity_TesseractTerminal( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TesseractTerminal(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public long getMinimumStoredEU() { + return (this.getBaseMetaTileEntity().getEUCapacity() / 100); + } + + @Override + public long maxEUInput() { + return TESSERACT_ENERGY_COST_DIMENSIONAL; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public long maxEUStore() { + return TESSERACT_ENERGY_COST_DIMENSIONAL * 8 * 32; + } + + @Override + public long maxSteamStore() { + return this.maxEUStore(); + } + + @Override + public boolean ownerControl() { + return true; + } + + @Override + public int getProgresstime() { + return this.getTesseract(this.mFrequency, false) != null ? 999 : 0; + } + + @Override + public int maxProgresstime() { + return 1000; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mFrequency", this.mFrequency); + aNBT.setString("mOwner", mOwner.toString()); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mFrequency = aNBT.getInteger("mFrequency"); + this.mOwner = UUID.fromString(aNBT.getString("mOnwer")); + } + + @Override + public void onConfigLoad(final GT_Config aConfig) { + sInterDimensionalTesseractAllowed = true; + if (CORE.GTNH) { + TESSERACT_ENERGY_COST = 512; + TESSERACT_ENERGY_COST_DIMENSIONAL = 2048; + } else { + TESSERACT_ENERGY_COST = 128; + TESSERACT_ENERGY_COST_DIMENSIONAL = 512; + } + } + + @Override + public boolean onRightclick( + final IGregTechTileEntity aBaseMetaTileEntity, + final EntityPlayer aPlayer, + final byte aSide, + final float aX, + final float aY, + final float aZ) { + + if (this.mOwner == null) { + if (this.getBaseMetaTileEntity().getOwnerName() != null + && !this.getBaseMetaTileEntity().getOwnerName().equals("")) { + if (this.getBaseMetaTileEntity() + .getOwnerName() + .toLowerCase() + .equals(aPlayer.getDisplayName().toLowerCase())) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity().getOwnerName()); + } + } + } + + if (aPlayer.getUniqueID().compareTo(this.mOwner) == 0) { + if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0: + // Utils.LOG_WARNING("Freq. -1 | " + this.mFrequency); + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency -= 1; + break; + case 1: + // Utils.LOG_WARNING("Freq. +1 | " + this.mFrequency); + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency += 1; + default: + // Utils.LOG_WARNING("Did not click the correct place."); + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + break; + } + PlayerUtils.messagePlayer(aPlayer, "Frequency: " + this.mFrequency); + if (this.getTesseract(this.mFrequency, false) != null) { + PlayerUtils.messagePlayer( + aPlayer, + new StringBuilder() + .append(EnumChatFormatting.GREEN) + .append(" (Connected)") + .toString()); + } + } + } else if (aPlayer.getUniqueID().compareTo(this.mOwner) != 0) { + GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Terminal to configure."); + } + return true; + } + + @Override + public void onScrewdriverRightClick( + final byte aSide, final EntityPlayer aPlayer, final float aX, final float aY, final float aZ) { + if (aPlayer.getUniqueID().compareTo(this.mOwner) == 0) { + if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0: + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency -= 64; + break; + case 1: + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency += 64; + break; + case 2: + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency -= 512; + break; + case 3: + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + this.mFrequency += 512; + } + GT_Utility.sendChatToPlayer( + aPlayer, + "Frequency: " + this.mFrequency + + (this.getTesseract(this.mFrequency, false) == null + ? "" + : new StringBuilder() + .append(EnumChatFormatting.GREEN) + .append(" (Connected)") + .toString())); + } + } else if (aPlayer.getUniqueID().compareTo(this.mOwner) != 0) { + GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Terminal to configure."); + } + } + + public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + public GT_MetaTileEntity_TesseractGenerator getTesseract(final int aFrequency, final boolean aWorkIrrelevant) { + final GT_MetaTileEntity_TesseractGenerator rTesseract = + TesseractHelper.getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), aFrequency); + if (rTesseract == null) { + return null; + } + if (!TesseractHelper.isGeneratorOwnedByPlayer(PlayerUtils.getPlayerOnServerFromUUID(mOwner), rTesseract)) { + return null; + } + if (rTesseract.mFrequency != aFrequency) { + TesseractHelper.setTerminalOwnershipByPlayer( + PlayerUtils.getPlayerOnServerFromUUID(mOwner), Integer.valueOf(aFrequency), null); + return null; + } + if (!rTesseract.isValidTesseractGenerator(this.getBaseMetaTileEntity().getOwnerName(), aWorkIrrelevant)) { + return null; + } + if ((!sInterDimensionalTesseractAllowed) + && (rTesseract.getBaseMetaTileEntity().getWorld() + != this.getBaseMetaTileEntity().getWorld())) { + return null; + } + return rTesseract; + } + + @Override + public String[] getInfoData() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity != null) + && (this.getBaseMetaTileEntity().isAllowedToWork()) + && (tTileEntity.isSendingInformation())) { + return tTileEntity.getInfoData(); + } + return new String[] { + "Tesseract Generator", + "Freqency:", + "" + this.mFrequency, + this.getTesseract(this.mFrequency, false) != null ? "Active" : "Inactive" + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean isDigitalChest() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.isDigitalChest(); + } + + @Override + public ItemStack[] getStoredItemData() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.getStoredItemData(); + } + + @Override + public void setItemCount(final int aCount) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return; + } + tTileEntity.setItemCount(aCount); + } + + @Override + public int getMaxItemCount() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return 0; + } + return tTileEntity.getMaxItemCount(); + } + + @Override + public boolean isItemValidForSlot(final int aIndex, final ItemStack aStack) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.isItemValidForSlot(aIndex, aStack); + } + + @Override + public int[] getAccessibleSlotsFromSide(final int aSide) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return new int[0]; + } + return tTileEntity.getAccessibleSlotsFromSide(aSide); + } + + @Override + public boolean canInsertItem(final int aIndex, final ItemStack aStack, final int aSide) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.canInsertItem(aIndex, aStack, aSide); + } + + @Override + public boolean canExtractItem(final int aIndex, final ItemStack aStack, final int aSide) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.canExtractItem(aIndex, aStack, aSide); + } + + @Override + public int getSizeInventory() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return 0; + } + return tTileEntity.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(final int aIndex) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.getStackInSlot(aIndex); + } + + @Override + public void setInventorySlotContents(final int aIndex, final ItemStack aStack) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return; + } + tTileEntity.setInventorySlotContents(aIndex, aStack); + } + + @Override + public ItemStack decrStackSize(final int aIndex, final int aAmount) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.decrStackSize(aIndex, aAmount); + } + + @Override + public String getInventoryName() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return ""; + } + return tTileEntity.getInventoryName(); + } + + @Override + public int getInventoryStackLimit() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return 0; + } + return tTileEntity.getInventoryStackLimit(); + } + + @Override + public boolean canFill(final ForgeDirection aSide, final Fluid aFluid) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.canFill(aSide, aFluid); + } + + @Override + public boolean canDrain(final ForgeDirection aSide, final Fluid aFluid) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return false; + } + return tTileEntity.canDrain(aSide, aFluid); + } + + @Override + public FluidTankInfo[] getTankInfo(final ForgeDirection aSide) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return new FluidTankInfo[0]; + } + return tTileEntity.getTankInfo(aSide); + } + + @Override + public int fill_default(final ForgeDirection aDirection, final FluidStack aFluid, final boolean doFill) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return 0; + } + return tTileEntity.fill(aDirection, aFluid, doFill); + } + + @Override + public FluidStack drain(final ForgeDirection aDirection, final int maxDrain, final boolean doDrain) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.drain(aDirection, maxDrain, doDrain); + } + + @Override + public FluidStack drain(final ForgeDirection aSide, final FluidStack aFluid, final boolean doDrain) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity().isAllowedToWork())) { + return null; + } + return tTileEntity.drain(aSide, aFluid, doDrain); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if ((this.getBaseMetaTileEntity().isServerSide()) + && (this.getBaseMetaTileEntity().isAllowedToWork())) { + // Set owner + if (PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()) != null) { + if (this.mOwner == null) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity().getOwnerName()); + } + } + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, true); + if (tTileEntity != null) { + tTileEntity.addEnergyConsumption(this); + if ((!this.mDidWork) && (this.getTesseract(this.mFrequency, false) != null)) { + this.mDidWork = true; + this.getBaseMetaTileEntity().issueBlockUpdate(); + this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(128, false); + } + } else if (this.mDidWork == true) { + this.mDidWork = false; + this.getBaseMetaTileEntity().issueBlockUpdate(); + } + } + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Accesses Tesseract Generators remotely", + "Connect with pipes to extract items or fluids", + "Outputs from the back face", + "Consumes " + TESSERACT_ENERGY_COST + "EU/t for same dimension transfers", + "Consumes " + TESSERACT_ENERGY_COST_DIMENSIONAL + "EU/t for cross dimensional transfers", + CORE.GT_Tooltip + }; + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + return new ITexture[0][0][0]; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return aSide == aFacing + ? new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) + } + : new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(Textures.BlockIcons.VOID) + }; + } + + // To-Do? + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return false; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + if (this.getBaseMetaTileEntity().getOwnerName() != null + && !this.getBaseMetaTileEntity().getOwnerName().equals("")) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity().getOwnerName()); + } + super.onCreated(aStack, aWorld, aPlayer); + } + + @Override + public void onRemoval() { + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner).remove(this.mFrequency); + } catch (Throwable t) { + } + super.onRemoval(); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Base.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Base.java index 4173489be6..5bd16c7fb2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Base.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Base.java @@ -23,274 +23,287 @@ import net.minecraftforge.fluids.FluidTankInfo; public class GT_MetaTileEntity_Boiler_Base extends GT_MetaTileEntity_Boiler { - private final int steamPerSecond; - private final int tier; - - public GT_MetaTileEntity_Boiler_Base(int aID, String aNameRegional, int tier) { - super(aID, "electricboiler." + tier + ".tier.single", aNameRegional, - "Produces " + (CORE.ConfigSwitches.boilerSteamPerSecond * tier) + "L of Steam per second"); - this.steamPerSecond = (CORE.ConfigSwitches.boilerSteamPerSecond * tier); - this.tier = tier; - } - - public GT_MetaTileEntity_Boiler_Base(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - this.steamPerSecond = (CORE.ConfigSwitches.boilerSteamPerSecond * aTier); - this.tier = aTier; - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - "Produces " + getPollution() + " pollution/sec", - "Consumes fuel only when temperature is less than 100C", - "Fuel with burn time greater than 500 is more efficient.", - "Doesn't explode if there's no water", - CORE.GT_Tooltip - }; - } - - public ITexture getOverlayIcon() { - return new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - protected GT_RenderedTexture getCasingTexture() { - if (this.tier == 1) { - return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_LV_SIDE); - } else if (this.tier == 2) { - return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_MV_SIDE); - } else { - return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_HV_SIDE); - } - // return new - // GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 - : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex - + 1]; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.tier][aColor + 1], - this.getCasingTexture() }; - } - - public ITexture[] getBack(final byte aColor) { - return this.getSides(aColor); - } - - public ITexture[] getBottom(final byte aColor) { - return this.getSides(aColor); - } - - public ITexture[] getTop(final byte aColor) { - return this.getSides(aColor); - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.tier][aColor + 1], - this.getCasingTexture() }; - } - - public ITexture[] getFrontActive(final byte aColor) { - return this.getFront(aColor); - } - - public ITexture[] getBackActive(final byte aColor) { - return this.getSides(aColor); - } - - public ITexture[] getBottomActive(final byte aColor) { - return this.getBottom(aColor); - } - - public ITexture[] getTopActive(final byte aColor) { - return this.getTop(aColor); - } - - public ITexture[] getSidesActive(final byte aColor) { - return this.getSides(aColor); - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide != this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public boolean isFacingValid(final byte aSide) { - return aSide > 1; - } - - // Please find out what I do. - // I do stuff within the GUI. - // this.mTemperature = Math.min(54, Math.max(0, this.mTemperature * 54 / (((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).maxProgresstime() - 10))); - @Override - public int maxProgresstime() { - return 1000 + (250 * tier); - } - - @Override - public boolean isElectric() { - return false; - } - - @Override - public int getCapacity() { - return (16000 + (16000 * tier)); - } - - // This type of machine can have different water and steam capacities. - public int getSteamCapacity() { - return 2 * getCapacity(); - } - - @Override - protected int getProductionPerSecond() { - return steamPerSecond; - } - - @Override - protected int getMaxTemperature() { - return maxProgresstime(); - } - - @Override - protected int getEnergyConsumption() { - return 2; - } - - @Override - protected int getCooldownInterval() { - return 40; - } - - @Override - protected int getHeatUpRate() { - return 10; - } - - @Override - protected void updateFuel(IGregTechTileEntity tile, long ticks) { - ItemStack fuelStack = this.mInventory[2]; - if(fuelStack == null) return; - - int burnTime = getBurnTime(fuelStack); - if (burnTime > 0 && this.mTemperature <= 101) { - consumeFuel(tile, fuelStack, burnTime); - } - } - - @Override - protected void produceSteam(int aAmount) { - super.produceSteam(aAmount); - - if(mSteam.amount > getSteamCapacity()) { - sendSound(SOUND_EVENT_LET_OFF_EXCESS_STEAM); - - mSteam.amount = getSteamCapacity(); - } - } - - @Override - // Since this type of machine can have different water and steam capacities, we need to override getTankInfo() to - // support returning those different capacities. - public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { - return new FluidTankInfo[]{ - new FluidTankInfo(this.mFluid, getCapacity()), - new FluidTankInfo(this.mSteam, getSteamCapacity()) - }; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aIndex == 1 || aIndex == 3; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aIndex == 2; - } - - @Override - protected int getPollution() { - return (int) (CORE.ConfigSwitches.basePollutionPerSecondBoiler*CORE.ConfigSwitches.pollutionReleasedByTierBoiler[this.tier]); - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_AdvancedBoiler(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_AdvancedBoiler(aPlayerInventory, aBaseMetaTileEntity, "AdvancedBoiler.png"); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Boiler_Base(this.mName, tier, this.mDescription, this.mTextures); - } - - @Override - protected void onDangerousWaterLack(IGregTechTileEntity tile, long ticks) { - // Smart boilers don't explode! - } - - /** - * Returns burn time if the stack is a valid fuel, otherwise return 0. - */ - private static int getBurnTime(ItemStack stack) { - int burnTime = GameRegistry.getFuelValue(stack); - if (burnTime <= 0) { - burnTime = TileEntityFurnace.getItemBurnTime(stack); - } - - return burnTime; - } - - public void consumeFuel(IGregTechTileEntity tile, ItemStack fuel, int burnTime) { - this.mProcessingEnergy += burnTime / 10; - this.mTemperature += burnTime / 500; // will add bonus temperature points if the burn time is pretty high - - tile.decrStackSize(2, 1); - if (tile.getRandomNumber(3) == 0) { - if (fuel.getDisplayName().toLowerCase().contains("charcoal") - || fuel.getDisplayName().toLowerCase().contains("coke")) { - tile.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); - } else { - tile.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); - } - } - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCover) { - if (aSide != this.getBaseMetaTileEntity().getFrontFacing()) { - return true; - } - return super.allowCoverOnSide(aSide, aCover); - } + private final int steamPerSecond; + private final int tier; + + public GT_MetaTileEntity_Boiler_Base(int aID, String aNameRegional, int tier) { + super( + aID, + "electricboiler." + tier + ".tier.single", + aNameRegional, + "Produces " + (CORE.ConfigSwitches.boilerSteamPerSecond * tier) + "L of Steam per second"); + this.steamPerSecond = (CORE.ConfigSwitches.boilerSteamPerSecond * tier); + this.tier = tier; + } + + public GT_MetaTileEntity_Boiler_Base(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + this.steamPerSecond = (CORE.ConfigSwitches.boilerSteamPerSecond * aTier); + this.tier = aTier; + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Produces " + getPollution() + " pollution/sec", + "Consumes fuel only when temperature is less than 100C", + "Fuel with burn time greater than 500 is more efficient.", + "Doesn't explode if there's no water", + CORE.GT_Tooltip + }; + } + + public ITexture getOverlayIcon() { + return new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + protected GT_RenderedTexture getCasingTexture() { + if (this.tier == 1) { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_LV_SIDE); + } else if (this.tier == 2) { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_MV_SIDE); + } else { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_HV_SIDE); + } + // return new + // GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.tier][aColor + 1], this.getCasingTexture()}; + } + + public ITexture[] getBack(final byte aColor) { + return this.getSides(aColor); + } + + public ITexture[] getBottom(final byte aColor) { + return this.getSides(aColor); + } + + public ITexture[] getTop(final byte aColor) { + return this.getSides(aColor); + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.tier][aColor + 1], this.getCasingTexture()}; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + public ITexture[] getBackActive(final byte aColor) { + return this.getSides(aColor); + } + + public ITexture[] getBottomActive(final byte aColor) { + return this.getBottom(aColor); + } + + public ITexture[] getTopActive(final byte aColor) { + return this.getTop(aColor); + } + + public ITexture[] getSidesActive(final byte aColor) { + return this.getSides(aColor); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isFacingValid(final byte aSide) { + return aSide > 1; + } + + // Please find out what I do. + // I do stuff within the GUI. + // this.mTemperature = Math.min(54, Math.max(0, this.mTemperature * 54 / (((GT_MetaTileEntity_Boiler) + // this.mTileEntity.getMetaTileEntity()).maxProgresstime() - 10))); + @Override + public int maxProgresstime() { + return 1000 + (250 * tier); + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public int getCapacity() { + return (16000 + (16000 * tier)); + } + + // This type of machine can have different water and steam capacities. + public int getSteamCapacity() { + return 2 * getCapacity(); + } + + @Override + protected int getProductionPerSecond() { + return steamPerSecond; + } + + @Override + protected int getMaxTemperature() { + return maxProgresstime(); + } + + @Override + protected int getEnergyConsumption() { + return 2; + } + + @Override + protected int getCooldownInterval() { + return 40; + } + + @Override + protected int getHeatUpRate() { + return 10; + } + + @Override + protected void updateFuel(IGregTechTileEntity tile, long ticks) { + ItemStack fuelStack = this.mInventory[2]; + if (fuelStack == null) return; + + int burnTime = getBurnTime(fuelStack); + if (burnTime > 0 && this.mTemperature <= 101) { + consumeFuel(tile, fuelStack, burnTime); + } + } + + @Override + protected void produceSteam(int aAmount) { + super.produceSteam(aAmount); + + if (mSteam.amount > getSteamCapacity()) { + sendSound(SOUND_EVENT_LET_OFF_EXCESS_STEAM); + + mSteam.amount = getSteamCapacity(); + } + } + + @Override + // Since this type of machine can have different water and steam capacities, we need to override getTankInfo() to + // support returning those different capacities. + public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { + return new FluidTankInfo[] { + new FluidTankInfo(this.mFluid, getCapacity()), new FluidTankInfo(this.mSteam, getSteamCapacity()) + }; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aIndex == 1 || aIndex == 3; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aIndex == 2; + } + + @Override + protected int getPollution() { + return (int) (CORE.ConfigSwitches.basePollutionPerSecondBoiler + * CORE.ConfigSwitches.pollutionReleasedByTierBoiler[this.tier]); + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_AdvancedBoiler(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_AdvancedBoiler(aPlayerInventory, aBaseMetaTileEntity, "AdvancedBoiler.png"); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Boiler_Base(this.mName, tier, this.mDescription, this.mTextures); + } + + @Override + protected void onDangerousWaterLack(IGregTechTileEntity tile, long ticks) { + // Smart boilers don't explode! + } + + /** + * Returns burn time if the stack is a valid fuel, otherwise return 0. + */ + private static int getBurnTime(ItemStack stack) { + int burnTime = GameRegistry.getFuelValue(stack); + if (burnTime <= 0) { + burnTime = TileEntityFurnace.getItemBurnTime(stack); + } + + return burnTime; + } + + public void consumeFuel(IGregTechTileEntity tile, ItemStack fuel, int burnTime) { + this.mProcessingEnergy += burnTime / 10; + this.mTemperature += burnTime / 500; // will add bonus temperature points if the burn time is pretty high + + tile.decrStackSize(2, 1); + if (tile.getRandomNumber(3) == 0) { + if (fuel.getDisplayName().toLowerCase().contains("charcoal") + || fuel.getDisplayName().toLowerCase().contains("coke")) { + tile.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); + } else { + tile.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); + } + } + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCover) { + if (aSide != this.getBaseMetaTileEntity().getFrontFacing()) { + return true; + } + return super.allowCoverOnSide(aSide, aCover); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_HV.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_HV.java index dfbd254897..867623f692 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_HV.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_HV.java @@ -5,52 +5,55 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; - import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -public class GT_MetaTileEntity_Boiler_HV - extends GT_MetaTileEntity_Boiler_Base { - +public class GT_MetaTileEntity_Boiler_HV extends GT_MetaTileEntity_Boiler_Base { + public GT_MetaTileEntity_Boiler_HV(int aID, String aNameRegional, int aBoilerTier) { - super(aID, aNameRegional, aBoilerTier); + super(aID, aNameRegional, aBoilerTier); } - + public GT_MetaTileEntity_Boiler_HV(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aDescription, aTextures); } @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Boiler_HV(this.mName, 3, this.mDescription, this.mTextures); } - - + + @Override + protected GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_HV_SIDE); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT) + }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + super.getTop(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Talonite) + }; + } + @Override - protected GT_RenderedTexture getCasingTexture(){ - return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_HV_SIDE); - } - - + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE) + }; + } + @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{super.getFront(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT)}; - } - - @Override - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{super.getTop(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Talonite)}; - } - - @Override - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{super.getFrontActive(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE)}; - } - - @Override - public ITexture[] getTopActive(final byte aColor) { - return getTop(aColor); - } - - - -}
\ No newline at end of file + public ITexture[] getTopActive(final byte aColor) { + return getTop(aColor); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_LV.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_LV.java index e2b9046c68..6aeedaa6f3 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_LV.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_LV.java @@ -5,48 +5,55 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; - import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -public class GT_MetaTileEntity_Boiler_LV -extends GT_MetaTileEntity_Boiler_Base { - - public GT_MetaTileEntity_Boiler_LV(int aID, String aNameRegional, int aBoilerTier) { - super(aID, aNameRegional, aBoilerTier); - } - - public GT_MetaTileEntity_Boiler_LV(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Boiler_LV(this.mName, 1, this.mDescription, this.mTextures); - } - - - @Override - protected GT_RenderedTexture getCasingTexture(){ - return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_LV_SIDE); - } - - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{super.getFront(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT)}; - } - - @Override - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{super.getTop(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Potin)}; - } - - @Override - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{super.getFrontActive(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE)}; - } - - @Override - public ITexture[] getTopActive(final byte aColor) { - return getTop(aColor); - } -}
\ No newline at end of file +public class GT_MetaTileEntity_Boiler_LV extends GT_MetaTileEntity_Boiler_Base { + + public GT_MetaTileEntity_Boiler_LV(int aID, String aNameRegional, int aBoilerTier) { + super(aID, aNameRegional, aBoilerTier); + } + + public GT_MetaTileEntity_Boiler_LV(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Boiler_LV(this.mName, 1, this.mDescription, this.mTextures); + } + + @Override + protected GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_LV_SIDE); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT) + }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + super.getTop(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Potin) + }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE) + }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return getTop(aColor); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_MV.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_MV.java index 7ef781da17..9f329f92da 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_MV.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_MV.java @@ -5,48 +5,55 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; - import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -public class GT_MetaTileEntity_Boiler_MV -extends GT_MetaTileEntity_Boiler_Base { - - public GT_MetaTileEntity_Boiler_MV(int aID, String aNameRegional, int aBoilerTier) { - super(aID, aNameRegional, aBoilerTier); - } - - public GT_MetaTileEntity_Boiler_MV(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Boiler_MV(this.mName, 2, this.mDescription, this.mTextures); - } - - @Override - protected GT_RenderedTexture getCasingTexture(){ - return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_MV_SIDE); - } - - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{super.getFront(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT)}; - } - - @Override - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{super.getTop(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Tumbaga)}; - } - - @Override - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{super.getFrontActive(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE)}; - } - - @Override - public ITexture[] getTopActive(final byte aColor) { - return getTop(aColor); - } - -}
\ No newline at end of file +public class GT_MetaTileEntity_Boiler_MV extends GT_MetaTileEntity_Boiler_Base { + + public GT_MetaTileEntity_Boiler_MV(int aID, String aNameRegional, int aBoilerTier) { + super(aID, aNameRegional, aBoilerTier); + } + + public GT_MetaTileEntity_Boiler_MV(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Boiler_MV(this.mName, 2, this.mDescription, this.mTextures); + } + + @Override + protected GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_MV_SIDE); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT) + }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + super.getTop(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Tumbaga) + }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE) + }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return getTop(aColor); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Solar.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Solar.java index f9cf904cc2..ba6b037d76 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Solar.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Solar.java @@ -1,11 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.generators; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_AdvancedBoiler; -import gtPlusPlus.xmod.gregtech.api.gui.GUI_AdvancedBoiler; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.enums.Dyes; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -13,182 +7,214 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_ModHandler; -import gregtech.common.gui.GT_Container_Boiler; -import gregtech.common.gui.GT_GUIContainer_Boiler; import gregtech.common.tileentities.boilers.GT_MetaTileEntity_Boiler; - +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_AdvancedBoiler; +import gtPlusPlus.xmod.gregtech.api.gui.GUI_AdvancedBoiler; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; -public class GT_MetaTileEntity_Boiler_Solar -extends GT_MetaTileEntity_Boiler { - public GT_MetaTileEntity_Boiler_Solar(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional, "Steam Power by the Sun"); - } - - public GT_MetaTileEntity_Boiler_Solar(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - "Produces "+(this.getPollution()*20)+" pollution/sec", - CORE.GT_Tooltip}; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[4][17][]; - for (byte i = -1; i < 16; i = (byte) (i + 1)) { - final ITexture[] tmp0 = {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM, Dyes.getModulation(i, Dyes._NULL.mRGBa))}; - rTextures[0][(i + 1)] = tmp0; - final ITexture[] tmp1 = {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP, Dyes.getModulation(i, Dyes._NULL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.BOILER_SOLAR)}; - rTextures[1][(i + 1)] = tmp1; - final ITexture[] tmp2 = {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE, Dyes.getModulation(i, Dyes._NULL.mRGBa))}; - rTextures[2][(i + 1)] = tmp2; - final ITexture[] tmp3 = {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE, Dyes.getModulation(i, Dyes._NULL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE)}; - rTextures[3][(i + 1)] = tmp3; - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[aSide >= 2 ? ((byte) (aSide != aFacing ? 2 : 3)) : aSide][aColorIndex + 1]; - } - - @Override - public int maxProgresstime() { - return 500; - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_AdvancedBoiler(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_AdvancedBoiler(aPlayerInventory, aBaseMetaTileEntity, "SolarBoiler.png"); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Boiler_Solar(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - private int mRunTime = 0; - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("mRunTime", this.mRunTime); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - this.mRunTime = aNBT.getInteger("mRunTime"); - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if ((aBaseMetaTileEntity.isServerSide()) && (aTick > 20L)) { - if (this.mTemperature <= 20) { - this.mTemperature = 20; - this.mLossTimer = 0; - } - if (++this.mLossTimer > 45) { - this.mTemperature -= 1; - this.mLossTimer = 0; - } - if (this.mSteam != null) { - final byte i = aBaseMetaTileEntity.getFrontFacing(); - final IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide(i); - if (tTileEntity != null) { - final FluidStack tDrained = aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), Math.max(1, this.mSteam.amount / 2), false); - if (tDrained != null) { - final int tFilledAmount = tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), tDrained, false); - if (tFilledAmount > 0) { - tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), tFilledAmount, true), true); - } - } - } - } - if ((aTick % 25L) == 0L) { - if (this.mTemperature > 100) { - if ((this.mFluid == null) || (!GT_ModHandler.isWater(this.mFluid)) || (this.mFluid.amount <= 0)) { - this.mHadNoWater = true; - } else { - if (this.mHadNoWater) { - aBaseMetaTileEntity.doExplosion(2048L); - return; - } - this.mFluid.amount -= 1; - this.mRunTime += 1; - int tOutput = 150; - if(this.mRunTime > 10000){ - tOutput = Math.max(50, 150 - ((this.mRunTime-10000)/100)); - } - if (this.mSteam == null) { - this.mSteam = GT_ModHandler.getSteam(tOutput); - } else if (GT_ModHandler.isSteam(this.mSteam)) { - this.mSteam.amount += tOutput; - } else { - this.mSteam = GT_ModHandler.getSteam(tOutput); - } - } - } else { - this.mHadNoWater = false; - } - } - if ((this.mSteam != null) && - (this.mSteam.amount > 16000)) { - this.sendSound((byte) 1); - this.mSteam.amount = 12000; - } - if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()) && ((aTick % 256L) == 0L) && (!aBaseMetaTileEntity.getWorld().isThundering())) { - final boolean bRain = aBaseMetaTileEntity.getWorld().isRaining() && (aBaseMetaTileEntity.getBiome().rainfall > 0.0F); - this.mProcessingEnergy += (bRain && (aBaseMetaTileEntity.getWorld().skylightSubtracted >= 4)) || !aBaseMetaTileEntity.getSkyAtSide((byte) 1) ? 0 : !bRain && aBaseMetaTileEntity.getWorld().isDaytime() ? 8 : 1; - } - if ((this.mTemperature < 500) && (this.mProcessingEnergy > 0) && ((aTick % 12L) == 0L)) { - this.mProcessingEnergy -= 1; - this.mTemperature += 1; - } - aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0); - } - } - - @Override - protected int getPollution() { - return 0; - } - - @Override - protected int getProductionPerSecond() { - return 0; - } - - @Override - protected int getMaxTemperature() { - return 0; - } - - @Override - protected int getEnergyConsumption() { - return 0; - } - - @Override - protected int getCooldownInterval() { - return 0; - } - - @Override - protected void updateFuel(IGregTechTileEntity iGregTechTileEntity, long l) { - - } +public class GT_MetaTileEntity_Boiler_Solar extends GT_MetaTileEntity_Boiler { + public GT_MetaTileEntity_Boiler_Solar(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional, "Steam Power by the Sun"); + } + + public GT_MetaTileEntity_Boiler_Solar( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, "Produces " + (this.getPollution() * 20) + " pollution/sec", CORE.GT_Tooltip + }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[4][17][]; + for (byte i = -1; i < 16; i = (byte) (i + 1)) { + final ITexture[] tmp0 = { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM, Dyes.getModulation(i, Dyes._NULL.mRGBa)) + }; + rTextures[0][(i + 1)] = tmp0; + final ITexture[] tmp1 = { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP, Dyes.getModulation(i, Dyes._NULL.mRGBa)), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_SOLAR) + }; + rTextures[1][(i + 1)] = tmp1; + final ITexture[] tmp2 = { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE, Dyes.getModulation(i, Dyes._NULL.mRGBa)) + }; + rTextures[2][(i + 1)] = tmp2; + final ITexture[] tmp3 = { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE, Dyes.getModulation(i, Dyes._NULL.mRGBa)), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) + }; + rTextures[3][(i + 1)] = tmp3; + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[aSide >= 2 ? ((byte) (aSide != aFacing ? 2 : 3)) : aSide][aColorIndex + 1]; + } + + @Override + public int maxProgresstime() { + return 500; + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_AdvancedBoiler(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_AdvancedBoiler(aPlayerInventory, aBaseMetaTileEntity, "SolarBoiler.png"); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Boiler_Solar(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + private int mRunTime = 0; + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mRunTime", this.mRunTime); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mRunTime = aNBT.getInteger("mRunTime"); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if ((aBaseMetaTileEntity.isServerSide()) && (aTick > 20L)) { + if (this.mTemperature <= 20) { + this.mTemperature = 20; + this.mLossTimer = 0; + } + if (++this.mLossTimer > 45) { + this.mTemperature -= 1; + this.mLossTimer = 0; + } + if (this.mSteam != null) { + final byte i = aBaseMetaTileEntity.getFrontFacing(); + final IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide(i); + if (tTileEntity != null) { + final FluidStack tDrained = aBaseMetaTileEntity.drain( + ForgeDirection.getOrientation(i), Math.max(1, this.mSteam.amount / 2), false); + if (tDrained != null) { + final int tFilledAmount = tTileEntity.fill( + ForgeDirection.getOrientation(i).getOpposite(), tDrained, false); + if (tFilledAmount > 0) { + tTileEntity.fill( + ForgeDirection.getOrientation(i).getOpposite(), + aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), tFilledAmount, true), + true); + } + } + } + } + if ((aTick % 25L) == 0L) { + if (this.mTemperature > 100) { + if ((this.mFluid == null) || (!GT_ModHandler.isWater(this.mFluid)) || (this.mFluid.amount <= 0)) { + this.mHadNoWater = true; + } else { + if (this.mHadNoWater) { + aBaseMetaTileEntity.doExplosion(2048L); + return; + } + this.mFluid.amount -= 1; + this.mRunTime += 1; + int tOutput = 150; + if (this.mRunTime > 10000) { + tOutput = Math.max(50, 150 - ((this.mRunTime - 10000) / 100)); + } + if (this.mSteam == null) { + this.mSteam = GT_ModHandler.getSteam(tOutput); + } else if (GT_ModHandler.isSteam(this.mSteam)) { + this.mSteam.amount += tOutput; + } else { + this.mSteam = GT_ModHandler.getSteam(tOutput); + } + } + } else { + this.mHadNoWater = false; + } + } + if ((this.mSteam != null) && (this.mSteam.amount > 16000)) { + this.sendSound((byte) 1); + this.mSteam.amount = 12000; + } + if ((this.mProcessingEnergy <= 0) + && (aBaseMetaTileEntity.isAllowedToWork()) + && ((aTick % 256L) == 0L) + && (!aBaseMetaTileEntity.getWorld().isThundering())) { + final boolean bRain = + aBaseMetaTileEntity.getWorld().isRaining() && (aBaseMetaTileEntity.getBiome().rainfall > 0.0F); + this.mProcessingEnergy += (bRain && (aBaseMetaTileEntity.getWorld().skylightSubtracted >= 4)) + || !aBaseMetaTileEntity.getSkyAtSide((byte) 1) + ? 0 + : !bRain && aBaseMetaTileEntity.getWorld().isDaytime() ? 8 : 1; + } + if ((this.mTemperature < 500) && (this.mProcessingEnergy > 0) && ((aTick % 12L) == 0L)) { + this.mProcessingEnergy -= 1; + this.mTemperature += 1; + } + aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0); + } + } + + @Override + protected int getPollution() { + return 0; + } + + @Override + protected int getProductionPerSecond() { + return 0; + } + + @Override + protected int getMaxTemperature() { + return 0; + } + + @Override + protected int getEnergyConsumption() { + return 0; + } + + @Override + protected int getCooldownInterval() { + return 0; + } + + @Override + protected void updateFuel(IGregTechTileEntity iGregTechTileEntity, long l) {} } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_RfConvertor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_RfConvertor.java index c6f368f0c0..340a97fccf 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_RfConvertor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_RfConvertor.java @@ -2,8 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.generators; import static gregtech.api.enums.GT_Values.V; -import cofh.api.energy.IEnergyConnection; -import cofh.api.energy.IEnergyHandler; import cofh.api.energy.IEnergyProvider; import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyStorage; @@ -20,7 +18,6 @@ import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; @@ -41,308 +38,342 @@ import net.minecraftforge.common.util.ForgeDirection; */ public class GT_MetaTileEntity_RfConvertor extends GregtechMetaEnergyBuffer implements IEnergyReceiver { - - public GT_MetaTileEntity_RfConvertor(final String aName, final int aTier, - final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { - super(aName, aTier, aDescription, aTextures, aSlotCount); - } - - public GT_MetaTileEntity_RfConvertor(final int aID, final String aName, - final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aDescription, aSlotCount); - } - - @Override - public String[] getDescription() { - return new String[] { - "Use Screwdriver to change voltage", - "Hold Shift while using Screwdriver to change amperage", - EnumChatFormatting.DARK_AQUA+"Variable Output Voltage", - CORE.GT_Tooltip}; - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[12][17][]; - GT_RenderedTexture aTex = new GT_RenderedTexture(TexturesGtBlock.Casing_Material_ZirconiumCarbide); - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; - rTextures[1][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; - rTextures[2][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; - rTextures[3][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; - rTextures[4][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; - rTextures[5][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; - rTextures[6][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; - rTextures[7][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; - rTextures[8][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; - rTextures[9][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; - rTextures[10][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; - rTextures[11][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; - } - return rTextures; - } - - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return mTextures[Math.min(2, aSide) + (aSide == aFacing ? 3 : 0) + (aActive ? 0 : 6)][aColorIndex + 1]; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RfConvertor(this.mName, this.mTier, this.mDescription, - this.mTextures, this.mInventory.length); - } - - @Override - public long getMinimumStoredEU() { - return 0; - } - - @Override - public long maxEUStore() { - return Integer.MAX_VALUE; - } - - @Override - public long maxEUInput() { - return 0; - } - - @Override - public long maxEUOutput() { - return V[this.mTier]; - } - - @Override - public long maxAmperesIn() { - return 0; - } - - @Override - public boolean isEnetInput() { - return false; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isInputFacing(byte aSide) { - return !isOutputFacing(aSide); - } - - @Override - public boolean isOutputFacing(byte aSide) { - return aSide == getBaseMetaTileEntity().getFrontFacing(); - } - - @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, - final IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, - final IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (!aBaseMetaTileEntity.isActive()) { - aBaseMetaTileEntity.setActive(true); - } - if (this.getEUVar() < this.maxEUStore()) { - for (byte i = 0; i < 6 && aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity(); i++) { - if (isInputFacing(i)) { - receiveEnergy(ForgeDirection.getOrientation(i), Integer.MAX_VALUE, false); - } - } - } - return; - } - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public String[] getInfoData() { - String[] infoData = super.getInfoData(); - return new String[] { - infoData[0], - "Converts RF -> GTEU | Tier: "+this.mTier, - infoData[1], - infoData[2] - }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setByte("mTier", this.mTier); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - this.mTier = aNBT.getByte("mTier"); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (aPlayer.isSneaking()) { - byte aTest = (byte) (aCurrentOutputAmperage + 1); - if (aTest > 16 || aTest <= 0 ) { - aTest = 1; - } - aCurrentOutputAmperage = aTest; - PlayerUtils.messagePlayer(aPlayer, "Now handling "+maxAmperesOut()+" Amps."); - } - else { - if (this.mTier < (CORE.GTNH ? GT_Values.V.length : 9)) { - this.mTier++; - } - else { - this.mTier = 0; - } - PlayerUtils.messagePlayer(aPlayer, "Now running at "+GT_Values.VOLTAGE_NAMES[this.mTier]+"."); - } - - } - - @Override - public boolean canConnectEnergy(ForgeDirection from) { - if (isOutputFacing((byte) from.ordinal())) { - return false; - } - return true; - } - - @Override - public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { - - // Cannot accept power on the output face. - if (!canConnectEnergy(from) || isOutputFacing((byte) from.ordinal())) { - return 0; - } - - TileEntity tTileEntity = this.getBaseMetaTileEntity().getTileEntityAtSide((byte) from.ordinal()); - if (tTileEntity == null) { - return 0; - } - - Logger.WARNING("Someone is trying to inject RF from "+from+". Type:"+tTileEntity.getClass().getName()); - - // Calculate maximum RF we need to consume - int aInputRF = MathUtils.safeInt(this.maxEUOutput() * GregTech_API.mEUtoRF / 100); - - // Make sure we only consume the correct amount of RF that is pushed into this Tile. - if (aInputRF > maxReceive) { - aInputRF = maxReceive; - } - - int aInjectedRF = 0; - boolean aVal = false; - - long aStoredEU = this.getEUVar(); - long aMaxEU = this.maxEUStore(); - Logger.WARNING("Stored: "+aStoredEU+", Capacity: "+aMaxEU+""); - if (aStoredEU < aMaxEU) { - Logger.WARNING("StoredEU < MaxEU"); - long aRemainingSpace = aMaxEU - aStoredEU; - if (aRemainingSpace > 0) { - long tEU = 0; - byte aSide = (byte) from.ordinal(); - Logger.WARNING("Free: "+aRemainingSpace+"EU"); - if (tTileEntity instanceof IEnergyProvider && ((IEnergyProvider) tTileEntity).extractEnergy(ForgeDirection.getOrientation(GT_Utility.getOppositeSide(aSide)), 1, true) == 1) { - tEU = (long) ((IEnergyProvider) tTileEntity).extractEnergy(ForgeDirection.getOrientation(GT_Utility.getOppositeSide(aSide)), (int) maxEUOutput() * 100 / GregTech_API.mRFtoEU, false); - Logger.WARNING("Drained from IEnergyProvider Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); - tEU = tEU * GregTech_API.mRFtoEU / 100; - } - else if (tTileEntity instanceof IEnergyStorage && ((IEnergyStorage) tTileEntity).extractEnergy(1, true) == 1) { - tEU = (long) ((IEnergyStorage) tTileEntity).extractEnergy((int) maxEUOutput() * 100 / GregTech_API.mRFtoEU, false); - Logger.WARNING("Drained from IEnergyStorage Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); - tEU = tEU * GregTech_API.mRFtoEU / 100; - } - else if (GregTech_API.meIOLoaded && tTileEntity instanceof IPowerContainer && ((IPowerContainer) tTileEntity).getEnergyStored() > 0) { - int storedRF = ((IPowerContainer) tTileEntity).getEnergyStored(); - int extractRF = (int) maxEUOutput() * 100 / GregTech_API.mRFtoEU; - tEU = 0; - if (tTileEntity instanceof TileCapBank) { - ICapBankNetwork network = ((TileCapBank) tTileEntity).getNetwork(); - if (network != null && network.getEnergyStoredL() > 0) { - tEU = Math.min((Math.min(Math.min(network.getEnergyStoredL(), storedRF - extractRF), network.getMaxOutput())) * GregTech_API.mRFtoEU / 100, maxEUOutput()); - Logger.WARNING("Drained from EIO CapBank Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); - network.addEnergy((int) -(tEU * 100 / GregTech_API.mRFtoEU)); - } - } else { - if (storedRF > extractRF) { - ((IPowerContainer) tTileEntity).setEnergyStored(storedRF - extractRF); - tEU = maxEUOutput(); - Logger.WARNING("Drained from EIO Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); - } else { - ((IPowerContainer) tTileEntity).setEnergyStored(0); - tEU = storedRF * GregTech_API.mRFtoEU / 100; - Logger.WARNING("Drained from EIO Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); - } - } - } - Logger.WARNING("EU to inject: "+tEU+"EU"); - if (!simulate) { - aVal = this.getBaseMetaTileEntity().increaseStoredEnergyUnits(tEU, true); - } - if (tEU > 0) { - Logger.WARNING("Tried injecting "+tEU+" eu into self. Success? "+aVal); - } - } - } - return aInjectedRF; - } - - @Override - public int getEnergyStored(ForgeDirection from) { - long aStoredEU = this.getEUVar(); - long aMaxEU = this.maxEUStore(); - if (aStoredEU == 0) { - return 0; - } - if (aStoredEU < aMaxEU) { - long aRemainingSpace = aMaxEU - aStoredEU; - if (aRemainingSpace > 0) { - if (aRemainingSpace > (this.maxEUOutput() / (GregTech_API.mEUtoRF / 100))) { - int aCalculatedFreeSpace = 0; - int aRfPer10Eu = GregTech_API.mEUtoRF / 10; - // Calculate how many lots of '10 - aCalculatedFreeSpace = (int) Math.floor(aRemainingSpace / 10); - // Return value equal to how many lots of '10eu' packets we can fit in. - return Integer.MAX_VALUE - MathUtils.balance(aCalculatedFreeSpace * aRfPer10Eu, 0, Integer.MAX_VALUE); - } - } - } - return Integer.MAX_VALUE; - } - - @Override - public int getMaxEnergyStored(ForgeDirection from) { - return Integer.MAX_VALUE; - } -}
\ No newline at end of file + public GT_MetaTileEntity_RfConvertor( + final String aName, + final int aTier, + final String aDescription, + final ITexture[][][] aTextures, + final int aSlotCount) { + super(aName, aTier, aDescription, aTextures, aSlotCount); + } + + public GT_MetaTileEntity_RfConvertor( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aDescription, aSlotCount); + } + + @Override + public String[] getDescription() { + return new String[] { + "Use Screwdriver to change voltage", + "Hold Shift while using Screwdriver to change amperage", + EnumChatFormatting.DARK_AQUA + "Variable Output Voltage", + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[12][17][]; + GT_RenderedTexture aTex = new GT_RenderedTexture(TexturesGtBlock.Casing_Material_ZirconiumCarbide); + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; + rTextures[1][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; + rTextures[2][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; + rTextures[3][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; + rTextures[4][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; + rTextures[5][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; + rTextures[6][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; + rTextures[7][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; + rTextures[8][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; + rTextures[9][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; + rTextures[10][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; + rTextures[11][i + 1] = new ITexture[] {aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + return mTextures[Math.min(2, aSide) + (aSide == aFacing ? 3 : 0) + (aActive ? 0 : 6)][aColorIndex + 1]; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_RfConvertor( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return Integer.MAX_VALUE; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return V[this.mTier]; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isInputFacing(byte aSide) { + return !isOutputFacing(aSide); + } + + @Override + public boolean isOutputFacing(byte aSide) { + return aSide == getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (!aBaseMetaTileEntity.isActive()) { + aBaseMetaTileEntity.setActive(true); + } + if (this.getEUVar() < this.maxEUStore()) { + for (byte i = 0; + i < 6 && aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity(); + i++) { + if (isInputFacing(i)) { + receiveEnergy(ForgeDirection.getOrientation(i), Integer.MAX_VALUE, false); + } + } + } + return; + } + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + String[] infoData = super.getInfoData(); + return new String[] {infoData[0], "Converts RF -> GTEU | Tier: " + this.mTier, infoData[1], infoData[2]}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mTier", this.mTier); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mTier = aNBT.getByte("mTier"); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + byte aTest = (byte) (aCurrentOutputAmperage + 1); + if (aTest > 16 || aTest <= 0) { + aTest = 1; + } + aCurrentOutputAmperage = aTest; + PlayerUtils.messagePlayer(aPlayer, "Now handling " + maxAmperesOut() + " Amps."); + } else { + if (this.mTier < (CORE.GTNH ? GT_Values.V.length : 9)) { + this.mTier++; + } else { + this.mTier = 0; + } + PlayerUtils.messagePlayer(aPlayer, "Now running at " + GT_Values.VOLTAGE_NAMES[this.mTier] + "."); + } + } + + @Override + public boolean canConnectEnergy(ForgeDirection from) { + if (isOutputFacing((byte) from.ordinal())) { + return false; + } + return true; + } + + @Override + public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { + + // Cannot accept power on the output face. + if (!canConnectEnergy(from) || isOutputFacing((byte) from.ordinal())) { + return 0; + } + + TileEntity tTileEntity = this.getBaseMetaTileEntity().getTileEntityAtSide((byte) from.ordinal()); + if (tTileEntity == null) { + return 0; + } + + Logger.WARNING("Someone is trying to inject RF from " + from + ". Type:" + + tTileEntity.getClass().getName()); + + // Calculate maximum RF we need to consume + int aInputRF = MathUtils.safeInt(this.maxEUOutput() * GregTech_API.mEUtoRF / 100); + + // Make sure we only consume the correct amount of RF that is pushed into this Tile. + if (aInputRF > maxReceive) { + aInputRF = maxReceive; + } + + int aInjectedRF = 0; + boolean aVal = false; + + long aStoredEU = this.getEUVar(); + long aMaxEU = this.maxEUStore(); + Logger.WARNING("Stored: " + aStoredEU + ", Capacity: " + aMaxEU + ""); + if (aStoredEU < aMaxEU) { + Logger.WARNING("StoredEU < MaxEU"); + long aRemainingSpace = aMaxEU - aStoredEU; + if (aRemainingSpace > 0) { + long tEU = 0; + byte aSide = (byte) from.ordinal(); + Logger.WARNING("Free: " + aRemainingSpace + "EU"); + if (tTileEntity instanceof IEnergyProvider + && ((IEnergyProvider) tTileEntity) + .extractEnergy( + ForgeDirection.getOrientation(GT_Utility.getOppositeSide(aSide)), + 1, + true) + == 1) { + tEU = (long) ((IEnergyProvider) tTileEntity) + .extractEnergy( + ForgeDirection.getOrientation(GT_Utility.getOppositeSide(aSide)), + (int) maxEUOutput() * 100 / GregTech_API.mRFtoEU, + false); + Logger.WARNING("Drained from IEnergyProvider Tile: " + (tEU * 100 / GregTech_API.mRFtoEU) + ""); + tEU = tEU * GregTech_API.mRFtoEU / 100; + } else if (tTileEntity instanceof IEnergyStorage + && ((IEnergyStorage) tTileEntity).extractEnergy(1, true) == 1) { + tEU = (long) ((IEnergyStorage) tTileEntity) + .extractEnergy((int) maxEUOutput() * 100 / GregTech_API.mRFtoEU, false); + Logger.WARNING("Drained from IEnergyStorage Tile: " + (tEU * 100 / GregTech_API.mRFtoEU) + ""); + tEU = tEU * GregTech_API.mRFtoEU / 100; + } else if (GregTech_API.meIOLoaded + && tTileEntity instanceof IPowerContainer + && ((IPowerContainer) tTileEntity).getEnergyStored() > 0) { + int storedRF = ((IPowerContainer) tTileEntity).getEnergyStored(); + int extractRF = (int) maxEUOutput() * 100 / GregTech_API.mRFtoEU; + tEU = 0; + if (tTileEntity instanceof TileCapBank) { + ICapBankNetwork network = ((TileCapBank) tTileEntity).getNetwork(); + if (network != null && network.getEnergyStoredL() > 0) { + tEU = Math.min( + (Math.min( + Math.min(network.getEnergyStoredL(), storedRF - extractRF), + network.getMaxOutput())) + * GregTech_API.mRFtoEU + / 100, + maxEUOutput()); + Logger.WARNING("Drained from EIO CapBank Tile: " + (tEU * 100 / GregTech_API.mRFtoEU) + ""); + network.addEnergy((int) -(tEU * 100 / GregTech_API.mRFtoEU)); + } + } else { + if (storedRF > extractRF) { + ((IPowerContainer) tTileEntity).setEnergyStored(storedRF - extractRF); + tEU = maxEUOutput(); + Logger.WARNING("Drained from EIO Tile: " + (tEU * 100 / GregTech_API.mRFtoEU) + ""); + } else { + ((IPowerContainer) tTileEntity).setEnergyStored(0); + tEU = storedRF * GregTech_API.mRFtoEU / 100; + Logger.WARNING("Drained from EIO Tile: " + (tEU * 100 / GregTech_API.mRFtoEU) + ""); + } + } + } + Logger.WARNING("EU to inject: " + tEU + "EU"); + if (!simulate) { + aVal = this.getBaseMetaTileEntity().increaseStoredEnergyUnits(tEU, true); + } + if (tEU > 0) { + Logger.WARNING("Tried injecting " + tEU + " eu into self. Success? " + aVal); + } + } + } + return aInjectedRF; + } + + @Override + public int getEnergyStored(ForgeDirection from) { + long aStoredEU = this.getEUVar(); + long aMaxEU = this.maxEUStore(); + if (aStoredEU == 0) { + return 0; + } + if (aStoredEU < aMaxEU) { + long aRemainingSpace = aMaxEU - aStoredEU; + if (aRemainingSpace > 0) { + if (aRemainingSpace > (this.maxEUOutput() / (GregTech_API.mEUtoRF / 100))) { + int aCalculatedFreeSpace = 0; + int aRfPer10Eu = GregTech_API.mEUtoRF / 10; + // Calculate how many lots of '10 + aCalculatedFreeSpace = (int) Math.floor(aRemainingSpace / 10); + // Return value equal to how many lots of '10eu' packets we can fit in. + return Integer.MAX_VALUE + - MathUtils.balance(aCalculatedFreeSpace * aRfPer10Eu, 0, Integer.MAX_VALUE); + } + } + } + return Integer.MAX_VALUE; + } + + @Override + public int getMaxEnergyStored(ForgeDirection from) { + return Integer.MAX_VALUE; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_SemiFluidGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_SemiFluidGenerator.java index d1628bdb59..7d9ecebf2c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_SemiFluidGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_SemiFluidGenerator.java @@ -11,161 +11,175 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicGenerator; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_SemiFluidGenerator extends GT_MetaTileEntity_BasicGenerator { - public int mEfficiency; - - /*public GT_MetaTileEntity_SemiFluidGenerator(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier); - onConfigLoad(); - }*/ - - public GT_MetaTileEntity_SemiFluidGenerator(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, - "Requires semi-fluid Fuel", - new ITexture[0]); - onConfigLoad(); - } - - public GT_MetaTileEntity_SemiFluidGenerator(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - onConfigLoad(); - } - - public int getPollution() { - return (int) (CORE.ConfigSwitches.basePollutionPerSecondSemiFluidGenerator * CORE.ConfigSwitches.pollutionReleasedByTierSemiFluidGenerator[this.mTier]); - } - - @Override - public int getCapacity() { - return 4000 * this.mTier; - } - - public void onConfigLoad() { - this.mEfficiency = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, - "SemiFluidGenerator.efficiency.tier." + this.mTier, 100 - (this.mTier * 5)); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_SemiFluidGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipes() { - //Logger.WARNING("Fuel Count: "+Gregtech_Recipe_Map.sSemiFluidLiquidFuels.mRecipeList.size()); - return GTPP_Recipe_Map.sSemiFluidLiquidFuels; - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - "Produces "+(this.getPollution())+" pollution/sec", - "Fuel Efficiency: "+this.getEfficiency() + "%", - CORE.GT_Tooltip}; - } - - @Override - public int getEfficiency() { - return this.mEfficiency; - } - - @Override - public boolean isOutputFacing(byte aSide) { - return (aSide == getBaseMetaTileEntity().getFrontFacing()); - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCover) { - if (aSide != this.getBaseMetaTileEntity().getFrontFacing()) { - return true; - } - return super.allowCoverOnSide(aSide, aCover); - } - - @Override - public int getFuelValue(ItemStack aStack) { - if ((GT_Utility.isStackInvalid(aStack)) || (getRecipes() == null)) { - Logger.WARNING("Bad Fuel?"); - return 0; - } - int rValue = Math.max(GT_ModHandler.getFuelCanValue(aStack) * 6 / 5, super.getFuelValue(aStack)); - if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { - rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); - } - Logger.WARNING("Good Fuel: "+rValue); - return rValue; - } - - @Override - public ITexture[] getFront(byte aColor) { - return new ITexture[] { super.getFront(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_FRONT), - Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier] }; - } - - @Override - public ITexture[] getBack(byte aColor) { - return new ITexture[] { super.getBack(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP) }; - } - - @Override - public ITexture[] getBottom(byte aColor) { - return new ITexture[] { super.getBottom(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM) }; - } - - @Override - public ITexture[] getTop(byte aColor) { - return new ITexture[] { super.getTop(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE) }; - } - - @Override - public ITexture[] getSides(byte aColor) { - return new ITexture[] { super.getSides(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP) }; - } - - @Override - public ITexture[] getFrontActive(byte aColor) { - return new ITexture[] { super.getFrontActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_FRONT_ACTIVE), - Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier] }; - } - - @Override - public ITexture[] getBackActive(byte aColor) { - return new ITexture[] { super.getBackActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP_ACTIVE) }; - } - - @Override - public ITexture[] getBottomActive(byte aColor) { - return new ITexture[] { super.getBottomActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM_ACTIVE) }; - } - - @Override - public ITexture[] getTopActive(byte aColor) { - return new ITexture[] { super.getTopActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE_ACTIVE) }; - } - - @Override - public ITexture[] getSidesActive(byte aColor) { - return new ITexture[] { super.getSidesActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP_ACTIVE) }; - } - + public int mEfficiency; + + /*public GT_MetaTileEntity_SemiFluidGenerator(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + onConfigLoad(); + }*/ + + public GT_MetaTileEntity_SemiFluidGenerator(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, "Requires semi-fluid Fuel", new ITexture[0]); + onConfigLoad(); + } + + public GT_MetaTileEntity_SemiFluidGenerator( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + onConfigLoad(); + } + + public int getPollution() { + return (int) (CORE.ConfigSwitches.basePollutionPerSecondSemiFluidGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierSemiFluidGenerator[this.mTier]); + } + + @Override + public int getCapacity() { + return 4000 * this.mTier; + } + + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, + "SemiFluidGenerator.efficiency.tier." + this.mTier, + 100 - (this.mTier * 5)); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_SemiFluidGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipes() { + // Logger.WARNING("Fuel Count: "+Gregtech_Recipe_Map.sSemiFluidLiquidFuels.mRecipeList.size()); + return GTPP_Recipe_Map.sSemiFluidLiquidFuels; + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Produces " + (this.getPollution()) + " pollution/sec", + "Fuel Efficiency: " + this.getEfficiency() + "%", + CORE.GT_Tooltip + }; + } + + @Override + public int getEfficiency() { + return this.mEfficiency; + } + + @Override + public boolean isOutputFacing(byte aSide) { + return (aSide == getBaseMetaTileEntity().getFrontFacing()); + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCover) { + if (aSide != this.getBaseMetaTileEntity().getFrontFacing()) { + return true; + } + return super.allowCoverOnSide(aSide, aCover); + } + + @Override + public int getFuelValue(ItemStack aStack) { + if ((GT_Utility.isStackInvalid(aStack)) || (getRecipes() == null)) { + Logger.WARNING("Bad Fuel?"); + return 0; + } + int rValue = Math.max(GT_ModHandler.getFuelCanValue(aStack) * 6 / 5, super.getFuelValue(aStack)); + if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { + rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); + } + Logger.WARNING("Good Fuel: " + rValue); + return rValue; + } + + @Override + public ITexture[] getFront(byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_FRONT), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier] + }; + } + + @Override + public ITexture[] getBack(byte aColor) { + return new ITexture[] { + super.getBack(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP) + }; + } + + @Override + public ITexture[] getBottom(byte aColor) { + return new ITexture[] { + super.getBottom(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM) + }; + } + + @Override + public ITexture[] getTop(byte aColor) { + return new ITexture[] { + super.getTop(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE) + }; + } + + @Override + public ITexture[] getSides(byte aColor) { + return new ITexture[] { + super.getSides(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP) + }; + } + + @Override + public ITexture[] getFrontActive(byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_FRONT_ACTIVE), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier] + }; + } + + @Override + public ITexture[] getBackActive(byte aColor) { + return new ITexture[] { + super.getBackActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP_ACTIVE) + }; + } + + @Override + public ITexture[] getBottomActive(byte aColor) { + return new ITexture[] { + super.getBottomActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM_ACTIVE) + }; + } + + @Override + public ITexture[] getTopActive(byte aColor) { + return new ITexture[] { + super.getTopActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE_ACTIVE) + }; + } + + @Override + public ITexture[] getSidesActive(byte aColor) { + return new ITexture[] { + super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP_ACTIVE) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityDoubleFuelGeneratorBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityDoubleFuelGeneratorBase.java index 2a0133245e..2897f621d6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityDoubleFuelGeneratorBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityDoubleFuelGeneratorBase.java @@ -1,9 +1,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.generators; import cpw.mods.fml.common.registry.GameRegistry; - -import net.minecraft.item.ItemStack; - import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; import gregtech.api.enums.ItemList; @@ -17,137 +14,177 @@ import gregtech.api.util.GT_Recipe; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators.GregtechRocketFuelGeneratorBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; -public class GregtechMetaTileEntityDoubleFuelGeneratorBase -extends GregtechRocketFuelGeneratorBase { +public class GregtechMetaTileEntityDoubleFuelGeneratorBase extends GregtechRocketFuelGeneratorBase { - public int mEfficiency; + public int mEfficiency; - public GregtechMetaTileEntityDoubleFuelGeneratorBase(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier, "Requires two liquid Fuels. Fuel A is Fastburn, Fuel B is slowburn.", new ITexture[0]); - this.onConfigLoad(); - } + public GregtechMetaTileEntityDoubleFuelGeneratorBase( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + "Requires two liquid Fuels. Fuel A is Fastburn, Fuel B is slowburn.", + new ITexture[0]); + this.onConfigLoad(); + } + + public GregtechMetaTileEntityDoubleFuelGeneratorBase( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + this.onConfigLoad(); + } - public GregtechMetaTileEntityDoubleFuelGeneratorBase(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - this.onConfigLoad(); - } - @Override public String[] getDescription() { - return new String[]{this.mDescription, - "Generates power at " + this.getEfficiency() + "% Efficiency per tick", - "Output Voltage: "+this.getOutputTier()+" EU/t", - CORE.GT_Tooltip - }; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide == this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntityDoubleFuelGeneratorBase(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipes() { - return GT_Recipe.GT_Recipe_Map.sDieselFuels; - } - - @Override - public int getCapacity() { - return 32000; - } - - public void onConfigLoad() { - this.mEfficiency = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "RocketEngine.efficiency.tier." + this.mTier, (100 - (this.mTier * 8))); - } - - @Override - public int getEfficiency() { - return this.mEfficiency; - } - - @Override - public int getFuelValue(final ItemStack aStack) { - int rValue = Math.max((GT_ModHandler.getFuelCanValue(aStack) * 6) / 5, super.getFuelValue(aStack)); - if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { - rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); - } - return rValue; - } - - private GT_RenderedTexture getCasingTexture(){ - if (this.mTier <= 4){ - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); - } - else if (this.mTier == 5){ - - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); - } - else { - - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Ultra); - } - //return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); - } - - - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{super.getFront(aColor)[0], this.getCasingTexture(), Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - @Override - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{super.getBack(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent)}; - } - - @Override - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{super.getBottom(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - @Override - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{super.getTop(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_Off)}; - } - - @Override - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{super.getSides(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal)}; - } - - @Override - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{super.getFrontActive(aColor)[0], this.getCasingTexture(), Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - @Override - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{super.getBackActive(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast)}; - } - - @Override - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{super.getBottomActive(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - @Override - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{super.getTopActive(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_On)}; - } - - @Override - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{super.getSidesActive(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal_Active)}; - } - - @Override - public int getPollution() { - return 250; - } + return new String[] { + this.mDescription, + "Generates power at " + this.getEfficiency() + "% Efficiency per tick", + "Output Voltage: " + this.getOutputTier() + " EU/t", + CORE.GT_Tooltip + }; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityDoubleFuelGeneratorBase( + this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipes() { + return GT_Recipe.GT_Recipe_Map.sDieselFuels; + } + + @Override + public int getCapacity() { + return 32000; + } + + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, "RocketEngine.efficiency.tier." + this.mTier, (100 - (this.mTier * 8))); + } + + @Override + public int getEfficiency() { + return this.mEfficiency; + } + + @Override + public int getFuelValue(final ItemStack aStack) { + int rValue = Math.max((GT_ModHandler.getFuelCanValue(aStack) * 6) / 5, super.getFuelValue(aStack)); + if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { + rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); + } + return rValue; + } + + private GT_RenderedTexture getCasingTexture() { + if (this.mTier <= 4) { + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } else if (this.mTier == 5) { + + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); + } else { + + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Ultra); + } + // return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], + this.getCasingTexture(), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + @Override + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + super.getBack(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent) + }; + } + + @Override + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + super.getBottom(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + super.getTop(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_Off) + }; + } + + @Override + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + super.getSides(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal) + }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + this.getCasingTexture(), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + @Override + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + super.getBackActive(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast) + }; + } + + @Override + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + super.getBottomActive(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + super.getTopActive(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_On) + }; + } + + @Override + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + super.getSidesActive(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal_Active) + }; + } + + @Override + public int getPollution() { + return 250; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityGeothermalGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityGeothermalGenerator.java index a392ae5a58..ba63952baf 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityGeothermalGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityGeothermalGenerator.java @@ -1,10 +1,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.generators; import cpw.mods.fml.common.registry.GameRegistry; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; import gregtech.api.enums.ItemList; @@ -16,136 +12,172 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicGenera import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; - import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; -public class GregtechMetaTileEntityGeothermalGenerator -extends GT_MetaTileEntity_BasicGenerator -{ - - public int mEfficiency; - - public GregtechMetaTileEntityGeothermalGenerator(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier, "Requires Pahoehoe Lava or Normal Lava as Fuel", new ITexture[0]); - this.onConfigLoad(); - } - - public GregtechMetaTileEntityGeothermalGenerator(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - this.onConfigLoad(); - } - - @Override - public String[] getDescription() { - String aPollution = "Causes "+this.getPollution()+ " Pollution per second"; - return new String[]{ - this.mDescription, - "Generates power at " + this.getEfficiency() + "% Efficiency per tick", - aPollution, - CORE.GT_Tooltip}; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()){ - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public int getCapacity() { - //return MathUtils.roundToClosestMultiple(32000*(this.mTier/2), 25000); - return 5000*this.mTier; - } - - public void onConfigLoad() { - this.mEfficiency = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "ThermalGenerator.efficiency.tier." + this.mTier, (100 - (this.mTier * 7))); - } - - @Override - public int getEfficiency() { - return this.mEfficiency; - } - - @Override - public int getFuelValue(final ItemStack aStack) { - int rValue = Math.max((GT_ModHandler.getFuelCanValue(aStack) * 6) / 5, super.getFuelValue(aStack)); - if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { - rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); - } - return rValue; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide == this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntityGeothermalGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{super.getFront(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - @Override - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{super.getBack(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BACK), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Vertical)}; - } - - @Override - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{super.getBottom(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM)}; - } - - @Override - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{super.getTop(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER)}; - } - - @Override - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{super.getSides(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.BOILER_LAVA_FRONT)}; - } - - @Override - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{super.getFrontActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE_ACTIVE), Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - @Override - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{super.getBackActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BACK_ACTIVE), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Vertical_Active)}; - } - - @Override - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{super.getBottomActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM_ACTIVE)}; - } - - @Override - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{super.getTopActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_ACTIVE)}; - } - - @Override - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.BOILER_LAVA_FRONT_ACTIVE)}; - } - - @Override - public GT_Recipe_Map getRecipes() - { - return GT_Recipe_Map.sHotFuels; - } - - public int getPollution() { - return (int) (CORE.ConfigSwitches.basePollutionPerSecondGeothermalGenerator * CORE.ConfigSwitches.pollutionReleasedByTierGeothermalGenerator[mTier]); - } -}
\ No newline at end of file +public class GregtechMetaTileEntityGeothermalGenerator extends GT_MetaTileEntity_BasicGenerator { + + public int mEfficiency; + + public GregtechMetaTileEntityGeothermalGenerator( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier, "Requires Pahoehoe Lava or Normal Lava as Fuel", new ITexture[0]); + this.onConfigLoad(); + } + + public GregtechMetaTileEntityGeothermalGenerator( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + this.onConfigLoad(); + } + + @Override + public String[] getDescription() { + String aPollution = "Causes " + this.getPollution() + " Pollution per second"; + return new String[] { + this.mDescription, + "Generates power at " + this.getEfficiency() + "% Efficiency per tick", + aPollution, + CORE.GT_Tooltip + }; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public int getCapacity() { + // return MathUtils.roundToClosestMultiple(32000*(this.mTier/2), 25000); + return 5000 * this.mTier; + } + + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, + "ThermalGenerator.efficiency.tier." + this.mTier, + (100 - (this.mTier * 7))); + } + + @Override + public int getEfficiency() { + return this.mEfficiency; + } + + @Override + public int getFuelValue(final ItemStack aStack) { + int rValue = Math.max((GT_ModHandler.getFuelCanValue(aStack) * 6) / 5, super.getFuelValue(aStack)); + if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { + rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); + } + return rValue; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityGeothermalGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + @Override + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + super.getBack(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BACK), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Vertical) + }; + } + + @Override + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + super.getBottom(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM) + }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + super.getTop(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER) + }; + } + + @Override + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {super.getSides(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.BOILER_LAVA_FRONT) + }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE_ACTIVE), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + @Override + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + super.getBackActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BACK_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Vertical_Active) + }; + } + + @Override + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + super.getBottomActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM_ACTIVE) + }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + super.getTopActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_ACTIVE) + }; + } + + @Override + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.BOILER_LAVA_FRONT_ACTIVE) + }; + } + + @Override + public GT_Recipe_Map getRecipes() { + return GT_Recipe_Map.sHotFuels; + } + + public int getPollution() { + return (int) (CORE.ConfigSwitches.basePollutionPerSecondGeothermalGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierGeothermalGenerator[mTier]); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityRocketFuelGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityRocketFuelGenerator.java index c05c7ae3ff..b6c2f27ce6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityRocketFuelGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityRocketFuelGenerator.java @@ -9,134 +9,164 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GTPP_Recipe; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators.GregtechRocketFuelGeneratorBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import net.minecraft.item.ItemStack; -public class GregtechMetaTileEntityRocketFuelGenerator -extends GregtechRocketFuelGeneratorBase { - - public int mEfficiency; - - public GregtechMetaTileEntityRocketFuelGenerator(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier, "Requires GT++ Rocket Fuels", new ITexture[0]); - this.onConfigLoad(); - } - - public GregtechMetaTileEntityRocketFuelGenerator(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - this.onConfigLoad(); - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide == this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - //Logger.INFO("Valid Fuels: "+Recipe_GT.Gregtech_Recipe_Map.sRocketFuels.mRecipeList.size()); - return new GregtechMetaTileEntityRocketFuelGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipes() { - return GTPP_Recipe.GTPP_Recipe_Map.sRocketFuels; - } - - @Override - public int getCapacity() { - return 32000; - } - - public void onConfigLoad() { - this.mEfficiency = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "RocketEngine.efficiency.tier." + this.mTier, 80 - (10 * (this.mTier - 4))); - } - - @Override - public int getEfficiency() { - int eff = 80 - (10 * (this.mTier - 4)); - return eff; - - } - - @Override - public int getFuelValue(final ItemStack aStack) { - int rValue = Math.max((GT_ModHandler.getFuelCanValue(aStack) * 6) / 5, super.getFuelValue(aStack)); - if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { - rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); - } - return rValue; - } - - private GT_RenderedTexture getCasingTexture(){ - if (this.mTier <= 4){ - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); - } - else if (this.mTier == 5){ - - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); - } - else{ - - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Ultra); - } - //return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); - } - - - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{super.getFront(aColor)[0], this.getCasingTexture(), Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - @Override - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{super.getBack(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent)}; - } - - @Override - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{super.getBottom(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - @Override - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{super.getTop(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_Off)}; - } - - @Override - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{super.getSides(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal)}; - } - - @Override - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{super.getFrontActive(aColor)[0], this.getCasingTexture(), Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - @Override - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{super.getBackActive(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast)}; - } - - @Override - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{super.getBottomActive(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - @Override - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{super.getTopActive(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_On)}; - } - - @Override - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{super.getSidesActive(aColor)[0], this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal_Active)}; - } +public class GregtechMetaTileEntityRocketFuelGenerator extends GregtechRocketFuelGeneratorBase { + + public int mEfficiency; + + public GregtechMetaTileEntityRocketFuelGenerator( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier, "Requires GT++ Rocket Fuels", new ITexture[0]); + this.onConfigLoad(); + } + + public GregtechMetaTileEntityRocketFuelGenerator( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + this.onConfigLoad(); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + // Logger.INFO("Valid Fuels: "+Recipe_GT.Gregtech_Recipe_Map.sRocketFuels.mRecipeList.size()); + return new GregtechMetaTileEntityRocketFuelGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipes() { + return GTPP_Recipe.GTPP_Recipe_Map.sRocketFuels; + } + + @Override + public int getCapacity() { + return 32000; + } + + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, + "RocketEngine.efficiency.tier." + this.mTier, + 80 - (10 * (this.mTier - 4))); + } + + @Override + public int getEfficiency() { + int eff = 80 - (10 * (this.mTier - 4)); + return eff; + } + + @Override + public int getFuelValue(final ItemStack aStack) { + int rValue = Math.max((GT_ModHandler.getFuelCanValue(aStack) * 6) / 5, super.getFuelValue(aStack)); + if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { + rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); + } + return rValue; + } + + private GT_RenderedTexture getCasingTexture() { + if (this.mTier <= 4) { + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } else if (this.mTier == 5) { + + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); + } else { + + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Ultra); + } + // return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], + this.getCasingTexture(), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + @Override + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + super.getBack(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent) + }; + } + + @Override + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + super.getBottom(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + super.getTop(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_Off) + }; + } + + @Override + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + super.getSides(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal) + }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + this.getCasingTexture(), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + @Override + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + super.getBackActive(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast) + }; + } + + @Override + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + super.getBottomActive(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + super.getTopActive(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_On) + }; + } + + @Override + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + super.getSidesActive(aColor)[0], + this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal_Active) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntitySolarGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntitySolarGenerator.java index 68dbc4fb61..660fdb50b6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntitySolarGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntitySolarGenerator.java @@ -2,8 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.generators; import static gregtech.api.enums.GT_Values.V; -import net.minecraft.entity.player.InventoryPlayer; - import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; import gregtech.api.enums.Textures; @@ -11,177 +9,218 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_SolarGenerator; import gtPlusPlus.xmod.gregtech.api.gui.GUI_SolarGenerator; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators.GregtechMetaSolarGenerator; +import net.minecraft.entity.player.InventoryPlayer; public class GregtechMetaTileEntitySolarGenerator extends GregtechMetaSolarGenerator { - public GregtechMetaTileEntitySolarGenerator(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier, "Feasts on the power of the Sun!", new ITexture[0]); - this.onConfigLoad(); - } + public GregtechMetaTileEntitySolarGenerator( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier, "Feasts on the power of the Sun!", new ITexture[0]); + this.onConfigLoad(); + } + + public GregtechMetaTileEntitySolarGenerator( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + this.onConfigLoad(); + } - public GregtechMetaTileEntitySolarGenerator(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - this.onConfigLoad(); - } - @Override public String[] getDescription() { - return new String[]{this.mDescription, - "Generates power at " + this.getEfficiency() + "% Efficiency per tick", - "Output Voltage: "+this.getOutputTier()+" EU/t", - CORE.GT_Tooltip - }; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide == this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_SolarGenerator(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_SolarGenerator(aPlayerInventory, aBaseMetaTileEntity, "SolarBoiler.png"); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntitySolarGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - public void onConfigLoad() { - this.mEfficiency = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "SunAbsorber.efficiency.tier." + this.mTier, 100 - (this.mTier * 10)); - - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() - && (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUOutput() + aBaseMetaTileEntity.getEUCapacity()))) { - - if (this.mSolarCharge <= 20) { - //Utils.LOG_WARNING("1."); - this.mSolarCharge = 20; - this.mLossTimer = 0; - } - if (++this.mLossTimer > 45) { - //Utils.LOG_WARNING("2."); - this.mSolarCharge -= 1; - this.mLossTimer = 0; - } - - if ((aTick % 10L) == 0L) { - - Logger.WARNING("getUniversalEnergyStored: "+aBaseMetaTileEntity.getUniversalEnergyStored() + " maxEUOutput * 20 + getMinimumStoredEU: " + ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())); - - if ((this.mSolarCharge > 100) && (aBaseMetaTileEntity.isAllowedToWork()) && - (!aBaseMetaTileEntity.getWorld().isThundering()) && - (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUStore() - this.getMinimumStoredEU()))) { - this.getBaseMetaTileEntity().increaseStoredEnergyUnits(sEnergyPerTick * this.getEfficiency(), true); - } - } - - if ((this.mSolarCharge < 500) && (this.mProcessingEnergy != 0) && ((aTick % 32L) == 0L)) { - Logger.WARNING("Adding Solar Charge. Currently "+this.mSolarCharge); - this.mProcessingEnergy -= 1; - this.mSolarCharge += 1; - } - - if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()) && ((aTick % 64L) == 0L) && (!aBaseMetaTileEntity.getWorld().isThundering())) { - Logger.WARNING("Adding Processing Energy. Currently "+this.mProcessingEnergy); - final boolean bRain = aBaseMetaTileEntity.getWorld().isRaining() && (aBaseMetaTileEntity.getBiome().rainfall > 0.0F); - this.mProcessingEnergy += (bRain && (aBaseMetaTileEntity.getWorld().skylightSubtracted >= 4)) || !aBaseMetaTileEntity.getSkyAtSide((byte) 1) ? 0 : !bRain && aBaseMetaTileEntity.getWorld().isDaytime() ? 8 : 1; - } - - if (aBaseMetaTileEntity.isServerSide()){ - //Utils.LOG_WARNING("6."); - aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && (aBaseMetaTileEntity.getUniversalEnergyStored() >= (this.maxEUOutput() + this.getMinimumStoredEU()))); - } - } - } - - @Override - public void inValidate() { - - } - - @Override - public int getEfficiency() { - return this.mEfficiency; - } - - @Override - public long maxEUStore() { - return Math.max(this.getEUVar(), (V[this.mTier] * 16000) + this.getMinimumStoredEU()); - } - - - ITexture SolarArray[] = {new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_8V), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LV), new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_MV), new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_HV), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_EV), new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV), new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LuV), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_ZPM), new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_UV), new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL)}; - - - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{super.getFront(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_FRONT), - Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - @Override - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{super.getBack(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC)}; - } - - @Override - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{super.getBottom(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC)}; - } - - @Override - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{super.getTop(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL)}; - } - - @Override - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{super.getSides(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC)}; - } - - @Override - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{super.getFrontActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_FRONT_ACTIVE), - Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier]}; - } - - @Override - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{super.getBackActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_ACTIVE)}; - } - - @Override - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{super.getBottomActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_ACTIVE)}; - } - - @Override - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{super.getTopActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL)}; - } - - @Override - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_ACTIVE)}; - } - -}
\ No newline at end of file + return new String[] { + this.mDescription, + "Generates power at " + this.getEfficiency() + "% Efficiency per tick", + "Output Voltage: " + this.getOutputTier() + " EU/t", + CORE.GT_Tooltip + }; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_SolarGenerator(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_SolarGenerator(aPlayerInventory, aBaseMetaTileEntity, "SolarBoiler.png"); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntitySolarGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, "SunAbsorber.efficiency.tier." + this.mTier, 100 - (this.mTier * 10)); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide() + && aBaseMetaTileEntity.isAllowedToWork() + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < (this.maxEUOutput() + aBaseMetaTileEntity.getEUCapacity()))) { + + if (this.mSolarCharge <= 20) { + // Utils.LOG_WARNING("1."); + this.mSolarCharge = 20; + this.mLossTimer = 0; + } + if (++this.mLossTimer > 45) { + // Utils.LOG_WARNING("2."); + this.mSolarCharge -= 1; + this.mLossTimer = 0; + } + + if ((aTick % 10L) == 0L) { + + Logger.WARNING("getUniversalEnergyStored: " + aBaseMetaTileEntity.getUniversalEnergyStored() + + " maxEUOutput * 20 + getMinimumStoredEU: " + + ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())); + + if ((this.mSolarCharge > 100) + && (aBaseMetaTileEntity.isAllowedToWork()) + && (!aBaseMetaTileEntity.getWorld().isThundering()) + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < (this.maxEUStore() - this.getMinimumStoredEU()))) { + this.getBaseMetaTileEntity().increaseStoredEnergyUnits(sEnergyPerTick * this.getEfficiency(), true); + } + } + + if ((this.mSolarCharge < 500) && (this.mProcessingEnergy != 0) && ((aTick % 32L) == 0L)) { + Logger.WARNING("Adding Solar Charge. Currently " + this.mSolarCharge); + this.mProcessingEnergy -= 1; + this.mSolarCharge += 1; + } + + if ((this.mProcessingEnergy <= 0) + && (aBaseMetaTileEntity.isAllowedToWork()) + && ((aTick % 64L) == 0L) + && (!aBaseMetaTileEntity.getWorld().isThundering())) { + Logger.WARNING("Adding Processing Energy. Currently " + this.mProcessingEnergy); + final boolean bRain = + aBaseMetaTileEntity.getWorld().isRaining() && (aBaseMetaTileEntity.getBiome().rainfall > 0.0F); + this.mProcessingEnergy += (bRain && (aBaseMetaTileEntity.getWorld().skylightSubtracted >= 4)) + || !aBaseMetaTileEntity.getSkyAtSide((byte) 1) + ? 0 + : !bRain && aBaseMetaTileEntity.getWorld().isDaytime() ? 8 : 1; + } + + if (aBaseMetaTileEntity.isServerSide()) { + // Utils.LOG_WARNING("6."); + aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() + && (aBaseMetaTileEntity.getUniversalEnergyStored() + >= (this.maxEUOutput() + this.getMinimumStoredEU()))); + } + } + } + + @Override + public void inValidate() {} + + @Override + public int getEfficiency() { + return this.mEfficiency; + } + + @Override + public long maxEUStore() { + return Math.max(this.getEUVar(), (V[this.mTier] * 16000) + this.getMinimumStoredEU()); + } + + ITexture SolarArray[] = { + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_8V), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LV), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_MV), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_HV), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_EV), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LuV), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_ZPM), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_UV), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL) + }; + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_FRONT), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + @Override + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + super.getBack(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC) + }; + } + + @Override + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + super.getBottom(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC) + }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {super.getTop(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL)}; + } + + @Override + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + super.getSides(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC) + }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_FRONT_ACTIVE), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier] + }; + } + + @Override + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + super.getBackActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_ACTIVE) + }; + } + + @Override + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + super.getBottomActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_ACTIVE) + }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] {super.getTopActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL)}; + } + + @Override + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_ACTIVE) + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java index ab000b98d4..5e8907073f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java @@ -1,390 +1,399 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.generators; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicGenerator; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.api.util.GTPP_Recipe; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator { - public int mEfficiency; - private int mDays; - private long mTicksToBurnFor; - private int mVoltage = 0; - private GT_Recipe mCurrentRecipe; - private int mDaysRemaining = 0; - private int mDayTick = 0; - private byte mNewTier = 0; - - public int removeDayOfTime(){ - if (this.mDaysRemaining > 0){ - return this.mDaysRemaining--; - } - return this.mDaysRemaining; - } - - //Generates fuel value based on MC days - public static int convertDaysToTicks(float days){ - int value = 0; - value = MathUtils.roundToClosestInt(20*86400*days); - return value; - } - - public static long getTotalEUGenerated(int ticks, int voltage){ - return ticks*voltage; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setLong("mTicksToBurnFor", this.mTicksToBurnFor); - aNBT.setInteger("mVoltage", this.mVoltage); - aNBT.setInteger("mDaysRemaining", this.mDaysRemaining); - aNBT.setInteger("mDayTick", this.mDayTick); - aNBT.setByte("mNewTier", this.mNewTier); - - - if (this.mCurrentRecipe != null){ - final NBTTagList list = new NBTTagList(); - final ItemStack stack = this.mCurrentRecipe.mInputs[0]; - if(stack != null){ - final NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("mSlot", 0); - list.appendTag(data); - } - aNBT.setTag("mRecipeItem", list); - } - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - //this.mMachineBlock = aNBT.getByte("mMachineBlock"); - this.mTicksToBurnFor = aNBT.getLong("mTicksToBurnFor"); - this.mVoltage = aNBT.getInteger("mVoltage"); - this.mDaysRemaining = aNBT.getInteger("mDaysRemaining"); - this.mDayTick = aNBT.getInteger("mDayTick"); - this.mNewTier = aNBT.getByte("mNewTier"); - - try { - ReflectionUtils.setByte(this, "mTier", this.mNewTier); - } - catch (Exception e) { - if (this.getBaseMetaTileEntity() != null){ - IGregTechTileEntity thisTile = this.getBaseMetaTileEntity(); - if (thisTile.isAllowedToWork() || thisTile.isActive()){ - thisTile.setActive(false); - } - } - } - - - final NBTTagList list = aNBT.getTagList("mRecipeItem", 10); - final NBTTagCompound data = list.getCompoundTagAt(0); - ItemStack lastUsedFuel = ItemStack.loadItemStackFromNBT(data); - if (lastUsedFuel != null){ - this.mCurrentRecipe = getRecipes().findRecipe(getBaseMetaTileEntity(), false, 9223372036854775807L, null, new ItemStack[] { lastUsedFuel }); - } - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()){ - if (this.mDayTick < 24000){ - this.mDayTick++; - } - else if (this.mDayTick >= 24000){ - this.mDayTick = 0; - this.mDaysRemaining = this.removeDayOfTime(); - } - } - - - if ((aBaseMetaTileEntity.isServerSide()) && (aBaseMetaTileEntity.isAllowedToWork()) && (aTick % 10L == 0L)) { - long tProducedEU = 0L; - if (this.mFluid == null) { - if (aBaseMetaTileEntity.getUniversalEnergyStored() < maxEUOutput() + getMinimumStoredEU()) { - this.mInventory[getStackDisplaySlot()] = null; - } else { - if (this.mInventory[getStackDisplaySlot()] == null) - this.mInventory[getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); - this.mInventory[getStackDisplaySlot()].setStackDisplayName("Generating: " - + (aBaseMetaTileEntity.getUniversalEnergyStored() - getMinimumStoredEU()) + " EU"); - } - } else { - int tFuelValue = getFuelValue(this.mFluid); - int tConsumed = consumedFluidPerOperation(this.mFluid); - if ((tFuelValue > 0) && (tConsumed > 0) && (this.mFluid.amount > tConsumed)) { - long tFluidAmountToUse = Math.min(this.mFluid.amount / tConsumed, - (maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue); - if ((tFluidAmountToUse > 0L) - && (aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true))) { - tProducedEU = tFluidAmountToUse * tFuelValue; - FluidStack tmp260_257 = this.mFluid; - tmp260_257.amount = (int) (tmp260_257.amount - (tFluidAmountToUse * tConsumed)); - } - } - } - if ((this.mInventory[getInputSlot()] != null) - && (aBaseMetaTileEntity.getUniversalEnergyStored() < maxEUOutput() * 20L + getMinimumStoredEU()) - && (GT_Utility.getFluidForFilledItem(this.mInventory[getInputSlot()], true) == null)) { - int tFuelValue = getFuelValue(this.mInventory[getInputSlot()]); - if (tFuelValue > 0) { - ItemStack tEmptyContainer = getEmptyContainer(this.mInventory[getInputSlot()]); - if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), tEmptyContainer)) { - aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); - aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); - tProducedEU = tFuelValue; - } - } - } - if ((tProducedEU > 0L) && (getPollution() > 0)) { - PollutionUtils.addPollution(aBaseMetaTileEntity, (int) (tProducedEU * getPollution() / 500 * this.mTier + 1L)); - } - } - - if (aBaseMetaTileEntity.isServerSide()) - aBaseMetaTileEntity.setActive((aBaseMetaTileEntity.isAllowedToWork()) - && (aBaseMetaTileEntity.getUniversalEnergyStored() >= maxEUOutput() + getMinimumStoredEU())); - } - - @Override - public String[] getDescription() { - return new String[]{this.mDescription, - "Fuel is measured in minecraft days (Check with Scanner)", - "RTG changes output voltage depending on fuel", - "Generates power at " + this.getEfficiency() + "% Efficiency per tick", - "Output Voltage: "+this.getOutputTier()+" EU/t", - CORE.GT_Tooltip - }; - } - - public GregtechMetaTileEntity_RTG(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, "Requires RTG Pellets", new ITexture[0]); - } - - private byte getTier(){ - int voltage = this.mVoltage; - if (voltage >= 512){ - return 4; - } - else if (voltage >= 128){ - return 3; - } - else if (voltage >= 32){ - return 2; - } - else if (voltage >= 8){ - return 1; - } - return 0; - } - - public GregtechMetaTileEntity_RTG(String aName, int aTier, String aDescription, - ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public boolean isOutputFacing(byte aSide) { - return ((aSide > 1) && (aSide != getBaseMetaTileEntity().getFrontFacing()) - && (aSide != getBaseMetaTileEntity().getBackFacing())); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_RTG(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipes() { - return GTPP_Recipe.GTPP_Recipe_Map.sRTGFuels; - } - - @Override - public int getCapacity() { - return 0; - } - - @Override - public int getEfficiency() { - return this.mEfficiency = 100; - } - - @Override - public ITexture[] getFront(byte aColor) { - return new ITexture[] { super.getFront(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_MASSFAB) }; - } - - @Override - public ITexture[] getBack(byte aColor) { - return new ITexture[] { super.getBack(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP) }; - } - - @Override - public ITexture[] getBottom(byte aColor) { - return new ITexture[] { super.getBottom(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP) }; - } - - @Override - public ITexture[] getTop(byte aColor) { - return new ITexture[] { super.getTop(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP), - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE) }; - } - - @Override - public ITexture[] getSides(byte aColor) { - return new ITexture[]{ - gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS[this.mTier][(0)], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), - gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[getTier()]}; - } - - @Override - public ITexture[] getFrontActive(byte aColor) { - return new ITexture[] { super.getFrontActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_MASSFAB_ACTIVE) }; - } - - @Override - public ITexture[] getBackActive(byte aColor) { - return new ITexture[] { super.getBackActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) }; - } - - @Override - public ITexture[] getBottomActive(byte aColor) { - return new ITexture[] { super.getBottomActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) }; - } - - @Override - public ITexture[] getTopActive(byte aColor) { - return new ITexture[] { super.getTopActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE_ACTIVE) }; - } - - @Override - public ITexture[] getSidesActive(byte aColor) { - return new ITexture[]{ - gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS[this.mTier][(0)], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), - gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[getTier()]}; - } - - - public int getPollution() { - return 0; - } - - @Override - public int getFuelValue(ItemStack aStack) { - if ((GT_Utility.isStackInvalid(aStack)) || (getRecipes() == null)) - return 0; - GT_Recipe tFuel = getRecipes().findRecipe(getBaseMetaTileEntity(), false, 9223372036854775807L, null, - new ItemStack[] { aStack }); - if (tFuel != null){ - this.mCurrentRecipe = tFuel; - int voltage = tFuel.mEUt; - this.mVoltage = voltage; - int sfsf = this.mTier; - //this.mDaysRemaining = tFuel.mSpecialValue*365; - - //Do some voodoo. - byte mTier2; - //mTier2 = ReflectionUtils.getField(this.getClass(), "mTier"); - try { - if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_AM241.get(1))){ - mTier2 = 1; - } - else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_PO210.get(1))){ - mTier2 = 3; - } - else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_PU238.get(1))){ - mTier2 = 2; - } - else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_SR90.get(1))){ - mTier2 = 1; - } - else { - //Utils.LOG_INFO("test:"+tFuel.mInputs[0].getDisplayName() + " | " + (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_PU238.get(1)))); - mTier2 = 0; - } - ReflectionUtils.setByte(this, "mTier", mTier2); - this.mNewTier = mTier2; - //ReflectionUtils.setFinalStatic(mTier2, GT_Values.V[0]); - } catch (Exception e) { - Logger.WARNING("Failed setting mTier."); - e.printStackTrace(); - } - - this.mTicksToBurnFor = getTotalEUGenerated(convertDaysToTicks(tFuel.mSpecialValue), voltage); - if (mTicksToBurnFor >= Integer.MAX_VALUE){ - mTicksToBurnFor = Integer.MAX_VALUE; - Logger.WARNING("Fuel went over Int limit, setting to MAX_VALUE."); - } - this.mDaysRemaining = MathUtils.roundToClosestInt(mTicksToBurnFor/20/60/3); - Logger.WARNING("step | "+(int) (mTicksToBurnFor * getEfficiency() / 100L)); - return (int) (mTicksToBurnFor * getEfficiency() / 100L); - //return (int) (tFuel.mSpecialValue * 365L * getEfficiency() / 100L); - //return tFuel.mEUt; - } - Logger.WARNING("Not sure"); - return 0; - } - - @Override - public long maxEUOutput() { - return ((getBaseMetaTileEntity().isAllowedToWork()) ? this.mVoltage : 0L); - } - - @Override - public long getOutputTier() { - if (this.mCurrentRecipe != null){ - return this.mVoltage = this.mCurrentRecipe.mEUt; - } - return 0; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public String[] getInfoData() { - return new String[] { "RTG - Running at tier "+this.mTier, - "Active: "+this.getBaseMetaTileEntity().isActive(), "Current Output: " + this.mVoltage + " EU/t", - "Days of Fuel remaining: "+(mTicksToBurnFor/20/60/20), - "Hours of Fuel remaining: "+(mTicksToBurnFor/20/60/60), - "Ticks of "+this.mVoltage+"v remaining: "+(mTicksToBurnFor), - "Current Recipe input: "+ this.mCurrentRecipe != null ? this.mCurrentRecipe.mInputs[0].getDisplayName() + " x1" : "NUll" - }; - } - -}
\ No newline at end of file + public int mEfficiency; + private int mDays; + private long mTicksToBurnFor; + private int mVoltage = 0; + private GT_Recipe mCurrentRecipe; + private int mDaysRemaining = 0; + private int mDayTick = 0; + private byte mNewTier = 0; + + public int removeDayOfTime() { + if (this.mDaysRemaining > 0) { + return this.mDaysRemaining--; + } + return this.mDaysRemaining; + } + + // Generates fuel value based on MC days + public static int convertDaysToTicks(float days) { + int value = 0; + value = MathUtils.roundToClosestInt(20 * 86400 * days); + return value; + } + + public static long getTotalEUGenerated(int ticks, int voltage) { + return ticks * voltage; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setLong("mTicksToBurnFor", this.mTicksToBurnFor); + aNBT.setInteger("mVoltage", this.mVoltage); + aNBT.setInteger("mDaysRemaining", this.mDaysRemaining); + aNBT.setInteger("mDayTick", this.mDayTick); + aNBT.setByte("mNewTier", this.mNewTier); + + if (this.mCurrentRecipe != null) { + final NBTTagList list = new NBTTagList(); + final ItemStack stack = this.mCurrentRecipe.mInputs[0]; + if (stack != null) { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("mSlot", 0); + list.appendTag(data); + } + aNBT.setTag("mRecipeItem", list); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + // this.mMachineBlock = aNBT.getByte("mMachineBlock"); + this.mTicksToBurnFor = aNBT.getLong("mTicksToBurnFor"); + this.mVoltage = aNBT.getInteger("mVoltage"); + this.mDaysRemaining = aNBT.getInteger("mDaysRemaining"); + this.mDayTick = aNBT.getInteger("mDayTick"); + this.mNewTier = aNBT.getByte("mNewTier"); + + try { + ReflectionUtils.setByte(this, "mTier", this.mNewTier); + } catch (Exception e) { + if (this.getBaseMetaTileEntity() != null) { + IGregTechTileEntity thisTile = this.getBaseMetaTileEntity(); + if (thisTile.isAllowedToWork() || thisTile.isActive()) { + thisTile.setActive(false); + } + } + } + + final NBTTagList list = aNBT.getTagList("mRecipeItem", 10); + final NBTTagCompound data = list.getCompoundTagAt(0); + ItemStack lastUsedFuel = ItemStack.loadItemStackFromNBT(data); + if (lastUsedFuel != null) { + this.mCurrentRecipe = getRecipes() + .findRecipe( + getBaseMetaTileEntity(), false, 9223372036854775807L, null, new ItemStack[] {lastUsedFuel}); + } + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mDayTick < 24000) { + this.mDayTick++; + } else if (this.mDayTick >= 24000) { + this.mDayTick = 0; + this.mDaysRemaining = this.removeDayOfTime(); + } + } + + if ((aBaseMetaTileEntity.isServerSide()) && (aBaseMetaTileEntity.isAllowedToWork()) && (aTick % 10L == 0L)) { + long tProducedEU = 0L; + if (this.mFluid == null) { + if (aBaseMetaTileEntity.getUniversalEnergyStored() < maxEUOutput() + getMinimumStoredEU()) { + this.mInventory[getStackDisplaySlot()] = null; + } else { + if (this.mInventory[getStackDisplaySlot()] == null) + this.mInventory[getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); + this.mInventory[getStackDisplaySlot()].setStackDisplayName("Generating: " + + (aBaseMetaTileEntity.getUniversalEnergyStored() - getMinimumStoredEU()) + " EU"); + } + } else { + int tFuelValue = getFuelValue(this.mFluid); + int tConsumed = consumedFluidPerOperation(this.mFluid); + if ((tFuelValue > 0) && (tConsumed > 0) && (this.mFluid.amount > tConsumed)) { + long tFluidAmountToUse = Math.min( + this.mFluid.amount / tConsumed, + (maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue); + if ((tFluidAmountToUse > 0L) + && (aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true))) { + tProducedEU = tFluidAmountToUse * tFuelValue; + FluidStack tmp260_257 = this.mFluid; + tmp260_257.amount = (int) (tmp260_257.amount - (tFluidAmountToUse * tConsumed)); + } + } + } + if ((this.mInventory[getInputSlot()] != null) + && (aBaseMetaTileEntity.getUniversalEnergyStored() < maxEUOutput() * 20L + getMinimumStoredEU()) + && (GT_Utility.getFluidForFilledItem(this.mInventory[getInputSlot()], true) == null)) { + int tFuelValue = getFuelValue(this.mInventory[getInputSlot()]); + if (tFuelValue > 0) { + ItemStack tEmptyContainer = getEmptyContainer(this.mInventory[getInputSlot()]); + if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), tEmptyContainer)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); + aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); + tProducedEU = tFuelValue; + } + } + } + if ((tProducedEU > 0L) && (getPollution() > 0)) { + PollutionUtils.addPollution( + aBaseMetaTileEntity, (int) (tProducedEU * getPollution() / 500 * this.mTier + 1L)); + } + } + + if (aBaseMetaTileEntity.isServerSide()) + aBaseMetaTileEntity.setActive((aBaseMetaTileEntity.isAllowedToWork()) + && (aBaseMetaTileEntity.getUniversalEnergyStored() >= maxEUOutput() + getMinimumStoredEU())); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Fuel is measured in minecraft days (Check with Scanner)", + "RTG changes output voltage depending on fuel", + "Generates power at " + this.getEfficiency() + "% Efficiency per tick", + "Output Voltage: " + this.getOutputTier() + " EU/t", + CORE.GT_Tooltip + }; + } + + public GregtechMetaTileEntity_RTG(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, "Requires RTG Pellets", new ITexture[0]); + } + + private byte getTier() { + int voltage = this.mVoltage; + if (voltage >= 512) { + return 4; + } else if (voltage >= 128) { + return 3; + } else if (voltage >= 32) { + return 2; + } else if (voltage >= 8) { + return 1; + } + return 0; + } + + public GregtechMetaTileEntity_RTG(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public boolean isOutputFacing(byte aSide) { + return ((aSide > 1) + && (aSide != getBaseMetaTileEntity().getFrontFacing()) + && (aSide != getBaseMetaTileEntity().getBackFacing())); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_RTG(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipes() { + return GTPP_Recipe.GTPP_Recipe_Map.sRTGFuels; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public int getEfficiency() { + return this.mEfficiency = 100; + } + + @Override + public ITexture[] getFront(byte aColor) { + return new ITexture[] { + super.getFront(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_MASSFAB) + }; + } + + @Override + public ITexture[] getBack(byte aColor) { + return new ITexture[] { + super.getBack(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP) + }; + } + + @Override + public ITexture[] getBottom(byte aColor) { + return new ITexture[] { + super.getBottom(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP) + }; + } + + @Override + public ITexture[] getTop(byte aColor) { + return new ITexture[] { + super.getTop(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP), + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE) + }; + } + + @Override + public ITexture[] getSides(byte aColor) { + return new ITexture[] { + gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS[this.mTier][(0)], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[getTier()] + }; + } + + @Override + public ITexture[] getFrontActive(byte aColor) { + return new ITexture[] { + super.getFrontActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_MASSFAB_ACTIVE) + }; + } + + @Override + public ITexture[] getBackActive(byte aColor) { + return new ITexture[] { + super.getBackActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) + }; + } + + @Override + public ITexture[] getBottomActive(byte aColor) { + return new ITexture[] { + super.getBottomActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) + }; + } + + @Override + public ITexture[] getTopActive(byte aColor) { + return new ITexture[] { + super.getTopActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE_ACTIVE) + }; + } + + @Override + public ITexture[] getSidesActive(byte aColor) { + return new ITexture[] { + gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS[this.mTier][(0)], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[getTier()] + }; + } + + public int getPollution() { + return 0; + } + + @Override + public int getFuelValue(ItemStack aStack) { + if ((GT_Utility.isStackInvalid(aStack)) || (getRecipes() == null)) return 0; + GT_Recipe tFuel = getRecipes() + .findRecipe(getBaseMetaTileEntity(), false, 9223372036854775807L, null, new ItemStack[] {aStack}); + if (tFuel != null) { + this.mCurrentRecipe = tFuel; + int voltage = tFuel.mEUt; + this.mVoltage = voltage; + int sfsf = this.mTier; + // this.mDaysRemaining = tFuel.mSpecialValue*365; + + // Do some voodoo. + byte mTier2; + // mTier2 = ReflectionUtils.getField(this.getClass(), "mTier"); + try { + if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_AM241.get(1))) { + mTier2 = 1; + } else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_PO210.get(1))) { + mTier2 = 3; + } else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_PU238.get(1))) { + mTier2 = 2; + } else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_SR90.get(1))) { + mTier2 = 1; + } else { + // Utils.LOG_INFO("test:"+tFuel.mInputs[0].getDisplayName() + " | " + + // (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_PU238.get(1)))); + mTier2 = 0; + } + ReflectionUtils.setByte(this, "mTier", mTier2); + this.mNewTier = mTier2; + // ReflectionUtils.setFinalStatic(mTier2, GT_Values.V[0]); + } catch (Exception e) { + Logger.WARNING("Failed setting mTier."); + e.printStackTrace(); + } + + this.mTicksToBurnFor = getTotalEUGenerated(convertDaysToTicks(tFuel.mSpecialValue), voltage); + if (mTicksToBurnFor >= Integer.MAX_VALUE) { + mTicksToBurnFor = Integer.MAX_VALUE; + Logger.WARNING("Fuel went over Int limit, setting to MAX_VALUE."); + } + this.mDaysRemaining = MathUtils.roundToClosestInt(mTicksToBurnFor / 20 / 60 / 3); + Logger.WARNING("step | " + (int) (mTicksToBurnFor * getEfficiency() / 100L)); + return (int) (mTicksToBurnFor * getEfficiency() / 100L); + // return (int) (tFuel.mSpecialValue * 365L * getEfficiency() / 100L); + // return tFuel.mEUt; + } + Logger.WARNING("Not sure"); + return 0; + } + + @Override + public long maxEUOutput() { + return ((getBaseMetaTileEntity().isAllowedToWork()) ? this.mVoltage : 0L); + } + + @Override + public long getOutputTier() { + if (this.mCurrentRecipe != null) { + return this.mVoltage = this.mCurrentRecipe.mEUt; + } + return 0; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public String[] getInfoData() { + return new String[] { + "RTG - Running at tier " + this.mTier, + "Active: " + this.getBaseMetaTileEntity().isActive(), + "Current Output: " + this.mVoltage + " EU/t", + "Days of Fuel remaining: " + (mTicksToBurnFor / 20 / 60 / 20), + "Hours of Fuel remaining: " + (mTicksToBurnFor / 20 / 60 / 60), + "Ticks of " + this.mVoltage + "v remaining: " + (mTicksToBurnFor), + "Current Recipe input: " + this.mCurrentRecipe != null + ? this.mCurrentRecipe.mInputs[0].getDisplayName() + " x1" + : "NUll" + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_CombustionGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_CombustionGenerator.java index 58919f0954..3398ad0fc6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_CombustionGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_CombustionGenerator.java @@ -15,25 +15,27 @@ public class GT_MetaTileEntity_ULV_CombustionGenerator extends GT_MetaTileEntity super(aID, aName, aNameRegional, aTier); } - public GT_MetaTileEntity_ULV_CombustionGenerator(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + public GT_MetaTileEntity_ULV_CombustionGenerator( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aDescription, aTextures); } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - "Produces "+(this.getPollution()*20)+" pollution/sec", - "Fuel Efficiency: "+this.getEfficiency() + "%", - CORE.GT_Tooltip}; - } @Override - public long maxEUStore() { + public String[] getDescription() { + return new String[] { + this.mDescription, + "Produces " + (this.getPollution() * 20) + " pollution/sec", + "Fuel Efficiency: " + this.getEfficiency() + "%", + CORE.GT_Tooltip + }; + } + + @Override + public long maxEUStore() { return Math.max(getEUVar(), V[1] * 80L + getMinimumStoredEU()); - } + } - @Override + @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_ULV_CombustionGenerator(this.mName, this.mTier, this.mDescription, this.mTextures); } @@ -45,6 +47,7 @@ public class GT_MetaTileEntity_ULV_CombustionGenerator extends GT_MetaTileEntity @Override public void onConfigLoad() { - this.mEfficiency = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "DieselGenerator.efficiency.tier." + this.mTier, 95); + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, "DieselGenerator.efficiency.tier." + this.mTier, 95); } -}
\ No newline at end of file +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_GasTurbine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_GasTurbine.java index 17bb4463c4..b8f8004dad 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_GasTurbine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_GasTurbine.java @@ -21,20 +21,21 @@ public class GT_MetaTileEntity_ULV_GasTurbine extends GT_MetaTileEntity_GasTurbi public GT_MetaTileEntity_ULV_GasTurbine(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aDescription, aTextures); } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - "Produces "+(this.getPollution()*20)+" pollution/sec", - "Fuel Efficiency: "+this.getEfficiency() + "%", - CORE.GT_Tooltip}; - } @Override - public long maxEUStore() { + public String[] getDescription() { + return new String[] { + this.mDescription, + "Produces " + (this.getPollution() * 20) + " pollution/sec", + "Fuel Efficiency: " + this.getEfficiency() + "%", + CORE.GT_Tooltip + }; + } + + @Override + public long maxEUStore() { return Math.max(getEUVar(), V[1] * 80L + getMinimumStoredEU()); - } + } public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_ULV_GasTurbine(this.mName, this.mTier, this.mDescription, this.mTextures); @@ -47,13 +48,15 @@ public class GT_MetaTileEntity_ULV_GasTurbine extends GT_MetaTileEntity_GasTurbi @Override public void onConfigLoad() { - this.mEfficiency = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "GasTurbine.efficiency.tier." + this.mTier, 95); + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, "GasTurbine.efficiency.tier." + this.mTier, 95); } @Override public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{super.getSidesActive(aColor)[0], - new GT_RenderedTexture((IIconContainer) TexturesGtBlock.Overlay_Machine_Turbine_Active)}; - } - -}
\ No newline at end of file + return new ITexture[] { + super.getSidesActive(aColor)[0], + new GT_RenderedTexture((IIconContainer) TexturesGtBlock.Overlay_Machine_Turbine_Active) + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_SteamTurbine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_SteamTurbine.java index ef3310c6fc..09e3e3201c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_SteamTurbine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_SteamTurbine.java @@ -21,20 +21,21 @@ public class GT_MetaTileEntity_ULV_SteamTurbine extends GT_MetaTileEntity_SteamT public GT_MetaTileEntity_ULV_SteamTurbine(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aDescription, aTextures); } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - "Produces "+(this.getPollution()*20)+" pollution/sec", - "Fuel Efficiency: "+this.getEfficiency() + "%", - CORE.GT_Tooltip}; - } @Override - public long maxEUStore() { + public String[] getDescription() { + return new String[] { + this.mDescription, + "Produces " + (this.getPollution() * 20) + " pollution/sec", + "Fuel Efficiency: " + this.getEfficiency() + "%", + CORE.GT_Tooltip + }; + } + + @Override + public long maxEUStore() { return Math.max(getEUVar(), V[1] * 80L + getMinimumStoredEU()); - } + } public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_ULV_SteamTurbine(this.mName, this.mTier, this.mDescription, this.mTextures); @@ -44,15 +45,18 @@ public class GT_MetaTileEntity_ULV_SteamTurbine extends GT_MetaTileEntity_SteamT public int getCapacity() { return 16000; } - + @Override public void onConfigLoad() { - this.mEfficiency = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "SteamTurbine.efficiency.tier." + this.mTier, 6 + 1); + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, "SteamTurbine.efficiency.tier." + this.mTier, 6 + 1); } @Override public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{super.getSidesActive(aColor)[0], - new GT_RenderedTexture((IIconContainer) TexturesGtBlock.Overlay_Machine_Turbine_Active)}; - } + return new ITexture[] { + super.getSidesActive(aColor)[0], + new GT_RenderedTexture((IIconContainer) TexturesGtBlock.Overlay_Machine_Turbine_Active) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/creative/GregtechMetaCreativeEnergyBuffer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/creative/GregtechMetaCreativeEnergyBuffer.java index 087da7465d..fb2af1cd44 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/creative/GregtechMetaCreativeEnergyBuffer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/creative/GregtechMetaCreativeEnergyBuffer.java @@ -2,9 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.generators.creative; import static gregtech.api.enums.GT_Values.V; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -21,6 +18,8 @@ import gtPlusPlus.core.util.sys.KeyboardUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; import gtPlusPlus.xmod.gregtech.common.tileentities.storage.GregtechMetaEnergyBuffer; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -36,198 +35,229 @@ import net.minecraft.world.World; */ public class GregtechMetaCreativeEnergyBuffer extends GregtechMetaEnergyBuffer { - private int mVoltageTier = 3; - - public GregtechMetaCreativeEnergyBuffer(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { - super(aName, aTier, aDescription, aTextures, aSlotCount); - // TODO Auto-generated constructor stub - } - - public GregtechMetaCreativeEnergyBuffer(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aDescription, aSlotCount); - } - - @Override - public String[] getDescription() { - return new String[]{this.mDescription, "Use Screwdriver to change voltage", "Hold Shift while using Screwdriver to change amperage", EnumChatFormatting.GREEN - + "CREATIVE MACHINE", CORE.GT_Tooltip}; - } - - /* - * MACHINE_STEEL_SIDE - */ - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - CustomIcon h = TexturesGtBlock.Casing_Material_RedSteel; - CustomIcon g = TexturesGtBlock.Casing_Material_Grisium; - CustomIcon k; - boolean j = MathUtils.isNumberEven(this.mVoltageTier); - final ITexture[][][] rTextures = new ITexture[2][17][]; - k = j ? g : h; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = new ITexture[]{new GT_RenderedTexture(k)}; - rTextures[1][i - + 1] = new ITexture[]{new GT_RenderedTexture(k), this.mInventory.length > 4 ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mVoltageTier] : Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mVoltageTier]}; - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[aSide == aFacing ? 1 : 0][aColorIndex + 1]; - } - - @Override - protected void showEnergy(final World worldIn, final EntityPlayer playerIn){ - final long tempStorage = this.getBaseMetaTileEntity().getStoredEU(); - final double c = ((double) tempStorage / this.maxEUStore()) * 100; - final double roundOff = Math.round(c * 100.00) / 100.00; - PlayerUtils.messagePlayer(playerIn, "Energy: " + GT_Utility.formatNumbers(tempStorage) + " EU at "+V[this.mVoltageTier]+"v ("+roundOff+"%)"); - PlayerUtils.messagePlayer(playerIn, "Amperage: " + GT_Utility.formatNumbers(maxAmperesOut())+"A"); - - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaCreativeEnergyBuffer(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); - } - - @Override - public long getMinimumStoredEU() { - return 0; - } - - @Override - public long maxEUStore() { - return Long.MAX_VALUE; - } - - @Override - public long maxEUInput() { - return V[mVoltageTier]; - } - - @Override - public long maxEUOutput() { - return V[mVoltageTier]; - } - - @Override - public long maxAmperesIn() { - return aCurrentOutputAmperage; - } - - @Override - public long maxAmperesOut() { - return aCurrentOutputAmperage; - } - - @Override - public int getProgresstime() { - return Integer.MAX_VALUE; - } - @Override - public int maxProgresstime() { - return Integer.MAX_VALUE; - } - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - aBaseMetaTileEntity.increaseStoredEnergyUnits(Integer.MAX_VALUE, true); - } - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public String[] getInfoData() { - String[] infoData = super.getInfoData(); - return new String[]{infoData[0], "THIS IS A CREATIVE ITEM - FOR TESTING | Tier: " + this.mVoltageTier, infoData[1], infoData[2]}; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mVoltageTier", this.mVoltageTier); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - this.mVoltageTier = aNBT.getInteger("mVoltageTier"); - super.loadNBTData(aNBT); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (KeyboardUtils.isShiftKeyDown()) { - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - else { - if (this.mVoltageTier < (GT_Values.VN[9].equals("UHV") ? GT_Values.V.length - 1 : 9)) { - this.mVoltageTier++; - } - else { - this.mVoltageTier = 0; - } - this.markDirty(); - try { - Field field = ReflectionUtils.getField(this.getClass(), "mTextures"); - field.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - ITexture[][][] V = getTextureSet(null); - if (V != null) { - Logger.REFLECTION("Got Valid Textures."); - if (this.getBaseMetaTileEntity().isClientSide()) { - Logger.REFLECTION("Clientside Call."); - Logger.REFLECTION("Refreshing Textures on buffer."); - field.set(this, V); - Logger.REFLECTION("Refreshed Textures on buffer."); - } - else { - Logger.REFLECTION("Serverside Call."); - } - } - else { - Logger.REFLECTION("Bad mTextures setter."); - } - } - catch (Throwable t) { - // Bad refresh. - t.printStackTrace(); - Logger.REFLECTION("Bad mTextures setter."); - } - PlayerUtils.messagePlayer(aPlayer, "Now running at " + GT_Values.VOLTAGE_NAMES[this.mVoltageTier] + "."); - } - - } + private int mVoltageTier = 3; + + public GregtechMetaCreativeEnergyBuffer( + final String aName, + final int aTier, + final String aDescription, + final ITexture[][][] aTextures, + final int aSlotCount) { + super(aName, aTier, aDescription, aTextures, aSlotCount); + // TODO Auto-generated constructor stub + } + + public GregtechMetaCreativeEnergyBuffer( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aDescription, aSlotCount); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Use Screwdriver to change voltage", + "Hold Shift while using Screwdriver to change amperage", + EnumChatFormatting.GREEN + "CREATIVE MACHINE", + CORE.GT_Tooltip + }; + } + + /* + * MACHINE_STEEL_SIDE + */ + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + CustomIcon h = TexturesGtBlock.Casing_Material_RedSteel; + CustomIcon g = TexturesGtBlock.Casing_Material_Grisium; + CustomIcon k; + boolean j = MathUtils.isNumberEven(this.mVoltageTier); + final ITexture[][][] rTextures = new ITexture[2][17][]; + k = j ? g : h; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = new ITexture[] {new GT_RenderedTexture(k)}; + rTextures[1][i + 1] = new ITexture[] { + new GT_RenderedTexture(k), + this.mInventory.length > 4 + ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mVoltageTier] + : Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mVoltageTier] + }; + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[aSide == aFacing ? 1 : 0][aColorIndex + 1]; + } + + @Override + protected void showEnergy(final World worldIn, final EntityPlayer playerIn) { + final long tempStorage = this.getBaseMetaTileEntity().getStoredEU(); + final double c = ((double) tempStorage / this.maxEUStore()) * 100; + final double roundOff = Math.round(c * 100.00) / 100.00; + PlayerUtils.messagePlayer( + playerIn, + "Energy: " + GT_Utility.formatNumbers(tempStorage) + " EU at " + V[this.mVoltageTier] + "v (" + roundOff + + "%)"); + PlayerUtils.messagePlayer(playerIn, "Amperage: " + GT_Utility.formatNumbers(maxAmperesOut()) + "A"); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaCreativeEnergyBuffer( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return Long.MAX_VALUE; + } + + @Override + public long maxEUInput() { + return V[mVoltageTier]; + } + + @Override + public long maxEUOutput() { + return V[mVoltageTier]; + } + + @Override + public long maxAmperesIn() { + return aCurrentOutputAmperage; + } + + @Override + public long maxAmperesOut() { + return aCurrentOutputAmperage; + } + + @Override + public int getProgresstime() { + return Integer.MAX_VALUE; + } + + @Override + public int maxProgresstime() { + return Integer.MAX_VALUE; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.increaseStoredEnergyUnits(Integer.MAX_VALUE, true); + } + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + String[] infoData = super.getInfoData(); + return new String[] { + infoData[0], "THIS IS A CREATIVE ITEM - FOR TESTING | Tier: " + this.mVoltageTier, infoData[1], infoData[2] + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mVoltageTier", this.mVoltageTier); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mVoltageTier = aNBT.getInteger("mVoltageTier"); + super.loadNBTData(aNBT); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (KeyboardUtils.isShiftKeyDown()) { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } else { + if (this.mVoltageTier < (GT_Values.VN[9].equals("UHV") ? GT_Values.V.length - 1 : 9)) { + this.mVoltageTier++; + } else { + this.mVoltageTier = 0; + } + this.markDirty(); + try { + Field field = ReflectionUtils.getField(this.getClass(), "mTextures"); + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + ITexture[][][] V = getTextureSet(null); + if (V != null) { + Logger.REFLECTION("Got Valid Textures."); + if (this.getBaseMetaTileEntity().isClientSide()) { + Logger.REFLECTION("Clientside Call."); + Logger.REFLECTION("Refreshing Textures on buffer."); + field.set(this, V); + Logger.REFLECTION("Refreshed Textures on buffer."); + } else { + Logger.REFLECTION("Serverside Call."); + } + } else { + Logger.REFLECTION("Bad mTextures setter."); + } + } catch (Throwable t) { + // Bad refresh. + t.printStackTrace(); + Logger.REFLECTION("Bad mTextures setter."); + } + PlayerUtils.messagePlayer(aPlayer, "Now running at " + GT_Values.VOLTAGE_NAMES[this.mVoltageTier] + "."); + } + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java index 4651121500..2847a15539 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; -import java.util.*; - import gregtech.api.enums.*; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -18,6 +16,7 @@ import gtPlusPlus.xmod.gregtech.api.gui.basic.*; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import ic2.api.crops.*; import ic2.core.item.DamageHandler; +import java.util.*; import net.minecraft.entity.player.*; import net.minecraft.item.*; import net.minecraft.nbt.NBTTagCompound; @@ -25,668 +24,709 @@ import net.minecraft.tileentity.TileEntity; public class GT_MetaTileEntity_CropHarvestor extends GT_MetaTileEntity_BasicTank { - protected String mLocalName; - - private static final int SLOT_WEEDEX_1 = 1; - private static final int SLOT_WEEDEX_2 = 2; - private static final int SLOT_FERT_1 = 3; - private static final int SLOT_FERT_4 = 6; - private static final int SLOT_OUTPUT_START = 7; - - public boolean mModeAlternative = false; - - public GT_MetaTileEntity_CropHarvestor(final int aID, final int aTier, final String aDescription) { - super(aID, "basicmachine.cropharvester.0"+aTier, "Crop Manager ("+GT_Values.VN[aTier]+")", aTier, 21, aDescription); - this.mLocalName = "Crop Manager ("+GT_Values.VN[aTier]+")"; - } - - public GT_MetaTileEntity_CropHarvestor(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, 21, aDescription, aTextures); - this.mLocalName = "Crop Manager ("+GT_Values.VN[aTier]+")"; - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_CropHarvestor(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_CropHarvestor(aPlayerInventory, aBaseMetaTileEntity, this.mLocalName); - } - - @Override - public boolean isTransformerUpgradable() { - return true; - } - - @Override - public boolean isOverclockerUpgradable() { - return true; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isInputFacing(byte aSide) { - return true; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isElectric() { - return true; - } - - @Override - public long maxAmperesIn() { - return 8; - } - - @Override - public long getMinimumStoredEU() { - return GT_Values.V[this.mTier]; - } - - @Override - public long maxEUStore() { - return GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier]); - } - - @Override - public long maxEUInput() { - return GT_Values.V[this.mTier]; - } - - @Override - public int getCapacity() { - return 32000 * this.mTier; - } - - @Override - public int getTankPressure() { - return -100; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_CropHarvestor(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public int getSizeInventory() { - return 21; - } - - private static final int getRange(int aTier) { - switch(aTier) { - case 1: - return 1; - case 2: - return 5; - case 3: - return 9; - case 4: - return 13; - case 5: - return 17; - case 6: - return 21; - case 7: - return 25; - case 8: - return 29; - case 9: - return 33; - default: - return 0; - } - } - - private HashSet<ICropTile> mCropCache = new HashSet<ICropTile>(); - private boolean mInvalidCache = false; - - public boolean doesInventoryHaveSpace() { - for (int i = SLOT_OUTPUT_START; i < this.getSizeInventory(); i++) { - if (this.mInventory[i] == null || this.mInventory[i].stackSize < 64) { - return true; - } - } - return false; - } - - public long powerUsage() { - return this.maxEUInput() / 8; - } - - public long powerUsageSecondary() { - return this.maxEUInput() / 32; - } - - - public static AutoMap<ItemStack> splitOutputStacks(ItemStack aOutput) { - return splitOutputStacks(new ItemStack[] {aOutput}); - } - - public static AutoMap<ItemStack> splitOutputStacks(ItemStack[] aOutputs) { - AutoMap<ItemStack> aOutputMap = new AutoMap<ItemStack>(); - for (ItemStack aStack : aOutputs) { - if (aStack != null) { - if (aStack.stackSize <= 64) { - aOutputMap.add(aStack); - } else { - int aStacks = 0; - int aExcess = 0; - int aOriginalSize = aStack.stackSize; - while (aOriginalSize >= 64) { - aStacks += 1; - aOriginalSize -= 64; - } - aExcess = aOriginalSize; - for (int i = 0; i < aStacks; i++) { - aOutputMap.add(ItemUtils.getSimpleStack(aStack, 64)); - } - aOutputMap.add(ItemUtils.getSimpleStack(aStack, aExcess)); - } - } - } - return aOutputMap; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (getBaseMetaTileEntity().isServerSide() && getBaseMetaTileEntity().isAllowedToWork() && (getBaseMetaTileEntity().hasWorkJustBeenEnabled() || aTick % 100 == 0)) { - if (this.getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU()) { - - int aTileX = this.getBaseMetaTileEntity().getXCoord(); - int aTileY = this.getBaseMetaTileEntity().getXCoord(); - int aTileZ = this.getBaseMetaTileEntity().getXCoord(); - - int aRadius = 10 + getRange(this.mTier); - int aSide = (aRadius-1)/2; - ArrayList<ItemStack> aAllDrops = new ArrayList<ItemStack>(); - - if (this.mCropCache.isEmpty() || aTick % 1200 == 0 || this.mInvalidCache) { - if (!this.mCropCache.isEmpty()) { - this.mCropCache.clear(); - } - //Logger.INFO("Looking for crops."); - for (int y = 0; y <= 2; y++) { - for (int x = (-aSide); x <= aSide; x++) { - for (int z = (-aSide); z <= aSide; z++) { - TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityOffset(x, y, z); - if (tTileEntity != null && tTileEntity instanceof ICropTile) { - ICropTile tCrop = (ICropTile) tTileEntity; - this.mCropCache.add(tCrop); - } - } - } - } - } - - //Process Cache - if (doesInventoryHaveSpace()) { - for (ICropTile tCrop : this.mCropCache) { - if (tCrop == null) { - this.mInvalidCache = true; - break; - } - CropCard aCrop = tCrop.getCrop(); - if (aCrop != null) { - //Logger.INFO("Found "+aCrop.displayName()+" at offset "+x+", "+y+", "+z); - if (!aCrop.canGrow(tCrop) && aCrop.canBeHarvested(tCrop)) { - if (getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsage(), true)) { - ItemStack[] aHarvest = tCrop.harvest_automated(true); - if (aHarvest != null && aHarvest.length > 0) { - for (ItemStack aStack : aHarvest) { - if (aStack.stackSize > 0) { - if (this.mTier * 5 > MathUtils.randInt(1, 100)) { - aStack.stackSize += Math.floor(tCrop.getGain()/10); - Logger.INFO("Bonus output given for "+aCrop.displayName()); - } - Logger.INFO("Harvested "+aCrop.displayName()); - aAllDrops.addAll(splitOutputStacks(aStack)); - } - } - } - } - } - if (this.mModeAlternative) { - processSecondaryFunctions(tCrop); - } - } - } - - if (!aAllDrops.isEmpty()) { - Logger.INFO("Handling "+aAllDrops.size()+" Harvests"); - Iterator<ItemStack> iter = aAllDrops.iterator(); - while (iter.hasNext()) { - ItemStack aDrop = iter.next(); - if (ItemUtils.checkForInvalidItems(aDrop)) { - - for (int i = SLOT_OUTPUT_START; i < this.getSizeInventory(); i++) { - if (this.mInventory[i] != null) { - //Logger.INFO("Slot "+i+" contains "+this.mInventory[i].getDisplayName()); - if (GT_Utility.areStacksEqual(aDrop, this.mInventory[i], false)) { - //Same - if (this.mInventory[i].stackSize < 64 && (this.mInventory[i].stackSize + aDrop.stackSize <= 64)) { - //can merge - //Logger.INFO("Slot "+i+" size: "+mInventory[i].stackSize+" + Drop Size: "+aDrop.stackSize+" = "+(mInventory[i].stackSize + aDrop.stackSize)); - this.mInventory[i].stackSize += aDrop.stackSize; - break; - } - else if (this.mInventory[i].stackSize < 64 && (this.mInventory[i].stackSize + aDrop.stackSize > 64)) { - //can merge - //Logger.INFO("Slot "+i+" size: "+mInventory[i].stackSize+" + Drop Size: "+aDrop.stackSize+" = "+(mInventory[i].stackSize + aDrop.stackSize)); - int aRemainder = this.mInventory[i].stackSize + aDrop.stackSize - 64; - Logger.INFO("Remainder: "+aRemainder+", Continuing."); - this.mInventory[i].stackSize = 64; - aDrop.stackSize = aRemainder; - continue; - } - else { - //Logger.INFO("Slot "+i+" size: 64, Continuing."); - continue; - } - } - } - else { - //Logger.INFO("Slot "+i+" is empty, setting to "+aDrop.getDisplayName()+" x"+aDrop.stackSize); - this.mInventory[i] = aDrop; - break; - } - } - } - - } - } - } - } - } - } - - public boolean hasFertilizer() { - for (int i = SLOT_FERT_1; i <= SLOT_FERT_4; i++) { - if (this.mInventory[i] != null) { - return true; - } - } - return false; - } - - public boolean consumeFertilizer(boolean aSimulate) { - if (hasFertilizer()) { - for (int i = SLOT_FERT_1; i <= SLOT_FERT_4; i++) { - if (this.mInventory[i] != null) { - consume(i, 1, aSimulate); - return true; - } - } - } - return false; - } - - public boolean hasWeedEX() { - for (int i = SLOT_WEEDEX_1; i <= SLOT_WEEDEX_2; i++) { - if (this.mInventory[i] != null) { - return true; - } - } - return false; - } - - public boolean consumeWeedEX(boolean aSimulate) { - if (hasWeedEX()) { - for (int i = SLOT_WEEDEX_1; i <= SLOT_WEEDEX_2; i++) { - if (this.mInventory[i] != null) { - damage(i, 1, aSimulate); - return true; - } - } - } - return false; - } - - public void processSecondaryFunctions(ICropTile aCrop) { - if (!this.mModeAlternative) { - return; - } - if (hasFertilizer() && consumeFertilizer(true) && this.getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU() && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) && applyFertilizer(aCrop)) { - if (consumeFertilizer(false)) { - //Logger.INFO("Consumed Fert."); - } - } - if (this.getFluidAmount() > 0 && this.getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU() && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) && applyHydration(aCrop)) { - //Logger.INFO("Consumed Water."); - } - if (hasWeedEX() && consumeWeedEX(true) && this.getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU() && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) && applyWeedEx(aCrop)) { - if (consumeWeedEX(false)) { - //Logger.INFO("Consumed Weed-EX."); - } - } - } - - - public boolean applyWeedEx(ICropTile aCrop) { - if (aCrop.getWeedExStorage() < 150) { - aCrop.setWeedExStorage(aCrop.getWeedExStorage() + 50); - boolean triggerDecline; - triggerDecline = aCrop.getWorld().rand.nextInt(3) == 0; - if (aCrop.getCrop() != null && aCrop.getCrop().isWeed(aCrop) && aCrop.getWeedExStorage() >= 75 && triggerDecline) { - switch (aCrop.getWorld().rand.nextInt(5)) { - case 0 : - if (aCrop.getGrowth() > 0) { - aCrop.setGrowth((byte) (aCrop.getGrowth() - 1)); - } - case 1 : - if (aCrop.getGain() > 0) { - aCrop.setGain((byte) (aCrop.getGain() - 1)); - } - default : - if (aCrop.getResistance() > 0) { - aCrop.setResistance((byte) (aCrop.getResistance() - 1)); - } - } - } - return true; - } else { - return false; - } - } - - public boolean applyFertilizer(ICropTile aCrop) { - if (aCrop.getNutrientStorage() >= 100) { - return false; - } else { - //Logger.INFO("Current Nutrient: "+aCrop.getNutrientStorage()+" for "+aCrop.getCrop().displayName()); - aCrop.setNutrientStorage(aCrop.getNutrientStorage() + 100); - return true; - } - } - - public boolean applyHydration(ICropTile aCrop) { - if (aCrop.getHydrationStorage() >= 200 || this.getFluidAmount() == 0) { - //Logger.INFO("Hydration Max"); - return false; - } else { - int apply = 200 - aCrop.getHydrationStorage(); - if (this.getFluidAmount() >= 0) { - int drain = 0; - if (this.getFluidAmount() >= apply) { - drain = apply; - } - else { - drain = this.getFluidAmount(); - } - this.mFluid.amount -= drain; - if (this.mFluid.amount <= 0) { - this.mFluid = null; - } - //Logger.INFO("Did Hydrate"); - aCrop.setHydrationStorage(aCrop.getHydrationStorage() + drain); - return true; - } - else { - //Logger.INFO("No water?"); - return false; - } - } - } - - public boolean consume(int aSlot, int amount, boolean simulate) { - ItemStack stack = this.mInventory[aSlot]; - if (stack != null && stack.stackSize >= amount) { - int currentAmount = Math.min(amount, stack.stackSize); - amount -= currentAmount; - if (!simulate) { - if (stack.stackSize == currentAmount) { - this.mInventory[aSlot] = null; - } else { - stack.stackSize -= currentAmount; - } - } - else { - return amount >= 0; - } - return true; - } - return false; - } - - public ItemStack damage(int aSlot, int amount, boolean simulate) { - ItemStack ret = null; - int damageApplied = 0; - ItemStack stack = this.mInventory[aSlot]; - Item item = stack.getItem(); - if (stack != null && item.isDamageable() && (ret == null - || stack.getItem() == ret.getItem() && ItemStack.areItemStackTagsEqual(stack, ret))) { - if (simulate) { - stack = stack.copy(); - } - int maxDamage = DamageHandler.getMaxDamage(stack); - while (amount > 0 && stack.stackSize > 0) { - int currentAmount = Math.min(amount, maxDamage - DamageHandler.getDamage(stack)); - DamageHandler.damage(stack, currentAmount, null); - damageApplied += currentAmount; - amount -= currentAmount; - if (DamageHandler.getDamage(stack) >= maxDamage) { - --stack.stackSize; - DamageHandler.setDamage(stack, 0); - } - - if (ret == null) { - ret = stack.copy(); - } - } - if (stack.stackSize == 0 && !simulate) { - this.mInventory[aSlot] = null; - } - } - - if (ret != null) { - int i = DamageHandler.getMaxDamage(ret); - ret.stackSize = damageApplied / i; - DamageHandler.setDamage(ret, damageApplied % i); - } - return ret; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aStack != null && aIndex >= SLOT_OUTPUT_START && aIndex < this.getSizeInventory(); - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - if (aStack != null) { - if (aStack.getItem().getUnlocalizedName().equals("ic2.itemFertilizer")) { - return aIndex >= SLOT_FERT_1 && aIndex <= SLOT_FERT_4; - } - else if (aStack.getItem().getUnlocalizedName().equals("ic2.itemWeedEx")) { - return aIndex >= SLOT_WEEDEX_1 && aIndex <= SLOT_WEEDEX_2; - } - } - return false; - } - - @Override - public String[] getDescription() { - int aRadius = 10 + getRange(this.mTier); - int aSide = (aRadius-1)/2; - return new String[] { - this.mDescription, - "Secondary mode can Hydrate/Fertilize/Weed-EX", - "Consumes "+powerUsage()+"eu per harvest", - "Consumes "+powerUsageSecondary()+"eu per secondary operation", - "Can harvest 2 blocks above", - "Radius: "+aSide+" each side ("+aRadius+"x3x"+aRadius+")", - "Has "+(this.mTier * 5)+"% chance for extra drops", - "Holds "+this.getCapacity()+"L of Water", - CORE.GT_Tooltip - }; - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - return true; - } - - /*@Override - public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { - if (aSide == aFacing) - return 118+(aRedstone?8:0); - if (GT_Utility.getOppositeSide(aSide) == aFacing) - return 113+(aRedstone?8:0); - - int tIndex = 128+(aRedstone?8:0); - - switch (aFacing) { - case 0: - return tIndex+64; - case 1: - return tIndex+32; - case 2: switch (aSide) { - case 0: return tIndex+32; - case 1: return tIndex+32; - case 4: return tIndex+16; - case 5: return tIndex+48; - } - case 3: switch (aSide) { - case 0: return tIndex+64; - case 1: return tIndex+64; - case 4: return tIndex+48; - case 5: return tIndex+16; - } - case 4: switch (aSide) { - case 0: return tIndex+16; - case 1: return tIndex+16; - case 2: return tIndex+48; - case 3: return tIndex+16; - } - case 5: switch (aSide) { - case 0: return tIndex+48; - case 1: return tIndex+48; - case 2: return tIndex+16; - case 3: return tIndex+48; - } - } - return tIndex; - } */ - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFront(i); - rTextures[6][i + 1] = this.getBack(i); - rTextures[7][i + 1] = this.getBottom(i); - rTextures[8][i + 1] = this.getTop(i); - rTextures[9][i + 1] = this.getSides(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == 0 || aSide == 1) { - return this.mTextures[3][aColorIndex + 1]; - } - else { - return this.mTextures[4][aColorIndex + 1]; - } - /*return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 - : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex - + 1];*/ - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter)}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter)}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Boxes)}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Boxes)}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter)}; - } - - @Override - public boolean doesFillContainers() { - return false; - } - - @Override - public boolean doesEmptyContainers() { - return false; - } - - @Override - public boolean canTankBeFilled() { - return true; - } - - @Override - public boolean canTankBeEmptied() { - return false; - } - - @Override - public boolean displaysItemStack() { - return false; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("mModeAlternative", this.mModeAlternative); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - this.mModeAlternative = aNBT.getBoolean("mModeAlternative"); - } - + protected String mLocalName; + + private static final int SLOT_WEEDEX_1 = 1; + private static final int SLOT_WEEDEX_2 = 2; + private static final int SLOT_FERT_1 = 3; + private static final int SLOT_FERT_4 = 6; + private static final int SLOT_OUTPUT_START = 7; + + public boolean mModeAlternative = false; + + public GT_MetaTileEntity_CropHarvestor(final int aID, final int aTier, final String aDescription) { + super( + aID, + "basicmachine.cropharvester.0" + aTier, + "Crop Manager (" + GT_Values.VN[aTier] + ")", + aTier, + 21, + aDescription); + this.mLocalName = "Crop Manager (" + GT_Values.VN[aTier] + ")"; + } + + public GT_MetaTileEntity_CropHarvestor( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 21, aDescription, aTextures); + this.mLocalName = "Crop Manager (" + GT_Values.VN[aTier] + ")"; + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_CropHarvestor(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_CropHarvestor(aPlayerInventory, aBaseMetaTileEntity, this.mLocalName); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isInputFacing(byte aSide) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public long maxAmperesIn() { + return 8; + } + + @Override + public long getMinimumStoredEU() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUStore() { + return GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier]); + } + + @Override + public long maxEUInput() { + return GT_Values.V[this.mTier]; + } + + @Override + public int getCapacity() { + return 32000 * this.mTier; + } + + @Override + public int getTankPressure() { + return -100; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_CropHarvestor(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public int getSizeInventory() { + return 21; + } + + private static final int getRange(int aTier) { + switch (aTier) { + case 1: + return 1; + case 2: + return 5; + case 3: + return 9; + case 4: + return 13; + case 5: + return 17; + case 6: + return 21; + case 7: + return 25; + case 8: + return 29; + case 9: + return 33; + default: + return 0; + } + } + + private HashSet<ICropTile> mCropCache = new HashSet<ICropTile>(); + private boolean mInvalidCache = false; + + public boolean doesInventoryHaveSpace() { + for (int i = SLOT_OUTPUT_START; i < this.getSizeInventory(); i++) { + if (this.mInventory[i] == null || this.mInventory[i].stackSize < 64) { + return true; + } + } + return false; + } + + public long powerUsage() { + return this.maxEUInput() / 8; + } + + public long powerUsageSecondary() { + return this.maxEUInput() / 32; + } + + public static AutoMap<ItemStack> splitOutputStacks(ItemStack aOutput) { + return splitOutputStacks(new ItemStack[] {aOutput}); + } + + public static AutoMap<ItemStack> splitOutputStacks(ItemStack[] aOutputs) { + AutoMap<ItemStack> aOutputMap = new AutoMap<ItemStack>(); + for (ItemStack aStack : aOutputs) { + if (aStack != null) { + if (aStack.stackSize <= 64) { + aOutputMap.add(aStack); + } else { + int aStacks = 0; + int aExcess = 0; + int aOriginalSize = aStack.stackSize; + while (aOriginalSize >= 64) { + aStacks += 1; + aOriginalSize -= 64; + } + aExcess = aOriginalSize; + for (int i = 0; i < aStacks; i++) { + aOutputMap.add(ItemUtils.getSimpleStack(aStack, 64)); + } + aOutputMap.add(ItemUtils.getSimpleStack(aStack, aExcess)); + } + } + } + return aOutputMap; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (getBaseMetaTileEntity().isServerSide() + && getBaseMetaTileEntity().isAllowedToWork() + && (getBaseMetaTileEntity().hasWorkJustBeenEnabled() || aTick % 100 == 0)) { + if (this.getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU()) { + + int aTileX = this.getBaseMetaTileEntity().getXCoord(); + int aTileY = this.getBaseMetaTileEntity().getXCoord(); + int aTileZ = this.getBaseMetaTileEntity().getXCoord(); + + int aRadius = 10 + getRange(this.mTier); + int aSide = (aRadius - 1) / 2; + ArrayList<ItemStack> aAllDrops = new ArrayList<ItemStack>(); + + if (this.mCropCache.isEmpty() || aTick % 1200 == 0 || this.mInvalidCache) { + if (!this.mCropCache.isEmpty()) { + this.mCropCache.clear(); + } + // Logger.INFO("Looking for crops."); + for (int y = 0; y <= 2; y++) { + for (int x = (-aSide); x <= aSide; x++) { + for (int z = (-aSide); z <= aSide; z++) { + TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityOffset(x, y, z); + if (tTileEntity != null && tTileEntity instanceof ICropTile) { + ICropTile tCrop = (ICropTile) tTileEntity; + this.mCropCache.add(tCrop); + } + } + } + } + } + + // Process Cache + if (doesInventoryHaveSpace()) { + for (ICropTile tCrop : this.mCropCache) { + if (tCrop == null) { + this.mInvalidCache = true; + break; + } + CropCard aCrop = tCrop.getCrop(); + if (aCrop != null) { + // Logger.INFO("Found "+aCrop.displayName()+" at offset "+x+", "+y+", "+z); + if (!aCrop.canGrow(tCrop) && aCrop.canBeHarvested(tCrop)) { + if (getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsage(), true)) { + ItemStack[] aHarvest = tCrop.harvest_automated(true); + if (aHarvest != null && aHarvest.length > 0) { + for (ItemStack aStack : aHarvest) { + if (aStack.stackSize > 0) { + if (this.mTier * 5 > MathUtils.randInt(1, 100)) { + aStack.stackSize += Math.floor(tCrop.getGain() / 10); + Logger.INFO("Bonus output given for " + aCrop.displayName()); + } + Logger.INFO("Harvested " + aCrop.displayName()); + aAllDrops.addAll(splitOutputStacks(aStack)); + } + } + } + } + } + if (this.mModeAlternative) { + processSecondaryFunctions(tCrop); + } + } + } + + if (!aAllDrops.isEmpty()) { + Logger.INFO("Handling " + aAllDrops.size() + " Harvests"); + Iterator<ItemStack> iter = aAllDrops.iterator(); + while (iter.hasNext()) { + ItemStack aDrop = iter.next(); + if (ItemUtils.checkForInvalidItems(aDrop)) { + + for (int i = SLOT_OUTPUT_START; i < this.getSizeInventory(); i++) { + if (this.mInventory[i] != null) { + // Logger.INFO("Slot "+i+" contains "+this.mInventory[i].getDisplayName()); + if (GT_Utility.areStacksEqual(aDrop, this.mInventory[i], false)) { + // Same + if (this.mInventory[i].stackSize < 64 + && (this.mInventory[i].stackSize + aDrop.stackSize <= 64)) { + // can merge + // Logger.INFO("Slot "+i+" size: "+mInventory[i].stackSize+" + Drop + // Size: "+aDrop.stackSize+" = "+(mInventory[i].stackSize + + // aDrop.stackSize)); + this.mInventory[i].stackSize += aDrop.stackSize; + break; + } else if (this.mInventory[i].stackSize < 64 + && (this.mInventory[i].stackSize + aDrop.stackSize > 64)) { + // can merge + // Logger.INFO("Slot "+i+" size: "+mInventory[i].stackSize+" + Drop + // Size: "+aDrop.stackSize+" = "+(mInventory[i].stackSize + + // aDrop.stackSize)); + int aRemainder = this.mInventory[i].stackSize + aDrop.stackSize - 64; + Logger.INFO("Remainder: " + aRemainder + ", Continuing."); + this.mInventory[i].stackSize = 64; + aDrop.stackSize = aRemainder; + continue; + } else { + // Logger.INFO("Slot "+i+" size: 64, Continuing."); + continue; + } + } + } else { + // Logger.INFO("Slot "+i+" is empty, setting to "+aDrop.getDisplayName()+" + // x"+aDrop.stackSize); + this.mInventory[i] = aDrop; + break; + } + } + } + } + } + } + } + } + } + + public boolean hasFertilizer() { + for (int i = SLOT_FERT_1; i <= SLOT_FERT_4; i++) { + if (this.mInventory[i] != null) { + return true; + } + } + return false; + } + + public boolean consumeFertilizer(boolean aSimulate) { + if (hasFertilizer()) { + for (int i = SLOT_FERT_1; i <= SLOT_FERT_4; i++) { + if (this.mInventory[i] != null) { + consume(i, 1, aSimulate); + return true; + } + } + } + return false; + } + + public boolean hasWeedEX() { + for (int i = SLOT_WEEDEX_1; i <= SLOT_WEEDEX_2; i++) { + if (this.mInventory[i] != null) { + return true; + } + } + return false; + } + + public boolean consumeWeedEX(boolean aSimulate) { + if (hasWeedEX()) { + for (int i = SLOT_WEEDEX_1; i <= SLOT_WEEDEX_2; i++) { + if (this.mInventory[i] != null) { + damage(i, 1, aSimulate); + return true; + } + } + } + return false; + } + + public void processSecondaryFunctions(ICropTile aCrop) { + if (!this.mModeAlternative) { + return; + } + if (hasFertilizer() + && consumeFertilizer(true) + && this.getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU() + && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) + && applyFertilizer(aCrop)) { + if (consumeFertilizer(false)) { + // Logger.INFO("Consumed Fert."); + } + } + if (this.getFluidAmount() > 0 + && this.getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU() + && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) + && applyHydration(aCrop)) { + // Logger.INFO("Consumed Water."); + } + if (hasWeedEX() + && consumeWeedEX(true) + && this.getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU() + && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) + && applyWeedEx(aCrop)) { + if (consumeWeedEX(false)) { + // Logger.INFO("Consumed Weed-EX."); + } + } + } + + public boolean applyWeedEx(ICropTile aCrop) { + if (aCrop.getWeedExStorage() < 150) { + aCrop.setWeedExStorage(aCrop.getWeedExStorage() + 50); + boolean triggerDecline; + triggerDecline = aCrop.getWorld().rand.nextInt(3) == 0; + if (aCrop.getCrop() != null + && aCrop.getCrop().isWeed(aCrop) + && aCrop.getWeedExStorage() >= 75 + && triggerDecline) { + switch (aCrop.getWorld().rand.nextInt(5)) { + case 0: + if (aCrop.getGrowth() > 0) { + aCrop.setGrowth((byte) (aCrop.getGrowth() - 1)); + } + case 1: + if (aCrop.getGain() > 0) { + aCrop.setGain((byte) (aCrop.getGain() - 1)); + } + default: + if (aCrop.getResistance() > 0) { + aCrop.setResistance((byte) (aCrop.getResistance() - 1)); + } + } + } + return true; + } else { + return false; + } + } + + public boolean applyFertilizer(ICropTile aCrop) { + if (aCrop.getNutrientStorage() >= 100) { + return false; + } else { + // Logger.INFO("Current Nutrient: "+aCrop.getNutrientStorage()+" for "+aCrop.getCrop().displayName()); + aCrop.setNutrientStorage(aCrop.getNutrientStorage() + 100); + return true; + } + } + + public boolean applyHydration(ICropTile aCrop) { + if (aCrop.getHydrationStorage() >= 200 || this.getFluidAmount() == 0) { + // Logger.INFO("Hydration Max"); + return false; + } else { + int apply = 200 - aCrop.getHydrationStorage(); + if (this.getFluidAmount() >= 0) { + int drain = 0; + if (this.getFluidAmount() >= apply) { + drain = apply; + } else { + drain = this.getFluidAmount(); + } + this.mFluid.amount -= drain; + if (this.mFluid.amount <= 0) { + this.mFluid = null; + } + // Logger.INFO("Did Hydrate"); + aCrop.setHydrationStorage(aCrop.getHydrationStorage() + drain); + return true; + } else { + // Logger.INFO("No water?"); + return false; + } + } + } + + public boolean consume(int aSlot, int amount, boolean simulate) { + ItemStack stack = this.mInventory[aSlot]; + if (stack != null && stack.stackSize >= amount) { + int currentAmount = Math.min(amount, stack.stackSize); + amount -= currentAmount; + if (!simulate) { + if (stack.stackSize == currentAmount) { + this.mInventory[aSlot] = null; + } else { + stack.stackSize -= currentAmount; + } + } else { + return amount >= 0; + } + return true; + } + return false; + } + + public ItemStack damage(int aSlot, int amount, boolean simulate) { + ItemStack ret = null; + int damageApplied = 0; + ItemStack stack = this.mInventory[aSlot]; + Item item = stack.getItem(); + if (stack != null + && item.isDamageable() + && (ret == null || stack.getItem() == ret.getItem() && ItemStack.areItemStackTagsEqual(stack, ret))) { + if (simulate) { + stack = stack.copy(); + } + int maxDamage = DamageHandler.getMaxDamage(stack); + while (amount > 0 && stack.stackSize > 0) { + int currentAmount = Math.min(amount, maxDamage - DamageHandler.getDamage(stack)); + DamageHandler.damage(stack, currentAmount, null); + damageApplied += currentAmount; + amount -= currentAmount; + if (DamageHandler.getDamage(stack) >= maxDamage) { + --stack.stackSize; + DamageHandler.setDamage(stack, 0); + } + + if (ret == null) { + ret = stack.copy(); + } + } + if (stack.stackSize == 0 && !simulate) { + this.mInventory[aSlot] = null; + } + } + + if (ret != null) { + int i = DamageHandler.getMaxDamage(ret); + ret.stackSize = damageApplied / i; + DamageHandler.setDamage(ret, damageApplied % i); + } + return ret; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aStack != null && aIndex >= SLOT_OUTPUT_START && aIndex < this.getSizeInventory(); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + if (aStack != null) { + if (aStack.getItem().getUnlocalizedName().equals("ic2.itemFertilizer")) { + return aIndex >= SLOT_FERT_1 && aIndex <= SLOT_FERT_4; + } else if (aStack.getItem().getUnlocalizedName().equals("ic2.itemWeedEx")) { + return aIndex >= SLOT_WEEDEX_1 && aIndex <= SLOT_WEEDEX_2; + } + } + return false; + } + + @Override + public String[] getDescription() { + int aRadius = 10 + getRange(this.mTier); + int aSide = (aRadius - 1) / 2; + return new String[] { + this.mDescription, + "Secondary mode can Hydrate/Fertilize/Weed-EX", + "Consumes " + powerUsage() + "eu per harvest", + "Consumes " + powerUsageSecondary() + "eu per secondary operation", + "Can harvest 2 blocks above", + "Radius: " + aSide + " each side (" + aRadius + "x3x" + aRadius + ")", + "Has " + (this.mTier * 5) + "% chance for extra drops", + "Holds " + this.getCapacity() + "L of Water", + CORE.GT_Tooltip + }; + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return true; + } + + /*@Override + public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) + return 118+(aRedstone?8:0); + if (GT_Utility.getOppositeSide(aSide) == aFacing) + return 113+(aRedstone?8:0); + + int tIndex = 128+(aRedstone?8:0); + + switch (aFacing) { + case 0: + return tIndex+64; + case 1: + return tIndex+32; + case 2: switch (aSide) { + case 0: return tIndex+32; + case 1: return tIndex+32; + case 4: return tIndex+16; + case 5: return tIndex+48; + } + case 3: switch (aSide) { + case 0: return tIndex+64; + case 1: return tIndex+64; + case 4: return tIndex+48; + case 5: return tIndex+16; + } + case 4: switch (aSide) { + case 0: return tIndex+16; + case 1: return tIndex+16; + case 2: return tIndex+48; + case 3: return tIndex+16; + } + case 5: switch (aSide) { + case 0: return tIndex+48; + case 1: return tIndex+48; + case 2: return tIndex+16; + case 3: return tIndex+48; + } + } + return tIndex; + } */ + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getBack(i); + rTextures[7][i + 1] = this.getBottom(i); + rTextures[8][i + 1] = this.getTop(i); + rTextures[9][i + 1] = this.getSides(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == 0 || aSide == 1) { + return this.mTextures[3][aColorIndex + 1]; + } else { + return this.mTextures[4][aColorIndex + 1]; + } + /*return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + + 1];*/ + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Boxes) + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Boxes) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter) + }; + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mModeAlternative", this.mModeAlternative); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mModeAlternative = aNBT.getBoolean("mModeAlternative"); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_WorldAccelerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_WorldAccelerator.java index 129446c40d..6ba1e373eb 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_WorldAccelerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_WorldAccelerator.java @@ -2,21 +2,8 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; import static gregtech.api.enums.GT_Values.V; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons.CustomIcon; import gregtech.api.interfaces.ITexture; @@ -24,305 +11,313 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.objects.GT_RenderedTexture; - import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.PlayerUtils; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; public class GT_MetaTileEntity_WorldAccelerator extends GT_MetaTileEntity_TieredMachineBlock { - public static String[] BlacklistedTileEntiyClassNames; - - private byte mMode = 0; // 0: RandomTicks around 1: TileEntities with range - // 1 - private static CustomIcon _mGTIco_Norm_Idle; - private static CustomIcon _mGTIco_Norm_Active; - private static CustomIcon _mGTIco_TE_Idle; - private static CustomIcon _mGTIco_TE_Active; - private static int[] mAccelerateStatic = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512, 512, 512, 512, 512, 512 }; - - @Override - public void registerIcons(IIconRegister aBlockIconRegister) { - super.registerIcons(aBlockIconRegister); - _mGTIco_Norm_Idle = new CustomIcon("iconsets/OVERLAY_ACCELERATOR"); - _mGTIco_Norm_Active = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_ACTIVE"); - _mGTIco_TE_Idle = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_TE"); - _mGTIco_TE_Active = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_TE_ACTIVE"); - } - - @SideOnly(Side.CLIENT) - @Override - public void onValueUpdate(byte aValue) { - mMode = aValue; - } - - @Override - public byte getUpdateData() { - return mMode; - } - - public GT_MetaTileEntity_WorldAccelerator(int pID, String pName, String pNameRegional, int pTier) { - super(pID, pName, pNameRegional, pTier, 0, ""); - } - - @Override - public String[] getDescription() { - return new String[] { - String.format("Accelerating things (Radius: %d EU/t: %d Speed Bonus: x%d)", mTier, - getEnergyDemand(mTier, false), mAccelerateStatic[mTier]), - "Use a screwdriver to change mode", "To accelerate TileEntities, this machine has to be adjacent to it", - "This machine accepts up to 8 Amps", "Accelerating TileEntities doubles Energy-Demand"}; - - } - - public GT_MetaTileEntity_WorldAccelerator(String pName, int pTier, int pInvSlotCount, String pDescription, - ITexture[][][] pTextures) { - super(pName, pTier, pInvSlotCount, pDescription, pTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity pTileEntity) { - return new GT_MetaTileEntity_WorldAccelerator(mName, mTier, mInventory.length, mDescription, mTextures); - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] pTextures) { - return new ITexture[0][0][0]; - } - - @Override - public ITexture[] getTexture(IGregTechTileEntity pBaseMetaTileEntity, byte pSide, byte pFacing, byte pColorIndex, - boolean pActive, boolean pRedstone) { - if (mMode == 0) - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][pColorIndex + 1], - (pSide < 2) ? null - : pActive ? new GT_RenderedTexture(_mGTIco_Norm_Active) - : new GT_RenderedTexture(_mGTIco_Norm_Idle) }; - else - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][pColorIndex + 1], (pSide < 2) ? null - : pActive ? new GT_RenderedTexture(_mGTIco_TE_Active) : new GT_RenderedTexture(_mGTIco_TE_Idle) }; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity pBaseMetaTileEntity, int pIndex, byte pSide, ItemStack pStack) { - return false; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity pBaseMetaTileEntity, int pIndex, byte pSide, ItemStack pStack) { - return false; - } - - @Override - public void saveNBTData(NBTTagCompound pNBT) { - pNBT.setByte("mAccelMode", mMode); - } - - public static long getEnergyDemand(int pTier, boolean pIsAcceleratingTEs) { - return V[pTier] * (pIsAcceleratingTEs ? 6 : 3); - } - - @Override - public void loadNBTData(NBTTagCompound pNBT) { - mMode = pNBT.getByte("mAccelMode"); - } - - @Override - public boolean isAccessAllowed(EntityPlayer pPlayer) { - return true; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isInputFacing(byte aSide) { - return true; - } - - @Override - public boolean isTeleporterCompatible() { - return false; - } - - @Override - public long getMinimumStoredEU() { - return 512; - } - - @Override - public long maxEUStore() { - return 512 + V[mTier] * 50; - } - - @Override - public long maxEUInput() { - return V[mTier]; - } - - @Override - public long maxAmperesIn() { - return 8; - } - - private static String[] mModeStr = { "Blocks", "TileEntities" }; - - @Override - public void onScrewdriverRightClick(byte pSide, EntityPlayer pPlayer, float pX, float pY, float pZ) { - mMode = (byte) (mMode == 0x00 ? 0x01 : 0x00); - markDirty(); - PlayerUtils.messagePlayer(pPlayer, String.format("Switched mode to: %s", mModeStr[mMode])); - } - - @Override - public void onPostTick(IGregTechTileEntity pBaseMetaTileEntity, long pTick) { - try { - if (!pBaseMetaTileEntity.isServerSide()) - return; - - long tEnergyDemand = getEnergyDemand(mTier, (mMode == 1)); - - // Do we have enough energy to run? Or are we not allowed to run? - if (pBaseMetaTileEntity.getStoredEU() < tEnergyDemand || !pBaseMetaTileEntity.isAllowedToWork()) { - // Check if machine was active before - if (pBaseMetaTileEntity.isActive()) - pBaseMetaTileEntity.setActive(false); // Then disable it now - } else { - // Continue to drain power - if (pBaseMetaTileEntity.decreaseStoredEnergyUnits(tEnergyDemand, false)) { - World tWorld = pBaseMetaTileEntity.getWorld(); - // Limit the random ticks to once per second - if (mMode == 0) { - if (pTick % 20 == 0) - doAccelerateNormalBlocks(pBaseMetaTileEntity, tWorld); - } else - doAccelerateTileEntities(pBaseMetaTileEntity, tWorld); - - } else { - // Energy drain failed. Disable machine - if (pBaseMetaTileEntity.isActive()) - pBaseMetaTileEntity.setActive(false); - } - } - } catch (Exception e) { - Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.onPostTick.crash"); - Logger.ERROR(e.getMessage()); - } - } - - private void doAccelerateTileEntities(IGregTechTileEntity pBaseMetaTileEntity, World pWorld) { - try { - if (!pBaseMetaTileEntity.isActive()) - getBaseMetaTileEntity().setActive(true); - - for (ForgeDirection tDir : ForgeDirection.VALID_DIRECTIONS) { - TileEntity tTile = pBaseMetaTileEntity.getTileEntityAtSide((byte) tDir.ordinal()); - if (isTEBlackListed(tTile)) - continue; - - long tMaxTime = System.nanoTime() + 1000000; - for (int j = 0; j < mAccelerateStatic[mTier]; j++) { - tTile.updateEntity(); - if (System.nanoTime() > tMaxTime) - break; - } - } - } catch (Exception e) { - Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.doAccelerateTileEntities.crash"); - Logger.ERROR(e.getMessage()); - } - } - - private static List<String> _mBlacklistedTileEntities = new ArrayList<String>(); - - // Inspired by ChromatiCraft's TileAccelerator - private boolean isTEBlackListed(TileEntity pTile) { - if (pTile == null) - return true; // Obvious - if (!pTile.canUpdate()) - return true; // Skip if TE can't update at all - if (pTile.isInvalid()) - return true; // Obvious - - String tSimpleClassName = pTile.getClass().getSimpleName().toLowerCase(); - String tCanonicalName = pTile.getClass().getCanonicalName().toLowerCase(); - if (tSimpleClassName.contains("conduit") || tSimpleClassName.contains("wire") - || tSimpleClassName.contains("cable")) - return true; - if (tCanonicalName.contains("appeng") || tCanonicalName.contains("gregtech")) - // Don't accelerate ANY Gregtech machines! - return true; - for (String tS : BlacklistedTileEntiyClassNames) { - if (tCanonicalName.equalsIgnoreCase(tS)) - return true; - } - - return false; - } - - /** - * Accelerate normal blocks. Eats some power and adds randomTicks to every - * block within its working area (Tier-Number = radius) This does only - * affect blocks that implement the "RandomTick" method; Which is mostly - * used for grass growth and plants. - * - * @param pBaseMetaTileEntity - */ - private void doAccelerateNormalBlocks(IGregTechTileEntity pBaseMetaTileEntity, World pWorld) { - if (!pBaseMetaTileEntity.isActive()) - getBaseMetaTileEntity().setActive(true); - - Random rnd = new Random(); - int tX = pBaseMetaTileEntity.getXCoord(); - int tY = pBaseMetaTileEntity.getYCoord(); - int tZ = pBaseMetaTileEntity.getZCoord(); - - int tX1 = tX - mTier; - int tX2 = tX + mTier; - int tY1 = Math.max(tY - mTier, 0); // Limit to bedrock - int tY2 = Math.min(tY + mTier, 255); // Limit to build height - int tZ1 = tZ - mTier; - int tZ2 = tZ + mTier; - - for (int xi = tX1; xi <= tX2; xi++) - for (int yi = tY1; yi <= tY2; yi++) - for (int zi = tZ1; zi <= tZ2; zi++) - tryTickBlock(pWorld, xi, yi, zi, rnd); - - } - - /** - * Send a tick to the target block - * - * @param pWorld - * @param pX - * @param pY - * @param pZ - * @param pRnd - */ - private void tryTickBlock(World pWorld, int pX, int pY, int pZ, Random pRnd) { - try { - for (int j = 0; j < mTier; j++) { - Block tBlock = pWorld.getBlock(pX, pY, pZ); - if (tBlock.getTickRandomly()) - tBlock.updateTick(pWorld, pX, pY, pZ, pRnd); - } - } catch (Exception e) { - Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.tryTickBlock.crash"); - Logger.ERROR(e.getMessage()); - } - } -}
\ No newline at end of file + public static String[] BlacklistedTileEntiyClassNames; + + private byte mMode = 0; // 0: RandomTicks around 1: TileEntities with range + // 1 + private static CustomIcon _mGTIco_Norm_Idle; + private static CustomIcon _mGTIco_Norm_Active; + private static CustomIcon _mGTIco_TE_Idle; + private static CustomIcon _mGTIco_TE_Active; + private static int[] mAccelerateStatic = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512, 512, 512, 512, 512, 512}; + + @Override + public void registerIcons(IIconRegister aBlockIconRegister) { + super.registerIcons(aBlockIconRegister); + _mGTIco_Norm_Idle = new CustomIcon("iconsets/OVERLAY_ACCELERATOR"); + _mGTIco_Norm_Active = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_ACTIVE"); + _mGTIco_TE_Idle = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_TE"); + _mGTIco_TE_Active = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_TE_ACTIVE"); + } + + @SideOnly(Side.CLIENT) + @Override + public void onValueUpdate(byte aValue) { + mMode = aValue; + } + + @Override + public byte getUpdateData() { + return mMode; + } + + public GT_MetaTileEntity_WorldAccelerator(int pID, String pName, String pNameRegional, int pTier) { + super(pID, pName, pNameRegional, pTier, 0, ""); + } + + @Override + public String[] getDescription() { + return new String[] { + String.format( + "Accelerating things (Radius: %d EU/t: %d Speed Bonus: x%d)", + mTier, getEnergyDemand(mTier, false), mAccelerateStatic[mTier]), + "Use a screwdriver to change mode", + "To accelerate TileEntities, this machine has to be adjacent to it", + "This machine accepts up to 8 Amps", + "Accelerating TileEntities doubles Energy-Demand" + }; + } + + public GT_MetaTileEntity_WorldAccelerator( + String pName, int pTier, int pInvSlotCount, String pDescription, ITexture[][][] pTextures) { + super(pName, pTier, pInvSlotCount, pDescription, pTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity pTileEntity) { + return new GT_MetaTileEntity_WorldAccelerator(mName, mTier, mInventory.length, mDescription, mTextures); + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] pTextures) { + return new ITexture[0][0][0]; + } + + @Override + public ITexture[] getTexture( + IGregTechTileEntity pBaseMetaTileEntity, + byte pSide, + byte pFacing, + byte pColorIndex, + boolean pActive, + boolean pRedstone) { + if (mMode == 0) + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][pColorIndex + 1], + (pSide < 2) + ? null + : pActive + ? new GT_RenderedTexture(_mGTIco_Norm_Active) + : new GT_RenderedTexture(_mGTIco_Norm_Idle) + }; + else + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][pColorIndex + 1], + (pSide < 2) + ? null + : pActive ? new GT_RenderedTexture(_mGTIco_TE_Active) : new GT_RenderedTexture(_mGTIco_TE_Idle) + }; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity pBaseMetaTileEntity, int pIndex, byte pSide, ItemStack pStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity pBaseMetaTileEntity, int pIndex, byte pSide, ItemStack pStack) { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound pNBT) { + pNBT.setByte("mAccelMode", mMode); + } + + public static long getEnergyDemand(int pTier, boolean pIsAcceleratingTEs) { + return V[pTier] * (pIsAcceleratingTEs ? 6 : 3); + } + + @Override + public void loadNBTData(NBTTagCompound pNBT) { + mMode = pNBT.getByte("mAccelMode"); + } + + @Override + public boolean isAccessAllowed(EntityPlayer pPlayer) { + return true; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isInputFacing(byte aSide) { + return true; + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 512; + } + + @Override + public long maxEUStore() { + return 512 + V[mTier] * 50; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public long maxAmperesIn() { + return 8; + } + + private static String[] mModeStr = {"Blocks", "TileEntities"}; + + @Override + public void onScrewdriverRightClick(byte pSide, EntityPlayer pPlayer, float pX, float pY, float pZ) { + mMode = (byte) (mMode == 0x00 ? 0x01 : 0x00); + markDirty(); + PlayerUtils.messagePlayer(pPlayer, String.format("Switched mode to: %s", mModeStr[mMode])); + } + + @Override + public void onPostTick(IGregTechTileEntity pBaseMetaTileEntity, long pTick) { + try { + if (!pBaseMetaTileEntity.isServerSide()) return; + + long tEnergyDemand = getEnergyDemand(mTier, (mMode == 1)); + + // Do we have enough energy to run? Or are we not allowed to run? + if (pBaseMetaTileEntity.getStoredEU() < tEnergyDemand || !pBaseMetaTileEntity.isAllowedToWork()) { + // Check if machine was active before + if (pBaseMetaTileEntity.isActive()) pBaseMetaTileEntity.setActive(false); // Then disable it now + } else { + // Continue to drain power + if (pBaseMetaTileEntity.decreaseStoredEnergyUnits(tEnergyDemand, false)) { + World tWorld = pBaseMetaTileEntity.getWorld(); + // Limit the random ticks to once per second + if (mMode == 0) { + if (pTick % 20 == 0) doAccelerateNormalBlocks(pBaseMetaTileEntity, tWorld); + } else doAccelerateTileEntities(pBaseMetaTileEntity, tWorld); + + } else { + // Energy drain failed. Disable machine + if (pBaseMetaTileEntity.isActive()) pBaseMetaTileEntity.setActive(false); + } + } + } catch (Exception e) { + Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.onPostTick.crash"); + Logger.ERROR(e.getMessage()); + } + } + + private void doAccelerateTileEntities(IGregTechTileEntity pBaseMetaTileEntity, World pWorld) { + try { + if (!pBaseMetaTileEntity.isActive()) getBaseMetaTileEntity().setActive(true); + + for (ForgeDirection tDir : ForgeDirection.VALID_DIRECTIONS) { + TileEntity tTile = pBaseMetaTileEntity.getTileEntityAtSide((byte) tDir.ordinal()); + if (isTEBlackListed(tTile)) continue; + + long tMaxTime = System.nanoTime() + 1000000; + for (int j = 0; j < mAccelerateStatic[mTier]; j++) { + tTile.updateEntity(); + if (System.nanoTime() > tMaxTime) break; + } + } + } catch (Exception e) { + Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.doAccelerateTileEntities.crash"); + Logger.ERROR(e.getMessage()); + } + } + + private static List<String> _mBlacklistedTileEntities = new ArrayList<String>(); + + // Inspired by ChromatiCraft's TileAccelerator + private boolean isTEBlackListed(TileEntity pTile) { + if (pTile == null) return true; // Obvious + if (!pTile.canUpdate()) return true; // Skip if TE can't update at all + if (pTile.isInvalid()) return true; // Obvious + + String tSimpleClassName = pTile.getClass().getSimpleName().toLowerCase(); + String tCanonicalName = pTile.getClass().getCanonicalName().toLowerCase(); + if (tSimpleClassName.contains("conduit") + || tSimpleClassName.contains("wire") + || tSimpleClassName.contains("cable")) return true; + if (tCanonicalName.contains("appeng") || tCanonicalName.contains("gregtech")) + // Don't accelerate ANY Gregtech machines! + return true; + for (String tS : BlacklistedTileEntiyClassNames) { + if (tCanonicalName.equalsIgnoreCase(tS)) return true; + } + + return false; + } + + /** + * Accelerate normal blocks. Eats some power and adds randomTicks to every + * block within its working area (Tier-Number = radius) This does only + * affect blocks that implement the "RandomTick" method; Which is mostly + * used for grass growth and plants. + * + * @param pBaseMetaTileEntity + */ + private void doAccelerateNormalBlocks(IGregTechTileEntity pBaseMetaTileEntity, World pWorld) { + if (!pBaseMetaTileEntity.isActive()) getBaseMetaTileEntity().setActive(true); + + Random rnd = new Random(); + int tX = pBaseMetaTileEntity.getXCoord(); + int tY = pBaseMetaTileEntity.getYCoord(); + int tZ = pBaseMetaTileEntity.getZCoord(); + + int tX1 = tX - mTier; + int tX2 = tX + mTier; + int tY1 = Math.max(tY - mTier, 0); // Limit to bedrock + int tY2 = Math.min(tY + mTier, 255); // Limit to build height + int tZ1 = tZ - mTier; + int tZ2 = tZ + mTier; + + for (int xi = tX1; xi <= tX2; xi++) + for (int yi = tY1; yi <= tY2; yi++) + for (int zi = tZ1; zi <= tZ2; zi++) tryTickBlock(pWorld, xi, yi, zi, rnd); + } + + /** + * Send a tick to the target block + * + * @param pWorld + * @param pX + * @param pY + * @param pZ + * @param pRnd + */ + private void tryTickBlock(World pWorld, int pX, int pY, int pZ, Random pRnd) { + try { + for (int j = 0; j < mTier; j++) { + Block tBlock = pWorld.getBlock(pX, pY, pZ); + if (tBlock.getTickRandomly()) tBlock.updateTick(pWorld, pX, pY, pZ, pRnd); + } + } catch (Exception e) { + Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.tryTickBlock.crash"); + Logger.ERROR(e.getMessage()); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java index 33ffd1f118..23263bd9fd 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java @@ -2,8 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; import static gregtech.api.enums.GT_Values.V; -import org.apache.commons.lang3.ArrayUtils; - import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; import gregtech.api.enums.Textures; @@ -34,834 +32,865 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import org.apache.commons.lang3.ArrayUtils; public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_BasicMachine { - public int mPollutionReduction = 0; - protected int mBaseEff = 2500; - protected int mOptimalAirFlow = 0; - protected boolean mHasPollution = false; - protected int SLOT_ROTOR = 5; - protected int SLOT_FILTER = 6; - protected static boolean mPollutionEnabled = true; - - protected boolean mSaveRotor = false; - - public GregtechMetaAtmosphericReconditioner(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 2, "Making sure you don't live in Gwalior - Uses 2A", 3, 0, "Recycler.png", "", - new ITexture[]{ - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB), - new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active), - new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab), - new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast), - new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB) - }); - mPollutionEnabled = PollutionUtils.isPollutionEnabled(); - } - - public GregtechMetaAtmosphericReconditioner(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 2, aDescription, aTextures, 2, 0, aGUIName, aNEIName); - mPollutionEnabled = PollutionUtils.isPollutionEnabled(); - } - - /*public GregtechMetaAtmosphericReconditioner(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 2, aDescription, aTextures, 2, 0, aGUIName, aNEIName); - }*/ - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaAtmosphericReconditioner(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); - } - - @Override - public String[] getDescription() { - - boolean highTier = this.mTier >= 7; - - String[] A = new String[]{ - this.mDescription, - highTier ? "Will attempt to remove 1/4 pollution from 8 surrounding chunks" : "", - highTier ? "If these chunks are not loaded, they will be ignored" : "", - "Requires a turbine rotor and an Air Filter [T1/T2] to run.", - "The turbine rotor must be manually inserted/replaced", - "Can be configured with a soldering iron to change modes", - "Low Efficiency: Removes half pollution, Turbine takes 50% dmg", - "High Efficiency: Removes full pollution, Turbine takes 100% dmg", - "Turbine Rotor will not break in LE mode", - "Insert an equal tier Conveyor Module to enable automation" - }; - if (!mPollutionEnabled) { - String[] B = new String[] { - "===============================================", - "Pollution is disabled, scrubbers will now have a bonus use", - "They are now able to remove ALL lingering pollution as GT ignores it", - "and it will linger forever!", - "===============================================", - }; - A = ArrayUtils.addAll(A, B); - } - return A; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); - aNBT.setBoolean("mSaveRotor", mSaveRotor); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - this.mOptimalAirFlow = aNBT.getInteger("mOptimalAirFlow"); - this.mSaveRotor = aNBT.getBoolean("mSaveRotor"); - } - - @Override - public long maxAmperesIn() { - return 2; - } - - @Override - public long getMinimumStoredEU() { - return V[mTier] * 2; - } - - @Override - public long maxEUStore() { - return V[mTier] * 256; - } - - @Override - public long maxEUInput() { - return V[mTier]; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (aBaseMetaTileEntity.isServerSide()) { - - //Get Current Pollution Amount. - int mCurrentPollution = getCurrentChunkPollution(); - boolean isIdle = true; - - //Get Inventory Item - ItemStack stackRotor = this.mInventory[SLOT_ROTOR]; - ItemStack stackFilter = this.mInventory[SLOT_FILTER]; - - //Power Drain - long drainEU = maxEUInput() * maxAmperesIn(); - if (aBaseMetaTileEntity.isActive() && aBaseMetaTileEntity.getStoredEU() >= drainEU){ - if(aBaseMetaTileEntity.decreaseStoredEnergyUnits(drainEU, false)){ - isIdle = false; - } - else { - aBaseMetaTileEntity.setActive(false); - this.sendSound((byte) -122); - } - } - else if (!aBaseMetaTileEntity.isActive() && aBaseMetaTileEntity.getStoredEU() >= drainEU/4){ - if(aBaseMetaTileEntity.decreaseStoredEnergyUnits((drainEU/4), false)){ - isIdle = false; - } - else { - aBaseMetaTileEntity.setActive(false); - this.sendSound((byte) -122); - } - } - else { - aBaseMetaTileEntity.setActive(false); - this.sendSound((byte) -122); - } - - //Only try once/sec. - if (!isIdle && aTick % 20L == 0L){ - - - - for (int i=0;i<this.mInventory.length;i++) { - ItemStack aSlotContent = this.mInventory[i]; - if (aSlotContent != null) { - Logger.INFO("Found "+aSlotContent.getDisplayName()+" in slot "+i); - } - } - - for (int i=0;i<this.mInventory.length;i++) { - if (hasRotor(this.mInventory[i])) { - Logger.INFO("Found Rotor in slot "+i); - break; - } - } - for (int i=0;i<this.mInventory.length;i++) { - if (hasAirFilter(this.mInventory[i])) { - Logger.INFO("Found Filter in slot "+i); - break; - } - } - - //Check if machine can work. - if ((aBaseMetaTileEntity.isAllowedToWork())){ - Logger.INFO("Can work."); - - //Enable machine animation/graphic - if (hasRotor(stackRotor) && hasAirFilter(stackFilter) && this.mHasPollution){ - if (!this.getBaseMetaTileEntity().isActive()) { - Logger.INFO("Set Active."); - aBaseMetaTileEntity.setActive(true); - } - } - else if (!this.mHasPollution || mCurrentPollution <= 0 || stackRotor == null || stackFilter == null || !hasRotor(stackRotor) || !hasAirFilter(stackFilter)){ - if (!this.getBaseMetaTileEntity().isActive()) { - Logger.INFO("Set Inactive."); - aBaseMetaTileEntity.setActive(false); - this.sendSound((byte) -122); - } - } - - //If Active. - if (aBaseMetaTileEntity.isActive()){ - Logger.INFO("Doing something."); - - //Do nothing if there is no pollution. - if(this.mHasPollution && mCurrentPollution > 0){ - Logger.INFO("Has Pollution? "+mHasPollution+", Current Pollution: "+mCurrentPollution); - - //Only check every 30s. - if (!isIdle && aTick % (20L * 30) == 0L){ - mPollutionEnabled = PollutionUtils.isPollutionEnabled(); - //Clear out pollution if it's disabled, because I am a nice gal. - if (!PollutionUtils.isPollutionEnabled()) { - PollutionUtils.nullifyPollution(this.getBaseMetaTileEntity()); - } - } - - - - - //Use a Turbine - if(hasRotor(stackRotor) && hasAirFilter(stackFilter)){ - Logger.INFO("Found Turbine."); - - mBaseEff = getBaseEfficiency(stackRotor); - mOptimalAirFlow = getOptimalAirFlow(stackRotor); - - //Make sure we have a valid Turbine and Eff/Airflow - if (this.mBaseEff > 0 && this.mOptimalAirFlow > 0){ - //Utils.LOG_WARNING("Pollution Cleaner [5]"); - - //Log Debug information. - Logger.INFO("mBaseEff[1]:"+mBaseEff); - Logger.INFO("mOptimalAirFlow[1]:"+mOptimalAirFlow); - - //Calculate The Voltage we are running - long tVoltage = drainEU; - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - - //Check Sides for Air, - //More air means more pollution processing. - int mAirSides = getFreeSpaces(); - - int reduction = 0; - - //If no sides are free, how will you process the atmosphere? - if (mAirSides > 0){ - reduction += (((Math.max((tTier-2), 1)*2)*50)*mAirSides); //Was originally *100 - Logger.INFO("mPollutionReduction[1]:"+reduction); - - //I stole this code - reduction = (MathUtils.safeInt((long)reduction*this.mBaseEff)/100000)*mAirSides*Math.max((tTier-2), 1); - Logger.INFO("reduction[2]:"+reduction); - reduction = MathUtils.safeInt(((long)reduction/100)*this.mOptimalAirFlow); - Logger.INFO("reduction[3]:"+reduction); - - mPollutionReduction = reduction; - - //Set a temp to remove variable to aleviate duplicate code. - int toRemove = 0; - - Logger.INFO("mCurrentPollution[4]:"+mCurrentPollution); - Logger.INFO("mCurrentPollution[5]:"+reduction); - if (reduction <= mCurrentPollution){ - //Clean some Air. - toRemove = reduction; - } - else { - //Makes sure we don't get negative pollution. - toRemove = mCurrentPollution; - } - - toRemove = toRemove/2; - Logger.INFO("mCurrentPollution[6]:"+toRemove); - - //We are good to clean - if (toRemove > 0){ - if (damageTurbineRotor() && damageAirFilter()){ - Logger.INFO("Removing "+toRemove+" pollution"); - removePollution(mSaveRotor ? (toRemove/2) : toRemove); - Logger.INFO("mNewPollution[4]:"+getCurrentChunkPollution()); - } - else { - Logger.INFO("Could not damage turbine rotor or Air Filter."); - aBaseMetaTileEntity.setActive(false); - } - } //End of pollution removal block. - } //End of valid air sides block. - } //End of valid toolstats block. - } //End of correct inventory item block. - else { - //Utils.LOG_WARNING("Wrong Tool metaitem Found."); - } - } - } - else if (!aBaseMetaTileEntity.isActive()) { - return; - } - } //End of can work block. - else { //Disable Machine. - //aBaseMetaTileEntity.setActive(false); - } - } //End of 1/sec action block. - else { - - if (hasRotor(stackRotor) && hasAirFilter(stackFilter) && this.mHasPollution && !isIdle && aBaseMetaTileEntity.isAllowedToWork()){ - aBaseMetaTileEntity.setActive(true); - } - else if (isIdle || !this.mHasPollution || mCurrentPollution <= 0 || stackRotor == null || stackFilter == null || !hasRotor(stackRotor) || !hasAirFilter(stackFilter)){ - aBaseMetaTileEntity.setActive(false); - } - - } - if (this.getBaseMetaTileEntity().isActive()) { - if (MathUtils.randInt(0, 5) <= 2) { - this.sendSound((byte) -120); - } - } - - } //End of is serverside block. - } - - - public int getCurrentChunkPollution(){ - int mCurrentChunkPollution = 0; - if (this.mTier < 7) { - mCurrentChunkPollution = PollutionUtils.getPollution(getBaseMetaTileEntity()); - } - else { - AutoMap<Chunk> aSurrounding = new AutoMap<Chunk>(); - World aWorld = this.getBaseMetaTileEntity().getWorld(); - int xPos = this.getBaseMetaTileEntity().getXCoord(); - int zPos = this.getBaseMetaTileEntity().getZCoord(); - Chunk a1 = aWorld.getChunkFromBlockCoords(xPos-32, zPos-32); - Chunk a2 = aWorld.getChunkFromBlockCoords(xPos-32, zPos); - Chunk a3 = aWorld.getChunkFromBlockCoords(xPos-32, zPos+32); - Chunk b1 = aWorld.getChunkFromBlockCoords(xPos, zPos-32); - Chunk b2 = aWorld.getChunkFromBlockCoords(xPos, zPos); - Chunk b3 = aWorld.getChunkFromBlockCoords(xPos, zPos+32); - Chunk c1 = aWorld.getChunkFromBlockCoords(xPos+32, zPos-32); - Chunk c2 = aWorld.getChunkFromBlockCoords(xPos+32, zPos); - Chunk c3 = aWorld.getChunkFromBlockCoords(xPos+32, zPos+32); - aSurrounding.put(a1); - aSurrounding.put(a2); - aSurrounding.put(a3); - aSurrounding.put(b1); - aSurrounding.put(b2); - aSurrounding.put(b3); - aSurrounding.put(c1); - aSurrounding.put(c2); - aSurrounding.put(c3); - for (Chunk r : aSurrounding) { - mCurrentChunkPollution += getPollutionInChunk(r); - } - } - if (mCurrentChunkPollution > 0){ - mHasPollution = true; - } - else { - mHasPollution = false; - } - return mCurrentChunkPollution; - } - - public int getPollutionInChunk(Chunk aChunk){ - int mCurrentChunkPollution = PollutionUtils.getPollution(aChunk); - if (mCurrentChunkPollution > 0){ - mHasPollution = true; - } - else { - mHasPollution = false; - } - return mCurrentChunkPollution; - } - - public boolean hasRotor(ItemStack rotorStack){ - if(rotorStack != null){ - if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { - //Logger.INFO("Found Basic Turbine Rotor."); - return true; - } - else if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool && rotorStack.getItemDamage() >= 170 && rotorStack.getItemDamage() <= 179){ - //Logger.INFO("Found Turbine Rotor."); - return true; - } - else { - //Logger.INFO("Found: "+rotorStack.getDisplayName()+":"+rotorStack.getItemDamage()); - } - } - //Logger.INFO("Found No Turbine Rotor."); - return false; - } - - public boolean damageTurbineRotor(){ - try{ - - boolean creativeRotor = false; - ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; - if (rotorStack == null) { - return false; - } - else if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { - long currentUse = ItemBasicScrubberTurbine.getFilterDamage(rotorStack); - //Remove broken Filter - if (rotorStack.getItemDamage() == 0 && currentUse >= 2000-10){ - Logger.INFO("Depleting ItemBasicScrubberTurbine T1"); - this.mInventory[this.SLOT_FILTER] = null; - return false; - } - else if (rotorStack.getItemDamage() == 1 && currentUse >= 4000-10){ - Logger.INFO("Depleting ItemBasicScrubberTurbine T2"); - this.mInventory[this.SLOT_FILTER] = null; - return false; - } - else if (rotorStack.getItemDamage() == 2 && currentUse >= 6000-10){ - Logger.INFO("Depleting ItemBasicScrubberTurbine T3"); - this.mInventory[this.SLOT_FILTER] = null; - return false; - } - else { - //Do Damage - Logger.INFO("Damaging ItemBasicScrubberTurbine"); - ItemBasicScrubberTurbine.setFilterDamage(rotorStack, currentUse+10); - Logger.INFO("Rotor Damage: "+currentUse); - return true; - } - } - else if(rotorStack.getItem() instanceof GT_MetaGenerated_Tool_01) { - Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(rotorStack); - Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(rotorStack); - if (t1 == Materials._NULL && t2 == Materials._NULL){ - Logger.INFO("Found creative rotor."); - creativeRotor = true; - } - } - else { - Logger.INFO("Bad item in rotor slot."); - return false; - } - - if(mInventory[SLOT_ROTOR].getItem() instanceof GT_MetaGenerated_Tool_01 && - ((GT_MetaGenerated_Tool) mInventory[SLOT_ROTOR].getItem()).getToolStats(mInventory[SLOT_ROTOR]).getSpeedMultiplier()>0 && - GT_MetaGenerated_Tool.getPrimaryMaterial(mInventory[SLOT_ROTOR]).mToolSpeed>0 ) { - - long damageValue = (long) Math.floor(Math.abs(MathUtils.randFloat(1, 2) - MathUtils.randFloat(1, 3)) * (1 + 3 - 1) + 1); - double fDam = Math.floor(Math.abs(MathUtils.randFloat(1f, 2f) - MathUtils.randFloat(1f, 2f)) * (1f + 2f - 1f) + 1f); - damageValue -= fDam; - - //Logger.INFO("Trying to do "+damageValue+" damage to the rotor. ["+fDam+"]"); - /*Materials M1 = GT_MetaGenerated_Tool.getPrimaryMaterial(this.mInventory[this.SLOT_ROTOR]); - Materials M2 = GT_MetaGenerated_Tool.getSecondaryMaterial(this.mInventory[this.SLOT_ROTOR]); - - Logger.INFO("Trying to do "+damageValue+" damage to the rotor. [2]");*/ - - //Damage Rotor - //int rotorDurability = this.mInventory[this.SLOT_ROTOR].getItemDamage(); - long rotorDamage = creativeRotor ? 0 : GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); - long rotorDurabilityMax = creativeRotor ? Integer.MAX_VALUE : GT_MetaGenerated_Tool.getToolMaxDamage(this.mInventory[this.SLOT_ROTOR]); - long rotorDurability = (rotorDurabilityMax - rotorDamage); - Logger.INFO("Rotor Damage: "+rotorDamage + " | Max Durability: "+rotorDurabilityMax+" | "+" Remaining Durability: "+rotorDurability); - if (rotorDurability >= damageValue){ - - - if (!mSaveRotor){ - Logger.INFO("Damaging Rotor."); - - if (!creativeRotor) - GT_ModHandler.damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue, 0, null); - - long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); - if (tempDur < rotorDurabilityMax){ - return true; - } - else { - rotorDurability = 0; - } - } - else { - Logger.INFO("Damaging Rotor."); - if (rotorDurability > 1000){ - if (!creativeRotor) - GT_ModHandler.damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue/2, 0, null); - long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); - if (tempDur < rotorDurabilityMax){ - return true; - } - else { - rotorDurability = 0; - } - } - } - - - } - - if (rotorDurability <= 0 && !mSaveRotor && !creativeRotor) { - Logger.INFO("Destroying Rotor."); - this.mInventory[this.SLOT_ROTOR] = null; - return false; - } - else if (rotorDurability <= 0 && mSaveRotor) { - Logger.INFO("Saving Rotor."); - return false; - } - - - }else { - Logger.INFO("Bad Rotor."); - return false; - } - } - catch (Throwable t){ - t.printStackTrace(); - } - return false; - } - - public int getFreeSpaces(){ - int mAir = 0; - IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); - if(aBaseMetaTileEntity.getAirOffset(1, 0, 0)){ - mAir++; - } - if(aBaseMetaTileEntity.getAirOffset(-1, 0, 0)){ - mAir++; - } - if(aBaseMetaTileEntity.getAirOffset(0, 0, 1)){ - mAir++; - } - if(aBaseMetaTileEntity.getAirOffset(0, 0, -1)){ - mAir++; - } - if(aBaseMetaTileEntity.getAirOffset(0, 1, 0)){ - mAir++; - } - if(aBaseMetaTileEntity.getAirOffset(0, -1, 0)){ - mAir++; - } - return mAir; - } - - public boolean removePollution(int toRemove){ - - if (this == null || this.getBaseMetaTileEntity() == null || this.getBaseMetaTileEntity().getWorld() == null) { - return false; - } - - if (this.mTier < 7) { - int startPollution = getCurrentChunkPollution(); - Logger.INFO("Current Chunk Pollution: "+startPollution); - PollutionUtils.removePollution(this.getBaseMetaTileEntity(), toRemove); - int after = getCurrentChunkPollution(); - Logger.INFO("Current Chunk Pollution: "+after); - return (after<startPollution); - } - else { - int chunksWithRemoval = 0; - int totalRemoved = 0; - AutoMap<Chunk> aSurrounding = new AutoMap<Chunk>(); - Chunk aThisChunk = this.getBaseMetaTileEntity().getWorld().getChunkFromBlockCoords(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getZCoord()); - int mainChunkX = aThisChunk.xPosition; - int mainChunkZ = aThisChunk.zPosition; - - World aWorld = this.getBaseMetaTileEntity().getWorld(); - int xPos = this.getBaseMetaTileEntity().getXCoord(); - int zPos = this.getBaseMetaTileEntity().getZCoord(); - - Chunk a1 = aWorld.getChunkFromBlockCoords(xPos-32, zPos-32); - Chunk a2 = aWorld.getChunkFromBlockCoords(xPos-32, zPos); - Chunk a3 = aWorld.getChunkFromBlockCoords(xPos-32, zPos+32); - Chunk b1 = aWorld.getChunkFromBlockCoords(xPos, zPos-32); - Chunk b2 = aWorld.getChunkFromBlockCoords(xPos, zPos); - Chunk b3 = aWorld.getChunkFromBlockCoords(xPos, zPos+32); - Chunk c1 = aWorld.getChunkFromBlockCoords(xPos+32, zPos-32); - Chunk c2 = aWorld.getChunkFromBlockCoords(xPos+32, zPos); - Chunk c3 = aWorld.getChunkFromBlockCoords(xPos+32, zPos+32); - - aSurrounding.put(a1); - aSurrounding.put(a2); - aSurrounding.put(a3); - aSurrounding.put(b1); - aSurrounding.put(b2); - aSurrounding.put(b3); - aSurrounding.put(c1); - aSurrounding.put(c2); - aSurrounding.put(c3); - - for (Chunk r : aSurrounding) { - if (!r.isChunkLoaded) { - continue; - } - - int startPollution = getPollutionInChunk(r); - if (startPollution == 0) { - continue; - } - - Logger.INFO("Trying to remove pollution from chunk "+r.xPosition+", "+r.zPosition+" | "+startPollution); - int after = 0; - boolean isMainChunk = r.isAtLocation(mainChunkX, mainChunkZ); - - int removal = Math.max(0, !isMainChunk ? (toRemove/4) : toRemove); - if (removePollution(r, removal)) { - chunksWithRemoval++; - after = getPollutionInChunk(r); - } - else { - after = 0; - } - if (startPollution - after > 0) { - totalRemoved += (startPollution - after); - } - Logger.INFO("Removed "+(startPollution - after)+" pollution from chunk "+r.xPosition+", "+r.zPosition+" | "+after); - } - return totalRemoved > 0 && chunksWithRemoval > 0; - } - } - - public boolean removePollution(Chunk aChunk, int toRemove){ - int before = getCurrentChunkPollution(); - PollutionUtils.removePollution(aChunk, toRemove); - int after = getCurrentChunkPollution(); - return (after<before); - } - - - public boolean hasAirFilter(ItemStack filter){ - if (filter == null) { - return false; - } - if (filter.getItem() instanceof ItemAirFilter){ - return true; - } - return false; - } - - public boolean damageAirFilter(){ - ItemStack filter = this.mInventory[this.SLOT_FILTER]; - if (filter == null) { - return false; - } - - boolean creativeRotor = false; - ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; - if (rotorStack != null) { - if(rotorStack.getItem() instanceof GT_MetaGenerated_Tool_01) { - Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(rotorStack); - Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(rotorStack); - if (t1 == Materials._NULL && t2 == Materials._NULL){ - creativeRotor = true; - } - } - } - - if (creativeRotor) { - return true; - } - - - if (filter.getItem() instanceof ItemAirFilter){ - - long currentUse = ItemAirFilter.getFilterDamage(filter); - - //Remove broken Filter - if (filter.getItemDamage() == 0 && currentUse >= 50-1){ - this.mInventory[this.SLOT_FILTER] = null; - return false; - } - else if (filter.getItemDamage() == 1 && currentUse >= 2500-1){ - this.mInventory[this.SLOT_FILTER] = null; - return false; - } - else { - //Do Damage - ItemAirFilter.setFilterDamage(filter, currentUse+1); - Logger.INFO("Filter Damage: "+currentUse); - return true; - } - } - return false; - } - - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_PollutionCleaner(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_PollutionCleaner(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), this.mGUIName); - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - if (aIndex == SLOT_FILTER) { - if (aStack.getItem() instanceof ItemAirFilter) { - Logger.INFO("Inserting Air Filter into "+aIndex); - return true; - } - } - if (aIndex == SLOT_ROTOR) { - if (this.mInventory[7] != null) { - Logger.INFO("Found conveyor, can automate turbines. Inserting into "+aIndex); - if (aStack.getItem() instanceof ItemBasicScrubberTurbine) { - return true; - } - if (aStack.getItem() instanceof GT_MetaGenerated_Tool && aStack.getItemDamage() >= 170 && aStack.getItemDamage() <= 179){ - return true; - } - } - } - //return super.canInsertItem(aIndex, aStack, aSide); - return false; - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - public boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, - float aZ) { - this.mSaveRotor = Utils.invertBoolean(mSaveRotor); - if (mSaveRotor){ - PlayerUtils.messagePlayer(aPlayer, "Running in low efficiency mode, rotors will not break."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Running in high efficiency mode, rotors will break."); - } - return true; - } - - @Override - public void doSound(byte aIndex, double aX, double aY, double aZ) { - if (aIndex == -120) { - GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(103)), MathUtils.randInt(5, 50), 0.05F, aX, aY, aZ); - } else if (aIndex == -121 || aIndex == -122) { - //GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(108)), 0, 0.5F, aX, aY, aZ); - } /*else if (aIndex == -122) { - GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(6)), 100, 1.0F, aX, aY, aZ); - }*/ else { - super.doSound((byte) 0, aX, aY, aZ); - } - } - - @Override - public boolean canHaveInsufficientEnergy() { - // TODO Auto-generated method stub - return super.canHaveInsufficientEnergy(); - } - - @Override - public String[] getInfoData() { - AutoMap<String> aTooltipSuper = new AutoMap<String>(); - for (String s : super.getInfoData()) { - aTooltipSuper.put(s); - } - int mAirSides = getFreeSpaces(); - int reduction = 0; - - try { - long tVoltage = maxEUInput(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - reduction += (((Math.max((tTier-2), 1)*2)*50)*mAirSides); - reduction = (MathUtils.safeInt((long)reduction*this.mBaseEff)/100000)*mAirSides*Math.max((tTier-2), 1); - reduction = MathUtils.safeInt(((long)reduction/100)*this.mOptimalAirFlow); - - aTooltipSuper.put("Maximum pollution removed per second: "+reduction); - } - catch (Throwable t) { - aTooltipSuper.put("Maximum pollution removed per second: "+mPollutionReduction); - } - aTooltipSuper.put("Air Sides: "+mAirSides); - - String[] mBuiltOutput = new String[aTooltipSuper.size()]; - int aIndex = 0; - for (String i : aTooltipSuper) { - mBuiltOutput[aIndex++] = i; - } - - - - return mBuiltOutput; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { - if (aSide <= 1) { - return false; - } - return super.allowCoverOnSide(aSide, aCoverID); - } - - @Override - public ITexture[] getTopFacingInactive(byte aColor) { - return super.getTopFacingInactive(aColor); - } - - @Override - public void setItemNBT(NBTTagCompound aNBT) { - aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); - aNBT.setBoolean("mSaveRotor", mSaveRotor); - super.setItemNBT(aNBT); - } - - private static ItemStack[] sGregTurbines; - - public static ItemStack getTieredTurbine(int aTier) { - if (sGregTurbines == null) { - sGregTurbines = new ItemStack[3]; - sGregTurbines[0] = GT_MetaGenerated_Tool.sInstances.get("gt.metatool.01").getToolWithStats(GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Iron, Materials.Iron, null); - sGregTurbines[1] = GT_MetaGenerated_Tool.sInstances.get("gt.metatool.01").getToolWithStats(GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Bronze, Materials.Bronze, null); - sGregTurbines[2] = GT_MetaGenerated_Tool.sInstances.get("gt.metatool.01").getToolWithStats(GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Steel, Materials.Steel, null); - } - else { - return sGregTurbines[aTier]; - } - - return null; - } - - public int getBaseEfficiency(ItemStack aStackRotor) { - if (aStackRotor.getItem() instanceof ItemBasicScrubberTurbine) { - return getBaseEfficiency(getTieredTurbine(aStackRotor.getItemDamage())); - } - return (int) ((50.0F + (10.0F * ((GT_MetaGenerated_Tool) aStackRotor.getItem()).getToolCombatDamage(aStackRotor))) * 100); - } - - public int getOptimalAirFlow(ItemStack aStackRotor) { - if (aStackRotor.getItem() instanceof ItemBasicScrubberTurbine) { - return getOptimalAirFlow(getTieredTurbine(aStackRotor.getItemDamage())); - } - return (int) Math.max(Float.MIN_NORMAL, ((GT_MetaGenerated_Tool) aStackRotor.getItem()).getToolStats(aStackRotor).getSpeedMultiplier() - * GT_MetaGenerated_Tool.getPrimaryMaterial(aStackRotor).mToolSpeed * 50); - } - -}
\ No newline at end of file + public int mPollutionReduction = 0; + protected int mBaseEff = 2500; + protected int mOptimalAirFlow = 0; + protected boolean mHasPollution = false; + protected int SLOT_ROTOR = 5; + protected int SLOT_FILTER = 6; + protected static boolean mPollutionEnabled = true; + + protected boolean mSaveRotor = false; + + public GregtechMetaAtmosphericReconditioner(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 2, + "Making sure you don't live in Gwalior - Uses 2A", + 3, + 0, + "Recycler.png", + "", + new ITexture[] { + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB) + }); + mPollutionEnabled = PollutionUtils.isPollutionEnabled(); + } + + public GregtechMetaAtmosphericReconditioner( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 2, aDescription, aTextures, 2, 0, aGUIName, aNEIName); + mPollutionEnabled = PollutionUtils.isPollutionEnabled(); + } + + /*public GregtechMetaAtmosphericReconditioner(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 2, aDescription, aTextures, 2, 0, aGUIName, aNEIName); + }*/ + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaAtmosphericReconditioner( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public String[] getDescription() { + + boolean highTier = this.mTier >= 7; + + String[] A = new String[] { + this.mDescription, + highTier ? "Will attempt to remove 1/4 pollution from 8 surrounding chunks" : "", + highTier ? "If these chunks are not loaded, they will be ignored" : "", + "Requires a turbine rotor and an Air Filter [T1/T2] to run.", + "The turbine rotor must be manually inserted/replaced", + "Can be configured with a soldering iron to change modes", + "Low Efficiency: Removes half pollution, Turbine takes 50% dmg", + "High Efficiency: Removes full pollution, Turbine takes 100% dmg", + "Turbine Rotor will not break in LE mode", + "Insert an equal tier Conveyor Module to enable automation" + }; + if (!mPollutionEnabled) { + String[] B = new String[] { + "===============================================", + "Pollution is disabled, scrubbers will now have a bonus use", + "They are now able to remove ALL lingering pollution as GT ignores it", + "and it will linger forever!", + "===============================================", + }; + A = ArrayUtils.addAll(A, B); + } + return A; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); + aNBT.setBoolean("mSaveRotor", mSaveRotor); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mOptimalAirFlow = aNBT.getInteger("mOptimalAirFlow"); + this.mSaveRotor = aNBT.getBoolean("mSaveRotor"); + } + + @Override + public long maxAmperesIn() { + return 2; + } + + @Override + public long getMinimumStoredEU() { + return V[mTier] * 2; + } + + @Override + public long maxEUStore() { + return V[mTier] * 256; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + + // Get Current Pollution Amount. + int mCurrentPollution = getCurrentChunkPollution(); + boolean isIdle = true; + + // Get Inventory Item + ItemStack stackRotor = this.mInventory[SLOT_ROTOR]; + ItemStack stackFilter = this.mInventory[SLOT_FILTER]; + + // Power Drain + long drainEU = maxEUInput() * maxAmperesIn(); + if (aBaseMetaTileEntity.isActive() && aBaseMetaTileEntity.getStoredEU() >= drainEU) { + if (aBaseMetaTileEntity.decreaseStoredEnergyUnits(drainEU, false)) { + isIdle = false; + } else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } else if (!aBaseMetaTileEntity.isActive() && aBaseMetaTileEntity.getStoredEU() >= drainEU / 4) { + if (aBaseMetaTileEntity.decreaseStoredEnergyUnits((drainEU / 4), false)) { + isIdle = false; + } else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + + // Only try once/sec. + if (!isIdle && aTick % 20L == 0L) { + + for (int i = 0; i < this.mInventory.length; i++) { + ItemStack aSlotContent = this.mInventory[i]; + if (aSlotContent != null) { + Logger.INFO("Found " + aSlotContent.getDisplayName() + " in slot " + i); + } + } + + for (int i = 0; i < this.mInventory.length; i++) { + if (hasRotor(this.mInventory[i])) { + Logger.INFO("Found Rotor in slot " + i); + break; + } + } + for (int i = 0; i < this.mInventory.length; i++) { + if (hasAirFilter(this.mInventory[i])) { + Logger.INFO("Found Filter in slot " + i); + break; + } + } + + // Check if machine can work. + if ((aBaseMetaTileEntity.isAllowedToWork())) { + Logger.INFO("Can work."); + + // Enable machine animation/graphic + if (hasRotor(stackRotor) && hasAirFilter(stackFilter) && this.mHasPollution) { + if (!this.getBaseMetaTileEntity().isActive()) { + Logger.INFO("Set Active."); + aBaseMetaTileEntity.setActive(true); + } + } else if (!this.mHasPollution + || mCurrentPollution <= 0 + || stackRotor == null + || stackFilter == null + || !hasRotor(stackRotor) + || !hasAirFilter(stackFilter)) { + if (!this.getBaseMetaTileEntity().isActive()) { + Logger.INFO("Set Inactive."); + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } + + // If Active. + if (aBaseMetaTileEntity.isActive()) { + Logger.INFO("Doing something."); + + // Do nothing if there is no pollution. + if (this.mHasPollution && mCurrentPollution > 0) { + Logger.INFO( + "Has Pollution? " + mHasPollution + ", Current Pollution: " + mCurrentPollution); + + // Only check every 30s. + if (!isIdle && aTick % (20L * 30) == 0L) { + mPollutionEnabled = PollutionUtils.isPollutionEnabled(); + // Clear out pollution if it's disabled, because I am a nice gal. + if (!PollutionUtils.isPollutionEnabled()) { + PollutionUtils.nullifyPollution(this.getBaseMetaTileEntity()); + } + } + + // Use a Turbine + if (hasRotor(stackRotor) && hasAirFilter(stackFilter)) { + Logger.INFO("Found Turbine."); + + mBaseEff = getBaseEfficiency(stackRotor); + mOptimalAirFlow = getOptimalAirFlow(stackRotor); + + // Make sure we have a valid Turbine and Eff/Airflow + if (this.mBaseEff > 0 && this.mOptimalAirFlow > 0) { + // Utils.LOG_WARNING("Pollution Cleaner [5]"); + + // Log Debug information. + Logger.INFO("mBaseEff[1]:" + mBaseEff); + Logger.INFO("mOptimalAirFlow[1]:" + mOptimalAirFlow); + + // Calculate The Voltage we are running + long tVoltage = drainEU; + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + // Check Sides for Air, + // More air means more pollution processing. + int mAirSides = getFreeSpaces(); + + int reduction = 0; + + // If no sides are free, how will you process the atmosphere? + if (mAirSides > 0) { + reduction += (((Math.max((tTier - 2), 1) * 2) * 50) + * mAirSides); // Was originally *100 + Logger.INFO("mPollutionReduction[1]:" + reduction); + + // I stole this code + reduction = (MathUtils.safeInt((long) reduction * this.mBaseEff) / 100000) + * mAirSides + * Math.max((tTier - 2), 1); + Logger.INFO("reduction[2]:" + reduction); + reduction = MathUtils.safeInt(((long) reduction / 100) * this.mOptimalAirFlow); + Logger.INFO("reduction[3]:" + reduction); + + mPollutionReduction = reduction; + + // Set a temp to remove variable to aleviate duplicate code. + int toRemove = 0; + + Logger.INFO("mCurrentPollution[4]:" + mCurrentPollution); + Logger.INFO("mCurrentPollution[5]:" + reduction); + if (reduction <= mCurrentPollution) { + // Clean some Air. + toRemove = reduction; + } else { + // Makes sure we don't get negative pollution. + toRemove = mCurrentPollution; + } + + toRemove = toRemove / 2; + Logger.INFO("mCurrentPollution[6]:" + toRemove); + + // We are good to clean + if (toRemove > 0) { + if (damageTurbineRotor() && damageAirFilter()) { + Logger.INFO("Removing " + toRemove + " pollution"); + removePollution(mSaveRotor ? (toRemove / 2) : toRemove); + Logger.INFO("mNewPollution[4]:" + getCurrentChunkPollution()); + } else { + Logger.INFO("Could not damage turbine rotor or Air Filter."); + aBaseMetaTileEntity.setActive(false); + } + } // End of pollution removal block. + } // End of valid air sides block. + } // End of valid toolstats block. + } // End of correct inventory item block. + else { + // Utils.LOG_WARNING("Wrong Tool metaitem Found."); + } + } + } else if (!aBaseMetaTileEntity.isActive()) { + return; + } + } // End of can work block. + else { // Disable Machine. + // aBaseMetaTileEntity.setActive(false); + } + } // End of 1/sec action block. + else { + + if (hasRotor(stackRotor) + && hasAirFilter(stackFilter) + && this.mHasPollution + && !isIdle + && aBaseMetaTileEntity.isAllowedToWork()) { + aBaseMetaTileEntity.setActive(true); + } else if (isIdle + || !this.mHasPollution + || mCurrentPollution <= 0 + || stackRotor == null + || stackFilter == null + || !hasRotor(stackRotor) + || !hasAirFilter(stackFilter)) { + aBaseMetaTileEntity.setActive(false); + } + } + if (this.getBaseMetaTileEntity().isActive()) { + if (MathUtils.randInt(0, 5) <= 2) { + this.sendSound((byte) -120); + } + } + } // End of is serverside block. + } + + public int getCurrentChunkPollution() { + int mCurrentChunkPollution = 0; + if (this.mTier < 7) { + mCurrentChunkPollution = PollutionUtils.getPollution(getBaseMetaTileEntity()); + } else { + AutoMap<Chunk> aSurrounding = new AutoMap<Chunk>(); + World aWorld = this.getBaseMetaTileEntity().getWorld(); + int xPos = this.getBaseMetaTileEntity().getXCoord(); + int zPos = this.getBaseMetaTileEntity().getZCoord(); + Chunk a1 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos - 32); + Chunk a2 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos); + Chunk a3 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos + 32); + Chunk b1 = aWorld.getChunkFromBlockCoords(xPos, zPos - 32); + Chunk b2 = aWorld.getChunkFromBlockCoords(xPos, zPos); + Chunk b3 = aWorld.getChunkFromBlockCoords(xPos, zPos + 32); + Chunk c1 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos - 32); + Chunk c2 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos); + Chunk c3 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos + 32); + aSurrounding.put(a1); + aSurrounding.put(a2); + aSurrounding.put(a3); + aSurrounding.put(b1); + aSurrounding.put(b2); + aSurrounding.put(b3); + aSurrounding.put(c1); + aSurrounding.put(c2); + aSurrounding.put(c3); + for (Chunk r : aSurrounding) { + mCurrentChunkPollution += getPollutionInChunk(r); + } + } + if (mCurrentChunkPollution > 0) { + mHasPollution = true; + } else { + mHasPollution = false; + } + return mCurrentChunkPollution; + } + + public int getPollutionInChunk(Chunk aChunk) { + int mCurrentChunkPollution = PollutionUtils.getPollution(aChunk); + if (mCurrentChunkPollution > 0) { + mHasPollution = true; + } else { + mHasPollution = false; + } + return mCurrentChunkPollution; + } + + public boolean hasRotor(ItemStack rotorStack) { + if (rotorStack != null) { + if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { + // Logger.INFO("Found Basic Turbine Rotor."); + return true; + } else if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool + && rotorStack.getItemDamage() >= 170 + && rotorStack.getItemDamage() <= 179) { + // Logger.INFO("Found Turbine Rotor."); + return true; + } else { + // Logger.INFO("Found: "+rotorStack.getDisplayName()+":"+rotorStack.getItemDamage()); + } + } + // Logger.INFO("Found No Turbine Rotor."); + return false; + } + + public boolean damageTurbineRotor() { + try { + + boolean creativeRotor = false; + ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; + if (rotorStack == null) { + return false; + } else if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { + long currentUse = ItemBasicScrubberTurbine.getFilterDamage(rotorStack); + // Remove broken Filter + if (rotorStack.getItemDamage() == 0 && currentUse >= 2000 - 10) { + Logger.INFO("Depleting ItemBasicScrubberTurbine T1"); + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else if (rotorStack.getItemDamage() == 1 && currentUse >= 4000 - 10) { + Logger.INFO("Depleting ItemBasicScrubberTurbine T2"); + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else if (rotorStack.getItemDamage() == 2 && currentUse >= 6000 - 10) { + Logger.INFO("Depleting ItemBasicScrubberTurbine T3"); + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else { + // Do Damage + Logger.INFO("Damaging ItemBasicScrubberTurbine"); + ItemBasicScrubberTurbine.setFilterDamage(rotorStack, currentUse + 10); + Logger.INFO("Rotor Damage: " + currentUse); + return true; + } + } else if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool_01) { + Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(rotorStack); + Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(rotorStack); + if (t1 == Materials._NULL && t2 == Materials._NULL) { + Logger.INFO("Found creative rotor."); + creativeRotor = true; + } + } else { + Logger.INFO("Bad item in rotor slot."); + return false; + } + + if (mInventory[SLOT_ROTOR].getItem() instanceof GT_MetaGenerated_Tool_01 + && ((GT_MetaGenerated_Tool) mInventory[SLOT_ROTOR].getItem()) + .getToolStats(mInventory[SLOT_ROTOR]) + .getSpeedMultiplier() + > 0 + && GT_MetaGenerated_Tool.getPrimaryMaterial(mInventory[SLOT_ROTOR]).mToolSpeed > 0) { + + long damageValue = (long) + Math.floor(Math.abs(MathUtils.randFloat(1, 2) - MathUtils.randFloat(1, 3)) * (1 + 3 - 1) + 1); + double fDam = Math.floor( + Math.abs(MathUtils.randFloat(1f, 2f) - MathUtils.randFloat(1f, 2f)) * (1f + 2f - 1f) + 1f); + damageValue -= fDam; + + // Logger.INFO("Trying to do "+damageValue+" damage to the rotor. ["+fDam+"]"); + /*Materials M1 = GT_MetaGenerated_Tool.getPrimaryMaterial(this.mInventory[this.SLOT_ROTOR]); + Materials M2 = GT_MetaGenerated_Tool.getSecondaryMaterial(this.mInventory[this.SLOT_ROTOR]); + + Logger.INFO("Trying to do "+damageValue+" damage to the rotor. [2]");*/ + + // Damage Rotor + // int rotorDurability = this.mInventory[this.SLOT_ROTOR].getItemDamage(); + long rotorDamage = + creativeRotor ? 0 : GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + long rotorDurabilityMax = creativeRotor + ? Integer.MAX_VALUE + : GT_MetaGenerated_Tool.getToolMaxDamage(this.mInventory[this.SLOT_ROTOR]); + long rotorDurability = (rotorDurabilityMax - rotorDamage); + Logger.INFO("Rotor Damage: " + rotorDamage + " | Max Durability: " + rotorDurabilityMax + " | " + + " Remaining Durability: " + rotorDurability); + if (rotorDurability >= damageValue) { + + if (!mSaveRotor) { + Logger.INFO("Damaging Rotor."); + + if (!creativeRotor) + GT_ModHandler.damageOrDechargeItem( + this.mInventory[this.SLOT_ROTOR], (int) damageValue, 0, null); + + long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + if (tempDur < rotorDurabilityMax) { + return true; + } else { + rotorDurability = 0; + } + } else { + Logger.INFO("Damaging Rotor."); + if (rotorDurability > 1000) { + if (!creativeRotor) + GT_ModHandler.damageOrDechargeItem( + this.mInventory[this.SLOT_ROTOR], (int) damageValue / 2, 0, null); + long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + if (tempDur < rotorDurabilityMax) { + return true; + } else { + rotorDurability = 0; + } + } + } + } + + if (rotorDurability <= 0 && !mSaveRotor && !creativeRotor) { + Logger.INFO("Destroying Rotor."); + this.mInventory[this.SLOT_ROTOR] = null; + return false; + } else if (rotorDurability <= 0 && mSaveRotor) { + Logger.INFO("Saving Rotor."); + return false; + } + + } else { + Logger.INFO("Bad Rotor."); + return false; + } + } catch (Throwable t) { + t.printStackTrace(); + } + return false; + } + + public int getFreeSpaces() { + int mAir = 0; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + if (aBaseMetaTileEntity.getAirOffset(1, 0, 0)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(-1, 0, 0)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(0, 0, 1)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(0, 0, -1)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(0, 1, 0)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(0, -1, 0)) { + mAir++; + } + return mAir; + } + + public boolean removePollution(int toRemove) { + + if (this == null + || this.getBaseMetaTileEntity() == null + || this.getBaseMetaTileEntity().getWorld() == null) { + return false; + } + + if (this.mTier < 7) { + int startPollution = getCurrentChunkPollution(); + Logger.INFO("Current Chunk Pollution: " + startPollution); + PollutionUtils.removePollution(this.getBaseMetaTileEntity(), toRemove); + int after = getCurrentChunkPollution(); + Logger.INFO("Current Chunk Pollution: " + after); + return (after < startPollution); + } else { + int chunksWithRemoval = 0; + int totalRemoved = 0; + AutoMap<Chunk> aSurrounding = new AutoMap<Chunk>(); + Chunk aThisChunk = this.getBaseMetaTileEntity() + .getWorld() + .getChunkFromBlockCoords( + this.getBaseMetaTileEntity().getXCoord(), + this.getBaseMetaTileEntity().getZCoord()); + int mainChunkX = aThisChunk.xPosition; + int mainChunkZ = aThisChunk.zPosition; + + World aWorld = this.getBaseMetaTileEntity().getWorld(); + int xPos = this.getBaseMetaTileEntity().getXCoord(); + int zPos = this.getBaseMetaTileEntity().getZCoord(); + + Chunk a1 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos - 32); + Chunk a2 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos); + Chunk a3 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos + 32); + Chunk b1 = aWorld.getChunkFromBlockCoords(xPos, zPos - 32); + Chunk b2 = aWorld.getChunkFromBlockCoords(xPos, zPos); + Chunk b3 = aWorld.getChunkFromBlockCoords(xPos, zPos + 32); + Chunk c1 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos - 32); + Chunk c2 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos); + Chunk c3 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos + 32); + + aSurrounding.put(a1); + aSurrounding.put(a2); + aSurrounding.put(a3); + aSurrounding.put(b1); + aSurrounding.put(b2); + aSurrounding.put(b3); + aSurrounding.put(c1); + aSurrounding.put(c2); + aSurrounding.put(c3); + + for (Chunk r : aSurrounding) { + if (!r.isChunkLoaded) { + continue; + } + + int startPollution = getPollutionInChunk(r); + if (startPollution == 0) { + continue; + } + + Logger.INFO("Trying to remove pollution from chunk " + r.xPosition + ", " + r.zPosition + " | " + + startPollution); + int after = 0; + boolean isMainChunk = r.isAtLocation(mainChunkX, mainChunkZ); + + int removal = Math.max(0, !isMainChunk ? (toRemove / 4) : toRemove); + if (removePollution(r, removal)) { + chunksWithRemoval++; + after = getPollutionInChunk(r); + } else { + after = 0; + } + if (startPollution - after > 0) { + totalRemoved += (startPollution - after); + } + Logger.INFO("Removed " + (startPollution - after) + " pollution from chunk " + r.xPosition + ", " + + r.zPosition + " | " + after); + } + return totalRemoved > 0 && chunksWithRemoval > 0; + } + } + + public boolean removePollution(Chunk aChunk, int toRemove) { + int before = getCurrentChunkPollution(); + PollutionUtils.removePollution(aChunk, toRemove); + int after = getCurrentChunkPollution(); + return (after < before); + } + + public boolean hasAirFilter(ItemStack filter) { + if (filter == null) { + return false; + } + if (filter.getItem() instanceof ItemAirFilter) { + return true; + } + return false; + } + + public boolean damageAirFilter() { + ItemStack filter = this.mInventory[this.SLOT_FILTER]; + if (filter == null) { + return false; + } + + boolean creativeRotor = false; + ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; + if (rotorStack != null) { + if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool_01) { + Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(rotorStack); + Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(rotorStack); + if (t1 == Materials._NULL && t2 == Materials._NULL) { + creativeRotor = true; + } + } + } + + if (creativeRotor) { + return true; + } + + if (filter.getItem() instanceof ItemAirFilter) { + + long currentUse = ItemAirFilter.getFilterDamage(filter); + + // Remove broken Filter + if (filter.getItemDamage() == 0 && currentUse >= 50 - 1) { + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else if (filter.getItemDamage() == 1 && currentUse >= 2500 - 1) { + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else { + // Do Damage + ItemAirFilter.setFilterDamage(filter, currentUse + 1); + Logger.INFO("Filter Damage: " + currentUse); + return true; + } + } + return false; + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_PollutionCleaner(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_PollutionCleaner(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), this.mGUIName); + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + if (aIndex == SLOT_FILTER) { + if (aStack.getItem() instanceof ItemAirFilter) { + Logger.INFO("Inserting Air Filter into " + aIndex); + return true; + } + } + if (aIndex == SLOT_ROTOR) { + if (this.mInventory[7] != null) { + Logger.INFO("Found conveyor, can automate turbines. Inserting into " + aIndex); + if (aStack.getItem() instanceof ItemBasicScrubberTurbine) { + return true; + } + if (aStack.getItem() instanceof GT_MetaGenerated_Tool + && aStack.getItemDamage() >= 170 + && aStack.getItemDamage() <= 179) { + return true; + } + } + } + // return super.canInsertItem(aIndex, aStack, aSide); + return false; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + public boolean onSolderingToolRightClick( + byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + this.mSaveRotor = Utils.invertBoolean(mSaveRotor); + if (mSaveRotor) { + PlayerUtils.messagePlayer(aPlayer, "Running in low efficiency mode, rotors will not break."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Running in high efficiency mode, rotors will break."); + } + return true; + } + + @Override + public void doSound(byte aIndex, double aX, double aY, double aZ) { + if (aIndex == -120) { + GT_Utility.doSoundAtClient( + (String) GregTech_API.sSoundList.get(Integer.valueOf(103)), + MathUtils.randInt(5, 50), + 0.05F, + aX, + aY, + aZ); + } else if (aIndex == -121 || aIndex == -122) { + // GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(108)), 0, 0.5F, aX, aY, + // aZ); + } /*else if (aIndex == -122) { + GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(6)), 100, 1.0F, aX, aY, aZ); + }*/ else { + super.doSound((byte) 0, aX, aY, aZ); + } + } + + @Override + public boolean canHaveInsufficientEnergy() { + // TODO Auto-generated method stub + return super.canHaveInsufficientEnergy(); + } + + @Override + public String[] getInfoData() { + AutoMap<String> aTooltipSuper = new AutoMap<String>(); + for (String s : super.getInfoData()) { + aTooltipSuper.put(s); + } + int mAirSides = getFreeSpaces(); + int reduction = 0; + + try { + long tVoltage = maxEUInput(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + reduction += (((Math.max((tTier - 2), 1) * 2) * 50) * mAirSides); + reduction = (MathUtils.safeInt((long) reduction * this.mBaseEff) / 100000) + * mAirSides + * Math.max((tTier - 2), 1); + reduction = MathUtils.safeInt(((long) reduction / 100) * this.mOptimalAirFlow); + + aTooltipSuper.put("Maximum pollution removed per second: " + reduction); + } catch (Throwable t) { + aTooltipSuper.put("Maximum pollution removed per second: " + mPollutionReduction); + } + aTooltipSuper.put("Air Sides: " + mAirSides); + + String[] mBuiltOutput = new String[aTooltipSuper.size()]; + int aIndex = 0; + for (String i : aTooltipSuper) { + mBuiltOutput[aIndex++] = i; + } + + return mBuiltOutput; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { + if (aSide <= 1) { + return false; + } + return super.allowCoverOnSide(aSide, aCoverID); + } + + @Override + public ITexture[] getTopFacingInactive(byte aColor) { + return super.getTopFacingInactive(aColor); + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); + aNBT.setBoolean("mSaveRotor", mSaveRotor); + super.setItemNBT(aNBT); + } + + private static ItemStack[] sGregTurbines; + + public static ItemStack getTieredTurbine(int aTier) { + if (sGregTurbines == null) { + sGregTurbines = new ItemStack[3]; + sGregTurbines[0] = GT_MetaGenerated_Tool.sInstances + .get("gt.metatool.01") + .getToolWithStats(GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Iron, Materials.Iron, null); + sGregTurbines[1] = GT_MetaGenerated_Tool.sInstances + .get("gt.metatool.01") + .getToolWithStats( + GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Bronze, Materials.Bronze, null); + sGregTurbines[2] = GT_MetaGenerated_Tool.sInstances + .get("gt.metatool.01") + .getToolWithStats( + GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Steel, Materials.Steel, null); + } else { + return sGregTurbines[aTier]; + } + + return null; + } + + public int getBaseEfficiency(ItemStack aStackRotor) { + if (aStackRotor.getItem() instanceof ItemBasicScrubberTurbine) { + return getBaseEfficiency(getTieredTurbine(aStackRotor.getItemDamage())); + } + return (int) + ((50.0F + (10.0F * ((GT_MetaGenerated_Tool) aStackRotor.getItem()).getToolCombatDamage(aStackRotor))) + * 100); + } + + public int getOptimalAirFlow(ItemStack aStackRotor) { + if (aStackRotor.getItem() instanceof ItemBasicScrubberTurbine) { + return getOptimalAirFlow(getTieredTurbine(aStackRotor.getItemDamage())); + } + return (int) Math.max( + Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStackRotor.getItem()) + .getToolStats(aStackRotor) + .getSpeedMultiplier() + * GT_MetaGenerated_Tool.getPrimaryMaterial(aStackRotor).mToolSpeed + * 50); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaCondensor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaCondensor.java index 0f7edd062d..531c7c5694 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaCondensor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaCondensor.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; -import net.minecraft.entity.player.InventoryPlayer; - import gregtech.api.enums.Dyes; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -9,166 +7,174 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_ModHandler; - import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_SteamCondenser; import gtPlusPlus.xmod.gregtech.api.gui.GUI_SteamCondenser; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators.GregtechMetaBoilerBase; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; -public class GregtechMetaCondensor extends GregtechMetaBoilerBase{ +public class GregtechMetaCondensor extends GregtechMetaBoilerBase { - public GregtechMetaCondensor(final int aID, final String aName, final String aNameRegional) - { - super(aID, aName, aNameRegional, "A Steam condenser - [IC2->Steam]", new ITexture[0]); - } + public GregtechMetaCondensor(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional, "A Steam condenser - [IC2->Steam]", new ITexture[0]); + } - public GregtechMetaCondensor(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) - { - super(aName, aTier, aDescription, aTextures); - } + public GregtechMetaCondensor( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } - @Override - public String[] getDescription() { - return new String[]{this.mDescription, "IC2 Steam + Water = Normal Steam.", "Requires no power to run, although it's not very fast.", CORE.GT_Tooltip}; - } + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "IC2 Steam + Water = Normal Steam.", + "Requires no power to run, although it's not very fast.", + CORE.GT_Tooltip + }; + } - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) - { - final ITexture[][][] rTextures = new ITexture[5][17][]; - for (byte i = -1; i < 16; i++){ - rTextures[0][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa))}; - rTextures[1][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) }; - rTextures[2][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) }; - rTextures[3][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER) }; - rTextures[4][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE) }; - } - return rTextures; - } + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[5][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][(i + 1)] = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)) + }; + rTextures[1][(i + 1)] = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) + }; + rTextures[2][(i + 1)] = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) + }; + rTextures[3][(i + 1)] = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER) + }; + rTextures[4][(i + 1)] = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE) + }; + } + return rTextures; + } - @Override - public int maxProgresstime() - { - return 1000; - } + @Override + public int maxProgresstime() { + return 1000; + } - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) - { - return new CONTAINER_SteamCondenser(aPlayerInventory, aBaseMetaTileEntity); - } + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_SteamCondenser(aPlayerInventory, aBaseMetaTileEntity); + } - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) - { - return new GUI_SteamCondenser(aPlayerInventory, aBaseMetaTileEntity, "SteelBoiler.png"); - } + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_SteamCondenser(aPlayerInventory, aBaseMetaTileEntity, "SteelBoiler.png"); + } - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) - { - return new GregtechMetaCondensor(this.mName, this.mTier, this.mDescription, this.mTextures); - } + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaCondensor(this.mName, this.mTier, this.mDescription, this.mTextures); + } - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) - { - this.RI = MathUtils.randLong(5L, 30L); - if ((aBaseMetaTileEntity.isServerSide()) && (aTick > 20L)) - { - if (this.mTemperature <= 5) - { - this.mTemperature = 5; - this.mLossTimer = 0; - } - if (++this.mLossTimer > 10) - { - this.mTemperature -= 1; - this.mLossTimer = 0; - } - for (byte i = 1; (this.mSteam != null) && (i < 6); i = (byte)(i + 1)) { - if (i != aBaseMetaTileEntity.getFrontFacing()) - { - final IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide(i); - if (tTileEntity != null) - { - final FluidStack tDrained = aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), Math.max(1, this.mSteam.amount / 2), false); - if (tDrained != null) - { - final int tFilledAmount = tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), tDrained, false); - if (tFilledAmount > 0) { - tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), tFilledAmount, true), true); - } - } - } - } - } - if ((aTick % 10L) == 0L) { - if (this.mTemperature > 5) - { - if ((this.mFluid == null) || (!GT_ModHandler.isWater(this.mFluid)) || (this.mFluid.amount <= 0)) - { - this.mHadNoWater = true; - } - else - { - if (this.mHadNoWater) - { - aBaseMetaTileEntity.doExplosion(2048L); - return; - } - this.mFluid.amount -= 1; - if (this.mSteam == null) { - this.mSteam = GT_ModHandler.getSteam(30L); - } else if (GT_ModHandler.isSteam(this.mSteam)) { - this.mSteam.amount += 30; - } else { - this.mSteam = GT_ModHandler.getSteam(30L); - } - } - } - else { - this.mHadNoWater = false; - } - } - if ((this.mSteam != null) && - (this.mSteam.amount > getSteamCapacity())) - { - this.sendSound((byte)1); - this.mSteam.amount = getSteamCapacity() * 3 / 4; - } - /*if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()) && - (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.bucket.get(IC2.getItemFromBlock(p_150898_0_))))) - { - this.mProcessingEnergy += 1000; - aBaseMetaTileEntity.decrStackSize(2, 1); - aBaseMetaTileEntity.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.bucket, Materials.Empty, 1L)); - }*/ - if ((this.mTemperature < 1000) && (this.mProcessingEnergy > 0) && ((aTick % this.RI) == 0L)) - { - this.mProcessingEnergy -= 40; - this.mTemperature += 2; - } - aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0); - } - } + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + this.RI = MathUtils.randLong(5L, 30L); + if ((aBaseMetaTileEntity.isServerSide()) && (aTick > 20L)) { + if (this.mTemperature <= 5) { + this.mTemperature = 5; + this.mLossTimer = 0; + } + if (++this.mLossTimer > 10) { + this.mTemperature -= 1; + this.mLossTimer = 0; + } + for (byte i = 1; (this.mSteam != null) && (i < 6); i = (byte) (i + 1)) { + if (i != aBaseMetaTileEntity.getFrontFacing()) { + final IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide(i); + if (tTileEntity != null) { + final FluidStack tDrained = aBaseMetaTileEntity.drain( + ForgeDirection.getOrientation(i), Math.max(1, this.mSteam.amount / 2), false); + if (tDrained != null) { + final int tFilledAmount = tTileEntity.fill( + ForgeDirection.getOrientation(i).getOpposite(), tDrained, false); + if (tFilledAmount > 0) { + tTileEntity.fill( + ForgeDirection.getOrientation(i).getOpposite(), + aBaseMetaTileEntity.drain( + ForgeDirection.getOrientation(i), tFilledAmount, true), + true); + } + } + } + } + } + if ((aTick % 10L) == 0L) { + if (this.mTemperature > 5) { + if ((this.mFluid == null) || (!GT_ModHandler.isWater(this.mFluid)) || (this.mFluid.amount <= 0)) { + this.mHadNoWater = true; + } else { + if (this.mHadNoWater) { + aBaseMetaTileEntity.doExplosion(2048L); + return; + } + this.mFluid.amount -= 1; + if (this.mSteam == null) { + this.mSteam = GT_ModHandler.getSteam(30L); + } else if (GT_ModHandler.isSteam(this.mSteam)) { + this.mSteam.amount += 30; + } else { + this.mSteam = GT_ModHandler.getSteam(30L); + } + } + } else { + this.mHadNoWater = false; + } + } + if ((this.mSteam != null) && (this.mSteam.amount > getSteamCapacity())) { + this.sendSound((byte) 1); + this.mSteam.amount = getSteamCapacity() * 3 / 4; + } + /*if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()) && + (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.bucket.get(IC2.getItemFromBlock(p_150898_0_))))) + { + this.mProcessingEnergy += 1000; + aBaseMetaTileEntity.decrStackSize(2, 1); + aBaseMetaTileEntity.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.bucket, Materials.Empty, 1L)); + }*/ + if ((this.mTemperature < 1000) && (this.mProcessingEnergy > 0) && ((aTick % this.RI) == 0L)) { + this.mProcessingEnergy -= 40; + this.mTemperature += 2; + } + aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0); + } + } - @Override - public final int fill(final FluidStack aFluid, final boolean doFill) - { - if ((Utils.isIC2Steam(aFluid)) && (this.mProcessingEnergy < 50)) - { - final int tFilledAmount = Math.min(50, aFluid.amount); - if (doFill) { - this.mProcessingEnergy += tFilledAmount; - } - return tFilledAmount; - } - return super.fill(aFluid, doFill); - } + @Override + public final int fill(final FluidStack aFluid, final boolean doFill) { + if ((Utils.isIC2Steam(aFluid)) && (this.mProcessingEnergy < 50)) { + final int tFilledAmount = Math.min(50, aFluid.amount); + if (doFill) { + this.mProcessingEnergy += tFilledAmount; + } + return tFilledAmount; + } + return super.fill(aFluid, doFill); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaGarbageCollector.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaGarbageCollector.java index 88658c399d..f1e0cc7161 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaGarbageCollector.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaGarbageCollector.java @@ -18,306 +18,402 @@ import net.minecraft.world.World; public class GregtechMetaGarbageCollector extends GregtechMetaTileEntity { - long mLastCleanup = 0; - long mLocalTickVar = 0; - int mFrequency = 5; - - public GregtechMetaGarbageCollector(final String aName, final String aNameRegional, final String aDescription) { - super(991, aName, aNameRegional, 5, 0, aDescription); - } - - public GregtechMetaGarbageCollector(final String aName, final String aDescription, final ITexture[][][] aTextures) { - super(aName, 5, 0, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[] {this.mDescription, - "Can request the JVM to perform garbage collection", - "Configurable to run once every 5 minute interval (5-180)", - "This Machine has no recipe", - "Admin Tool, Limit one per world if possible", - CORE.GT_Tooltip}; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; - } - - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; - } - - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; - } - - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; - } - - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redox_3)}; - } - - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; - } - - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; - } - - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; - } - - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; - } - - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redox_3)}; - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (mFrequency < 180){ - mFrequency += 5; - } - else { - mFrequency = 5; - } - PlayerUtils.messagePlayer(aPlayer, "Running every "+mFrequency+" minutes."); - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaGarbageCollector(this.mName, this.mDescription, this.mTextures); - } - - @Override public boolean isSimpleMachine() {return true;} - @Override public boolean isElectric() {return false;} - @Override public boolean isValidSlot(final int aIndex) {return false;} - @Override public boolean isFacingValid(final byte aFacing) {return true;} - @Override public boolean isEnetInput() {return false;} - @Override public boolean isEnetOutput() {return false;} - @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isTeleporterCompatible() {return false;} - @Override public long getMinimumStoredEU() {return 0;} - @Override public long maxEUStore() {return 0;} - - @Override - public int getCapacity() { - return 0; - } - - @Override - public long maxEUInput() { - return 0; - } - - @Override - public long maxEUOutput() { - return 0; - } - - @Override - public long maxAmperesIn() { - return 0; - } - - @Override - public long maxAmperesOut() { - return 0; - } - @Override public int rechargerSlotStartIndex() {return 0;} - @Override public int dechargerSlotStartIndex() {return 0;} - @Override public int rechargerSlotCount() {return 0;} - @Override public int dechargerSlotCount() {return 0;} - @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} - @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} - @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) - { - return true; - } - this.showPollution(aPlayer.getEntityWorld(), aPlayer); - return true; - } - - private void showPollution(final World worldIn, final EntityPlayer playerIn){ - PlayerUtils.messagePlayer(playerIn, "Running every "+mFrequency+" minutes. Owner: "+this.getBaseMetaTileEntity().getOwnerName()); - long aDiff = mLocalTickVar - this.mLastCleanup; - PlayerUtils.messagePlayer(playerIn, "Last run: "+Utils.getSecondsFromMillis(aDiff)+" seconds ago."); - - - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - - @Override - public String[] getInfoData() { - return new String[] { - this.getLocalName() - }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { - return new int[] {}; - } - - @Override - public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { - return false; - } - - @Override - public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { - return false; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(final int p_70301_1_) { - return null; - } - - @Override - public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { - return null; - } - - @Override - public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { - } - - @Override - public String getInventoryName() { - return null; - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - @Override - public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { - return true; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { - return false; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isTransformerUpgradable() { - return false; - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (this.getBaseMetaTileEntity().isServerSide()) { - mLocalTickVar = System.currentTimeMillis(); - long aDiff = mLocalTickVar - this.mLastCleanup; - if (Utils.getSecondsFromMillis(aDiff) >= (this.mFrequency * 60)) { - CORE.gc(); - this.mLastCleanup = mLocalTickVar; - } - } - } - -}
\ No newline at end of file + long mLastCleanup = 0; + long mLocalTickVar = 0; + int mFrequency = 5; + + public GregtechMetaGarbageCollector(final String aName, final String aNameRegional, final String aDescription) { + super(991, aName, aNameRegional, 5, 0, aDescription); + } + + public GregtechMetaGarbageCollector(final String aName, final String aDescription, final ITexture[][][] aTextures) { + super(aName, 5, 0, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Can request the JVM to perform garbage collection", + "Configurable to run once every 5 minute interval (5-180)", + "This Machine has no recipe", + "Admin Tool, Limit one per world if possible", + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium) + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redox_3) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel) + }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium) + }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redox_3) + }; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (mFrequency < 180) { + mFrequency += 5; + } else { + mFrequency = 5; + } + PlayerUtils.messagePlayer(aPlayer, "Running every " + mFrequency + " minutes."); + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaGarbageCollector(this.mName, this.mDescription, this.mTextures); + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return 0; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + private void showPollution(final World worldIn, final EntityPlayer playerIn) { + PlayerUtils.messagePlayer( + playerIn, + "Running every " + mFrequency + " minutes. Owner: " + + this.getBaseMetaTileEntity().getOwnerName()); + long aDiff = mLocalTickVar - this.mLastCleanup; + PlayerUtils.messagePlayer(playerIn, "Last run: " + Utils.getSecondsFromMillis(aDiff) + " seconds ago."); + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + return new String[] {this.getLocalName()}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return true; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) {} + + @Override + public void loadNBTData(final NBTTagCompound aNBT) {} + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.getBaseMetaTileEntity().isServerSide()) { + mLocalTickVar = System.currentTimeMillis(); + long aDiff = mLocalTickVar - this.mLastCleanup; + if (Utils.getSecondsFromMillis(aDiff) >= (this.mFrequency * 60)) { + CORE.gc(); + this.mLastCleanup = mLocalTickVar; + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java index 65217f9e53..ce04d50fab 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java @@ -18,365 +18,476 @@ import net.minecraft.world.World; public class GregtechMetaPollutionCreator extends GregtechMetaTileEntity { - int mCurrentPollution; - int mAveragePollution; - int mAveragePollutionArray[] = new int[10]; - private int mArrayPos = 0; - private int mTickTimer = 0; - private int mSecondTimer = 0; - - public GregtechMetaPollutionCreator(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); - } - - public GregtechMetaPollutionCreator(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { - super(aName, aTier, aSlotCount, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[] {this.mDescription, "A useful debug machine to create pollution.", CORE.GT_Tooltip}; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; - } - - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; - } - - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (pollutionMultiplier > 99){ - pollutionMultiplier = 1; - } - else { - pollutionMultiplier++; - } - PlayerUtils.messagePlayer(aPlayer, "Pollution Mutliplier is now "+pollutionMultiplier+"."); - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaPollutionCreator(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); - } - - @Override public boolean isSimpleMachine() {return false;} - @Override public boolean isElectric() {return true;} - @Override public boolean isValidSlot(final int aIndex) {return true;} - @Override public boolean isFacingValid(final byte aFacing) {return true;} - @Override public boolean isEnetInput() {return true;} - @Override public boolean isEnetOutput() {return false;} - @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isTeleporterCompatible() {return false;} - @Override public long getMinimumStoredEU() {return 0;} - @Override public long maxEUStore() {return 0;} - - @Override - public int getCapacity() { - return 0; - } - - @Override - public long maxEUInput() { - return 0; - } - - @Override - public long maxEUOutput() { - return 0; - } - - @Override - public long maxAmperesIn() { - return 0; - } - - @Override - public long maxAmperesOut() { - return 0; - } - @Override public int rechargerSlotStartIndex() {return 0;} - @Override public int dechargerSlotStartIndex() {return 0;} - @Override public int rechargerSlotCount() {return 0;} - @Override public int dechargerSlotCount() {return 0;} - @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} - @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} - @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) - { - return true; - } - this.showPollution(aPlayer.getEntityWorld(), aPlayer); - return true; - } - - public int pollutionMultiplier = 1; - - private void showPollution(final World worldIn, final EntityPlayer playerIn){ - if(!PollutionUtils.isPollutionEnabled()){ - PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); - } - else { - addPollution(); - PlayerUtils.messagePlayer(playerIn, "This chunk now contains "+getCurrentChunkPollution()+" pollution."); - //PlayerUtils.messagePlayer(playerIn, "Average over last ten minutes: "+getAveragePollutionOverLastTen()+" pollution."); - } - } - - private boolean addPollution(){ - PollutionUtils.addPollution(getBaseMetaTileEntity(), 100000*pollutionMultiplier); - return true; - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - public int getCurrentChunkPollution(){ - return getCurrentChunkPollution(this.getBaseMetaTileEntity()); - } - - public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity){ - return PollutionUtils.getPollution(aBaseMetaTileEntity); - } - - - @Override - public String[] getInfoData() { - return new String[] { - this.getLocalName(), - "Current Pollution: "+this.mCurrentPollution, - "Average/10 minutes:"+getAveragePollutionOverLastTen()}; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { - return new int[] {}; - } - - @Override - public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { - return false; - } - - @Override - public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { - return false; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(final int p_70301_1_) { - return null; - } - - @Override - public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { - return null; - } - - @Override - public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { - } - - @Override - public String getInventoryName() { - return null; - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - @Override - public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { - return false; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { - return false; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isTransformerUpgradable() { - return false; - } - - //int mCurrentPollution; - //int mAveragePollution; - //int mAveragePollutionArray[] = new int[10]; - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); - aNBT.setInteger("mAveragePollution", this.mAveragePollution); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); - this.mAveragePollution = aNBT.getInteger("mAveragePollution"); - } - - @Override - public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { - if (this.getBaseMetaTileEntity().isServerSide()) { - if (this.mCurrentPollution == 0) { - this.mCurrentPollution = getCurrentChunkPollution(); - } - if (this.mArrayPos < 0 || this.mArrayPos > 9) { - this.mArrayPos = 0; - } - this.mTickTimer = 0; - } - } - - - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (this.getBaseMetaTileEntity().isServerSide()) { - //TickTimer - 20 times a second - this.mTickTimer++; - if (mTickTimer % 20 == 0){ - this.mCurrentPollution = getCurrentChunkPollution(); - } - } - } - - public int getAveragePollutionOverLastTen(){ - int counter = 0; - int total = 0; - - for (int i=0;i<this.mAveragePollutionArray.length;i++){ - if (this.mAveragePollutionArray[i] != 0){ - total += this.mAveragePollutionArray[i]; - counter++; - } - } - int returnValue = 0; - if (total > 0 && counter > 0){ - returnValue = (total/counter); - this.mAveragePollution = returnValue; - } - else { - returnValue = getCurrentChunkPollution(); - } - //Logger.INFO("| DEBUG: "+returnValue +" | ArrayPos:"+this.mArrayPos+" | Counter:"+counter+" | Total:"+total+" |"); - return returnValue; - } - -}
\ No newline at end of file + int mCurrentPollution; + int mAveragePollution; + int mAveragePollutionArray[] = new int[10]; + private int mArrayPos = 0; + private int mTickTimer = 0; + private int mSecondTimer = 0; + + public GregtechMetaPollutionCreator( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaPollutionCreator( + final String aName, + final int aTier, + final String aDescription, + final ITexture[][][] aTextures, + final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "A useful debug machine to create pollution.", CORE.GT_Tooltip}; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (pollutionMultiplier > 99) { + pollutionMultiplier = 1; + } else { + pollutionMultiplier++; + } + PlayerUtils.messagePlayer(aPlayer, "Pollution Mutliplier is now " + pollutionMultiplier + "."); + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPollutionCreator( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return 0; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + public int pollutionMultiplier = 1; + + private void showPollution(final World worldIn, final EntityPlayer playerIn) { + if (!PollutionUtils.isPollutionEnabled()) { + PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); + } else { + addPollution(); + PlayerUtils.messagePlayer( + playerIn, "This chunk now contains " + getCurrentChunkPollution() + " pollution."); + // PlayerUtils.messagePlayer(playerIn, "Average over last ten minutes: "+getAveragePollutionOverLastTen()+" + // pollution."); + } + } + + private boolean addPollution() { + PollutionUtils.addPollution(getBaseMetaTileEntity(), 100000 * pollutionMultiplier); + return true; + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + public int getCurrentChunkPollution() { + return getCurrentChunkPollution(this.getBaseMetaTileEntity()); + } + + public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity) { + return PollutionUtils.getPollution(aBaseMetaTileEntity); + } + + @Override + public String[] getInfoData() { + return new String[] { + this.getLocalName(), + "Current Pollution: " + this.mCurrentPollution, + "Average/10 minutes:" + getAveragePollutionOverLastTen() + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + // int mCurrentPollution; + // int mAveragePollution; + // int mAveragePollutionArray[] = new int[10]; + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + aNBT.setInteger("mAveragePollution", this.mAveragePollution); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + if (this.getBaseMetaTileEntity().isServerSide()) { + if (this.mCurrentPollution == 0) { + this.mCurrentPollution = getCurrentChunkPollution(); + } + if (this.mArrayPos < 0 || this.mArrayPos > 9) { + this.mArrayPos = 0; + } + this.mTickTimer = 0; + } + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.getBaseMetaTileEntity().isServerSide()) { + // TickTimer - 20 times a second + this.mTickTimer++; + if (mTickTimer % 20 == 0) { + this.mCurrentPollution = getCurrentChunkPollution(); + } + } + } + + public int getAveragePollutionOverLastTen() { + int counter = 0; + int total = 0; + + for (int i = 0; i < this.mAveragePollutionArray.length; i++) { + if (this.mAveragePollutionArray[i] != 0) { + total += this.mAveragePollutionArray[i]; + counter++; + } + } + int returnValue = 0; + if (total > 0 && counter > 0) { + returnValue = (total / counter); + this.mAveragePollution = returnValue; + } else { + returnValue = getCurrentChunkPollution(); + } + // Logger.INFO("| DEBUG: "+returnValue +" | ArrayPos:"+this.mArrayPos+" | Counter:"+counter+" | Total:"+total+" + // |"); + return returnValue; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java index 69a4f96708..9ba3db911a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java @@ -19,417 +19,524 @@ import net.minecraft.world.World; public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { - int mCurrentPollution; - int mAveragePollution; - int mAveragePollutionArray[] = new int[10]; - private int mArrayPos = 0; - private int mTickTimer = 0; - private int mSecondTimer = 0; - private long mRedstoneLevel = 0; - - public GregtechMetaPollutionDetector(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); - } - - public GregtechMetaPollutionDetector(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { - super(aName, aTier, aSlotCount, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[] {this.mDescription, "Right click to check pollution levels.", - "Configure with screwdriver to set redstone output amount.", - "Does not use power.", - CORE.GT_Tooltip}; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return aSide == aFacing - ? new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), - new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) } - : new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), - new GT_RenderedTexture(Textures.BlockIcons.VOID) }; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - /*@Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - }*/ - - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; - } - - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; - } - - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaPollutionDetector(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); - } - - @Override public boolean isSimpleMachine() {return false;} - @Override public boolean isElectric() {return true;} - @Override public boolean isValidSlot(final int aIndex) {return true;} - @Override public boolean isFacingValid(final byte aFacing) {return true;} - @Override public boolean isEnetInput() {return true;} - @Override public boolean isEnetOutput() {return false;} - @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isTeleporterCompatible() {return false;} - @Override public long getMinimumStoredEU() {return 0;} - @Override public long maxEUStore() {return 0;} - - @Override - public int getCapacity() { - return 0; - } - - @Override - public long maxEUInput() { - return 0; - } - - @Override - public long maxEUOutput() { - return 0; - } - - @Override - public long maxAmperesIn() { - return 0; - } - - @Override - public long maxAmperesOut() { - return 0; - } - @Override public int rechargerSlotStartIndex() {return 0;} - @Override public int dechargerSlotStartIndex() {return 0;} - @Override public int rechargerSlotCount() {return 0;} - @Override public int dechargerSlotCount() {return 0;} - @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} - @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} - @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) - { - return true; - } - this.showPollution(aPlayer.getEntityWorld(), aPlayer); - return true; - } - - private void showPollution(final World worldIn, final EntityPlayer playerIn){ - if(!PollutionUtils.isPollutionEnabled()){ - PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); - } - else { - PlayerUtils.messagePlayer(playerIn, "This chunk contains "+getCurrentChunkPollution()+" pollution."); - PlayerUtils.messagePlayer(playerIn, "Emit Redstone at pollution level: "+this.mRedstoneLevel); - } - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - public int getCurrentChunkPollution(){ - return getCurrentChunkPollution(this.getBaseMetaTileEntity()); - } - - public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity){ - return PollutionUtils.getPollution(aBaseMetaTileEntity); - } - - - @Override - public String[] getInfoData() { - return new String[] { - this.getLocalName(), - "Current Pollution: "+this.mCurrentPollution, - "Average/10 Sec: "+this.mAveragePollution, - "Emit Redstone at pollution level: "+this.mRedstoneLevel}; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { - return new int[] {}; - } - - @Override - public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { - return false; - } - - @Override - public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { - return false; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(final int p_70301_1_) { - return null; - } - - @Override - public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { - return null; - } - - @Override - public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { - } - - @Override - public String getInventoryName() { - return null; - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - @Override - public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { - return false; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { - return false; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isTransformerUpgradable() { - return false; - } - - //int mCurrentPollution; - //int mAveragePollution; - //int mAveragePollutionArray[] = new int[10]; - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); - aNBT.setInteger("mAveragePollution", this.mAveragePollution); - aNBT.setLong("mRedstoneLevel", this.mRedstoneLevel); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); - this.mAveragePollution = aNBT.getInteger("mAveragePollution"); - this.mRedstoneLevel = aNBT.getLong("mRedstoneLevel"); - } - - @Override - public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - } - - public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { - return aSide != this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - - //Only Calc server-side - if (!this.getBaseMetaTileEntity().isServerSide()) { - return; - } - //Emit Redstone - if (this.getCurrentChunkPollution() >= this.mRedstoneLevel){ - for (int i=0;i<6;i++){ - this.getBaseMetaTileEntity().setStrongOutputRedstoneSignal((byte) i, (byte) 16); - } - this.markDirty(); - } - else { - for (int i=0;i<6;i++){ - this.getBaseMetaTileEntity().setStrongOutputRedstoneSignal((byte) i, (byte) 0); - } - this.markDirty(); - } - - //Do Math for stats - if (this.mTickTimer % 20 == 0) { - mCurrentPollution = this.getCurrentChunkPollution(); - if (mArrayPos > mAveragePollutionArray.length-1) { - mArrayPos = 0; - } - mAveragePollutionArray[mArrayPos] = mCurrentPollution; - mAveragePollution = getAveragePollutionOverLastTen(); - mArrayPos++; - } - this.mTickTimer++; - - } - - public int getAveragePollutionOverLastTen(){ - return MathUtils.getIntAverage(mAveragePollutionArray); - - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, - float aX, float aY, float aZ) { - - if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { - final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); - switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { - case 0: - this.mRedstoneLevel -= 5000; - break; - case 1: - this.mRedstoneLevel += 5000; - break; - case 2: - this.mRedstoneLevel -= 50000; - break; - case 3: - this.mRedstoneLevel += 50000; - } - this.markDirty(); - GT_Utility.sendChatToPlayer(aPlayer, "Emit Redstone at Pollution Level: " + this.mRedstoneLevel); - } - - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - public boolean allowGeneralRedstoneOutput() { - if (this.getCurrentChunkPollution() >= this.mRedstoneLevel){ - this.markDirty(); - return true; - } - return false; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, - EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { - return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); - } - - @Override - public void onMachineBlockUpdate() { - super.onMachineBlockUpdate(); - } - - @Override - public boolean hasSidedRedstoneOutputBehavior() { - if (this.getCurrentChunkPollution() >= this.mRedstoneLevel){ - this.markDirty(); - return true; - } - return false; - } - -}
\ No newline at end of file + int mCurrentPollution; + int mAveragePollution; + int mAveragePollutionArray[] = new int[10]; + private int mArrayPos = 0; + private int mTickTimer = 0; + private int mSecondTimer = 0; + private long mRedstoneLevel = 0; + + public GregtechMetaPollutionDetector( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaPollutionDetector( + final String aName, + final int aTier, + final String aDescription, + final ITexture[][][] aTextures, + final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Right click to check pollution levels.", + "Configure with screwdriver to set redstone output amount.", + "Does not use power.", + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return aSide == aFacing + ? new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) + } + : new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(Textures.BlockIcons.VOID) + }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + /*@Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; + }*/ + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPollutionDetector( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return 0; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + private void showPollution(final World worldIn, final EntityPlayer playerIn) { + if (!PollutionUtils.isPollutionEnabled()) { + PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); + } else { + PlayerUtils.messagePlayer(playerIn, "This chunk contains " + getCurrentChunkPollution() + " pollution."); + PlayerUtils.messagePlayer(playerIn, "Emit Redstone at pollution level: " + this.mRedstoneLevel); + } + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + public int getCurrentChunkPollution() { + return getCurrentChunkPollution(this.getBaseMetaTileEntity()); + } + + public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity) { + return PollutionUtils.getPollution(aBaseMetaTileEntity); + } + + @Override + public String[] getInfoData() { + return new String[] { + this.getLocalName(), + "Current Pollution: " + this.mCurrentPollution, + "Average/10 Sec: " + this.mAveragePollution, + "Emit Redstone at pollution level: " + this.mRedstoneLevel + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + // int mCurrentPollution; + // int mAveragePollution; + // int mAveragePollutionArray[] = new int[10]; + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + aNBT.setInteger("mAveragePollution", this.mAveragePollution); + aNBT.setLong("mRedstoneLevel", this.mRedstoneLevel); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + this.mRedstoneLevel = aNBT.getLong("mRedstoneLevel"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + // Only Calc server-side + if (!this.getBaseMetaTileEntity().isServerSide()) { + return; + } + // Emit Redstone + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel) { + for (int i = 0; i < 6; i++) { + this.getBaseMetaTileEntity().setStrongOutputRedstoneSignal((byte) i, (byte) 16); + } + this.markDirty(); + } else { + for (int i = 0; i < 6; i++) { + this.getBaseMetaTileEntity().setStrongOutputRedstoneSignal((byte) i, (byte) 0); + } + this.markDirty(); + } + + // Do Math for stats + if (this.mTickTimer % 20 == 0) { + mCurrentPollution = this.getCurrentChunkPollution(); + if (mArrayPos > mAveragePollutionArray.length - 1) { + mArrayPos = 0; + } + mAveragePollutionArray[mArrayPos] = mCurrentPollution; + mAveragePollution = getAveragePollutionOverLastTen(); + mArrayPos++; + } + this.mTickTimer++; + } + + public int getAveragePollutionOverLastTen() { + return MathUtils.getIntAverage(mAveragePollutionArray); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + + if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0: + this.mRedstoneLevel -= 5000; + break; + case 1: + this.mRedstoneLevel += 5000; + break; + case 2: + this.mRedstoneLevel -= 50000; + break; + case 3: + this.mRedstoneLevel += 50000; + } + this.markDirty(); + GT_Utility.sendChatToPlayer(aPlayer, "Emit Redstone at Pollution Level: " + this.mRedstoneLevel); + } + + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + public boolean allowGeneralRedstoneOutput() { + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel) { + this.markDirty(); + return true; + } + return false; + } + + @Override + public boolean onRightclick( + IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + + @Override + public void onMachineBlockUpdate() { + super.onMachineBlockUpdate(); + } + + @Override + public boolean hasSidedRedstoneOutputBehavior() { + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel) { + this.markDirty(); + return true; + } + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java index 58bddefc19..9b60732f62 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java @@ -3,11 +3,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; import static gregtech.api.enums.GT_Values.V; import static net.minecraftforge.common.ForgeChunkManager.getMaxChunkDepthFor; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - import com.google.common.collect.MapMaker; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -20,6 +15,10 @@ import gtPlusPlus.GTplusplus; import gtPlusPlus.core.chunkloading.GTPP_ChunkManager; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -29,378 +28,451 @@ import net.minecraftforge.common.ForgeChunkManager.Ticket; public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_BasicMachine { - public GregtechMetaTileEntityChunkLoader(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 4, "Loads " + getMaxChunksToLoadForTier(aTier) + " chunks when powered", 0, 0, "Recycler.png", "", new ITexture[]{}); - } - - public GregtechMetaTileEntityChunkLoader(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 4, aDescription, aTextures, 0, 0, aGUIName, aNEIName); - } - - public static int getMaxChunksToLoadForTier(int aTier) { - if (aTier < 4) { - return Math.min(3 * 3, getMaxChunkDepthFor(CORE.MODID)); - } - if (aTier < 6) { - return Math.min(7 * 7, getMaxChunkDepthFor(CORE.MODID)); - } - if (aTier < 8) { - return Math.min(15 * 15, getMaxChunkDepthFor(CORE.MODID)); - } - else { - return 0; - } - } - - public static int getChunkRadiusForTier(int aTier) { - if (aTier < 4) { - return Math.min(1, (int)Math.floor(Math.sqrt(getMaxChunkDepthFor(CORE.MODID)))); - } - if (aTier < 6) { - return Math.min(3, (int)Math.floor(Math.sqrt(getMaxChunkDepthFor(CORE.MODID)))); - } - if (aTier < 8) { - return Math.min(7, (int)Math.floor(Math.sqrt(getMaxChunkDepthFor(CORE.MODID)))); - } - else { - return 0; - } - } - - @Override - public String[] getDescription() { - return new String[] { - "Loads " + getMaxChunksToLoadForTier(this.mTier) + " chunks when powered", - "Consumes 2A", - "Behaves Identically to a Railcraft World Anchor", - CORE.GT_Tooltip - }; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; - } - - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; - } - - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; - } - - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; - } - - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; - } - - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; - } - - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; - } - - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; - } - - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; - } - - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntityChunkLoader(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - - @Override - public String[] getInfoData() { - return super.getInfoData(); - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { - return false; - } - - @Override - public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { - return false; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { - return true; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - - if (aBaseMetaTileEntity.isServerSide()) { - if (aBaseMetaTileEntity.getXCoord() != prevX || aBaseMetaTileEntity.getYCoord() != prevY || aBaseMetaTileEntity.getZCoord() != prevZ) { - releaseTicket(); - prevX = aBaseMetaTileEntity.getXCoord(); - prevY = aBaseMetaTileEntity.getYCoord(); - prevZ = aBaseMetaTileEntity.getZCoord(); - } - - if (hasActiveTicket() && (getTicket().world != aBaseMetaTileEntity.getWorld() || refreshTicket || !aBaseMetaTileEntity.isAllowedToWork())) { - releaseTicket(); - } - - if (++updateCycle % updateCycleLength == 0) { - updateCycle = 0; - if (canChunkload()) { - setEUVar(getEUVar() - getEnergyConsumption()); - } - } - - if (!hasActiveTicket()) { - requestTicket(); - } - } - } - - @Override - public long maxAmperesIn() { - return 4; - } - - @Override - public long getMinimumStoredEU() { - return V[mTier] * 2; - } - - @Override - public long maxEUStore() { - return V[mTier] * 256; - } - - @Override - public long maxEUInput() { - return V[mTier]; - } - - @Override - public void onRemoval() { - super.onRemoval(); - releaseTicket(); - } - - public long getEnergyConsumption() { - return V[mTier] * 2 * updateCycleLength; - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - - prevX = aNBT.getInteger("prevX"); - prevY = aNBT.getInteger("prevY"); - prevZ = aNBT.getInteger("prevZ"); - - NBTTagCompound uuidNBT = aNBT.getCompoundTag("uuid"); - uuid = new UUID(uuidNBT.getLong("most"), uuidNBT.getLong("least")); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - - aNBT.setInteger("prevX", prevX); - aNBT.setInteger("prevY", prevY); - aNBT.setInteger("prevZ", prevZ); - - if (uuid != null) { - NBTTagCompound uuidNBT = new NBTTagCompound(); - uuidNBT.setLong("most", uuid.getMostSignificantBits()); - uuidNBT.setLong("least", uuid.getLeastSignificantBits()); - aNBT.setTag("uuid", uuidNBT); - } - } - - public boolean canChunkload() { - return getBaseMetaTileEntity().isAllowedToWork() && getEUVar() >= getEnergyConsumption(); - } - - /* - * Chunkloading Vars - */ - - private Set<ChunkCoordIntPair> mLoadedChunks = new HashSet<>(); - private static final Map<UUID, Ticket> tickets = new MapMaker().makeMap(); - private boolean refreshTicket; - private int updateCycle = 0; - private static final int updateCycleLength = 20; - private UUID uuid; - private int prevX, prevY, prevZ; - private boolean hasTicket; - - public boolean addChunkToLoadedList(ChunkCoordIntPair aActiveChunk) { - return mLoadedChunks.add(aActiveChunk); - } - - public boolean removeChunkFromLoadedList(ChunkCoordIntPair aActiveChunk) { - return mLoadedChunks.remove(aActiveChunk); - } - - public Set<ChunkCoordIntPair> getManagedChunks() { - return mLoadedChunks; - } - - public int getChunkloaderTier() { - return mTier; - } - - public void forceChunkLoading(Ticket ticket) { - setTicket(ticket); - setupChunks(); - - if (mLoadedChunks != null) { - for (ChunkCoordIntPair chunk : mLoadedChunks) { - ForgeChunkManager.forceChunk(ticket, chunk); - } - } - } - - public void setupChunks() { - if (!hasTicket) { - mLoadedChunks = null; - } else { - mLoadedChunks = GTPP_ChunkManager.getChunksAround(getBaseMetaTileEntity().getXCoord() >> 4, getBaseMetaTileEntity().getZCoord() >> 4, getChunkRadiusForTier(mTier)); - } - } - - protected Ticket getTicketFromForge() { - return ForgeChunkManager.requestTicket(GTplusplus.instance, getBaseMetaTileEntity().getWorld(), ForgeChunkManager.Type.NORMAL); - } - - public boolean hasActiveTicket() { - return getTicket() != null; - } - - protected void releaseTicket() { - refreshTicket = false; - setTicket(null); - } - - protected void requestTicket() { - if (canChunkload()) { - Ticket chunkTicket = getTicketFromForge(); - if (chunkTicket != null) { - setTicketData(chunkTicket); - forceChunkLoading(chunkTicket); - } - } - } - - protected void setTicketData(Ticket chunkTicket) { - if (chunkTicket != null) { - chunkTicket.getModData().setInteger("xCoord", getBaseMetaTileEntity().getXCoord()); - chunkTicket.getModData().setInteger("yCoord", getBaseMetaTileEntity().getYCoord()); - chunkTicket.getModData().setInteger("zCoord", getBaseMetaTileEntity().getZCoord()); - chunkTicket.setChunkListDepth(getMaxChunksToLoadForTier(mTier)); - } - } - - public void setTicket(Ticket t) { - Ticket ticket = getTicket(); - if (ticket != t) { - if (ticket != null) { - if (ticket.world == getBaseMetaTileEntity().getWorld()) { - for (ChunkCoordIntPair chunk : ticket.getChunkList()) { - if (ForgeChunkManager.getPersistentChunksFor(getBaseMetaTileEntity().getWorld()).keys().contains(chunk)) { - ForgeChunkManager.unforceChunk(ticket, chunk); - } - } - ForgeChunkManager.releaseTicket(ticket); - } - tickets.remove(getUUID()); - } - } - hasTicket = t != null; - if (hasTicket) { - tickets.put(getUUID(), t); - } - } - - public Ticket getTicket() { - return tickets.get(getUUID()); - } - - public UUID getUUID() { - if (uuid == null) { - uuid = UUID.randomUUID(); - } - return uuid; - } -}
\ No newline at end of file + public GregtechMetaTileEntityChunkLoader(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 4, + "Loads " + getMaxChunksToLoadForTier(aTier) + " chunks when powered", + 0, + 0, + "Recycler.png", + "", + new ITexture[] {}); + } + + public GregtechMetaTileEntityChunkLoader( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 4, aDescription, aTextures, 0, 0, aGUIName, aNEIName); + } + + public static int getMaxChunksToLoadForTier(int aTier) { + if (aTier < 4) { + return Math.min(3 * 3, getMaxChunkDepthFor(CORE.MODID)); + } + if (aTier < 6) { + return Math.min(7 * 7, getMaxChunkDepthFor(CORE.MODID)); + } + if (aTier < 8) { + return Math.min(15 * 15, getMaxChunkDepthFor(CORE.MODID)); + } else { + return 0; + } + } + + public static int getChunkRadiusForTier(int aTier) { + if (aTier < 4) { + return Math.min(1, (int) Math.floor(Math.sqrt(getMaxChunkDepthFor(CORE.MODID)))); + } + if (aTier < 6) { + return Math.min(3, (int) Math.floor(Math.sqrt(getMaxChunkDepthFor(CORE.MODID)))); + } + if (aTier < 8) { + return Math.min(7, (int) Math.floor(Math.sqrt(getMaxChunkDepthFor(CORE.MODID)))); + } else { + return 0; + } + } + + @Override + public String[] getDescription() { + return new String[] { + "Loads " + getMaxChunksToLoadForTier(this.mTier) + " chunks when powered", + "Consumes 2A", + "Behaves Identically to a Railcraft World Anchor", + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier]) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier]) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier]) + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier]) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier]) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier + 1]) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier + 1]) + }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier + 1]) + }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier + 1]) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), + new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier + 1]) + }; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityChunkLoader( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + return super.getInfoData(); + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return true; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (aBaseMetaTileEntity.isServerSide()) { + if (aBaseMetaTileEntity.getXCoord() != prevX + || aBaseMetaTileEntity.getYCoord() != prevY + || aBaseMetaTileEntity.getZCoord() != prevZ) { + releaseTicket(); + prevX = aBaseMetaTileEntity.getXCoord(); + prevY = aBaseMetaTileEntity.getYCoord(); + prevZ = aBaseMetaTileEntity.getZCoord(); + } + + if (hasActiveTicket() + && (getTicket().world != aBaseMetaTileEntity.getWorld() + || refreshTicket + || !aBaseMetaTileEntity.isAllowedToWork())) { + releaseTicket(); + } + + if (++updateCycle % updateCycleLength == 0) { + updateCycle = 0; + if (canChunkload()) { + setEUVar(getEUVar() - getEnergyConsumption()); + } + } + + if (!hasActiveTicket()) { + requestTicket(); + } + } + } + + @Override + public long maxAmperesIn() { + return 4; + } + + @Override + public long getMinimumStoredEU() { + return V[mTier] * 2; + } + + @Override + public long maxEUStore() { + return V[mTier] * 256; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public void onRemoval() { + super.onRemoval(); + releaseTicket(); + } + + public long getEnergyConsumption() { + return V[mTier] * 2 * updateCycleLength; + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + + prevX = aNBT.getInteger("prevX"); + prevY = aNBT.getInteger("prevY"); + prevZ = aNBT.getInteger("prevZ"); + + NBTTagCompound uuidNBT = aNBT.getCompoundTag("uuid"); + uuid = new UUID(uuidNBT.getLong("most"), uuidNBT.getLong("least")); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + + aNBT.setInteger("prevX", prevX); + aNBT.setInteger("prevY", prevY); + aNBT.setInteger("prevZ", prevZ); + + if (uuid != null) { + NBTTagCompound uuidNBT = new NBTTagCompound(); + uuidNBT.setLong("most", uuid.getMostSignificantBits()); + uuidNBT.setLong("least", uuid.getLeastSignificantBits()); + aNBT.setTag("uuid", uuidNBT); + } + } + + public boolean canChunkload() { + return getBaseMetaTileEntity().isAllowedToWork() && getEUVar() >= getEnergyConsumption(); + } + + /* + * Chunkloading Vars + */ + + private Set<ChunkCoordIntPair> mLoadedChunks = new HashSet<>(); + private static final Map<UUID, Ticket> tickets = new MapMaker().makeMap(); + private boolean refreshTicket; + private int updateCycle = 0; + private static final int updateCycleLength = 20; + private UUID uuid; + private int prevX, prevY, prevZ; + private boolean hasTicket; + + public boolean addChunkToLoadedList(ChunkCoordIntPair aActiveChunk) { + return mLoadedChunks.add(aActiveChunk); + } + + public boolean removeChunkFromLoadedList(ChunkCoordIntPair aActiveChunk) { + return mLoadedChunks.remove(aActiveChunk); + } + + public Set<ChunkCoordIntPair> getManagedChunks() { + return mLoadedChunks; + } + + public int getChunkloaderTier() { + return mTier; + } + + public void forceChunkLoading(Ticket ticket) { + setTicket(ticket); + setupChunks(); + + if (mLoadedChunks != null) { + for (ChunkCoordIntPair chunk : mLoadedChunks) { + ForgeChunkManager.forceChunk(ticket, chunk); + } + } + } + + public void setupChunks() { + if (!hasTicket) { + mLoadedChunks = null; + } else { + mLoadedChunks = GTPP_ChunkManager.getChunksAround( + getBaseMetaTileEntity().getXCoord() >> 4, + getBaseMetaTileEntity().getZCoord() >> 4, + getChunkRadiusForTier(mTier)); + } + } + + protected Ticket getTicketFromForge() { + return ForgeChunkManager.requestTicket( + GTplusplus.instance, getBaseMetaTileEntity().getWorld(), ForgeChunkManager.Type.NORMAL); + } + + public boolean hasActiveTicket() { + return getTicket() != null; + } + + protected void releaseTicket() { + refreshTicket = false; + setTicket(null); + } + + protected void requestTicket() { + if (canChunkload()) { + Ticket chunkTicket = getTicketFromForge(); + if (chunkTicket != null) { + setTicketData(chunkTicket); + forceChunkLoading(chunkTicket); + } + } + } + + protected void setTicketData(Ticket chunkTicket) { + if (chunkTicket != null) { + chunkTicket + .getModData() + .setInteger("xCoord", getBaseMetaTileEntity().getXCoord()); + chunkTicket + .getModData() + .setInteger("yCoord", getBaseMetaTileEntity().getYCoord()); + chunkTicket + .getModData() + .setInteger("zCoord", getBaseMetaTileEntity().getZCoord()); + chunkTicket.setChunkListDepth(getMaxChunksToLoadForTier(mTier)); + } + } + + public void setTicket(Ticket t) { + Ticket ticket = getTicket(); + if (ticket != t) { + if (ticket != null) { + if (ticket.world == getBaseMetaTileEntity().getWorld()) { + for (ChunkCoordIntPair chunk : ticket.getChunkList()) { + if (ForgeChunkManager.getPersistentChunksFor( + getBaseMetaTileEntity().getWorld()) + .keys() + .contains(chunk)) { + ForgeChunkManager.unforceChunk(ticket, chunk); + } + } + ForgeChunkManager.releaseTicket(ticket); + } + tickets.remove(getUUID()); + } + } + hasTicket = t != null; + if (hasTicket) { + tickets.put(getUUID(), t); + } + } + + public Ticket getTicket() { + return tickets.get(getUUID()); + } + + public UUID getUUID() { + if (uuid == null) { + uuid = UUID.randomUUID(); + } + return uuid; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java index 8456f40797..ea2f47ab8e 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java @@ -1,204 +1,286 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; - -import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class GregtechMetaTileEntityThaumcraftResearcher extends GregtechMetaTileEntity { - public GregtechMetaTileEntityThaumcraftResearcher(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); - } - - public GregtechMetaTileEntityThaumcraftResearcher(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { - super(aName, aTier, aSlotCount, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[] {this.mDescription, "Generates Thaumcraft research notes, because it's magic."}; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Metal_Grate_A)}; - } - - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Metal_Grate_B)}; - } - - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{getSides(aColor)[0]}; - } - - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue)}; - } - - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; - } - - - public ITexture[] getFrontActive(final byte aColor) { - return getFront(aColor); - } - - - public ITexture[] getBackActive(final byte aColor) { - return getBack(aColor); - } - - - public ITexture[] getBottomActive(final byte aColor) { - return getBottom(aColor); - } - - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange)}; - } - - - public ITexture[] getSidesActive(final byte aColor) { - return getSides(aColor); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntityThaumcraftResearcher(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); - } - - @Override public boolean isSimpleMachine() {return false;} - @Override public boolean isElectric() {return true;} - @Override public boolean isValidSlot(final int aIndex) {return true;} - @Override public boolean isFacingValid(final byte aFacing) {return true;} - @Override public boolean isEnetInput() {return true;} - @Override public boolean isEnetOutput() {return false;} - @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getBackFacing();} - @Override public boolean isTeleporterCompatible() {return false;} - @Override public long getMinimumStoredEU() {return 0;} - @Override public long maxEUStore() {return 512000;} - @Override public int rechargerSlotStartIndex() {return 0;} - @Override public int dechargerSlotStartIndex() {return 0;} - @Override public int rechargerSlotCount() {return 0;} - @Override public int dechargerSlotCount() {return 0;} - @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} - - @Override - public int getCapacity() { - return 128000; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) - { - return true; - } - return true; - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return aSide==this.getBaseMetaTileEntity().getBackFacing(); - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return true; - } - - @Override - public String[] getInfoData() { - return new String[] { - this.getLocalName(), - }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public int getSizeInventory() { - return 2; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isTransformerUpgradable() { - return false; - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - //aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); - //aNBT.setInteger("mAveragePollution", this.mAveragePollution); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - //this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); - //this.mAveragePollution = aNBT.getInteger("mAveragePollution"); - } - - @Override - public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - } - -}
\ No newline at end of file + public GregtechMetaTileEntityThaumcraftResearcher( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaTileEntityThaumcraftResearcher( + final String aName, + final int aTier, + final String aDescription, + final ITexture[][][] aTextures, + final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "Generates Thaumcraft research notes, because it's magic."}; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Metal_Grate_A) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Metal_Grate_B) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {getSides(aColor)[0]}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; + } + + public ITexture[] getFrontActive(final byte aColor) { + return getFront(aColor); + } + + public ITexture[] getBackActive(final byte aColor) { + return getBack(aColor); + } + + public ITexture[] getBottomActive(final byte aColor) { + return getBottom(aColor); + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return getSides(aColor); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityThaumcraftResearcher( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return 512000; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public int getCapacity() { + return 128000; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + return true; + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aSide == this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return true; + } + + @Override + public String[] getInfoData() { + return new String[] { + this.getLocalName(), + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int getSizeInventory() { + return 2; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + // aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + // aNBT.setInteger("mAveragePollution", this.mAveragePollution); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + // this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + // this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java index f2fc0cce7a..ae8be6a161 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; -import java.util.List; - import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -12,58 +10,72 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.List; import net.minecraft.item.ItemStack; import team.chisel.carving.Carving; public class GregtechMetaTileEntity_AutoChisel extends GT_MetaTileEntity_BasicMachine { - private ItemStack mInputCache; - private ItemStack mOutputCache; - - public GregtechMetaTileEntity_AutoChisel(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, "Chisels things, Gregtech style", 1, 1, "Compressor.png", "", - new ITexture[]{ - new GT_RenderedTexture(BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), - new GT_RenderedTexture(BlockIcons.OVERLAY_SIDE_MASSFAB), - new GT_RenderedTexture(BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE), - new GT_RenderedTexture(BlockIcons.OVERLAY_FRONT_MULTI_SMELTER), - new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active), - new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab), - new GT_RenderedTexture(BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), - new GT_RenderedTexture(BlockIcons.OVERLAY_BOTTOM_MASSFAB) - }); - } - - public GregtechMetaTileEntity_AutoChisel(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_AutoChisel(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); - } - - @Override - public String[] getDescription() { - String[] A = new String[]{ - this.mDescription, - "What you want to chisel goes in slot 1", - "What you want to get goes in the special slot (bottom right)", - "If special slot is empty, first chisel result is used" - }; - return A; - } - + private ItemStack mInputCache; + private ItemStack mOutputCache; + + public GregtechMetaTileEntity_AutoChisel(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 1, + "Chisels things, Gregtech style", + 1, + 1, + "Compressor.png", + "", + new ITexture[] { + new GT_RenderedTexture(BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), + new GT_RenderedTexture(BlockIcons.OVERLAY_SIDE_MASSFAB), + new GT_RenderedTexture(BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE), + new GT_RenderedTexture(BlockIcons.OVERLAY_FRONT_MULTI_SMELTER), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab), + new GT_RenderedTexture(BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), + new GT_RenderedTexture(BlockIcons.OVERLAY_BOTTOM_MASSFAB) + }); + } + + public GregtechMetaTileEntity_AutoChisel( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_AutoChisel( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public String[] getDescription() { + String[] A = new String[] { + this.mDescription, + "What you want to chisel goes in slot 1", + "What you want to get goes in the special slot (bottom right)", + "If special slot is empty, first chisel result is used" + }; + return A; + } + @Override public GT_Recipe.GT_Recipe_Map getRecipeList() { return null; } - + private boolean hasValidCache(ItemStack aStack, ItemStack aSpecialSlot, boolean aClearOnFailure) { - if (mInputCache != null && mOutputCache != null) { - if (GT_Utility.areStacksEqual(aStack, mInputCache) && GT_Utility.areStacksEqual(aSpecialSlot, mOutputCache)) { - return true; - } + if (mInputCache != null && mOutputCache != null) { + if (GT_Utility.areStacksEqual(aStack, mInputCache) + && GT_Utility.areStacksEqual(aSpecialSlot, mOutputCache)) { + return true; + } } // clear cache if it was invalid if (aClearOnFailure) { @@ -72,84 +84,83 @@ public class GregtechMetaTileEntity_AutoChisel extends GT_MetaTileEntity_BasicMa } return false; } - + private void cacheItem(ItemStack mInputItem, ItemStack mOutputItem) { mOutputCache = mOutputItem.copy(); mInputCache = mInputItem.copy(); } @Override - protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return hasValidCache(aStack, this.getSpecialSlot(), false) ? true : super.allowPutStackValidated(aBaseMetaTileEntity, aIndex, aSide, aStack) && hasChiselResults(aStack); + protected boolean allowPutStackValidated( + IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return hasValidCache(aStack, this.getSpecialSlot(), false) + ? true + : super.allowPutStackValidated(aBaseMetaTileEntity, aIndex, aSide, aStack) && hasChiselResults(aStack); + } + + // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target + private static boolean canBeMadeFrom(ItemStack from, ItemStack to) { + List<ItemStack> results = getItemsForChiseling(from); + for (ItemStack s : results) { + if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) { + return true; + } + } + return false; + } + + // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target + private static boolean hasChiselResults(ItemStack from) { + List<ItemStack> results = getItemsForChiseling(from); + return results.size() > 0; } - - // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target - private static boolean canBeMadeFrom(ItemStack from, ItemStack to) { - List<ItemStack> results = getItemsForChiseling(from); - for (ItemStack s : results) { - if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) { - return true; - } - } - return false; - } - - // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target - private static boolean hasChiselResults(ItemStack from) { - List<ItemStack> results = getItemsForChiseling(from); - return results.size() > 0; - } - - private static List<ItemStack> getItemsForChiseling(ItemStack aStack){ - return Carving.chisel.getItemsForChiseling(aStack); - } - - private static ItemStack getChiselOutput(ItemStack aInput, ItemStack aTarget) { - ItemStack tOutput = null; - if (aTarget != null && canBeMadeFrom(aInput, aTarget)) { - tOutput = aTarget; - } - else if (aTarget != null && !canBeMadeFrom(aInput, aTarget)) { - tOutput = null; - } - else { - tOutput = getItemsForChiseling(aInput).get(0); - } - return tOutput; - } - + + private static List<ItemStack> getItemsForChiseling(ItemStack aStack) { + return Carving.chisel.getItemsForChiseling(aStack); + } + + private static ItemStack getChiselOutput(ItemStack aInput, ItemStack aTarget) { + ItemStack tOutput = null; + if (aTarget != null && canBeMadeFrom(aInput, aTarget)) { + tOutput = aTarget; + } else if (aTarget != null && !canBeMadeFrom(aInput, aTarget)) { + tOutput = null; + } else { + tOutput = getItemsForChiseling(aInput).get(0); + } + return tOutput; + } + @Override public int checkRecipe() { - ItemStack tOutput = null; - ItemStack aInput = getInputAt(0); - ItemStack aTarget = getSpecialSlot(); + ItemStack tOutput = null; + ItemStack aInput = getInputAt(0); + ItemStack aTarget = getSpecialSlot(); boolean tIsCached = hasValidCache(aInput, aTarget, true); - if (aInput != null && hasChiselResults(aInput) && aInput.stackSize > 0) { - tOutput = tIsCached ? mOutputCache.copy() : getChiselOutput(aInput, aTarget); - if (tOutput != null) { - tOutput = tOutput.copy(); - tOutput.stackSize = 1; - // We can chisel this - if (canOutput(tOutput)) { - getInputAt(0).stackSize -= 1; - calculateOverclockedNess(16, 20); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) { - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - } - if (!tIsCached) { - cacheItem(ItemUtils.getSimpleStack(aInput, 1), ItemUtils.getSimpleStack(tOutput, 1)); - } - this.mOutputItems[0] = tOutput.copy(); - return FOUND_AND_SUCCESSFULLY_USED_RECIPE; - } - else { - mOutputBlocked++; - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - } - } - } - return DID_NOT_FIND_RECIPE; + if (aInput != null && hasChiselResults(aInput) && aInput.stackSize > 0) { + tOutput = tIsCached ? mOutputCache.copy() : getChiselOutput(aInput, aTarget); + if (tOutput != null) { + tOutput = tOutput.copy(); + tOutput.stackSize = 1; + // We can chisel this + if (canOutput(tOutput)) { + getInputAt(0).stackSize -= 1; + calculateOverclockedNess(16, 20); + // In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) { + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + } + if (!tIsCached) { + cacheItem(ItemUtils.getSimpleStack(aInput, 1), ItemUtils.getSimpleStack(tOutput, 1)); + } + this.mOutputItems[0] = tOutput.copy(); + return FOUND_AND_SUCCESSFULLY_USED_RECIPE; + } else { + mOutputBlocked++; + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + } + } + } + return DID_NOT_FIND_RECIPE; } - -}
\ No newline at end of file +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_BasicWasher.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_BasicWasher.java index 99b3faa7d4..268863ffd2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_BasicWasher.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_BasicWasher.java @@ -6,66 +6,76 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; import gregtech.api.util.GT_Recipe; import gtPlusPlus.core.lib.CORE; -import gregtech.api.util.GTPP_Recipe; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_BasicWasher extends GT_MetaTileEntity_BasicMachine { - public GregtechMetaTileEntity_BasicWasher(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, - "It's like an automatic Cauldron for washing dusts.", 1, 1, "PotionBrewer.png", "", - new ITexture[]{ - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_ACTIVE), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE), - new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER) - } - ); - } - - public GregtechMetaTileEntity_BasicWasher(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); - } + public GregtechMetaTileEntity_BasicWasher(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 1, + "It's like an automatic Cauldron for washing dusts.", + 1, + 1, + "PotionBrewer.png", + "", + new ITexture[] { + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER) + }); + } - /*public GregtechMetaTileEntity_BasicWasher(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); - }*/ + public GregtechMetaTileEntity_BasicWasher( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } - @Override - public String[] getDescription() { - return new String[]{this.mDescription, "Grants no byproducts, but it is fast.", CORE.GT_Tooltip}; - } + /*public GregtechMetaTileEntity_BasicWasher(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + }*/ - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_BasicWasher(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); - } + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "Grants no byproducts, but it is fast.", CORE.GT_Tooltip}; + } - @Override - public GT_Recipe.GT_Recipe_Map getRecipeList() { - return GTPP_Recipe.GTPP_Recipe_Map.sSimpleWasherRecipes; - } + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_BasicWasher( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (getRecipeList().containsInput(aStack)); - } + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sSimpleWasherRecipes; + } - @Override - public boolean isFluidInputAllowed(FluidStack aFluid) { - return (aFluid.getFluid().getName().equals("water")) || (super.isFluidInputAllowed(aFluid)); - } + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) + && (getRecipeList().containsInput(aStack)); + } - @Override - public int getCapacity() { - return 8000 * Math.max(1, this.mTier); - } + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return (aFluid.getFluid().getName().equals("water")) || (super.isFluidInputAllowed(aFluid)); + } + @Override + public int getCapacity() { + return 8000 * Math.max(1, this.mTier); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ChemicalReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ChemicalReactor.java index c872e5c912..2ae5e1e54a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ChemicalReactor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ChemicalReactor.java @@ -1,13 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; -import static gregtech.api.enums.GT_Values.E; - -import java.util.HashSet; -import java.util.List; - -import cpw.mods.fml.common.registry.LanguageRegistry; -import gregtech.GT_Mod; -import gregtech.api.GregTech_API; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -15,16 +7,13 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; -import gregtech.api.util.GTPP_Recipe; -import gtPlusPlus.api.objects.random.XSTR; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.slots.SlotChemicalPlantInput; import gtPlusPlus.xmod.gregtech.api.gui.fluidreactor.Container_FluidReactor; import gtPlusPlus.xmod.gregtech.api.gui.fluidreactor.GUI_FluidReactor; -import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.List; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -37,630 +26,648 @@ import net.minecraftforge.fluids.IFluidHandler; public class GregtechMetaTileEntity_ChemicalReactor extends GT_MetaTileEntity_BasicMachine { - public boolean mFluidTransfer_1 = false; - public boolean mFluidTransfer_2 = false; - - public FluidStack[] mInputFluids = new FluidStack[4]; - public FluidStack[] mOutputFluids = new FluidStack[2]; - - public GregtechMetaTileEntity_ChemicalReactor(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, - "For mixing fluids", 4, 4, "ChemicalReactor.png", "", - new ITexture[]{ - new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Side_Active), - new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Side), - new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Front_Active), - new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Front), - new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top_Active), - new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top), - new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top_Active), - new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top) - } - ); - } - - public GregtechMetaTileEntity_ChemicalReactor(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); - } - - /*public GregtechMetaTileEntity_BasicWasher(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); - }*/ - - @Override - public String[] getDescription() { - return new String[]{this.mDescription, "Because why not?", CORE.GT_Tooltip}; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - try { - GregtechMetaTileEntity_ChemicalReactor y = new GregtechMetaTileEntity_ChemicalReactor(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); - return y; - } - catch(Throwable t) { - t.printStackTrace(); - } - return null; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - try { - Container_FluidReactor y = new Container_FluidReactor(aPlayerInventory, aBaseMetaTileEntity); - return y; - } - catch(Throwable t) { - t.printStackTrace(); - } - return null; - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_FluidReactor(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), - this.mGUIName, - GT_Utility.isStringValid(this.mNEIName) - ? this.mNEIName - : (this.getRecipeList() != null ? this.getRecipeList().mUnlocalizedName : "")); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeList() { - return null; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (getRecipeList().containsInput(aStack)); - } - - @Override - public boolean isFluidInputAllowed(FluidStack aFluid) { - return (super.isFluidInputAllowed(aFluid)); - } - - @Override - public int getCapacity() { - return 32000 * Math.max(1, this.mTier) / 4; - } - - @Override - public int getInputSlot() { - return 3; - } - - @Override - public boolean isLiquidInput(byte aSide) { - return aSide > 1; - } - - @Override - public boolean isLiquidOutput(byte aSide) { - return aSide < 2; - } - - @Override - public int getOutputSlot() { - return super.getOutputSlot(); - } - - @Override - public int getStackDisplaySlot() { - return super.getStackDisplaySlot(); - } - - @Override - public boolean doesEmptyContainers() { - return true; - } - - @Override - public boolean canTankBeFilled() { - return super.canTankBeFilled(); - } - - @Override - public boolean canTankBeEmptied() { - return super.canTankBeEmptied(); - } - - @Override - public FluidStack getDisplayedFluid() { - return super.getDisplayedFluid(); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("mFluidTransfer_1", mFluidTransfer_1); - aNBT.setBoolean("mFluidTransfer_2", mFluidTransfer_2); - for (int i=0;i<4;i++) { - if (this.mInputFluids[i] != null) { - aNBT.setTag("mInputFluid"+i, this.mInputFluids[i].writeToNBT(new NBTTagCompound())); - } - } - for (int i=0;i<2;i++) { - if (this.mOutputFluids[i] != null) { - aNBT.setTag("mOutputFluid"+i, this.mOutputFluids[i].writeToNBT(new NBTTagCompound())); - } - } - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - mFluidTransfer_1 = aNBT.getBoolean("mFluidTransfer_1"); - mFluidTransfer_2 = aNBT.getBoolean("mFluidTransfer_2"); - for (int i=0;i<4;i++) { - if (this.mInputFluids[i] == null) { - this.mInputFluids[i] = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mInputFluid"+i)); - } - } - for (int i=0;i<2;i++) { - if (this.mOutputFluids[i] == null) { - this.mOutputFluids[i] = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mOutputFluid"+i)); - } - } - } - - /* - * Custom Fluid Handling - TODO - */ - - public FluidStack getFillableStack() { - return this.mFluid; - } - - public FluidStack setFillableStack(FluidStack aFluid) { - this.mFluid = aFluid; - return this.mFluid; - } - - public FluidStack getDrainableStack() { - return this.mFluid; - } - - public FluidStack setDrainableStack(FluidStack aFluid) { - this.mFluid = aFluid; - return this.mFluid; - } - - - - - - - - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - // Re-implement basic machine logic from the ground up.= - - if (aBaseMetaTileEntity.isServerSide()) { - this.mCharge = aBaseMetaTileEntity.getStoredEU() / 2L > aBaseMetaTileEntity.getEUCapacity() / 3L; - this.mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3L; - this.doDisplayThings(); - boolean tSucceeded = false; - int i; - if (this.mMaxProgresstime > 0 && (this.mProgresstime >= 0 || aBaseMetaTileEntity.isAllowedToWork())) { - aBaseMetaTileEntity.setActive(true); - if (this.mProgresstime >= 0 && !this.drainEnergyForProcess((long) this.mEUt)) { - if (!this.mStuttering) { - this.stutterProcess(); - if (this.canHaveInsufficientEnergy()) { - this.mProgresstime = -100; - } - - this.mStuttering = true; - } - } else { - if (++this.mProgresstime >= this.mMaxProgresstime) { - for (i = 0; i < this.mOutputItems.length; ++i) { - for (i = 0; i < this.mOutputItems.length && !aBaseMetaTileEntity.addStackToSlot( - this.getOutputSlot() + (i + i) % this.mOutputItems.length, - this.mOutputItems[i]); ++i) { - ; - } - } - - if (this.mOutputFluid != null) { - if (this.getDrainableStack() == null) { - this.setDrainableStack(this.mOutputFluid.copy()); - } else if (this.mOutputFluid.isFluidEqual(this.getDrainableStack())) { - FluidStack var10000 = this.getDrainableStack(); - var10000.amount += this.mOutputFluid.amount; - } - } - - for (i = 0; i < this.mOutputItems.length; ++i) { - this.mOutputItems[i] = null; - } - - this.mOutputFluid = null; - this.mEUt = 0; - this.mProgresstime = 0; - this.mMaxProgresstime = 0; - this.mStuttering = false; - tSucceeded = true; - this.endProcess(); - } - - if (this.mProgresstime > 5) { - this.mStuttering = false; - } - } - } else { - aBaseMetaTileEntity.setActive(false); - } - - boolean tRemovedOutputFluid = false; - if (this.doesAutoOutputFluids() && this.getDrainableStack() != null - && aBaseMetaTileEntity.getFrontFacing() != this.mMainFacing && (tSucceeded || aTick % 20L == 0L)) { - IFluidHandler tTank = aBaseMetaTileEntity.getITankContainerAtSide(aBaseMetaTileEntity.getFrontFacing()); - if (tTank != null) { - FluidStack tDrained = this.drain(1000, false); - if (tDrained != null) { - int tFilledAmount = tTank.fill( - ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tDrained, false); - if (tFilledAmount > 0) { - tTank.fill(ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), - this.drain(tFilledAmount, true), true); - } - } - } - - if (this.getDrainableStack() == null) { - tRemovedOutputFluid = true; - } - } - - int j; - if (this.doesAutoOutput() && !this.isOutputEmpty() - && aBaseMetaTileEntity.getFrontFacing() != this.mMainFacing - && (tSucceeded || this.mOutputBlocked % 300 == 1 || aBaseMetaTileEntity.hasInventoryBeenModified() - || aTick % 600L == 0L)) { - TileEntity tTileEntity2 = aBaseMetaTileEntity.getTileEntityAtSide(aBaseMetaTileEntity.getFrontFacing()); - j = 0; - - for (byte tCosts = 1; j < this.mOutputItems.length && tCosts > 0 - && aBaseMetaTileEntity.isUniversalEnergyStored(128L); ++j) { - tCosts = GT_Utility.moveOneItemStack(aBaseMetaTileEntity, tTileEntity2, - aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), (List) null, - false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - if (tCosts > 0) { - aBaseMetaTileEntity.decreaseStoredEnergyUnits((long) tCosts, true); - } - } - } - - if (this.mOutputBlocked != 0) { - if (this.isOutputEmpty()) { - this.mOutputBlocked = 0; - } else { - ++this.mOutputBlocked; - } - } - - if (this.allowToCheckRecipe()) { - if (this.mMaxProgresstime <= 0 && aBaseMetaTileEntity.isAllowedToWork() - && (tRemovedOutputFluid || tSucceeded || aBaseMetaTileEntity.hasInventoryBeenModified() - || aTick % 600L == 0L || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) - && this.hasEnoughEnergyToCheckRecipe()) { - if (this.checkRecipe() == 2) { - if (this.mInventory[3] != null && this.mInventory[3].stackSize <= 0) { - this.mInventory[3] = null; - } - - i = this.getInputSlot(); - - for (j = i + this.mInputSlotCount; i < j; ++i) { - if (this.mInventory[i] != null && this.mInventory[i].stackSize <= 0) { - this.mInventory[i] = null; - } - } - - for (i = 0; i < this.mOutputItems.length; ++i) { - this.mOutputItems[i] = GT_Utility.copy(new Object[]{this.mOutputItems[i]}); - if (this.mOutputItems[i] != null && this.mOutputItems[i].stackSize > 64) { - this.mOutputItems[i].stackSize = 64; - } - - this.mOutputItems[i] = GT_OreDictUnificator.get(true, this.mOutputItems[i]); - } - - if (this.mFluid != null && this.mFluid.amount <= 0) { - this.mFluid = null; - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - if (GT_Utility.isDebugItem(this.mInventory[this.dechargerSlotStartIndex()])) { - this.mEUt = this.mMaxProgresstime = 1; - } - - this.startProcess(); - } else { - this.mMaxProgresstime = 0; - - for (i = 0; i < this.mOutputItems.length; ++i) { - this.mOutputItems[i] = null; - } - - this.mOutputFluid = null; - } - } - } else if (!this.mStuttering) { - this.stutterProcess(); - this.mStuttering = true; - } - } - - - - } - - @Override - protected void doDisplayThings() { - // TODO Auto-generated method stub - super.doDisplayThings(); - } - - @Override - protected ItemStack getSpecialSlot() { - // TODO Auto-generated method stub - return super.getSpecialSlot(); - } - - @Override - protected ItemStack getOutputAt(int aIndex) { - // TODO Auto-generated method stub - return super.getOutputAt(aIndex); - } - - @Override - protected ItemStack[] getAllOutputs() { - // TODO Auto-generated method stub - return super.getAllOutputs(); - } - - @Override - protected ItemStack getInputAt(int aIndex) { - // TODO Auto-generated method stub - return super.getInputAt(aIndex); - } - - @Override - protected ItemStack[] getAllInputs() { - // TODO Auto-generated method stub - return super.getAllInputs(); - } - - @Override - protected boolean displaysInputFluid() { - return true; - } - - @Override - protected boolean displaysOutputFluid() { - return true; - } - - @Override - public boolean doesAutoOutput() { - return super.doesAutoOutput(); - } - - @Override - public boolean doesAutoOutputFluids() { - return this.mFluidTransfer_1 && this.mFluidTransfer_2; - } - - @Override - public void startProcess() { - super.startProcess(); - } - - @Override - public void endProcess() { - super.endProcess(); - } - - @Override - public String[] getInfoData() { - return super.getInfoData(); - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return super.allowPullStack(aBaseMetaTileEntity, aIndex, aSide, aStack); - } - - @Override - public int checkRecipe() { - return super.checkRecipe(); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - - /* if (aBaseMetaTileEntity != null) { - if (!aBaseMetaTileEntity.getWorld().isRemote) { - itemslots : for (int i=3;i<7;i++) { - ItemStack aStack = aBaseMetaTileEntity.getStackInSlot(i); - if (aStack != null) { - if (FluidContainerRegistry.isContainer(aStack)) { - if (this.isItemValidForSlot(i, aStack)) { - // Add Fluid - FluidStack aContainerFluid = FluidContainerRegistry.getFluidForFilledItem(aStack); - if (aContainerFluid != null) { - fluidslots : for (FluidStack u : mInputFluids) { - if (u != null && u.isFluidEqual(aContainerFluid)) { - if (u.amount <= (this.getCapacity() - aContainerFluid.amount)) { - - // Matching, not full, let's fill, then continue - u.amount += aContainerFluid.amount; - - // Update stack size - if (aStack.stackSize > 1) { - aStack.stackSize--; - } - else { - aStack = null; - } - - // Add Output container - // TODO - - continue itemslots; - } - else { - // Too full - break fluidslots; - } - } - else { - if (u == null ) { - - // Empty, let's fill, then continue - u = aContainerFluid.copy(); - - // Update stack size - if (aStack.stackSize > 1) { - aStack.stackSize--; - } - else { - aStack = null; - } - - // Add Output container - // TODO - - continue itemslots; - - } - else { - // Not empty, doesn't match, check next slot. - continue fluidslots; - } - } - } - - - - } - // Eat Input - - // Add Container to Output - } - } - } - } - } - }*/ - - } - - @Override - public FluidStack getFluid() { - return super.getFluid(); - } - - @Override - public int getFluidAmount() { - return super.getFluidAmount(); - } - - @Override - public int fill(FluidStack aFluid, boolean doFill) { - return super.fill(aFluid, doFill); - } - - @Override - public FluidStack drain(int maxDrain, boolean doDrain) { - return super.drain(maxDrain, doDrain); - } - - @Override - public void setItemNBT(NBTTagCompound aNBT) { - super.setItemNBT(aNBT); - } - - @Override - public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { - if (aIndex >= 3 && aIndex <= 6) { - return SlotChemicalPlantInput.isItemValidForChemicalPlantSlot(aStack); - } - return false; - } - - @Override - public int[] getAccessibleSlotsFromSide(int aSide) { - return super.getAccessibleSlotsFromSide(aSide); - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - if (aIndex >= 3 && aIndex <= 6) { - return super.canInsertItem(aIndex, aStack, aSide); - } - return false; - } - - @Override - public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { - if (aIndex >= 7 && aIndex <= 11) { - return super.canExtractItem(aIndex, aStack, aSide); - } - return false; - } - - @Override - public boolean canFill(ForgeDirection aSide, Fluid aFluid) { - // TODO Auto-generated method stub - return super.canFill(aSide, aFluid); - } - - @Override - public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { - // TODO Auto-generated method stub - return super.canDrain(aSide, aFluid); - } - - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { - // TODO Auto-generated method stub - return super.getTankInfo(aSide); - } - - @Override - public int fill_default( - ForgeDirection aSide, FluidStack aFluid, boolean doFill - ) { - // TODO Auto-generated method stub - return super.fill_default(aSide, aFluid, doFill); - } - - @Override - public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { - // TODO Auto-generated method stub - return super.fill(aSide, aFluid, doFill); - } - - @Override - public FluidStack drain( - ForgeDirection aSide, FluidStack aFluid, boolean doDrain - ) { - // TODO Auto-generated method stub - return super.drain(aSide, aFluid, doDrain); - } - - @Override - public FluidStack drain( - ForgeDirection aSide, int maxDrain, boolean doDrain - ) { - // TODO Auto-generated method stub - return super.drain(aSide, maxDrain, doDrain); - } - + public boolean mFluidTransfer_1 = false; + public boolean mFluidTransfer_2 = false; + + public FluidStack[] mInputFluids = new FluidStack[4]; + public FluidStack[] mOutputFluids = new FluidStack[2]; + + public GregtechMetaTileEntity_ChemicalReactor(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 1, + "For mixing fluids", + 4, + 4, + "ChemicalReactor.png", + "", + new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Side_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Side), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Front_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Front), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top) + }); + } + + public GregtechMetaTileEntity_ChemicalReactor( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + /*public GregtechMetaTileEntity_BasicWasher(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + }*/ + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "Because why not?", CORE.GT_Tooltip}; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + try { + GregtechMetaTileEntity_ChemicalReactor y = new GregtechMetaTileEntity_ChemicalReactor( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + return y; + } catch (Throwable t) { + t.printStackTrace(); + } + return null; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + try { + Container_FluidReactor y = new Container_FluidReactor(aPlayerInventory, aBaseMetaTileEntity); + return y; + } catch (Throwable t) { + t.printStackTrace(); + } + return null; + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_FluidReactor( + aPlayerInventory, + aBaseMetaTileEntity, + this.getLocalName(), + this.mGUIName, + GT_Utility.isStringValid(this.mNEIName) + ? this.mNEIName + : (this.getRecipeList() != null ? this.getRecipeList().mUnlocalizedName : "")); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return null; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) + && (getRecipeList().containsInput(aStack)); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return (super.isFluidInputAllowed(aFluid)); + } + + @Override + public int getCapacity() { + return 32000 * Math.max(1, this.mTier) / 4; + } + + @Override + public int getInputSlot() { + return 3; + } + + @Override + public boolean isLiquidInput(byte aSide) { + return aSide > 1; + } + + @Override + public boolean isLiquidOutput(byte aSide) { + return aSide < 2; + } + + @Override + public int getOutputSlot() { + return super.getOutputSlot(); + } + + @Override + public int getStackDisplaySlot() { + return super.getStackDisplaySlot(); + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return super.canTankBeFilled(); + } + + @Override + public boolean canTankBeEmptied() { + return super.canTankBeEmptied(); + } + + @Override + public FluidStack getDisplayedFluid() { + return super.getDisplayedFluid(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mFluidTransfer_1", mFluidTransfer_1); + aNBT.setBoolean("mFluidTransfer_2", mFluidTransfer_2); + for (int i = 0; i < 4; i++) { + if (this.mInputFluids[i] != null) { + aNBT.setTag("mInputFluid" + i, this.mInputFluids[i].writeToNBT(new NBTTagCompound())); + } + } + for (int i = 0; i < 2; i++) { + if (this.mOutputFluids[i] != null) { + aNBT.setTag("mOutputFluid" + i, this.mOutputFluids[i].writeToNBT(new NBTTagCompound())); + } + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mFluidTransfer_1 = aNBT.getBoolean("mFluidTransfer_1"); + mFluidTransfer_2 = aNBT.getBoolean("mFluidTransfer_2"); + for (int i = 0; i < 4; i++) { + if (this.mInputFluids[i] == null) { + this.mInputFluids[i] = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mInputFluid" + i)); + } + } + for (int i = 0; i < 2; i++) { + if (this.mOutputFluids[i] == null) { + this.mOutputFluids[i] = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mOutputFluid" + i)); + } + } + } + + /* + * Custom Fluid Handling - TODO + */ + + public FluidStack getFillableStack() { + return this.mFluid; + } + + public FluidStack setFillableStack(FluidStack aFluid) { + this.mFluid = aFluid; + return this.mFluid; + } + + public FluidStack getDrainableStack() { + return this.mFluid; + } + + public FluidStack setDrainableStack(FluidStack aFluid) { + this.mFluid = aFluid; + return this.mFluid; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // Re-implement basic machine logic from the ground up.= + + if (aBaseMetaTileEntity.isServerSide()) { + this.mCharge = aBaseMetaTileEntity.getStoredEU() / 2L > aBaseMetaTileEntity.getEUCapacity() / 3L; + this.mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3L; + this.doDisplayThings(); + boolean tSucceeded = false; + int i; + if (this.mMaxProgresstime > 0 && (this.mProgresstime >= 0 || aBaseMetaTileEntity.isAllowedToWork())) { + aBaseMetaTileEntity.setActive(true); + if (this.mProgresstime >= 0 && !this.drainEnergyForProcess((long) this.mEUt)) { + if (!this.mStuttering) { + this.stutterProcess(); + if (this.canHaveInsufficientEnergy()) { + this.mProgresstime = -100; + } + + this.mStuttering = true; + } + } else { + if (++this.mProgresstime >= this.mMaxProgresstime) { + for (i = 0; i < this.mOutputItems.length; ++i) { + for (i = 0; + i < this.mOutputItems.length + && !aBaseMetaTileEntity.addStackToSlot( + this.getOutputSlot() + (i + i) % this.mOutputItems.length, + this.mOutputItems[i]); + ++i) { + ; + } + } + + if (this.mOutputFluid != null) { + if (this.getDrainableStack() == null) { + this.setDrainableStack(this.mOutputFluid.copy()); + } else if (this.mOutputFluid.isFluidEqual(this.getDrainableStack())) { + FluidStack var10000 = this.getDrainableStack(); + var10000.amount += this.mOutputFluid.amount; + } + } + + for (i = 0; i < this.mOutputItems.length; ++i) { + this.mOutputItems[i] = null; + } + + this.mOutputFluid = null; + this.mEUt = 0; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + this.mStuttering = false; + tSucceeded = true; + this.endProcess(); + } + + if (this.mProgresstime > 5) { + this.mStuttering = false; + } + } + } else { + aBaseMetaTileEntity.setActive(false); + } + + boolean tRemovedOutputFluid = false; + if (this.doesAutoOutputFluids() + && this.getDrainableStack() != null + && aBaseMetaTileEntity.getFrontFacing() != this.mMainFacing + && (tSucceeded || aTick % 20L == 0L)) { + IFluidHandler tTank = aBaseMetaTileEntity.getITankContainerAtSide(aBaseMetaTileEntity.getFrontFacing()); + if (tTank != null) { + FluidStack tDrained = this.drain(1000, false); + if (tDrained != null) { + int tFilledAmount = tTank.fill( + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tDrained, false); + if (tFilledAmount > 0) { + tTank.fill( + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), + this.drain(tFilledAmount, true), + true); + } + } + } + + if (this.getDrainableStack() == null) { + tRemovedOutputFluid = true; + } + } + + int j; + if (this.doesAutoOutput() + && !this.isOutputEmpty() + && aBaseMetaTileEntity.getFrontFacing() != this.mMainFacing + && (tSucceeded + || this.mOutputBlocked % 300 == 1 + || aBaseMetaTileEntity.hasInventoryBeenModified() + || aTick % 600L == 0L)) { + TileEntity tTileEntity2 = aBaseMetaTileEntity.getTileEntityAtSide(aBaseMetaTileEntity.getFrontFacing()); + j = 0; + + for (byte tCosts = 1; + j < this.mOutputItems.length && tCosts > 0 && aBaseMetaTileEntity.isUniversalEnergyStored(128L); + ++j) { + tCosts = GT_Utility.moveOneItemStack( + aBaseMetaTileEntity, + tTileEntity2, + aBaseMetaTileEntity.getFrontFacing(), + aBaseMetaTileEntity.getBackFacing(), + (List) null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + if (tCosts > 0) { + aBaseMetaTileEntity.decreaseStoredEnergyUnits((long) tCosts, true); + } + } + } + + if (this.mOutputBlocked != 0) { + if (this.isOutputEmpty()) { + this.mOutputBlocked = 0; + } else { + ++this.mOutputBlocked; + } + } + + if (this.allowToCheckRecipe()) { + if (this.mMaxProgresstime <= 0 + && aBaseMetaTileEntity.isAllowedToWork() + && (tRemovedOutputFluid + || tSucceeded + || aBaseMetaTileEntity.hasInventoryBeenModified() + || aTick % 600L == 0L + || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) + && this.hasEnoughEnergyToCheckRecipe()) { + if (this.checkRecipe() == 2) { + if (this.mInventory[3] != null && this.mInventory[3].stackSize <= 0) { + this.mInventory[3] = null; + } + + i = this.getInputSlot(); + + for (j = i + this.mInputSlotCount; i < j; ++i) { + if (this.mInventory[i] != null && this.mInventory[i].stackSize <= 0) { + this.mInventory[i] = null; + } + } + + for (i = 0; i < this.mOutputItems.length; ++i) { + this.mOutputItems[i] = GT_Utility.copy(new Object[] {this.mOutputItems[i]}); + if (this.mOutputItems[i] != null && this.mOutputItems[i].stackSize > 64) { + this.mOutputItems[i].stackSize = 64; + } + + this.mOutputItems[i] = GT_OreDictUnificator.get(true, this.mOutputItems[i]); + } + + if (this.mFluid != null && this.mFluid.amount <= 0) { + this.mFluid = null; + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + if (GT_Utility.isDebugItem(this.mInventory[this.dechargerSlotStartIndex()])) { + this.mEUt = this.mMaxProgresstime = 1; + } + + this.startProcess(); + } else { + this.mMaxProgresstime = 0; + + for (i = 0; i < this.mOutputItems.length; ++i) { + this.mOutputItems[i] = null; + } + + this.mOutputFluid = null; + } + } + } else if (!this.mStuttering) { + this.stutterProcess(); + this.mStuttering = true; + } + } + } + + @Override + protected void doDisplayThings() { + // TODO Auto-generated method stub + super.doDisplayThings(); + } + + @Override + protected ItemStack getSpecialSlot() { + // TODO Auto-generated method stub + return super.getSpecialSlot(); + } + + @Override + protected ItemStack getOutputAt(int aIndex) { + // TODO Auto-generated method stub + return super.getOutputAt(aIndex); + } + + @Override + protected ItemStack[] getAllOutputs() { + // TODO Auto-generated method stub + return super.getAllOutputs(); + } + + @Override + protected ItemStack getInputAt(int aIndex) { + // TODO Auto-generated method stub + return super.getInputAt(aIndex); + } + + @Override + protected ItemStack[] getAllInputs() { + // TODO Auto-generated method stub + return super.getAllInputs(); + } + + @Override + protected boolean displaysInputFluid() { + return true; + } + + @Override + protected boolean displaysOutputFluid() { + return true; + } + + @Override + public boolean doesAutoOutput() { + return super.doesAutoOutput(); + } + + @Override + public boolean doesAutoOutputFluids() { + return this.mFluidTransfer_1 && this.mFluidTransfer_2; + } + + @Override + public void startProcess() { + super.startProcess(); + } + + @Override + public void endProcess() { + super.endProcess(); + } + + @Override + public String[] getInfoData() { + return super.getInfoData(); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return super.allowPullStack(aBaseMetaTileEntity, aIndex, aSide, aStack); + } + + @Override + public int checkRecipe() { + return super.checkRecipe(); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + + /* if (aBaseMetaTileEntity != null) { + if (!aBaseMetaTileEntity.getWorld().isRemote) { + itemslots : for (int i=3;i<7;i++) { + ItemStack aStack = aBaseMetaTileEntity.getStackInSlot(i); + if (aStack != null) { + if (FluidContainerRegistry.isContainer(aStack)) { + if (this.isItemValidForSlot(i, aStack)) { + // Add Fluid + FluidStack aContainerFluid = FluidContainerRegistry.getFluidForFilledItem(aStack); + if (aContainerFluid != null) { + fluidslots : for (FluidStack u : mInputFluids) { + if (u != null && u.isFluidEqual(aContainerFluid)) { + if (u.amount <= (this.getCapacity() - aContainerFluid.amount)) { + + // Matching, not full, let's fill, then continue + u.amount += aContainerFluid.amount; + + // Update stack size + if (aStack.stackSize > 1) { + aStack.stackSize--; + } + else { + aStack = null; + } + + // Add Output container + // TODO + + continue itemslots; + } + else { + // Too full + break fluidslots; + } + } + else { + if (u == null ) { + + // Empty, let's fill, then continue + u = aContainerFluid.copy(); + + // Update stack size + if (aStack.stackSize > 1) { + aStack.stackSize--; + } + else { + aStack = null; + } + + // Add Output container + // TODO + + continue itemslots; + + } + else { + // Not empty, doesn't match, check next slot. + continue fluidslots; + } + } + } + + + + } + // Eat Input + + // Add Container to Output + } + } + } + } + } + }*/ + + } + + @Override + public FluidStack getFluid() { + return super.getFluid(); + } + + @Override + public int getFluidAmount() { + return super.getFluidAmount(); + } + + @Override + public int fill(FluidStack aFluid, boolean doFill) { + return super.fill(aFluid, doFill); + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return super.drain(maxDrain, doDrain); + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + super.setItemNBT(aNBT); + } + + @Override + public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { + if (aIndex >= 3 && aIndex <= 6) { + return SlotChemicalPlantInput.isItemValidForChemicalPlantSlot(aStack); + } + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(int aSide) { + return super.getAccessibleSlotsFromSide(aSide); + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + if (aIndex >= 3 && aIndex <= 6) { + return super.canInsertItem(aIndex, aStack, aSide); + } + return false; + } + + @Override + public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { + if (aIndex >= 7 && aIndex <= 11) { + return super.canExtractItem(aIndex, aStack, aSide); + } + return false; + } + + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + // TODO Auto-generated method stub + return super.canFill(aSide, aFluid); + } + + @Override + public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { + // TODO Auto-generated method stub + return super.canDrain(aSide, aFluid); + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { + // TODO Auto-generated method stub + return super.getTankInfo(aSide); + } + + @Override + public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + // TODO Auto-generated method stub + return super.fill_default(aSide, aFluid, doFill); + } + + @Override + public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + // TODO Auto-generated method stub + return super.fill(aSide, aFluid, doFill); + } + + @Override + public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) { + // TODO Auto-generated method stub + return super.drain(aSide, aFluid, doDrain); + } + + @Override + public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { + // TODO Auto-generated method stub + return super.drain(aSide, maxDrain, doDrain); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_CompactFusionReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_CompactFusionReactor.java index 2197ce193d..eb52042b9b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_CompactFusionReactor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_CompactFusionReactor.java @@ -1,13 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; -import java.util.ArrayList; -import java.util.Random; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; @@ -15,688 +7,718 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.api.util.GTPP_Recipe; - import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_DeluxeMachine; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.Random; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_CompactFusionReactor extends GT_MetaTileEntity_DeluxeMachine { - private boolean mCanProcessRecipe = false; - private boolean mCharging = false; - private long mChargeConsumed = 0; - - private GT_Recipe mLastRecipe; - private long mEUStore; - private boolean mRunningOnLoad = false; - private boolean mMachine = false; - private int mEfficiency, mEfficiencyIncrease, mEfficiencyMax = 0; - private int mStartUpCheck = 100, mUpdate = 0; - private FluidStack[] mOutputFluids = null; - - public GregtechMetaTileEntity_CompactFusionReactor(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, "It's like a midget Ra.", 1, 1, "PotionBrewer.png", ""); - } - - public GregtechMetaTileEntity_CompactFusionReactor(String aName, int aTier, String aDescription, - ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); - } - - @Override - public String[] getDescription() { - return new String[] { this.mDescription, "Not Very Fast, but not very big either.", - "Each side pair in/out puts to different slots.", "Top & Bottom Sides are Outputs.", - "Front & Back are Input Plasma 1.", "Sides are Input Plasma 2." }; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_CompactFusionReactor(this.mName, this.mTier, this.mDescription, - this.mTextures, this.mGUIName, this.mNEIName); - } - - public int tier() { - return this.mTier; - } - - public int tierOverclock() { - return this.mTier == 6 ? 0 : this.mTier == 7 ? 1 : 2; - } - - private GT_RenderedTexture getCasingTexture() { - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 - : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex - + 1]; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeList() { - return GTPP_Recipe.GTPP_Recipe_Map.sSlowFusionRecipes; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide == this.getBaseMetaTileEntity().getBackFacing(); - } - - @Override - public boolean isFluidInputAllowed(FluidStack aFluid) { - return (aFluid.getFluid().getName().contains("plasma")) || (super.isFluidInputAllowed(aFluid)); - } - - @Override - public int getCapacity() { - return 32000; - } - - @Override - public void abortProcess() { - super.abortProcess(); - } - - long mFusionPoint = 20000000L; - - @Override - public int checkRecipe() { - Logger.MACHINE_INFO("Recipe Tick 1."); - if (!this.mCanProcessRecipe) { - Logger.MACHINE_INFO("Recipe Tick 1.1 - Cannot Process Recipe."); - if (this.mChargeConsumed < mFusionPoint) { - Logger.MACHINE_INFO("Recipe Tick 1.2 - Cannot Ignite Fusion, Charge too low."); - this.mCharging = true; - this.mCanProcessRecipe = false; - if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits((mFusionPoint / 100), false)) { - Logger.MACHINE_INFO("Recipe Tick 1.3 - Charging Internal storage. " + (mFusionPoint / 100) + "/" - + mFusionPoint); - mChargeConsumed += (mFusionPoint / 100); - } - } - else { - mChargeConsumed = 0; - this.mCharging = false; - this.mCanProcessRecipe = true; - - } - } - else { - Logger.MACHINE_INFO("Recipe Tick 1.1 - Try to Process Recipe."); - if (checkRecipeMulti()) { - Logger.MACHINE_INFO("Recipe Tick 1.2 - Process Recipe was Successful."); - return 2; - } - } - Logger.MACHINE_INFO("Recipe Tick 2. - Process Recipe failed."); - return 0; - } - - public ArrayList<FluidStack> getStoredFluids() { - ArrayList<FluidStack> mList = new ArrayList<FluidStack>(); - mList.add(this.mFluid); - mList.add(this.mFluid2); - return mList; - } - - public boolean checkRecipeMulti() { - ArrayList<FluidStack> tFluidList = getStoredFluids(); - int tFluidList_sS = tFluidList.size(); - for (int i = 0; i < tFluidList_sS - 1; i++) { - for (int j = i + 1; j < tFluidList_sS; j++) { - if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { - if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { - tFluidList.remove(j--); - tFluidList_sS = tFluidList.size(); - } - else { - tFluidList.remove(i--); - tFluidList_sS = tFluidList.size(); - break; - } - } - } - } - if (tFluidList.size() > 1) { - FluidStack[] tFluids = tFluidList.toArray(new FluidStack[tFluidList.size()]); - GT_Recipe tRecipe = getRecipeList().findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, false, - GT_Values.V[8], tFluids, new ItemStack[] {}); - if (tRecipe == null) { - return false; - } - if ((tRecipe == null && !mRunningOnLoad) || (tRecipe != null && maxEUStore() < tRecipe.mSpecialValue)) { - this.mLastRecipe = null; - Logger.MACHINE_INFO("Just plain bad."); - return false; - } - if (mRunningOnLoad || tRecipe.isRecipeInputEqual(true, tFluids, new ItemStack[] {})) { - this.mLastRecipe = tRecipe; - this.mEUt = (this.mLastRecipe.mEUt * overclock(this.mLastRecipe.mSpecialValue)); - this.mMaxProgresstime = this.mLastRecipe.mDuration / overclock(this.mLastRecipe.mSpecialValue); - - this.mEfficiencyIncrease = 10000; - - this.mOutputFluids = this.mLastRecipe.mFluidOutputs; - mRunningOnLoad = false; - return true; - } - } - return false; - } - - public int overclock(int mStartEnergy) { - if (tierOverclock() == 1) { - return 1; - } - if (tierOverclock() == 2) { - return mStartEnergy < 160000000 ? 2 : 1; - } - return mStartEnergy < 160000000 ? 4 : mStartEnergy < 320000000 ? 2 : 1; - } - - @Override - public boolean displaysItemStack() { - return false; - } - - @Override - public boolean doesAutoOutputFluids() { - return true; - } - - @Override - public boolean doesEmptyContainers() { - return true; - } - - @Override - public boolean doesFillContainers() { - return true; - } - - @Override - public long maxAmperesIn() { - return 16L; - } - - @Override - public long maxEUStore() { - return Long.MAX_VALUE; - } - - @Override - public void doExplosion(long aExplosionPower) { - super.doExplosion(aExplosionPower * 2); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - onRunningTickMulti(); - if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) - && (aBaseMetaTileEntity.getFrontFacing() != 1) && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) - && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { - if (MathUtils.randInt(0, 4) == 4) { - final Random tRandom = aBaseMetaTileEntity.getWorld().rand; - aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", - (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), - aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), - (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), 0.0D, 0.0D, 0.0D); - aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", - (aBaseMetaTileEntity.getXCoord() + 0.4F) - (tRandom.nextFloat() * 0.3F), - aBaseMetaTileEntity.getYCoord() + 0.2f + (tRandom.nextFloat() * 0.1F), - (aBaseMetaTileEntity.getZCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), 0.0D, 0.0D, 0.0D); - aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", - (aBaseMetaTileEntity.getXCoord() + 0.6F) - (tRandom.nextFloat() * 0.9F), - aBaseMetaTileEntity.getYCoord() + 0.4f + (tRandom.nextFloat() * 0.3F), - (aBaseMetaTileEntity.getZCoord() + 1.8F) - (tRandom.nextFloat() * 2.6F), 0.0D, 0.0D, 0.0D); - } - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("mCanProcessRecipe", this.mCanProcessRecipe); - aNBT.setBoolean("mCharging", this.mCharging); - aNBT.setLong("mChargeConsumed", this.mChargeConsumed); - aNBT.setInteger("mEfficiency", this.mEfficiency); - aNBT.setInteger("mEfficiencyIncrease", this.mEfficiencyIncrease); - aNBT.setInteger("mEfficiencyMax", this.mEfficiencyMax); - aNBT.setInteger("mStartUpCheck", this.mStartUpCheck); - aNBT.setInteger("mUpdate", mUpdate); - aNBT.setInteger("mEfficiencyIncrease", mEfficiencyIncrease); - aNBT.setBoolean("mRunningOnLoad", this.mRunningOnLoad); - aNBT.setBoolean("mMachine", this.mMachine); - aNBT.setLong("mEUStore", this.mEUStore); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - if (mMaxProgresstime > 0) - mRunningOnLoad = true; - this.mCanProcessRecipe = aNBT.getBoolean("mCanProcessRecipe"); - this.mCharging = aNBT.getBoolean("mCharging"); - this.mChargeConsumed = aNBT.getLong("mChargeConsumed"); - this.mEfficiency = aNBT.getInteger("mEfficiency"); - this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); - this.mEfficiencyMax = aNBT.getInteger("mEfficiencyMax"); - this.mStartUpCheck = aNBT.getInteger("mStartUpCheck"); - this.mUpdate = aNBT.getInteger("mUpdate"); - this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); - this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); - this.mRunningOnLoad = aNBT.getBoolean("mRunningOnLoad"); - this.mMachine = aNBT.getBoolean("mMachine"); - this.mEUStore = aNBT.getLong("mEUStore"); - super.loadNBTData(aNBT); - } - - @Override - public String[] getInfoData() { - String tier = tier() == 6 ? "I" : tier() == 7 ? "II" : "III"; - float plasmaOut = 0; - String fusionName = ""; - int powerRequired = 0; - if (this.mLastRecipe != null) { - fusionName = this.mLastRecipe.mFluidOutputs[0].getLocalizedName() + " Fusion."; - powerRequired = this.mLastRecipe.mEUt; - if (this.mLastRecipe.getFluidOutput(0) != null) { - plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; - } - } - - return new String[] { "Fusion Reactor MK " + tier, "EU Required: " + powerRequired + "EU/t", - "Stored EU: " + this.getEUVar() + " / " + maxEUStore(), "Plasma Output: " + plasmaOut + "L/t", - "Current Recipe: " + fusionName }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab) }; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS) }; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS) }; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), - new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; - } - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), - new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active) }; - } - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW) }; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW) }; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), - new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue) }; - } - - @Override - public void onMachineBlockUpdate() { - this.mUpdate = 50; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - // super.onPostTick(aBaseMetaTileEntity, aTick); - if (aBaseMetaTileEntity.isServerSide()) { - // Logger.MACHINE_INFO("1"); - if (mEfficiency < 0) - mEfficiency = 0; - if (mRunningOnLoad) { - Logger.MACHINE_INFO("2"); - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - checkRecipeMulti(); - } - if (--mUpdate == 0 || --mStartUpCheck == 0) { - Logger.MACHINE_INFO("3"); - mMachine = true; - } - if (mStartUpCheck < 0) { - //Logger.MACHINE_INFO("4"); - if (mMachine) { - //Logger.MACHINE_INFO("5"); - - if (aBaseMetaTileEntity.getStoredEU() + (2048 * tierOverclock()) < maxEUStore()) { - if (aBaseMetaTileEntity.increaseStoredEnergyUnits(2048 * tierOverclock(), true)) { - //Logger.MACHINE_INFO("5.5 A"); - } - else { - //Logger.MACHINE_INFO("5.5 B"); - } - } - if (this.mEUStore <= 0 && mMaxProgresstime > 0) { - Logger.MACHINE_INFO("6"); - stopMachine(); - this.mLastRecipe = null; - } - if (mMaxProgresstime > 0) { - Logger.MACHINE_INFO("7"); - this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt, true); - if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { - if (mOutputFluids != null) - for (FluidStack tStack : mOutputFluids) - if (tStack != null) - addOutput(tStack); - mEfficiency = Math.max(0, (mEfficiency + mEfficiencyIncrease)); - mProgresstime = 0; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - if (mOutputFluids != null && mOutputFluids.length > 0) { - - } - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - if (aBaseMetaTileEntity.isAllowedToWork()) - checkRecipeMulti(); - } - } - else { - //Logger.MACHINE_INFO("8"); - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() - || aBaseMetaTileEntity.hasInventoryBeenModified()) { - Logger.MACHINE_INFO("9"); - // turnCasingActive(mMaxProgresstime > 0); - if (aBaseMetaTileEntity.isAllowedToWork()) { - Logger.MACHINE_INFO("10"); - if (checkRecipeMulti()) { - Logger.MACHINE_INFO("11"); - if (this.mEUStore < this.mLastRecipe.mSpecialValue) { - Logger.MACHINE_INFO("12"); - mMaxProgresstime = 0; - // turnCasingActive(false); - } - aBaseMetaTileEntity.decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue, true); - } - } - if (mMaxProgresstime <= 0) - mEfficiency = Math.max(0, mEfficiency - 1000); - } - } - } - else { - // turnCasingActive(false); - Logger.MACHINE_INFO("Bad"); - this.mLastRecipe = null; - stopMachine(); - } - } - Logger.MACHINE_INFO("Good | "+mMaxProgresstime); - aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); - } - } - - public boolean onRunningTickMulti() { - if (this.getBaseMetaTileEntity().isServerSide()) { - if (mEUt < 0) { - if (!drainEnergyInput(((long) -mEUt * 10000) / Math.max(1000, mEfficiency))) { - this.mLastRecipe = null; - stopMachine(); - Logger.MACHINE_INFO("a1"); - return false; - } - } - if (this.mEUStore <= 0) { - this.mLastRecipe = null; - stopMachine(); - Logger.MACHINE_INFO("a2"); - return false; - } - } - return true; - } - - public boolean drainEnergyInput(long aEU) { - return false; - } - - public boolean addOutput(FluidStack aLiquid) { - if (aLiquid == null) - return false; - FluidStack copiedFluidStack = aLiquid.copy(); - this.mOutputFluid = copiedFluidStack; - return false; - } - - public void stopMachine() { - mEUt = 0; - mEfficiency = 0; - mProgresstime = 0; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - getBaseMetaTileEntity().disableWorking(); - } - - @Override - public boolean isLiquidInput(byte aSide) { - switch (aSide) { - case 0: - return true; - case 1: - return true; - case 2: - return true; - case 3: - return false; - case 4: - return false; - case 5: - return false; - default: - return false; - } - } - - @Override - public boolean isLiquidOutput(byte aSide) { - switch (aSide) { - case 0: - return false; - case 1: - return false; - case 2: - return false; - case 3: - return true; - case 4: - return true; - case 5: - return true; - default: - return true; - } - } - - @Override - public int fill(FluidStack aFluid, boolean doFill) { - return super.fill(aFluid, doFill); - } - - @Override - public FluidStack drain(int maxDrain, boolean doDrain) { - return super.drain(maxDrain, doDrain); - } - - @Override - public int getTankPressure() { - return 500; - } - - @Override - public boolean canFill(ForgeDirection aSide, Fluid aFluid) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return false; - } - else { - return super.canFill(aSide, aFluid); - } - } - - @Override - public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return super.canDrain(aSide, aFluid); - } - else { - return false; - } - } - - @Override - public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return 0; - } - else { - return super.fill_default(aSide, aFluid, doFill); - } - } - - @Override - public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return super.fill(aSide, aFluid, doFill); - } - else { - return 0; - } - } - - @Override - public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return super.drain(aSide, aFluid, doDrain); - } - else { - return null; - } - } - - @Override - public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return super.drain(aSide, maxDrain, doDrain); - } - else { - return null; - } - } - - @Override - public boolean isOverclockerUpgradable() { - return true; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - // TODO Auto-generated method stub - return super.onRightclick(aBaseMetaTileEntity, aPlayer); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, - float aY, float aZ) { - // TODO Auto-generated method stub - return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - // TODO Auto-generated method stub - return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - // TODO Auto-generated method stub - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - return false; - } - - @Override - public void onExplosion() { - // TODO Auto-generated method stub - super.onExplosion(); - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { - super.startSoundLoop(aIndex, aX, aY, aZ); - if (aIndex == 1) { - GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(212)), 10, 1.0F, aX, aY, - aZ); - } - } - + private boolean mCanProcessRecipe = false; + private boolean mCharging = false; + private long mChargeConsumed = 0; + + private GT_Recipe mLastRecipe; + private long mEUStore; + private boolean mRunningOnLoad = false; + private boolean mMachine = false; + private int mEfficiency, mEfficiencyIncrease, mEfficiencyMax = 0; + private int mStartUpCheck = 100, mUpdate = 0; + private FluidStack[] mOutputFluids = null; + + public GregtechMetaTileEntity_CompactFusionReactor(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, "It's like a midget Ra.", 1, 1, "PotionBrewer.png", ""); + } + + public GregtechMetaTileEntity_CompactFusionReactor( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Not Very Fast, but not very big either.", + "Each side pair in/out puts to different slots.", + "Top & Bottom Sides are Outputs.", + "Front & Back are Input Plasma 1.", + "Sides are Input Plasma 2." + }; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_CompactFusionReactor( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + public int tier() { + return this.mTier; + } + + public int tierOverclock() { + return this.mTier == 6 ? 0 : this.mTier == 7 ? 1 : 2; + } + + private GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sSlowFusionRecipes; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return (aFluid.getFluid().getName().contains("plasma")) || (super.isFluidInputAllowed(aFluid)); + } + + @Override + public int getCapacity() { + return 32000; + } + + @Override + public void abortProcess() { + super.abortProcess(); + } + + long mFusionPoint = 20000000L; + + @Override + public int checkRecipe() { + Logger.MACHINE_INFO("Recipe Tick 1."); + if (!this.mCanProcessRecipe) { + Logger.MACHINE_INFO("Recipe Tick 1.1 - Cannot Process Recipe."); + if (this.mChargeConsumed < mFusionPoint) { + Logger.MACHINE_INFO("Recipe Tick 1.2 - Cannot Ignite Fusion, Charge too low."); + this.mCharging = true; + this.mCanProcessRecipe = false; + if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits((mFusionPoint / 100), false)) { + Logger.MACHINE_INFO("Recipe Tick 1.3 - Charging Internal storage. " + (mFusionPoint / 100) + "/" + + mFusionPoint); + mChargeConsumed += (mFusionPoint / 100); + } + } else { + mChargeConsumed = 0; + this.mCharging = false; + this.mCanProcessRecipe = true; + } + } else { + Logger.MACHINE_INFO("Recipe Tick 1.1 - Try to Process Recipe."); + if (checkRecipeMulti()) { + Logger.MACHINE_INFO("Recipe Tick 1.2 - Process Recipe was Successful."); + return 2; + } + } + Logger.MACHINE_INFO("Recipe Tick 2. - Process Recipe failed."); + return 0; + } + + public ArrayList<FluidStack> getStoredFluids() { + ArrayList<FluidStack> mList = new ArrayList<FluidStack>(); + mList.add(this.mFluid); + mList.add(this.mFluid2); + return mList; + } + + public boolean checkRecipeMulti() { + ArrayList<FluidStack> tFluidList = getStoredFluids(); + int tFluidList_sS = tFluidList.size(); + for (int i = 0; i < tFluidList_sS - 1; i++) { + for (int j = i + 1; j < tFluidList_sS; j++) { + if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { + if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { + tFluidList.remove(j--); + tFluidList_sS = tFluidList.size(); + } else { + tFluidList.remove(i--); + tFluidList_sS = tFluidList.size(); + break; + } + } + } + } + if (tFluidList.size() > 1) { + FluidStack[] tFluids = tFluidList.toArray(new FluidStack[tFluidList.size()]); + GT_Recipe tRecipe = getRecipeList() + .findRecipe( + this.getBaseMetaTileEntity(), + this.mLastRecipe, + false, + GT_Values.V[8], + tFluids, + new ItemStack[] {}); + if (tRecipe == null) { + return false; + } + if ((tRecipe == null && !mRunningOnLoad) || (tRecipe != null && maxEUStore() < tRecipe.mSpecialValue)) { + this.mLastRecipe = null; + Logger.MACHINE_INFO("Just plain bad."); + return false; + } + if (mRunningOnLoad || tRecipe.isRecipeInputEqual(true, tFluids, new ItemStack[] {})) { + this.mLastRecipe = tRecipe; + this.mEUt = (this.mLastRecipe.mEUt * overclock(this.mLastRecipe.mSpecialValue)); + this.mMaxProgresstime = this.mLastRecipe.mDuration / overclock(this.mLastRecipe.mSpecialValue); + + this.mEfficiencyIncrease = 10000; + + this.mOutputFluids = this.mLastRecipe.mFluidOutputs; + mRunningOnLoad = false; + return true; + } + } + return false; + } + + public int overclock(int mStartEnergy) { + if (tierOverclock() == 1) { + return 1; + } + if (tierOverclock() == 2) { + return mStartEnergy < 160000000 ? 2 : 1; + } + return mStartEnergy < 160000000 ? 4 : mStartEnergy < 320000000 ? 2 : 1; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean doesAutoOutputFluids() { + return true; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public long maxAmperesIn() { + return 16L; + } + + @Override + public long maxEUStore() { + return Long.MAX_VALUE; + } + + @Override + public void doExplosion(long aExplosionPower) { + super.doExplosion(aExplosionPower * 2); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + onRunningTickMulti(); + if ((aBaseMetaTileEntity.isClientSide()) + && (aBaseMetaTileEntity.isActive()) + && (aBaseMetaTileEntity.getFrontFacing() != 1) + && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) + && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { + if (MathUtils.randInt(0, 4) == 4) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), + aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), + (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), + 0.0D, + 0.0D, + 0.0D); + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.4F) - (tRandom.nextFloat() * 0.3F), + aBaseMetaTileEntity.getYCoord() + 0.2f + (tRandom.nextFloat() * 0.1F), + (aBaseMetaTileEntity.getZCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), + 0.0D, + 0.0D, + 0.0D); + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.6F) - (tRandom.nextFloat() * 0.9F), + aBaseMetaTileEntity.getYCoord() + 0.4f + (tRandom.nextFloat() * 0.3F), + (aBaseMetaTileEntity.getZCoord() + 1.8F) - (tRandom.nextFloat() * 2.6F), + 0.0D, + 0.0D, + 0.0D); + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mCanProcessRecipe", this.mCanProcessRecipe); + aNBT.setBoolean("mCharging", this.mCharging); + aNBT.setLong("mChargeConsumed", this.mChargeConsumed); + aNBT.setInteger("mEfficiency", this.mEfficiency); + aNBT.setInteger("mEfficiencyIncrease", this.mEfficiencyIncrease); + aNBT.setInteger("mEfficiencyMax", this.mEfficiencyMax); + aNBT.setInteger("mStartUpCheck", this.mStartUpCheck); + aNBT.setInteger("mUpdate", mUpdate); + aNBT.setInteger("mEfficiencyIncrease", mEfficiencyIncrease); + aNBT.setBoolean("mRunningOnLoad", this.mRunningOnLoad); + aNBT.setBoolean("mMachine", this.mMachine); + aNBT.setLong("mEUStore", this.mEUStore); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (mMaxProgresstime > 0) mRunningOnLoad = true; + this.mCanProcessRecipe = aNBT.getBoolean("mCanProcessRecipe"); + this.mCharging = aNBT.getBoolean("mCharging"); + this.mChargeConsumed = aNBT.getLong("mChargeConsumed"); + this.mEfficiency = aNBT.getInteger("mEfficiency"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mEfficiencyMax = aNBT.getInteger("mEfficiencyMax"); + this.mStartUpCheck = aNBT.getInteger("mStartUpCheck"); + this.mUpdate = aNBT.getInteger("mUpdate"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mRunningOnLoad = aNBT.getBoolean("mRunningOnLoad"); + this.mMachine = aNBT.getBoolean("mMachine"); + this.mEUStore = aNBT.getLong("mEUStore"); + super.loadNBTData(aNBT); + } + + @Override + public String[] getInfoData() { + String tier = tier() == 6 ? "I" : tier() == 7 ? "II" : "III"; + float plasmaOut = 0; + String fusionName = ""; + int powerRequired = 0; + if (this.mLastRecipe != null) { + fusionName = this.mLastRecipe.mFluidOutputs[0].getLocalizedName() + " Fusion."; + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; + } + } + + return new String[] { + "Fusion Reactor MK " + tier, + "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + this.getEUVar() + " / " + maxEUStore(), + "Plasma Output: " + plasmaOut + "L/t", + "Current Recipe: " + fusionName + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab)}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS)}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS)}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] {this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] {this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW)}; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW)}; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue) + }; + } + + @Override + public void onMachineBlockUpdate() { + this.mUpdate = 50; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + // Logger.MACHINE_INFO("1"); + if (mEfficiency < 0) mEfficiency = 0; + if (mRunningOnLoad) { + Logger.MACHINE_INFO("2"); + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + checkRecipeMulti(); + } + if (--mUpdate == 0 || --mStartUpCheck == 0) { + Logger.MACHINE_INFO("3"); + mMachine = true; + } + if (mStartUpCheck < 0) { + // Logger.MACHINE_INFO("4"); + if (mMachine) { + // Logger.MACHINE_INFO("5"); + + if (aBaseMetaTileEntity.getStoredEU() + (2048 * tierOverclock()) < maxEUStore()) { + if (aBaseMetaTileEntity.increaseStoredEnergyUnits(2048 * tierOverclock(), true)) { + // Logger.MACHINE_INFO("5.5 A"); + } else { + // Logger.MACHINE_INFO("5.5 B"); + } + } + if (this.mEUStore <= 0 && mMaxProgresstime > 0) { + Logger.MACHINE_INFO("6"); + stopMachine(); + this.mLastRecipe = null; + } + if (mMaxProgresstime > 0) { + Logger.MACHINE_INFO("7"); + this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt, true); + if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { + if (mOutputFluids != null) + for (FluidStack tStack : mOutputFluids) if (tStack != null) addOutput(tStack); + mEfficiency = Math.max(0, (mEfficiency + mEfficiencyIncrease)); + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + if (mOutputFluids != null && mOutputFluids.length > 0) {} + + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + if (aBaseMetaTileEntity.isAllowedToWork()) checkRecipeMulti(); + } + } else { + // Logger.MACHINE_INFO("8"); + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + if (aTick % 100 == 0 + || aBaseMetaTileEntity.hasWorkJustBeenEnabled() + || aBaseMetaTileEntity.hasInventoryBeenModified()) { + Logger.MACHINE_INFO("9"); + // turnCasingActive(mMaxProgresstime > 0); + if (aBaseMetaTileEntity.isAllowedToWork()) { + Logger.MACHINE_INFO("10"); + if (checkRecipeMulti()) { + Logger.MACHINE_INFO("11"); + if (this.mEUStore < this.mLastRecipe.mSpecialValue) { + Logger.MACHINE_INFO("12"); + mMaxProgresstime = 0; + // turnCasingActive(false); + } + aBaseMetaTileEntity.decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue, true); + } + } + if (mMaxProgresstime <= 0) mEfficiency = Math.max(0, mEfficiency - 1000); + } + } + } else { + // turnCasingActive(false); + Logger.MACHINE_INFO("Bad"); + this.mLastRecipe = null; + stopMachine(); + } + } + Logger.MACHINE_INFO("Good | " + mMaxProgresstime); + aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); + } + } + + public boolean onRunningTickMulti() { + if (this.getBaseMetaTileEntity().isServerSide()) { + if (mEUt < 0) { + if (!drainEnergyInput(((long) -mEUt * 10000) / Math.max(1000, mEfficiency))) { + this.mLastRecipe = null; + stopMachine(); + Logger.MACHINE_INFO("a1"); + return false; + } + } + if (this.mEUStore <= 0) { + this.mLastRecipe = null; + stopMachine(); + Logger.MACHINE_INFO("a2"); + return false; + } + } + return true; + } + + public boolean drainEnergyInput(long aEU) { + return false; + } + + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) return false; + FluidStack copiedFluidStack = aLiquid.copy(); + this.mOutputFluid = copiedFluidStack; + return false; + } + + public void stopMachine() { + mEUt = 0; + mEfficiency = 0; + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + getBaseMetaTileEntity().disableWorking(); + } + + @Override + public boolean isLiquidInput(byte aSide) { + switch (aSide) { + case 0: + return true; + case 1: + return true; + case 2: + return true; + case 3: + return false; + case 4: + return false; + case 5: + return false; + default: + return false; + } + } + + @Override + public boolean isLiquidOutput(byte aSide) { + switch (aSide) { + case 0: + return false; + case 1: + return false; + case 2: + return false; + case 3: + return true; + case 4: + return true; + case 5: + return true; + default: + return true; + } + } + + @Override + public int fill(FluidStack aFluid, boolean doFill) { + return super.fill(aFluid, doFill); + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return super.drain(maxDrain, doDrain); + } + + @Override + public int getTankPressure() { + return 500; + } + + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return false; + } else { + return super.canFill(aSide, aFluid); + } + } + + @Override + public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.canDrain(aSide, aFluid); + } else { + return false; + } + } + + @Override + public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return 0; + } else { + return super.fill_default(aSide, aFluid, doFill); + } + } + + @Override + public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.fill(aSide, aFluid, doFill); + } else { + return 0; + } + } + + @Override + public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.drain(aSide, aFluid, doDrain); + } else { + return null; + } + } + + @Override + public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.drain(aSide, maxDrain, doDrain); + } else { + return null; + } + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + // TODO Auto-generated method stub + return super.onRightclick(aBaseMetaTileEntity, aPlayer); + } + + @Override + public boolean onRightclick( + IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + // TODO Auto-generated method stub + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + // TODO Auto-generated method stub + return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + // TODO Auto-generated method stub + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + return false; + } + + @Override + public void onExplosion() { + // TODO Auto-generated method stub + super.onExplosion(); + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 1) { + GT_Utility.doSoundAtClient( + (String) GregTech_API.sSoundList.get(Integer.valueOf(212)), 10, 1.0F, aX, aY, aZ); + } + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_PocketFusion.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_PocketFusion.java index 6cae58ced2..08c9934db8 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_PocketFusion.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_PocketFusion.java @@ -1,13 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; -import java.util.ArrayList; -import java.util.Random; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; @@ -15,690 +7,722 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.api.util.GTPP_Recipe; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_DeluxeMachine; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.Random; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_PocketFusion extends GT_MetaTileEntity_DeluxeMachine { - private boolean mCanProcessRecipe = false; - private boolean mCharging = false; - private long mChargeConsumed = 0; - - private GT_Recipe mLastRecipe; - private long mEUStore; - private boolean mRunningOnLoad = false; - private boolean mMachine = false; - private int mEfficiency, mEfficiencyIncrease, mEfficiencyMax = 0; - private int mStartUpCheck = 100, mUpdate = 0; - private FluidStack[] mOutputFluids = null; - - public GregtechMetaTileEntity_PocketFusion(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, "It's like a midget Ra.", 1, 1, "PotionBrewer.png", ""); - } - - public GregtechMetaTileEntity_PocketFusion(String aName, int aTier, String aDescription, - ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); - } - - @Override - public String[] getDescription() { - return new String[] { this.mDescription, "Not Very Fast, but not very big either.", - "Each side pair in/out puts to different slots.", "Top & Bottom Sides are Outputs.", - "Front & Back are Input Plasma 1.", "Sides are Input Plasma 2.", CORE.GT_Tooltip }; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_PocketFusion(this.mName, this.mTier, this.mDescription, - this.mTextures, this.mGUIName, this.mNEIName); - } - - public int tier() { - return this.mTier; - } - - public int tierOverclock() { - return this.mTier == 6 ? 0 : this.mTier == 7 ? 1 : 2; - } - - private GT_RenderedTexture getCasingTexture() { - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 - : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex - + 1]; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeList() { - return GTPP_Recipe.GTPP_Recipe_Map.sSlowFusionRecipes; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide == this.getBaseMetaTileEntity().getBackFacing(); - } - - @Override - public boolean isFluidInputAllowed(FluidStack aFluid) { - return (aFluid.getFluid().getName().contains("plasma")) || (super.isFluidInputAllowed(aFluid)); - } - - @Override - public int getCapacity() { - return 32000; - } - - @Override - public void abortProcess() { - super.abortProcess(); - } - - long mFusionPoint = 20000000L; - - @Override - public int checkRecipe() { - Logger.MACHINE_INFO("Recipe Tick 1."); - if (!this.mCanProcessRecipe) { - Logger.MACHINE_INFO("Recipe Tick 1.1 - Cannot Process Recipe."); - if (this.mChargeConsumed < mFusionPoint) { - Logger.MACHINE_INFO("Recipe Tick 1.2 - Cannot Ignite Fusion, Charge too low."); - this.mCharging = true; - this.mCanProcessRecipe = false; - if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits((mFusionPoint / 100), false)) { - Logger.MACHINE_INFO("Recipe Tick 1.3 - Charging Internal storage. " + (mFusionPoint / 100) + "/" - + mFusionPoint); - mChargeConsumed += (mFusionPoint / 100); - } - } - else { - mChargeConsumed = 0; - this.mCharging = false; - this.mCanProcessRecipe = true; - - } - } - else { - Logger.MACHINE_INFO("Recipe Tick 1.1 - Try to Process Recipe."); - if (checkRecipeMulti()) { - Logger.MACHINE_INFO("Recipe Tick 1.2 - Process Recipe was Successful."); - return 2; - } - } - Logger.MACHINE_INFO("Recipe Tick 2. - Process Recipe failed."); - return 0; - } - - public ArrayList<FluidStack> getStoredFluids() { - ArrayList<FluidStack> mList = new ArrayList<FluidStack>(); - mList.add(this.mFluid); - mList.add(this.mFluid2); - return mList; - } - - public boolean checkRecipeMulti() { - ArrayList<FluidStack> tFluidList = getStoredFluids(); - int tFluidList_sS = tFluidList.size(); - for (int i = 0; i < tFluidList_sS - 1; i++) { - for (int j = i + 1; j < tFluidList_sS; j++) { - if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { - if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { - tFluidList.remove(j--); - tFluidList_sS = tFluidList.size(); - } - else { - tFluidList.remove(i--); - tFluidList_sS = tFluidList.size(); - break; - } - } - } - } - if (tFluidList.size() > 1) { - FluidStack[] tFluids = tFluidList.toArray(new FluidStack[tFluidList.size()]); - GT_Recipe tRecipe = getRecipeList().findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, false, - GT_Values.V[8], tFluids, new ItemStack[] {}); - - if (tRecipe == null) { - return false; - } - - if ((tRecipe == null && !mRunningOnLoad) || (tRecipe != null && maxEUStore() < tRecipe.mSpecialValue)) { - this.mLastRecipe = null; - Logger.MACHINE_INFO("Just plain bad."); - return false; - } - if (mRunningOnLoad || tRecipe.isRecipeInputEqual(true, tFluids, new ItemStack[] {})) { - this.mLastRecipe = tRecipe; - this.mEUt = (this.mLastRecipe.mEUt * overclock(this.mLastRecipe.mSpecialValue)); - this.mMaxProgresstime = this.mLastRecipe.mDuration / overclock(this.mLastRecipe.mSpecialValue); - - this.mEfficiencyIncrease = 10000; - - this.mOutputFluids = this.mLastRecipe.mFluidOutputs; - mRunningOnLoad = false; - return true; - } - } - return false; - } - - public int overclock(int mStartEnergy) { - if (tierOverclock() == 1) { - return 1; - } - if (tierOverclock() == 2) { - return mStartEnergy < 160000000 ? 2 : 1; - } - return mStartEnergy < 160000000 ? 4 : mStartEnergy < 320000000 ? 2 : 1; - } - - @Override - public boolean displaysItemStack() { - return false; - } - - @Override - public boolean doesAutoOutputFluids() { - return true; - } - - @Override - public boolean doesEmptyContainers() { - return true; - } - - @Override - public boolean doesFillContainers() { - return true; - } - - @Override - public long maxAmperesIn() { - return 16L; - } - - @Override - public long maxEUStore() { - return Long.MAX_VALUE; - } - - @Override - public void doExplosion(long aExplosionPower) { - super.doExplosion(aExplosionPower * 2); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - onRunningTickMulti(); - if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) - && (aBaseMetaTileEntity.getFrontFacing() != 1) && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) - && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { - if (MathUtils.randInt(0, 4) == 4) { - final Random tRandom = aBaseMetaTileEntity.getWorld().rand; - aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", - (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), - aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), - (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), 0.0D, 0.0D, 0.0D); - aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", - (aBaseMetaTileEntity.getXCoord() + 0.4F) - (tRandom.nextFloat() * 0.3F), - aBaseMetaTileEntity.getYCoord() + 0.2f + (tRandom.nextFloat() * 0.1F), - (aBaseMetaTileEntity.getZCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), 0.0D, 0.0D, 0.0D); - aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", - (aBaseMetaTileEntity.getXCoord() + 0.6F) - (tRandom.nextFloat() * 0.9F), - aBaseMetaTileEntity.getYCoord() + 0.4f + (tRandom.nextFloat() * 0.3F), - (aBaseMetaTileEntity.getZCoord() + 1.8F) - (tRandom.nextFloat() * 2.6F), 0.0D, 0.0D, 0.0D); - } - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("mCanProcessRecipe", this.mCanProcessRecipe); - aNBT.setBoolean("mCharging", this.mCharging); - aNBT.setLong("mChargeConsumed", this.mChargeConsumed); - aNBT.setInteger("mEfficiency", this.mEfficiency); - aNBT.setInteger("mEfficiencyIncrease", this.mEfficiencyIncrease); - aNBT.setInteger("mEfficiencyMax", this.mEfficiencyMax); - aNBT.setInteger("mStartUpCheck", this.mStartUpCheck); - aNBT.setInteger("mUpdate", mUpdate); - aNBT.setInteger("mEfficiencyIncrease", mEfficiencyIncrease); - aNBT.setBoolean("mRunningOnLoad", this.mRunningOnLoad); - aNBT.setBoolean("mMachine", this.mMachine); - aNBT.setLong("mEUStore", this.mEUStore); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - if (mMaxProgresstime > 0) - mRunningOnLoad = true; - this.mCanProcessRecipe = aNBT.getBoolean("mCanProcessRecipe"); - this.mCharging = aNBT.getBoolean("mCharging"); - this.mChargeConsumed = aNBT.getLong("mChargeConsumed"); - this.mEfficiency = aNBT.getInteger("mEfficiency"); - this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); - this.mEfficiencyMax = aNBT.getInteger("mEfficiencyMax"); - this.mStartUpCheck = aNBT.getInteger("mStartUpCheck"); - this.mUpdate = aNBT.getInteger("mUpdate"); - this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); - this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); - this.mRunningOnLoad = aNBT.getBoolean("mRunningOnLoad"); - this.mMachine = aNBT.getBoolean("mMachine"); - this.mEUStore = aNBT.getLong("mEUStore"); - super.loadNBTData(aNBT); - } - - @Override - public String[] getInfoData() { - String tier = tier() == 6 ? "I" : tier() == 7 ? "II" : "III"; - float plasmaOut = 0; - String fusionName = ""; - int powerRequired = 0; - if (this.mLastRecipe != null) { - fusionName = this.mLastRecipe.mFluidOutputs[0].getLocalizedName() + " Fusion."; - powerRequired = this.mLastRecipe.mEUt; - if (this.mLastRecipe.getFluidOutput(0) != null) { - plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; - } - } - - return new String[] { "Fusion Reactor MK " + tier, "EU Required: " + powerRequired + "EU/t", - "Stored EU: " + this.getEUVar() + " / " + maxEUStore(), "Plasma Output: " + plasmaOut + "L/t", - "Current Recipe: " + fusionName }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab) }; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS) }; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS) }; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), - new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; - } - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), - new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active) }; - } - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW) }; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW) }; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] { this.getCasingTexture(), - new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue) }; - } - - @Override - public void onMachineBlockUpdate() { - this.mUpdate = 50; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - // super.onPostTick(aBaseMetaTileEntity, aTick); - if (aBaseMetaTileEntity.isServerSide()) { - // Logger.MACHINE_INFO("1"); - if (mEfficiency < 0) - mEfficiency = 0; - if (mRunningOnLoad) { - Logger.MACHINE_INFO("2"); - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - checkRecipeMulti(); - } - if (--mUpdate == 0 || --mStartUpCheck == 0) { - Logger.MACHINE_INFO("3"); - mMachine = true; - } - if (mStartUpCheck < 0) { - //Logger.MACHINE_INFO("4"); - if (mMachine) { - //Logger.MACHINE_INFO("5"); - - if (aBaseMetaTileEntity.getStoredEU() + (2048 * tierOverclock()) < maxEUStore()) { - if (aBaseMetaTileEntity.increaseStoredEnergyUnits(2048 * tierOverclock(), true)) { - //Logger.MACHINE_INFO("5.5 A"); - } - else { - //Logger.MACHINE_INFO("5.5 B"); - } - } - if (this.mEUStore <= 0 && mMaxProgresstime > 0) { - Logger.MACHINE_INFO("6"); - stopMachine(); - this.mLastRecipe = null; - } - if (mMaxProgresstime > 0) { - Logger.MACHINE_INFO("7"); - this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt, true); - if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { - if (mOutputFluids != null) - for (FluidStack tStack : mOutputFluids) - if (tStack != null) - addOutput(tStack); - mEfficiency = Math.max(0, (mEfficiency + mEfficiencyIncrease)); - mProgresstime = 0; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - if (mOutputFluids != null && mOutputFluids.length > 0) { - - } - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - if (aBaseMetaTileEntity.isAllowedToWork()) - checkRecipeMulti(); - } - } - else { - //Logger.MACHINE_INFO("8"); - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() - || aBaseMetaTileEntity.hasInventoryBeenModified()) { - Logger.MACHINE_INFO("9"); - // turnCasingActive(mMaxProgresstime > 0); - if (aBaseMetaTileEntity.isAllowedToWork()) { - Logger.MACHINE_INFO("10"); - if (checkRecipeMulti()) { - Logger.MACHINE_INFO("11"); - if (this.mEUStore < this.mLastRecipe.mSpecialValue) { - Logger.MACHINE_INFO("12"); - mMaxProgresstime = 0; - // turnCasingActive(false); - } - aBaseMetaTileEntity.decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue, true); - } - } - if (mMaxProgresstime <= 0) - mEfficiency = Math.max(0, mEfficiency - 1000); - } - } - } - else { - // turnCasingActive(false); - Logger.MACHINE_INFO("Bad"); - this.mLastRecipe = null; - stopMachine(); - } - } - Logger.MACHINE_INFO("Good | "+mMaxProgresstime); - aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); - } - } - - public boolean onRunningTickMulti() { - if (this.getBaseMetaTileEntity().isServerSide()) { - if (mEUt < 0) { - if (!drainEnergyInput(((long) -mEUt * 10000) / Math.max(1000, mEfficiency))) { - this.mLastRecipe = null; - stopMachine(); - Logger.MACHINE_INFO("a1"); - return false; - } - } - if (this.mEUStore <= 0) { - this.mLastRecipe = null; - stopMachine(); - Logger.MACHINE_INFO("a2"); - return false; - } - } - return true; - } - - public boolean drainEnergyInput(long aEU) { - return false; - } - - public boolean addOutput(FluidStack aLiquid) { - if (aLiquid == null) - return false; - FluidStack copiedFluidStack = aLiquid.copy(); - this.mOutputFluid = copiedFluidStack; - return false; - } - - public void stopMachine() { - mEUt = 0; - mEfficiency = 0; - mProgresstime = 0; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - getBaseMetaTileEntity().disableWorking(); - } - - @Override - public boolean isLiquidInput(byte aSide) { - switch (aSide) { - case 0: - return true; - case 1: - return true; - case 2: - return true; - case 3: - return false; - case 4: - return false; - case 5: - return false; - default: - return false; - } - } - - @Override - public boolean isLiquidOutput(byte aSide) { - switch (aSide) { - case 0: - return false; - case 1: - return false; - case 2: - return false; - case 3: - return true; - case 4: - return true; - case 5: - return true; - default: - return true; - } - } - - @Override - public int fill(FluidStack aFluid, boolean doFill) { - return super.fill(aFluid, doFill); - } - - @Override - public FluidStack drain(int maxDrain, boolean doDrain) { - return super.drain(maxDrain, doDrain); - } - - @Override - public int getTankPressure() { - return 500; - } - - @Override - public boolean canFill(ForgeDirection aSide, Fluid aFluid) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return false; - } - else { - return super.canFill(aSide, aFluid); - } - } - - @Override - public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return super.canDrain(aSide, aFluid); - } - else { - return false; - } - } - - @Override - public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return 0; - } - else { - return super.fill_default(aSide, aFluid, doFill); - } - } - - @Override - public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return super.fill(aSide, aFluid, doFill); - } - else { - return 0; - } - } - - @Override - public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return super.drain(aSide, aFluid, doDrain); - } - else { - return null; - } - } - - @Override - public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { - if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { - return super.drain(aSide, maxDrain, doDrain); - } - else { - return null; - } - } - - @Override - public boolean isOverclockerUpgradable() { - return true; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - // TODO Auto-generated method stub - return super.onRightclick(aBaseMetaTileEntity, aPlayer); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, - float aY, float aZ) { - // TODO Auto-generated method stub - return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - // TODO Auto-generated method stub - return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - // TODO Auto-generated method stub - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - return false; - } - - @Override - public void onExplosion() { - // TODO Auto-generated method stub - super.onExplosion(); - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { - super.startSoundLoop(aIndex, aX, aY, aZ); - if (aIndex == 1) { - GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(212)), 10, 1.0F, aX, aY, - aZ); - } - } - + private boolean mCanProcessRecipe = false; + private boolean mCharging = false; + private long mChargeConsumed = 0; + + private GT_Recipe mLastRecipe; + private long mEUStore; + private boolean mRunningOnLoad = false; + private boolean mMachine = false; + private int mEfficiency, mEfficiencyIncrease, mEfficiencyMax = 0; + private int mStartUpCheck = 100, mUpdate = 0; + private FluidStack[] mOutputFluids = null; + + public GregtechMetaTileEntity_PocketFusion(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, "It's like a midget Ra.", 1, 1, "PotionBrewer.png", ""); + } + + public GregtechMetaTileEntity_PocketFusion( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Not Very Fast, but not very big either.", + "Each side pair in/out puts to different slots.", + "Top & Bottom Sides are Outputs.", + "Front & Back are Input Plasma 1.", + "Sides are Input Plasma 2.", + CORE.GT_Tooltip + }; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_PocketFusion( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + public int tier() { + return this.mTier; + } + + public int tierOverclock() { + return this.mTier == 6 ? 0 : this.mTier == 7 ? 1 : 2; + } + + private GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sSlowFusionRecipes; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return (aFluid.getFluid().getName().contains("plasma")) || (super.isFluidInputAllowed(aFluid)); + } + + @Override + public int getCapacity() { + return 32000; + } + + @Override + public void abortProcess() { + super.abortProcess(); + } + + long mFusionPoint = 20000000L; + + @Override + public int checkRecipe() { + Logger.MACHINE_INFO("Recipe Tick 1."); + if (!this.mCanProcessRecipe) { + Logger.MACHINE_INFO("Recipe Tick 1.1 - Cannot Process Recipe."); + if (this.mChargeConsumed < mFusionPoint) { + Logger.MACHINE_INFO("Recipe Tick 1.2 - Cannot Ignite Fusion, Charge too low."); + this.mCharging = true; + this.mCanProcessRecipe = false; + if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits((mFusionPoint / 100), false)) { + Logger.MACHINE_INFO("Recipe Tick 1.3 - Charging Internal storage. " + (mFusionPoint / 100) + "/" + + mFusionPoint); + mChargeConsumed += (mFusionPoint / 100); + } + } else { + mChargeConsumed = 0; + this.mCharging = false; + this.mCanProcessRecipe = true; + } + } else { + Logger.MACHINE_INFO("Recipe Tick 1.1 - Try to Process Recipe."); + if (checkRecipeMulti()) { + Logger.MACHINE_INFO("Recipe Tick 1.2 - Process Recipe was Successful."); + return 2; + } + } + Logger.MACHINE_INFO("Recipe Tick 2. - Process Recipe failed."); + return 0; + } + + public ArrayList<FluidStack> getStoredFluids() { + ArrayList<FluidStack> mList = new ArrayList<FluidStack>(); + mList.add(this.mFluid); + mList.add(this.mFluid2); + return mList; + } + + public boolean checkRecipeMulti() { + ArrayList<FluidStack> tFluidList = getStoredFluids(); + int tFluidList_sS = tFluidList.size(); + for (int i = 0; i < tFluidList_sS - 1; i++) { + for (int j = i + 1; j < tFluidList_sS; j++) { + if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { + if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { + tFluidList.remove(j--); + tFluidList_sS = tFluidList.size(); + } else { + tFluidList.remove(i--); + tFluidList_sS = tFluidList.size(); + break; + } + } + } + } + if (tFluidList.size() > 1) { + FluidStack[] tFluids = tFluidList.toArray(new FluidStack[tFluidList.size()]); + GT_Recipe tRecipe = getRecipeList() + .findRecipe( + this.getBaseMetaTileEntity(), + this.mLastRecipe, + false, + GT_Values.V[8], + tFluids, + new ItemStack[] {}); + + if (tRecipe == null) { + return false; + } + + if ((tRecipe == null && !mRunningOnLoad) || (tRecipe != null && maxEUStore() < tRecipe.mSpecialValue)) { + this.mLastRecipe = null; + Logger.MACHINE_INFO("Just plain bad."); + return false; + } + if (mRunningOnLoad || tRecipe.isRecipeInputEqual(true, tFluids, new ItemStack[] {})) { + this.mLastRecipe = tRecipe; + this.mEUt = (this.mLastRecipe.mEUt * overclock(this.mLastRecipe.mSpecialValue)); + this.mMaxProgresstime = this.mLastRecipe.mDuration / overclock(this.mLastRecipe.mSpecialValue); + + this.mEfficiencyIncrease = 10000; + + this.mOutputFluids = this.mLastRecipe.mFluidOutputs; + mRunningOnLoad = false; + return true; + } + } + return false; + } + + public int overclock(int mStartEnergy) { + if (tierOverclock() == 1) { + return 1; + } + if (tierOverclock() == 2) { + return mStartEnergy < 160000000 ? 2 : 1; + } + return mStartEnergy < 160000000 ? 4 : mStartEnergy < 320000000 ? 2 : 1; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean doesAutoOutputFluids() { + return true; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public long maxAmperesIn() { + return 16L; + } + + @Override + public long maxEUStore() { + return Long.MAX_VALUE; + } + + @Override + public void doExplosion(long aExplosionPower) { + super.doExplosion(aExplosionPower * 2); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + onRunningTickMulti(); + if ((aBaseMetaTileEntity.isClientSide()) + && (aBaseMetaTileEntity.isActive()) + && (aBaseMetaTileEntity.getFrontFacing() != 1) + && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) + && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { + if (MathUtils.randInt(0, 4) == 4) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), + aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), + (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), + 0.0D, + 0.0D, + 0.0D); + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.4F) - (tRandom.nextFloat() * 0.3F), + aBaseMetaTileEntity.getYCoord() + 0.2f + (tRandom.nextFloat() * 0.1F), + (aBaseMetaTileEntity.getZCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), + 0.0D, + 0.0D, + 0.0D); + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.6F) - (tRandom.nextFloat() * 0.9F), + aBaseMetaTileEntity.getYCoord() + 0.4f + (tRandom.nextFloat() * 0.3F), + (aBaseMetaTileEntity.getZCoord() + 1.8F) - (tRandom.nextFloat() * 2.6F), + 0.0D, + 0.0D, + 0.0D); + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mCanProcessRecipe", this.mCanProcessRecipe); + aNBT.setBoolean("mCharging", this.mCharging); + aNBT.setLong("mChargeConsumed", this.mChargeConsumed); + aNBT.setInteger("mEfficiency", this.mEfficiency); + aNBT.setInteger("mEfficiencyIncrease", this.mEfficiencyIncrease); + aNBT.setInteger("mEfficiencyMax", this.mEfficiencyMax); + aNBT.setInteger("mStartUpCheck", this.mStartUpCheck); + aNBT.setInteger("mUpdate", mUpdate); + aNBT.setInteger("mEfficiencyIncrease", mEfficiencyIncrease); + aNBT.setBoolean("mRunningOnLoad", this.mRunningOnLoad); + aNBT.setBoolean("mMachine", this.mMachine); + aNBT.setLong("mEUStore", this.mEUStore); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (mMaxProgresstime > 0) mRunningOnLoad = true; + this.mCanProcessRecipe = aNBT.getBoolean("mCanProcessRecipe"); + this.mCharging = aNBT.getBoolean("mCharging"); + this.mChargeConsumed = aNBT.getLong("mChargeConsumed"); + this.mEfficiency = aNBT.getInteger("mEfficiency"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mEfficiencyMax = aNBT.getInteger("mEfficiencyMax"); + this.mStartUpCheck = aNBT.getInteger("mStartUpCheck"); + this.mUpdate = aNBT.getInteger("mUpdate"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mRunningOnLoad = aNBT.getBoolean("mRunningOnLoad"); + this.mMachine = aNBT.getBoolean("mMachine"); + this.mEUStore = aNBT.getLong("mEUStore"); + super.loadNBTData(aNBT); + } + + @Override + public String[] getInfoData() { + String tier = tier() == 6 ? "I" : tier() == 7 ? "II" : "III"; + float plasmaOut = 0; + String fusionName = ""; + int powerRequired = 0; + if (this.mLastRecipe != null) { + fusionName = this.mLastRecipe.mFluidOutputs[0].getLocalizedName() + " Fusion."; + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; + } + } + + return new String[] { + "Fusion Reactor MK " + tier, + "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + this.getEUVar() + " / " + maxEUStore(), + "Plasma Output: " + plasmaOut + "L/t", + "Current Recipe: " + fusionName + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab)}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS)}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS)}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] {this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] {this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW)}; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW)}; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue) + }; + } + + @Override + public void onMachineBlockUpdate() { + this.mUpdate = 50; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + // Logger.MACHINE_INFO("1"); + if (mEfficiency < 0) mEfficiency = 0; + if (mRunningOnLoad) { + Logger.MACHINE_INFO("2"); + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + checkRecipeMulti(); + } + if (--mUpdate == 0 || --mStartUpCheck == 0) { + Logger.MACHINE_INFO("3"); + mMachine = true; + } + if (mStartUpCheck < 0) { + // Logger.MACHINE_INFO("4"); + if (mMachine) { + // Logger.MACHINE_INFO("5"); + + if (aBaseMetaTileEntity.getStoredEU() + (2048 * tierOverclock()) < maxEUStore()) { + if (aBaseMetaTileEntity.increaseStoredEnergyUnits(2048 * tierOverclock(), true)) { + // Logger.MACHINE_INFO("5.5 A"); + } else { + // Logger.MACHINE_INFO("5.5 B"); + } + } + if (this.mEUStore <= 0 && mMaxProgresstime > 0) { + Logger.MACHINE_INFO("6"); + stopMachine(); + this.mLastRecipe = null; + } + if (mMaxProgresstime > 0) { + Logger.MACHINE_INFO("7"); + this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt, true); + if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { + if (mOutputFluids != null) + for (FluidStack tStack : mOutputFluids) if (tStack != null) addOutput(tStack); + mEfficiency = Math.max(0, (mEfficiency + mEfficiencyIncrease)); + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + if (mOutputFluids != null && mOutputFluids.length > 0) {} + + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + if (aBaseMetaTileEntity.isAllowedToWork()) checkRecipeMulti(); + } + } else { + // Logger.MACHINE_INFO("8"); + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + if (aTick % 100 == 0 + || aBaseMetaTileEntity.hasWorkJustBeenEnabled() + || aBaseMetaTileEntity.hasInventoryBeenModified()) { + Logger.MACHINE_INFO("9"); + // turnCasingActive(mMaxProgresstime > 0); + if (aBaseMetaTileEntity.isAllowedToWork()) { + Logger.MACHINE_INFO("10"); + if (checkRecipeMulti()) { + Logger.MACHINE_INFO("11"); + if (this.mEUStore < this.mLastRecipe.mSpecialValue) { + Logger.MACHINE_INFO("12"); + mMaxProgresstime = 0; + // turnCasingActive(false); + } + aBaseMetaTileEntity.decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue, true); + } + } + if (mMaxProgresstime <= 0) mEfficiency = Math.max(0, mEfficiency - 1000); + } + } + } else { + // turnCasingActive(false); + Logger.MACHINE_INFO("Bad"); + this.mLastRecipe = null; + stopMachine(); + } + } + Logger.MACHINE_INFO("Good | " + mMaxProgresstime); + aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); + } + } + + public boolean onRunningTickMulti() { + if (this.getBaseMetaTileEntity().isServerSide()) { + if (mEUt < 0) { + if (!drainEnergyInput(((long) -mEUt * 10000) / Math.max(1000, mEfficiency))) { + this.mLastRecipe = null; + stopMachine(); + Logger.MACHINE_INFO("a1"); + return false; + } + } + if (this.mEUStore <= 0) { + this.mLastRecipe = null; + stopMachine(); + Logger.MACHINE_INFO("a2"); + return false; + } + } + return true; + } + + public boolean drainEnergyInput(long aEU) { + return false; + } + + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) return false; + FluidStack copiedFluidStack = aLiquid.copy(); + this.mOutputFluid = copiedFluidStack; + return false; + } + + public void stopMachine() { + mEUt = 0; + mEfficiency = 0; + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + getBaseMetaTileEntity().disableWorking(); + } + + @Override + public boolean isLiquidInput(byte aSide) { + switch (aSide) { + case 0: + return true; + case 1: + return true; + case 2: + return true; + case 3: + return false; + case 4: + return false; + case 5: + return false; + default: + return false; + } + } + + @Override + public boolean isLiquidOutput(byte aSide) { + switch (aSide) { + case 0: + return false; + case 1: + return false; + case 2: + return false; + case 3: + return true; + case 4: + return true; + case 5: + return true; + default: + return true; + } + } + + @Override + public int fill(FluidStack aFluid, boolean doFill) { + return super.fill(aFluid, doFill); + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return super.drain(maxDrain, doDrain); + } + + @Override + public int getTankPressure() { + return 500; + } + + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return false; + } else { + return super.canFill(aSide, aFluid); + } + } + + @Override + public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.canDrain(aSide, aFluid); + } else { + return false; + } + } + + @Override + public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return 0; + } else { + return super.fill_default(aSide, aFluid, doFill); + } + } + + @Override + public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.fill(aSide, aFluid, doFill); + } else { + return 0; + } + } + + @Override + public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.drain(aSide, aFluid, doDrain); + } else { + return null; + } + } + + @Override + public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.drain(aSide, maxDrain, doDrain); + } else { + return null; + } + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + // TODO Auto-generated method stub + return super.onRightclick(aBaseMetaTileEntity, aPlayer); + } + + @Override + public boolean onRightclick( + IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + // TODO Auto-generated method stub + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + // TODO Auto-generated method stub + return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + // TODO Auto-generated method stub + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + return false; + } + + @Override + public void onExplosion() { + // TODO Auto-generated method stub + super.onExplosion(); + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 1) { + GT_Utility.doSoundAtClient( + (String) GregTech_API.sSoundList.get(Integer.valueOf(212)), 10, 1.0F, aX, aY, aZ); + } + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorColdTrap.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorColdTrap.java index f7acc3390d..f9ecc4be18 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorColdTrap.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorColdTrap.java @@ -14,59 +14,58 @@ import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_ReactorColdTrap extends GT_MetaTileEntity_BasicMachine { - public GregtechMetaTileEntity_ReactorColdTrap(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, - "Just like the Arctic", 2, 9, "Dehydrator.png", "", - new ITexture[]{ - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_SIDE_ACTIVE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_SIDE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_FRONT_ACTIVE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_FRONT), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP_ACTIVE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP_ACTIVE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP) - } - ); - } + public GregtechMetaTileEntity_ReactorColdTrap(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, "Just like the Arctic", 2, 9, "Dehydrator.png", "", new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_SIDE_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_SIDE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_FRONT_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_FRONT), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP) + }); + } - public GregtechMetaTileEntity_ReactorColdTrap(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 2, 9, aGUIName, aNEIName); - } + public GregtechMetaTileEntity_ReactorColdTrap( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 2, 9, aGUIName, aNEIName); + } - @Override - public String[] getDescription() { - return new String[]{this.mDescription, "Does not require ice cubes", CORE.GT_Tooltip}; - } + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "Does not require ice cubes", CORE.GT_Tooltip}; + } - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_ReactorColdTrap(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); - } + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_ReactorColdTrap( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } - @Override - public boolean allowSelectCircuit() { - return true; - } + @Override + public boolean allowSelectCircuit() { + return true; + } - @Override - public GT_Recipe.GT_Recipe_Map getRecipeList() { - return GTPP_Recipe.GTPP_Recipe_Map.sColdTrapRecipes; - } + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sColdTrapRecipes; + } - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (getRecipeList().containsInput(aStack)); - } + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) + && (getRecipeList().containsInput(aStack)); + } - @Override - public boolean isFluidInputAllowed(FluidStack aFluid) { - return super.isFluidInputAllowed(aFluid); - } - - @Override - public int getCapacity() { - return 16000 * Math.max(1, this.mTier); - } + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return super.isFluidInputAllowed(aFluid); + } + @Override + public int getCapacity() { + return 16000 * Math.max(1, this.mTier); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorProcessingUnit.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorProcessingUnit.java index cfe86f37f5..8f8711a7fe 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorProcessingUnit.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorProcessingUnit.java @@ -14,59 +14,69 @@ import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_ReactorProcessingUnit extends GT_MetaTileEntity_BasicMachine { - public GregtechMetaTileEntity_ReactorProcessingUnit(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, - "Processes Nuclear things", 2, 9, "Dehydrator.png", "", - new ITexture[]{ - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_SIDE_ACTIVE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_SIDE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_FRONT_ACTIVE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_FRONT), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP_ACTIVE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP_ACTIVE), - new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP) - } - ); - } + public GregtechMetaTileEntity_ReactorProcessingUnit(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 1, + "Processes Nuclear things", + 2, + 9, + "Dehydrator.png", + "", + new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_SIDE_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_SIDE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_FRONT_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_FRONT), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP) + }); + } - public GregtechMetaTileEntity_ReactorProcessingUnit(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, 1, aDescription, aTextures, 2, 9, aGUIName, aNEIName); - } + public GregtechMetaTileEntity_ReactorProcessingUnit( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 2, 9, aGUIName, aNEIName); + } - @Override - public String[] getDescription() { - return new String[]{this.mDescription, CORE.GT_Tooltip}; - } + @Override + public String[] getDescription() { + return new String[] {this.mDescription, CORE.GT_Tooltip}; + } - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_ReactorProcessingUnit(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); - } + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_ReactorProcessingUnit( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } - @Override - public boolean allowSelectCircuit() { - return true; - } + @Override + public boolean allowSelectCircuit() { + return true; + } - @Override - public GT_Recipe.GT_Recipe_Map getRecipeList() { - return GTPP_Recipe.GTPP_Recipe_Map.sReactorProcessingUnitRecipes; - } + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sReactorProcessingUnitRecipes; + } - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (getRecipeList().containsInput(aStack)); - } + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) + && (getRecipeList().containsInput(aStack)); + } - @Override - public boolean isFluidInputAllowed(FluidStack aFluid) { - return super.isFluidInputAllowed(aFluid); - } - - @Override - public int getCapacity() { - return 8000 * Math.max(1, this.mTier); - } + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return super.isFluidInputAllowed(aFluid); + } + @Override + public int getCapacity() { + return 8000 * Math.max(1, this.mTier); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java index 13da9cd868..db74a46f1b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; -import java.util.*; - import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -17,6 +15,7 @@ import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.helpers.ChargingHelper; +import java.util.*; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -25,569 +24,683 @@ import net.minecraft.nbt.NBTTagCompound; public class GregtechMetaWirelessCharger extends GregtechMetaTileEntity { - private boolean mHasBeenMapped = false; - private int mCurrentDimension = 0; - public int mMode = 0; - public boolean mLocked = true; - - public GregtechMetaWirelessCharger(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); - } - - public GregtechMetaWirelessCharger(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { - super(aName, aTier, aSlotCount, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[] {this.mDescription, - "Can be locked to the owner by sneaking with a screwdriver", - "Can also be locked with a lock upgrade", - "", - "3 Modes, Long-Range, Local and Mixed.", - "Long-Range: Can supply 2A of power to a single player up to "+(GT_Values.V[this.mTier]*4)+"m away.", - "Local: Can supply several Amps to each player within "+this.mTier*20+"m.", - "Mixed: Provides both 2A of long range and 1A per player locally.", - "Mixed mode is more conservative of power and as a result only", - "Gets half the distances each singular mode gets.", - CORE.GT_Tooltip - }; - } - - public int getTier(){ - return this.mTier; - } - - public int getMode(){ - return this.mMode; - } - - public int getDimensionID(){ - return this.mCurrentDimension; - } - - public Map<String, UUID> getLocalMap(){ - return this.mLocalChargingMap; - } - - public Map<String, UUID> getLongRangeMap(){ - return this.mWirelessChargingMap; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; - } - - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; - } - - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - - if (aPlayer.isSneaking()) { - mLocked = !mLocked; - PlayerUtils.messagePlayer(aPlayer, mLocked ? "Locked to owner." : "Unlocked."); - return; - } - - mWirelessChargingMap.clear(); - mLocalChargingMap.clear(); - if (!this.getBaseMetaTileEntity().getWorld().playerEntities.isEmpty()){ - for (Object mTempPlayer : this.getBaseMetaTileEntity().getWorld().playerEntities){ - if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP){ - EntityPlayer mTemp = (EntityPlayer) mTempPlayer; - ChargingHelper.removeValidPlayer(mTemp, this); - } - } - } - - if (this.mMode >= 2){ - this.mMode = 0; - } - else { - this.mMode++; - } - if (this.mMode == 0){ - PlayerUtils.messagePlayer(aPlayer, "Now in Long-Range Charge Mode."); - } - else if (this.mMode == 1){ - PlayerUtils.messagePlayer(aPlayer, "Now in Local Charge Mode."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Now in Mixed Charge Mode."); - } - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaWirelessCharger(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); - } - - @Override public boolean isSimpleMachine() {return false;} - @Override public boolean isElectric() {return true;} - @Override public boolean isValidSlot(final int aIndex) {return true;} - @Override public boolean isFacingValid(final byte aFacing) {return true;} - @Override public boolean isEnetInput() {return true;} - @Override public boolean isEnetOutput() {return false;} - @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isTeleporterCompatible() {return false;} - @Override public long getMinimumStoredEU() {return 0;} - @Override public long maxEUStore() {return GT_Values.V[this.mTier]*128;} - - @Override - public int getCapacity() { - return (int) (GT_Values.V[this.mTier]*32); - } - - @Override - public long maxEUInput() { - return GT_Values.V[this.mTier]; - } - - @Override - public long maxEUOutput() { - return 0; - } - - @Override - public long maxAmperesIn() { - if (this.mMode == 0){ - return 2; - } - else if (this.mMode == 1){ - return this.mLocalChargingMap.size()*8; - } - else { - return ((this.mLocalChargingMap.size()*4)+this.mWirelessChargingMap.size()); - } - } - - @Override - public long maxAmperesOut() { - return 0; - } - @Override public int rechargerSlotStartIndex() {return 0;} - @Override public int dechargerSlotStartIndex() {return 0;} - @Override public int rechargerSlotCount() {return 0;} - @Override public int dechargerSlotCount() {return 0;} - @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} - @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} - @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) - { - return true; - } - return true; - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public String[] getInfoData() { - return new String[] { - this.getLocalName()}; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { - return new int[] {}; - } - - @Override - public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { - return false; - } - - @Override - public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { - return false; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(final int p_70301_1_) { - return null; - } - - @Override - public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { - return null; - } - - @Override - public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { - } - - @Override - public String getInventoryName() { - return null; - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - @Override - public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { - return false; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { - return false; - } - - @Override - public boolean isOverclockerUpgradable() { - return false; - } - - @Override - public boolean isTransformerUpgradable() { - return false; - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setBoolean("mLocked", this.mLocked); - aNBT.setInteger("mMode", this.mMode); - aNBT.setInteger("mCurrentDimension", this.mCurrentDimension); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.mLocked = aNBT.getBoolean("mLocked"); - this.mMode = aNBT.getInteger("mMode"); - this.mCurrentDimension = aNBT.getInteger("mCurrentDimension"); - } - - @Override - public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - } - - private Map<String, UUID> mWirelessChargingMap = new HashMap<String, UUID>(); - private Map<String, UUID> mLocalChargingMap = new HashMap<String, UUID>(); - - private boolean isValidPlayer(EntityPlayer aPlayer) { - BaseMetaTileEntity aTile = (BaseMetaTileEntity) this.getBaseMetaTileEntity(); - if (mLocked || ( aTile != null && aTile.privateAccess())) { - if (aPlayer.getUniqueID().equals(getBaseMetaTileEntity().getOwnerUuid())){ - return true; - } - else { - return false; - } - } - return true; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (this.getBaseMetaTileEntity().isServerSide()) { - - if (this.mCurrentDimension != aBaseMetaTileEntity.getWorld().provider.dimensionId){ - this.mCurrentDimension = aBaseMetaTileEntity.getWorld().provider.dimensionId; - } - - if (!mHasBeenMapped && ChargingHelper.addEntry(getTileEntityPosition(), this)){ - mHasBeenMapped = true; - } - - if (aTick % 20 == 0 && mHasBeenMapped){ - if (!aBaseMetaTileEntity.getWorld().playerEntities.isEmpty()){ - for (Object mTempPlayer : aBaseMetaTileEntity.getWorld().playerEntities){ - if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP){ - EntityPlayer mTemp = (EntityPlayer) mTempPlayer; - - if (this.mMode == 1 || this.mMode == 2){ - int tempRange = (this.mMode == 1 ? this.mTier*20 : this.mTier*10); - if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) < tempRange){ - if (isValidPlayer(mTemp) && !mLocalChargingMap.containsKey(mTemp.getDisplayName())){ - mLocalChargingMap.put(mTemp.getDisplayName(), mTemp.getPersistentID()); - ChargingHelper.addValidPlayer(mTemp, this); - //PlayerUtils.messagePlayer(mTemp, "You have entered charging range. ["+tempRange+"m - Local]."); - } - } - else { - if (mLocalChargingMap.containsKey(mTemp.getDisplayName())){ - if (mLocalChargingMap.remove(mTemp.getDisplayName()) != null){ - //PlayerUtils.messagePlayer(mTemp, "You have left charging range. ["+tempRange+"m - Local]."); - ChargingHelper.removeValidPlayer(mTemp, this); - } - } - } - } - if (this.mMode == 0 || this.mMode == 2){ - int tempRange = (int) (this.mMode == 0 ? 4*GT_Values.V[this.mTier] : 2*GT_Values.V[this.mTier]); - if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) <= tempRange){ - if (!mWirelessChargingMap.containsKey(mTemp.getDisplayName())){ - if (isValidPlayer(mTemp)) { - mWirelessChargingMap.put(mTemp.getDisplayName(), mTemp.getPersistentID()); - ChargingHelper.addValidPlayer(mTemp, this); - PlayerUtils.messagePlayer(mTemp, "You have entered charging range. ["+tempRange+"m - Long-Range]."); - } - } - } - else { - if (mWirelessChargingMap.containsKey(mTemp.getDisplayName())){ - if (mWirelessChargingMap.remove(mTemp.getDisplayName()) != null){ - PlayerUtils.messagePlayer(mTemp, "You have left charging range. ["+tempRange+"m - Long Range]."); - ChargingHelper.removeValidPlayer(mTemp, this); - } - } - } - } - /*if (this.mMode == 0 || this.mMode == 2){ - int tempRange = (int) (this.mMode == 0 ? 4*GT_Values.V[this.mTier] : 2*GT_Values.V[this.mTier]); - if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) < tempRange){ - if (!mWirelessChargingMap.containsKey(mTemp)){ - mWirelessChargingMap.put(mTemp, mTemp.getPersistentID()); - PlayerUtils.messagePlayer(mTemp, "You have entered charging range. ["+tempRange+"m]."); - ChargingHelper.addValidPlayer(mTemp, this); - } - } - else { - if (mWirelessChargingMap.containsKey(mTemp)){ - if (mWirelessChargingMap.remove(mTemp) != null){ - PlayerUtils.messagePlayer(mTemp, "You have left charging range. ["+tempRange+"m]."); - ChargingHelper.removeValidPlayer(mTemp, this); - } - } - } - } */ - - } - } - } - } - - - } - } - - public BlockPos getTileEntityPosition(){ - return new BlockPos(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord(), this.getBaseMetaTileEntity().getWorld()); - } - - public BlockPos getPositionOfEntity(Entity mEntity){ - if (mEntity == null){ - return null; - } - return EntityUtils.findBlockPosUnderEntity(mEntity); - } - - public double getDistanceBetweenTwoPositions(BlockPos objectA, BlockPos objectB){ - if (objectA == null || objectB == null){ - return 0f; - } - int[] objectArray1 = new int[]{objectA.xPos, objectA.yPos, objectA.zPos}; - int[] objectArray2 = new int[]{objectB.xPos, objectB.yPos, objectB.zPos}; - - final double distance = Math.sqrt( - (objectArray2[0]-objectArray1[0])*(objectArray2[0]-objectArray1[0]) - +(objectArray2[1]-objectArray1[1])*(objectArray2[1]-objectArray1[1]) - +(objectArray2[2]-objectArray1[2])*(objectArray2[2]-objectArray1[2])); - return distance; - } - - @Override - public void onRemoval() { - - ChargingHelper.removeEntry(getTileEntityPosition(), this); - - mWirelessChargingMap.clear(); - mLocalChargingMap.clear(); - if (!this.getBaseMetaTileEntity().getWorld().playerEntities.isEmpty()){ - for (Object mTempPlayer : this.getBaseMetaTileEntity().getWorld().playerEntities){ - if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP){ - EntityPlayer mTemp = (EntityPlayer) mTempPlayer; - ChargingHelper.removeValidPlayer(mTemp, this); - } - } - } - - - super.onRemoval(); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, - EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { - - int tempRange; - - if (this.mMode == 0 || this.mMode == 2){ - tempRange = (int) (this.mMode == 0 ? 4*GT_Values.V[this.mTier] : 2*GT_Values.V[this.mTier]); - } - else { - tempRange = this.mMode == 1 ? this.mTier*20 : this.mTier*10; - } - - if (this.mMode == 2){ - PlayerUtils.messagePlayer(aPlayer, "Mixed Mode | Local: "+this.mTier*10+"m | Long: "+tempRange+"m"); - PlayerUtils.messagePlayer(aPlayer, "Players with access:"); - for (String name : this.getLocalMap().keySet()) { - PlayerUtils.messagePlayer(aPlayer, "Local: "+name); - } - for (String name : this.getLongRangeMap().keySet()) { - PlayerUtils.messagePlayer(aPlayer, "Long: "+name); - } - } - else if (this.mMode == 1){ - PlayerUtils.messagePlayer(aPlayer, "Local Mode: "+this.mTier*20+"m"); - PlayerUtils.messagePlayer(aPlayer, "Players with access:"); - for (String name : this.getLocalMap().keySet()) { - PlayerUtils.messagePlayer(aPlayer, ""+name); - } - - } - else { - PlayerUtils.messagePlayer(aPlayer, "Long-range Mode: "+tempRange+"m"); - PlayerUtils.messagePlayer(aPlayer, "Players with access:"); - for (String name : this.getLongRangeMap().keySet()) { - PlayerUtils.messagePlayer(aPlayer, ""+name); - } - } - - return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); - } - - @Override - public void onServerStart() { - mWirelessChargingMap.clear(); - mLocalChargingMap.clear(); - super.onServerStart(); - } - - @Override - public void onExplosion() { - ChargingHelper.removeEntry(getTileEntityPosition(), this); - super.onExplosion(); - } - - @Override - public void doExplosion(long aExplosionPower) { - ChargingHelper.removeEntry(getTileEntityPosition(), this); - super.doExplosion(aExplosionPower); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (!mHasBeenMapped && ChargingHelper.addEntry(getTileEntityPosition(), this)){ - mHasBeenMapped = true; - } - } - super.onPreTick(aBaseMetaTileEntity, aTick); - } - -}
\ No newline at end of file + private boolean mHasBeenMapped = false; + private int mCurrentDimension = 0; + public int mMode = 0; + public boolean mLocked = true; + + public GregtechMetaWirelessCharger( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaWirelessCharger( + final String aName, + final int aTier, + final String aDescription, + final ITexture[][][] aTextures, + final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Can be locked to the owner by sneaking with a screwdriver", + "Can also be locked with a lock upgrade", + "", + "3 Modes, Long-Range, Local and Mixed.", + "Long-Range: Can supply 2A of power to a single player up to " + (GT_Values.V[this.mTier] * 4) + "m away.", + "Local: Can supply several Amps to each player within " + this.mTier * 20 + "m.", + "Mixed: Provides both 2A of long range and 1A per player locally.", + "Mixed mode is more conservative of power and as a result only", + "Gets half the distances each singular mode gets.", + CORE.GT_Tooltip + }; + } + + public int getTier() { + return this.mTier; + } + + public int getMode() { + return this.mMode; + } + + public int getDimensionID() { + return this.mCurrentDimension; + } + + public Map<String, UUID> getLocalMap() { + return this.mLocalChargingMap; + } + + public Map<String, UUID> getLongRangeMap() { + return this.mWirelessChargingMap; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) + }; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + + if (aPlayer.isSneaking()) { + mLocked = !mLocked; + PlayerUtils.messagePlayer(aPlayer, mLocked ? "Locked to owner." : "Unlocked."); + return; + } + + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + if (!this.getBaseMetaTileEntity().getWorld().playerEntities.isEmpty()) { + for (Object mTempPlayer : this.getBaseMetaTileEntity().getWorld().playerEntities) { + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP) { + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + + if (this.mMode >= 2) { + this.mMode = 0; + } else { + this.mMode++; + } + if (this.mMode == 0) { + PlayerUtils.messagePlayer(aPlayer, "Now in Long-Range Charge Mode."); + } else if (this.mMode == 1) { + PlayerUtils.messagePlayer(aPlayer, "Now in Local Charge Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Now in Mixed Charge Mode."); + } + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaWirelessCharger( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return GT_Values.V[this.mTier] * 128; + } + + @Override + public int getCapacity() { + return (int) (GT_Values.V[this.mTier] * 32); + } + + @Override + public long maxEUInput() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + if (this.mMode == 0) { + return 2; + } else if (this.mMode == 1) { + return this.mLocalChargingMap.size() * 8; + } else { + return ((this.mLocalChargingMap.size() * 4) + this.mWirelessChargingMap.size()); + } + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + return true; + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + return new String[] {this.getLocalName()}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setBoolean("mLocked", this.mLocked); + aNBT.setInteger("mMode", this.mMode); + aNBT.setInteger("mCurrentDimension", this.mCurrentDimension); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mLocked = aNBT.getBoolean("mLocked"); + this.mMode = aNBT.getInteger("mMode"); + this.mCurrentDimension = aNBT.getInteger("mCurrentDimension"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + private Map<String, UUID> mWirelessChargingMap = new HashMap<String, UUID>(); + private Map<String, UUID> mLocalChargingMap = new HashMap<String, UUID>(); + + private boolean isValidPlayer(EntityPlayer aPlayer) { + BaseMetaTileEntity aTile = (BaseMetaTileEntity) this.getBaseMetaTileEntity(); + if (mLocked || (aTile != null && aTile.privateAccess())) { + if (aPlayer.getUniqueID().equals(getBaseMetaTileEntity().getOwnerUuid())) { + return true; + } else { + return false; + } + } + return true; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.getBaseMetaTileEntity().isServerSide()) { + + if (this.mCurrentDimension != aBaseMetaTileEntity.getWorld().provider.dimensionId) { + this.mCurrentDimension = aBaseMetaTileEntity.getWorld().provider.dimensionId; + } + + if (!mHasBeenMapped && ChargingHelper.addEntry(getTileEntityPosition(), this)) { + mHasBeenMapped = true; + } + + if (aTick % 20 == 0 && mHasBeenMapped) { + if (!aBaseMetaTileEntity.getWorld().playerEntities.isEmpty()) { + for (Object mTempPlayer : aBaseMetaTileEntity.getWorld().playerEntities) { + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP) { + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + + if (this.mMode == 1 || this.mMode == 2) { + int tempRange = (this.mMode == 1 ? this.mTier * 20 : this.mTier * 10); + if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) + < tempRange) { + if (isValidPlayer(mTemp) + && !mLocalChargingMap.containsKey(mTemp.getDisplayName())) { + mLocalChargingMap.put(mTemp.getDisplayName(), mTemp.getPersistentID()); + ChargingHelper.addValidPlayer(mTemp, this); + // PlayerUtils.messagePlayer(mTemp, "You have entered charging range. + // ["+tempRange+"m - Local]."); + } + } else { + if (mLocalChargingMap.containsKey(mTemp.getDisplayName())) { + if (mLocalChargingMap.remove(mTemp.getDisplayName()) != null) { + // PlayerUtils.messagePlayer(mTemp, "You have left charging range. + // ["+tempRange+"m - Local]."); + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + } + if (this.mMode == 0 || this.mMode == 2) { + int tempRange = (int) + (this.mMode == 0 ? 4 * GT_Values.V[this.mTier] : 2 * GT_Values.V[this.mTier]); + if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) + <= tempRange) { + if (!mWirelessChargingMap.containsKey(mTemp.getDisplayName())) { + if (isValidPlayer(mTemp)) { + mWirelessChargingMap.put(mTemp.getDisplayName(), mTemp.getPersistentID()); + ChargingHelper.addValidPlayer(mTemp, this); + PlayerUtils.messagePlayer( + mTemp, + "You have entered charging range. [" + tempRange + + "m - Long-Range]."); + } + } + } else { + if (mWirelessChargingMap.containsKey(mTemp.getDisplayName())) { + if (mWirelessChargingMap.remove(mTemp.getDisplayName()) != null) { + PlayerUtils.messagePlayer( + mTemp, + "You have left charging range. [" + tempRange + "m - Long Range]."); + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + } + /*if (this.mMode == 0 || this.mMode == 2){ + int tempRange = (int) (this.mMode == 0 ? 4*GT_Values.V[this.mTier] : 2*GT_Values.V[this.mTier]); + if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) < tempRange){ + if (!mWirelessChargingMap.containsKey(mTemp)){ + mWirelessChargingMap.put(mTemp, mTemp.getPersistentID()); + PlayerUtils.messagePlayer(mTemp, "You have entered charging range. ["+tempRange+"m]."); + ChargingHelper.addValidPlayer(mTemp, this); + } + } + else { + if (mWirelessChargingMap.containsKey(mTemp)){ + if (mWirelessChargingMap.remove(mTemp) != null){ + PlayerUtils.messagePlayer(mTemp, "You have left charging range. ["+tempRange+"m]."); + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + } */ + + } + } + } + } + } + } + + public BlockPos getTileEntityPosition() { + return new BlockPos( + this.getBaseMetaTileEntity().getXCoord(), + this.getBaseMetaTileEntity().getYCoord(), + this.getBaseMetaTileEntity().getZCoord(), + this.getBaseMetaTileEntity().getWorld()); + } + + public BlockPos getPositionOfEntity(Entity mEntity) { + if (mEntity == null) { + return null; + } + return EntityUtils.findBlockPosUnderEntity(mEntity); + } + + public double getDistanceBetweenTwoPositions(BlockPos objectA, BlockPos objectB) { + if (objectA == null || objectB == null) { + return 0f; + } + int[] objectArray1 = new int[] {objectA.xPos, objectA.yPos, objectA.zPos}; + int[] objectArray2 = new int[] {objectB.xPos, objectB.yPos, objectB.zPos}; + + final double distance = Math.sqrt((objectArray2[0] - objectArray1[0]) * (objectArray2[0] - objectArray1[0]) + + (objectArray2[1] - objectArray1[1]) * (objectArray2[1] - objectArray1[1]) + + (objectArray2[2] - objectArray1[2]) * (objectArray2[2] - objectArray1[2])); + return distance; + } + + @Override + public void onRemoval() { + + ChargingHelper.removeEntry(getTileEntityPosition(), this); + + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + if (!this.getBaseMetaTileEntity().getWorld().playerEntities.isEmpty()) { + for (Object mTempPlayer : this.getBaseMetaTileEntity().getWorld().playerEntities) { + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP) { + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + + super.onRemoval(); + } + + @Override + public boolean onRightclick( + IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + + int tempRange; + + if (this.mMode == 0 || this.mMode == 2) { + tempRange = (int) (this.mMode == 0 ? 4 * GT_Values.V[this.mTier] : 2 * GT_Values.V[this.mTier]); + } else { + tempRange = this.mMode == 1 ? this.mTier * 20 : this.mTier * 10; + } + + if (this.mMode == 2) { + PlayerUtils.messagePlayer( + aPlayer, "Mixed Mode | Local: " + this.mTier * 10 + "m | Long: " + tempRange + "m"); + PlayerUtils.messagePlayer(aPlayer, "Players with access:"); + for (String name : this.getLocalMap().keySet()) { + PlayerUtils.messagePlayer(aPlayer, "Local: " + name); + } + for (String name : this.getLongRangeMap().keySet()) { + PlayerUtils.messagePlayer(aPlayer, "Long: " + name); + } + } else if (this.mMode == 1) { + PlayerUtils.messagePlayer(aPlayer, "Local Mode: " + this.mTier * 20 + "m"); + PlayerUtils.messagePlayer(aPlayer, "Players with access:"); + for (String name : this.getLocalMap().keySet()) { + PlayerUtils.messagePlayer(aPlayer, "" + name); + } + + } else { + PlayerUtils.messagePlayer(aPlayer, "Long-range Mode: " + tempRange + "m"); + PlayerUtils.messagePlayer(aPlayer, "Players with access:"); + for (String name : this.getLongRangeMap().keySet()) { + PlayerUtils.messagePlayer(aPlayer, "" + name); + } + } + + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + + @Override + public void onServerStart() { + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + super.onServerStart(); + } + + @Override + public void onExplosion() { + ChargingHelper.removeEntry(getTileEntityPosition(), this); + super.onExplosion(); + } + + @Override + public void doExplosion(long aExplosionPower) { + ChargingHelper.removeEntry(getTileEntityPosition(), this); + super.doExplosion(aExplosionPower); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (!mHasBeenMapped && ChargingHelper.addEntry(getTileEntityPosition(), this)) { + mHasBeenMapped = true; + } + } + super.onPreTick(aBaseMetaTileEntity, aTick); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java index 89b26eddc7..01cc1ab213 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java @@ -1,7 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.misc; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -25,568 +29,594 @@ import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GMTE_AmazonPackager extends GregtechMeta_MultiBlockBase<GMTE_AmazonPackager> implements ISurvivalConstructable { - - private long mVoltage; - private byte mTier; - private int mCasing; - - private ItemStack mSchematicCache;; - private ItemStack mInputCache; - private ItemStack mOutputCache; - private GT_Recipe mCachedRecipe; - - private IStructureDefinition<GMTE_AmazonPackager> STRUCTURE_DEFINITION = null; - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GMTE_AmazonPackager(mName); - } - - public GMTE_AmazonPackager(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GMTE_AmazonPackager(String aName) { - super(aName); - } - - @Override - public String getMachineType() { - return "Packager"; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "Generic3By3"; - } - - @Override - public IStructureDefinition<GMTE_AmazonPackager> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GMTE_AmazonPackager>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GMTE_AmazonPackager.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(TAE.getIndexFromPage(2, 9)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 9))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Amazon Warehouse") - .addInfo("This Multiblock is used for EXTREME packaging requirements") - .addInfo("Dust Schematics are inserted into the input busses") - .addInfo("If inserted into the controller, it is shared across all busses") - .addInfo("1x, 2x, 3x & Other Schematics are to be placed into the controller GUI slot") - .addInfo("500% faster than using single block machines of the same voltage") - .addInfo("Only uses 75% of the EU/t normally required") - .addInfo("Processes 16 items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front center") - .addCasingInfo("Supply Depot Casings", 10) - .addInputBus("Any casing", 1) - .addOutputBus("Any casing", 1) - .addEnergyHatch("Any casing", 1) - .addMaintenanceHatch("Any casing", 1) - .addMufflerHatch("Any casing", 1) - .toolTipFinisher("GT++"); - return tt; - } - - private final void initFields() { - mVoltage = getMaxInputVoltage(); - mTier = (byte) Math.max(1, GT_Utility.getTier(mVoltage)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return TAE.getIndexFromPage(2, 9); - } - - - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes; - } - - private static final FluidStack[] sNoFluids = new FluidStack[] {}; - - @Override - public boolean checkRecipe(ItemStack aStack) { - - //Just the best place to check this~ - initFields(); - - ArrayList<ItemStack> tItems = getStoredInputs(); - if (this.getGUIItemStack() != null) { - tItems.add(this.getGUIItemStack()); - } - ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); - boolean state = checkRecipeGeneric(tItemInputs, sNoFluids, getMaxParallelRecipes(), 75, 500, 10000); - - - if (state) { - return true; - } - else { - tItems = getStoredInputs(); - AutoMap<ItemStackData> mCompleted = new AutoMap<ItemStackData>(); - AutoMap<ItemStackData> mSchematics = new AutoMap<ItemStackData>(); - for (ItemStack tInputItem : tItems) { - if (tInputItem != null) { - if (ItemList.Schematic_1by1.isStackEqual((Object) tInputItem) || ItemList.Schematic_2by2.isStackEqual((Object) tInputItem) || ItemList.Schematic_3by3.isStackEqual((Object) tInputItem)) { - mSchematics.put(new ItemStackData(tInputItem)); - } - } - } - if (mSchematics.size() > 0) { - for (ItemStackData g : mSchematics) { - for (ItemStack tInputItem : tItems) { - if (tInputItem != null) { - mCompleted.put(new ItemStackData(tInputItem)); - checkRecipe(tInputItem, g.getStack()); - } - } - } - } - - return mCompleted != null && mCompleted.size() > 0; - } - } - - public boolean checkRecipe(ItemStack inputStack, ItemStack schematicStack) { - if (GT_Utility.isStackValid((Object) inputStack) && GT_Utility.isStackValid((Object) schematicStack) - && GT_Utility.getContainerItem(inputStack, true) == null) { - ItemStack tOutputStack; - if (ItemList.Schematic_1by1.isStackEqual((Object) schematicStack)&& inputStack.stackSize >= 1) { - tOutputStack = GT_ModHandler.getRecipeOutput(new ItemStack[]{inputStack}); - if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { - final ItemStack input = inputStack; - --input.stackSize; - this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); - //this.mMaxProgresstime = 16 / (1 << this.mTier - 1); - this.mMaxProgresstime = 2; - this.addOutput(tOutputStack); - updateSlots(); - return true; - } - return false; - } else if (ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) - && inputStack.stackSize >= 4) { - tOutputStack = GT_ModHandler.getRecipeOutput(new ItemStack[]{inputStack, - inputStack, null, inputStack, inputStack}); - if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { - final ItemStack input2 = inputStack; - input2.stackSize -= 4; - this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); - //this.mMaxProgresstime = 32 / (1 << this.mTier - 1); - this.mMaxProgresstime = 4; - this.addOutput(tOutputStack); - updateSlots(); - return true; - } - return false; - } else if (ItemList.Schematic_3by3.isStackEqual((Object) schematicStack) - && inputStack.stackSize >= 9) { - tOutputStack = GT_ModHandler.getRecipeOutput(new ItemStack[]{inputStack, - inputStack, inputStack, inputStack, inputStack, - inputStack, inputStack, inputStack, inputStack}); - if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { - final ItemStack input3 = inputStack; - input3.stackSize -= 9; - this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); - //this.mMaxProgresstime = 64 / (1 << this.mTier - 1); - this.mMaxProgresstime = 6; - this.addOutput(tOutputStack); - updateSlots(); - return true; - } - return false; - } - } - return false; - } - - private ItemStack getSchematic(ItemStack[] aInputs) { - for (ItemStack aStack : aInputs) { - if (ItemList.Schematic_Dust.isStackEqual(aStack) || ItemList.Schematic_1by1.isStackEqual(aStack) || ItemList.Schematic_2by2.isStackEqual(aStack) || ItemList.Schematic_3by3.isStackEqual(aStack)) { - return aStack; - } - } - return null; - } - - private ItemStack getRecipeInput(ItemStack[] aInputs) { - for (ItemStack aStack : aInputs) { - if (!ItemList.Schematic_Dust.isStackEqual(aStack) && !ItemList.Schematic_1by1.isStackEqual(aStack) && !ItemList.Schematic_2by2.isStackEqual(aStack) && !ItemList.Schematic_3by3.isStackEqual(aStack)) { - return aStack; - } - } - return null; - } - - private boolean hasValidCache(ItemStack aStack, ItemStack aSchematic, boolean aClearOnFailure) { - if (mSchematicCache != null && mInputCache != null && mOutputCache != null && mCachedRecipe != null) { - if (GT_Utility.areStacksEqual(aStack, mInputCache) && GT_Utility.areStacksEqual(aSchematic, mSchematicCache)) { - return true; - } - } - // clear cache if it was invalid - if (aClearOnFailure) { - mSchematicCache = null; - mInputCache = null; - mOutputCache = null; - mCachedRecipe = null; - } - return false; - } - - private void cacheItem(ItemStack aSchematic, ItemStack aInputItem, ItemStack aOutputItem, GT_Recipe aRecipe) { - mSchematicCache = aSchematic.copy(); - mInputCache = aInputItem.copy(); - mOutputCache = aOutputItem.copy(); - mCachedRecipe = aRecipe; - } - - private GT_Recipe generatePackageRecipe(ItemStack aSchematic, ItemStack aInput) { - boolean tIsCached = hasValidCache(aInput, aSchematic, true); - if (tIsCached) { - ItemStack tOutput = mOutputCache.copy(); - if (tOutput != null) { - if (mCachedRecipe != null && GT_Utility.areStacksEqual(aInput, mInputCache) && GT_Utility.areStacksEqual(tOutput, mOutputCache)) { - int aRequiredInputSize = 0; - if (ItemList.Schematic_Dust.isStackEqual(aSchematic)) { - if (OrePrefixes.dustTiny.contains(aInput)) { - aRequiredInputSize = 9; - } - if (OrePrefixes.dustSmall.contains(aInput)) { - aRequiredInputSize = 4; - } - if (OrePrefixes.dust.contains(aInput)) { - aRequiredInputSize = 1; - } - } - if (ItemList.Schematic_1by1.isStackEqual(aSchematic)) { - aRequiredInputSize = 1; - } - if (ItemList.Schematic_2by2.isStackEqual(aSchematic)) { - aRequiredInputSize = 4; - } - if (ItemList.Schematic_3by3.isStackEqual(aSchematic)) { - aRequiredInputSize = 9; - } - if (aInput.stackSize >= aRequiredInputSize) { - log("Using Cached Recipe. Require: "+aRequiredInputSize+", Found: "+aInput.stackSize); - return mCachedRecipe; - } - else { - log("Not enough input"); - } - } - } - } - // We can package this - GT_Recipe aRecipe = lookupRecipe(); - log("Looking up new recipe"); - if (aRecipe != null) { - // Cache it - aInput = aInput != null ? aInput : getRecipeInput(aRecipe.mInputs); - cacheItem(aSchematic, aInput, aRecipe.mOutputs[0], aRecipe); - if (hasValidCache(aInput, aSchematic, false)) { - log("Caching Recipe"); - return aRecipe; - } - } - return null; - } - - private GT_Recipe lookupRecipe() { - ArrayList<ItemStack> aItems = getStoredInputs(); - if (this.getGUIItemStack() != null) { - aItems.add(this.getGUIItemStack()); - } - ItemStack[] aItemInputs = aItems.toArray(new ItemStack[aItems.size()]); - GT_Recipe tRecipe = findRecipe( - getBaseMetaTileEntity(), mLastRecipe, false, false, - gregtech.api.enums.GT_Values.V[mTier], sNoFluids, aItemInputs); - - if (tRecipe != null) { - return tRecipe; - } - return null; - } - - @Override - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - ItemStack aInput = getRecipeInput(aItemInputs); - ItemStack aSchematic = getSchematic(aItemInputs); - GT_Recipe tRecipe = generatePackageRecipe(aSchematic, aInput); - - ItemStack[] aRealInputs = new ItemStack[] {aSchematic, aInput}; - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - if (tRecipe == null) { - log("BAD RETURN - 1"); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+aMaxParallelRecipes); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, sNoFluids, aItemInputs)) { - log("Broke at "+parallelRecipes+"."); - break; - } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - mCachedRecipe = null; - log("BAD RETURN - 3 - Reset Cached Recipe"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - if (this.hasPerfectOverclock()) this.mMaxProgresstime /= 4; - else this.mMaxProgresstime /= 2; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - log("GOOD RETURN - 1"); - return true; - } - - public boolean allowPutStack(final ItemStack aStack, ItemStack schematicStack) { - //If Schematic Static is not 1x1, 2x2, 3x3 - if (!ItemList.Schematic_1by1.isStackEqual((Object) schematicStack) && !ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) && !ItemList.Schematic_3by3.isStackEqual((Object) schematicStack)) { - return GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.containsInput(aStack); - } - //Something - if (GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.findRecipe((IHasWorldObjectAndCoords) this.getBaseMetaTileEntity(), true, GT_Values.V[this.mTier], - (FluidStack[]) null, new ItemStack[]{GT_Utility.copyAmount(64L, new Object[]{aStack}), schematicStack}) != null) { - return true; - } - //1x1 - if (ItemList.Schematic_1by1.isStackEqual((Object) schematicStack) - && GT_ModHandler.getRecipeOutput(new ItemStack[]{aStack}) != null) { - return true; - } - //2x2 - if (ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) - && GT_ModHandler.getRecipeOutput(new ItemStack[]{aStack, aStack, null, aStack, aStack}) != null) { - return true; - } - //3x3 - if (ItemList.Schematic_3by3.isStackEqual((Object) schematicStack) && GT_ModHandler.getRecipeOutput( - new ItemStack[]{aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack}) != null) { - return true; - } - return false; - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - @Override - public int getMaxEfficiency(ItemStack p0) { - return 10000; - } - - @Override - public int getPollutionPerSecond(ItemStack arg0){ - return CORE.ConfigSwitches.pollutionPerSecondMultiPackager; - } - - @Override - public int getMaxParallelRecipes() { - return (16 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } +public class GMTE_AmazonPackager extends GregtechMeta_MultiBlockBase<GMTE_AmazonPackager> + implements ISurvivalConstructable { + + private long mVoltage; + private byte mTier; + private int mCasing; + + private ItemStack mSchematicCache; + ; + private ItemStack mInputCache; + private ItemStack mOutputCache; + private GT_Recipe mCachedRecipe; + + private IStructureDefinition<GMTE_AmazonPackager> STRUCTURE_DEFINITION = null; + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GMTE_AmazonPackager(mName); + } + + public GMTE_AmazonPackager(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GMTE_AmazonPackager(String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Packager"; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "Generic3By3"; + } + + @Override + public IStructureDefinition<GMTE_AmazonPackager> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GMTE_AmazonPackager>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GMTE_AmazonPackager.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(TAE.getIndexFromPage(2, 9)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 9)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Amazon Warehouse") + .addInfo("This Multiblock is used for EXTREME packaging requirements") + .addInfo("Dust Schematics are inserted into the input busses") + .addInfo("If inserted into the controller, it is shared across all busses") + .addInfo("1x, 2x, 3x & Other Schematics are to be placed into the controller GUI slot") + .addInfo("500% faster than using single block machines of the same voltage") + .addInfo("Only uses 75% of the EU/t normally required") + .addInfo("Processes 16 items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Supply Depot Casings", 10) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher("GT++"); + return tt; + } + + private final void initFields() { + mVoltage = getMaxInputVoltage(); + mTier = (byte) Math.max(1, GT_Utility.getTier(mVoltage)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(2, 9); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes; + } + + private static final FluidStack[] sNoFluids = new FluidStack[] {}; + + @Override + public boolean checkRecipe(ItemStack aStack) { + + // Just the best place to check this~ + initFields(); + + ArrayList<ItemStack> tItems = getStoredInputs(); + if (this.getGUIItemStack() != null) { + tItems.add(this.getGUIItemStack()); + } + ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); + boolean state = checkRecipeGeneric(tItemInputs, sNoFluids, getMaxParallelRecipes(), 75, 500, 10000); + + if (state) { + return true; + } else { + tItems = getStoredInputs(); + AutoMap<ItemStackData> mCompleted = new AutoMap<ItemStackData>(); + AutoMap<ItemStackData> mSchematics = new AutoMap<ItemStackData>(); + for (ItemStack tInputItem : tItems) { + if (tInputItem != null) { + if (ItemList.Schematic_1by1.isStackEqual((Object) tInputItem) + || ItemList.Schematic_2by2.isStackEqual((Object) tInputItem) + || ItemList.Schematic_3by3.isStackEqual((Object) tInputItem)) { + mSchematics.put(new ItemStackData(tInputItem)); + } + } + } + if (mSchematics.size() > 0) { + for (ItemStackData g : mSchematics) { + for (ItemStack tInputItem : tItems) { + if (tInputItem != null) { + mCompleted.put(new ItemStackData(tInputItem)); + checkRecipe(tInputItem, g.getStack()); + } + } + } + } + + return mCompleted != null && mCompleted.size() > 0; + } + } + + public boolean checkRecipe(ItemStack inputStack, ItemStack schematicStack) { + if (GT_Utility.isStackValid((Object) inputStack) + && GT_Utility.isStackValid((Object) schematicStack) + && GT_Utility.getContainerItem(inputStack, true) == null) { + ItemStack tOutputStack; + if (ItemList.Schematic_1by1.isStackEqual((Object) schematicStack) && inputStack.stackSize >= 1) { + tOutputStack = GT_ModHandler.getRecipeOutput(new ItemStack[] {inputStack}); + if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { + final ItemStack input = inputStack; + --input.stackSize; + this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + // this.mMaxProgresstime = 16 / (1 << this.mTier - 1); + this.mMaxProgresstime = 2; + this.addOutput(tOutputStack); + updateSlots(); + return true; + } + return false; + } else if (ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) && inputStack.stackSize >= 4) { + tOutputStack = GT_ModHandler.getRecipeOutput( + new ItemStack[] {inputStack, inputStack, null, inputStack, inputStack}); + if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { + final ItemStack input2 = inputStack; + input2.stackSize -= 4; + this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + // this.mMaxProgresstime = 32 / (1 << this.mTier - 1); + this.mMaxProgresstime = 4; + this.addOutput(tOutputStack); + updateSlots(); + return true; + } + return false; + } else if (ItemList.Schematic_3by3.isStackEqual((Object) schematicStack) && inputStack.stackSize >= 9) { + tOutputStack = GT_ModHandler.getRecipeOutput(new ItemStack[] { + inputStack, + inputStack, + inputStack, + inputStack, + inputStack, + inputStack, + inputStack, + inputStack, + inputStack + }); + if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { + final ItemStack input3 = inputStack; + input3.stackSize -= 9; + this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + // this.mMaxProgresstime = 64 / (1 << this.mTier - 1); + this.mMaxProgresstime = 6; + this.addOutput(tOutputStack); + updateSlots(); + return true; + } + return false; + } + } + return false; + } + + private ItemStack getSchematic(ItemStack[] aInputs) { + for (ItemStack aStack : aInputs) { + if (ItemList.Schematic_Dust.isStackEqual(aStack) + || ItemList.Schematic_1by1.isStackEqual(aStack) + || ItemList.Schematic_2by2.isStackEqual(aStack) + || ItemList.Schematic_3by3.isStackEqual(aStack)) { + return aStack; + } + } + return null; + } + + private ItemStack getRecipeInput(ItemStack[] aInputs) { + for (ItemStack aStack : aInputs) { + if (!ItemList.Schematic_Dust.isStackEqual(aStack) + && !ItemList.Schematic_1by1.isStackEqual(aStack) + && !ItemList.Schematic_2by2.isStackEqual(aStack) + && !ItemList.Schematic_3by3.isStackEqual(aStack)) { + return aStack; + } + } + return null; + } + + private boolean hasValidCache(ItemStack aStack, ItemStack aSchematic, boolean aClearOnFailure) { + if (mSchematicCache != null && mInputCache != null && mOutputCache != null && mCachedRecipe != null) { + if (GT_Utility.areStacksEqual(aStack, mInputCache) + && GT_Utility.areStacksEqual(aSchematic, mSchematicCache)) { + return true; + } + } + // clear cache if it was invalid + if (aClearOnFailure) { + mSchematicCache = null; + mInputCache = null; + mOutputCache = null; + mCachedRecipe = null; + } + return false; + } + + private void cacheItem(ItemStack aSchematic, ItemStack aInputItem, ItemStack aOutputItem, GT_Recipe aRecipe) { + mSchematicCache = aSchematic.copy(); + mInputCache = aInputItem.copy(); + mOutputCache = aOutputItem.copy(); + mCachedRecipe = aRecipe; + } + + private GT_Recipe generatePackageRecipe(ItemStack aSchematic, ItemStack aInput) { + boolean tIsCached = hasValidCache(aInput, aSchematic, true); + if (tIsCached) { + ItemStack tOutput = mOutputCache.copy(); + if (tOutput != null) { + if (mCachedRecipe != null + && GT_Utility.areStacksEqual(aInput, mInputCache) + && GT_Utility.areStacksEqual(tOutput, mOutputCache)) { + int aRequiredInputSize = 0; + if (ItemList.Schematic_Dust.isStackEqual(aSchematic)) { + if (OrePrefixes.dustTiny.contains(aInput)) { + aRequiredInputSize = 9; + } + if (OrePrefixes.dustSmall.contains(aInput)) { + aRequiredInputSize = 4; + } + if (OrePrefixes.dust.contains(aInput)) { + aRequiredInputSize = 1; + } + } + if (ItemList.Schematic_1by1.isStackEqual(aSchematic)) { + aRequiredInputSize = 1; + } + if (ItemList.Schematic_2by2.isStackEqual(aSchematic)) { + aRequiredInputSize = 4; + } + if (ItemList.Schematic_3by3.isStackEqual(aSchematic)) { + aRequiredInputSize = 9; + } + if (aInput.stackSize >= aRequiredInputSize) { + log("Using Cached Recipe. Require: " + aRequiredInputSize + ", Found: " + aInput.stackSize); + return mCachedRecipe; + } else { + log("Not enough input"); + } + } + } + } + // We can package this + GT_Recipe aRecipe = lookupRecipe(); + log("Looking up new recipe"); + if (aRecipe != null) { + // Cache it + aInput = aInput != null ? aInput : getRecipeInput(aRecipe.mInputs); + cacheItem(aSchematic, aInput, aRecipe.mOutputs[0], aRecipe); + if (hasValidCache(aInput, aSchematic, false)) { + log("Caching Recipe"); + return aRecipe; + } + } + return null; + } + + private GT_Recipe lookupRecipe() { + ArrayList<ItemStack> aItems = getStoredInputs(); + if (this.getGUIItemStack() != null) { + aItems.add(this.getGUIItemStack()); + } + ItemStack[] aItemInputs = aItems.toArray(new ItemStack[aItems.size()]); + GT_Recipe tRecipe = findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + false, + gregtech.api.enums.GT_Values.V[mTier], + sNoFluids, + aItemInputs); + + if (tRecipe != null) { + return tRecipe; + } + return null; + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + ItemStack aInput = getRecipeInput(aItemInputs); + ItemStack aSchematic = getSchematic(aItemInputs); + GT_Recipe tRecipe = generatePackageRecipe(aSchematic, aInput); + + ItemStack[] aRealInputs = new ItemStack[] {aSchematic, aInput}; + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + aMaxParallelRecipes); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, sNoFluids, aItemInputs)) { + log("Broke at " + parallelRecipes + "."); + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + mCachedRecipe = null; + log("BAD RETURN - 3 - Reset Cached Recipe"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + if (this.hasPerfectOverclock()) this.mMaxProgresstime /= 4; + else this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + public boolean allowPutStack(final ItemStack aStack, ItemStack schematicStack) { + // If Schematic Static is not 1x1, 2x2, 3x3 + if (!ItemList.Schematic_1by1.isStackEqual((Object) schematicStack) + && !ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) + && !ItemList.Schematic_3by3.isStackEqual((Object) schematicStack)) { + return GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.containsInput(aStack); + } + // Something + if (GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.findRecipe( + (IHasWorldObjectAndCoords) this.getBaseMetaTileEntity(), + true, + GT_Values.V[this.mTier], + (FluidStack[]) null, + new ItemStack[] {GT_Utility.copyAmount(64L, new Object[] {aStack}), schematicStack}) + != null) { + return true; + } + // 1x1 + if (ItemList.Schematic_1by1.isStackEqual((Object) schematicStack) + && GT_ModHandler.getRecipeOutput(new ItemStack[] {aStack}) != null) { + return true; + } + // 2x2 + if (ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) + && GT_ModHandler.getRecipeOutput(new ItemStack[] {aStack, aStack, null, aStack, aStack}) != null) { + return true; + } + // 3x3 + if (ItemList.Schematic_3by3.isStackEqual((Object) schematicStack) + && GT_ModHandler.getRecipeOutput( + new ItemStack[] {aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack + }) + != null) { + return true; + } + return false; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + public int getMaxEfficiency(ItemStack p0) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack arg0) { + return CORE.ConfigSwitches.pollutionPerSecondMultiPackager; + } + + @Override + public int getMaxParallelRecipes() { + return (16 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GregtechMTE_TeslaTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GregtechMTE_TeslaTower.java index 769499476c..8b8d12dbd5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GregtechMTE_TeslaTower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GregtechMTE_TeslaTower.java @@ -2,13 +2,7 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.misc; import static gregtech.api.enums.GT_Values.W; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - import com.gtnewhorizon.structurelib.structure.IStructureDefinition; - import gregtech.api.GregTech_API; import gregtech.api.enums.TAE; import gregtech.api.interfaces.IIconContainer; @@ -27,6 +21,10 @@ import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; @@ -39,467 +37,480 @@ import net.minecraftforge.common.util.ForgeDirection; public class GregtechMTE_TeslaTower extends GregtechMeta_MultiBlockBase<GregtechMTE_TeslaTower> { - private Block casingBlock; - private int casingMeta; - private int frameMeta; - private int casingTextureIndex; - - private ForgeDirection back; - - private int xLoc, yLoc, zLoc; - - protected int mRange; - - /** - * Machine Mode, - * {@value false} Attacks all entities, - * {@value true} Only attacks players. - */ - - protected volatile boolean mMode = false; - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMTE_TeslaTower(mName); - } - - public GregtechMTE_TeslaTower(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - initFields(); - } - - public GregtechMTE_TeslaTower(String aName) { - super(aName); - initFields(); - } - - @Override - public String getMachineType() { - return "Weaponized Lighting Rod"; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - /*@Override - public String[] getTooltip() { - String casings = getCasingBlockItem().get(0).getDisplayName(); - return new String[]{ - "Controller Block for the Tesla Defence Tower Mk3200", - "Enemies within "+this.mRange+"m are blasted with a high energy plasma.", - "This uses 5,000,000EU per blast.", - "Can screwdriver to toggle mode between Players and all Entities.", - "Size(WxHxD): 3x7x3", "Controller (Front middle at bottom)", - "3x1x3 Base of " + casings, - "1x3x1 " + casings + " pillar (Center of base)", - "1x3x1 " + MaterialUtils.getMaterialName(getFrameMaterial()) + " Frame Boxes (Each pillar side and on top)", - "1x Maintenance Hatch (One of base casings)", - "1x " + VN[getMinTier()] + "+ Energy Hatch (Any bottom layer casing)"}; - }*/ - - @Override - protected final GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Tesla Defence Tower Mk3200") - .addInfo("Enemies within "+this.mRange+"m are blasted with a high energy plasma.") - .addInfo("This uses 5,000,000EU per blast.") - .addInfo("Can screwdriver to toggle mode between Players and all Entities.") - .addSeparator() - .beginStructureBlock(1, 7, 1, false) - .addController("Top Middle") - .addCasingInfo("Casing", 360) - .addOtherStructurePart("Rotor Assembly", "Any 1 dot hint", 1) - .addInputBus("Any 4 dot hint (min 1)", 4) - .addInputHatch("Any 4 dot hint(min 1)", 4) - .addOutputHatch("Any 4 dot hint(min 1)", 4) - .addEnergyHatch("Any 4 dot hint(min 1)", 4) - .addMaintenanceHatch("Any 4 dot hint(min 1)", 4) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - private final void initFields() { - casingBlock = ModBlocks.blockCasings2Misc; - casingMeta = getCasingBlockItem().get(0).getItemDamage(); - casingTextureIndex = getCasingTextureIndex(); - mRange = 50; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return getCasingTextureIndex(); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("mMode", this.mMode); - aNBT.setInteger("mRange", this.mRange); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - this.mMode = aNBT.getBoolean("mMode"); - this.mRange = aNBT.getInteger("mRange"); - super.loadNBTData(aNBT); - } - - private boolean isEnergyEnough() { - if (this.getEUVar() >= 5000000){ - return true; - } - return false; - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - - if (!isEnergyEnough()) { - this.mProgresstime = 0; - this.mMaxProgresstime = 20; - this.getBaseMetaTileEntity().setActive(false); - stopMachine(); - } - else { - this.mProgresstime = 1; - this.mMaxProgresstime = 100; - this.getBaseMetaTileEntity().setActive(true); - - } - return false; - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - updateCoordinates(); - //check base layer - for (int xOff = -1 + back.offsetX; xOff <= 1 + back.offsetX; xOff++) { - for (int zOff = -1 + back.offsetZ; zOff <= 1 + back.offsetZ; zOff++) { - if (xOff == 0 && zOff == 0) continue; - - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xOff, 0, zOff); - if (!checkCasingBlock(xOff, 0, zOff) - && !addMaintenanceToMachineList(tTileEntity, casingTextureIndex) - && !addEnergyInputToMachineList(tTileEntity, casingTextureIndex)){ - Logger.INFO("bad block"); - return false; - } - } - } - if(!checkHatches()){ - Logger.INFO("bad Hatches"); - return false; - } - if (GT_Utility.getTier(getMaxInputVoltage()) < getMinTier()){ - Logger.INFO("bad Voltage"); - return false; - } - //check tower - for (int yOff = 1; yOff < 4; yOff++) { - if (!checkCasingBlock(back.offsetX, yOff, back.offsetZ) - || !checkFrameBlock(back.offsetX + 1, yOff, back.offsetZ) - || !checkFrameBlock(back.offsetX - 1, yOff, back.offsetZ) - || !checkFrameBlock(back.offsetX, yOff, back.offsetZ + 1) - || !checkFrameBlock(back.offsetX, yOff, back.offsetZ - 1) - || !checkFrameBlock(back.offsetX, yOff + 3, back.offsetZ)){ - Logger.INFO("bad frame?"); - return false; - } - } - Logger.INFO("good"); - return true; - } - - private void updateCoordinates() { - casingTextureIndex = getCasingTextureIndex(); - mRange = 50; - xLoc = getBaseMetaTileEntity().getXCoord(); - yLoc = getBaseMetaTileEntity().getYCoord(); - zLoc = getBaseMetaTileEntity().getZCoord(); - back = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()); - } - - protected boolean checkCasingBlock(int xOff, int yOff, int zOff) { - Logger.INFO("Looking For Casing."); - return checkBlockAndMetaOffset(xOff, yOff, zOff, casingBlock, casingMeta); - } - //meta of frame is getTileEntityBaseType; frame should be checked using its drops (possible a high weight operation) - protected boolean checkFrameBlock(int xOff, int yOff, int zOff) { - Logger.INFO("Looking For Frame."); - return checkBlockAndMetaOffset(xOff, yOff, zOff, GregTech_API.sBlockMachines, frameMeta); - } - - protected boolean checkBlockAndMetaOffset(int xOff, int yOff, int zOff, Block block, int meta) { - return checkBlockAndMeta(xLoc + xOff, yLoc + yOff, zLoc + zOff, block, meta); - } - - private boolean checkBlockAndMeta(int x, int y, int z, Block block, int meta) { - Logger.INFO("Found: "+getBaseMetaTileEntity().getBlock(x, y, z).getLocalizedName()+" | Meta: "+getBaseMetaTileEntity().getMetaID(x, y, z)); - Logger.INFO("Expected: "+block.getLocalizedName()+" | Meta: "+meta); - return (meta == W || getBaseMetaTileEntity().getMetaID(x, y, z) == meta) - && getBaseMetaTileEntity().getBlock(x, y, z) == block; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - @Override - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerTick(ItemStack aStack) { - return 0; - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - protected int getMinTier() { - return 7; - } - - protected boolean checkHatches() { - return !mMaintenanceHatches.isEmpty() && !mEnergyHatches.isEmpty(); - } - - private Map<Pair<Long, Long>, Entity> mInRange = new HashMap<Pair<Long, Long>, Entity>(); - - @SuppressWarnings("unchecked") - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - try { - if (this.getBaseMetaTileEntity().isServerSide()){ - if (this.mEnergyHatches.size() > 0) { - for (final GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches){ - if (isValidMetaTileEntity(tHatch)) { - long mHT = tHatch.getBaseMetaTileEntity().getInputVoltage(); - if (tHatch.getEUVar() >= mHT) { - for (int o=0;o<(tHatch.getEUVar()/mHT);o++){ - //1A - if (this.getEUVar()<(this.maxEUStore()-mHT)){ - tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mHT, false); - this.setEUVar(this.getEUVar()+mHT); - } - //2A - if (this.getEUVar()<(this.maxEUStore()-mHT)){ - tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mHT, false); - this.setEUVar(this.getEUVar()+mHT); - } - } - } - } - } - } - - if (aTick % 10 == 0){ - if (this.getEUVar() >= 5000000){ - //Logger.INFO("Can Zap."); - this.getBaseMetaTileEntity().enableWorking(); - this.getBaseMetaTileEntity().setActive(true); - if (this.mProgresstime <= 0){ - this.mProgresstime++; - } - else if (this.mProgresstime >= 100){ - this.mProgresstime = 0; - } - this.mMaxProgresstime = 10000; - } - //Logger.INFO("Allowed to be Working? "+this.getBaseMetaTileEntity().isAllowedToWork()); - //Logger.INFO("Working? "+this.getBaseMetaTileEntity().isActive()); - //Logger.INFO("Has Working just been enabled? "+this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()); - } - - - if (aTick % 20 == 0){ - List<Object> o = aBaseMetaTileEntity.getWorld().loadedEntityList; - //Clean up old entities first - if (this.mInRange.size() > 0){ - for (Entity j : this.mInRange.values()){ - if (((Entity) j).getDistance(this.xLoc, this.yLoc, this.zLoc) > this.mRange){ - mInRange.remove(new Pair<Long, Long>(((Entity) j).getUniqueID().getMostSignificantBits(), ((Entity) j).getUniqueID().getLeastSignificantBits()), (Entity) j); - } - } - } - //Add new entities - if (o.size() > 0){ - for (Object r : o){ - if (r instanceof Entity){ - if (!((Entity) r).getUniqueID().equals(getOwner())){ - if (((Entity) r).isEntityAlive() || r instanceof EntityLiving){ - if (((Entity) r).getDistance(this.xLoc, this.yLoc, this.zLoc) <= this.mRange){ - if (r instanceof EntityItem){ - //Do nothing - } - else { - if (!this.mMode){ - mInRange.put(new Pair<Long, Long>(((Entity) r).getUniqueID().getMostSignificantBits(), ((Entity) r).getUniqueID().getLeastSignificantBits()), (Entity) r); - } - else { - if (r instanceof EntityPlayer){ - mInRange.put(new Pair<Long, Long>(((Entity) r).getUniqueID().getMostSignificantBits(), ((Entity) r).getUniqueID().getLeastSignificantBits()), (Entity) r); - } - } - } - } - } - } - } - } - } - } - } - } - catch (Throwable r){ - - } - super.onPreTick(aBaseMetaTileEntity, aTick); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - try { - if (this.getBaseMetaTileEntity().isServerSide()){ - //Handle Progress Time - if (this.getEUVar() >= 0 && !this.getBaseMetaTileEntity().isAllowedToWork()){ - this.mProgresstime = 20; - this.mMaxProgresstime = 40; - } - else if (this.getEUVar() >= 0 && this.getBaseMetaTileEntity().isAllowedToWork()){ - this.mProgresstime = 20; - this.mMaxProgresstime = 40; - } - - if (aTick % 10 == 0){ - if (this.mInRange.size() > 0){ - if (this.getEUVar() >= 5000000){ - - for (Entity f : mInRange.values()){ - if (f instanceof EntityLiving){ - int j1 = (int) f.posX; - int l1 = (int) f.posY; - int k1 = (int) f.posZ; - World world = aBaseMetaTileEntity.getWorld(); - - if (f.isEntityAlive() && !f.getUniqueID().equals(getOwner())){ - //if (world.canLightningStrikeAt(j1, l1+1, k1)){ - //if (isEnergyEnough() && world.addWeatherEffect(new EntityTeslaTowerLightning(world, (double)j1, (double)l1, (double)k1))){ - if (isEnergyEnough() && world.addWeatherEffect(new EntityTeslaTowerLightning(world, (double)j1, (double)l1, (double)k1, f, getOwner()))){ - if (f == null || f.isDead || !f.isEntityAlive()){ - this.mInRange.remove(new Pair<Long, Long>(f.getUniqueID().getMostSignificantBits(), f.getUniqueID().getLeastSignificantBits())); - } - this.setEUVar(this.getEUVar()-5000000); - } - //} - } - - } - } - } - } - } - } - } - catch (Throwable r){ - - } - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - - protected GregtechItemList getCasingBlockItem() { - return GregtechItemList.Casing_TeslaTower; - } - - protected int getCasingTextureIndex() { - return TAE.GTPP_INDEX(30); - } - - public UUID getOwner(){ - return PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); - } - - @Override - public boolean isEnetInput() { - return false; - } - - @Override - public long maxAmperesIn() { - return 32; - } - - @Override - public long maxEUInput() { - return 131072; - } - - @Override - public long maxEUStore() { - return Integer.MAX_VALUE; - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - mMode = Utils.invertBoolean(mMode); - this.mInRange.clear(); - if (mMode){ - PlayerUtils.messagePlayer(aPlayer, "[Tesla Tower] Now only targetting players."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "[Tesla Tower] Targetting all types of entities."); - } - } - - @Override - public int getMaxParallelRecipes() { - return 0; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - // TODO Auto-generated method stub - - } - - @Override - public IStructureDefinition getStructureDefinition() { - // TODO Auto-generated method stub - return null; - } - - + private Block casingBlock; + private int casingMeta; + private int frameMeta; + private int casingTextureIndex; + + private ForgeDirection back; + + private int xLoc, yLoc, zLoc; + + protected int mRange; + + /** + * Machine Mode, + * {@value false} Attacks all entities, + * {@value true} Only attacks players. + */ + protected volatile boolean mMode = false; + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMTE_TeslaTower(mName); + } + + public GregtechMTE_TeslaTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + initFields(); + } + + public GregtechMTE_TeslaTower(String aName) { + super(aName); + initFields(); + } + + @Override + public String getMachineType() { + return "Weaponized Lighting Rod"; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + /*@Override + public String[] getTooltip() { + String casings = getCasingBlockItem().get(0).getDisplayName(); + return new String[]{ + "Controller Block for the Tesla Defence Tower Mk3200", + "Enemies within "+this.mRange+"m are blasted with a high energy plasma.", + "This uses 5,000,000EU per blast.", + "Can screwdriver to toggle mode between Players and all Entities.", + "Size(WxHxD): 3x7x3", "Controller (Front middle at bottom)", + "3x1x3 Base of " + casings, + "1x3x1 " + casings + " pillar (Center of base)", + "1x3x1 " + MaterialUtils.getMaterialName(getFrameMaterial()) + " Frame Boxes (Each pillar side and on top)", + "1x Maintenance Hatch (One of base casings)", + "1x " + VN[getMinTier()] + "+ Energy Hatch (Any bottom layer casing)"}; + }*/ + + @Override + protected final GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Tesla Defence Tower Mk3200") + .addInfo("Enemies within " + this.mRange + "m are blasted with a high energy plasma.") + .addInfo("This uses 5,000,000EU per blast.") + .addInfo("Can screwdriver to toggle mode between Players and all Entities.") + .addSeparator() + .beginStructureBlock(1, 7, 1, false) + .addController("Top Middle") + .addCasingInfo("Casing", 360) + .addOtherStructurePart("Rotor Assembly", "Any 1 dot hint", 1) + .addInputBus("Any 4 dot hint (min 1)", 4) + .addInputHatch("Any 4 dot hint(min 1)", 4) + .addOutputHatch("Any 4 dot hint(min 1)", 4) + .addEnergyHatch("Any 4 dot hint(min 1)", 4) + .addMaintenanceHatch("Any 4 dot hint(min 1)", 4) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + private final void initFields() { + casingBlock = ModBlocks.blockCasings2Misc; + casingMeta = getCasingBlockItem().get(0).getItemDamage(); + casingTextureIndex = getCasingTextureIndex(); + mRange = 50; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureIndex(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mMode", this.mMode); + aNBT.setInteger("mRange", this.mRange); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mMode = aNBT.getBoolean("mMode"); + this.mRange = aNBT.getInteger("mRange"); + super.loadNBTData(aNBT); + } + + private boolean isEnergyEnough() { + if (this.getEUVar() >= 5000000) { + return true; + } + return false; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + + if (!isEnergyEnough()) { + this.mProgresstime = 0; + this.mMaxProgresstime = 20; + this.getBaseMetaTileEntity().setActive(false); + stopMachine(); + } else { + this.mProgresstime = 1; + this.mMaxProgresstime = 100; + this.getBaseMetaTileEntity().setActive(true); + } + return false; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + updateCoordinates(); + // check base layer + for (int xOff = -1 + back.offsetX; xOff <= 1 + back.offsetX; xOff++) { + for (int zOff = -1 + back.offsetZ; zOff <= 1 + back.offsetZ; zOff++) { + if (xOff == 0 && zOff == 0) continue; + + IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xOff, 0, zOff); + if (!checkCasingBlock(xOff, 0, zOff) + && !addMaintenanceToMachineList(tTileEntity, casingTextureIndex) + && !addEnergyInputToMachineList(tTileEntity, casingTextureIndex)) { + Logger.INFO("bad block"); + return false; + } + } + } + if (!checkHatches()) { + Logger.INFO("bad Hatches"); + return false; + } + if (GT_Utility.getTier(getMaxInputVoltage()) < getMinTier()) { + Logger.INFO("bad Voltage"); + return false; + } + // check tower + for (int yOff = 1; yOff < 4; yOff++) { + if (!checkCasingBlock(back.offsetX, yOff, back.offsetZ) + || !checkFrameBlock(back.offsetX + 1, yOff, back.offsetZ) + || !checkFrameBlock(back.offsetX - 1, yOff, back.offsetZ) + || !checkFrameBlock(back.offsetX, yOff, back.offsetZ + 1) + || !checkFrameBlock(back.offsetX, yOff, back.offsetZ - 1) + || !checkFrameBlock(back.offsetX, yOff + 3, back.offsetZ)) { + Logger.INFO("bad frame?"); + return false; + } + } + Logger.INFO("good"); + return true; + } + + private void updateCoordinates() { + casingTextureIndex = getCasingTextureIndex(); + mRange = 50; + xLoc = getBaseMetaTileEntity().getXCoord(); + yLoc = getBaseMetaTileEntity().getYCoord(); + zLoc = getBaseMetaTileEntity().getZCoord(); + back = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()); + } + + protected boolean checkCasingBlock(int xOff, int yOff, int zOff) { + Logger.INFO("Looking For Casing."); + return checkBlockAndMetaOffset(xOff, yOff, zOff, casingBlock, casingMeta); + } + // meta of frame is getTileEntityBaseType; frame should be checked using its drops (possible a high weight + // operation) + protected boolean checkFrameBlock(int xOff, int yOff, int zOff) { + Logger.INFO("Looking For Frame."); + return checkBlockAndMetaOffset(xOff, yOff, zOff, GregTech_API.sBlockMachines, frameMeta); + } + + protected boolean checkBlockAndMetaOffset(int xOff, int yOff, int zOff, Block block, int meta) { + return checkBlockAndMeta(xLoc + xOff, yLoc + yOff, zLoc + zOff, block, meta); + } + + private boolean checkBlockAndMeta(int x, int y, int z, Block block, int meta) { + Logger.INFO("Found: " + getBaseMetaTileEntity().getBlock(x, y, z).getLocalizedName() + " | Meta: " + + getBaseMetaTileEntity().getMetaID(x, y, z)); + Logger.INFO("Expected: " + block.getLocalizedName() + " | Meta: " + meta); + return (meta == W || getBaseMetaTileEntity().getMetaID(x, y, z) == meta) + && getBaseMetaTileEntity().getBlock(x, y, z) == block; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + protected int getMinTier() { + return 7; + } + + protected boolean checkHatches() { + return !mMaintenanceHatches.isEmpty() && !mEnergyHatches.isEmpty(); + } + + private Map<Pair<Long, Long>, Entity> mInRange = new HashMap<Pair<Long, Long>, Entity>(); + + @SuppressWarnings("unchecked") + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + try { + if (this.getBaseMetaTileEntity().isServerSide()) { + if (this.mEnergyHatches.size() > 0) { + for (final GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches) { + if (isValidMetaTileEntity(tHatch)) { + long mHT = tHatch.getBaseMetaTileEntity().getInputVoltage(); + if (tHatch.getEUVar() >= mHT) { + for (int o = 0; o < (tHatch.getEUVar() / mHT); o++) { + // 1A + if (this.getEUVar() < (this.maxEUStore() - mHT)) { + tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mHT, false); + this.setEUVar(this.getEUVar() + mHT); + } + // 2A + if (this.getEUVar() < (this.maxEUStore() - mHT)) { + tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mHT, false); + this.setEUVar(this.getEUVar() + mHT); + } + } + } + } + } + } + + if (aTick % 10 == 0) { + if (this.getEUVar() >= 5000000) { + // Logger.INFO("Can Zap."); + this.getBaseMetaTileEntity().enableWorking(); + this.getBaseMetaTileEntity().setActive(true); + if (this.mProgresstime <= 0) { + this.mProgresstime++; + } else if (this.mProgresstime >= 100) { + this.mProgresstime = 0; + } + this.mMaxProgresstime = 10000; + } + // Logger.INFO("Allowed to be Working? "+this.getBaseMetaTileEntity().isAllowedToWork()); + // Logger.INFO("Working? "+this.getBaseMetaTileEntity().isActive()); + // Logger.INFO("Has Working just been enabled? + // "+this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()); + } + + if (aTick % 20 == 0) { + List<Object> o = aBaseMetaTileEntity.getWorld().loadedEntityList; + // Clean up old entities first + if (this.mInRange.size() > 0) { + for (Entity j : this.mInRange.values()) { + if (((Entity) j).getDistance(this.xLoc, this.yLoc, this.zLoc) > this.mRange) { + mInRange.remove( + new Pair<Long, Long>( + ((Entity) j).getUniqueID().getMostSignificantBits(), + ((Entity) j).getUniqueID().getLeastSignificantBits()), + (Entity) j); + } + } + } + // Add new entities + if (o.size() > 0) { + for (Object r : o) { + if (r instanceof Entity) { + if (!((Entity) r).getUniqueID().equals(getOwner())) { + if (((Entity) r).isEntityAlive() || r instanceof EntityLiving) { + if (((Entity) r).getDistance(this.xLoc, this.yLoc, this.zLoc) <= this.mRange) { + if (r instanceof EntityItem) { + // Do nothing + } else { + if (!this.mMode) { + mInRange.put( + new Pair<Long, Long>( + ((Entity) r) + .getUniqueID() + .getMostSignificantBits(), + ((Entity) r) + .getUniqueID() + .getLeastSignificantBits()), + (Entity) r); + } else { + if (r instanceof EntityPlayer) { + mInRange.put( + new Pair<Long, Long>( + ((Entity) r) + .getUniqueID() + .getMostSignificantBits(), + ((Entity) r) + .getUniqueID() + .getLeastSignificantBits()), + (Entity) r); + } + } + } + } + } + } + } + } + } + } + } + } catch (Throwable r) { + + } + super.onPreTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + try { + if (this.getBaseMetaTileEntity().isServerSide()) { + // Handle Progress Time + if (this.getEUVar() >= 0 && !this.getBaseMetaTileEntity().isAllowedToWork()) { + this.mProgresstime = 20; + this.mMaxProgresstime = 40; + } else if (this.getEUVar() >= 0 && this.getBaseMetaTileEntity().isAllowedToWork()) { + this.mProgresstime = 20; + this.mMaxProgresstime = 40; + } + + if (aTick % 10 == 0) { + if (this.mInRange.size() > 0) { + if (this.getEUVar() >= 5000000) { + + for (Entity f : mInRange.values()) { + if (f instanceof EntityLiving) { + int j1 = (int) f.posX; + int l1 = (int) f.posY; + int k1 = (int) f.posZ; + World world = aBaseMetaTileEntity.getWorld(); + + if (f.isEntityAlive() && !f.getUniqueID().equals(getOwner())) { + // if (world.canLightningStrikeAt(j1, l1+1, k1)){ + // if (isEnergyEnough() && world.addWeatherEffect(new + // EntityTeslaTowerLightning(world, (double)j1, (double)l1, (double)k1))){ + if (isEnergyEnough() + && world.addWeatherEffect(new EntityTeslaTowerLightning( + world, (double) j1, (double) l1, (double) k1, f, getOwner()))) { + if (f == null || f.isDead || !f.isEntityAlive()) { + this.mInRange.remove(new Pair<Long, Long>( + f.getUniqueID().getMostSignificantBits(), + f.getUniqueID().getLeastSignificantBits())); + } + this.setEUVar(this.getEUVar() - 5000000); + } + // } + } + } + } + } + } + } + } + } catch (Throwable r) { + + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + protected GregtechItemList getCasingBlockItem() { + return GregtechItemList.Casing_TeslaTower; + } + + protected int getCasingTextureIndex() { + return TAE.GTPP_INDEX(30); + } + + public UUID getOwner() { + return PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public long maxAmperesIn() { + return 32; + } + + @Override + public long maxEUInput() { + return 131072; + } + + @Override + public long maxEUStore() { + return Integer.MAX_VALUE; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mMode = Utils.invertBoolean(mMode); + this.mInRange.clear(); + if (mMode) { + PlayerUtils.messagePlayer(aPlayer, "[Tesla Tower] Now only targetting players."); + } else { + PlayerUtils.messagePlayer(aPlayer, "[Tesla Tower] Targetting all types of entities."); + } + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + // TODO Auto-generated method stub + + } + + @Override + public IStructureDefinition getStructureDefinition() { + // TODO Auto-generated method stub + return null; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java index 7013986b81..337bf1fd3c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java @@ -1,7 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -22,373 +27,375 @@ import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.ofCoil; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_IndustrialAlloySmelter extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialAlloySmelter> implements ISurvivalConstructable { - - public static int CASING_TEXTURE_ID; - private HeatingCoilLevel mHeatingCapacity; - private int mLevel = 0; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialAlloySmelter> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialAlloySmelter(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 1); - } - - public GregtechMetaTileEntity_IndustrialAlloySmelter(String aName) { - super(aName); - CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 1); - } - - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialAlloySmelter(this.mName); - } - - @Override - protected IIconContainer getActiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER; - } - - @Override - protected int getCasingTextureId() { - return CASING_TEXTURE_ID; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "MultiFurnace.png"); - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sAlloySmelterRecipes; - } - - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialAlloySmelter; - } - - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Alloy Smelter"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Alloy Smelter") - .addInfo("Gains one parallel per voltage tier") - .addInfo("Gains one multiplier per coil tier") - .addInfo("Parallel = Tier * Coil Tier") - .addInfo("Gains 5% speed bonus per coil tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 5, 3, true) - .addController("Bottom center") - .addCasingInfo("Inconel Reinforced Casings", 10) - .addCasingInfo("Integral Encasement V", 8) - .addCasingInfo("Heating Coils", 16) - .addInputBus("Any Inconel Reinforced Casing", 1) - .addOutputBus("Any Inconel Reinforced Casing", 1) - .addEnergyHatch("Any Inconel Reinforced Casing", 1) - .addMaintenanceHatch("Any Inconel Reinforced Casing", 1) - .addMufflerHatch("Any Inconel Reinforced Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialAlloySmelter> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialAlloySmelter>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"HHH", "H-H", "HHH"}, - {"VVV", "V-V", "VVV"}, - {"HHH", "H-H", "HHH"}, - {"C~C", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialAlloySmelter.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 1))) - ) - .addElement( - 'H', - ofCoil( - GregtechMetaTileEntity_IndustrialAlloySmelter::setCoilLevel, GregtechMetaTileEntity_IndustrialAlloySmelter::getCoilLevel - ) - ) - .addElement( - 'V', - ofBlock( - ModBlocks.blockCasingsTieredGTPP, 4 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName, stackSize, hintsOnly, 1, 4, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mLevel = 0; - setCoilLevel(HeatingCoilLevel.None); - return checkPiece(mName, 1, 4, 0) && mCasing >= 10 && getCoilLevel() != HeatingCoilLevel.None && (mLevel = getCoilLevel().getTier() + 1) > 0 && checkHatch(); - } - - @Override - public int getMaxParallelRecipes() { - return (this.mLevel * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - - @Override - public boolean checkRecipe(ItemStack aStack) { - FluidStack[] tFluids = getStoredFluids().toArray(new FluidStack[0]); - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - ArrayList<ItemStack> tInputs = new ArrayList<>(); - if (isValidMetaTileEntity(tBus)) { - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) { - tInputs.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - } - if (tInputs.size() > 1) { - ItemStack[] tItems = tInputs.toArray(new ItemStack[0]); - if (checkRecipeGeneric(tItems, tFluids, getMaxParallelRecipes(), 100, 5 * this.mLevel, 10000)) { - return true; - } - } - } - return false; - } - - @Override - public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, - long aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[] {}; - this.mOutputFluids = new FluidStack[] {}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - Logger.WARNING("Running checkRecipeGeneric(0)"); - - GT_Recipe tRecipe = this.getRecipeMap().findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - - Logger.WARNING("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - if (tRecipe == null) { - Logger.WARNING("BAD RETURN - 1"); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - Logger.WARNING("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - int tHeatCapacityDivTiers = (int) mHeatingCapacity.getHeat() / 900; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - // Count recipes to do in parallel, consuming input items and fluids and - // considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - Logger.WARNING("Broke at " + parallelRecipes + "."); - break; - } - Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - Logger.WARNING("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = mLevel * 5; - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); - int rInt = 2; - - this.mEUt = (int) Math.max(Math.ceil(tTotalEUt), 1); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= (tHeatCapacityDivTiers >= rInt ? 4 : 2); - } - } - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) - tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - Logger.WARNING("GOOD RETURN - 1"); - return true; - - } - - public HeatingCoilLevel getCoilLevel() { - return mHeatingCapacity; - } - - public void setCoilLevel(HeatingCoilLevel aCoilLevel) { - mHeatingCapacity = aCoilLevel; - } +public class GregtechMetaTileEntity_IndustrialAlloySmelter + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialAlloySmelter> + implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + private HeatingCoilLevel mHeatingCapacity; + private int mLevel = 0; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialAlloySmelter> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialAlloySmelter(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 1); + } + + public GregtechMetaTileEntity_IndustrialAlloySmelter(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 1); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialAlloySmelter(this.mName); + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "MultiFurnace.png"); + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sAlloySmelterRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialAlloySmelter; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Alloy Smelter"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Alloy Smelter") + .addInfo("Gains one parallel per voltage tier") + .addInfo("Gains one multiplier per coil tier") + .addInfo("Parallel = Tier * Coil Tier") + .addInfo("Gains 5% speed bonus per coil tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 5, 3, true) + .addController("Bottom center") + .addCasingInfo("Inconel Reinforced Casings", 10) + .addCasingInfo("Integral Encasement V", 8) + .addCasingInfo("Heating Coils", 16) + .addInputBus("Any Inconel Reinforced Casing", 1) + .addOutputBus("Any Inconel Reinforced Casing", 1) + .addEnergyHatch("Any Inconel Reinforced Casing", 1) + .addMaintenanceHatch("Any Inconel Reinforced Casing", 1) + .addMufflerHatch("Any Inconel Reinforced Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialAlloySmelter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialAlloySmelter>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"VVV", "V-V", "VVV"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialAlloySmelter.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 1)))) + .addElement( + 'H', + ofCoil( + GregtechMetaTileEntity_IndustrialAlloySmelter::setCoilLevel, + GregtechMetaTileEntity_IndustrialAlloySmelter::getCoilLevel)) + .addElement('V', ofBlock(ModBlocks.blockCasingsTieredGTPP, 4)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 4, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mLevel = 0; + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 4, 0) + && mCasing >= 10 + && getCoilLevel() != HeatingCoilLevel.None + && (mLevel = getCoilLevel().getTier() + 1) > 0 + && checkHatch(); + } + + @Override + public int getMaxParallelRecipes() { + return (this.mLevel * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + FluidStack[] tFluids = getStoredFluids().toArray(new FluidStack[0]); + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tInputs = new ArrayList<>(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) { + tInputs.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + } + if (tInputs.size() > 1) { + ItemStack[] tItems = tInputs.toArray(new ItemStack[0]); + if (checkRecipeGeneric(tItems, tFluids, getMaxParallelRecipes(), 100, 5 * this.mLevel, 10000)) { + return true; + } + } + } + return false; + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + Logger.WARNING("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = this.getRecipeMap() + .findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + + Logger.WARNING("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + Logger.WARNING("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + int tHeatCapacityDivTiers = (int) mHeatingCapacity.getHeat() / 900; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and + // considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + Logger.WARNING("Broke at " + parallelRecipes + "."); + break; + } + Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = mLevel * 5; + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + int rInt = 2; + + this.mEUt = (int) Math.max(Math.ceil(tTotalEUt), 1); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= (tHeatCapacityDivTiers >= rInt ? 4 : 2); + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.WARNING("GOOD RETURN - 1"); + return true; + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java index 79025840ed..9cc6b7fedd 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java @@ -1,5 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -25,280 +30,287 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialArcFurnace extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialArcFurnace> implements ISurvivalConstructable { - - //862 - private static final int mCasingTextureID = TAE.getIndexFromPage(3, 3); - public static String mCasingName = "Tempered Arc Furnace Casing"; - private boolean mPlasmaMode = false; - private int mSize = 0; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialArcFurnace(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialArcFurnace(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialArcFurnace(this.mName); - } - - @Override - public String getMachineType() { - return "(Plasma/Electric) Arc Furnace"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for Industrial Arc Furnace") - .addInfo("250% faster than using single block machines of the same voltage") - .addInfo("Processes 8 items per voltage tier * W/L") - .addInfo("Max Size required to process Plasma recipes") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .addController("Top center") - .addStructureInfo("Size: nx3xn [WxHxL] (Hollow)") - .addStructureInfo("n can be 3, 5 or 7") - .addCasingInfo(mCasingName, 10) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialArcFurnace>builder() - .addShape(mName + "3", new String[][]{ - {"CCC", "C~C", "CCC"}, - {"CCC", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - }) - .addShape(mName + "5", new String[][]{ - {"CCCCC", "CCCCC", "CC~CC", "CCCCC", "CCCCC"}, - {"CCCCC", "C---C", "C---C", "C---C", "CCCCC"}, - {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, - }) - .addShape(mName + "7", new String[][]{ - {"CCCCCCC", "CCCCCCC", "CCCCCCC", "CCC~CCC", "CCCCCCC", "CCCCCCC", "CCCCCCC"}, - {"CCCCCCC", "C-----C", "C-----C", "C-----C", "C-----C", "C-----C", "CCCCCCC"}, - {"CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC"}, - }) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialArcFurnace.class) - .atLeast(InputBus, InputHatch, OutputBus, OutputHatch, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings4Misc, 3))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - public void clearHatches() { - mOutputHatches.clear(); - mInputHatches.clear(); - mOutputBusses.clear(); - mInputBusses.clear(); - mEnergyHatches.clear(); - mMaintenanceHatches.clear(); - mMufflerHatches.clear(); - } - - private int getSizeFromHint(ItemStack stackSize) { - switch (stackSize.stackSize) { - case 1: return 3; - case 2: return 5; - default: return 7; - } - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - int size = getSizeFromHint(stackSize); - buildPiece(mName + size, stackSize, hintsOnly, (size - 1) / 2, (size - 1) / 2, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - int size = getSizeFromHint(stackSize); - return survivialBuildPiece(mName + size, stackSize, (size - 1) / 2, (size - 1) / 2, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mSize = 0; - if (checkPiece(mName + "3", 1, 1, 0)) { - mSize = 3; - return mCasing >= 10 && checkHatch(); - } - mCasing = 0; - clearHatches(); - if (checkPiece(mName + "5", 2, 2, 0)) { - mSize = 5; - return mCasing >= 10 && checkHatch(); - } - mCasing = 0; - clearHatches(); - if (checkPiece(mName + "7", 3, 3, 0)) { - mSize = 7; - return mCasing >= 10 && checkHatch(); - } - return false; - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(207)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return mCasingTextureID; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialExtruder"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return mPlasmaMode ? GT_Recipe.GT_Recipe_Map.sPlasmaArcFurnaceRecipes : GT_Recipe.GT_Recipe_Map.sArcFurnaceRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return this.checkRecipeGeneric(getMaxParallelRecipes(), 100, 250); - } - - @Override - public int getMaxParallelRecipes() { - return (this.mSize * 8 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialArcFurnace; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings4Misc; - } - - - public byte getCasingMeta() { - return 3; - } - - public Block getCasingBlock2() { - return ModBlocks.blockCasings3Misc; - } - - - public byte getCasingMeta2() { - return 15; - } - - public byte getCasingTextureIndex() { - return (byte) mCasingTextureID; - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (this.mSize > 5) { - this.mPlasmaMode = Utils.invertBoolean(mPlasmaMode); - if (mPlasmaMode) { - PlayerUtils.messagePlayer(aPlayer, "["+EnumChatFormatting.RED+"MODE"+EnumChatFormatting.RESET+"] "+EnumChatFormatting.LIGHT_PURPLE+"Plasma"+EnumChatFormatting.RESET); - } - else { - PlayerUtils.messagePlayer(aPlayer, "["+EnumChatFormatting.RED+"MODE"+EnumChatFormatting.RESET+"] "+EnumChatFormatting.YELLOW+"Electric"+EnumChatFormatting.RESET); - } - } - else { - PlayerUtils.messagePlayer(aPlayer, "["+EnumChatFormatting.RED+"MODE"+EnumChatFormatting.RESET+"] "+EnumChatFormatting.GRAY+"Cannot change mode, structure not large enough."+EnumChatFormatting.RESET); - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("mPlasmaMode", mPlasmaMode); - aNBT.setInteger("mSize", mSize); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - mPlasmaMode = aNBT.getBoolean("mPlasmaMode"); - mSize = aNBT.getInteger("mSize"); - } - - @Override - public void onMachineBlockUpdate() { - mUpdate = 100; - } +public class GregtechMetaTileEntity_IndustrialArcFurnace + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialArcFurnace> + implements ISurvivalConstructable { + + // 862 + private static final int mCasingTextureID = TAE.getIndexFromPage(3, 3); + public static String mCasingName = "Tempered Arc Furnace Casing"; + private boolean mPlasmaMode = false; + private int mSize = 0; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialArcFurnace(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialArcFurnace(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialArcFurnace(this.mName); + } + + @Override + public String getMachineType() { + return "(Plasma/Electric) Arc Furnace"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for Industrial Arc Furnace") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes 8 items per voltage tier * W/L") + .addInfo("Max Size required to process Plasma recipes") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addController("Top center") + .addStructureInfo("Size: nx3xn [WxHxL] (Hollow)") + .addStructureInfo("n can be 3, 5 or 7") + .addCasingInfo(mCasingName, 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialArcFurnace>builder() + .addShape(mName + "3", new String[][] { + {"CCC", "C~C", "CCC"}, + {"CCC", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + }) + .addShape(mName + "5", new String[][] { + {"CCCCC", "CCCCC", "CC~CC", "CCCCC", "CCCCC"}, + {"CCCCC", "C---C", "C---C", "C---C", "CCCCC"}, + {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, + }) + .addShape(mName + "7", new String[][] { + {"CCCCCCC", "CCCCCCC", "CCCCCCC", "CCC~CCC", "CCCCCCC", "CCCCCCC", "CCCCCCC"}, + {"CCCCCCC", "C-----C", "C-----C", "C-----C", "C-----C", "C-----C", "CCCCCCC"}, + {"CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC"}, + }) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialArcFurnace.class) + .atLeast(InputBus, InputHatch, OutputBus, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings4Misc, 3)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public void clearHatches() { + mOutputHatches.clear(); + mInputHatches.clear(); + mOutputBusses.clear(); + mInputBusses.clear(); + mEnergyHatches.clear(); + mMaintenanceHatches.clear(); + mMufflerHatches.clear(); + } + + private int getSizeFromHint(ItemStack stackSize) { + switch (stackSize.stackSize) { + case 1: + return 3; + case 2: + return 5; + default: + return 7; + } + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + int size = getSizeFromHint(stackSize); + buildPiece(mName + size, stackSize, hintsOnly, (size - 1) / 2, (size - 1) / 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + int size = getSizeFromHint(stackSize); + return survivialBuildPiece( + mName + size, stackSize, (size - 1) / 2, (size - 1) / 2, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mSize = 0; + if (checkPiece(mName + "3", 1, 1, 0)) { + mSize = 3; + return mCasing >= 10 && checkHatch(); + } + mCasing = 0; + clearHatches(); + if (checkPiece(mName + "5", 2, 2, 0)) { + mSize = 5; + return mCasing >= 10 && checkHatch(); + } + mCasing = 0; + clearHatches(); + if (checkPiece(mName + "7", 3, 3, 0)) { + mSize = 7; + return mCasing >= 10 && checkHatch(); + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return mCasingTextureID; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialExtruder"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mPlasmaMode + ? GT_Recipe.GT_Recipe_Map.sPlasmaArcFurnaceRecipes + : GT_Recipe.GT_Recipe_Map.sArcFurnaceRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return this.checkRecipeGeneric(getMaxParallelRecipes(), 100, 250); + } + + @Override + public int getMaxParallelRecipes() { + return (this.mSize * 8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialArcFurnace; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + public byte getCasingMeta() { + return 3; + } + + public Block getCasingBlock2() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta2() { + return 15; + } + + public byte getCasingTextureIndex() { + return (byte) mCasingTextureID; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (this.mSize > 5) { + this.mPlasmaMode = Utils.invertBoolean(mPlasmaMode); + if (mPlasmaMode) { + PlayerUtils.messagePlayer( + aPlayer, + "[" + EnumChatFormatting.RED + "MODE" + EnumChatFormatting.RESET + "] " + + EnumChatFormatting.LIGHT_PURPLE + "Plasma" + EnumChatFormatting.RESET); + } else { + PlayerUtils.messagePlayer( + aPlayer, + "[" + EnumChatFormatting.RED + "MODE" + EnumChatFormatting.RESET + "] " + + EnumChatFormatting.YELLOW + "Electric" + EnumChatFormatting.RESET); + } + } else { + PlayerUtils.messagePlayer( + aPlayer, + "[" + EnumChatFormatting.RED + "MODE" + EnumChatFormatting.RESET + "] " + EnumChatFormatting.GRAY + + "Cannot change mode, structure not large enough." + EnumChatFormatting.RESET); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mPlasmaMode", mPlasmaMode); + aNBT.setInteger("mSize", mSize); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mPlasmaMode = aNBT.getBoolean("mPlasmaMode"); + mSize = aNBT.getInteger("mSize"); + } + + @Override + public void onMachineBlockUpdate() { + mUpdate = 100; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java index fd8d895990..346c8804ab 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java @@ -1,5 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -24,219 +30,211 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialCentrifuge extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCentrifuge> implements ISurvivalConstructable { - - private boolean mIsAnimated; - private static final CustomIcon frontFaceActive = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE5"); - private static final CustomIcon frontFace = new CustomIcon("iconsets/LARGECENTRIFUGE5"); - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialCentrifuge> STRUCTURE_DEFINITION = null; - //public static double recipesComplete = 0; - - public GregtechMetaTileEntity_IndustrialCentrifuge(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - mIsAnimated = true; - } - - public GregtechMetaTileEntity_IndustrialCentrifuge(final String aName) { - super(aName); - mIsAnimated = true; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialCentrifuge(this.mName); - } - - @Override - public String getMachineType() { - return "Centrifuge"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Centrifuge") - .addInfo("125% faster than using single block machines of the same voltage") - .addInfo("Disable animations with a screwdriver") - .addInfo("Only uses 90% of the EU/t normally required") - .addInfo("Processes six items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front Center") - .addCasingInfo("Centrifuge Casings", 10) - .addInputBus("Any Casing except front", 1) - .addOutputBus("Any Casing except front", 1) - .addInputHatch("Any Casing except front", 1) - .addOutputHatch("Any Casing except front", 1) - .addEnergyHatch("Any Casing except front", 1) - .addMaintenanceHatch("Any Casing except front", 1) - .addMufflerHatch("Any Casing except front", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialCentrifuge> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCentrifuge>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialCentrifuge.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 0))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - if (usingAnimations()) { - return frontFaceActive; - } else { - return frontFace; - } - } - - @Override - protected IIconContainer getInactiveOverlay() { - return frontFace; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(0); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialCentrifuge"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe.GTPP_Recipe_Map.sMultiblockCentrifugeRecipes_GT; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(6* GT_Utility.getTier(this.getMaxInputVoltage()), 90, 125); - } - - @Override - public int getMaxParallelRecipes() { - return (6 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 90; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasingsMisc; - } - - public byte getCasingMeta() { - return 0; - } - - public byte getCasingTextureIndex() { - return (byte) TAE.GTPP_INDEX(0); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCentrifuge; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - this.mIsAnimated = !mIsAnimated; - Logger.INFO("Is Centrifuge animated "+this.mIsAnimated); - if (this.mIsAnimated) { - PlayerUtils.messagePlayer(aPlayer, "Using Animated Turbine Texture. "); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Using Static Turbine Texture. "); - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("mIsAnimated", mIsAnimated); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - if (aNBT.hasKey("mIsAnimated")) { - mIsAnimated = aNBT.getBoolean("mIsAnimated"); - } - else { - mIsAnimated = true; - } - } - - public boolean usingAnimations() { - //Logger.INFO("Is animated? "+this.mIsAnimated); - return this.mIsAnimated; - } - -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialCentrifuge + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCentrifuge> + implements ISurvivalConstructable { + + private boolean mIsAnimated; + private static final CustomIcon frontFaceActive = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE5"); + private static final CustomIcon frontFace = new CustomIcon("iconsets/LARGECENTRIFUGE5"); + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialCentrifuge> STRUCTURE_DEFINITION = null; + // public static double recipesComplete = 0; + + public GregtechMetaTileEntity_IndustrialCentrifuge(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + mIsAnimated = true; + } + + public GregtechMetaTileEntity_IndustrialCentrifuge(final String aName) { + super(aName); + mIsAnimated = true; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCentrifuge(this.mName); + } + + @Override + public String getMachineType() { + return "Centrifuge"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Centrifuge") + .addInfo("125% faster than using single block machines of the same voltage") + .addInfo("Disable animations with a screwdriver") + .addInfo("Only uses 90% of the EU/t normally required") + .addInfo("Processes six items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Centrifuge Casings", 10) + .addInputBus("Any Casing except front", 1) + .addOutputBus("Any Casing except front", 1) + .addInputHatch("Any Casing except front", 1) + .addOutputHatch("Any Casing except front", 1) + .addEnergyHatch("Any Casing except front", 1) + .addMaintenanceHatch("Any Casing except front", 1) + .addMufflerHatch("Any Casing except front", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCentrifuge> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCentrifuge>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialCentrifuge.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 0)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + if (usingAnimations()) { + return frontFaceActive; + } else { + return frontFace; + } + } + + @Override + protected IIconContainer getInactiveOverlay() { + return frontFace; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(0); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialCentrifuge"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sMultiblockCentrifugeRecipes_GT; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(6 * GT_Utility.getTier(this.getMaxInputVoltage()), 90, 125); + } + + @Override + public int getMaxParallelRecipes() { + return (6 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 90; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasingsMisc; + } + + public byte getCasingMeta() { + return 0; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(0); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCentrifuge; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + this.mIsAnimated = !mIsAnimated; + Logger.INFO("Is Centrifuge animated " + this.mIsAnimated); + if (this.mIsAnimated) { + PlayerUtils.messagePlayer(aPlayer, "Using Animated Turbine Texture. "); + } else { + PlayerUtils.messagePlayer(aPlayer, "Using Static Turbine Texture. "); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mIsAnimated", mIsAnimated); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("mIsAnimated")) { + mIsAnimated = aNBT.getBoolean("mIsAnimated"); + } else { + mIsAnimated = true; + } + } + + public boolean usingAnimations() { + // Logger.INFO("Is animated? "+this.mIsAnimated); + return this.mIsAnimated; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java index 8233437748..92fc3cb1c8 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java @@ -1,7 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -19,6 +23,8 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -26,143 +32,137 @@ import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; import team.chisel.carving.Carving; +public class GregtechMetaTileEntity_IndustrialChisel + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialChisel> implements ISurvivalConstructable { -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_IndustrialChisel extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialChisel> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialChisel> STRUCTURE_DEFINITION = null; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialChisel> STRUCTURE_DEFINITION = null; private ItemStack mInputCache; private ItemStack mOutputCache; private GTPP_Recipe mCachedRecipe; - public GregtechMetaTileEntity_IndustrialChisel(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialChisel(String aName) { - super(aName); - } - - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialChisel(this.mName); - } - - @Override - public String getMachineType() { - return "Chisel"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Factory Grade Auto Chisel") - .addInfo("Target block goes in GUI slot") - .addInfo("If no target provided, firdt chisel result is used") - .addInfo("Speed: +200% | EU Usage: 75% | Parallel: Tier x 16") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front center") - .addCasingInfo("Sturdy Printer Casing", 10) - .addInputBus("Any casing", 1) - .addOutputBus("Any casing", 1) - .addEnergyHatch("Any casing", 1) - .addMaintenanceHatch("Any casing", 1) - .addMufflerHatch("Any casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialChisel> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialChisel>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialChisel.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(90) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings5Misc, 5))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return 90; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "ImplosionCompressor"; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return null; - } - - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - + public GregtechMetaTileEntity_IndustrialChisel(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialChisel(String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialChisel(this.mName); + } + + @Override + public String getMachineType() { + return "Chisel"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Auto Chisel") + .addInfo("Target block goes in GUI slot") + .addInfo("If no target provided, firdt chisel result is used") + .addInfo("Speed: +200% | EU Usage: 75% | Parallel: Tier x 16") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Sturdy Printer Casing", 10) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialChisel> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialChisel>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialChisel.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(90) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings5Misc, 5)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return 90; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ImplosionCompressor"; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + private boolean hasValidCache(ItemStack aStack, ItemStack aSpecialSlot, boolean aClearOnFailure) { - if (mInputCache != null && mOutputCache != null && mCachedRecipe != null) { - if (GT_Utility.areStacksEqual(aStack, mInputCache) && GT_Utility.areStacksEqual(aSpecialSlot, mOutputCache)) { - return true; - } + if (mInputCache != null && mOutputCache != null && mCachedRecipe != null) { + if (GT_Utility.areStacksEqual(aStack, mInputCache) + && GT_Utility.areStacksEqual(aSpecialSlot, mOutputCache)) { + return true; + } } // clear cache if it was invalid if (aClearOnFailure) { @@ -172,286 +172,284 @@ public class GregtechMetaTileEntity_IndustrialChisel extends GregtechMeta_MultiB } return false; } - + private void cacheItem(ItemStack aInputItem, ItemStack aOutputItem, GTPP_Recipe aRecipe) { mInputCache = aInputItem.copy(); mOutputCache = aOutputItem.copy(); mCachedRecipe = aRecipe; } - - // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target - private static boolean canBeMadeFrom(ItemStack from, ItemStack to) { - List<ItemStack> results = getItemsForChiseling(from); - for (ItemStack s : results) { - if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) { - return true; - } - } - return false; - } - - // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target - private static boolean hasChiselResults(ItemStack from) { - List<ItemStack> results = getItemsForChiseling(from); - return results.size() > 0; - } - - private static List<ItemStack> getItemsForChiseling(ItemStack aStack){ - return Carving.chisel.getItemsForChiseling(aStack); - } - - private static ItemStack getChiselOutput(ItemStack aInput, ItemStack aTarget) { - ItemStack tOutput = null; - if (aTarget != null && canBeMadeFrom(aInput, aTarget)) { - tOutput = aTarget; - } - else if (aTarget != null && !canBeMadeFrom(aInput, aTarget)) { - tOutput = null; - } - else { - tOutput = getItemsForChiseling(aInput).get(0); - } - return tOutput; - } - - private GTPP_Recipe generateChiselRecipe(ItemStack aInput, ItemStack aTarget) { + + // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target + private static boolean canBeMadeFrom(ItemStack from, ItemStack to) { + List<ItemStack> results = getItemsForChiseling(from); + for (ItemStack s : results) { + if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) { + return true; + } + } + return false; + } + + // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target + private static boolean hasChiselResults(ItemStack from) { + List<ItemStack> results = getItemsForChiseling(from); + return results.size() > 0; + } + + private static List<ItemStack> getItemsForChiseling(ItemStack aStack) { + return Carving.chisel.getItemsForChiseling(aStack); + } + + private static ItemStack getChiselOutput(ItemStack aInput, ItemStack aTarget) { + ItemStack tOutput = null; + if (aTarget != null && canBeMadeFrom(aInput, aTarget)) { + tOutput = aTarget; + } else if (aTarget != null && !canBeMadeFrom(aInput, aTarget)) { + tOutput = null; + } else { + tOutput = getItemsForChiseling(aInput).get(0); + } + return tOutput; + } + + private GTPP_Recipe generateChiselRecipe(ItemStack aInput, ItemStack aTarget) { boolean tIsCached = hasValidCache(aInput, aTarget, true); - if (tIsCached || aInput != null && hasChiselResults(aInput)) { - ItemStack tOutput = tIsCached ? mOutputCache.copy() : getChiselOutput(aInput, aTarget); - if (tOutput != null) { - if (mCachedRecipe != null && GT_Utility.areStacksEqual(aInput, mInputCache) && GT_Utility.areStacksEqual(tOutput, mOutputCache)) { - return mCachedRecipe; - } - // We can chisel this - GTPP_Recipe aRecipe = new GTPP_Recipe( - false, - new ItemStack[] {ItemUtils.getSimpleStack(aInput, 1)}, - new ItemStack[] {ItemUtils.getSimpleStack(tOutput, 1)}, - null, - new int[] {10000}, - new FluidStack[] {}, - new FluidStack[] {}, - 20, - 16, - 0); - - // Cache it - cacheItem(aInput, tOutput, aRecipe); - return aRecipe; - } - } - return null; - } - - public boolean checkRecipe(final ItemStack aStack) { - ArrayList<ItemStack> aItems = this.getStoredInputs(); - if (!aItems.isEmpty()) { - - GT_Recipe tRecipe = generateChiselRecipe(aItems.get(0), this.getGUIItemStack()); - - if (tRecipe == null) { - log("BAD RETURN - 0"); - return false; - } - - // Based on the Processing Array. A bit overkill, but very flexible. - ItemStack[] aItemInputs = aItems.toArray(new ItemStack[aItems.size()]); - FluidStack[] aFluidInputs = new FluidStack[] {}; - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - int aMaxParallelRecipes = getMaxParallelRecipes(); - int aEUPercent = getEuDiscountForParallelism(); - int aSpeedBonusPercent = 200; - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+aMaxParallelRecipes); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - log("Broke at "+parallelRecipes+"."); - break; - } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - log("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+aMaxParallelRecipes); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tRecipeEUt: "+tRecipeEUt); - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(10000) <= tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - log("GOOD RETURN - 1"); - return true; - } - - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (16 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 75; - } - - private static String sChiselSound = null; - - private static final String getChiselSound() { - if (sChiselSound == null) { - sChiselSound = Carving.chisel.getVariationSound(Blocks.stone, 0); - } - return sChiselSound; - } - - @Override - public String getSound() { - return getChiselSound(); - } - - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialChisel; - } - - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - -}
\ No newline at end of file + if (tIsCached || aInput != null && hasChiselResults(aInput)) { + ItemStack tOutput = tIsCached ? mOutputCache.copy() : getChiselOutput(aInput, aTarget); + if (tOutput != null) { + if (mCachedRecipe != null + && GT_Utility.areStacksEqual(aInput, mInputCache) + && GT_Utility.areStacksEqual(tOutput, mOutputCache)) { + return mCachedRecipe; + } + // We can chisel this + GTPP_Recipe aRecipe = new GTPP_Recipe( + false, + new ItemStack[] {ItemUtils.getSimpleStack(aInput, 1)}, + new ItemStack[] {ItemUtils.getSimpleStack(tOutput, 1)}, + null, + new int[] {10000}, + new FluidStack[] {}, + new FluidStack[] {}, + 20, + 16, + 0); + + // Cache it + cacheItem(aInput, tOutput, aRecipe); + return aRecipe; + } + } + return null; + } + + public boolean checkRecipe(final ItemStack aStack) { + ArrayList<ItemStack> aItems = this.getStoredInputs(); + if (!aItems.isEmpty()) { + + GT_Recipe tRecipe = generateChiselRecipe(aItems.get(0), this.getGUIItemStack()); + + if (tRecipe == null) { + log("BAD RETURN - 0"); + return false; + } + + // Based on the Processing Array. A bit overkill, but very flexible. + ItemStack[] aItemInputs = aItems.toArray(new ItemStack[aItems.size()]); + FluidStack[] aFluidInputs = new FluidStack[] {}; + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + int aMaxParallelRecipes = getMaxParallelRecipes(); + int aEUPercent = getEuDiscountForParallelism(); + int aSpeedBonusPercent = 200; + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + aMaxParallelRecipes); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at " + parallelRecipes + "."); + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + aMaxParallelRecipes); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tRecipeEUt: " + tRecipeEUt); + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(10000) <= tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (16 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 75; + } + + private static String sChiselSound = null; + + private static final String getChiselSound() { + if (sChiselSound == null) { + sChiselSound = Carving.chisel.getVariationSound(Blocks.stone, 0); + } + return sChiselSound; + } + + @Override + public String getSound() { + return getChiselSound(); + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialChisel; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java index de9701283a..8e826a7fc4 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java @@ -1,5 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -20,226 +27,194 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialCokeOven extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCokeOven> implements ISurvivalConstructable { - - private int mLevel = 0; - private int mCasing; - private int mCasing1; - private int mCasing2; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialCokeOven> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialCokeOven(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialCokeOven(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialCokeOven(this.mName); - } - - @Override - public String getMachineType() { - return "Coke Oven"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Processes Logs and Coal into Charcoal and Coal Coke.") - .addInfo("Controller Block for the Industrial Coke Oven") - .addInfo("Gain 4% energy discount per voltage tier") - .addInfo("Process 12x materials with Heat Resistant Casings") - .addInfo("Or 24x materials with Heat Proof Casings") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front middle at bottom") - .addCasingInfo("Structural Coke Oven Casings", 8) - .addCasingInfo("Heat Resistant/Proof Coke Oven Casings", 8) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialCokeOven> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCokeOven>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"HHH", "H-H", "HHH"}, - {"C~C", "CCC", "CCC"}, - })) - .addShape(mName + "1", transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"aaa", "a-a", "aaa"}, - {"C~C", "CCC", "CCC"}, - })) - .addShape(mName + "2", transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"bbb", "b-b", "bbb"}, - {"C~C", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialCokeOven.class) - .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) - .casingIndex(TAE.GTPP_INDEX(1)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 1))) - ) - .addElement( - 'H', - ofChain( - onElementPass( - x -> ++x.mCasing1, - ofBlock( - ModBlocks.blockCasingsMisc, 2 - ) - ), - onElementPass( - x -> ++x.mCasing2, - ofBlock( - ModBlocks.blockCasingsMisc, 3 - ) - ) - ) - ) - .addElement( - 'a', - ofBlock( - ModBlocks.blockCasingsMisc, 2 - ) - ) - .addElement( - 'b', - ofBlock( - ModBlocks.blockCasingsMisc, 3 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - if (stackSize.stackSize == 1) - buildPiece(mName + "1" , stackSize, hintsOnly, 1, 2, 0); - else - buildPiece(mName + "2" , stackSize, hintsOnly, 1, 2, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - if (stackSize.stackSize == 1) - return survivialBuildPiece(mName + "1", stackSize, 1, 2, 0, elementBudget, source, actor, false, true); - else - return survivialBuildPiece(mName + "2", stackSize, 1, 2, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mCasing1 = 0; - mCasing2 = 0; - mLevel = 0; - if (checkPiece(mName, 1, 2, 0)) { - if (mCasing1 == 8) mLevel = 1; - if (mCasing2 == 8) mLevel = 2; - return mLevel > 0 && mCasing >= 8 && checkHatch(); - } - return false; - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(207)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(1); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "CokeOven"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe.GTPP_Recipe_Map.sCokeOvenRecipes; - - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); - } - - @Override - public int getMaxParallelRecipes() { - return this.mLevel * 12; - } - - @Override - public int getEuDiscountForParallelism() { - return (100-(GT_Utility.getTier(this.getMaxInputVoltage())*4)); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCokeOven; - } - - @Override - public int getAmountOfOutputs() { - return 24; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } +public class GregtechMetaTileEntity_IndustrialCokeOven + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCokeOven> + implements ISurvivalConstructable { + + private int mLevel = 0; + private int mCasing; + private int mCasing1; + private int mCasing2; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialCokeOven> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialCokeOven(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialCokeOven(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCokeOven(this.mName); + } + + @Override + public String getMachineType() { + return "Coke Oven"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Processes Logs and Coal into Charcoal and Coal Coke.") + .addInfo("Controller Block for the Industrial Coke Oven") + .addInfo("Gain 4% energy discount per voltage tier") + .addInfo("Process 12x materials with Heat Resistant Casings") + .addInfo("Or 24x materials with Heat Proof Casings") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front middle at bottom") + .addCasingInfo("Structural Coke Oven Casings", 8) + .addCasingInfo("Heat Resistant/Proof Coke Oven Casings", 8) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCokeOven> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCokeOven>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addShape(mName + "1", transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"aaa", "a-a", "aaa"}, + {"C~C", "CCC", "CCC"}, + })) + .addShape(mName + "2", transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"bbb", "b-b", "bbb"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialCokeOven.class) + .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(1)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 1)))) + .addElement( + 'H', + ofChain( + onElementPass(x -> ++x.mCasing1, ofBlock(ModBlocks.blockCasingsMisc, 2)), + onElementPass(x -> ++x.mCasing2, ofBlock(ModBlocks.blockCasingsMisc, 3)))) + .addElement('a', ofBlock(ModBlocks.blockCasingsMisc, 2)) + .addElement('b', ofBlock(ModBlocks.blockCasingsMisc, 3)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + if (stackSize.stackSize == 1) buildPiece(mName + "1", stackSize, hintsOnly, 1, 2, 0); + else buildPiece(mName + "2", stackSize, hintsOnly, 1, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + if (stackSize.stackSize == 1) + return survivialBuildPiece(mName + "1", stackSize, 1, 2, 0, elementBudget, source, actor, false, true); + else return survivialBuildPiece(mName + "2", stackSize, 1, 2, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mCasing1 = 0; + mCasing2 = 0; + mLevel = 0; + if (checkPiece(mName, 1, 2, 0)) { + if (mCasing1 == 8) mLevel = 1; + if (mCasing2 == 8) mLevel = 2; + return mLevel > 0 && mCasing >= 8 && checkHatch(); + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(1); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "CokeOven"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sCokeOvenRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); + } + + @Override + public int getMaxParallelRecipes() { + return this.mLevel * 12; + } + + @Override + public int getEuDiscountForParallelism() { + return (100 - (GT_Utility.getTier(this.getMaxInputVoltage()) * 4)); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCokeOven; + } + + @Override + public int getAmountOfOutputs() { + return 24; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java index 089b28a046..ac184e175b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java @@ -1,5 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -23,199 +29,192 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialCuttingMachine extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCuttingMachine> implements ISurvivalConstructable { - - private boolean mCuttingMode = true; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialCuttingMachine> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialCuttingMachine(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialCuttingMachine(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialCuttingMachine(this.mName); - } - - @Override - public String getMachineType() { - return "Cutting Machine / Slicing Machine"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Cutting Factory") - .addInfo("200% faster than using single block machines of the same voltage") - .addInfo("Only uses 75% of the EU/t normally required") - .addInfo("Processes four items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 5, true) - .addController("Front Center") - .addCasingInfo("Cutting Factory Frames", 26) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialCuttingMachine> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCuttingMachine>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC", "CCC", "CCC"}, - {"C~C", "C-C", "C-C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialCuttingMachine.class) - .atLeast(InputBus, InputHatch, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 13))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 26 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(29); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialCuttingMachine"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return mCuttingMode ? GT_Recipe.GT_Recipe_Map.sCutterRecipes : GT_Recipe.GT_Recipe_Map.sSlicerRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric((4* GT_Utility.getTier(this.getMaxInputVoltage())), 75, 200); - } - - @Override - public int getMaxParallelRecipes() { - return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 75; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCuttingMachine; - } - - @Override - public int getAmountOfOutputs() { - return 2; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings2Misc; - } - - - public byte getCasingMeta() { - return 13; - } - - - public byte getCasingTextureIndex() { - return (byte) TAE.GTPP_INDEX(29); - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - mCuttingMode = Utils.invertBoolean(mCuttingMode); - String aMode = mCuttingMode ? "Cutting" : "Slicing"; - PlayerUtils.messagePlayer(aPlayer, "Mode: "+aMode); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("mCuttingMode", mCuttingMode); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - if (aNBT.hasKey("mCuttingMode")) { - mCuttingMode = aNBT.getBoolean("mCuttingMode"); - } - else { - mCuttingMode = true; - } - } -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialCuttingMachine + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCuttingMachine> + implements ISurvivalConstructable { + + private boolean mCuttingMode = true; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialCuttingMachine> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialCuttingMachine( + final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialCuttingMachine(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCuttingMachine(this.mName); + } + + @Override + public String getMachineType() { + return "Cutting Machine / Slicing Machine"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Cutting Factory") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Only uses 75% of the EU/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfo("Cutting Factory Frames", 26) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCuttingMachine> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCuttingMachine>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + {"C~C", "C-C", "C-C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialCuttingMachine.class) + .atLeast(InputBus, InputHatch, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 13)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 26 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(29); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialCuttingMachine"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mCuttingMode ? GT_Recipe.GT_Recipe_Map.sCutterRecipes : GT_Recipe.GT_Recipe_Map.sSlicerRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((4 * GT_Utility.getTier(this.getMaxInputVoltage())), 75, 200); + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 75; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCuttingMachine; + } + + @Override + public int getAmountOfOutputs() { + return 2; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 13; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(29); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mCuttingMode = Utils.invertBoolean(mCuttingMode); + String aMode = mCuttingMode ? "Cutting" : "Slicing"; + PlayerUtils.messagePlayer(aPlayer, "Mode: " + aMode); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mCuttingMode", mCuttingMode); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("mCuttingMode")) { + mCuttingMode = aNBT.getBoolean("mCuttingMode"); + } else { + mCuttingMode = true; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java index e562e2d29d..c1ed59ce2b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java @@ -1,7 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -23,6 +28,8 @@ import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -30,362 +37,363 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.ofCoil; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_IndustrialDehydrator extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialDehydrator> implements ISurvivalConstructable { - - private static int CASING_TEXTURE_ID; - private static String mCasingName = "Vacuum Casing"; - private HeatingCoilLevel mHeatingCapacity; - private boolean mDehydratorMode = false; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialDehydrator> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialDehydrator(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - CASING_TEXTURE_ID = TAE.getIndexFromPage(3, 10); - } - - public GregtechMetaTileEntity_IndustrialDehydrator(String aName) { - super(aName); - CASING_TEXTURE_ID = TAE.getIndexFromPage(3, 10); - } - - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialDehydrator(mName); - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Factory Grade Vacuum Furnace") - .addInfo("Can toggle the operation temperature with a Screwdriver") - .addInfo("All Dehydrator recipes are Low Temp recipes") - .addInfo("Speed: +120% | EU Usage: 50% | Parallel: 4") - .addInfo("Each 900K over the min. Heat Capacity grants 5% speedup (multiplicatively)") - .addInfo("Each 1800K over the min. Heat Capacity allows for one upgraded overclock") - .addInfo("Upgraded overclocks reduce recipe time to 25% and increase EU/t to 400%") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 5, 3, true) - .addController("Bottom Center") - .addCasingInfo(mCasingName, 10) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialDehydrator> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialDehydrator>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"HHH", "H-H", "HHH"}, - {"HHH", "H-H", "HHH"}, - {"HHH", "H-H", "HHH"}, - {"C~C", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialDehydrator.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings4Misc, 10))) - ) - .addElement( - 'H', - ofCoil( - GregtechMetaTileEntity_IndustrialDehydrator::setCoilLevel, GregtechMetaTileEntity_IndustrialDehydrator::getCoilLevel - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 4, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 4, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - setCoilLevel(HeatingCoilLevel.None); - return checkPiece(mName, 1, 4, 0) && mCasing >= 10 && getCoilLevel() != HeatingCoilLevel.None && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return CASING_TEXTURE_ID; - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return mDehydratorMode ? GTPP_Recipe.GTPP_Recipe_Map.sChemicalDehydratorRecipes : GTPP_Recipe.GTPP_Recipe_Map.sVacuumFurnaceRecipes; - } - - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialDehydrator; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getMachineType() { - return "Vacuum Furnace / Dehydrator"; - } - - @Override - public int getMaxParallelRecipes() { - return 4; - } - - @Override - public int getEuDiscountForParallelism() { - return 50; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "ElectricBlastFurnace"; - } - - public boolean checkRecipe(ItemStack aStack) { - return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 120); - } - - @Override - public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, - long aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[] {}; - this.mOutputFluids = new FluidStack[] {}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - Logger.WARNING("Running checkRecipeGeneric(0)"); - - GT_Recipe tRecipe = this.getRecipeMap().findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - - Logger.WARNING("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - if (tRecipe == null || this.mHeatingCapacity.getHeat() < tRecipe.mSpecialValue) { - Logger.WARNING("BAD RETURN - 1"); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - Logger.WARNING("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - int tHeatCapacityDivTiers = (int) (mHeatingCapacity.getHeat() - tRecipe.mSpecialValue) / 900; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - // Count recipes to do in parallel, consuming input items and fluids and - // considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - Logger.WARNING("Broke at " + parallelRecipes + "."); - break; - } - Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - Logger.WARNING("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); - int rInt = 2; - - this.mEUt = (int) Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= (tHeatCapacityDivTiers >= rInt ? 4 : 2); - } - } - - if (tHeatCapacityDivTiers > 0) { - this.mEUt = (int) (this.mEUt * (Math.pow(0.95, tHeatCapacityDivTiers))); - } - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) - tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - Logger.WARNING("GOOD RETURN - 1"); - return true; - - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - mDehydratorMode = Utils.invertBoolean(mDehydratorMode); - String aMode = mDehydratorMode ? "Dehydrator" : "Vacuum Furnace"; - PlayerUtils.messagePlayer(aPlayer, "Mode: "+aMode); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("mDehydratorMode", mDehydratorMode); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - mDehydratorMode = aNBT.getBoolean("mDehydratorMode"); - } - - public HeatingCoilLevel getCoilLevel() { - return mHeatingCapacity; - } - - public void setCoilLevel(HeatingCoilLevel aCoilLevel) { - mHeatingCapacity = aCoilLevel; - } +public class GregtechMetaTileEntity_IndustrialDehydrator + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialDehydrator> + implements ISurvivalConstructable { + + private static int CASING_TEXTURE_ID; + private static String mCasingName = "Vacuum Casing"; + private HeatingCoilLevel mHeatingCapacity; + private boolean mDehydratorMode = false; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialDehydrator> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialDehydrator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(3, 10); + } + + public GregtechMetaTileEntity_IndustrialDehydrator(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(3, 10); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialDehydrator(mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Vacuum Furnace") + .addInfo("Can toggle the operation temperature with a Screwdriver") + .addInfo("All Dehydrator recipes are Low Temp recipes") + .addInfo("Speed: +120% | EU Usage: 50% | Parallel: 4") + .addInfo("Each 900K over the min. Heat Capacity grants 5% speedup (multiplicatively)") + .addInfo("Each 1800K over the min. Heat Capacity allows for one upgraded overclock") + .addInfo("Upgraded overclocks reduce recipe time to 25% and increase EU/t to 400%") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 5, 3, true) + .addController("Bottom Center") + .addCasingInfo(mCasingName, 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialDehydrator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialDehydrator>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialDehydrator.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings4Misc, 10)))) + .addElement( + 'H', + ofCoil( + GregtechMetaTileEntity_IndustrialDehydrator::setCoilLevel, + GregtechMetaTileEntity_IndustrialDehydrator::getCoilLevel)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 4, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 4, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 4, 0) && mCasing >= 10 && getCoilLevel() != HeatingCoilLevel.None && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mDehydratorMode + ? GTPP_Recipe.GTPP_Recipe_Map.sChemicalDehydratorRecipes + : GTPP_Recipe.GTPP_Recipe_Map.sVacuumFurnaceRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialDehydrator; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getMachineType() { + return "Vacuum Furnace / Dehydrator"; + } + + @Override + public int getMaxParallelRecipes() { + return 4; + } + + @Override + public int getEuDiscountForParallelism() { + return 50; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ElectricBlastFurnace"; + } + + public boolean checkRecipe(ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 120); + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + Logger.WARNING("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = this.getRecipeMap() + .findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + + Logger.WARNING("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null || this.mHeatingCapacity.getHeat() < tRecipe.mSpecialValue) { + Logger.WARNING("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + int tHeatCapacityDivTiers = (int) (mHeatingCapacity.getHeat() - tRecipe.mSpecialValue) / 900; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and + // considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + Logger.WARNING("Broke at " + parallelRecipes + "."); + break; + } + Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + int rInt = 2; + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= (tHeatCapacityDivTiers >= rInt ? 4 : 2); + } + } + + if (tHeatCapacityDivTiers > 0) { + this.mEUt = (int) (this.mEUt * (Math.pow(0.95, tHeatCapacityDivTiers))); + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.WARNING("GOOD RETURN - 1"); + return true; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mDehydratorMode = Utils.invertBoolean(mDehydratorMode); + String aMode = mDehydratorMode ? "Dehydrator" : "Vacuum Furnace"; + PlayerUtils.messagePlayer(aPlayer, "Mode: " + aMode); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mDehydratorMode", mDehydratorMode); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mDehydratorMode = aNBT.getBoolean("mDehydratorMode"); + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } } - - diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java index 9f7cbc8859..835b6c6378 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java @@ -1,5 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -18,161 +24,157 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialElectrolyzer extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialElectrolyzer> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialElectrolyzer> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialElectrolyzer(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialElectrolyzer(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialElectrolyzer(this.mName); - } - - @Override - public String getMachineType() { - return "Electrolyzer"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Electrolyzer") - .addInfo("180% faster than using single block machines of the same voltage") - .addInfo("Only uses 90% of the EU/t normally required") - .addInfo("Processes two items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front Center") - .addCasingInfo("Electrolyzer Casings", 10) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialElectrolyzer> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialElectrolyzer>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialElectrolyzer.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(TAE.GTPP_INDEX(5)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 5))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(5); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialElectrolyzer"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map.sMultiblockElectrolyzerRecipes_GT; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(2* GT_Utility.getTier(this.getMaxInputVoltage()), 90, 180); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialElectrolyzer; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public int getMaxParallelRecipes() { - return 2* GT_Utility.getTier(this.getMaxInputVoltage()); - } - - @Override - public int getEuDiscountForParallelism() { - return 90; - } -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialElectrolyzer + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialElectrolyzer> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialElectrolyzer> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialElectrolyzer( + final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialElectrolyzer(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialElectrolyzer(this.mName); + } + + @Override + public String getMachineType() { + return "Electrolyzer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Electrolyzer") + .addInfo("180% faster than using single block machines of the same voltage") + .addInfo("Only uses 90% of the EU/t normally required") + .addInfo("Processes two items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Electrolyzer Casings", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialElectrolyzer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialElectrolyzer>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialElectrolyzer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(TAE.GTPP_INDEX(5)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 5)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(5); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialElectrolyzer"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map.sMultiblockElectrolyzerRecipes_GT; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(2 * GT_Utility.getTier(this.getMaxInputVoltage()), 90, 180); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialElectrolyzer; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 2 * GT_Utility.getTier(this.getMaxInputVoltage()); + } + + @Override + public int getEuDiscountForParallelism() { + return 90; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java index 4b794506f9..91c232d8fe 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java @@ -1,6 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -19,213 +23,207 @@ import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialExtruder extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialExtruder> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialExtruder> STRUCTURE_DEFINITION = null; - - - public GregtechMetaTileEntity_IndustrialExtruder(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialExtruder(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialExtruder(this.mName); - } - - @Override - public String getMachineType() { - return "Extruder"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Material Extruder") - .addInfo("250% faster than using single block machines of the same voltage") - .addInfo("Processes four items per voltage tier") - .addInfo("Extrusion Shape for recipe goes in the Input Bus") - .addInfo("Each Input Bus can have a different shape!") - .addInfo("You can use several input buses per multiblock") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 5, true) - .addController("Front Center") - .addCasingInfo("Inconel Reinforced Casings", 28) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Back Center", 2) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialExtruder> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialExtruder>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC", "CCC", "CCC"}, - {"C~C", "C-C", "C-C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialExtruder.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta()))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 28 && checkHatch(); - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(203)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(33); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialExtruder"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sExtruderRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); - tBus.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tBus)) { - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) - tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - ItemStack[] inputs = new ItemStack[tBusItems.size()]; - int slot = 0; - for (ItemStack g : tBusItems) { - inputs[slot++] = g; - } - if (inputs.length > 0) { - int para = (4* GT_Utility.getTier(this.getMaxInputVoltage())); - log("Recipe. ["+inputs.length+"]["+para+"]"); - if (checkRecipeGeneric(inputs, new FluidStack[]{}, para, 100, 250, 10000)) { - log("Recipe 2."); - return true; - } - } - - } - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialExtruder; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings3Misc; - } - - public byte getCasingMeta() { - return 1; - } - - public byte getCasingTextureIndex() { - return (byte) TAE.GTPP_INDEX(33); - } +public class GregtechMetaTileEntity_IndustrialExtruder + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialExtruder> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialExtruder> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialExtruder(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialExtruder(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialExtruder(this.mName); + } + + @Override + public String getMachineType() { + return "Extruder"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Material Extruder") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes four items per voltage tier") + .addInfo("Extrusion Shape for recipe goes in the Input Bus") + .addInfo("Each Input Bus can have a different shape!") + .addInfo("You can use several input buses per multiblock") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfo("Inconel Reinforced Casings", 28) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Back Center", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialExtruder> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialExtruder>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + {"C~C", "C-C", "C-C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialExtruder.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 28 && checkHatch(); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(203)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(33); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialExtruder"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sExtruderRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + ItemStack[] inputs = new ItemStack[tBusItems.size()]; + int slot = 0; + for (ItemStack g : tBusItems) { + inputs[slot++] = g; + } + if (inputs.length > 0) { + int para = (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + log("Recipe. [" + inputs.length + "][" + para + "]"); + if (checkRecipeGeneric(inputs, new FluidStack[] {}, para, 100, 250, 10000)) { + log("Recipe 2."); + return true; + } + } + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialExtruder; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta() { + return 1; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(33); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialFluidHeater.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialFluidHeater.java index 292c42930b..f6d65aafe6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialFluidHeater.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialFluidHeater.java @@ -1,5 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -19,197 +25,191 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialFluidHeater extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialFluidHeater> implements ISurvivalConstructable { - - private int mCasing1; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialFluidHeater> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialFluidHeater(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialFluidHeater(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialFluidHeater(this.mName); - } - - @Override - public String getMachineType() { - return "Fluid Heater"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Fluid Heater") - .addInfo("120% faster than using single block machines of the same voltage") - .addInfo("Only uses 90% of the EU/t normally required") - .addInfo("Processes eight items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(5, 6, 5, true) - .addController("Front Center") - .addCasingInfo("Top/Bottom layer: Multi-use Casings", 34) - .addCasingInfo("Middle layers: Thermal Containment Casing", 47) - .addInputBus("Bottom Layer (optional)", 1) - .addInputHatch("Bottom Layer", 1) - .addOutputBus("Top Layer (optional)", 1) - .addOutputHatch("Top Layer", 1) - .addEnergyHatch("Any Multi-use Casing", 1) - .addMaintenanceHatch("Any Multi-use Casing", 1) - .addMufflerHatch("Any Multi-use Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialFluidHeater> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialFluidHeater>builder() - .addShape(mName, transpose(new String[][]{ - {" TTT ", "TTTTT", "TTTTT", "TTTTT", " TTT "}, - {" XXX ", "X---X", "X---X", "X---X", " XXX "}, - {" XXX ", "X---X", "X---X", "X---X", " XXX "}, - {" XXX ", "X---X", "X---X", "X---X", " XXX "}, - {" X~X ", "X---X", "X---X", "X---X", " XXX "}, - {" BBB ", "BBBBB", "BBBBB", "BBBBB", " BBB "}, - })) - .addElement( - 'B', - buildHatchAdder(GregtechMetaTileEntity_IndustrialFluidHeater.class) - .atLeast(InputBus, InputHatch, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing1, ofBlock(getCasingBlock2(), getCasingMeta2()))) - ) - .addElement('X', ofBlock(getCasingBlock1(), getCasingMeta1())) - .addElement( - 'T', - buildHatchAdder(GregtechMetaTileEntity_IndustrialFluidHeater.class) - .atLeast(OutputBus, OutputHatch, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing1, ofBlock(getCasingBlock2(), getCasingMeta2()))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 2, 4, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 2, 4, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing1 = 0; - boolean didBuild = checkPiece(mName, 2, 4, 0); - log("Built? "+didBuild+", "+mCasing1); - return didBuild && mCasing1 >= 34 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return TAE.getIndexFromPage(0, 1); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialThermalCentrifuge"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sFluidHeaterRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 120); - } - - @Override - public int getMaxParallelRecipes() { - return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 90; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialThermalCentrifuge; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock1() { - return ModBlocks.blockCasings2Misc; - } - - public byte getCasingMeta1() { - return 11; - } - - public Block getCasingBlock2() { - return ModBlocks.blockCasings3Misc; - } - - public byte getCasingMeta2() { - return 2; - } - - public byte getCasingTextureIndex() { - return (byte) TAE.getIndexFromPage(2, 2); - } - -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialFluidHeater + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialFluidHeater> + implements ISurvivalConstructable { + + private int mCasing1; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialFluidHeater> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialFluidHeater(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialFluidHeater(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialFluidHeater(this.mName); + } + + @Override + public String getMachineType() { + return "Fluid Heater"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Fluid Heater") + .addInfo("120% faster than using single block machines of the same voltage") + .addInfo("Only uses 90% of the EU/t normally required") + .addInfo("Processes eight items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 6, 5, true) + .addController("Front Center") + .addCasingInfo("Top/Bottom layer: Multi-use Casings", 34) + .addCasingInfo("Middle layers: Thermal Containment Casing", 47) + .addInputBus("Bottom Layer (optional)", 1) + .addInputHatch("Bottom Layer", 1) + .addOutputBus("Top Layer (optional)", 1) + .addOutputHatch("Top Layer", 1) + .addEnergyHatch("Any Multi-use Casing", 1) + .addMaintenanceHatch("Any Multi-use Casing", 1) + .addMufflerHatch("Any Multi-use Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialFluidHeater> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialFluidHeater>builder() + .addShape(mName, transpose(new String[][] { + {" TTT ", "TTTTT", "TTTTT", "TTTTT", " TTT "}, + {" XXX ", "X---X", "X---X", "X---X", " XXX "}, + {" XXX ", "X---X", "X---X", "X---X", " XXX "}, + {" XXX ", "X---X", "X---X", "X---X", " XXX "}, + {" X~X ", "X---X", "X---X", "X---X", " XXX "}, + {" BBB ", "BBBBB", "BBBBB", "BBBBB", " BBB "}, + })) + .addElement( + 'B', + buildHatchAdder(GregtechMetaTileEntity_IndustrialFluidHeater.class) + .atLeast(InputBus, InputHatch, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing1, ofBlock(getCasingBlock2(), getCasingMeta2())))) + .addElement('X', ofBlock(getCasingBlock1(), getCasingMeta1())) + .addElement( + 'T', + buildHatchAdder(GregtechMetaTileEntity_IndustrialFluidHeater.class) + .atLeast(OutputBus, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing1, ofBlock(getCasingBlock2(), getCasingMeta2())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 2, 4, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 2, 4, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing1 = 0; + boolean didBuild = checkPiece(mName, 2, 4, 0); + log("Built? " + didBuild + ", " + mCasing1); + return didBuild && mCasing1 >= 34 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(0, 1); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialThermalCentrifuge"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sFluidHeaterRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 120); + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 90; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialThermalCentrifuge; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock1() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta1() { + return 11; + } + + public Block getCasingBlock2() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta2() { + return 2; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.getIndexFromPage(2, 2); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialForgeHammer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialForgeHammer.java index 3fefffda7a..ba31a4753a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialForgeHammer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialForgeHammer.java @@ -1,8 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlocksFlat; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -23,301 +26,304 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlocksFlat; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialForgeHammer extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialForgeHammer> implements ISurvivalConstructable { - - private int mCasing; - private int mAnvil; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialForgeHammer> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialForgeHammer(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialForgeHammer(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - setAnvilBlocks(); - return new GregtechMetaTileEntity_IndustrialForgeHammer(this.mName); - } - - @Override - public String getMachineType() { - return "Forge Hammer"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Forge Hammer") - .addInfo("Speed: +100% | EU Usage: 100% | Parallel: Tier x Anvil Tier x 8") - .addInfo("T1 - Vanilla Anvil") - .addInfo("Anvil goes in Middle 3x3x3 Structure"); - if (LoadedMods.Railcraft) { - tt.addInfo("T2 - Steel Anvil"); - } - if (LoadedMods.EnderIO) { - tt.addInfo("T3 - Dark Steel Anvil"); - } - if (LoadedMods.ThaumicBases) { - tt.addInfo("T3 - Thaumic Anvil"); - tt.addInfo("T4 - Void Anvil"); - } - tt.addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front Center") - .addCasingInfo("Forge Casing", 10) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialForgeHammer> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - Map<Block, Integer> aBlockMap = new HashMap<Block, Integer>(); - aBlockMap.put(sAnvil, 0); - if (LoadedMods.Railcraft) { - aBlockMap.put(sSteelAnvil, 0); - } - if (LoadedMods.EnderIO) { - aBlockMap.put(sDarkSteelAnvil, 0); - } - if (LoadedMods.ThaumicBases) { - aBlockMap.put(sThaumiumAnvil, 0); - aBlockMap.put(sVoidAnvil, 0); - } - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialForgeHammer>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "CAC", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialForgeHammer.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(TAE.getIndexFromPage(1, 11)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings5Misc, 6))) - ) - .addElement('A', onElementPass(x -> ++x.mAnvil, ofBlocksFlat(aBlockMap, sAnvil, 0))) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - setAnvilBlocks(); - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - setAnvilBlocks(); - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(1); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return TAE.getIndexFromPage(1, 11); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "MaterialPress"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sHammerRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - Block aAnvil = this.getBaseMetaTileEntity().getBlockAtSide(this.getBaseMetaTileEntity().getBackFacing()); - if (aAnvil != null) { - int aAnvilTier = getAnvilTier(aAnvil); - if (aAnvilTier > 0) { - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); - tBus.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tBus)) { - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) - tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - if (checkRecipeGeneric(tBusItems.toArray(new ItemStack[]{}), new FluidStack[]{}, getMaxParallelRecipes() * aAnvilTier, 100, 100, 10000)) { - return true; - } - } - } - } - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialForgeHammer; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - private static Block sAnvil; - private static Block sSteelAnvil; - private static Block sDarkSteelAnvil; - private static Block sThaumiumAnvil; - private static Block sVoidAnvil; - - private static void setAnvilBlocks() { - if (sAnvil == null) { - sAnvil = Blocks.anvil; - if (LoadedMods.Railcraft) { - sSteelAnvil = GameRegistry.findBlock("Railcraft", "anvil"); - } - if (LoadedMods.EnderIO) { - sDarkSteelAnvil = GameRegistry.findBlock("EnderIO", "blockDarkSteelAnvil"); - } - if (LoadedMods.ThaumicBases) { - sThaumiumAnvil = GameRegistry.findBlock("thaumicbases", "thaumicAnvil"); - sVoidAnvil = GameRegistry.findBlock("thaumicbases", "voidAnvil"); - } - } - } - - public static boolean isBlockAnvil(Block aBlock) { - setAnvilBlocks(); - if (sAnvil == aBlock) { - return true; - } - if (LoadedMods.Railcraft) { - if (sSteelAnvil == aBlock) { - return true; - } - } - if (LoadedMods.EnderIO) { - if (sDarkSteelAnvil == aBlock) { - return true; - } - } - if (LoadedMods.ThaumicBases) { - if (sThaumiumAnvil == aBlock || sVoidAnvil == aBlock) { - return true; - } - } - return false; - } - - public static int getAnvilTier(Block aBlock) { - if (isBlockAnvil(aBlock)) { - if (sAnvil == aBlock) { - return 1; - } - if (LoadedMods.Railcraft) { - if (sSteelAnvil == aBlock) { - return 2; - } - } - if (LoadedMods.EnderIO) { - if (sDarkSteelAnvil == aBlock) { - return 3; - } - } - if (LoadedMods.ThaumicBases) { - if (sThaumiumAnvil == aBlock) { - return 3; - } - if (sVoidAnvil == aBlock) { - return 4; - } - } - } - return 0; - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - setAnvilBlocks(); - super.onFirstTick(aBaseMetaTileEntity); - } - +public class GregtechMetaTileEntity_IndustrialForgeHammer + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialForgeHammer> + implements ISurvivalConstructable { + + private int mCasing; + private int mAnvil; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialForgeHammer> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialForgeHammer(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialForgeHammer(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + setAnvilBlocks(); + return new GregtechMetaTileEntity_IndustrialForgeHammer(this.mName); + } + + @Override + public String getMachineType() { + return "Forge Hammer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Forge Hammer") + .addInfo("Speed: +100% | EU Usage: 100% | Parallel: Tier x Anvil Tier x 8") + .addInfo("T1 - Vanilla Anvil") + .addInfo("Anvil goes in Middle 3x3x3 Structure"); + if (LoadedMods.Railcraft) { + tt.addInfo("T2 - Steel Anvil"); + } + if (LoadedMods.EnderIO) { + tt.addInfo("T3 - Dark Steel Anvil"); + } + if (LoadedMods.ThaumicBases) { + tt.addInfo("T3 - Thaumic Anvil"); + tt.addInfo("T4 - Void Anvil"); + } + tt.addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Forge Casing", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialForgeHammer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + Map<Block, Integer> aBlockMap = new HashMap<Block, Integer>(); + aBlockMap.put(sAnvil, 0); + if (LoadedMods.Railcraft) { + aBlockMap.put(sSteelAnvil, 0); + } + if (LoadedMods.EnderIO) { + aBlockMap.put(sDarkSteelAnvil, 0); + } + if (LoadedMods.ThaumicBases) { + aBlockMap.put(sThaumiumAnvil, 0); + aBlockMap.put(sVoidAnvil, 0); + } + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialForgeHammer>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "CAC", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialForgeHammer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(TAE.getIndexFromPage(1, 11)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings5Misc, 6)))) + .addElement('A', onElementPass(x -> ++x.mAnvil, ofBlocksFlat(aBlockMap, sAnvil, 0))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + setAnvilBlocks(); + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + setAnvilBlocks(); + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(1); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(1, 11); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MaterialPress"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sHammerRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + Block aAnvil = this.getBaseMetaTileEntity() + .getBlockAtSide(this.getBaseMetaTileEntity().getBackFacing()); + if (aAnvil != null) { + int aAnvilTier = getAnvilTier(aAnvil); + if (aAnvilTier > 0) { + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + if (checkRecipeGeneric( + tBusItems.toArray(new ItemStack[] {}), + new FluidStack[] {}, + getMaxParallelRecipes() * aAnvilTier, + 100, + 100, + 10000)) { + return true; + } + } + } + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialForgeHammer; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private static Block sAnvil; + private static Block sSteelAnvil; + private static Block sDarkSteelAnvil; + private static Block sThaumiumAnvil; + private static Block sVoidAnvil; + + private static void setAnvilBlocks() { + if (sAnvil == null) { + sAnvil = Blocks.anvil; + if (LoadedMods.Railcraft) { + sSteelAnvil = GameRegistry.findBlock("Railcraft", "anvil"); + } + if (LoadedMods.EnderIO) { + sDarkSteelAnvil = GameRegistry.findBlock("EnderIO", "blockDarkSteelAnvil"); + } + if (LoadedMods.ThaumicBases) { + sThaumiumAnvil = GameRegistry.findBlock("thaumicbases", "thaumicAnvil"); + sVoidAnvil = GameRegistry.findBlock("thaumicbases", "voidAnvil"); + } + } + } + + public static boolean isBlockAnvil(Block aBlock) { + setAnvilBlocks(); + if (sAnvil == aBlock) { + return true; + } + if (LoadedMods.Railcraft) { + if (sSteelAnvil == aBlock) { + return true; + } + } + if (LoadedMods.EnderIO) { + if (sDarkSteelAnvil == aBlock) { + return true; + } + } + if (LoadedMods.ThaumicBases) { + if (sThaumiumAnvil == aBlock || sVoidAnvil == aBlock) { + return true; + } + } + return false; + } + + public static int getAnvilTier(Block aBlock) { + if (isBlockAnvil(aBlock)) { + if (sAnvil == aBlock) { + return 1; + } + if (LoadedMods.Railcraft) { + if (sSteelAnvil == aBlock) { + return 2; + } + } + if (LoadedMods.EnderIO) { + if (sDarkSteelAnvil == aBlock) { + return 3; + } + } + if (LoadedMods.ThaumicBases) { + if (sThaumiumAnvil == aBlock) { + return 3; + } + if (sVoidAnvil == aBlock) { + return 4; + } + } + } + return 0; + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + setAnvilBlocks(); + super.onFirstTick(aBaseMetaTileEntity); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java index 43a1686b2e..b06d416fef 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java @@ -1,6 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.Random; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -18,255 +23,248 @@ import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.Random; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; +public class GregtechMetaTileEntity_IndustrialMacerator + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMacerator> + implements ISurvivalConstructable { -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + private int mCasing; + private int mPerLayer; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialMacerator> STRUCTURE_DEFINITION = null; -public class GregtechMetaTileEntity_IndustrialMacerator extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMacerator> implements ISurvivalConstructable { - - private int mCasing; - private int mPerLayer; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialMacerator> STRUCTURE_DEFINITION = null; + public GregtechMetaTileEntity_IndustrialMacerator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } - public GregtechMetaTileEntity_IndustrialMacerator(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } + public GregtechMetaTileEntity_IndustrialMacerator(final String aName) { + super(aName); + } - public GregtechMetaTileEntity_IndustrialMacerator(final String aName) { - super(aName); - } + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMacerator(this.mName); + } - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialMacerator(this.mName); - } + @Override + public String getMachineType() { + return "Macerator/Pulverizer"; + } - @Override - public String getMachineType() { - return "Macerator/Pulverizer"; - } + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Maceration Stack") + .addInfo("60% faster than using single block machines of the same voltage") + .addInfo("Processes 8*tier materials at a time") + .addInfo("ULV = Tier 0, LV = Tier 1, etc.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 6, 3, true) + .addController("Bottom Center") + .addCasingInfo("Maceration Stack Casings", 26) + .addInputBus("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addOutputBus("One per layer except bottom layer", 2) + .addMufflerHatch("Any Casing", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Maceration Stack") - .addInfo("60% faster than using single block machines of the same voltage") - .addInfo("Processes 8*tier materials at a time") - .addInfo("ULV = Tier 0, LV = Tier 1, etc.") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 6, 3, true) - .addController("Bottom Center") - .addCasingInfo("Maceration Stack Casings", 26) - .addInputBus("Bottom Casing", 1) - .addEnergyHatch("Bottom Casing", 1) - .addMaintenanceHatch("Bottom Casing", 1) - .addOutputBus("One per layer except bottom layer", 2) - .addMufflerHatch("Any Casing", 2) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMacerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMacerator>builder() + .addShape(mName + "top", transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + })) + .addShape(mName + "mid", transpose(new String[][] { + {"CCC", "C-C", "CCC"}, + })) + .addShape(mName + "bottom", transpose(new String[][] { + {"B~B", "BBB", "BBB"}, + })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) + .atLeast(OutputBus) + .shouldReject(t -> t.mPerLayer + 1 == t.mOutputBusses.size()) + .casingIndex(TAE.GTPP_INDEX(7)) + .dot(2) + .build(), + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) + .atLeast(Energy, Maintenance, Muffler) + .shouldReject(t -> t.mPerLayer + 1 == t.mOutputBusses.size()) + .casingIndex(TAE.GTPP_INDEX(7)) + .dot(2) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 7)))) + .addElement( + 'B', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) + .atLeast(Energy, Maintenance, InputBus) + .casingIndex(TAE.GTPP_INDEX(7)) + .dot(2) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 7)))) + .build(); + } + return STRUCTURE_DEFINITION; + } - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialMacerator> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMacerator>builder() - .addShape(mName + "top", transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - })) - .addShape(mName + "mid", transpose(new String[][]{ - {"CCC", "C-C", "CCC"}, - })) - .addShape(mName + "bottom", transpose(new String[][]{ - {"B~B", "BBB", "BBB"}, - })) - .addElement( - 'C', - ofChain( - buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) - .atLeast(OutputBus) - .shouldReject(t -> t.mPerLayer + 1 == t.mOutputBusses.size()) - .casingIndex(TAE.GTPP_INDEX(7)) - .dot(2) - .build(), - buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) - .atLeast(Energy, Maintenance, Muffler) - .shouldReject(t -> t.mPerLayer + 1 == t.mOutputBusses.size()) - .casingIndex(TAE.GTPP_INDEX(7)) - .dot(2) - .build(), - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasingsMisc, 7 - ) - ) - ) - ) - .addElement( - 'B', - ofChain( - buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) - .atLeast(Energy, Maintenance, InputBus) - .casingIndex(TAE.GTPP_INDEX(7)) - .dot(2) - .build(), - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasingsMisc, 7 - ) - ) - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName + "bottom", stackSize, hintsOnly, 1, 0, 0); + buildPiece(mName + "mid", stackSize, hintsOnly, 1, 1, 0); + buildPiece(mName + "mid", stackSize, hintsOnly, 1, 2, 0); + buildPiece(mName + "mid", stackSize, hintsOnly, 1, 3, 0); + buildPiece(mName + "mid", stackSize, hintsOnly, 1, 4, 0); + buildPiece(mName + "top", stackSize, hintsOnly, 1, 5, 0); + } - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName + "bottom", stackSize, hintsOnly, 1, 0, 0); - buildPiece(mName + "mid", stackSize, hintsOnly, 1, 1, 0); - buildPiece(mName + "mid", stackSize, hintsOnly, 1, 2, 0); - buildPiece(mName + "mid", stackSize, hintsOnly, 1, 3, 0); - buildPiece(mName + "mid", stackSize, hintsOnly, 1, 4, 0); - buildPiece(mName + "top", stackSize, hintsOnly, 1, 5, 0); - } + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + int built; + built = survivialBuildPiece(mName + "bottom", stackSize, 1, 0, 0, elementBudget, source, actor, false, true); + mPerLayer = 0; + if (built >= 0) return built; + built = survivialBuildPiece(mName + "mid", stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + mPerLayer = 1; + if (built >= 0) return built; + built = survivialBuildPiece(mName + "mid", stackSize, 1, 2, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + mPerLayer = 2; + built = survivialBuildPiece(mName + "mid", stackSize, 1, 3, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + mPerLayer = 3; + built = survivialBuildPiece(mName + "mid", stackSize, 1, 4, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + return survivialBuildPiece(mName + "top", stackSize, 1, 5, 0, elementBudget, source, actor, false, true); + } - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - int built; - built = survivialBuildPiece(mName + "bottom", stackSize, 1, 0, 0, elementBudget, source, actor, false, true); - mPerLayer = 0; - if (built >= 0) return built; - built = survivialBuildPiece(mName + "mid", stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - mPerLayer = 1; - if (built >= 0) return built; - built = survivialBuildPiece(mName + "mid", stackSize, 1, 2, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - mPerLayer = 2; - built = survivialBuildPiece(mName + "mid", stackSize, 1, 3, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - mPerLayer = 3; - built = survivialBuildPiece(mName + "mid", stackSize, 1, 4, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - return survivialBuildPiece(mName + "top", stackSize, 1, 5, 0, elementBudget, source, actor, false, true); - } + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mPerLayer = 0; + if (checkPiece(mName + "bottom", 1, 0, 0)) { + while (mPerLayer < 4) { + if (!checkPiece(mName + "mid", 1, mPerLayer + 1, 0) || mPerLayer + 1 != mOutputBusses.size()) + return false; + mPerLayer++; + } + return checkPiece(mName + "top", 1, 5, 0) && mOutputBusses.size() == 5 && mCasing >= 26 && checkHatch(); + } + return false; + } - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mPerLayer = 0; - if (checkPiece(mName + "bottom", 1, 0 ,0)) { - while (mPerLayer < 4) { - if (!checkPiece(mName + "mid", 1, mPerLayer + 1, 0) || - mPerLayer + 1 != mOutputBusses.size()) return false; - mPerLayer ++; - } - return checkPiece(mName + "top", 1, 5, 0) && mOutputBusses.size() == 5 && mCasing >= 26 && checkHatch(); - } - return false; - } + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(201)); + } - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(201)); - } + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_MatterFab_Active; + } - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_MatterFab_Active; - } + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_MatterFab; + } - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_MatterFab; - } + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(7); + } - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(7); - } + @Override + public boolean hasSlotInGUI() { + return false; + } - @Override - public boolean hasSlotInGUI() { - return false; - } + @Override + public String getCustomGUIResourceName() { + return "MacerationStack"; + } - @Override - public String getCustomGUIResourceName() { - return "MacerationStack"; - } + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; + } - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; - } + @Override + public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if ((aBaseMetaTileEntity.isClientSide()) + && (aBaseMetaTileEntity.isActive()) + && (aBaseMetaTileEntity.getFrontFacing() != 1) + && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) + && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "smoke", + (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), + aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), + (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), + 0.0D, + 0.0D, + 0.0D); + } + } - @Override - public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) && (aBaseMetaTileEntity.getFrontFacing() != 1) && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { - final Random tRandom = aBaseMetaTileEntity.getWorld().rand; - aBaseMetaTileEntity.getWorld().spawnParticle("smoke", (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), 0.0D, 0.0D, 0.0D); - } - } + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 60, 7500); + } - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 60, 7500); - } - - @Override - protected boolean doesMachineBoostOutput() { - return true; - } - - @Override - public int getMaxParallelRecipes() { - final long tVoltage = getMaxInputVoltage(); - final byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - return Math.max(1, 8 * tTier); - } + @Override + protected boolean doesMachineBoostOutput() { + return true; + } - @Override - public int getEuDiscountForParallelism() { - return 100; - } + @Override + public int getMaxParallelRecipes() { + final long tVoltage = getMaxInputVoltage(); + final byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + return Math.max(1, 8 * tTier); + } - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } + @Override + public int getEuDiscountForParallelism() { + return 100; + } - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMacerator; - } + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } - @Override - public int getAmountOfOutputs() { - return 16; - } + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMacerator; + } - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } + @Override + public int getAmountOfOutputs() { + return 16; + } - @Override - public boolean isOverclockerUpgradable() { - return true; - } + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } -}
\ No newline at end of file + @Override + public boolean isOverclockerUpgradable() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java index 03a71ea918..356d72ff88 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java @@ -1,6 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -19,210 +23,198 @@ import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialMixer extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMixer> implements ISurvivalConstructable { - - public static int CASING_TEXTURE_ID; - public static String mCasingName = "Multi-Use Casing"; - public static String mCasingName2 = "Titanium Turbine Casing"; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialMixer> STRUCTURE_DEFINITION = null; - - - public GregtechMetaTileEntity_IndustrialMixer(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 2); - } - - public GregtechMetaTileEntity_IndustrialMixer(final String aName) { - super(aName); - CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 2); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialMixer(this.mName); - } - - @Override - public String getMachineType() { - return "Mixer"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Mixer") - .addInfo("250% faster than using single block machines of the same voltage") - .addInfo("Processes eight recipes per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 4, 3, false) - .addController("Second Layer Center") - .addCasingInfo(mCasingName, 16) - .addCasingInfo(mCasingName2, 2) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialMixer> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMixer>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"CCC", "CMC", "CCC"}, - {"C~C", "CMC", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialMixer.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 2))) - ) - .addElement( - 'M', - ofBlock( - GregTech_API.sBlockCasings4, 11 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 2, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 2, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 2, 0) && mCasing >= 16 && checkHatch(); - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(203)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return CASING_TEXTURE_ID; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialMixer"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map.sMultiblockMixerRecipes_GT; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); - tBus.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tBus)) { - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) - tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - ItemStack[] inputs = new ItemStack[tBusItems.size()]; - int slot = 0; - for (ItemStack g : tBusItems) { - inputs[slot++] = g; - } - log("Recipe. ["+inputs.length+"]["+getMaxParallelRecipes()+"]"); - FluidStack[] fluid = this.getStoredFluids().toArray(new FluidStack[] {}); - if (checkRecipeGeneric(inputs,fluid , getMaxParallelRecipes(), getEuDiscountForParallelism(), 250, 10000)) { - log("Recipe 2."); - return true; - } - - } - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMixer; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } +public class GregtechMetaTileEntity_IndustrialMixer + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMixer> implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + public static String mCasingName = "Multi-Use Casing"; + public static String mCasingName2 = "Titanium Turbine Casing"; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialMixer> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialMixer(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 2); + } + + public GregtechMetaTileEntity_IndustrialMixer(final String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 2); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMixer(this.mName); + } + + @Override + public String getMachineType() { + return "Mixer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Mixer") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes eight recipes per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, false) + .addController("Second Layer Center") + .addCasingInfo(mCasingName, 16) + .addCasingInfo(mCasingName2, 2) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMixer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMixer>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"CCC", "CMC", "CCC"}, + {"C~C", "CMC", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialMixer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 2)))) + .addElement('M', ofBlock(GregTech_API.sBlockCasings4, 11)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 2, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 2, 0) && mCasing >= 16 && checkHatch(); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(203)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialMixer"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map.sMultiblockMixerRecipes_GT; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + ItemStack[] inputs = new ItemStack[tBusItems.size()]; + int slot = 0; + for (ItemStack g : tBusItems) { + inputs[slot++] = g; + } + log("Recipe. [" + inputs.length + "][" + getMaxParallelRecipes() + "]"); + FluidStack[] fluid = this.getStoredFluids().toArray(new FluidStack[] {}); + if (checkRecipeGeneric(inputs, fluid, getMaxParallelRecipes(), getEuDiscountForParallelism(), 250, 10000)) { + log("Recipe 2."); + return true; + } + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMixer; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMolecularTransformer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMolecularTransformer.java index d4a505cc2e..dcca512e1a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMolecularTransformer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMolecularTransformer.java @@ -1,5 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -21,226 +26,224 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialMolecularTransformer extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMolecularTransformer> implements ISurvivalConstructable { - - private static final int CASING_TEXTURE_ID = 48; - private int mCasing = 0; - - public GregtechMetaTileEntity_IndustrialMolecularTransformer(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialMolecularTransformer(final String aName) { - super(aName); - } - - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialMolecularTransformer(this.mName); - } - - @Override - public String getMachineType() { - return "Molecular Transformer"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Changes the structure of items to produce new ones") - .addInfo("Maximum 1x of each bus/hatch.") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(7, 7, 7, false) - .addController("Top Center") - .addCasingInfo("Robust Tungstensteel Machine Casing", 40) - .addCasingInfo("Tungstensteel Coils", 16) - .addCasingInfo("Molecular Containment Casing", 52) - .addCasingInfo("High Voltage Current Capacitor", 32) - .addCasingInfo("Particle Containment Casing", 4) - .addCasingInfo("Resonance Chamber I", 5) - .addCasingInfo("Modulator I", 4) - .addInputBus("Any Robust Tungstensteel Machine Casing", 1) - .addOutputBus("Any Robust Tungstensteel Machine Casing", 1) - .addEnergyHatch("Any Robust Tungstensteel Machine Casing", 1) - .addMaintenanceHatch("Any Robust Tungstensteel Machine Casing", 1) - .addMufflerHatch("Any Robust Tungstensteel Machine Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - - private static final String STRUCTURE_PIECE_MAIN = "main"; - private static IStructureDefinition<GregtechMetaTileEntity_IndustrialMolecularTransformer> STRUCTURE_DEFINITION = null; - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialMolecularTransformer> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMolecularTransformer>builder() - .addShape(STRUCTURE_PIECE_MAIN, (new String[][]{ - {" ", " ", " xxx ", " x~x ", " xxx ", " ", " "}, - {" ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " "}, - {" ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " "}, - {" ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " "}, - {" t ", " ttxtt ", " tyyyt ", "txyzyxt", " tyyyt ", " ttxtt ", " t "}, - {" c ", " ccecc ", " cxfxc ", "cefefec", " cxfxc ", " ccecc ", " c "}, - {" h ", " hhhhh ", " hhhhh ", "hhhhhhh", " hhhhh ", " hhhhh ", " h "}, - })) - - .addElement('x', ofBlock(getCasingBlock(), getCasingMeta())) - .addElement('y', ofBlock(getCasingBlock(), getCasingMeta2())) - .addElement('z', ofBlock(getCasingBlock(), getCasingMeta3())) - .addElement('e', ofBlock(getCasingBlock2(), 0)) - .addElement('f', ofBlock(getCasingBlock2(), 4)) - .addElement('c', ofBlock(getCoilBlock(), 3)) - .addElement('t', ofBlock(getCasingBlock3(), getTungstenCasingMeta())) - .addElement('h', buildHatchAdder(GregtechMetaTileEntity_IndustrialMolecularTransformer.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock3(), getTungstenCasingMeta()))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 3, 3, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 3, 3, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - boolean aDidBuild = checkPiece(STRUCTURE_PIECE_MAIN, 3, 3, 0); - if (this.mInputBusses.size() != 1 || this.mOutputBusses.size() != 1 || this.mEnergyHatches.size() != 1) { - return false; - } - // there are 16 slot that only allow casing, so we subtract this from the grand total required - return aDidBuild && mCasing >= 40 - 16 && checkHatch(); - } - - protected static int getCasingTextureIndex() { - return CASING_TEXTURE_ID; - } - - protected static Block getCasingBlock() { - return ModBlocks.blockSpecialMultiCasings; - } - - protected static Block getCasingBlock2() { - return ModBlocks.blockSpecialMultiCasings2; - } - - protected static Block getCasingBlock3() { - return GregTech_API.sBlockCasings4; - } - - protected static Block getCoilBlock() { - return GregTech_API.sBlockCasings5; - } - - protected static int getCasingMeta() { - return 11; - } - - protected static int getCasingMeta2() { - return 12; - } - - protected static int getCasingMeta3() { - return 13; - } - - protected static int getTungstenCasingMeta() { - return 0; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return 44; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe_Map.sMolecularTransformerRecipes; - } - - public boolean isCorrectMachinePart(final ItemStack aStack) { - return true; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(); - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiMolecularTransformer; - } - - public int getDamageToComponent(final ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public boolean isNewExtendedFacingValid(ExtendedFacing alignment) { - return alignment.getDirection() == ForgeDirection.UP && super.isNewExtendedFacingValid(alignment); - } +public class GregtechMetaTileEntity_IndustrialMolecularTransformer + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMolecularTransformer> + implements ISurvivalConstructable { + + private static final int CASING_TEXTURE_ID = 48; + private int mCasing = 0; + + public GregtechMetaTileEntity_IndustrialMolecularTransformer( + final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialMolecularTransformer(final String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMolecularTransformer(this.mName); + } + + @Override + public String getMachineType() { + return "Molecular Transformer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Changes the structure of items to produce new ones") + .addInfo("Maximum 1x of each bus/hatch.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(7, 7, 7, false) + .addController("Top Center") + .addCasingInfo("Robust Tungstensteel Machine Casing", 40) + .addCasingInfo("Tungstensteel Coils", 16) + .addCasingInfo("Molecular Containment Casing", 52) + .addCasingInfo("High Voltage Current Capacitor", 32) + .addCasingInfo("Particle Containment Casing", 4) + .addCasingInfo("Resonance Chamber I", 5) + .addCasingInfo("Modulator I", 4) + .addInputBus("Any Robust Tungstensteel Machine Casing", 1) + .addOutputBus("Any Robust Tungstensteel Machine Casing", 1) + .addEnergyHatch("Any Robust Tungstensteel Machine Casing", 1) + .addMaintenanceHatch("Any Robust Tungstensteel Machine Casing", 1) + .addMufflerHatch("Any Robust Tungstensteel Machine Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialMolecularTransformer> STRUCTURE_DEFINITION = + null; + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMolecularTransformer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMolecularTransformer>builder() + .addShape(STRUCTURE_PIECE_MAIN, (new String[][] { + {" ", " ", " xxx ", " x~x ", " xxx ", " ", " "}, + {" ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " "}, + {" ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " "}, + {" ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " "}, + {" t ", " ttxtt ", " tyyyt ", "txyzyxt", " tyyyt ", " ttxtt ", " t "}, + {" c ", " ccecc ", " cxfxc ", "cefefec", " cxfxc ", " ccecc ", " c "}, + {" h ", " hhhhh ", " hhhhh ", "hhhhhhh", " hhhhh ", " hhhhh ", " h "}, + })) + .addElement('x', ofBlock(getCasingBlock(), getCasingMeta())) + .addElement('y', ofBlock(getCasingBlock(), getCasingMeta2())) + .addElement('z', ofBlock(getCasingBlock(), getCasingMeta3())) + .addElement('e', ofBlock(getCasingBlock2(), 0)) + .addElement('f', ofBlock(getCasingBlock2(), 4)) + .addElement('c', ofBlock(getCoilBlock(), 3)) + .addElement('t', ofBlock(getCasingBlock3(), getTungstenCasingMeta())) + .addElement( + 'h', + buildHatchAdder(GregtechMetaTileEntity_IndustrialMolecularTransformer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock3(), getTungstenCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 3, 3, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + boolean aDidBuild = checkPiece(STRUCTURE_PIECE_MAIN, 3, 3, 0); + if (this.mInputBusses.size() != 1 || this.mOutputBusses.size() != 1 || this.mEnergyHatches.size() != 1) { + return false; + } + // there are 16 slot that only allow casing, so we subtract this from the grand total required + return aDidBuild && mCasing >= 40 - 16 && checkHatch(); + } + + protected static int getCasingTextureIndex() { + return CASING_TEXTURE_ID; + } + + protected static Block getCasingBlock() { + return ModBlocks.blockSpecialMultiCasings; + } + + protected static Block getCasingBlock2() { + return ModBlocks.blockSpecialMultiCasings2; + } + + protected static Block getCasingBlock3() { + return GregTech_API.sBlockCasings4; + } + + protected static Block getCoilBlock() { + return GregTech_API.sBlockCasings5; + } + + protected static int getCasingMeta() { + return 11; + } + + protected static int getCasingMeta2() { + return 12; + } + + protected static int getCasingMeta3() { + return 13; + } + + protected static int getTungstenCasingMeta() { + return 0; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return 44; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe_Map.sMolecularTransformerRecipes; + } + + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(); + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiMolecularTransformer; + } + + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean isNewExtendedFacingValid(ExtendedFacing alignment) { + return alignment.getDirection() == ForgeDirection.UP && super.isNewExtendedFacingValid(alignment); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java index 4fe8848397..f3e54a3f1a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java @@ -1,7 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -21,6 +25,8 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -29,500 +35,493 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_IndustrialMultiMachine extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMultiMachine> implements ISurvivalConstructable { - - protected int mInternalMode = 0; - protected GT_Recipe[] mLastRecipeExtended = new GT_Recipe[9]; - private static final int MODE_COMPRESSOR = 0; - private static final int MODE_LATHE = 1; - private static final int MODE_MAGNETIC = 2; - private static final int MODE_FERMENTER = 3; - private static final int MODE_FLUIDEXTRACT = 4; - private static final int MODE_EXTRACTOR = 5; - private static final int MODE_LASER = 6; - private static final int MODE_AUTOCLAVE = 7; - private static final int MODE_FLUIDSOLIDIFY = 8; - private static final int[][] MODE_MAP = new int[][] {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}; - public static final String[] aToolTipNames = new String[9]; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialMultiMachine> STRUCTURE_DEFINITION = null; - - static { - for (int id = 0; id < 9; id++) { - GT_Recipe.GT_Recipe_Map recipeMap = getRecipeMap(id); - if (recipeMap != null) { - String aNEI = GT_LanguageManager.getTranslation(getRecipeMap(id).mNEIName); - aToolTipNames[id] = aNEI != null ? aNEI : "BAD NEI NAME (Report to Github)"; - } - } - } - - - public GregtechMetaTileEntity_IndustrialMultiMachine(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialMultiMachine(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialMultiMachine(this.mName); - } - - @Override - public String getMachineType() { - return "Nine in One"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - String[] aBuiltStrings = new String[3]; - aBuiltStrings[0] = aToolTipNames[0] + ", " + aToolTipNames[1] + ", " + aToolTipNames[2]; - aBuiltStrings[1] = aToolTipNames[3] + ", " + aToolTipNames[4] + ", " + aToolTipNames[5]; - aBuiltStrings[2] = aToolTipNames[6] + ", " + aToolTipNames[7] + ", " + aToolTipNames[8]; - - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Multi-Machine") - .addInfo("250% faster than using single block machines of the same voltage") - .addInfo("Only uses 80% of the EU/t normally required") - .addInfo("Processes two items per voltage tier") - .addInfo("Machine Type: [A] - " + EnumChatFormatting.YELLOW + aBuiltStrings[0] + EnumChatFormatting.RESET) - .addInfo("Machine Type: [B] - " + EnumChatFormatting.YELLOW + aBuiltStrings[1] + EnumChatFormatting.RESET) - .addInfo("Machine Type: [C] - " + EnumChatFormatting.YELLOW + aBuiltStrings[2] + EnumChatFormatting.RESET) - .addInfo("Read Multi-Machine Manual for extra information") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front Center") - .addCasingInfo("Multi-Use Casings", 6) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialMultiMachine> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMultiMachine>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialMultiMachine.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(getTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 2))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return getTextureIndex(); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "Generic3By3"; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - ArrayList<FluidStack> tFluids = getStoredFluids(); - //Logger.MACHINE_INFO("1"); - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); - tBus.mRecipeMap = getRecipeMap(); - //Logger.MACHINE_INFO("2"); - if (isValidMetaTileEntity(tBus)) { - //Logger.MACHINE_INFO("3"); - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) - tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - - boolean aFoundCircuitInBus = false; - for (ItemStack aBusItem : tBusItems) { - if (ItemUtils.isControlCircuit(aBusItem)) { - aFoundCircuitInBus = true; - } - } - if (!aFoundCircuitInBus) { - continue; - } - - Object[] tempArray = tFluids.toArray(new FluidStack[] {}); - FluidStack[] properArray; - properArray = ((tempArray != null && tempArray.length > 0) ? (FluidStack[]) tempArray : new FluidStack[] {}); - - //Logger.MACHINE_INFO("4"); - if (checkRecipeGeneric(tBusItems.toArray(new ItemStack[]{}), properArray, - (2*GT_Utility.getTier(this.getMaxInputVoltage())), 80, 250, 10000)) return true; - } - return false; - - //return checkRecipeGeneric(2*GT_Utility.getTier(this.getMaxInputVoltage()), 90, 180); - } - - @Override - public int getMaxParallelRecipes() { - return (2 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 80; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - if (mInternalMode == 0) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeMetal; - } - else if (mInternalMode == 1) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeFluid; - } - else { //config 2 - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeMisc; - } - } - - public int getTextureIndex() { - return TAE.getIndexFromPage(2, 2); - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - private ItemStack getCircuit(ItemStack[] t) { - for (ItemStack j : t) { - if (j.getItem() == CI.getNumberedCircuit(0).getItem()) { - if (j.getItemDamage() >= 20 && j.getItemDamage() <= 22) { - return j; - } - } - } - return null; - } - - private final int getCircuitID(ItemStack circuit) { - int H = circuit.getItemDamage(); - int T = (H == 20 ? 0 : (H == 21 ? 1 : (H == 22 ? 2 : -1))); - return MODE_MAP[this.mInternalMode][T]; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return null; - } - - private final GT_Recipe.GT_Recipe_Map getRecipeMap(ItemStack circuit) { - return getRecipeMap(getCircuitID(circuit)); - } - - private static final GT_Recipe.GT_Recipe_Map getRecipeMap(int aMode) { - if (aMode == MODE_COMPRESSOR) { - return GT_Recipe.GT_Recipe_Map.sCompressorRecipes; - } - else if (aMode == MODE_LATHE) { - return GT_Recipe.GT_Recipe_Map.sLatheRecipes; - } - else if (aMode == MODE_MAGNETIC) { - return GT_Recipe.GT_Recipe_Map.sPolarizerRecipes; - } - else if (aMode == MODE_FERMENTER) { - return GT_Recipe.GT_Recipe_Map.sFermentingRecipes; - } - else if (aMode == MODE_FLUIDEXTRACT) { - return GT_Recipe.GT_Recipe_Map.sFluidExtractionRecipes; - } - else if (aMode == MODE_EXTRACTOR) { - return GT_Recipe.GT_Recipe_Map.sExtractorRecipes; - } - else if (aMode == MODE_LASER) { - return GT_Recipe.GT_Recipe_Map.sLaserEngraverRecipes; - } - else if (aMode == MODE_AUTOCLAVE) { - return GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes; - } - else if (aMode == MODE_FLUIDSOLIDIFY) { - return GT_Recipe.GT_Recipe_Map.sFluidSolidficationRecipes; - } - else { - return null; - } - } - - @Override - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll) { - - // Based on the Processing Array. A bit overkill, but very flexible. - - // Get Circuit info for this recipe. - ItemStack tCircuit = getCircuit(aItemInputs); - int tCircuitID = getCircuitID(tCircuit); - - Logger.MACHINE_INFO("Mode: "+tCircuitID); - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - - GT_Recipe.GT_Recipe_Map tRecipeMap = this.getRecipeMap(tCircuit); - if (tRecipeMap == null) - return false; - GT_Recipe tRecipe = tRecipeMap.findRecipe( - getBaseMetaTileEntity(), this.mLastRecipeExtended[tCircuitID], false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - - // Remember last recipe - an optimization for findRecipe() - //this.mLastRecipe = tRecipe; //Let's not do this, it's bad. - //Instead, how about I use a array for types? - this.mLastRecipeExtended[tCircuitID] = tRecipe; - - if (tRecipe == null) { - Logger.MACHINE_INFO("BAD RETURN - 1|"+tCircuitID); - - if (aItemInputs.length > 0) { - Logger.MACHINE_INFO("Input Items: "+ItemUtils.getArrayStackNames(aItemInputs)); - } - if (aFluidInputs.length > 0) { - Logger.MACHINE_INFO("Input Fluids: "+ItemUtils.getFluidArrayStackNames(aFluidInputs)); - } - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - Logger.MACHINE_INFO("BAD RETURN - 2|"+tCircuitID); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - - Logger.WARNING("parallelRecipes: "+parallelRecipes); - Logger.WARNING("aMaxParallelRecipes: "+aMaxParallelRecipes); - Logger.WARNING("tTotalEUt: "+tTotalEUt); - Logger.WARNING("tVoltage: "+tVoltage); - Logger.WARNING("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - Logger.WARNING("Broke at "+parallelRecipes+"."); - break; - } - Logger.WARNING("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - Logger.MACHINE_INFO("BAD RETURN - 3|"+tCircuitID); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - Logger.MACHINE_INFO("GOOD RETURN - 1|"+tCircuitID); - return true; - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (mInternalMode < 2) { - mInternalMode++; - } - else { - mInternalMode = 0; - } - String mModeString = (mInternalMode == 0 ? "Metal" : mInternalMode == 1 ? "Fluid" : mInternalMode == 2 ? "Misc." : "null"); - PlayerUtils.messagePlayer(aPlayer, "Multi-Machine is now in "+mModeString+" mode."); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mInternalMode", mInternalMode); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - this.mInternalMode = aNBT.getInteger("mInternalMode"); - super.loadNBTData(aNBT); - } - - -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialMultiMachine + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMultiMachine> + implements ISurvivalConstructable { + + protected int mInternalMode = 0; + protected GT_Recipe[] mLastRecipeExtended = new GT_Recipe[9]; + private static final int MODE_COMPRESSOR = 0; + private static final int MODE_LATHE = 1; + private static final int MODE_MAGNETIC = 2; + private static final int MODE_FERMENTER = 3; + private static final int MODE_FLUIDEXTRACT = 4; + private static final int MODE_EXTRACTOR = 5; + private static final int MODE_LASER = 6; + private static final int MODE_AUTOCLAVE = 7; + private static final int MODE_FLUIDSOLIDIFY = 8; + private static final int[][] MODE_MAP = new int[][] {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}; + public static final String[] aToolTipNames = new String[9]; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialMultiMachine> STRUCTURE_DEFINITION = null; + + static { + for (int id = 0; id < 9; id++) { + GT_Recipe.GT_Recipe_Map recipeMap = getRecipeMap(id); + if (recipeMap != null) { + String aNEI = GT_LanguageManager.getTranslation(getRecipeMap(id).mNEIName); + aToolTipNames[id] = aNEI != null ? aNEI : "BAD NEI NAME (Report to Github)"; + } + } + } + + public GregtechMetaTileEntity_IndustrialMultiMachine( + final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialMultiMachine(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMultiMachine(this.mName); + } + + @Override + public String getMachineType() { + return "Nine in One"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + String[] aBuiltStrings = new String[3]; + aBuiltStrings[0] = aToolTipNames[0] + ", " + aToolTipNames[1] + ", " + aToolTipNames[2]; + aBuiltStrings[1] = aToolTipNames[3] + ", " + aToolTipNames[4] + ", " + aToolTipNames[5]; + aBuiltStrings[2] = aToolTipNames[6] + ", " + aToolTipNames[7] + ", " + aToolTipNames[8]; + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Multi-Machine") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Only uses 80% of the EU/t normally required") + .addInfo("Processes two items per voltage tier") + .addInfo("Machine Type: [A] - " + EnumChatFormatting.YELLOW + aBuiltStrings[0] + + EnumChatFormatting.RESET) + .addInfo("Machine Type: [B] - " + EnumChatFormatting.YELLOW + aBuiltStrings[1] + + EnumChatFormatting.RESET) + .addInfo("Machine Type: [C] - " + EnumChatFormatting.YELLOW + aBuiltStrings[2] + + EnumChatFormatting.RESET) + .addInfo("Read Multi-Machine Manual for extra information") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Multi-Use Casings", 6) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMultiMachine> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMultiMachine>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialMultiMachine.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(getTextureIndex()) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 2)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return getTextureIndex(); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "Generic3By3"; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + ArrayList<FluidStack> tFluids = getStoredFluids(); + // Logger.MACHINE_INFO("1"); + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + // Logger.MACHINE_INFO("2"); + if (isValidMetaTileEntity(tBus)) { + // Logger.MACHINE_INFO("3"); + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + + boolean aFoundCircuitInBus = false; + for (ItemStack aBusItem : tBusItems) { + if (ItemUtils.isControlCircuit(aBusItem)) { + aFoundCircuitInBus = true; + } + } + if (!aFoundCircuitInBus) { + continue; + } + + Object[] tempArray = tFluids.toArray(new FluidStack[] {}); + FluidStack[] properArray; + properArray = + ((tempArray != null && tempArray.length > 0) ? (FluidStack[]) tempArray : new FluidStack[] {}); + + // Logger.MACHINE_INFO("4"); + if (checkRecipeGeneric( + tBusItems.toArray(new ItemStack[] {}), + properArray, + (2 * GT_Utility.getTier(this.getMaxInputVoltage())), + 80, + 250, + 10000)) return true; + } + return false; + + // return checkRecipeGeneric(2*GT_Utility.getTier(this.getMaxInputVoltage()), 90, 180); + } + + @Override + public int getMaxParallelRecipes() { + return (2 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 80; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (mInternalMode == 0) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeMetal; + } else if (mInternalMode == 1) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeFluid; + } else { // config 2 + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeMisc; + } + } + + public int getTextureIndex() { + return TAE.getIndexFromPage(2, 2); + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private ItemStack getCircuit(ItemStack[] t) { + for (ItemStack j : t) { + if (j.getItem() == CI.getNumberedCircuit(0).getItem()) { + if (j.getItemDamage() >= 20 && j.getItemDamage() <= 22) { + return j; + } + } + } + return null; + } + + private final int getCircuitID(ItemStack circuit) { + int H = circuit.getItemDamage(); + int T = (H == 20 ? 0 : (H == 21 ? 1 : (H == 22 ? 2 : -1))); + return MODE_MAP[this.mInternalMode][T]; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + private final GT_Recipe.GT_Recipe_Map getRecipeMap(ItemStack circuit) { + return getRecipeMap(getCircuitID(circuit)); + } + + private static final GT_Recipe.GT_Recipe_Map getRecipeMap(int aMode) { + if (aMode == MODE_COMPRESSOR) { + return GT_Recipe.GT_Recipe_Map.sCompressorRecipes; + } else if (aMode == MODE_LATHE) { + return GT_Recipe.GT_Recipe_Map.sLatheRecipes; + } else if (aMode == MODE_MAGNETIC) { + return GT_Recipe.GT_Recipe_Map.sPolarizerRecipes; + } else if (aMode == MODE_FERMENTER) { + return GT_Recipe.GT_Recipe_Map.sFermentingRecipes; + } else if (aMode == MODE_FLUIDEXTRACT) { + return GT_Recipe.GT_Recipe_Map.sFluidExtractionRecipes; + } else if (aMode == MODE_EXTRACTOR) { + return GT_Recipe.GT_Recipe_Map.sExtractorRecipes; + } else if (aMode == MODE_LASER) { + return GT_Recipe.GT_Recipe_Map.sLaserEngraverRecipes; + } else if (aMode == MODE_AUTOCLAVE) { + return GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes; + } else if (aMode == MODE_FLUIDSOLIDIFY) { + return GT_Recipe.GT_Recipe_Map.sFluidSolidficationRecipes; + } else { + return null; + } + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + + // Based on the Processing Array. A bit overkill, but very flexible. + + // Get Circuit info for this recipe. + ItemStack tCircuit = getCircuit(aItemInputs); + int tCircuitID = getCircuitID(tCircuit); + + Logger.MACHINE_INFO("Mode: " + tCircuitID); + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + + GT_Recipe.GT_Recipe_Map tRecipeMap = this.getRecipeMap(tCircuit); + if (tRecipeMap == null) return false; + GT_Recipe tRecipe = tRecipeMap.findRecipe( + getBaseMetaTileEntity(), + this.mLastRecipeExtended[tCircuitID], + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + + // Remember last recipe - an optimization for findRecipe() + // this.mLastRecipe = tRecipe; //Let's not do this, it's bad. + // Instead, how about I use a array for types? + this.mLastRecipeExtended[tCircuitID] = tRecipe; + + if (tRecipe == null) { + Logger.MACHINE_INFO("BAD RETURN - 1|" + tCircuitID); + + if (aItemInputs.length > 0) { + Logger.MACHINE_INFO("Input Items: " + ItemUtils.getArrayStackNames(aItemInputs)); + } + if (aFluidInputs.length > 0) { + Logger.MACHINE_INFO("Input Fluids: " + ItemUtils.getFluidArrayStackNames(aFluidInputs)); + } + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + Logger.MACHINE_INFO("BAD RETURN - 2|" + tCircuitID); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + Logger.WARNING("parallelRecipes: " + parallelRecipes); + Logger.WARNING("aMaxParallelRecipes: " + aMaxParallelRecipes); + Logger.WARNING("tTotalEUt: " + tTotalEUt); + Logger.WARNING("tVoltage: " + tVoltage); + Logger.WARNING("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + Logger.WARNING("Broke at " + parallelRecipes + "."); + break; + } + Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + Logger.MACHINE_INFO("BAD RETURN - 3|" + tCircuitID); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.MACHINE_INFO("GOOD RETURN - 1|" + tCircuitID); + return true; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (mInternalMode < 2) { + mInternalMode++; + } else { + mInternalMode = 0; + } + String mModeString = + (mInternalMode == 0 ? "Metal" : mInternalMode == 1 ? "Fluid" : mInternalMode == 2 ? "Misc." : "null"); + PlayerUtils.messagePlayer(aPlayer, "Multi-Machine is now in " + mModeString + " mode."); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mInternalMode", mInternalMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mInternalMode = aNBT.getInteger("mInternalMode"); + super.loadNBTData(aNBT); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java index 7f826575cc..a5d009f7b1 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java @@ -1,6 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -20,214 +24,214 @@ import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialPlatePress extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialPlatePress> implements ISurvivalConstructable { - - private boolean mFormingMode = false; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialPlatePress> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialPlatePress(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialPlatePress(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialPlatePress(this.mName); - } - - @Override - public String getMachineType() { - return "Bending Machine, Forming Press"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for Advanced Bending & Forming") - .addInfo("500% faster than using single block machines of the same voltage") - .addInfo("Processes four items per voltage tier") - .addInfo("Circuit for recipe goes in the Input Bus") - .addInfo("Each Input Bus can have a different Circuit/Shape!") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front Center") - .addCasingInfo("Material Press Machine Casings", 10) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialPlatePress> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialPlatePress>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialPlatePress.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(50) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 4))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(203); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return 50; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "MaterialPress"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return mFormingMode ? GT_Recipe.GT_Recipe_Map.sPressRecipes : GT_Recipe.GT_Recipe_Map.sBenderRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); - tBus.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tBus)) { - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) - tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - - if (checkRecipeGeneric(tBusItems.toArray(new ItemStack[]{}), new FluidStack[]{}, - (4* GT_Utility.getTier(this.getMaxInputVoltage())), 100, 500, 10000)) return true; - } - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - if (this.mFormingMode) return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialPlatePress_ModeForming; - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialPlatePress_ModeBending; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("mFormingMode", mFormingMode); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mFormingMode = aNBT.getBoolean("mFormingMode"); - super.loadNBTData(aNBT); - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - mFormingMode = Utils.invertBoolean(mFormingMode); - if (mFormingMode){ - PlayerUtils.messagePlayer(aPlayer, "Now running in Forming Press Mode."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Now running in Bending Mode."); - } - } +public class GregtechMetaTileEntity_IndustrialPlatePress + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialPlatePress> + implements ISurvivalConstructable { + + private boolean mFormingMode = false; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialPlatePress> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialPlatePress(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialPlatePress(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialPlatePress(this.mName); + } + + @Override + public String getMachineType() { + return "Bending Machine, Forming Press"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for Advanced Bending & Forming") + .addInfo("500% faster than using single block machines of the same voltage") + .addInfo("Processes four items per voltage tier") + .addInfo("Circuit for recipe goes in the Input Bus") + .addInfo("Each Input Bus can have a different Circuit/Shape!") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Material Press Machine Casings", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialPlatePress> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialPlatePress>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialPlatePress.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(50) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 4)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(203); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return 50; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MaterialPress"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mFormingMode ? GT_Recipe.GT_Recipe_Map.sPressRecipes : GT_Recipe.GT_Recipe_Map.sBenderRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + + if (checkRecipeGeneric( + tBusItems.toArray(new ItemStack[] {}), + new FluidStack[] {}, + (4 * GT_Utility.getTier(this.getMaxInputVoltage())), + 100, + 500, + 10000)) return true; + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (this.mFormingMode) return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialPlatePress_ModeForming; + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialPlatePress_ModeBending; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mFormingMode", mFormingMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mFormingMode = aNBT.getBoolean("mFormingMode"); + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mFormingMode = Utils.invertBoolean(mFormingMode); + if (mFormingMode) { + PlayerUtils.messagePlayer(aPlayer, "Now running in Forming Press Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Now running in Bending Mode."); + } + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java index 74d0a63aed..bd62bb495f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java @@ -1,6 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.Random; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -17,201 +21,199 @@ import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.Random; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialSifter extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialSifter> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialSifter> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialSifter(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialSifter(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialSifter(this.mName); - } - - @Override - public String getMachineType() { - return "Sifter"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Sifter") - .addInfo("400% faster than single-block machines of the same voltage") - .addInfo("Only uses 75% of the EU/t normally required") - .addInfo("Processes four items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(5, 3, 5, false) - .addController("Bottom Center") - .addCasingInfo("Sieve Grate", 18) - .addCasingInfo("Sieve Casings", 35) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing (x4)", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialSifter> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialSifter>builder() - .addShape(mName, transpose(new String[][]{ - {"CCCCC", "CMMMC", "CMMMC", "CMMMC", "CCCCC"}, - {"CCCCC", "CMMMC", "CMMMC", "CMMMC", "CCCCC"}, - {"CC~CC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialSifter.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(TAE.GTPP_INDEX(21)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 5))) - ) - .addElement( - 'M', - ofBlock( - ModBlocks.blockCasings2Misc, 6 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 2, 2, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 2, 2, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 2, 2, 0) && mCasing >= 35 && mOutputBusses.size() >= 4 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(21); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialSifter"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sSifterRecipes; - } - - @Override - public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) && (aBaseMetaTileEntity.getFrontFacing() != 1) && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { - final Random tRandom = aBaseMetaTileEntity.getWorld().rand; - if (tRandom.nextFloat() > 0.4) return; - - final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 2; - final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 2; - - aBaseMetaTileEntity.getWorld().spawnParticle("smoke", - (aBaseMetaTileEntity.getXCoord() + xDir + 2.1F) - (tRandom.nextFloat() * 3.2F), - aBaseMetaTileEntity.getYCoord() + 2.5f + (tRandom.nextFloat() * 1.2F), - (aBaseMetaTileEntity.getZCoord() + zDir + 2.1F) - (tRandom.nextFloat() * 3.2F), - 0.0, 0.0, 0.0); - - } - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric((4* GT_Utility.getTier(this.getMaxInputVoltage())), 75, 400, 10000); - } - - @Override - protected boolean doesMachineBoostOutput() { - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 75; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialSifter; - } - - @Override - public int getAmountOfOutputs() { - return 16; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public boolean isOverclockerUpgradable() { - return true; - } +public class GregtechMetaTileEntity_IndustrialSifter + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialSifter> implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialSifter> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialSifter(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialSifter(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialSifter(this.mName); + } + + @Override + public String getMachineType() { + return "Sifter"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Sifter") + .addInfo("400% faster than single-block machines of the same voltage") + .addInfo("Only uses 75% of the EU/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 3, 5, false) + .addController("Bottom Center") + .addCasingInfo("Sieve Grate", 18) + .addCasingInfo("Sieve Casings", 35) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing (x4)", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialSifter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialSifter>builder() + .addShape(mName, transpose(new String[][] { + {"CCCCC", "CMMMC", "CMMMC", "CMMMC", "CCCCC"}, + {"CCCCC", "CMMMC", "CMMMC", "CMMMC", "CCCCC"}, + {"CC~CC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialSifter.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(TAE.GTPP_INDEX(21)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 5)))) + .addElement('M', ofBlock(ModBlocks.blockCasings2Misc, 6)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 2, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 2, 2, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 2, 0) && mCasing >= 35 && mOutputBusses.size() >= 4 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(21); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialSifter"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sSifterRecipes; + } + + @Override + public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if ((aBaseMetaTileEntity.isClientSide()) + && (aBaseMetaTileEntity.isActive()) + && (aBaseMetaTileEntity.getFrontFacing() != 1) + && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) + && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + if (tRandom.nextFloat() > 0.4) return; + + final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 2; + final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 2; + + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "smoke", + (aBaseMetaTileEntity.getXCoord() + xDir + 2.1F) - (tRandom.nextFloat() * 3.2F), + aBaseMetaTileEntity.getYCoord() + 2.5f + (tRandom.nextFloat() * 1.2F), + (aBaseMetaTileEntity.getZCoord() + zDir + 2.1F) - (tRandom.nextFloat() * 3.2F), + 0.0, + 0.0, + 0.0); + } + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((4 * GT_Utility.getTier(this.getMaxInputVoltage())), 75, 400, 10000); + } + + @Override + protected boolean doesMachineBoostOutput() { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 75; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialSifter; + } + + @Override + public int getAmountOfOutputs() { + return 16; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSinter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSinter.java index 5a62c6c335..91698e4a0c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSinter.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSinter.java @@ -1,30 +1,6 @@ /* package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - -import gregtech.api.enums.TAE; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.block.ModBlocks; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; public class GregtechMetaTileEntity_IndustrialSinter extends GT_MetaTileEntity_MultiBlockBase { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java index 4e4e5009fc..08758e22bb 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java @@ -1,5 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -20,203 +27,173 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialThermalCentrifuge extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialThermalCentrifuge> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialThermalCentrifuge> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialThermalCentrifuge(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialThermalCentrifuge(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialThermalCentrifuge(this.mName); - } - - @Override - public String getMachineType() { - return "Thermal Centrifuge"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Thermal Centrifuge") - .addInfo("150% faster than using single block machines of the same voltage") - .addInfo("Only uses 80% of the EU/t normally required") - .addInfo("Processes eight items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 2, 3, false) - .addController("Front Center") - .addCasingInfo("Thermal Processing Casings/Noise Hazard Sign Blocks", 8) - .addInputBus("Bottom Casing", 1) - .addOutputBus("Bottom Casing", 1) - .addEnergyHatch("Bottom Casing", 1) - .addMaintenanceHatch("Bottom Casing", 1) - .addMufflerHatch("Bottom Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialThermalCentrifuge> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialThermalCentrifuge>builder() - .addShape(mName, transpose(new String[][]{ - {"X~X", "XXX", "XXX"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - ofChain( - buildHatchAdder(GregtechMetaTileEntity_IndustrialThermalCentrifuge.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .build(), - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasings2Misc, 0 - ) - ), - onElementPass( - x -> ++x.mCasing, - ofBlock( - GregTech_API.sBlockCasings3, 9 - ) - ) - ) - ) - .addElement( - 'X', - ofChain( - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasings2Misc, 0 - ) - ), - onElementPass( - x -> ++x.mCasing, - ofBlock( - GregTech_API.sBlockCasings3, 9 - ) - ) - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 0, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 0, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 0, 0) && mCasing >= 8 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return getCasingTextureIndex(); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialThermalCentrifuge"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sThermalCentrifugeRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric((8* GT_Utility.getTier(this.getMaxInputVoltage())), 80, 150); - } - - @Override - public int getMaxParallelRecipes() { - return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 80; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialThermalCentrifuge; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings2Misc; - } - - public byte getCasingMeta() { - return 0; - } - - public byte getCasingTextureIndex() { - return (byte) TAE.GTPP_INDEX(16); - } - -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialThermalCentrifuge + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialThermalCentrifuge> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialThermalCentrifuge> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialThermalCentrifuge( + final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialThermalCentrifuge(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialThermalCentrifuge(this.mName); + } + + @Override + public String getMachineType() { + return "Thermal Centrifuge"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Thermal Centrifuge") + .addInfo("150% faster than using single block machines of the same voltage") + .addInfo("Only uses 80% of the EU/t normally required") + .addInfo("Processes eight items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 2, 3, false) + .addController("Front Center") + .addCasingInfo("Thermal Processing Casings/Noise Hazard Sign Blocks", 8) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addMufflerHatch("Bottom Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialThermalCentrifuge> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialThermalCentrifuge>builder() + .addShape(mName, transpose(new String[][] { + {"X~X", "XXX", "XXX"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialThermalCentrifuge.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 0)), + onElementPass(x -> ++x.mCasing, ofBlock(GregTech_API.sBlockCasings3, 9)))) + .addElement( + 'X', + ofChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 0)), + onElementPass(x -> ++x.mCasing, ofBlock(GregTech_API.sBlockCasings3, 9)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 0, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 0, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 0, 0) && mCasing >= 8 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureIndex(); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialThermalCentrifuge"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sThermalCentrifugeRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((8 * GT_Utility.getTier(this.getMaxInputVoltage())), 80, 150); + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 80; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialThermalCentrifuge; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(16); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java index 3f94e4d647..283942ff6d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java @@ -1,6 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -19,247 +24,244 @@ import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialVacuumFreezer extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialVacuumFreezer> implements ISurvivalConstructable { - - public static int CASING_TEXTURE_ID; - public static String mCryoFuelName = "Gelid Cryotheum"; - public static String mCasingName = "Advanced Cryogenic Casing"; - public static String mHatchName = "Cryotheum Hatch"; - public static FluidStack mFuelStack; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialVacuumFreezer> STRUCTURE_DEFINITION = null; - - private final ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mCryotheumHatches = new ArrayList<>(); - - - public GregtechMetaTileEntity_IndustrialVacuumFreezer(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); - CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 10); - } - - public GregtechMetaTileEntity_IndustrialVacuumFreezer(final String aName) { - super(aName); - mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); - CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 10); - } - - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return (IMetaTileEntity) new GregtechMetaTileEntity_IndustrialVacuumFreezer(this.mName); - } - - @Override - public String getMachineType() { - return "Vacuum Freezer"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Factory Grade Advanced Vacuum Freezer") - .addInfo("Speed: +100% | EU Usage: 100% | Parallel: 4") - .addInfo("Consumes 1L of " + mCryoFuelName + "/t during operation") - .addInfo("Constructed exactly the same as a normal Vacuum Freezer") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front Center") - .addCasingInfo(mCasingName, 10) - .addStructureHint(mHatchName, 1) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialVacuumFreezer> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialVacuumFreezer>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - ofChain( - buildHatchAdder(GregtechMetaTileEntity_IndustrialVacuumFreezer.class) - .adder(GregtechMetaTileEntity_IndustrialVacuumFreezer::addCryotheumHatch) - .hatchId(967) - .shouldReject(t -> !t.mCryotheumHatches.isEmpty()) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .build(), - buildHatchAdder(GregtechMetaTileEntity_IndustrialVacuumFreezer.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .build(), - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasings3Misc, 10 - ) - ) - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mCryotheumHatches.clear(); - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - @Override - public boolean checkHatch() { - return super.checkHatch() && !mCryotheumHatches.isEmpty(); - } - - private boolean addCryotheumHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 967) { - return addToMachineListInternal(mCryotheumHatches, aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public void updateSlots() { - for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mCryotheumHatches) - if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); - super.updateSlots(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return CASING_TEXTURE_ID; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "VacuumFreezer"; - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe.GTPP_Recipe_Map.sAdvFreezerRecipes_GT; - } - - public boolean isCorrectMachinePart(final ItemStack aStack) { - return true; - } - - public boolean checkRecipe(final ItemStack aStack) { - return this.checkRecipeGeneric(4, 100, 100); - } - - @Override - public int getMaxParallelRecipes() { - return 4; - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialVacuumFreezer; - } - - public int getDamageToComponent(final ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - private int mGraceTimer = 2; - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - /*if (this.getBaseMetaTileEntity().isActive()) { - if (!this.depleteInput(mFuelStack.copy())) { - this.getBaseMetaTileEntity().setActive(false); - } - } */ - super.onPostTick(aBaseMetaTileEntity, aTick); - - if (this.mStartUpCheck < 0) { - if (this.mMaxProgresstime > 0 && this.mProgresstime != 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { - if (aTick % 10 == 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { - if (!this.depleteInputFromRestrictedHatches(this.mCryotheumHatches, 10)) { - if (mGraceTimer-- == 0) { - this.causeMaintenanceIssue(); - this.stopMachine(); - mGraceTimer = 2; - } - } - } - } - } - } -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialVacuumFreezer + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialVacuumFreezer> + implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + public static String mCryoFuelName = "Gelid Cryotheum"; + public static String mCasingName = "Advanced Cryogenic Casing"; + public static String mHatchName = "Cryotheum Hatch"; + public static FluidStack mFuelStack; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialVacuumFreezer> STRUCTURE_DEFINITION = null; + + private final ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mCryotheumHatches = new ArrayList<>(); + + public GregtechMetaTileEntity_IndustrialVacuumFreezer( + final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 10); + } + + public GregtechMetaTileEntity_IndustrialVacuumFreezer(final String aName) { + super(aName); + mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 10); + } + + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return (IMetaTileEntity) new GregtechMetaTileEntity_IndustrialVacuumFreezer(this.mName); + } + + @Override + public String getMachineType() { + return "Vacuum Freezer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Vacuum Freezer") + .addInfo("Speed: +100% | EU Usage: 100% | Parallel: 4") + .addInfo("Consumes 1L of " + mCryoFuelName + "/t during operation") + .addInfo("Constructed exactly the same as a normal Vacuum Freezer") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo(mCasingName, 10) + .addStructureHint(mHatchName, 1) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialVacuumFreezer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialVacuumFreezer>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialVacuumFreezer.class) + .adder(GregtechMetaTileEntity_IndustrialVacuumFreezer::addCryotheumHatch) + .hatchId(967) + .shouldReject(t -> !t.mCryotheumHatches.isEmpty()) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_IndustrialVacuumFreezer.class) + .atLeast( + InputBus, + OutputBus, + Maintenance, + Energy, + Muffler, + InputHatch, + OutputHatch) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 10)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mCryotheumHatches.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + public boolean checkHatch() { + return super.checkHatch() && !mCryotheumHatches.isEmpty(); + } + + private boolean addCryotheumHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase + && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 967) { + return addToMachineListInternal(mCryotheumHatches, aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void updateSlots() { + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mCryotheumHatches) + if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); + super.updateSlots(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "VacuumFreezer"; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sAdvFreezerRecipes_GT; + } + + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + public boolean checkRecipe(final ItemStack aStack) { + return this.checkRecipeGeneric(4, 100, 100); + } + + @Override + public int getMaxParallelRecipes() { + return 4; + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialVacuumFreezer; + } + + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private int mGraceTimer = 2; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + /*if (this.getBaseMetaTileEntity().isActive()) { + if (!this.depleteInput(mFuelStack.copy())) { + this.getBaseMetaTileEntity().setActive(false); + } + } */ + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (this.mStartUpCheck < 0) { + if (this.mMaxProgresstime > 0 && this.mProgresstime != 0 + || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + if (aTick % 10 == 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + if (!this.depleteInputFromRestrictedHatches(this.mCryotheumHatches, 10)) { + if (mGraceTimer-- == 0) { + this.causeMaintenanceIssue(); + this.stopMachine(); + mGraceTimer = 2; + } + } + } + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java index a63ffa36cd..7af022fffc 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java @@ -1,5 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -31,314 +37,309 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialWashPlant extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialWashPlant> implements ISurvivalConstructable { - - private int mMode = 0; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialWashPlant> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialWashPlant(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialWashPlant(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialWashPlant(this.mName); - } - - @Override - public String getMachineType() { - return "Ore Washer, Simple Washer, Chemical Bath"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Wash Plant") - .addInfo("Can be configured with a screwdriver to also do Simple Washer and process Chemical Bathing") - .addInfo("400% faster than using single block machines of the same voltage") - .addInfo("Processes four item per voltage tier") - .addInfo("Always requires an Input Hatch full of water to refill structure") - .addInfo("Need to be filled with water.") - .addInfo("Will automatically fill water from input hatch.") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(5, 3, 7, true) - .addController("Front Center") - .addCasingInfo("Wash Plant Casings", 40) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialWashPlant> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialWashPlant>builder() - .addShape(mName, transpose(new String[][]{ - {"CCCCC", "C C", "C C", "C C", "C C", "C C", "CCCCC"}, - {"CC~CC", "C C", "C C", "C C", "C C", "C C", "CCCCC"}, - {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialWashPlant.class) - .atLeast(InputBus, InputHatch, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta()))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 2, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 2, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 2, 1, 0) && mCasing >= 40 && checkHatch(); - } - - @Override - protected IAlignmentLimits getInitialAlignmentLimits() { - // don't rotate a washer, water will flow out. - return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return getCasingTextureIndex(); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialWashPlant"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return mMode == 0 ? GT_Recipe.GT_Recipe_Map.sOreWasherRecipes : mMode == 1 ? GTPP_Recipe_Map.sSimpleWasherRecipes : GT_Recipe.GT_Recipe_Map.sChemicalBathRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - if (checkForWater()) { - return checkRecipeGeneric((4 * GT_Utility.getTier(this.getMaxInputVoltage())), 100, 400); - } - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (4* GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - if (mMode == 2) return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWashPlant_ModeChemBath; - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWashPlant_ModeWasher; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings2Misc; - } - - - public byte getCasingMeta() { - return 4; - } - - - public byte getCasingTextureIndex() { - return (byte) TAE.GTPP_INDEX(11); - } - - public boolean checkForWater() { - - //Get Facing direction - IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); - int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int mCurrentDirectionX; - int mCurrentDirectionZ; - int mOffsetX_Lower = 0; - int mOffsetX_Upper = 0; - int mOffsetZ_Lower = 0; - int mOffsetZ_Upper = 0; - - if (mDirectionX == 0){ - mCurrentDirectionX = 2; - mCurrentDirectionZ = 3; - mOffsetX_Lower = -2; - mOffsetX_Upper = 2; - mOffsetZ_Lower = -3; - mOffsetZ_Upper = 3; - } - else { - mCurrentDirectionX = 3; - mCurrentDirectionZ = 2; - mOffsetX_Lower = -3; - mOffsetX_Upper = 3; - mOffsetZ_Lower = -2; - mOffsetZ_Upper = 2; - } - - //if (aBaseMetaTileEntity.fac) - - final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * mCurrentDirectionX; - final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * mCurrentDirectionZ; - - int tAmount = 0; - for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { - for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { - for (int h = 0; h < 2; ++h) { - Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); - if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == Blocks.water) { - if (this.getStoredFluids() != null) { - for (FluidStack stored : this.getStoredFluids()) { - if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { - if (stored.amount >= 1000) { - //Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); - stored.amount -= 1000; - Block fluidUsed = null; - if (tBlock == Blocks.air || tBlock == Blocks.flowing_water) { - fluidUsed = Blocks.water; - } - if (tBlock == Blocks.water) { - fluidUsed = BlocksItems.getFluidBlock(InternalName.fluidDistilledWater); - } - aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getXCoord() + xDir + i, aBaseMetaTileEntity.getYCoord() + h, aBaseMetaTileEntity.getZCoord() + zDir + j, fluidUsed); - - - } - } - } - } - } - if (tBlock == Blocks.water) { - ++tAmount; - //Utils.LOG_WARNING("Found Water"); - } else if (tBlock == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)) { - ++tAmount; - ++tAmount; - //Utils.LOG_WARNING("Found Distilled Water"); - } - } - } - } - - boolean isValidWater = tAmount >= 45; - if (isValidWater){ - Logger.WARNING("Filled structure."); - } - else { - Logger.WARNING("Did not fill structure."); - } - return isValidWater; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mMode", mMode); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - if (aNBT.hasKey("mChemicalMode")) { - boolean aTempMode = aNBT.getBoolean("mChemicalMode"); - if (aTempMode) { - mMode = 2; - } - else { - mMode = 0; - } - aNBT.removeTag("mChemicalMode"); - } - if (aNBT.hasKey("mMode")) { - mMode = aNBT.getInteger("mMode"); - } - super.loadNBTData(aNBT); - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - mMode++; - if (mMode > 2) { - mMode = 0; - } - if (mMode == 0){ - PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Ore Washer Mode."); - } - else if (mMode == 1){ - PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Simple Washer Mode."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Chemical Bath Mode."); - } - } - -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialWashPlant + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialWashPlant> + implements ISurvivalConstructable { + + private int mMode = 0; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialWashPlant> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialWashPlant(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialWashPlant(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialWashPlant(this.mName); + } + + @Override + public String getMachineType() { + return "Ore Washer, Simple Washer, Chemical Bath"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Wash Plant") + .addInfo("Can be configured with a screwdriver to also do Simple Washer and process Chemical Bathing") + .addInfo("400% faster than using single block machines of the same voltage") + .addInfo("Processes four item per voltage tier") + .addInfo("Always requires an Input Hatch full of water to refill structure") + .addInfo("Need to be filled with water.") + .addInfo("Will automatically fill water from input hatch.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 3, 7, true) + .addController("Front Center") + .addCasingInfo("Wash Plant Casings", 40) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialWashPlant> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialWashPlant>builder() + .addShape(mName, transpose(new String[][] { + {"CCCCC", "C C", "C C", "C C", "C C", "C C", "CCCCC"}, + {"CC~CC", "C C", "C C", "C C", "C C", "C C", "CCCCC"}, + {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialWashPlant.class) + .atLeast(InputBus, InputHatch, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 2, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 2, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 1, 0) && mCasing >= 40 && checkHatch(); + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a washer, water will flow out. + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureIndex(); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialWashPlant"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mMode == 0 + ? GT_Recipe.GT_Recipe_Map.sOreWasherRecipes + : mMode == 1 ? GTPP_Recipe_Map.sSimpleWasherRecipes : GT_Recipe.GT_Recipe_Map.sChemicalBathRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + if (checkForWater()) { + return checkRecipeGeneric((4 * GT_Utility.getTier(this.getMaxInputVoltage())), 100, 400); + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (mMode == 2) return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWashPlant_ModeChemBath; + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWashPlant_ModeWasher; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 4; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(11); + } + + public boolean checkForWater() { + + // Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + if (mDirectionX == 0) { + mCurrentDirectionX = 2; + mCurrentDirectionZ = 3; + mOffsetX_Lower = -2; + mOffsetX_Upper = 2; + mOffsetZ_Lower = -3; + mOffsetZ_Upper = 3; + } else { + mCurrentDirectionX = 3; + mCurrentDirectionZ = 2; + mOffsetX_Lower = -3; + mOffsetX_Upper = 3; + mOffsetZ_Lower = -2; + mOffsetZ_Upper = 2; + } + + // if (aBaseMetaTileEntity.fac) + + final int xDir = + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * mCurrentDirectionX; + final int zDir = + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; ++h) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == Blocks.water) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = null; + if (tBlock == Blocks.air || tBlock == Blocks.flowing_water) { + fluidUsed = Blocks.water; + } + if (tBlock == Blocks.water) { + fluidUsed = BlocksItems.getFluidBlock(InternalName.fluidDistilledWater); + } + aBaseMetaTileEntity + .getWorld() + .setBlock( + aBaseMetaTileEntity.getXCoord() + xDir + i, + aBaseMetaTileEntity.getYCoord() + h, + aBaseMetaTileEntity.getZCoord() + zDir + j, + fluidUsed); + } + } + } + } + } + if (tBlock == Blocks.water) { + ++tAmount; + // Utils.LOG_WARNING("Found Water"); + } else if (tBlock == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)) { + ++tAmount; + ++tAmount; + // Utils.LOG_WARNING("Found Distilled Water"); + } + } + } + } + + boolean isValidWater = tAmount >= 45; + if (isValidWater) { + Logger.WARNING("Filled structure."); + } else { + Logger.WARNING("Did not fill structure."); + } + return isValidWater; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mMode", mMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("mChemicalMode")) { + boolean aTempMode = aNBT.getBoolean("mChemicalMode"); + if (aTempMode) { + mMode = 2; + } else { + mMode = 0; + } + aNBT.removeTag("mChemicalMode"); + } + if (aNBT.hasKey("mMode")) { + mMode = aNBT.getInteger("mMode"); + } + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mMode++; + if (mMode > 2) { + mMode = 0; + } + if (mMode == 0) { + PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Ore Washer Mode."); + } else if (mMode == 1) { + PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Simple Washer Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Chemical Bath Mode."); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java index c6292020f7..88a0a849dd 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java @@ -1,5 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -20,176 +26,171 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_IndustrialWireMill extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialWireMill> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialWireMill> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_IndustrialWireMill(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialWireMill(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialWireMill(this.mName); - } - - @Override - public String getMachineType() { - return "Wiremill"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Wire Factory") - .addInfo("200% faster than using single block machines of the same voltage") - .addInfo("Only uses 75% of the EU/t normally required") - .addInfo("Processes four items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 5, true) - .addController("Front Center") - .addCasingInfo("Wire Factory Casings", 32) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialWireMill> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialWireMill>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC", "CCC", "CCC"}, - {"C~C", "C-C", "C-C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialWireMill.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta()))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 32 && checkHatch(); - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(204); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(6); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "IndustrialWireFactory"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sWiremillRecipes; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric((4* GT_Utility.getTier(this.getMaxInputVoltage())), 75, 200); - } - - @Override - public int getMaxParallelRecipes() { - return (4* GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 75; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWireMill; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasingsMisc; - } - - public byte getCasingMeta() { - return 6; - } - - public byte getCasingTextureIndex() { - return (byte) TAE.GTPP_INDEX(6); - } -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialWireMill + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialWireMill> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialWireMill> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialWireMill(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialWireMill(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialWireMill(this.mName); + } + + @Override + public String getMachineType() { + return "Wiremill"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Wire Factory") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Only uses 75% of the EU/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfo("Wire Factory Casings", 32) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialWireMill> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialWireMill>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + {"C~C", "C-C", "C-C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialWireMill.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 32 && checkHatch(); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(204); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(6); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialWireFactory"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sWiremillRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((4 * GT_Utility.getTier(this.getMaxInputVoltage())), 75, 200); + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 75; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWireMill; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasingsMisc; + } + + public byte getCasingMeta() { + return 6; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(6); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IronBlastFurnace.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IronBlastFurnace.java index 5d6904bd46..439ab234cf 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IronBlastFurnace.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IronBlastFurnace.java @@ -1,12 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; @@ -18,386 +11,527 @@ import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; - import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_IronBlastFurnace; import gtPlusPlus.xmod.gregtech.api.gui.GUI_IronBlastFurnace; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; -public class GregtechMetaTileEntity_IronBlastFurnace -extends MetaTileEntity { - private static final ITexture[] FACING_SIDE = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top)}; - private static final ITexture[] FACING_FRONT = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_Off)}; - private static final ITexture[] FACING_ACTIVE = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_On)}; - public int mMaxProgresstime = 0; - public int mUpdate = 30; - public int mProgresstime = 0; - public boolean mMachine = false; - public ItemStack mOutputItem1; - public ItemStack mOutputItem2; - - public GregtechMetaTileEntity_IronBlastFurnace(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional, 4); - } - - public GregtechMetaTileEntity_IronBlastFurnace(final String aName) { - super(aName, 4); - } - - @Override - public String[] getDescription() { - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - return new String[]{"Iron is a much better furnace material!", - "Can be Automated", - "Multiblock: 3x3x5 hollow with opening on top", - "Same shape as Bronze/Bricked blast furnace, except one ring of 8 taller.", - "40 Iron Plated Bricks required", - }; - } - else { - return new String[]{"Sloooowly, Skip the Bronze age, Get some Steel!", - "Multiblock: 3x3x5 hollow with opening on top", - "40 Iron Plated Bricks required", - "----", - "Even though Iron melts hotter than bronze,", - "this machine is to help players skip looking", - "for tin and copper, which are not as common", - "as Iron is. This machine takes 5x longer than the bronze", - "blast furnace as a result.", - "----", - }; - } - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == aFacing) { - return aActive ? FACING_ACTIVE : FACING_FRONT; - } - return FACING_SIDE; - } - - @Override - public boolean isSteampowered() { - return false; - } - - @Override - public boolean isElectric() { - return false; - } - - @Override - public boolean isPneumatic() { - return false; - } - - @Override - public boolean isEnetInput() { - return false; - } - - @Override - public boolean isEnetOutput() { - return false; - } - - @Override - public boolean isInputFacing(final byte aSide) { - return false; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return false; - } - - @Override - public boolean isTeleporterCompatible() { - return false; - } - - @Override - public boolean isFacingValid(final byte aFacing) { - return aFacing > 1; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public int getProgresstime() { - return this.mProgresstime; - } - - @Override - public int maxProgresstime() { - return this.mMaxProgresstime; - } - - @Override - public int increaseProgress(final int aProgress) { - this.mProgresstime += aProgress; - return this.mMaxProgresstime - this.mProgresstime; - } - - @Override - public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aCoverID) { - return (GregTech_API.getCoverBehavior(aCoverID.toStack()).isSimpleCover()) && (super.allowCoverOnSide(aSide, aCoverID)); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IronBlastFurnace(this.mName); - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setInteger("mProgresstime", this.mProgresstime); - aNBT.setInteger("mMaxProgresstime", this.mMaxProgresstime); - if (this.mOutputItem1 != null) { - final NBTTagCompound tNBT = new NBTTagCompound(); - this.mOutputItem1.writeToNBT(tNBT); - aNBT.setTag("mOutputItem1", tNBT); - } - if (this.mOutputItem2 != null) { - final NBTTagCompound tNBT = new NBTTagCompound(); - this.mOutputItem2.writeToNBT(tNBT); - aNBT.setTag("mOutputItem2", tNBT); - } - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.mUpdate = 30; - this.mProgresstime = aNBT.getInteger("mProgresstime"); - this.mMaxProgresstime = aNBT.getInteger("mMaxProgresstime"); - this.mOutputItem1 = GT_Utility.loadItem(aNBT, "mOutputItem1"); - this.mOutputItem2 = GT_Utility.loadItem(aNBT, "mOutputItem2"); - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_IronBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_IronBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); - } - - private boolean checkMachine() { - final int xDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetX; - final int zDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetZ; - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 4; j++) { //This is height - for (int k = -1; k < 2; k++) { - if (((xDir + i) != 0) || (j != 0) || ((zDir + k) != 0)) { - if ((i != 0) || (j == -1) || (k != 0)) { - if ((this.getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k) != ModBlocks.blockCasingsMisc) || (this.getBaseMetaTileEntity().getMetaIDOffset(xDir + i, j, zDir + k) != 10)) { - return false; - } - } else if ((!GT_Utility.arrayContains(this.getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k), new Object[]{Blocks.lava, Blocks.flowing_lava, null})) && (!this.getBaseMetaTileEntity().getAirOffset(xDir + i, j, zDir + k))) { - return false; - } - } - } - } - } - return true; - } - - @Override - public void onMachineBlockUpdate() { - this.mUpdate = 30; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) { - if ((aBaseMetaTileEntity.isClientSide()) && - (aBaseMetaTileEntity.isActive())) { - aBaseMetaTileEntity.getWorld().spawnParticle("cloud", aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1) + Math.random(), aBaseMetaTileEntity.getOffsetY(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1) + Math.random(), 0.0D, 0.3D, 0.0D); - } - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mUpdate-- == 0) { - this.mMachine = this.checkMachine(); - } - if (this.mMachine) { - if (this.mMaxProgresstime > 0) { - if (++this.mProgresstime >= this.mMaxProgresstime) { - this.addOutputProducts(); - this.mOutputItem1 = null; - this.mOutputItem2 = null; - this.mProgresstime = 0; - this.mMaxProgresstime = 0; - try { - GT_Mod.instance.achievements.issueAchievement(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "steel"); - } catch (final Exception e) { - } - } - } else if (aBaseMetaTileEntity.isAllowedToWork()) { - this.checkRecipe(); - } - } - 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; - } - } - } - } - - 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 spaceForOutput(final ItemStack aStack1, final 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; - } - - private int getProperTime(int time) { - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - return (int) (time/3); - } - else { - return time; - } - } - - 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) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 4L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 1); - this.getBaseMetaTileEntity().decrStackSize(1, 4*3); - this.mMaxProgresstime = getProperTime(36000); - return true; - } - if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 2) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 4L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 1); - this.getBaseMetaTileEntity().decrStackSize(1, 2*3); - this.mMaxProgresstime = getProperTime(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) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 9); - this.getBaseMetaTileEntity().decrStackSize(1, 4*3); - this.mMaxProgresstime = getProperTime(64800); - return true; - } - } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "dustSteel")) { - if ((this.mInventory[1].getItem() == Items.coal) && (this.mInventory[1].stackSize >= 2) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 2L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 1); - this.getBaseMetaTileEntity().decrStackSize(1, 2*3); - this.mMaxProgresstime = getProperTime(3600); - return true; - } - if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 1) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 2L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 1); - this.getBaseMetaTileEntity().decrStackSize(1, 1*3); - this.mMaxProgresstime = getProperTime(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) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 2L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 9); - this.getBaseMetaTileEntity().decrStackSize(1, 2*3); - this.mMaxProgresstime = getProperTime(32400); - return true; - } - } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "blockIron")) { - if ((this.mInventory[1].getItem() == Items.coal) && (this.mInventory[1].stackSize >= 36) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 1); - this.getBaseMetaTileEntity().decrStackSize(1, 64); - this.mMaxProgresstime = getProperTime(64800); - return true; - } - if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 18) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Ash, 4L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 1); - this.getBaseMetaTileEntity().decrStackSize(1, 18*3); - this.mMaxProgresstime = getProperTime(43200); - return true; - } - if (((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCoal")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCharcoal"))) && (this.mInventory[1].stackSize >= 4) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { - this.getBaseMetaTileEntity().decrStackSize(0, 1); - this.getBaseMetaTileEntity().decrStackSize(1, 4*3); - this.mMaxProgresstime = getProperTime(64800); - return true; - } - } - } - this.mOutputItem1 = null; - this.mOutputItem2 = null; - return false; - } - - @Override - public boolean isGivingInformation() { - return false; - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return aIndex > 1; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - if (aIndex < 2) { - } - return !GT_Utility.areStacksEqual(aStack, this.mInventory[0]); - } - - @Override - public byte getTileEntityBaseType() { - return 0; - } +public class GregtechMetaTileEntity_IronBlastFurnace extends MetaTileEntity { + private static final ITexture[] FACING_SIDE = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top)}; + private static final ITexture[] FACING_FRONT = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_Off) + }; + private static final ITexture[] FACING_ACTIVE = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_On) + }; + public int mMaxProgresstime = 0; + public int mUpdate = 30; + public int mProgresstime = 0; + public boolean mMachine = false; + public ItemStack mOutputItem1; + public ItemStack mOutputItem2; + + public GregtechMetaTileEntity_IronBlastFurnace(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional, 4); + } + + public GregtechMetaTileEntity_IronBlastFurnace(final String aName) { + super(aName, 4); + } + + @Override + public String[] getDescription() { + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + return new String[] { + "Iron is a much better furnace material!", + "Can be Automated", + "Multiblock: 3x3x5 hollow with opening on top", + "Same shape as Bronze/Bricked blast furnace, except one ring of 8 taller.", + "40 Iron Plated Bricks required", + }; + } else { + return new String[] { + "Sloooowly, Skip the Bronze age, Get some Steel!", + "Multiblock: 3x3x5 hollow with opening on top", + "40 Iron Plated Bricks required", + "----", + "Even though Iron melts hotter than bronze,", + "this machine is to help players skip looking", + "for tin and copper, which are not as common", + "as Iron is. This machine takes 5x longer than the bronze", + "blast furnace as a result.", + "----", + }; + } + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == aFacing) { + return aActive ? FACING_ACTIVE : FACING_FRONT; + } + return FACING_SIDE; + } + + @Override + public boolean isSteampowered() { + return false; + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public boolean isPneumatic() { + return false; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return false; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return false; + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing > 1; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public int getProgresstime() { + return this.mProgresstime; + } + + @Override + public int maxProgresstime() { + return this.mMaxProgresstime; + } + + @Override + public int increaseProgress(final int aProgress) { + this.mProgresstime += aProgress; + return this.mMaxProgresstime - this.mProgresstime; + } + + @Override + public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aCoverID) { + return (GregTech_API.getCoverBehavior(aCoverID.toStack()).isSimpleCover()) + && (super.allowCoverOnSide(aSide, aCoverID)); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IronBlastFurnace(this.mName); + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mProgresstime", this.mProgresstime); + aNBT.setInteger("mMaxProgresstime", this.mMaxProgresstime); + if (this.mOutputItem1 != null) { + final NBTTagCompound tNBT = new NBTTagCompound(); + this.mOutputItem1.writeToNBT(tNBT); + aNBT.setTag("mOutputItem1", tNBT); + } + if (this.mOutputItem2 != null) { + final NBTTagCompound tNBT = new NBTTagCompound(); + this.mOutputItem2.writeToNBT(tNBT); + aNBT.setTag("mOutputItem2", tNBT); + } + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mUpdate = 30; + this.mProgresstime = aNBT.getInteger("mProgresstime"); + this.mMaxProgresstime = aNBT.getInteger("mMaxProgresstime"); + this.mOutputItem1 = GT_Utility.loadItem(aNBT, "mOutputItem1"); + this.mOutputItem2 = GT_Utility.loadItem(aNBT, "mOutputItem2"); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_IronBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_IronBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); + } + + private boolean checkMachine() { + final int xDir = + ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetX; + final int zDir = + ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetZ; + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 4; j++) { // This is height + for (int k = -1; k < 2; k++) { + if (((xDir + i) != 0) || (j != 0) || ((zDir + k) != 0)) { + if ((i != 0) || (j == -1) || (k != 0)) { + if ((this.getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k) + != ModBlocks.blockCasingsMisc) + || (this.getBaseMetaTileEntity().getMetaIDOffset(xDir + i, j, zDir + k) != 10)) { + return false; + } + } else if ((!GT_Utility.arrayContains( + this.getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k), + new Object[] {Blocks.lava, Blocks.flowing_lava, null})) + && (!this.getBaseMetaTileEntity().getAirOffset(xDir + i, j, zDir + k))) { + return false; + } + } + } + } + } + return true; + } + + @Override + public void onMachineBlockUpdate() { + this.mUpdate = 30; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) { + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { + aBaseMetaTileEntity + .getWorld() + .spawnParticle( + "cloud", + aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1) + Math.random(), + aBaseMetaTileEntity.getOffsetY(aBaseMetaTileEntity.getBackFacing(), 1), + aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1) + Math.random(), + 0.0D, + 0.3D, + 0.0D); + } + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate-- == 0) { + this.mMachine = this.checkMachine(); + } + if (this.mMachine) { + if (this.mMaxProgresstime > 0) { + if (++this.mProgresstime >= this.mMaxProgresstime) { + this.addOutputProducts(); + this.mOutputItem1 = null; + this.mOutputItem2 = null; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + try { + GT_Mod.instance.achievements.issueAchievement( + aBaseMetaTileEntity + .getWorld() + .getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), + "steel"); + } catch (final Exception e) { + } + } + } else if (aBaseMetaTileEntity.isAllowedToWork()) { + this.checkRecipe(); + } + } + 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; + } + } + } + } + + 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 spaceForOutput(final ItemStack aStack1, final 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; + } + + private int getProperTime(int time) { + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + return (int) (time / 3); + } else { + return time; + } + } + + 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) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), + this.mOutputItem2 = + GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 4 * 3); + this.mMaxProgresstime = getProperTime(36000); + return true; + } + if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) + && (this.mInventory[1].stackSize >= 2) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), + this.mOutputItem2 = + GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 2 * 3); + this.mMaxProgresstime = getProperTime(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) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), + this.mOutputItem2 = + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 9); + this.getBaseMetaTileEntity().decrStackSize(1, 4 * 3); + this.mMaxProgresstime = getProperTime(64800); + return true; + } + } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "dustSteel")) { + if ((this.mInventory[1].getItem() == Items.coal) + && (this.mInventory[1].stackSize >= 2) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), + this.mOutputItem2 = + GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 2L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 2 * 3); + this.mMaxProgresstime = getProperTime(3600); + return true; + } + if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) + && (this.mInventory[1].stackSize >= 1) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), + this.mOutputItem2 = + GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 2L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 1 * 3); + this.mMaxProgresstime = getProperTime(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) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), + this.mOutputItem2 = + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 2L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 9); + this.getBaseMetaTileEntity().decrStackSize(1, 2 * 3); + this.mMaxProgresstime = getProperTime(32400); + return true; + } + } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "blockIron")) { + if ((this.mInventory[1].getItem() == Items.coal) + && (this.mInventory[1].stackSize >= 36) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), + this.mOutputItem2 = + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 64); + this.mMaxProgresstime = getProperTime(64800); + return true; + } + if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) + && (this.mInventory[1].stackSize >= 18) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), + this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Ash, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 18 * 3); + this.mMaxProgresstime = getProperTime(43200); + return true; + } + if (((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCoal")) + || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCharcoal"))) + && (this.mInventory[1].stackSize >= 4) + && (this.spaceForOutput( + this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), + this.mOutputItem2 = + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 4 * 3); + this.mMaxProgresstime = getProperTime(64800); + return true; + } + } + } + this.mOutputItem1 = null; + this.mOutputItem2 = null; + return false; + } + + @Override + public boolean isGivingInformation() { + return false; + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aIndex > 1; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + if (aIndex < 2) {} + return !GT_Utility.areStacksEqual(aStack, this.mInventory[0]); + } + + @Override + public byte getTileEntityBaseType() { + return 0; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java index 17687ff4c7..49713b3592 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java @@ -1,8 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -29,6 +33,9 @@ import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.GT_MetaTileEntity_Hatch_MillingBalls; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -41,661 +48,648 @@ import net.minecraft.world.chunk.Chunk; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_IsaMill extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IsaMill> implements ISurvivalConstructable { - - protected boolean boostEu = false; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IsaMill> STRUCTURE_DEFINITION = null; - - private static final IIconContainer frontFaceActive = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE5"); - private static final IIconContainer frontFace = new CustomIcon("iconsets/Grinder/GRINDER5"); - - private final ArrayList<GT_MetaTileEntity_Hatch_MillingBalls> mMillingBallBuses = new ArrayList<GT_MetaTileEntity_Hatch_MillingBalls>(); - private static final DamageSource mIsaMillDamageSource = new DamageSource("gtpp.grinder").setDamageBypassesArmor(); - - public GregtechMetaTileEntity_IsaMill(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IsaMill(String aName) { - super(aName); - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Large Grinding Machine") - .addInfo("Grind ores.") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 7, false) - .addController("Front Center") - .addCasingInfo("IsaMill Exterior Casing", 40) +public class GregtechMetaTileEntity_IsaMill extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IsaMill> + implements ISurvivalConstructable { + + protected boolean boostEu = false; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IsaMill> STRUCTURE_DEFINITION = null; + + private static final IIconContainer frontFaceActive = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE5"); + private static final IIconContainer frontFace = new CustomIcon("iconsets/Grinder/GRINDER5"); + + private final ArrayList<GT_MetaTileEntity_Hatch_MillingBalls> mMillingBallBuses = + new ArrayList<GT_MetaTileEntity_Hatch_MillingBalls>(); + private static final DamageSource mIsaMillDamageSource = new DamageSource("gtpp.grinder").setDamageBypassesArmor(); + + public GregtechMetaTileEntity_IsaMill(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IsaMill(String aName) { + super(aName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Grinding Machine") + .addInfo("Grind ores.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 7, false) + .addController("Front Center") + .addCasingInfo("IsaMill Exterior Casing", 40) .addOtherStructurePart("IsaMill Gearbox", "5x, Inner Blocks") .addOtherStructurePart("IsaMill Piping", "8x, ring around controller") .addStructureInfo("IsaMill Pipings must not be obstructed in front (only air blocks)") - .addOtherStructurePart("Milling Ball Hatch", "Any Casing") - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IsaMill> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IsaMill>builder() - .addShape(mName, transpose(new String[][]{ - {"DDD", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC"}, - {"D~D", "CGC", "CGC", "CGC", "CGC", "CGC", "CCC"}, - {"DDD", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - ofChain( - buildHatchAdder(GregtechMetaTileEntity_IsaMill.class) - .adder(GregtechMetaTileEntity_IsaMill::addMillingBallsHatch) - .hatchClass(GT_MetaTileEntity_Hatch_MillingBalls.class) - .shouldReject(t -> !t.mMillingBallBuses.isEmpty()) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .build(), - buildHatchAdder(GregtechMetaTileEntity_IsaMill.class) - .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .build(), - onElementPass( - x -> ++x.mCasing, - ofBlock( - getCasingBlock(), getCasingMeta() - ) - ) - ) - ) - .addElement( - 'D', - ofBlock( - getIntakeBlock(), getIntakeMeta() - ) - ) - .addElement( - 'G', - ofBlock( - getGearboxBlock(), getGearboxMeta() - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mMillingBallBuses.clear(); - return checkPiece(mName, 1, 1, 0) && mCasing >= 48 - 8 && checkHatch(); - } - - @Override - public boolean checkHatch() { - return super.checkHatch() && mMillingBallBuses.size() == 1; - } - - @Override - protected IIconContainer getActiveOverlay() { - return frontFaceActive; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return frontFace; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(2); - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - return getMaxEfficiency(aStack) > 0; - } - - private boolean addMillingBallsHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_MillingBalls) { - return addToMachineListInternal(mMillingBallBuses, aMetaTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_MillingBalls) { - log("Found GT_MetaTileEntity_Hatch_MillingBalls"); - return addToMachineListInternal(mMillingBallBuses, aMetaTileEntity, aBaseCasingIndex); - } - return super.addToMachineList(aTileEntity, aBaseCasingIndex); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe.GTPP_Recipe_Map.sOreMillRecipes; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mUpdate == 1 || this.mStartUpCheck == 1) { - this.mMillingBallBuses.clear(); - } - } - if (aTick % 20 == 0) { - checkForEntities(aBaseMetaTileEntity, aTick); - } - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - private final AutoMap<BlockPos> mFrontBlockPosCache = new AutoMap<BlockPos>(); - - public void checkForEntities(IGregTechTileEntity aBaseMetaTileEntity, long aTime) { - - if (aTime % 100 == 0) { - mFrontBlockPosCache.clear(); - } - if (mFrontBlockPosCache.isEmpty()) { - byte tSide = aBaseMetaTileEntity.getBackFacing(); - int aTileX = aBaseMetaTileEntity.getXCoord(); - int aTileY = aBaseMetaTileEntity.getYCoord(); - int aTileZ = aBaseMetaTileEntity.getZCoord(); - boolean xFacing = (tSide == 4 || tSide == 5); - boolean zFacing = (tSide == 2 || tSide == 3); - - // Check Casings - int aDepthOffset = (tSide == 2 || tSide == 4) ? 1 : -1; - for (int aHorizontalOffset = -1; aHorizontalOffset < 2; aHorizontalOffset++) { - for (int aVerticalOffset = -1; aVerticalOffset < 2; aVerticalOffset++) { - int aX = !xFacing ? (aTileX + aHorizontalOffset) : (aTileX + aDepthOffset); - int aY = aTileY + aVerticalOffset; - int aZ = !zFacing ? (aTileZ + aHorizontalOffset) : (aTileZ + aDepthOffset); - mFrontBlockPosCache.add(new BlockPos(aX, aY, aZ, aBaseMetaTileEntity.getWorld())); - } - } - } - - AutoMap<EntityLivingBase> aEntities = getEntities(mFrontBlockPosCache, aBaseMetaTileEntity.getWorld()); - if (!aEntities.isEmpty()) { - for (EntityLivingBase aFoundEntity : aEntities) { - if (aFoundEntity instanceof EntityPlayer) { - EntityPlayer aPlayer = (EntityPlayer) aFoundEntity; - if (PlayerUtils.isCreative(aPlayer) || !PlayerUtils.canTakeDamage(aPlayer)) { - continue; - } - else { - if (aFoundEntity.getHealth() > 0) { - EntityUtils.doDamage(aFoundEntity, mIsaMillDamageSource, (int) (aFoundEntity.getMaxHealth() / 5)); - if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { - generateParticles(aFoundEntity); - } - } - } - } - if (aFoundEntity.getHealth() > 0) { - EntityUtils.doDamage(aFoundEntity, mIsaMillDamageSource, Math.max(1, (int) (aFoundEntity.getMaxHealth() / 3))); - if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { - generateParticles(aFoundEntity); - } - } - } - } - } - - private static final AutoMap<EntityLivingBase> getEntities(AutoMap<BlockPos> aPositionsToCheck, World aWorld){ - AutoMap<EntityLivingBase> aEntities = new AutoMap<EntityLivingBase>(); - HashSet<Chunk> aChunksToCheck = new HashSet<Chunk>(); - if (!aPositionsToCheck.isEmpty()) { - Chunk aLocalChunk; - for (BlockPos aPos : aPositionsToCheck) { - aLocalChunk = aWorld.getChunkFromBlockCoords(aPos.xPos, aPos.zPos); - aChunksToCheck.add(aLocalChunk); - } - } - if (!aChunksToCheck.isEmpty()) { - AutoMap<EntityLivingBase> aEntitiesFound = new AutoMap<EntityLivingBase>(); - for (Chunk aChunk : aChunksToCheck) { - if (aChunk.isChunkLoaded) { - List[] aEntityLists = aChunk.entityLists; - for (List aEntitySubList : aEntityLists) { - for (Object aEntity : aEntitySubList) { - if (aEntity instanceof EntityLivingBase) { - EntityLivingBase aPlayer = (EntityLivingBase) aEntity; - aEntitiesFound.add(aPlayer); - } - } - } - } - } - if (!aEntitiesFound.isEmpty()) { - for (EntityLivingBase aEntity : aEntitiesFound) { - BlockPos aPlayerPos = EntityUtils.findBlockPosOfEntity(aEntity); - for (BlockPos aBlockSpaceToCheck : aPositionsToCheck) { - if (aBlockSpaceToCheck.equals(aPlayerPos)) { - aEntities.add(aEntity); - } - } - } - } - } - return aEntities; - } - - private static void generateParticles(EntityLivingBase aEntity) { - BlockPos aPlayerPosBottom = EntityUtils.findBlockPosOfEntity(aEntity); - BlockPos aPlayerPosTop = aPlayerPosBottom.getUp(); - AutoMap<BlockPos> aEntityPositions = new AutoMap<BlockPos>(); - aEntityPositions.add(aPlayerPosBottom); - aEntityPositions.add(aPlayerPosTop); - for (int i = 0; i < 64; i++) { - BlockPos aEffectPos = aEntityPositions.get(aEntity.height > 1f ? MathUtils.randInt(0, 1) : 0); - float aOffsetX = MathUtils.randFloat(-0.35f, 0.35f); - float aOffsetY = MathUtils.randFloat(-0.25f, 0.35f); - float aOffsetZ = MathUtils.randFloat(-0.35f, 0.35f); - aEntity.worldObj.spawnParticle("reddust", aEffectPos.xPos + aOffsetX, aEffectPos.yPos + 0.3f + aOffsetY, aEffectPos.zPos + aOffsetZ, 0.0D, 0.0D, 0.0D); - } - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - return checkRecipeGeneric(); - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings5Misc; - } - - public byte getCasingMeta() { - return 0; - } - - public Block getIntakeBlock() { - return ModBlocks.blockCasings5Misc; - } - - public byte getIntakeMeta() { - return 1; - } - - public Block getGearboxBlock() { - return ModBlocks.blockCasings5Misc; - } - - public byte getGearboxMeta() { - return 2; - } - - public byte getCasingTextureIndex() { - return 66; - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IsaMill(this.mName); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 1; - } - - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIsaMill; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public String[] getExtraInfoData() { - return new String[]{ - "IsaMill Grinding Machine", - "Current Efficiency: " + (mEfficiency / 100) + "%", - getIdealStatus() == getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance" - }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Grinding Machine"; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - /* - * Milling Ball Handling - */ - - @Override + .addOtherStructurePart("Milling Ball Hatch", "Any Casing") + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IsaMill> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IsaMill>builder() + .addShape(mName, transpose(new String[][] { + {"DDD", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC"}, + {"D~D", "CGC", "CGC", "CGC", "CGC", "CGC", "CCC"}, + {"DDD", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IsaMill.class) + .adder(GregtechMetaTileEntity_IsaMill::addMillingBallsHatch) + .hatchClass(GT_MetaTileEntity_Hatch_MillingBalls.class) + .shouldReject(t -> !t.mMillingBallBuses.isEmpty()) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_IsaMill.class) + .atLeast( + InputBus, + OutputBus, + InputHatch, + OutputHatch, + Maintenance, + Energy, + Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement('D', ofBlock(getIntakeBlock(), getIntakeMeta())) + .addElement('G', ofBlock(getGearboxBlock(), getGearboxMeta())) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mMillingBallBuses.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 48 - 8 && checkHatch(); + } + + @Override + public boolean checkHatch() { + return super.checkHatch() && mMillingBallBuses.size() == 1; + } + + @Override + protected IIconContainer getActiveOverlay() { + return frontFaceActive; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return frontFace; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(2); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + private boolean addMillingBallsHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_MillingBalls) { + return addToMachineListInternal(mMillingBallBuses, aMetaTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_MillingBalls) { + log("Found GT_MetaTileEntity_Hatch_MillingBalls"); + return addToMachineListInternal(mMillingBallBuses, aMetaTileEntity, aBaseCasingIndex); + } + return super.addToMachineList(aTileEntity, aBaseCasingIndex); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sOreMillRecipes; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mMillingBallBuses.clear(); + } + } + if (aTick % 20 == 0) { + checkForEntities(aBaseMetaTileEntity, aTick); + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + private final AutoMap<BlockPos> mFrontBlockPosCache = new AutoMap<BlockPos>(); + + public void checkForEntities(IGregTechTileEntity aBaseMetaTileEntity, long aTime) { + + if (aTime % 100 == 0) { + mFrontBlockPosCache.clear(); + } + if (mFrontBlockPosCache.isEmpty()) { + byte tSide = aBaseMetaTileEntity.getBackFacing(); + int aTileX = aBaseMetaTileEntity.getXCoord(); + int aTileY = aBaseMetaTileEntity.getYCoord(); + int aTileZ = aBaseMetaTileEntity.getZCoord(); + boolean xFacing = (tSide == 4 || tSide == 5); + boolean zFacing = (tSide == 2 || tSide == 3); + + // Check Casings + int aDepthOffset = (tSide == 2 || tSide == 4) ? 1 : -1; + for (int aHorizontalOffset = -1; aHorizontalOffset < 2; aHorizontalOffset++) { + for (int aVerticalOffset = -1; aVerticalOffset < 2; aVerticalOffset++) { + int aX = !xFacing ? (aTileX + aHorizontalOffset) : (aTileX + aDepthOffset); + int aY = aTileY + aVerticalOffset; + int aZ = !zFacing ? (aTileZ + aHorizontalOffset) : (aTileZ + aDepthOffset); + mFrontBlockPosCache.add(new BlockPos(aX, aY, aZ, aBaseMetaTileEntity.getWorld())); + } + } + } + + AutoMap<EntityLivingBase> aEntities = getEntities(mFrontBlockPosCache, aBaseMetaTileEntity.getWorld()); + if (!aEntities.isEmpty()) { + for (EntityLivingBase aFoundEntity : aEntities) { + if (aFoundEntity instanceof EntityPlayer) { + EntityPlayer aPlayer = (EntityPlayer) aFoundEntity; + if (PlayerUtils.isCreative(aPlayer) || !PlayerUtils.canTakeDamage(aPlayer)) { + continue; + } else { + if (aFoundEntity.getHealth() > 0) { + EntityUtils.doDamage( + aFoundEntity, mIsaMillDamageSource, (int) (aFoundEntity.getMaxHealth() / 5)); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { + generateParticles(aFoundEntity); + } + } + } + } + if (aFoundEntity.getHealth() > 0) { + EntityUtils.doDamage( + aFoundEntity, mIsaMillDamageSource, Math.max(1, (int) (aFoundEntity.getMaxHealth() / 3))); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { + generateParticles(aFoundEntity); + } + } + } + } + } + + private static final AutoMap<EntityLivingBase> getEntities(AutoMap<BlockPos> aPositionsToCheck, World aWorld) { + AutoMap<EntityLivingBase> aEntities = new AutoMap<EntityLivingBase>(); + HashSet<Chunk> aChunksToCheck = new HashSet<Chunk>(); + if (!aPositionsToCheck.isEmpty()) { + Chunk aLocalChunk; + for (BlockPos aPos : aPositionsToCheck) { + aLocalChunk = aWorld.getChunkFromBlockCoords(aPos.xPos, aPos.zPos); + aChunksToCheck.add(aLocalChunk); + } + } + if (!aChunksToCheck.isEmpty()) { + AutoMap<EntityLivingBase> aEntitiesFound = new AutoMap<EntityLivingBase>(); + for (Chunk aChunk : aChunksToCheck) { + if (aChunk.isChunkLoaded) { + List[] aEntityLists = aChunk.entityLists; + for (List aEntitySubList : aEntityLists) { + for (Object aEntity : aEntitySubList) { + if (aEntity instanceof EntityLivingBase) { + EntityLivingBase aPlayer = (EntityLivingBase) aEntity; + aEntitiesFound.add(aPlayer); + } + } + } + } + } + if (!aEntitiesFound.isEmpty()) { + for (EntityLivingBase aEntity : aEntitiesFound) { + BlockPos aPlayerPos = EntityUtils.findBlockPosOfEntity(aEntity); + for (BlockPos aBlockSpaceToCheck : aPositionsToCheck) { + if (aBlockSpaceToCheck.equals(aPlayerPos)) { + aEntities.add(aEntity); + } + } + } + } + } + return aEntities; + } + + private static void generateParticles(EntityLivingBase aEntity) { + BlockPos aPlayerPosBottom = EntityUtils.findBlockPosOfEntity(aEntity); + BlockPos aPlayerPosTop = aPlayerPosBottom.getUp(); + AutoMap<BlockPos> aEntityPositions = new AutoMap<BlockPos>(); + aEntityPositions.add(aPlayerPosBottom); + aEntityPositions.add(aPlayerPosTop); + for (int i = 0; i < 64; i++) { + BlockPos aEffectPos = aEntityPositions.get(aEntity.height > 1f ? MathUtils.randInt(0, 1) : 0); + float aOffsetX = MathUtils.randFloat(-0.35f, 0.35f); + float aOffsetY = MathUtils.randFloat(-0.25f, 0.35f); + float aOffsetZ = MathUtils.randFloat(-0.35f, 0.35f); + aEntity.worldObj.spawnParticle( + "reddust", + aEffectPos.xPos + aOffsetX, + aEffectPos.yPos + 0.3f + aOffsetY, + aEffectPos.zPos + aOffsetZ, + 0.0D, + 0.0D, + 0.0D); + } + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + return checkRecipeGeneric(); + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public Block getIntakeBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getIntakeMeta() { + return 1; + } + + public Block getGearboxBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getGearboxMeta() { + return 2; + } + + public byte getCasingTextureIndex() { + return 66; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IsaMill(this.mName); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIsaMill; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public String[] getExtraInfoData() { + return new String[] { + "IsaMill Grinding Machine", + "Current Efficiency: " + (mEfficiency / 100) + "%", + getIdealStatus() == getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance" + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Grinding Machine"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + /* + * Milling Ball Handling + */ + + @Override public ArrayList<ItemStack> getStoredInputs() { - ArrayList<ItemStack> tItems = super.getStoredInputs(); + ArrayList<ItemStack> tItems = super.getStoredInputs(); for (GT_MetaTileEntity_Hatch_MillingBalls tHatch : mMillingBallBuses) { tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - tItems.addAll(tHatch.getContentUsageSlots()); + if (isValidMetaTileEntity(tHatch)) { + tItems.addAll(tHatch.getContentUsageSlots()); + } + } + return tItems; + } + + public int getMaxBallDurability(ItemStack aStack) { + return ItemGenericChemBase.getMaxBallDurability(aStack); + } + + private ItemStack findMillingBall(ItemStack[] aItemInputs) { + if (mMillingBallBuses.size() != 1) { + return null; + } else { + GT_MetaTileEntity_Hatch_MillingBalls aBus = mMillingBallBuses.get(0); + if (aBus != null) { + AutoMap<ItemStack> aAvailableItems = aBus.getContentUsageSlots(); + if (!aAvailableItems.isEmpty()) { + for (final ItemStack aInput : aItemInputs) { + if (ItemUtils.isMillingBall(aInput)) { + for (ItemStack aBall : aAvailableItems) { + if (GT_Utility.areStacksEqual(aBall, aInput, true)) { + Logger.INFO("Found a valid milling ball to use."); + return aBall; + } + } + } + } + } + } + } + return null; + } + + private void damageMillingBall(ItemStack aStack) { + if (MathUtils.randFloat(0, 10000000) / 10000000f < (1.2f - (0.2 * 1))) { + int damage = getMillingBallDamage(aStack) + 1; + log("damage milling ball " + damage); + if (damage >= getMaxBallDurability(aStack)) { + log("consuming milling ball"); + aStack.stackSize -= 1; + } else { + setDamage(aStack, damage); + } + } else { + log("not damaging milling ball"); + } + } + + private int getMillingBallDamage(ItemStack aStack) { + return ItemGenericChemBase.getMillingBallDamage(aStack); + } + + private void setDamage(ItemStack aStack, int aAmount) { + ItemGenericChemBase.setMillingBallDamage(aStack, aAmount); + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + // checks if it has a milling ball with enough durability + ItemStack tMillingBallRecipe = findMillingBall(aItemInputs); + if (tMillingBallRecipe == null) { + log("does not have milling ball"); + return false; + } + + GT_Recipe tRecipe = findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + log("aEUPercent " + aEUPercent); + log("mEUt " + tRecipe.mEUt); + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + 1); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tEnergy: " + tEnergy); + log("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < 1 && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at " + parallelRecipes + "."); + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 4; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } } } - return tItems; - } - - - public int getMaxBallDurability(ItemStack aStack) { - return ItemGenericChemBase.getMaxBallDurability(aStack); - } - - private ItemStack findMillingBall(ItemStack[] aItemInputs) { - if (mMillingBallBuses.size() != 1) { - return null; - } - else { - GT_MetaTileEntity_Hatch_MillingBalls aBus = mMillingBallBuses.get(0); - if (aBus != null) { - AutoMap<ItemStack> aAvailableItems = aBus.getContentUsageSlots(); - if (!aAvailableItems.isEmpty()) { - for (final ItemStack aInput : aItemInputs) { - if (ItemUtils.isMillingBall(aInput)) { - for (ItemStack aBall : aAvailableItems) { - if (GT_Utility.areStacksEqual(aBall, aInput, true)) { - Logger.INFO("Found a valid milling ball to use."); - return aBall; - } - } - } - } - } - } - } - return null; - } - - - private void damageMillingBall(ItemStack aStack) { - if (MathUtils.randFloat(0, 10000000)/10000000f < (1.2f - (0.2 * 1))) { - int damage = getMillingBallDamage(aStack) + 1; - log("damage milling ball "+damage); - if (damage >= getMaxBallDurability(aStack)) { - log("consuming milling ball"); - aStack.stackSize -= 1; - } - else { - setDamage(aStack,damage); - } - } - else { - log("not damaging milling ball"); - } - } - - private int getMillingBallDamage(ItemStack aStack) { - return ItemGenericChemBase.getMillingBallDamage(aStack); - } - - private void setDamage(ItemStack aStack,int aAmount) { - ItemGenericChemBase.setMillingBallDamage(aStack, aAmount); - } - - - @Override - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - // checks if it has a milling ball with enough durability - ItemStack tMillingBallRecipe = findMillingBall(aItemInputs); - if (tMillingBallRecipe == null) { - log("does not have milling ball"); - return false; - } - - GT_Recipe tRecipe = findRecipe( - getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - - - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - - if (tRecipe == null) { - log("BAD RETURN - 1"); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - log("aEUPercent "+aEUPercent); - log("mEUt "+tRecipe.mEUt); - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+1); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tEnergy: "+tEnergy); - log("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < 1 && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - log("Broke at "+parallelRecipes+"."); - break; - } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - log("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 4; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - - // Damage Milling ball once all is said and done. - if (tMillingBallRecipe != null) { - log("damaging milling ball"); - damageMillingBall(tMillingBallRecipe); - } - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - log("GOOD RETURN - 1"); - return true; - } + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Damage Milling ball once all is said and done. + if (tMillingBallRecipe != null) { + log("damaging milling ball"); + damageMillingBall(tMillingBallRecipe); + } + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java index 23d28bb3dc..2ca76f5353 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java @@ -1,7 +1,9 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -23,418 +25,447 @@ import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; - -public class GregtechMetaTileEntity_SpargeTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_SpargeTower> implements ISurvivalConstructable { - - protected static final String STRUCTURE_PIECE_BASE = "base"; - protected static final String STRUCTURE_PIECE_LAYER = "layer"; - protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; - protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; - private static final IStructureDefinition<GregtechMetaTileEntity_SpargeTower> STRUCTURE_DEFINITION; - - static { - IHatchElement<GregtechMetaTileEntity_SpargeTower> layeredOutputHatch = OutputHatch - .withCount(GregtechMetaTileEntity_SpargeTower::getCurrentLayerOutputHatchCount) - .withAdder(GregtechMetaTileEntity_SpargeTower::addLayerOutputHatch); - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SpargeTower>builder() - .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][]{ - {"b~b", "bbb", "bbb"}, - })) - .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][]{ - {"lll", "lcl", "lll"} - })) - .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][]{ - {"lll", "l-l", "lll"} - })) - .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][]{ - {"lll", "lll", "lll"} - })) - .addElement('b', buildHatchAdder(GregtechMetaTileEntity_SpargeTower.class) - .atLeast(Energy, InputHatch, InputBus, Maintenance) - .casingIndex(getCasingIndex()) - .dot(1) - .buildAndChain(onElementPass(GregtechMetaTileEntity_SpargeTower::onCasingFound, ofBlock(ModBlocks.blockCasings5Misc, 4))) - ) - .addElement('l', ofChain( - buildHatchAdder(GregtechMetaTileEntity_SpargeTower.class) - .atLeast(layeredOutputHatch) - .casingIndex(getCasingIndex()) - .dot(2) - .build(), - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, getCasingIndex(), 2), - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 2), - onElementPass(GregtechMetaTileEntity_SpargeTower::onCasingFound, ofBlock(ModBlocks.blockCasings5Misc, 4)) - )) - .addElement('c', ofChain( - onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addOutputToMachineList, getCasingIndex(), 3)), - onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 3)), - onElementPass(t -> t.onTopLayerFound(true), ofBlock(ModBlocks.blockCasings5Misc, 4)), - isAir() - )) - .build(); - } - - protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); - protected int mHeight; - protected int mCasing; - protected boolean mTopLayerFound; - - public GregtechMetaTileEntity_SpargeTower(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_SpargeTower(String aName) { - super(aName); - } - - public static int getCasingIndex() { - return 68; - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_SpargeTower(this.mName); - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType("Gas Sparge Tower") - .addInfo("Controller block for the Sparging Tower") - .addInfo("Fluids are only put out at the correct height") - .addInfo("The correct height equals the slot number in the NEI recipe") - .addSeparator() - .beginStructureBlock(3, 8, 3, true) - .addController("Front bottom") - .addOtherStructurePart("Sparge Tower Exterior Casing", "45 (minimum)") - .addEnergyHatch("Any casing", 1, 2) - .addMaintenanceHatch("Any casing", 1, 2, 3) - .addInputHatch("2x Input Hatches (Any bottom layer casing)", 1) - .addOutputHatch("6x Output Hatches (At least one per layer except bottom layer)", 2, 3) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return getCasingIndex(); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DistillationTower.png"); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { - generateRecipes(); - } - return GTPP_Recipe_Map.sSpargeTowerRecipes; - } - - private static boolean generateRecipes() { - for (GasSpargingRecipe aRecipe : GasSpargingRecipeMap.mRecipes) { - GTPP_Recipe newRecipe = new GTPP_Recipe( - false, - new ItemStack[] {}, - new ItemStack[] {}, - null, - null, - aRecipe.mFluidInputs.clone(), - new FluidStack[] {}, - aRecipe.mDuration, - aRecipe.mEUt, - 0); - GTPP_Recipe_Map.sSpargeTowerRecipes.add(newRecipe); - } - if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { - return false; - } - return true; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - ArrayList<FluidStack> tFluidList = getStoredFluids(); - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(0, GT_Utility.getTier(tVoltage)); - FluidStack[] tFluids = tFluidList.toArray(new FluidStack[0]); - if (tFluids.length > 0) { - Logger.INFO("Found "+tFluids.length+" input fluids. Searching "+GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.size()+" recipes."); - GT_Recipe tRecipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids); - if (tRecipe != null) { - Logger.INFO("Found recipe!"); - if (tRecipe.isRecipeInputEqual(true, tFluids)) { - Logger.INFO("Found recipe that matches!"); - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Reset outputs and progress stats - this.mEUt = 0; - this.mProgresstime = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - this.mLastRecipe = tRecipe; - - calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); - int aDevProgress = this.mMaxProgresstime / 10; - this.mMaxProgresstime = Math.max(1, aDevProgress); - this.mOutputItems = new ItemStack[]{}; - ArrayList<FluidStack> aFluidOutputs = getByproductsOfSparge(tRecipe.mFluidInputs[0], tRecipe.mFluidInputs[1]); - this.mOutputFluids = (FluidStack[]) aFluidOutputs.toArray(new FluidStack[0]); - updateSlots(); - Logger.INFO("Done!"); - return true; - } - } - else { - Logger.INFO("Did not find recipe!"); - } - } - this.mEUt = 0; - this.mEfficiency = 0; - Logger.INFO("Did not find recipe! (2)"); - return false; - } - - private static ArrayList<FluidStack> getByproductsOfSparge(final FluidStack aSpargeGas, final FluidStack aSpentFuel){ - GasSpargingRecipe aSpargeRecipe = GasSpargingRecipeMap.findRecipe(aSpargeGas, aSpentFuel); - ArrayList<FluidStack> aOutputGases = new ArrayList<FluidStack>(); - if (aSpargeRecipe == null) { - Logger.INFO("Did not find sparge recipe!"); - return aOutputGases; - } - int aSpargeGasAmount = aSpargeRecipe.mInputGas.amount; - - aOutputGases.add(aSpargeRecipe.mOutputSpargedFuel.copy()); - ArrayList<FluidStack> aTempMap = new ArrayList<FluidStack>(); - for (int i=2;i<aSpargeRecipe.mFluidOutputs.length;i++) { - int aGasAmount = MathUtils.randInt(0, (aSpargeRecipe.mMaxOutputQuantity[i-2]/100)); - FluidStack aOutput = aSpargeRecipe.mFluidOutputs[i].copy(); - aSpargeGasAmount -= aGasAmount; - FluidStack aSpargeOutput = null; - if (aGasAmount > 0) { - aSpargeOutput = new FluidStack(aOutput.getFluid(), aGasAmount); - } - aTempMap.add(aSpargeOutput); - } - Logger.INFO("Sparge gas left: "+aSpargeGasAmount); - if (aSpargeGasAmount > 0) { - aOutputGases.add(new FluidStack(aSpargeRecipe.mInputGas.getFluid(), aSpargeGasAmount)); - } - //Logger.INFO("Sparge Outputs: "+ItemUtils.getArrayStackNames(aTempMap)); - aOutputGases.addAll(aTempMap); - Logger.INFO("Sparge output size: "+aOutputGases.size()); - //Logger.INFO("Output of sparging: "+ItemUtils.getArrayStackNames(aOutputGases)); - return aOutputGases; - } - - protected void onCasingFound() { - mCasing++; - } - - protected void onTopLayerFound(boolean aIsCasing) { - mTopLayerFound = true; - if (aIsCasing) { - onCasingFound(); - } - } - - protected int getCurrentLayerOutputHatchCount() { - return mOutputHatchesByLayer.size() < mHeight ? 0 : mOutputHatchesByLayer.get(mHeight - 1).size(); - } - - protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null || aTileEntity.isDead() || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output)) { - Logger.INFO("Bad Output Hatch"); - return false; - } - while (mOutputHatchesByLayer.size() < mHeight) { - mOutputHatchesByLayer.add(new ArrayList<>()); - } - GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) aTileEntity.getMetaTileEntity(); - tHatch.updateTexture(aBaseCasingIndex); - boolean addedHatch = mOutputHatchesByLayer.get(mHeight - 1).add(tHatch); - Logger.INFO("Added Hatch: "+addedHatch); - return addedHatch; - } - - @Override - protected IAlignmentLimits getInitialAlignmentLimits() { - // don't rotate a freaking tower, it won't work - return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_SpargeTower> getStructureDefinition() { - return STRUCTURE_DEFINITION; - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - // reset - mOutputHatchesByLayer.forEach(List::clear); - mHeight = 1; - mTopLayerFound = false; - mCasing = 0; - - // check base - if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) { - Logger.INFO("Bad Base. Height: "+mHeight); - return false; - } - - // check each layer - while (mHeight < 8 && checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0) && !mTopLayerFound) { - if (mOutputHatchesByLayer.get(mHeight - 1).isEmpty()) { - // layer without output hatch - Logger.INFO("Height: "+mHeight + " - Missing output on "+(mHeight - 1)); - return false; - } - // not top - mHeight++; - } - - // validate final invariants... - Logger.INFO("Height: "+mHeight); - Logger.INFO("Casings: "+mCasing); - Logger.INFO("Required: "+(7 * mHeight - 5)); - Logger.INFO("Found Top: "+mTopLayerFound); - return mCasing >= 45 && mTopLayerFound && mMaintenanceHatches.size() == 1; - } - - @Override - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerTick(ItemStack aStack) { - return 0; - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - protected void addFluidOutputs(FluidStack[] mOutputFluids2) { - for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { - FluidStack tStack = mOutputFluids2[i] != null ? mOutputFluids2[i].copy() : null; - if (tStack == null) { - continue; - } - if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) { - dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); - } - } - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); - int tTotalHeight = 8; // min 2 output layer, so at least 1 + 2 height - for (int i = 1; i < tTotalHeight - 1; i++) { - buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); - } - buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - mHeight = 0; - int built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 1, 0, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - int tTotalHeight = 8; // min 2 output layer, so at least 1 + 2 height - for (int i = 1; i < tTotalHeight - 1; i++) { - mHeight = i; - built = survivialBuildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, 1, i, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - } - mHeight = tTotalHeight - 1; - return survivialBuildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, 1, tTotalHeight - 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getMachineType() { - return "Gas Sparger"; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public boolean onPlungerRightClick(EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { - int aLayerIndex = 0; - PlayerUtils.messagePlayer(aPlayer, "Trying to clear "+mOutputHatchesByLayer.size()+" layers of output hatches."); - for (List<GT_MetaTileEntity_Hatch_Output> layer : this.mOutputHatchesByLayer) { - int aHatchIndex = 0; - for (GT_MetaTileEntity_Hatch_Output hatch : layer) { - if (hatch.mFluid != null) { - PlayerUtils.messagePlayer(aPlayer, "Clearing "+hatch.mFluid.amount+"L of "+hatch.mFluid.getLocalizedName()+" from hatch "+aHatchIndex+" on layer "+aLayerIndex+"."); - hatch.mFluid = null; - } - aHatchIndex++; - } - aLayerIndex++; - } - return aLayerIndex > 0; - } +public class GregtechMetaTileEntity_SpargeTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_SpargeTower> + implements ISurvivalConstructable { + + protected static final String STRUCTURE_PIECE_BASE = "base"; + protected static final String STRUCTURE_PIECE_LAYER = "layer"; + protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; + protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; + private static final IStructureDefinition<GregtechMetaTileEntity_SpargeTower> STRUCTURE_DEFINITION; + + static { + IHatchElement<GregtechMetaTileEntity_SpargeTower> layeredOutputHatch = OutputHatch.withCount( + GregtechMetaTileEntity_SpargeTower::getCurrentLayerOutputHatchCount) + .withAdder(GregtechMetaTileEntity_SpargeTower::addLayerOutputHatch); + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SpargeTower>builder() + .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][] { + {"b~b", "bbb", "bbb"}, + })) + .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][] {{"lll", "lcl", "lll"}})) + .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][] {{"lll", "l-l", "lll"}})) + .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][] {{"lll", "lll", "lll"}})) + .addElement( + 'b', + buildHatchAdder(GregtechMetaTileEntity_SpargeTower.class) + .atLeast(Energy, InputHatch, InputBus, Maintenance) + .casingIndex(getCasingIndex()) + .dot(1) + .buildAndChain(onElementPass( + GregtechMetaTileEntity_SpargeTower::onCasingFound, + ofBlock(ModBlocks.blockCasings5Misc, 4)))) + .addElement( + 'l', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_SpargeTower.class) + .atLeast(layeredOutputHatch) + .casingIndex(getCasingIndex()) + .dot(2) + .build(), + ofHatchAdder( + GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, + getCasingIndex(), + 2), + ofHatchAdder( + GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, + getCasingIndex(), + 2), + onElementPass( + GregtechMetaTileEntity_SpargeTower::onCasingFound, + ofBlock(ModBlocks.blockCasings5Misc, 4)))) + .addElement( + 'c', + ofChain( + onElementPass( + t -> t.onTopLayerFound(false), + ofHatchAdder( + GregtechMetaTileEntity_SpargeTower::addOutputToMachineList, + getCasingIndex(), + 3)), + onElementPass( + t -> t.onTopLayerFound(false), + ofHatchAdder( + GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, + getCasingIndex(), + 3)), + onElementPass(t -> t.onTopLayerFound(true), ofBlock(ModBlocks.blockCasings5Misc, 4)), + isAir())) + .build(); + } + + protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); + protected int mHeight; + protected int mCasing; + protected boolean mTopLayerFound; + + public GregtechMetaTileEntity_SpargeTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_SpargeTower(String aName) { + super(aName); + } + + public static int getCasingIndex() { + return 68; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_SpargeTower(this.mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Gas Sparge Tower") + .addInfo("Controller block for the Sparging Tower") + .addInfo("Fluids are only put out at the correct height") + .addInfo("The correct height equals the slot number in the NEI recipe") + .addSeparator() + .beginStructureBlock(3, 8, 3, true) + .addController("Front bottom") + .addOtherStructurePart("Sparge Tower Exterior Casing", "45 (minimum)") + .addEnergyHatch("Any casing", 1, 2) + .addMaintenanceHatch("Any casing", 1, 2, 3) + .addInputHatch("2x Input Hatches (Any bottom layer casing)", 1) + .addOutputHatch("6x Output Hatches (At least one per layer except bottom layer)", 2, 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return getCasingIndex(); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DistillationTower.png"); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { + generateRecipes(); + } + return GTPP_Recipe_Map.sSpargeTowerRecipes; + } + + private static boolean generateRecipes() { + for (GasSpargingRecipe aRecipe : GasSpargingRecipeMap.mRecipes) { + GTPP_Recipe newRecipe = new GTPP_Recipe( + false, + new ItemStack[] {}, + new ItemStack[] {}, + null, + null, + aRecipe.mFluidInputs.clone(), + new FluidStack[] {}, + aRecipe.mDuration, + aRecipe.mEUt, + 0); + GTPP_Recipe_Map.sSpargeTowerRecipes.add(newRecipe); + } + if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { + return false; + } + return true; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + ArrayList<FluidStack> tFluidList = getStoredFluids(); + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(0, GT_Utility.getTier(tVoltage)); + FluidStack[] tFluids = tFluidList.toArray(new FluidStack[0]); + if (tFluids.length > 0) { + Logger.INFO("Found " + tFluids.length + " input fluids. Searching " + + GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.size() + " recipes."); + GT_Recipe tRecipe = getRecipeMap() + .findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids); + if (tRecipe != null) { + Logger.INFO("Found recipe!"); + if (tRecipe.isRecipeInputEqual(true, tFluids)) { + Logger.INFO("Found recipe that matches!"); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Reset outputs and progress stats + this.mEUt = 0; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + this.mLastRecipe = tRecipe; + + calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); + int aDevProgress = this.mMaxProgresstime / 10; + this.mMaxProgresstime = Math.max(1, aDevProgress); + this.mOutputItems = new ItemStack[] {}; + ArrayList<FluidStack> aFluidOutputs = + getByproductsOfSparge(tRecipe.mFluidInputs[0], tRecipe.mFluidInputs[1]); + this.mOutputFluids = (FluidStack[]) aFluidOutputs.toArray(new FluidStack[0]); + updateSlots(); + Logger.INFO("Done!"); + return true; + } + } else { + Logger.INFO("Did not find recipe!"); + } + } + this.mEUt = 0; + this.mEfficiency = 0; + Logger.INFO("Did not find recipe! (2)"); + return false; + } + + private static ArrayList<FluidStack> getByproductsOfSparge( + final FluidStack aSpargeGas, final FluidStack aSpentFuel) { + GasSpargingRecipe aSpargeRecipe = GasSpargingRecipeMap.findRecipe(aSpargeGas, aSpentFuel); + ArrayList<FluidStack> aOutputGases = new ArrayList<FluidStack>(); + if (aSpargeRecipe == null) { + Logger.INFO("Did not find sparge recipe!"); + return aOutputGases; + } + int aSpargeGasAmount = aSpargeRecipe.mInputGas.amount; + + aOutputGases.add(aSpargeRecipe.mOutputSpargedFuel.copy()); + ArrayList<FluidStack> aTempMap = new ArrayList<FluidStack>(); + for (int i = 2; i < aSpargeRecipe.mFluidOutputs.length; i++) { + int aGasAmount = MathUtils.randInt(0, (aSpargeRecipe.mMaxOutputQuantity[i - 2] / 100)); + FluidStack aOutput = aSpargeRecipe.mFluidOutputs[i].copy(); + aSpargeGasAmount -= aGasAmount; + FluidStack aSpargeOutput = null; + if (aGasAmount > 0) { + aSpargeOutput = new FluidStack(aOutput.getFluid(), aGasAmount); + } + aTempMap.add(aSpargeOutput); + } + Logger.INFO("Sparge gas left: " + aSpargeGasAmount); + if (aSpargeGasAmount > 0) { + aOutputGases.add(new FluidStack(aSpargeRecipe.mInputGas.getFluid(), aSpargeGasAmount)); + } + // Logger.INFO("Sparge Outputs: "+ItemUtils.getArrayStackNames(aTempMap)); + aOutputGases.addAll(aTempMap); + Logger.INFO("Sparge output size: " + aOutputGases.size()); + // Logger.INFO("Output of sparging: "+ItemUtils.getArrayStackNames(aOutputGases)); + return aOutputGases; + } + + protected void onCasingFound() { + mCasing++; + } + + protected void onTopLayerFound(boolean aIsCasing) { + mTopLayerFound = true; + if (aIsCasing) { + onCasingFound(); + } + } + + protected int getCurrentLayerOutputHatchCount() { + return mOutputHatchesByLayer.size() < mHeight + ? 0 + : mOutputHatchesByLayer.get(mHeight - 1).size(); + } + + protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null + || aTileEntity.isDead() + || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output)) { + Logger.INFO("Bad Output Hatch"); + return false; + } + while (mOutputHatchesByLayer.size() < mHeight) { + mOutputHatchesByLayer.add(new ArrayList<>()); + } + GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) aTileEntity.getMetaTileEntity(); + tHatch.updateTexture(aBaseCasingIndex); + boolean addedHatch = mOutputHatchesByLayer.get(mHeight - 1).add(tHatch); + Logger.INFO("Added Hatch: " + addedHatch); + return addedHatch; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a freaking tower, it won't work + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SpargeTower> getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + // reset + mOutputHatchesByLayer.forEach(List::clear); + mHeight = 1; + mTopLayerFound = false; + mCasing = 0; + + // check base + if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) { + Logger.INFO("Bad Base. Height: " + mHeight); + return false; + } + + // check each layer + while (mHeight < 8 && checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0) && !mTopLayerFound) { + if (mOutputHatchesByLayer.get(mHeight - 1).isEmpty()) { + // layer without output hatch + Logger.INFO("Height: " + mHeight + " - Missing output on " + (mHeight - 1)); + return false; + } + // not top + mHeight++; + } + + // validate final invariants... + Logger.INFO("Height: " + mHeight); + Logger.INFO("Casings: " + mCasing); + Logger.INFO("Required: " + (7 * mHeight - 5)); + Logger.INFO("Found Top: " + mTopLayerFound); + return mCasing >= 45 && mTopLayerFound && mMaintenanceHatches.size() == 1; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + protected void addFluidOutputs(FluidStack[] mOutputFluids2) { + for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { + FluidStack tStack = mOutputFluids2[i] != null ? mOutputFluids2[i].copy() : null; + if (tStack == null) { + continue; + } + if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) { + dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); + } + } + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); + int tTotalHeight = 8; // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); + } + buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + mHeight = 0; + int built = survivialBuildPiece( + STRUCTURE_PIECE_BASE, stackSize, 1, 0, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + int tTotalHeight = 8; // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + mHeight = i; + built = survivialBuildPiece( + STRUCTURE_PIECE_LAYER_HINT, stackSize, 1, i, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + } + mHeight = tTotalHeight - 1; + return survivialBuildPiece( + STRUCTURE_PIECE_TOP_HINT, stackSize, 1, tTotalHeight - 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getMachineType() { + return "Gas Sparger"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean onPlungerRightClick(EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + int aLayerIndex = 0; + PlayerUtils.messagePlayer( + aPlayer, "Trying to clear " + mOutputHatchesByLayer.size() + " layers of output hatches."); + for (List<GT_MetaTileEntity_Hatch_Output> layer : this.mOutputHatchesByLayer) { + int aHatchIndex = 0; + for (GT_MetaTileEntity_Hatch_Output hatch : layer) { + if (hatch.mFluid != null) { + PlayerUtils.messagePlayer( + aPlayer, + "Clearing " + hatch.mFluid.amount + "L of " + hatch.mFluid.getLocalizedName() + + " from hatch " + aHatchIndex + " on layer " + aLayerIndex + "."); + hatch.mFluid = null; + } + aHatchIndex++; + } + aLayerIndex++; + } + return aLayerIndex > 0; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_AssemblyLine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_AssemblyLine.java index be7aa8b98a..70551220ca 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_AssemblyLine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_AssemblyLine.java @@ -1,9 +1,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; -import java.util.ArrayList; - import com.gtnewhorizon.structurelib.structure.IStructureDefinition; - import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; @@ -23,6 +20,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.LangUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -31,640 +29,666 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; -public class GregtechMetaTileEntity_Adv_AssemblyLine extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_AssemblyLine> { - - public ArrayList<GT_MetaTileEntity_Hatch_DataAccess> mDataAccessHatches = new ArrayList<GT_MetaTileEntity_Hatch_DataAccess>(); - - public static String[] mCasingName = new String[5]; - private final int CASING_TEXTURE_ID = TAE.getIndexFromPage(0, 13); - private final int META_BaseCasing = 0; //4 - private final int META_ContainmentCasing = 15; //3 - private final int META_Shielding = 13; //1 - private final int META_PipeCasing = 1; //4 - private final int META_IntegralCasing = 6; //0 - private final int META_ContainmentChamberCasing = 2; //4 - - - public GregtechMetaTileEntity_Adv_AssemblyLine(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - mCasingName[0] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 0); - mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); - mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); - mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); - mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); - } - - public GregtechMetaTileEntity_Adv_AssemblyLine(String aName) { - super(aName); - } - - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_Adv_AssemblyLine(this.mName); - } - - /* public String[] getTooltip() { - if (mCasingName[0].toLowerCase().contains(".name")) { - mCasingName[0] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 0); - } - if (mCasingName[1].toLowerCase().contains(".name")) { - mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); - } - if (mCasingName[2].toLowerCase().contains(".name")) { - mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); - } - if (mCasingName[3].toLowerCase().contains(".name")) { - mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); - } - if (mCasingName[4].toLowerCase().contains(".name")) { - mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); - } - return new String[]{ - "Advanced Integrated Assembly Line" - }; - }*/ - - @Override - protected final GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - private Block getCasing(int casingID) { - if (casingID == 1) { - return ModBlocks.blockCasingsMisc; - } - else if (casingID == 2) { - return ModBlocks.blockCasings2Misc; - } - else if (casingID == 3) { - return ModBlocks.blockCasings3Misc; - } - else if (casingID == 4) { - return ModBlocks.blockCasings4Misc; - } - else { - return ModBlocks.blockCasingsTieredGTPP; - } - } - - @Override - protected IIconContainer getActiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE_ACTIVE; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE; - } - - @Override - protected int getCasingTextureId() { - return 16; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "AssemblyLine.png"); - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return null; - } - - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - public boolean checkRecipe(ItemStack aStack) { - if(GT_Values.D1)System.out.println("Start ALine recipe check"); - ArrayList<ItemStack> tDataStickList = getDataItems(2); - if (tDataStickList.size() == 0) return false; - if(GT_Values.D1)System.out.println("Stick accepted, " + tDataStickList.size() + " Data Sticks found"); - - ItemStack tStack[] = new ItemStack[15]; - FluidStack[] tFluids = new FluidStack[4]; - boolean findRecipe = false; - nextDS:for (ItemStack tDataStick : tDataStickList){ - NBTTagCompound tTag = tDataStick.getTagCompound(); - if (tTag == null) continue; - for (int i = 0; i < 15; i++) { - int count = tTag.getInteger("a"+i); - if (!tTag.hasKey("" + i) && count <= 0) continue; - if (mInputBusses.get(i) == null) { - continue nextDS; - } - - ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); - boolean flag = true; - if (count > 0) { - for (int j = 0; j < count; j++) { - tStack[i] = GT_Utility.loadItem(tTag, "a" + i + ":" + j); - if (tStack[i] == null) continue; - if(GT_Values.D1)System.out.println("Item "+i+" : "+tStack[i].getUnlocalizedName()); - if (GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) && tStack[i].stackSize <= stackInSlot.stackSize) { - flag = false; - break; - } - } - } - if (flag) { - tStack[i] = GT_Utility.loadItem(tTag, "" + i); - if (tStack[i] == null) { - flag = false; - continue; - } - if(GT_Values.D1)System.out.println("Item "+i+" : "+tStack[i].getUnlocalizedName()); - if (GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) && tStack[i].stackSize <= stackInSlot.stackSize) { - flag = false; - } - } - if(GT_Values.D1) System.out.println(i + (flag ? " not accepted" : " accepted")); - if (flag) continue nextDS; - } - - if(GT_Values.D1)System.out.println("All Items done, start fluid check"); - for (int i = 0; i < 4; i++) { - if (!tTag.hasKey("f" + i)) continue; - tFluids[i] = GT_Utility.loadFluid(tTag, "f" + i); - if (tFluids[i] == null) continue; - if(GT_Values.D1)System.out.println("Fluid "+i+" "+tFluids[i].getUnlocalizedName()); - if (mInputHatches.get(i) == null) { - continue nextDS; - } - FluidStack fluidInHatch = mInputHatches.get(i).mFluid; - if (fluidInHatch == null || !GT_Utility.areFluidsEqual(fluidInHatch, tFluids[i], true) || fluidInHatch.amount < tFluids[i].amount) { - if(GT_Values.D1)System.out.println(i+" not accepted"); - continue nextDS; - } - if(GT_Values.D1)System.out.println(i+" accepted"); - } - - if(GT_Values.D1)System.out.println("Input accepted, check other values"); - if (!tTag.hasKey("output")) continue; - mOutputItems = new ItemStack[]{GT_Utility.loadItem(tTag, "output")}; - if (mOutputItems[0] == null || !GT_Utility.isStackValid(mOutputItems[0])) - continue; - - if (!tTag.hasKey("time")) continue; - mMaxProgresstime = tTag.getInteger("time"); - if (mMaxProgresstime <= 0) continue; - - if (!tTag.hasKey("eu")) continue; - mEUt = tTag.getInteger("eu"); - - if(GT_Values.D1)System.out.println("Find avaiable recipe"); - findRecipe = true; - break; - } - if (!findRecipe) return false; - - if(GT_Values.D1)System.out.println("All checked start consuming inputs"); - for (int i = 0; i < 15; i++) { - if (tStack[i] == null) continue; - ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); - stackInSlot.stackSize -= tStack[i].stackSize; - } - - for (int i = 0; i < 4; i++) { - if (tFluids[i] == null) continue; - mInputHatches.get(i).mFluid.amount -= tFluids[i].amount; - if (mInputHatches.get(i).mFluid.amount <= 0) { - mInputHatches.get(i).mFluid = null; - } - } - if(GT_Values.D1)System.out.println("Check overclock"); - - byte tTier = (byte) Math.max(1, GT_Utility.getTier(getMaxInputVoltage())); - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - if (mEUt <= 16) { - this.mEUt = (mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - if (this.mEUt > 0) { - this.mEUt = -this.mEUt; - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - updateSlots(); - if(GT_Values.D1)System.out.println("Recipe sucessfull"); - return true; - } - - public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { - super.startSoundLoop(aIndex, aX, aY, aZ); - if (aIndex == 20) { - GT_Utility.doSoundAtClient(GregTech_API.sSoundList.get(212), 10, 1.0F, aX, aY, aZ); - } - } - - public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 4; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 4; - - // Counts for all Casing Types - int aBaseCasingCount = 0; - int aContainmentCasingCount = 0; - int aShieldingCount = 0; - int aPipeCount = 0; - int aIntegralCasingCount = 0; - int aContainmentChamberCount = 0; - - // Bottom Layer - aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, -7, xDir, zDir); - log("Bottom Layer is Valid. Moving to Layer 1."); - - // Layer 1 - aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -6, xDir, zDir); - aIntegralCasingCount += checkIntegralRing(aBaseMetaTileEntity, getCasing(0), this.META_IntegralCasing, -6, xDir, zDir); - aContainmentChamberCount += checkContainmentRing(aBaseMetaTileEntity, getCasing(4), this.META_ContainmentChamberCasing, -6, xDir, zDir); - log("Layer 1 is Valid. Moving to Layer 2."); - - // Layer 2 - aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -5, xDir, zDir); - aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -5, xDir, zDir); - log("Layer 2 is Valid. Moving to Layer 3."); - - // Layer 3 - aContainmentCasingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(3), this.META_ContainmentCasing, -4, xDir, zDir); - aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -4, xDir, zDir); - log("Layer 3 is Valid. Moving to Layer 4."); - - // Layer 4 - aContainmentCasingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(3), this.META_ContainmentCasing, -3, xDir, zDir); - aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -3, xDir, zDir); - log("Layer 4 is Valid. Moving to Layer 5."); - - // Layer 5 - aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -2, xDir, zDir); - aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -2, xDir, zDir); - log("Layer 5 is Valid. Moving to Layer 6."); - - // Layer 6 - aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -1, xDir, zDir); - aIntegralCasingCount += checkIntegralRing(aBaseMetaTileEntity, getCasing(0), this.META_IntegralCasing, -1, xDir, zDir); - aContainmentChamberCount += checkContainmentRing(aBaseMetaTileEntity, getCasing(4), this.META_ContainmentChamberCasing, -1, xDir, zDir); - log("Layer 6 is Valid. Moving to Top Layer."); - - // Top Layer - aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, 0, xDir, zDir); - - log("Found "+aBaseCasingCount+" "+mCasingName[0]+"s"); - log("Found "+aShieldingCount+" "+mCasingName[4]+"s"); - log("Found "+aPipeCount+" "+mCasingName[1]+"s"); - log("Found "+aContainmentCasingCount+" "+mCasingName[3]+"s"); - log("Found "+aIntegralCasingCount+" "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s"); - log("Found "+aContainmentChamberCount+" "+mCasingName[2]+"s"); - - // Try mesage player - String aOwnerName = this.getBaseMetaTileEntity().getOwnerName(); - EntityPlayer aOwner = null; - if (aOwnerName != null && aOwnerName.length() > 0) { - aOwner = PlayerUtils.getPlayer(aOwnerName); - } - - if (aShieldingCount != 128) { - log("Not enough "+mCasingName[4]+"s, require 128."); - if (aOwner != null) { - PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[4]+"s, require 128."); - } - return false; - } - if (aPipeCount != 20) { - log("Not enough "+mCasingName[1]+"s, require 20."); - if (aOwner != null) { - PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[1]+"s, require 20."); - } - return false; - } - if (aContainmentCasingCount != 64) { - log("Not enough "+mCasingName[3]+"s, require 64."); - if (aOwner != null) { - PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[3]+"s, require 64."); - } - return false; - } - if (aContainmentChamberCount != 42) { - log("Not enough "+mCasingName[2]+"s, require 42."); - if (aOwner != null) { - PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[2]+"s, require 42."); - } - return false; - } - if (aBaseCasingCount < 140) { - log("Not enough "+mCasingName[0]+"s, require 140 at a minimum."); - if (aOwner != null) { - PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[0]+"s, require 140 at a minimum."); - } - return false; - } - if (aIntegralCasingCount != 48) { - log("Not enough "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s, require 48."); - if (aOwner != null) { - PlayerUtils.messagePlayer(aOwner, "Not enough "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s, require 48."); - } - return false; - } - log("LNR Formed."); - if (aOwner != null) { - PlayerUtils.messagePlayer(aOwner, "Large Naquadah Reactor has formed successfully."); - } - return true; - } - - public boolean addNaquadahHatchToMachineInput(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_DataAccess) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); - return mDataAccessHatches.add((GT_MetaTileEntity_Hatch_DataAccess) aMetaTileEntity); - } - return false; - } - - public int checkEntireLayer(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { - int aCasingCount = 0; - for (int x = -4; x < 5; x++) { - for (int z = -4; z < 5; z++) { - int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; - int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; - //Skip the corners - if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { - continue; - } - // Skip controller - if (aY == 0 && x == 0 && z == 0) { - continue; - } - - Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); - int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); - if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { - aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); - if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, true, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { - log("Layer has error. Height: "+aY); - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); - return 0; - } - } - } - return aCasingCount; - } - - public int checkOuterRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { - int aCasingCount = 0; - for (int x = -4; x < 5; x++) { - for (int z = -4; z < 5; z++) { - int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; - int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; - //Skip the corners - if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { - continue; - } - - // If we are on the 5x5 ring, proceed - if ((x > -4 && x < 4 ) && (z > -4 && z < 4)) { - if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); - } - else { - continue; - } - } - - Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); - int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); - if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { - aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); - if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { - log("Layer has error. Height: "+aY); - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); - return 0; - } - } - } - return aCasingCount; - } - public int checkIntegralRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { - int aCasingCount = 0; - for (int x = -3; x < 4; x++) { - for (int z = -3; z < 4; z++) { - int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; - int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; - //Skip the corners - if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { - continue; - } - - // If we are on the 5x5 ring, proceed - if ((x > -3 && x < 3 ) && (z > -3 && z < 3)) { - if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); - } - else { - continue; - } - } - - Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); - int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); - if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { - aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); - if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { - log("Layer has error. Height: "+aY); - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); - return 0; - } - } - } - return aCasingCount; - } - - public int checkPipes(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { - int aCasingCount = 0; - for (int x = -1; x < 2; x++) { - for (int z = -1; z < 2; z++) { - int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; - int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; - //Skip the corners - if ((x == 1 && z == 1) || (x == -1 && z == -1) || (x == 1 && z == -1) || (x == -1 && z == 1) || (x == 0 && z == 0)) { - Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); - int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); - if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { - aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); - if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { - log("Pipe has error. Height: "+aY); - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); - return 0; - }; - } - } - } - return aCasingCount; - } - - public int checkContainmentRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { - int aCasingCount = 0; - for (int x = -2; x < 3; x++) { - for (int z = -2; z < 3; z++) { - int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; - int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; - //Skip the corners - if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { - continue; - } - - Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); - int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); - if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { - aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); - if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { - log("Layer has error. Height: "+aY); - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); - return 0; - } - } - } - return aCasingCount; - } - - /** - * @param state using bitmask, 1 for IntegratedCircuit, 2 for DataStick, 4 for DataOrb - */ - - private boolean isCorrectDataItem(ItemStack aStack, int state){ - if ((state & 1) != 0 && ItemList.Circuit_Integrated.isStackEqual(aStack, true, true)) return true; - if ((state & 2) != 0 && ItemList.Tool_DataStick.isStackEqual(aStack, false, true)) return true; - if ((state & 4) != 0 && ItemList.Tool_DataOrb.isStackEqual(aStack, false, true)) return true; - return false; - } - - /** - * @param state using bitmask, 1 for IntegratedCircuit, 2 for DataStick, 4 for DataOrb - */ - - public ArrayList<ItemStack> getDataItems(int state) { - ArrayList<ItemStack> rList = new ArrayList<ItemStack>(); - if (GT_Utility.isStackValid(mInventory[1]) && isCorrectDataItem(mInventory[1], state)) { - rList.add(mInventory[1]); - } - for (GT_MetaTileEntity_Hatch_DataAccess tHatch : mDataAccessHatches) { - if (isValidMetaTileEntity(tHatch)) { - for (int i = 0; i < tHatch.getBaseMetaTileEntity().getSizeInventory(); i++) { - if (tHatch.getBaseMetaTileEntity().getStackInSlot(i) != null - && isCorrectDataItem(tHatch.getBaseMetaTileEntity().getStackInSlot(i), state)) - rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - } - return rList; - } - - public boolean addDataAccessToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) return false; - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) return false; - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_DataAccess) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); - return mDataAccessHatches.add((GT_MetaTileEntity_Hatch_DataAccess) aMetaTileEntity); - } - return false; - } - - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - public int getPollutionPerTick(ItemStack aStack) { - return 0; - } - - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Assembly Line"; - } - - @Override - public int getMaxParallelRecipes() { - return 0; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - // Fix GT bug - if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { - log("Fixing Bad Facing. (GT Bug)"); - this.getBaseMetaTileEntity().setFrontFacing((byte) 1); - } - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - // TODO Auto-generated method stub - - } - - @Override - public IStructureDefinition getStructureDefinition() { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean checkMachine( - IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack - ) { - // TODO Auto-generated method stub - return false; - } +public class GregtechMetaTileEntity_Adv_AssemblyLine + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_AssemblyLine> { + + public ArrayList<GT_MetaTileEntity_Hatch_DataAccess> mDataAccessHatches = + new ArrayList<GT_MetaTileEntity_Hatch_DataAccess>(); + + public static String[] mCasingName = new String[5]; + private final int CASING_TEXTURE_ID = TAE.getIndexFromPage(0, 13); + private final int META_BaseCasing = 0; // 4 + private final int META_ContainmentCasing = 15; // 3 + private final int META_Shielding = 13; // 1 + private final int META_PipeCasing = 1; // 4 + private final int META_IntegralCasing = 6; // 0 + private final int META_ContainmentChamberCasing = 2; // 4 + + public GregtechMetaTileEntity_Adv_AssemblyLine(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + mCasingName[0] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 0); + mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); + mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); + mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); + mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); + } + + public GregtechMetaTileEntity_Adv_AssemblyLine(String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_AssemblyLine(this.mName); + } + + /* public String[] getTooltip() { + if (mCasingName[0].toLowerCase().contains(".name")) { + mCasingName[0] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 0); + } + if (mCasingName[1].toLowerCase().contains(".name")) { + mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); + } + if (mCasingName[2].toLowerCase().contains(".name")) { + mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); + } + if (mCasingName[3].toLowerCase().contains(".name")) { + mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); + } + if (mCasingName[4].toLowerCase().contains(".name")) { + mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); + } + return new String[]{ + "Advanced Integrated Assembly Line" + }; + }*/ + + @Override + protected final GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()).toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + private Block getCasing(int casingID) { + if (casingID == 1) { + return ModBlocks.blockCasingsMisc; + } else if (casingID == 2) { + return ModBlocks.blockCasings2Misc; + } else if (casingID == 3) { + return ModBlocks.blockCasings3Misc; + } else if (casingID == 4) { + return ModBlocks.blockCasings4Misc; + } else { + return ModBlocks.blockCasingsTieredGTPP; + } + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE; + } + + @Override + protected int getCasingTextureId() { + return 16; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "AssemblyLine.png"); + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public boolean checkRecipe(ItemStack aStack) { + if (GT_Values.D1) System.out.println("Start ALine recipe check"); + ArrayList<ItemStack> tDataStickList = getDataItems(2); + if (tDataStickList.size() == 0) return false; + if (GT_Values.D1) System.out.println("Stick accepted, " + tDataStickList.size() + " Data Sticks found"); + + ItemStack tStack[] = new ItemStack[15]; + FluidStack[] tFluids = new FluidStack[4]; + boolean findRecipe = false; + nextDS: + for (ItemStack tDataStick : tDataStickList) { + NBTTagCompound tTag = tDataStick.getTagCompound(); + if (tTag == null) continue; + for (int i = 0; i < 15; i++) { + int count = tTag.getInteger("a" + i); + if (!tTag.hasKey("" + i) && count <= 0) continue; + if (mInputBusses.get(i) == null) { + continue nextDS; + } + + ItemStack stackInSlot = + mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); + boolean flag = true; + if (count > 0) { + for (int j = 0; j < count; j++) { + tStack[i] = GT_Utility.loadItem(tTag, "a" + i + ":" + j); + if (tStack[i] == null) continue; + if (GT_Values.D1) System.out.println("Item " + i + " : " + tStack[i].getUnlocalizedName()); + if (GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) + && tStack[i].stackSize <= stackInSlot.stackSize) { + flag = false; + break; + } + } + } + if (flag) { + tStack[i] = GT_Utility.loadItem(tTag, "" + i); + if (tStack[i] == null) { + flag = false; + continue; + } + if (GT_Values.D1) System.out.println("Item " + i + " : " + tStack[i].getUnlocalizedName()); + if (GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) + && tStack[i].stackSize <= stackInSlot.stackSize) { + flag = false; + } + } + if (GT_Values.D1) System.out.println(i + (flag ? " not accepted" : " accepted")); + if (flag) continue nextDS; + } + + if (GT_Values.D1) System.out.println("All Items done, start fluid check"); + for (int i = 0; i < 4; i++) { + if (!tTag.hasKey("f" + i)) continue; + tFluids[i] = GT_Utility.loadFluid(tTag, "f" + i); + if (tFluids[i] == null) continue; + if (GT_Values.D1) System.out.println("Fluid " + i + " " + tFluids[i].getUnlocalizedName()); + if (mInputHatches.get(i) == null) { + continue nextDS; + } + FluidStack fluidInHatch = mInputHatches.get(i).mFluid; + if (fluidInHatch == null + || !GT_Utility.areFluidsEqual(fluidInHatch, tFluids[i], true) + || fluidInHatch.amount < tFluids[i].amount) { + if (GT_Values.D1) System.out.println(i + " not accepted"); + continue nextDS; + } + if (GT_Values.D1) System.out.println(i + " accepted"); + } + + if (GT_Values.D1) System.out.println("Input accepted, check other values"); + if (!tTag.hasKey("output")) continue; + mOutputItems = new ItemStack[] {GT_Utility.loadItem(tTag, "output")}; + if (mOutputItems[0] == null || !GT_Utility.isStackValid(mOutputItems[0])) continue; + + if (!tTag.hasKey("time")) continue; + mMaxProgresstime = tTag.getInteger("time"); + if (mMaxProgresstime <= 0) continue; + + if (!tTag.hasKey("eu")) continue; + mEUt = tTag.getInteger("eu"); + + if (GT_Values.D1) System.out.println("Find avaiable recipe"); + findRecipe = true; + break; + } + if (!findRecipe) return false; + + if (GT_Values.D1) System.out.println("All checked start consuming inputs"); + for (int i = 0; i < 15; i++) { + if (tStack[i] == null) continue; + ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); + stackInSlot.stackSize -= tStack[i].stackSize; + } + + for (int i = 0; i < 4; i++) { + if (tFluids[i] == null) continue; + mInputHatches.get(i).mFluid.amount -= tFluids[i].amount; + if (mInputHatches.get(i).mFluid.amount <= 0) { + mInputHatches.get(i).mFluid = null; + } + } + if (GT_Values.D1) System.out.println("Check overclock"); + + byte tTier = (byte) Math.max(1, GT_Utility.getTier(getMaxInputVoltage())); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + if (mEUt <= 16) { + this.mEUt = (mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + if (this.mEUt > 0) { + this.mEUt = -this.mEUt; + } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + updateSlots(); + if (GT_Values.D1) System.out.println("Recipe sucessfull"); + return true; + } + + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 20) { + GT_Utility.doSoundAtClient(GregTech_API.sSoundList.get(212), 10, 1.0F, aX, aY, aZ); + } + } + + public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 4; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 4; + + // Counts for all Casing Types + int aBaseCasingCount = 0; + int aContainmentCasingCount = 0; + int aShieldingCount = 0; + int aPipeCount = 0; + int aIntegralCasingCount = 0; + int aContainmentChamberCount = 0; + + // Bottom Layer + aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, -7, xDir, zDir); + log("Bottom Layer is Valid. Moving to Layer 1."); + + // Layer 1 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -6, xDir, zDir); + aIntegralCasingCount += + checkIntegralRing(aBaseMetaTileEntity, getCasing(0), this.META_IntegralCasing, -6, xDir, zDir); + aContainmentChamberCount += checkContainmentRing( + aBaseMetaTileEntity, getCasing(4), this.META_ContainmentChamberCasing, -6, xDir, zDir); + log("Layer 1 is Valid. Moving to Layer 2."); + + // Layer 2 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -5, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -5, xDir, zDir); + log("Layer 2 is Valid. Moving to Layer 3."); + + // Layer 3 + aContainmentCasingCount += + checkOuterRing(aBaseMetaTileEntity, getCasing(3), this.META_ContainmentCasing, -4, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -4, xDir, zDir); + log("Layer 3 is Valid. Moving to Layer 4."); + + // Layer 4 + aContainmentCasingCount += + checkOuterRing(aBaseMetaTileEntity, getCasing(3), this.META_ContainmentCasing, -3, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -3, xDir, zDir); + log("Layer 4 is Valid. Moving to Layer 5."); + + // Layer 5 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -2, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -2, xDir, zDir); + log("Layer 5 is Valid. Moving to Layer 6."); + + // Layer 6 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -1, xDir, zDir); + aIntegralCasingCount += + checkIntegralRing(aBaseMetaTileEntity, getCasing(0), this.META_IntegralCasing, -1, xDir, zDir); + aContainmentChamberCount += checkContainmentRing( + aBaseMetaTileEntity, getCasing(4), this.META_ContainmentChamberCasing, -1, xDir, zDir); + log("Layer 6 is Valid. Moving to Top Layer."); + + // Top Layer + aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, 0, xDir, zDir); + + log("Found " + aBaseCasingCount + " " + mCasingName[0] + "s"); + log("Found " + aShieldingCount + " " + mCasingName[4] + "s"); + log("Found " + aPipeCount + " " + mCasingName[1] + "s"); + log("Found " + aContainmentCasingCount + " " + mCasingName[3] + "s"); + log("Found " + aIntegralCasingCount + " " + LangUtils.getLocalizedNameOfBlock(getCasing(0), 6) + "s"); + log("Found " + aContainmentChamberCount + " " + mCasingName[2] + "s"); + + // Try mesage player + String aOwnerName = this.getBaseMetaTileEntity().getOwnerName(); + EntityPlayer aOwner = null; + if (aOwnerName != null && aOwnerName.length() > 0) { + aOwner = PlayerUtils.getPlayer(aOwnerName); + } + + if (aShieldingCount != 128) { + log("Not enough " + mCasingName[4] + "s, require 128."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough " + mCasingName[4] + "s, require 128."); + } + return false; + } + if (aPipeCount != 20) { + log("Not enough " + mCasingName[1] + "s, require 20."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough " + mCasingName[1] + "s, require 20."); + } + return false; + } + if (aContainmentCasingCount != 64) { + log("Not enough " + mCasingName[3] + "s, require 64."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough " + mCasingName[3] + "s, require 64."); + } + return false; + } + if (aContainmentChamberCount != 42) { + log("Not enough " + mCasingName[2] + "s, require 42."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough " + mCasingName[2] + "s, require 42."); + } + return false; + } + if (aBaseCasingCount < 140) { + log("Not enough " + mCasingName[0] + "s, require 140 at a minimum."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough " + mCasingName[0] + "s, require 140 at a minimum."); + } + return false; + } + if (aIntegralCasingCount != 48) { + log("Not enough " + LangUtils.getLocalizedNameOfBlock(getCasing(0), 6) + "s, require 48."); + if (aOwner != null) { + PlayerUtils.messagePlayer( + aOwner, "Not enough " + LangUtils.getLocalizedNameOfBlock(getCasing(0), 6) + "s, require 48."); + } + return false; + } + log("LNR Formed."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Large Naquadah Reactor has formed successfully."); + } + return true; + } + + public boolean addNaquadahHatchToMachineInput(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_DataAccess) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return mDataAccessHatches.add((GT_MetaTileEntity_Hatch_DataAccess) aMetaTileEntity); + } + return false; + } + + public int checkEntireLayer( + IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -4; x < 5; x++) { + for (int z = -4; z < 5; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + // Skip the corners + if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { + continue; + } + // Skip controller + if (aY == 0 && x == 0 && z == 0) { + continue; + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = + aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure( + tTileEntity, CASING_TEXTURE_ID, true, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: " + aY); + // this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + public int checkOuterRing( + IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -4; x < 5; x++) { + for (int z = -4; z < 5; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + // Skip the corners + if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { + continue; + } + + // If we are on the 5x5 ring, proceed + if ((x > -4 && x < 4) && (z > -4 && z < 4)) { + if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { + // this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, + // 3); + } else { + continue; + } + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = + aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure( + tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: " + aY); + // this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + public int checkIntegralRing( + IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -3; x < 4; x++) { + for (int z = -3; z < 4; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + // Skip the corners + if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { + continue; + } + + // If we are on the 5x5 ring, proceed + if ((x > -3 && x < 3) && (z > -3 && z < 3)) { + if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { + // this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, + // 3); + } else { + continue; + } + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = + aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure( + tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: " + aY); + // this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + public int checkPipes( + IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -1; x < 2; x++) { + for (int z = -1; z < 2; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + // Skip the corners + if ((x == 1 && z == 1) + || (x == -1 && z == -1) + || (x == 1 && z == -1) + || (x == -1 && z == 1) + || (x == 0 && z == 0)) { + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = + aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure( + tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Pipe has error. Height: " + aY); + // this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, + // 3); + return 0; + } + ; + } + } + } + return aCasingCount; + } + + public int checkContainmentRing( + IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -2; x < 3; x++) { + for (int z = -2; z < 3; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + // Skip the corners + if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { + continue; + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = + aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure( + tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: " + aY); + // this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + /** + * @param state using bitmask, 1 for IntegratedCircuit, 2 for DataStick, 4 for DataOrb + */ + private boolean isCorrectDataItem(ItemStack aStack, int state) { + if ((state & 1) != 0 && ItemList.Circuit_Integrated.isStackEqual(aStack, true, true)) return true; + if ((state & 2) != 0 && ItemList.Tool_DataStick.isStackEqual(aStack, false, true)) return true; + if ((state & 4) != 0 && ItemList.Tool_DataOrb.isStackEqual(aStack, false, true)) return true; + return false; + } + + /** + * @param state using bitmask, 1 for IntegratedCircuit, 2 for DataStick, 4 for DataOrb + */ + public ArrayList<ItemStack> getDataItems(int state) { + ArrayList<ItemStack> rList = new ArrayList<ItemStack>(); + if (GT_Utility.isStackValid(mInventory[1]) && isCorrectDataItem(mInventory[1], state)) { + rList.add(mInventory[1]); + } + for (GT_MetaTileEntity_Hatch_DataAccess tHatch : mDataAccessHatches) { + if (isValidMetaTileEntity(tHatch)) { + for (int i = 0; i < tHatch.getBaseMetaTileEntity().getSizeInventory(); i++) { + if (tHatch.getBaseMetaTileEntity().getStackInSlot(i) != null + && isCorrectDataItem(tHatch.getBaseMetaTileEntity().getStackInSlot(i), state)) + rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + } + return rList; + } + + public boolean addDataAccessToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_DataAccess) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return mDataAccessHatches.add((GT_MetaTileEntity_Hatch_DataAccess) aMetaTileEntity); + } + return false; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Assembly Line"; + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + // Fix GT bug + if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { + log("Fixing Bad Facing. (GT Bug)"); + this.getBaseMetaTileEntity().setFrontFacing((byte) 1); + } + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + // TODO Auto-generated method stub + + } + + @Override + public IStructureDefinition getStructureDefinition() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + // TODO Auto-generated method stub + return false; + } } - diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java index 8b24bb2d0d..6058d23996 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java @@ -1,7 +1,9 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -26,6 +28,8 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -33,433 +37,454 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; - -public class GregtechMetaTileEntity_Adv_DistillationTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_DistillationTower> implements ISurvivalConstructable { - - private Mode mMode = Mode.DistillationTower; - private boolean mUpgraded = false; - - protected static final String STRUCTURE_PIECE_BASE = "base"; - protected static final String STRUCTURE_PIECE_LAYER = "layer"; - protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; - protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; - - protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); - protected int mHeight; - protected int mCasing; - protected boolean mTopLayerFound; - - private static IStructureDefinition<GregtechMetaTileEntity_Adv_DistillationTower> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_Adv_DistillationTower(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_Adv_DistillationTower(String aName) { - super(aName); - } - - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_Adv_DistillationTower(this.mName); - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_Adv_DistillationTower> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - IHatchElement<GregtechMetaTileEntity_Adv_DistillationTower> layeredOutputHatch = OutputHatch - .withCount(GregtechMetaTileEntity_Adv_DistillationTower::getCurrentLayerOutputHatchCount) - .withAdder(GregtechMetaTileEntity_Adv_DistillationTower::addLayerOutputHatch); - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_DistillationTower>builder() - .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][]{ - {"b~b", "bbb", "bbb"}, - })) - .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][]{ - {"lll", "lcl", "lll"} - })) - .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][]{ - {"lll", "l-l", "lll"} - })) - .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][]{ - {"ttt", "ttt", "ttt"} - })) - .addElement('b', ofChain( - buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) - .atLeast(Energy, OutputBus, InputHatch, InputBus, Maintenance) - .casingIndex(getCasingTextureId()) - .dot(1) - .build(), - ofBlock(GregTech_API.sBlockCasings4, 1) - )) - .addElement('l', buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) - .atLeast(layeredOutputHatch, Muffler, Energy, Maintenance) - .casingIndex(getCasingTextureId()) - .dot(2) - .buildAndChain(GregTech_API.sBlockCasings4, 1) - ) - .addElement('c', ofChain( - onElementPass(GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, ofHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower::addMufflerToMachineList, getCasingTextureId(), 3)), - onElementPass(GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, ofHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower::addOutputToMachineList, getCasingTextureId(), 3)), - onElementPass(GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, ofHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower::addMaintenanceToMachineList, getCasingTextureId(), 3)), - onElementPass(GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, ofBlock(GregTech_API.sBlockCasings4, 1)), - isAir() - )) - .addElement('t', buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) - .atLeast(layeredOutputHatch, Muffler) - .casingIndex(getCasingTextureId()) - .dot(2) - .buildAndChain(GregTech_API.sBlockCasings4, 1) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - - protected int getCurrentLayerOutputHatchCount() { - return mOutputHatchesByLayer.size() < mHeight ? 0 : mOutputHatchesByLayer.get(mHeight - 1).size(); - } - - protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null || aTileEntity.isDead() || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output)) - return false; - while (mOutputHatchesByLayer.size() < mHeight) - mOutputHatchesByLayer.add(new ArrayList<>()); - GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) aTileEntity.getMetaTileEntity(); - tHatch.updateTexture(aBaseCasingIndex); - return mOutputHatchesByLayer.get(mHeight - 1).add(tHatch); - } - - protected void onTopLayerFound() { - mTopLayerFound = true; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Advanced Distillation Tower") - .addInfo("Use 15% less energy in distillery mode") - .addInfo("250%/100% faster in DT/distillery mode") - .addInfo("Right click the controller with screwdriver to change mode.") - .addInfo("Max parallel dictated by tower tier and mode") - .addInfo("DTower Mode: T1=4, T2=12") - .addInfo("Distilery Mode: Tower Tier * (4*InputTier)") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .addCasingInfo("Clean Stainless Steel Machine Casing", 7) - .addInputBus("Bottom Casing", 1) - .addOutputBus("Bottom Casing", 1) - .addInputHatch("Bottom Casing", 1) - .addMaintenanceHatch("Bottom Casing", 1) - .addEnergyHatch("Bottom Casing", 1) - .addOutputHatch("One per layer except bottom", 2) - .addMufflerHatch("Top Casing", 3) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); - int tTotalHeight = Math.min(12, stackSize.stackSize + 2); // min 2 output layer, so at least 1 + 2 height - for (int i = 1; i < tTotalHeight - 1; i++) { - buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); - } - buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - mHeight = 0; - int built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 1, 0, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - int tTotalHeight = Math.min(12, stackSize.stackSize + 2); // min 2 output layer, so at least 1 + 2 height - for (int i = 1; i < tTotalHeight - 1; i++) { - mHeight = i; - built = survivialBuildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, 1, i, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - } - mHeight = tTotalHeight; - return survivialBuildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, 1, tTotalHeight - 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - // reset - mOutputHatchesByLayer.forEach(List::clear); - mHeight = 1; - mTopLayerFound = false; - - // check base - if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) - return false; - - // check each layer - while (mHeight < 12) { - if (!checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0)) { - return false; - } - if (mOutputHatchesByLayer.size() < mHeight || mOutputHatchesByLayer.get(mHeight - 1).isEmpty()) - // layer without output hatch - return false; - if (mTopLayerFound || !mMufflerHatches.isEmpty()) { - break; - } - // not top - mHeight++; - } - return mTopLayerFound && mHeight >= 2 && checkHatch(); - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName()+(mUpgraded ? " T2" : ""), "MultiblockDisplay.png"); - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return mMode.getRecipeMap(); - } - - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - @Override - protected IAlignmentLimits getInitialAlignmentLimits() { - // don't rotate a freaking tower, it won't work - return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); - } - - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(ItemStack aStack) { - if (this.mMode == Mode.Distillery) return CORE.ConfigSwitches.pollutionPerSecondMultiAdvDistillationTower_ModeDistillery; - return CORE.ConfigSwitches.pollutionPerSecondMultiAdvDistillationTower_ModeDT; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setByte("mMode", (byte) mMode.ordinal()); - aNBT.setBoolean("mUpgraded", mUpgraded); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mMode = Mode.values()[aNBT.getByte("mMode")]; - mUpgraded = aNBT.getBoolean("mUpgraded"); - super.loadNBTData(aNBT); - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - mMode = mMode.next(); - PlayerUtils.messagePlayer(aPlayer, "Now running in " + mMode + " Mode."); - } - - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public boolean addOutput(FluidStack aLiquid) { - if (aLiquid == null) return false; - FluidStack copiedFluidStack = aLiquid.copy(); - for (List<GT_MetaTileEntity_Hatch_Output> hatches : mOutputHatchesByLayer) { - if (dumpFluid(hatches, copiedFluidStack, true)) - return true; - } - for (List<GT_MetaTileEntity_Hatch_Output> hatches : mOutputHatchesByLayer) { - if (dumpFluid(hatches, copiedFluidStack, false)) - return true; - } - return false; - } - - @Override - protected void addFluidOutputs(FluidStack[] mOutputFluids2) { - if (mMode == Mode.DistillationTower) { - // dt mode - for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { - FluidStack tStack = mOutputFluids2[i].copy(); - if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) - dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); - } - } else { - // distillery mode - for (FluidStack outputFluidStack : mOutputFluids2) { - addOutput(outputFluidStack); - } - } - } - - @Override - public int canBufferOutputs(ItemStack[] aItemOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) { - // do void excess checks - if (mVoidExcess) return aParallelRecipes; - // sb mode. no need to check layered outputs - if (mMode == Mode.Distillery) return super.canBufferOutputs(aItemOutputs, aFluidOutputs, aParallelRecipes); - // not enough output hatches - if (mOutputHatchesByLayer.size() < aFluidOutputs.length) { - log("Not enough output layers for distillation towers"); - return 0; - } - // first check if item output can be held. We delegate this to super class since we do not have special item hatches - aParallelRecipes = super.canBufferOutputs(aItemOutputs, new FluidStack[0], aParallelRecipes); - if (aParallelRecipes == 0) return 0; - for (int i = 0; i < aFluidOutputs.length; i++) { - FluidStack tFluidOutput = aFluidOutputs[i]; - FluidStack tCopied = new FluidStack(tFluidOutput, 0); - int toFill = tFluidOutput.amount * aParallelRecipes; - for (GT_MetaTileEntity_Hatch_Output hatch : mOutputHatchesByLayer.get(i)) { - boolean fluidMatch = - hatch.isFluidLocked() ? - tFluidOutput.getFluid().getName().equals(hatch.getLockedFluidName()) : - hatch.getFluid() == null || hatch.getFluid().isFluidEqual(tFluidOutput); - - if (fluidMatch) { - tCopied.amount = toFill; - toFill -= hatch.fill(tCopied, false); - if (toFill == 0) - // no more current fluid to fill. break out to go to next fluid - break; - } - } - // use ceil div - aParallelRecipes -= (toFill + tFluidOutput.amount - 1) / tFluidOutput.amount; - } - return aParallelRecipes; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "DistillationTower"; - } - - @Override - public String getMachineType() { - return "Distillery, Distillation Tower"; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - // Run standard recipe handling for distillery recipes - if (mMode == Mode.Distillery) { - return this.checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 100); - } - else { - ItemStack[] inputs = getCompactedInputs(); - - for (GT_MetaTileEntity_Hatch_Input hatch : mInputHatches) { - FluidStack tFluid = hatch.getFluid(); - if (tFluid != null) { - if (checkRecipeGeneric(inputs, new FluidStack[]{tFluid}, getMaxParallelRecipes(), 100, 250, 10000)) { - return true; - } - } - } - return false; - } - } - - @Override - public int getMaxParallelRecipes() { - switch (mMode) { - case DistillationTower: - return getTierOfTower() == 1 ? 4 : getTierOfTower() == 2 ? 12 : 0; - case Distillery: - return getTierOfTower() * (4 * GT_Utility.getTier(this.getMaxInputVoltage())); - default: - return 0; - } - } - - @Override - public int getEuDiscountForParallelism() { - return 15; - } - - private int getTierOfTower() { - return mUpgraded ? 2 : 1; - } - - @Override - protected IIconContainer getActiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER; - } - - @Override - protected int getCasingTextureId() { - return 49; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (aTick % 20 == 0 && !mUpgraded) { - ItemStack aGuiStack = this.getGUIItemStack(); - if (aGuiStack != null) { - if (GT_Utility.areStacksEqual(aGuiStack, GregtechItemList.Distillus_Upgrade_Chip.get(1))) { - this.mUpgraded = true; - ItemUtils.depleteStack(aGuiStack); - } - } - } - } - - @Override - public void setItemNBT(NBTTagCompound aNBT) { - aNBT.setBoolean("mUpgraded", mUpgraded); - super.setItemNBT(aNBT); - } - - private enum Mode { - DistillationTower(GT_Recipe_Map.sDistillationRecipes), - Distillery(GT_Recipe_Map.sDistilleryRecipes), - ; - static final Mode[] VALUES = values(); - private final GT_Recipe_Map recipeMap; - - Mode(GT_Recipe_Map recipeMap) { - this.recipeMap = recipeMap; - } - - public GT_Recipe_Map getRecipeMap() { - return recipeMap; - } - - public Mode next() { - return VALUES[ordinal() + 1 % VALUES.length]; - } - } -}
\ No newline at end of file +public class GregtechMetaTileEntity_Adv_DistillationTower + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_DistillationTower> + implements ISurvivalConstructable { + + private Mode mMode = Mode.DistillationTower; + private boolean mUpgraded = false; + + protected static final String STRUCTURE_PIECE_BASE = "base"; + protected static final String STRUCTURE_PIECE_LAYER = "layer"; + protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; + protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; + + protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); + protected int mHeight; + protected int mCasing; + protected boolean mTopLayerFound; + + private static IStructureDefinition<GregtechMetaTileEntity_Adv_DistillationTower> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Adv_DistillationTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Adv_DistillationTower(String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_DistillationTower(this.mName); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_DistillationTower> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + IHatchElement<GregtechMetaTileEntity_Adv_DistillationTower> layeredOutputHatch = OutputHatch.withCount( + GregtechMetaTileEntity_Adv_DistillationTower::getCurrentLayerOutputHatchCount) + .withAdder(GregtechMetaTileEntity_Adv_DistillationTower::addLayerOutputHatch); + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_DistillationTower>builder() + .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][] { + {"b~b", "bbb", "bbb"}, + })) + .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][] {{"lll", "lcl", "lll"}})) + .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][] {{"lll", "l-l", "lll"}})) + .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][] {{"ttt", "ttt", "ttt"}})) + .addElement( + 'b', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) + .atLeast(Energy, OutputBus, InputHatch, InputBus, Maintenance) + .casingIndex(getCasingTextureId()) + .dot(1) + .build(), + ofBlock(GregTech_API.sBlockCasings4, 1))) + .addElement( + 'l', + buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) + .atLeast(layeredOutputHatch, Muffler, Energy, Maintenance) + .casingIndex(getCasingTextureId()) + .dot(2) + .buildAndChain(GregTech_API.sBlockCasings4, 1)) + .addElement( + 'c', + ofChain( + onElementPass( + GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, + ofHatchAdder( + GregtechMetaTileEntity_Adv_DistillationTower + ::addMufflerToMachineList, + getCasingTextureId(), + 3)), + onElementPass( + GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, + ofHatchAdder( + GregtechMetaTileEntity_Adv_DistillationTower + ::addOutputToMachineList, + getCasingTextureId(), + 3)), + onElementPass( + GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, + ofHatchAdder( + GregtechMetaTileEntity_Adv_DistillationTower + ::addMaintenanceToMachineList, + getCasingTextureId(), + 3)), + onElementPass( + GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, + ofBlock(GregTech_API.sBlockCasings4, 1)), + isAir())) + .addElement( + 't', + buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) + .atLeast(layeredOutputHatch, Muffler) + .casingIndex(getCasingTextureId()) + .dot(2) + .buildAndChain(GregTech_API.sBlockCasings4, 1)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + protected int getCurrentLayerOutputHatchCount() { + return mOutputHatchesByLayer.size() < mHeight + ? 0 + : mOutputHatchesByLayer.get(mHeight - 1).size(); + } + + protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null + || aTileEntity.isDead() + || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output)) return false; + while (mOutputHatchesByLayer.size() < mHeight) mOutputHatchesByLayer.add(new ArrayList<>()); + GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) aTileEntity.getMetaTileEntity(); + tHatch.updateTexture(aBaseCasingIndex); + return mOutputHatchesByLayer.get(mHeight - 1).add(tHatch); + } + + protected void onTopLayerFound() { + mTopLayerFound = true; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Advanced Distillation Tower") + .addInfo("Use 15% less energy in distillery mode") + .addInfo("250%/100% faster in DT/distillery mode") + .addInfo("Right click the controller with screwdriver to change mode.") + .addInfo("Max parallel dictated by tower tier and mode") + .addInfo("DTower Mode: T1=4, T2=12") + .addInfo("Distilery Mode: Tower Tier * (4*InputTier)") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addCasingInfo("Clean Stainless Steel Machine Casing", 7) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addOutputHatch("One per layer except bottom", 2) + .addMufflerHatch("Top Casing", 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); + int tTotalHeight = Math.min(12, stackSize.stackSize + 2); // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); + } + buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + mHeight = 0; + int built = survivialBuildPiece( + STRUCTURE_PIECE_BASE, stackSize, 1, 0, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + int tTotalHeight = Math.min(12, stackSize.stackSize + 2); // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + mHeight = i; + built = survivialBuildPiece( + STRUCTURE_PIECE_LAYER_HINT, stackSize, 1, i, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + } + mHeight = tTotalHeight; + return survivialBuildPiece( + STRUCTURE_PIECE_TOP_HINT, stackSize, 1, tTotalHeight - 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + // reset + mOutputHatchesByLayer.forEach(List::clear); + mHeight = 1; + mTopLayerFound = false; + + // check base + if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) return false; + + // check each layer + while (mHeight < 12) { + if (!checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0)) { + return false; + } + if (mOutputHatchesByLayer.size() < mHeight + || mOutputHatchesByLayer.get(mHeight - 1).isEmpty()) + // layer without output hatch + return false; + if (mTopLayerFound || !mMufflerHatches.isEmpty()) { + break; + } + // not top + mHeight++; + } + return mTopLayerFound && mHeight >= 2 && checkHatch(); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, + aBaseMetaTileEntity, + getLocalName() + (mUpgraded ? " T2" : ""), + "MultiblockDisplay.png"); + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mMode.getRecipeMap(); + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a freaking tower, it won't work + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + if (this.mMode == Mode.Distillery) + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvDistillationTower_ModeDistillery; + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvDistillationTower_ModeDT; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mMode", (byte) mMode.ordinal()); + aNBT.setBoolean("mUpgraded", mUpgraded); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mMode = Mode.values()[aNBT.getByte("mMode")]; + mUpgraded = aNBT.getBoolean("mUpgraded"); + super.loadNBTData(aNBT); + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mMode = mMode.next(); + PlayerUtils.messagePlayer(aPlayer, "Now running in " + mMode + " Mode."); + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) return false; + FluidStack copiedFluidStack = aLiquid.copy(); + for (List<GT_MetaTileEntity_Hatch_Output> hatches : mOutputHatchesByLayer) { + if (dumpFluid(hatches, copiedFluidStack, true)) return true; + } + for (List<GT_MetaTileEntity_Hatch_Output> hatches : mOutputHatchesByLayer) { + if (dumpFluid(hatches, copiedFluidStack, false)) return true; + } + return false; + } + + @Override + protected void addFluidOutputs(FluidStack[] mOutputFluids2) { + if (mMode == Mode.DistillationTower) { + // dt mode + for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { + FluidStack tStack = mOutputFluids2[i].copy(); + if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) + dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); + } + } else { + // distillery mode + for (FluidStack outputFluidStack : mOutputFluids2) { + addOutput(outputFluidStack); + } + } + } + + @Override + public int canBufferOutputs(ItemStack[] aItemOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) { + // do void excess checks + if (mVoidExcess) return aParallelRecipes; + // sb mode. no need to check layered outputs + if (mMode == Mode.Distillery) return super.canBufferOutputs(aItemOutputs, aFluidOutputs, aParallelRecipes); + // not enough output hatches + if (mOutputHatchesByLayer.size() < aFluidOutputs.length) { + log("Not enough output layers for distillation towers"); + return 0; + } + // first check if item output can be held. We delegate this to super class since we do not have special item + // hatches + aParallelRecipes = super.canBufferOutputs(aItemOutputs, new FluidStack[0], aParallelRecipes); + if (aParallelRecipes == 0) return 0; + for (int i = 0; i < aFluidOutputs.length; i++) { + FluidStack tFluidOutput = aFluidOutputs[i]; + FluidStack tCopied = new FluidStack(tFluidOutput, 0); + int toFill = tFluidOutput.amount * aParallelRecipes; + for (GT_MetaTileEntity_Hatch_Output hatch : mOutputHatchesByLayer.get(i)) { + boolean fluidMatch = hatch.isFluidLocked() + ? tFluidOutput.getFluid().getName().equals(hatch.getLockedFluidName()) + : hatch.getFluid() == null || hatch.getFluid().isFluidEqual(tFluidOutput); + + if (fluidMatch) { + tCopied.amount = toFill; + toFill -= hatch.fill(tCopied, false); + if (toFill == 0) + // no more current fluid to fill. break out to go to next fluid + break; + } + } + // use ceil div + aParallelRecipes -= (toFill + tFluidOutput.amount - 1) / tFluidOutput.amount; + } + return aParallelRecipes; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "DistillationTower"; + } + + @Override + public String getMachineType() { + return "Distillery, Distillation Tower"; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + // Run standard recipe handling for distillery recipes + if (mMode == Mode.Distillery) { + return this.checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 100); + } else { + ItemStack[] inputs = getCompactedInputs(); + + for (GT_MetaTileEntity_Hatch_Input hatch : mInputHatches) { + FluidStack tFluid = hatch.getFluid(); + if (tFluid != null) { + if (checkRecipeGeneric( + inputs, new FluidStack[] {tFluid}, getMaxParallelRecipes(), 100, 250, 10000)) { + return true; + } + } + } + return false; + } + } + + @Override + public int getMaxParallelRecipes() { + switch (mMode) { + case DistillationTower: + return getTierOfTower() == 1 ? 4 : getTierOfTower() == 2 ? 12 : 0; + case Distillery: + return getTierOfTower() * (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + default: + return 0; + } + } + + @Override + public int getEuDiscountForParallelism() { + return 15; + } + + private int getTierOfTower() { + return mUpgraded ? 2 : 1; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER; + } + + @Override + protected int getCasingTextureId() { + return 49; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aTick % 20 == 0 && !mUpgraded) { + ItemStack aGuiStack = this.getGUIItemStack(); + if (aGuiStack != null) { + if (GT_Utility.areStacksEqual(aGuiStack, GregtechItemList.Distillus_Upgrade_Chip.get(1))) { + this.mUpgraded = true; + ItemUtils.depleteStack(aGuiStack); + } + } + } + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + aNBT.setBoolean("mUpgraded", mUpgraded); + super.setItemNBT(aNBT); + } + + private enum Mode { + DistillationTower(GT_Recipe_Map.sDistillationRecipes), + Distillery(GT_Recipe_Map.sDistilleryRecipes), + ; + static final Mode[] VALUES = values(); + private final GT_Recipe_Map recipeMap; + + Mode(GT_Recipe_Map recipeMap) { + this.recipeMap = recipeMap; + } + + public GT_Recipe_Map getRecipeMap() { + return recipeMap; + } + + public Mode next() { + return VALUES[ordinal() + 1 % VALUES.length]; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java index 5c16be3e88..d493b695a6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java @@ -1,7 +1,13 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -19,10 +25,11 @@ import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -31,473 +38,473 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.ofCoil; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_Adv_EBF extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_EBF> implements ISurvivalConstructable { - - public static int CASING_TEXTURE_ID; - public static String mHotFuelName = "Blazing Pyrotheum"; - public static String mCasingName = "Volcanus Casing"; - public static String mHatchName = "Pyrotheum Hatch"; - private IStructureDefinition<GregtechMetaTileEntity_Adv_EBF> STRUCTURE_DEFINITION = null; - private int mCasing; - private final ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mPyrotheumHatches = new ArrayList<>(); - - private HeatingCoilLevel mHeatingCapacity; - private boolean isBussesSeparate = false; - - public GregtechMetaTileEntity_Adv_EBF(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 11); - } - - public GregtechMetaTileEntity_Adv_EBF(String aName) { - super(aName); - CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 11); - } - - @Override - public String getMachineType() { - return "Blast Furnace"; - } - - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_Adv_EBF(this.mName); - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Factory Grade Advanced Blast Furnace") - .addInfo("Speed: +120% | EU Usage: 90% | Parallel: 8") - .addInfo("Consumes 10L of " + mHotFuelName + " per second during operation") - .addInfo("Constructed exactly the same as a normal EBF") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .addController("Bottom center") - .addCasingInfo(mCasingName, 9) - .addInputHatch("Any Casing", 1) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addStructureHint(mHatchName, 1) - .addEnergyHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_Adv_EBF> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_EBF>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"HHH", "H-H", "HHH"}, - {"HHH", "H-H", "HHH"}, - {"C~C", "CCC", "CCC"}, - })) - .addElement( - 'C', - ofChain( - buildHatchAdder(GregtechMetaTileEntity_Adv_EBF.class) - .adder(GregtechMetaTileEntity_Adv_EBF::addPyrotheumHatch) - .hatchId(968) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .build(), - buildHatchAdder(GregtechMetaTileEntity_Adv_EBF.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .build(), - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasings3Misc, 11 - ) - ) - ) - ) - .addElement( - 'H', - ofCoil( - GregtechMetaTileEntity_Adv_EBF::setCoilLevel, GregtechMetaTileEntity_Adv_EBF::getCoilLevel - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName, stackSize, hintsOnly, 1, 3, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mPyrotheumHatches.clear(); - setCoilLevel(HeatingCoilLevel.None); - return checkPiece(mName, 1, 3, 0) && mCasing >= 9 && getCoilLevel() != HeatingCoilLevel.None && checkHatch(); - } - - @Override - public boolean checkHatch() { - return super.checkHatch() || !mPyrotheumHatches.isEmpty(); - } - - private boolean addPyrotheumHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 968) { - return addToMachineListInternal(mPyrotheumHatches, aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public void updateSlots() { - for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mPyrotheumHatches) - if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); - super.updateSlots(); - } - - private boolean depleteFuel(int aAmount) { - for (final GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : this.mPyrotheumHatches) { - if (isValidMetaTileEntity(tHatch)) { - FluidStack tLiquid = tHatch.getFluid(); - if (tLiquid == null || tLiquid.amount < aAmount) { - continue; - } - tLiquid = tHatch.drain(aAmount, false); - if (tLiquid != null && tLiquid.amount >= aAmount) { - tLiquid = tHatch.drain(aAmount, true); - return tLiquid != null && tLiquid.amount >= aAmount; - } - } - } - return false; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return CASING_TEXTURE_ID; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "ElectricBlastFurnace"; - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sBlastRecipes; - } - - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - if (isBussesSeparate) { - FluidStack[] tFluids = getStoredFluids().toArray(new FluidStack[0]); - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - ArrayList<ItemStack> tInputs = new ArrayList<>(); - if (isValidMetaTileEntity(tBus)) { - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) { - tInputs.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - } - if (tInputs.size() > 0) { - if (checkRecipeGeneric(tInputs.toArray(new ItemStack[0]), tFluids, 8, 90, 120, 10000)) { - return true; - } - } - } - return false; - } else { - return checkRecipeGeneric(8, 90, 120); - } - } - - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiAdvEBF; - } - - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, - long aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[] {}; - this.mOutputFluids = new FluidStack[] {}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - Logger.WARNING("Running checkRecipeGeneric(0)"); - - GT_Recipe tRecipe = this.getRecipeMap().findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - - Logger.WARNING("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - if (tRecipe == null || this.mHeatingCapacity.getHeat() < tRecipe.mSpecialValue) { - Logger.WARNING("BAD RETURN - 1"); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - Logger.WARNING("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - int tHeatCapacityDivTiers = (int) (mHeatingCapacity.getHeat() - tRecipe.mSpecialValue) / 900; - if (tHeatCapacityDivTiers > 0) - tRecipeEUt = (int) (tRecipeEUt * (Math.pow(0.95, tHeatCapacityDivTiers))); - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - // Count recipes to do in parallel, consuming input items and fluids and - // considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - Logger.WARNING("Broke at " + parallelRecipes + "."); - break; - } - Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - Logger.WARNING("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); - int tHalfHeatCapacityDivTiers = tHeatCapacityDivTiers / 2; - - this.mEUt = (int) Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - if (tHalfHeatCapacityDivTiers > 0) { - this.mMaxProgresstime = mMaxProgresstime / 4; - tHalfHeatCapacityDivTiers--; - } else { - this.mMaxProgresstime = mMaxProgresstime / 2; - } - if (this.mMaxProgresstime <= 1) { - break; - } - } - } - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) - tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - Logger.WARNING("GOOD RETURN - 1"); - return true; - - } - - private int mGraceTimer = 2; - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - //Try dry Pyrotheum after all other logic - if (this.mStartUpCheck < 0) { - if (this.mMaxProgresstime > 0 && this.mProgresstime != 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { - if (aTick % 10 == 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { - if (!this.depleteInputFromRestrictedHatches(this.mPyrotheumHatches, 5)) { - if (mGraceTimer-- == 0) { - this.causeMaintenanceIssue(); - this.stopMachine(); - mGraceTimer = 2; - } - } - } - } - } - - } - - @Override - public int getMaxParallelRecipes() { - return 8; - } - - @Override - public int getEuDiscountForParallelism() { - return 90; - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - isBussesSeparate = !isBussesSeparate; - aPlayer.addChatMessage(new ChatComponentTranslation(isBussesSeparate ? "interaction.separateBusses.enabled" : "interaction.separateBusses.disabled")); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("isBussesSeparate", isBussesSeparate); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - isBussesSeparate = aNBT.getBoolean("isBussesSeparate"); - super.loadNBTData(aNBT); - } - - public HeatingCoilLevel getCoilLevel() { - return mHeatingCapacity; - } - - public void setCoilLevel(HeatingCoilLevel aCoilLevel) { - mHeatingCapacity = aCoilLevel; - } +public class GregtechMetaTileEntity_Adv_EBF extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_EBF> + implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + public static String mHotFuelName = "Blazing Pyrotheum"; + public static String mCasingName = "Volcanus Casing"; + public static String mHatchName = "Pyrotheum Hatch"; + private IStructureDefinition<GregtechMetaTileEntity_Adv_EBF> STRUCTURE_DEFINITION = null; + private int mCasing; + private final ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mPyrotheumHatches = new ArrayList<>(); + + private HeatingCoilLevel mHeatingCapacity; + private boolean isBussesSeparate = false; + + public GregtechMetaTileEntity_Adv_EBF(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 11); + } + + public GregtechMetaTileEntity_Adv_EBF(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 11); + } + + @Override + public String getMachineType() { + return "Blast Furnace"; + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_EBF(this.mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Blast Furnace") + .addInfo("Speed: +120% | EU Usage: 90% | Parallel: 8") + .addInfo("Consumes 10L of " + mHotFuelName + " per second during operation") + .addInfo("Constructed exactly the same as a normal EBF") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addController("Bottom center") + .addCasingInfo(mCasingName, 9) + .addInputHatch("Any Casing", 1) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addStructureHint(mHatchName, 1) + .addEnergyHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_EBF> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_EBF>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_Adv_EBF.class) + .adder(GregtechMetaTileEntity_Adv_EBF::addPyrotheumHatch) + .hatchId(968) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_Adv_EBF.class) + .atLeast( + InputBus, + OutputBus, + Maintenance, + Energy, + Muffler, + InputHatch, + OutputHatch) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 11)))) + .addElement( + 'H', + ofCoil( + GregtechMetaTileEntity_Adv_EBF::setCoilLevel, + GregtechMetaTileEntity_Adv_EBF::getCoilLevel)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mPyrotheumHatches.clear(); + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 3, 0) && mCasing >= 9 && getCoilLevel() != HeatingCoilLevel.None && checkHatch(); + } + + @Override + public boolean checkHatch() { + return super.checkHatch() || !mPyrotheumHatches.isEmpty(); + } + + private boolean addPyrotheumHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase + && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 968) { + return addToMachineListInternal(mPyrotheumHatches, aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void updateSlots() { + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mPyrotheumHatches) + if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); + super.updateSlots(); + } + + private boolean depleteFuel(int aAmount) { + for (final GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : this.mPyrotheumHatches) { + if (isValidMetaTileEntity(tHatch)) { + FluidStack tLiquid = tHatch.getFluid(); + if (tLiquid == null || tLiquid.amount < aAmount) { + continue; + } + tLiquid = tHatch.drain(aAmount, false); + if (tLiquid != null && tLiquid.amount >= aAmount) { + tLiquid = tHatch.drain(aAmount, true); + return tLiquid != null && tLiquid.amount >= aAmount; + } + } + } + return false; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ElectricBlastFurnace"; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sBlastRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + if (isBussesSeparate) { + FluidStack[] tFluids = getStoredFluids().toArray(new FluidStack[0]); + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tInputs = new ArrayList<>(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) { + tInputs.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + } + if (tInputs.size() > 0) { + if (checkRecipeGeneric(tInputs.toArray(new ItemStack[0]), tFluids, 8, 90, 120, 10000)) { + return true; + } + } + } + return false; + } else { + return checkRecipeGeneric(8, 90, 120); + } + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvEBF; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + Logger.WARNING("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = this.getRecipeMap() + .findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + + Logger.WARNING("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null || this.mHeatingCapacity.getHeat() < tRecipe.mSpecialValue) { + Logger.WARNING("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + int tHeatCapacityDivTiers = (int) (mHeatingCapacity.getHeat() - tRecipe.mSpecialValue) / 900; + if (tHeatCapacityDivTiers > 0) tRecipeEUt = (int) (tRecipeEUt * (Math.pow(0.95, tHeatCapacityDivTiers))); + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and + // considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + Logger.WARNING("Broke at " + parallelRecipes + "."); + break; + } + Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + int tHalfHeatCapacityDivTiers = tHeatCapacityDivTiers / 2; + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + if (tHalfHeatCapacityDivTiers > 0) { + this.mMaxProgresstime = mMaxProgresstime / 4; + tHalfHeatCapacityDivTiers--; + } else { + this.mMaxProgresstime = mMaxProgresstime / 2; + } + if (this.mMaxProgresstime <= 1) { + break; + } + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.WARNING("GOOD RETURN - 1"); + return true; + } + + private int mGraceTimer = 2; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + // Try dry Pyrotheum after all other logic + if (this.mStartUpCheck < 0) { + if (this.mMaxProgresstime > 0 && this.mProgresstime != 0 + || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + if (aTick % 10 == 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + if (!this.depleteInputFromRestrictedHatches(this.mPyrotheumHatches, 5)) { + if (mGraceTimer-- == 0) { + this.causeMaintenanceIssue(); + this.stopMachine(); + mGraceTimer = 2; + } + } + } + } + } + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + @Override + public int getEuDiscountForParallelism() { + return 90; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + isBussesSeparate = !isBussesSeparate; + aPlayer.addChatMessage(new ChatComponentTranslation( + isBussesSeparate ? "interaction.separateBusses.enabled" : "interaction.separateBusses.disabled")); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("isBussesSeparate", isBussesSeparate); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + isBussesSeparate = aNBT.getBoolean("isBussesSeparate"); + super.loadNBTData(aNBT); + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java index 8aa91fa41a..8df07d8990 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java @@ -19,16 +19,15 @@ import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import net.minecraft.block.Block; - import java.lang.reflect.Method; +import net.minecraft.block.Block; public class GregtechMetaTileEntity_Adv_Fusion_MK4 extends GT_MetaTileEntity_FusionComputer { - public static final Method mUpdateHatchTexture; - - static { - mUpdateHatchTexture = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); + public static final Method mUpdateHatchTexture; + + static { + mUpdateHatchTexture = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); } public GregtechMetaTileEntity_Adv_Fusion_MK4(int aID, String aName, String aNameRegional) { @@ -56,7 +55,7 @@ public class GregtechMetaTileEntity_Adv_Fusion_MK4 extends GT_MetaTileEntity_Fus .addStructureInfo("ALL Hatches must be UHV or better") .toolTipFinisher(CORE.GT_Tooltip_Builder); return tt; - } + } @Override public int tier() { @@ -69,91 +68,107 @@ public class GregtechMetaTileEntity_Adv_Fusion_MK4 extends GT_MetaTileEntity_Fus } @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_Adv_Fusion_MK4(mName); - } - - @Override - public Block getCasing() { - return getFusionCoil(); - } - - @Override - public int getCasingMeta() { - return 12; - } - - @Override - public Block getFusionCoil() { - return ModBlocks.blockCasings3Misc; - } - - @Override - public int getFusionCoilMeta() { - return 13; - } - - @Override - public int tierOverclock() { - return 8; - } - - @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_Fusion_MK4(mName); + } + + @Override + public Block getCasing() { + return getFusionCoil(); + } + + @Override + public int getCasingMeta() { + return 12; + } + + @Override + public Block getFusionCoil() { + return ModBlocks.blockCasings3Misc; + } + + @Override + public int getFusionCoilMeta() { + return 13; + } + + @Override + public int tierOverclock() { + return 8; + } + + @Override public int overclock(int mStartEnergy) { return (mStartEnergy < 160000000) ? 16 : ((mStartEnergy < 320000000) ? 8 : (mStartEnergy < 640000000) ? 4 : 1); } - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[]{ - new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, - Dyes.getModulation(-1, Dyes._NULL.mRGBa)), - TextureFactory.builder().addIcon(this.getIconOverlay()).extFacing().build()}; - } else if (!aActive) { - return new ITexture[]{ - new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, - Dyes.getModulation(-1, Dyes._NULL.mRGBa))}; - } else { - return new ITexture[]{ - new GT_RenderedTexture(TexturesGtBlock.TEXTURE_CASING_FUSION_CASING_ULTRA, - Dyes.getModulation(-1, Dyes._NULL.mRGBa))}; - } - } + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, Dyes.getModulation(-1, Dyes._NULL.mRGBa)), + TextureFactory.builder() + .addIcon(this.getIconOverlay()) + .extFacing() + .build() + }; + } else if (!aActive) { + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, Dyes.getModulation(-1, Dyes._NULL.mRGBa)) + }; + } else { + return new ITexture[] { + new GT_RenderedTexture( + TexturesGtBlock.TEXTURE_CASING_FUSION_CASING_ULTRA, Dyes.getModulation(-1, Dyes._NULL.mRGBa)) + }; + } + } @Override public ITexture getTextureOverlay() { - return new GT_RenderedTexture(this.mMaxProgresstime > 0 ? TexturesGtBlock.Casing_Machine_Screen_3 : TexturesGtBlock.Casing_Machine_Screen_1); - } - - public IIconContainer getIconOverlay() { - return this.mMaxProgresstime > 0 ? TexturesGtBlock.Casing_Machine_Screen_3 : TexturesGtBlock.Casing_Machine_Screen_1; - } - - public boolean turnCasingActive(final boolean status) { - try { - if (this.mEnergyHatches != null) { - for (final GT_MetaTileEntity_Hatch_Energy hatch : this.mEnergyHatches) { - mUpdateHatchTexture.invoke(hatch, (status ? TAE.getIndexFromPage(2, 14) : 53)); - } - } - if (this.mOutputHatches != null) { - for (final GT_MetaTileEntity_Hatch_Output hatch2 : this.mOutputHatches) { - mUpdateHatchTexture.invoke(hatch2, (status ? TAE.getIndexFromPage(2, 14) : 53)); - } - } - if (this.mInputHatches != null) { - for (final GT_MetaTileEntity_Hatch_Input hatch3 : this.mInputHatches) { - mUpdateHatchTexture.invoke(hatch3, (status ? TAE.getIndexFromPage(2, 14) : 53)); - } - } - } - catch (Throwable t) { - return false; - } - return true; - } - + return new GT_RenderedTexture( + this.mMaxProgresstime > 0 + ? TexturesGtBlock.Casing_Machine_Screen_3 + : TexturesGtBlock.Casing_Machine_Screen_1); + } + + public IIconContainer getIconOverlay() { + return this.mMaxProgresstime > 0 + ? TexturesGtBlock.Casing_Machine_Screen_3 + : TexturesGtBlock.Casing_Machine_Screen_1; + } + + public boolean turnCasingActive(final boolean status) { + try { + if (this.mEnergyHatches != null) { + for (final GT_MetaTileEntity_Hatch_Energy hatch : this.mEnergyHatches) { + mUpdateHatchTexture.invoke(hatch, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch2 : this.mOutputHatches) { + mUpdateHatchTexture.invoke(hatch2, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch3 : this.mInputHatches) { + mUpdateHatchTexture.invoke(hatch3, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + } catch (Throwable t) { + return false; + } + return true; + } + @Override public String[] getInfoData() { String tier = "IV"; @@ -162,15 +177,15 @@ public class GregtechMetaTileEntity_Adv_Fusion_MK4 extends GT_MetaTileEntity_Fus if (this.mLastRecipe != null) { powerRequired = this.mLastRecipe.mEUt; if (this.mLastRecipe.getFluidOutput(0) != null) { - plasmaOut = (float)this.mLastRecipe.getFluidOutput(0).amount / (float)this.mLastRecipe.mDuration; + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; } } - return new String[]{ - "Fusion Reactor MK "+tier, - "EU Required: "+powerRequired+"EU/t", - "Stored EU: "+mEUStore+" / "+maxEUStore(), - "Plasma Output: "+plasmaOut+"L/t"}; + return new String[] { + "Fusion Reactor MK " + tier, + "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + mEUStore + " / " + maxEUStore(), + "Plasma Output: " + plasmaOut + "L/t" + }; } - } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_HeatExchanger.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_HeatExchanger.java index d568c298ee..002cffb816 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_HeatExchanger.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_HeatExchanger.java @@ -6,7 +6,6 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; - import gregtech.api.GregTech_API; import gregtech.api.enums.TAE; import gregtech.api.gui.GT_GUIContainer_MultiMachine; @@ -31,55 +30,84 @@ import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -public class GregtechMetaTileEntity_Adv_HeatExchanger extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_HeatExchanger> { - - private static final int CASING_INDEX = TAE.getIndexFromPage(1, 12); +public class GregtechMetaTileEntity_Adv_HeatExchanger + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_HeatExchanger> { + + private static final int CASING_INDEX = TAE.getIndexFromPage(1, 12); private static final String STRUCTURE_PIECE_MAIN = "main"; - - private static final IStructureDefinition<GregtechMetaTileEntity_Adv_HeatExchanger> STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_HeatExchanger>builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - {" ccc ", "cCCCc", "cCCCc", "cCCCc", " ccc "}, - {" ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, - {" ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, - {" ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, - {" ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, - {" c~c ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, - {" hhh ", "hHHHh", "hHHHh", "hHHHh", " hhh "}, - {" f f ", "f f", " ", "f f", " f f "}, - {" f f ", "f f", " ", "f f", " f f "}, - })) - .addElement('P', ofBlock(GregTech_API.sBlockCasings2, 15)) - .addElement('f', ofBlock(getFrame(), 0)) - .addElement('C', ofChain( - ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addColdFluidOutputToMachineList, CASING_INDEX, 2), - onElementPass(GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, ofBlock(ModBlocks.blockSpecialMultiCasings, 14)) - )) - .addElement('H', ofChain( - ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addHotFluidInputToMachineList, CASING_INDEX, 3), - onElementPass(GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, ofBlock(ModBlocks.blockSpecialMultiCasings, 14)) - )) - .addElement('h', ofChain( - ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addInputToMachineList, CASING_INDEX, 1), - ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addOutputToMachineList, CASING_INDEX, 1), - ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addMaintenanceToMachineList, CASING_INDEX, 1), - onElementPass(GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, ofBlock(ModBlocks.blockSpecialMultiCasings, 14)) - )) - .addElement('c', ofChain( - onElementPass(GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, ofBlock(ModBlocks.blockSpecialMultiCasings, 14)) - )) - .build(); - public static float penalty_per_config = 0.015f; // penalize 1.5% efficiency per circuitry level (1-25) + + private static final IStructureDefinition<GregtechMetaTileEntity_Adv_HeatExchanger> STRUCTURE_DEFINITION = + StructureDefinition.<GregtechMetaTileEntity_Adv_HeatExchanger>builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][] { + {" ccc ", "cCCCc", "cCCCc", "cCCCc", " ccc "}, + {" ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, + {" ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, + {" ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, + {" ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, + {" c~c ", "cPPPc", "cPPPc", "cPPPc", " ccc "}, + {" hhh ", "hHHHh", "hHHHh", "hHHHh", " hhh "}, + {" f f ", "f f", " ", "f f", " f f "}, + {" f f ", "f f", " ", "f f", " f f "}, + })) + .addElement('P', ofBlock(GregTech_API.sBlockCasings2, 15)) + .addElement('f', ofBlock(getFrame(), 0)) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_Adv_HeatExchanger::addColdFluidOutputToMachineList, + CASING_INDEX, + 2), + onElementPass( + GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, + ofBlock(ModBlocks.blockSpecialMultiCasings, 14)))) + .addElement( + 'H', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_Adv_HeatExchanger::addHotFluidInputToMachineList, + CASING_INDEX, + 3), + onElementPass( + GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, + ofBlock(ModBlocks.blockSpecialMultiCasings, 14)))) + .addElement( + 'h', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_Adv_HeatExchanger::addInputToMachineList, + CASING_INDEX, + 1), + ofHatchAdder( + GregtechMetaTileEntity_Adv_HeatExchanger::addOutputToMachineList, + CASING_INDEX, + 1), + ofHatchAdder( + GregtechMetaTileEntity_Adv_HeatExchanger::addMaintenanceToMachineList, + CASING_INDEX, + 1), + onElementPass( + GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, + ofBlock(ModBlocks.blockSpecialMultiCasings, 14)))) + .addElement( + 'c', + ofChain(onElementPass( + GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, + ofBlock(ModBlocks.blockSpecialMultiCasings, 14)))) + .build(); + public static float penalty_per_config = 0.015f; // penalize 1.5% efficiency per circuitry level (1-25) private GT_MetaTileEntity_Hatch_Input mInputHotFluidHatch; private GT_MetaTileEntity_Hatch_Output mOutputColdFluidHatch; private boolean superheated = false; - private int superheated_threshold=0; + private int superheated_threshold = 0; private float water; private int mCasingAmount; public GregtechMetaTileEntity_Adv_HeatExchanger(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } + public GregtechMetaTileEntity_Adv_HeatExchanger(String aName) { super(aName); } @@ -143,7 +171,8 @@ public class GregtechMetaTileEntity_Adv_HeatExchanger extends GregtechMeta_Multi @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeHeatExchanger.png"); + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeHeatExchanger.png"); } @Override @@ -158,18 +187,17 @@ public class GregtechMetaTileEntity_Adv_HeatExchanger extends GregtechMeta_Multi @Override public boolean checkRecipe(ItemStack aStack) { - if (mInputHotFluidHatch.getFluid() == null) - return true; + if (mInputHotFluidHatch.getFluid() == null) return true; int fluidAmountToConsume = mInputHotFluidHatch.getFluidAmount(); // how much fluid is in hatch // The XL LHE works as fast as 32 regular LHEs. These are the comments from the original LHE, // with changes where the values needed to change for the 32x speed multiplier - superheated_threshold = 128000; // default: must have 4000L -> 128000L per second to generate superheated steam - float efficiency = 1f; // default: operate at 100% efficiency with no integrated circuitry + superheated_threshold = 128000; // default: must have 4000L -> 128000L per second to generate superheated steam + float efficiency = 1f; // default: operate at 100% efficiency with no integrated circuitry int shs_reduction_per_config = 4800; // reduce threshold 150L -> 4800L per second per circuitry level (1-25) float steam_output_multiplier = 20f; // default: multiply output by 4 * 10 (boosted x5) - float penalty = 0.0f; // penalty to apply to output based on circuitry level (1-25). + float penalty = 0.0f; // penalty to apply to output based on circuitry level (1-25). boolean do_lava = false; // Do we have an integrated circuit with a valid configuration? @@ -190,15 +218,19 @@ public class GregtechMetaTileEntity_Adv_HeatExchanger extends GregtechMeta_Multi do_lava = true; } else if (mInputHotFluidHatch.getFluid().isFluidEqual(FluidRegistry.getFluidStack("ic2hotcoolant", 1))) { steam_output_multiplier /= 2f; // was boosted x2 on top of x5 -> total x10 -> nerf with this code back to 5x - superheated_threshold /=5f; // 10x smaller since the Hot Things production in reactor is the same. + superheated_threshold /= 5f; // 10x smaller since the Hot Things production in reactor is the same. } else { // If we're working with neither, fail out - superheated_threshold=0; + superheated_threshold = 0; return false; } - superheated = fluidAmountToConsume >= superheated_threshold; // set the internal superheated flag if we have enough hot fluid. Used in the onRunningTick method. - fluidAmountToConsume = Math.min(fluidAmountToConsume, superheated_threshold * 2); // Don't consume too much hot fluid per second, maximum is 2x SH threshold. + superheated = fluidAmountToConsume + >= superheated_threshold; // set the internal superheated flag if we have enough hot fluid. Used in the + // onRunningTick method. + fluidAmountToConsume = Math.min( + fluidAmountToConsume, + superheated_threshold * 2); // Don't consume too much hot fluid per second, maximum is 2x SH threshold. mInputHotFluidHatch.drain(fluidAmountToConsume, true); this.mMaxProgresstime = 20; this.mEUt = (int) (fluidAmountToConsume * steam_output_multiplier * efficiency); @@ -221,24 +253,27 @@ public class GregtechMetaTileEntity_Adv_HeatExchanger extends GregtechMeta_Multi @Override public boolean onRunningTick(ItemStack aStack) { if (this.mEUt > 0) { - int tGeneratedEU = (int) (this.mEUt * 2L * this.mEfficiency / 10000L); // APPROXIMATELY how much steam to generate. + int tGeneratedEU = + (int) (this.mEUt * 2L * this.mEfficiency / 10000L); // APPROXIMATELY how much steam to generate. if (tGeneratedEU > 0) { if (superheated) tGeneratedEU /= 2; // We produce half as much superheated steam if necessary int distilledConsumed = useWater(tGeneratedEU / 160f); // how much distilled water to consume - //tGeneratedEU = distilledConsumed * 160; // EXACTLY how much steam to generate, producing a perfect 1:160 ratio with distilled water consumption + // tGeneratedEU = distilledConsumed * 160; // EXACTLY how much steam to generate, producing a perfect + // 1:160 ratio with distilled water consumption FluidStack distilledStack = GT_ModHandler.getDistilledWater(distilledConsumed); if (depleteInput(distilledStack)) // Consume the distilled water { if (superheated) { - addOutput(FluidRegistry.getFluidStack("ic2superheatedsteam", tGeneratedEU)); // Generate superheated steam + addOutput(FluidRegistry.getFluidStack( + "ic2superheatedsteam", tGeneratedEU)); // Generate superheated steam } else { addOutput(GT_ModHandler.getSteam(tGeneratedEU)); // Generate regular steam } } else { - GT_Log.exp.println(this.mName+" had no more Distilled water!"); + GT_Log.exp.println(this.mName + " had no more Distilled water!"); explodeMultiblock(); // Generate crater } } @@ -298,6 +333,7 @@ public class GregtechMetaTileEntity_Adv_HeatExchanger extends GregtechMeta_Multi public int getDamageToComponent(ItemStack aStack) { return 0; } + @Override public boolean explodesOnComponentBreak(ItemStack aStack) { return false; @@ -315,20 +351,26 @@ public class GregtechMetaTileEntity_Adv_HeatExchanger extends GregtechMeta_Multi @Override public String[] getExtraInfoData() { - return new String[]{ - StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + - EnumChatFormatting.GREEN + GT_Utility.formatNumbers(mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + - EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(mMaxProgresstime / 20) + EnumChatFormatting.RESET + " s", - StatCollector.translateToLocal("GT5U.multiblock.usage") + " " + StatCollector.translateToLocal("GT5U.LHE.steam") + ": " + - (superheated ? EnumChatFormatting.RED : EnumChatFormatting.YELLOW) + GT_Utility.formatNumbers(superheated ? -2 * mEUt : -mEUt) + EnumChatFormatting.RESET + " EU/t", - StatCollector.translateToLocal("GT5U.multiblock.problems") + ": " + - EnumChatFormatting.RED + (getIdealStatus() - getRepairStatus()) + EnumChatFormatting.RESET + " " + - StatCollector.translateToLocal("GT5U.multiblock.efficiency") + ": " + - EnumChatFormatting.YELLOW + mEfficiency / 100.0F + EnumChatFormatting.RESET + " %", - StatCollector.translateToLocal("GT5U.LHE.superheated") + ": " + - (superheated ? EnumChatFormatting.RED : EnumChatFormatting.BLUE) + superheated + EnumChatFormatting.RESET, - StatCollector.translateToLocal("GT5U.LHE.superheated") + " " + StatCollector.translateToLocal("GT5U.LHE.threshold") + ": " + - EnumChatFormatting.GREEN + GT_Utility.formatNumbers(superheated_threshold) + EnumChatFormatting.RESET + return new String[] { + StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(mMaxProgresstime / 20) + EnumChatFormatting.RESET + " s", + StatCollector.translateToLocal("GT5U.multiblock.usage") + " " + + StatCollector.translateToLocal("GT5U.LHE.steam") + ": " + + (superheated ? EnumChatFormatting.RED : EnumChatFormatting.YELLOW) + + GT_Utility.formatNumbers(superheated ? -2 * mEUt : -mEUt) + EnumChatFormatting.RESET + " EU/t", + StatCollector.translateToLocal("GT5U.multiblock.problems") + ": " + EnumChatFormatting.RED + + (getIdealStatus() - getRepairStatus()) + EnumChatFormatting.RESET + " " + + StatCollector.translateToLocal("GT5U.multiblock.efficiency") + + ": " + EnumChatFormatting.YELLOW + + mEfficiency / 100.0F + EnumChatFormatting.RESET + " %", + StatCollector.translateToLocal("GT5U.LHE.superheated") + ": " + + (superheated ? EnumChatFormatting.RED : EnumChatFormatting.BLUE) + superheated + + EnumChatFormatting.RESET, + StatCollector.translateToLocal("GT5U.LHE.superheated") + " " + + StatCollector.translateToLocal("GT5U.LHE.threshold") + ": " + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(superheated_threshold) + EnumChatFormatting.RESET }; } @@ -336,33 +378,38 @@ public class GregtechMetaTileEntity_Adv_HeatExchanger extends GregtechMeta_Multi public void construct(ItemStack stackSize, boolean hintsOnly) { buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 2, 5, 0); } - @Override - public boolean hasSlotInGUI() { - return true; - } - @Override - public String getCustomGUIResourceName() { - return null; - } - @Override - public String getMachineType() { - return "Heat Exchanger"; - } - @Override - public int getMaxParallelRecipes() { - return 0; - } - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - private static Block sFrame; - - public static Block getFrame() { - if (sFrame == null) { - sFrame = BlockBaseModular.getMaterialBlock(ALLOY.TALONITE, BlockTypes.FRAME); - } - return sFrame; - } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Heat Exchanger"; + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + private static Block sFrame; + + public static Block getFrame() { + if (sFrame == null) { + sFrame = BlockBaseModular.getMaterialBlock(ALLOY.TALONITE, BlockTypes.FRAME); + } + return sFrame; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java index de85c3acdc..6ec4e8ddbe 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java @@ -6,7 +6,6 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; - import gregtech.api.GregTech_API; import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -18,186 +17,177 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.Gregtech import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import net.minecraft.item.ItemStack; -public class GregtechMetaTileEntity_Adv_Implosion extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_Implosion> { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_Adv_Implosion> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_Adv_Implosion(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_Adv_Implosion(String aName) { - super(aName); - } - - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_Adv_Implosion(this.mName); - } - - @Override - public String getMachineType() { - return "Implosion Compressor"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Factory Grade Advanced Implosion Compressor") - .addInfo("Speed: +100% | EU Usage: 100% | Parallel: ((Tier/2)+1)") - .addInfo("Constructed exactly the same as a normal Implosion Compressor") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front center") - .addCasingInfo("Robust TungstenSteel Casing", 10) - .addInputBus("Any casing", 1) - .addOutputBus("Any casing", 1) - .addEnergyHatch("Any casing", 1) - .addMaintenanceHatch("Any casing", 1) - .addMufflerHatch("Any casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_Adv_Implosion> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_Implosion>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - ofChain( - ofHatchAdder( - GregtechMetaTileEntity_Adv_Implosion::addAdvImplosionList, 48, 1 - ), - onElementPass( - x -> ++x.mCasing, - ofBlock( - sBlockCasings4, 0 - ) - ) - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - public final boolean addAdvImplosionList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return 48; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "ImplosionCompressor"; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sImplosionRecipes; - } - - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric((GT_Utility.getTier(this.getMaxInputVoltage())/2+1), 100, 100); - } - - public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { - super.startSoundLoop(aIndex, aX, aY, aZ); - if (aIndex == 20) { - GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(5)), 10, 1.0F, aX, aY, aZ); - } - } - - @Override - public String getSound() { - return (String) GregTech_API.sSoundList.get(Integer.valueOf(5)); - } - - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiAdvImplosion; - } - - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (GT_Utility.getTier(this.getMaxInputVoltage())/2+1); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - -}
\ No newline at end of file +public class GregtechMetaTileEntity_Adv_Implosion + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_Implosion> { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_Adv_Implosion> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Adv_Implosion(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Adv_Implosion(String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_Implosion(this.mName); + } + + @Override + public String getMachineType() { + return "Implosion Compressor"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Implosion Compressor") + .addInfo("Speed: +100% | EU Usage: 100% | Parallel: ((Tier/2)+1)") + .addInfo("Constructed exactly the same as a normal Implosion Compressor") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Robust TungstenSteel Casing", 10) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_Implosion> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_Implosion>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder(GregtechMetaTileEntity_Adv_Implosion::addAdvImplosionList, 48, 1), + onElementPass(x -> ++x.mCasing, ofBlock(sBlockCasings4, 0)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addAdvImplosionList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return 48; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ImplosionCompressor"; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sImplosionRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((GT_Utility.getTier(this.getMaxInputVoltage()) / 2 + 1), 100, 100); + } + + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 20) { + GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(5)), 10, 1.0F, aX, aY, aZ); + } + } + + @Override + public String getSound() { + return (String) GregTech_API.sSoundList.get(Integer.valueOf(5)); + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvImplosion; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (GT_Utility.getTier(this.getMaxInputVoltage()) / 2 + 1); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java index 3d23523b0a..4b24df6ee7 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java @@ -9,7 +9,6 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -25,139 +24,127 @@ import net.minecraft.item.ItemStack; public class GregtechMetaTileEntity_SteamCompressor extends GregtechMeta_SteamMultiBase { - private String mCasingName = "Bronze Plated Bricks"; - private IStructureDefinition<GregtechMetaTileEntity_SteamCompressor> STRUCTURE_DEFINITION = null; - private int mCasing; - - public GregtechMetaTileEntity_SteamCompressor(String aName) { - super(aName); - } - - public GregtechMetaTileEntity_SteamCompressor(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { - return new GregtechMetaTileEntity_SteamCompressor(this.mName); - } - - @Override - protected GT_RenderedTexture getFrontOverlay() { - return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_STEAM_COMPRESSOR); - } - - @Override - protected GT_RenderedTexture getFrontOverlayActive() { - return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_STEAM_COMPRESSOR_ACTIVE); - } - - @Override - public String getMachineType() { - return "Compressor"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Steam Compressor") - .addInfo("Compresses " + getMaxParallelRecipes() + " things at a time") - .addSeparator() - .beginStructureBlock(3, 3, 4, true) - .addController("Front center") - .addCasingInfo(mCasingName, 28) - .addOtherStructurePart(TT_steaminputbus, "Any casing", 1) - .addOtherStructurePart(TT_steamoutputbus, "Any casing", 1) - .addOtherStructurePart(TT_steamhatch, "Any casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_SteamCompressor> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SteamCompressor>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC", "CCC"}, - {"C~C", "C-C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - ofChain( - ofHatchAdder( - GregtechMetaTileEntity_SteamCompressor::addSteamMultiList, 10, 1 - ), - onElementPass( - x -> ++x.mCasing, - ofBlock( - sBlockCasings1, 10 - ) - ) - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - public final boolean addSteamMultiList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 31040){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusOutput){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - fixAllMaintenanceIssue(); - return checkPiece(mName, 1, 1, 0) && mCasing >= 28; - } - - @Override - public int getMaxParallelRecipes() { - return 8; - } - - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sCompressorRecipes; - } - - @Override - public ItemStack[] getOutputItems(GT_Recipe aRecipe) { - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[1]; - for (int h = 0; h < 1; h++) { - if (aRecipe.getOutput(h) != null) { - tOutputItems[h] = aRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - return tOutputItems; - } - - @Override - public int getOutputCount(ItemStack[] aOutputs) { - return 1; - } - - - + private String mCasingName = "Bronze Plated Bricks"; + private IStructureDefinition<GregtechMetaTileEntity_SteamCompressor> STRUCTURE_DEFINITION = null; + private int mCasing; + + public GregtechMetaTileEntity_SteamCompressor(String aName) { + super(aName); + } + + public GregtechMetaTileEntity_SteamCompressor(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { + return new GregtechMetaTileEntity_SteamCompressor(this.mName); + } + + @Override + protected GT_RenderedTexture getFrontOverlay() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_STEAM_COMPRESSOR); + } + + @Override + protected GT_RenderedTexture getFrontOverlayActive() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_STEAM_COMPRESSOR_ACTIVE); + } + + @Override + public String getMachineType() { + return "Compressor"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Steam Compressor") + .addInfo("Compresses " + getMaxParallelRecipes() + " things at a time") + .addSeparator() + .beginStructureBlock(3, 3, 4, true) + .addController("Front center") + .addCasingInfo(mCasingName, 28) + .addOtherStructurePart(TT_steaminputbus, "Any casing", 1) + .addOtherStructurePart(TT_steamoutputbus, "Any casing", 1) + .addOtherStructurePart(TT_steamhatch, "Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SteamCompressor> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SteamCompressor>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC", "CCC"}, + {"C~C", "C-C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder(GregtechMetaTileEntity_SteamCompressor::addSteamMultiList, 10, 1), + onElementPass(x -> ++x.mCasing, ofBlock(sBlockCasings1, 10)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addSteamMultiList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase + && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 31040) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusOutput) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + fixAllMaintenanceIssue(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 28; + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sCompressorRecipes; + } + + @Override + public ItemStack[] getOutputItems(GT_Recipe aRecipe) { + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[1]; + for (int h = 0; h < 1; h++) { + if (aRecipe.getOutput(h) != null) { + tOutputItems[h] = aRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + return tOutputItems; + } + + @Override + public int getOutputCount(ItemStack[] aOutputs) { + return 1; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java index 85a58c5ded..5d57d68f41 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java @@ -24,142 +24,130 @@ import net.minecraft.item.ItemStack; public class GregtechMetaTileEntity_SteamMacerator extends GregtechMeta_SteamMultiBase { - private String mCasingName = "Bronze Plated Bricks"; - private IStructureDefinition<GregtechMetaTileEntity_SteamMacerator> STRUCTURE_DEFINITION = null; - private int mCasing; - - public GregtechMetaTileEntity_SteamMacerator(String aName) { - super(aName); - } - - public GregtechMetaTileEntity_SteamMacerator(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { - return new GregtechMetaTileEntity_SteamMacerator(this.mName); - } - - @Override - protected GT_RenderedTexture getFrontOverlay() { - return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR); - } - - @Override - protected GT_RenderedTexture getFrontOverlayActive() { - return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR_ACTIVE); - } - - @Override - public String getMachineType() { - return "Macerator"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - if (mCasingName.contains("gt.blockcasings")) { - mCasingName = ItemList.Casing_BronzePlatedBricks.get(1).getDisplayName(); - } - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Steam Macerator") - .addInfo("Macerates " + getMaxParallelRecipes() + " ores at a time") - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front center") - .addCasingInfo(mCasingName, 14) - .addOtherStructurePart(TT_steaminputbus, "Any casing", 1) - .addOtherStructurePart(TT_steamoutputbus, "Any casing", 1) - .addOtherStructurePart(TT_steamhatch, "Any casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_SteamMacerator> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SteamMacerator>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - ofChain( - ofHatchAdder( - GregtechMetaTileEntity_SteamMacerator::addSteamMaceratorList, 10, 1 - ), - onElementPass( - x -> ++x.mCasing, - ofBlock( - sBlockCasings1, 10 - ) - ) - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - public final boolean addSteamMaceratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 31040){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusOutput){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - fixAllMaintenanceIssue(); - return checkPiece(mName, 1, 1, 0) && mCasing >= 14; - } - - @Override - public int getMaxParallelRecipes() { - return 8; - } - - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; - } - - @Override - public ItemStack[] getOutputItems(GT_Recipe aRecipe) { - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[1]; - for (int h = 0; h < 1; h++) { - if (aRecipe.getOutput(h) != null) { - tOutputItems[h] = aRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - return tOutputItems; - } - - @Override - public int getOutputCount(ItemStack[] aOutputs) { - return 1; - } - - - + private String mCasingName = "Bronze Plated Bricks"; + private IStructureDefinition<GregtechMetaTileEntity_SteamMacerator> STRUCTURE_DEFINITION = null; + private int mCasing; + + public GregtechMetaTileEntity_SteamMacerator(String aName) { + super(aName); + } + + public GregtechMetaTileEntity_SteamMacerator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { + return new GregtechMetaTileEntity_SteamMacerator(this.mName); + } + + @Override + protected GT_RenderedTexture getFrontOverlay() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR); + } + + @Override + protected GT_RenderedTexture getFrontOverlayActive() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR_ACTIVE); + } + + @Override + public String getMachineType() { + return "Macerator"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.contains("gt.blockcasings")) { + mCasingName = ItemList.Casing_BronzePlatedBricks.get(1).getDisplayName(); + } + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Steam Macerator") + .addInfo("Macerates " + getMaxParallelRecipes() + " ores at a time") + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo(mCasingName, 14) + .addOtherStructurePart(TT_steaminputbus, "Any casing", 1) + .addOtherStructurePart(TT_steamoutputbus, "Any casing", 1) + .addOtherStructurePart(TT_steamhatch, "Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SteamMacerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SteamMacerator>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder(GregtechMetaTileEntity_SteamMacerator::addSteamMaceratorList, 10, 1), + onElementPass(x -> ++x.mCasing, ofBlock(sBlockCasings1, 10)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addSteamMaceratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase + && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 31040) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusOutput) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + fixAllMaintenanceIssue(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 14; + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; + } + + @Override + public ItemStack[] getOutputItems(GT_Recipe aRecipe) { + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[1]; + for (int h = 0; h < 1; h++) { + if (aRecipe.getOutput(h) != null) { + tOutputItems[h] = aRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + return tOutputItems; + } + + @Override + public int getOutputCount(ItemStack[] aOutputs) { + return 1; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java index 19acd30668..b68880a63a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java @@ -1,7 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.lang.reflect.Field; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -26,6 +29,8 @@ import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.helpers.CraftingHelper; import gtPlusPlus.xmod.gregtech.common.helpers.autocrafter.AC_Helper_Utils; +import java.lang.reflect.Field; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -33,610 +38,612 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GT4Entity_AutoCrafter extends GregtechMeta_MultiBlockBase<GT4Entity_AutoCrafter> implements ISurvivalConstructable { - - private MODE mMachineMode = MODE.ASSEMBLY; - private byte mTier = 1; - protected GT_Recipe mLastRecipeToBuffer; - private int mCasing; - private IStructureDefinition<GT4Entity_AutoCrafter> STRUCTURE_DEFINITION = null; - - /** The crafting matrix inventory (3x3). */ - public CraftingHelper mInventoryCrafter; - - public static enum MODE { - CRAFTING("CIRCUIT", "ASSEMBLY"), ASSEMBLY("CRAFTING", "DISASSEMBLY"), DISASSEMBLY("ASSEMBLY", "CIRCUIT"), CIRCUIT("DISASSEMBLY", "CRAFTING"); - - private final String lastMode; - private final String nextMode; - - MODE(String previous, String next) { - this.lastMode = previous; - this.nextMode = next; - } - - public MODE nextMode() { - return MODE.valueOf(this.nextMode); - } - - public MODE lastMode() { - return MODE.valueOf(this.lastMode); - } - - } - - public void onRightclick(EntityPlayer aPlayer) { - } - - public GT4Entity_AutoCrafter(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GT4Entity_AutoCrafter(String mName) { - super(mName); - } - - @Override - public String getMachineType() { - String sType = "Assembler, Disassembler, "+((CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && !CORE.GTNH) ? "Circuit Assembler" : ""); - return sType; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT4Entity_AutoCrafter(this.mName); - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - @Override - public boolean onRunningTick(ItemStack aStack) { - return super.onRunningTick(aStack); - //return true; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiAutoCrafter; - } - - public int getAmountOfOutputs() { - return 1; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Highly Advanced Autocrafter") - .addInfo("Right Click with a Screwdriver to change mode") - .addInfo("200% faster than using single block machines of the same voltage") - .addInfo("Processes two items per voltage tier") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front Center") - .addCasingInfo("Autocrafter Frame", 10) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER; - } - - @Override - protected int getCasingTextureId() { - return TAE.getIndexFromPage(0, 10); - } - - @Override - public IStructureDefinition<GT4Entity_AutoCrafter> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GT4Entity_AutoCrafter>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GT4Entity_AutoCrafter.class) - .atLeast(InputBus, OutputBus, InputHatch, Maintenance, Energy, Muffler) - .casingIndex(TAE.getIndexFromPage(0, 10)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 12))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - if (checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch()) { - setTier(); - return true; - } else return false; - } - - private static GT_Recipe_Map fCircuitMap; - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - if (this.mMachineMode == MODE.ASSEMBLY) { - return GT_Recipe.GT_Recipe_Map.sAssemblerRecipes; - } - else if (this.mMachineMode == MODE.CIRCUIT && !CORE.GTNH) { - if (fCircuitMap != null) { - return fCircuitMap; - } - GT_Recipe_Map r; - try { - Field f = ReflectionUtils.getField(GT_Recipe.GT_Recipe_Map.class, "sCircuitAssemblerRecipes"); - if (f != null) { - r = (GT_Recipe_Map) f.get(null); - if (r != null) { - fCircuitMap = r; - return r; - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - } - } - else if (this.mMachineMode == MODE.DISASSEMBLY || this.mMachineMode == MODE.CRAFTING) { - return null; - } - return GT_Recipe.GT_Recipe_Map.sAssemblerRecipes; - } - - private boolean isModernGT = true; - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (isModernGT && !CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - isModernGT = false; - } - //5.09 support - if (isModernGT && !CORE.GTNH) { - mMachineMode = mMachineMode.nextMode(); - if (mMachineMode == MODE.CRAFTING) { - PlayerUtils.messagePlayer(aPlayer, "Running the Auto-Crafter in mode: "+EnumChatFormatting.AQUA+"AutoCrafting"); - } else if (mMachineMode == MODE.ASSEMBLY) { - PlayerUtils.messagePlayer(aPlayer, "Running the Auto-Crafter in mode: "+EnumChatFormatting.GREEN+"Assembly"); - } else if (mMachineMode == MODE.DISASSEMBLY) { - PlayerUtils.messagePlayer(aPlayer, "Running the Auto-Crafter in mode: "+EnumChatFormatting.RED+"Disassembly"); - } else { - PlayerUtils.messagePlayer(aPlayer, "Running the Auto-Crafter in mode: "+EnumChatFormatting.YELLOW+"Circuit Assembly"); - } - } - //5.08 support - else { - if (mMachineMode.nextMode() == MODE.CIRCUIT) { - mMachineMode = MODE.ASSEMBLY; - } - else if (mMachineMode.nextMode() == MODE.CRAFTING) { - mMachineMode = MODE.ASSEMBLY; - } - else { - mMachineMode = mMachineMode.nextMode(); - } - - if (mMachineMode == MODE.CRAFTING) { - PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: "+EnumChatFormatting.AQUA+"AutoCrafting"); - } else if (mMachineMode == MODE.ASSEMBLY) { - PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: "+EnumChatFormatting.GREEN+"Assembly"); - } else { - PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: "+EnumChatFormatting.RED+"Disassembly"); - } - } - } - -// @Override -// public boolean checkRecipe(final ItemStack aStack) { -// -// final long tVoltage = this.getMaxInputVoltage(); -// final byte tTier = this.mTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); -// -// if (mMachineMode == MODE.DISASSEMBLY) { -// return doDisassembly(); -// } else if (mMachineMode == MODE.CRAFTING) { -// return doCrafting(aStack); -// } else { -// return super.checkRecipeGeneric(getMaxParallelRecipes(), 100, 200); -// } -// } - - private void setTier() { - long tVoltage = getMaxInputVoltage(); - this.mTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - if (mMachineMode == MODE.DISASSEMBLY) { - return doDisassembly(); - } else if (mMachineMode == MODE.CRAFTING) { - return doCrafting(aStack); - } else { - ArrayList<FluidStack> tFluids = getStoredFluids(); - //Logger.MACHINE_INFO("1"); - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); - //Logger.MACHINE_INFO("2"); - if (isValidMetaTileEntity(tBus)) { - //Logger.MACHINE_INFO("3"); - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) - tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - - Object[] tempArray = tFluids.toArray(new FluidStack[] {}); - FluidStack[] properArray; - properArray = ((tempArray != null && tempArray.length > 0) ? (FluidStack[]) tempArray : new FluidStack[] {}); - - //Logger.MACHINE_INFO("4"); - if (checkRecipeGeneric(tBusItems.toArray(new ItemStack[]{}), properArray, - getMaxParallelRecipes(), 100, 200, 10000)) return true; - } - return false; - } - } - - @Override - public int getMaxParallelRecipes() { - return 2 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - public boolean doDisassembly() { - - final ArrayList<ItemStack> tInputList = this.getStoredInputs(); - for (int tInputList_sS = tInputList.size(), i = 0; i < tInputList_sS - 1; ++i) { - for (int j = i + 1; j < tInputList_sS; ++j) { - if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { - if (tInputList.get(i).stackSize < tInputList.get(j).stackSize) { - tInputList.remove(i--); - tInputList_sS = tInputList.size(); - break; - } - tInputList.remove(j--); - tInputList_sS = tInputList.size(); - } - } - } - final ItemStack[] tInputs = tInputList.toArray(new ItemStack[tInputList.size()]); - - ItemStack inputItem = tInputs[0]; - if (tInputs[0].stackSize <= 0) { - tInputs[0] = null; - this.updateSlots(); - } - int outputSlots = this.mOutputBusses.get(0).getSizeInventory(); - - if (this.mOutputBusses.size() > 1) { - outputSlots = 0; - for (GT_MetaTileEntity_Hatch_OutputBus r : this.mOutputBusses) { - outputSlots += r.getSizeInventory(); - } - } - - this.mOutputItems = new ItemStack[outputSlots]; - if (inputItem != null && inputItem.stackSize > 0) { - NBTTagCompound tNBT = inputItem.getTagCompound(); - if (tNBT != null) { - tNBT = tNBT.getCompoundTag("GT.CraftingComponents"); - if (tNBT != null) { - this.mEUt = 16 * (1 << this.mTier - 1) * (1 << this.mTier - 1); - this.mMaxProgresstime = (100 - (8 * this.mTier)); - for (int i = 0; i < this.mOutputItems.length; ++i) { - if (this.getBaseMetaTileEntity().getRandomNumber(100) < 60 + 12 * this.mTier) { - this.mOutputItems[i] = GT_Utility.loadItem(tNBT, "Ingredient." + i); - if (this.mOutputItems[i] != null) { - this.mMaxProgresstime *= (int) 1.5; - } - } - } - - if (this.mTier > 5) { - this.mMaxProgresstime >>= this.mTier - 5; - } - if (this.mEUt > 0) - this.mEUt = (-this.mEUt); - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - inputItem.stackSize--; - if (inputItem.stackSize <= 0) { - tInputs[0] = null; - } - this.updateSlots(); - return true; - - } - } - } - return false; - } - - private boolean doesCrafterHave9SlotInput() { - GT_MetaTileEntity_Hatch_InputBus craftingInput = null; - if (!this.mInputBusses.isEmpty()) { - for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses) { - if (x.mInventory.length == 9) { - craftingInput = x; - } - } - } - // Return if no input hatch set. - if (craftingInput == null) { - Logger.WARNING("Cannot do Auto-Crafting without a 9-slot Input Bus [MV]."); - return false; - - } else { - return true; - } - } - - private boolean doCrafting(ItemStack aStack) { - this.mMaxProgresstime = 0; - return false; // do nothing - /* - try { - // Set Crafting input hatch - if (!doesCrafterHave9SlotInput()) { - return false; - } - - // Read stored data from encrypted data stick. - ItemStack storedData_Output[] = NBTUtils.readItemsFromNBT(aStack, "Output"); - ItemStack storedData_Input[] = NBTUtils.readItemsFromNBT(aStack); - if (storedData_Output != null && storedData_Input != null) { - ItemStack loadedData[] = new ItemStack[9]; - if (storedData_Input.length >= 1) { - int number = 0; - for (ItemStack a : storedData_Input) { - if (a.getItem() == ModItems.ZZZ_Empty) { - // Utils.LOG_WARNING("Allocating free memory into crafting manager slot - // "+number+"."); - loadedData[number] = null; - } else { - // Utils.LOG_WARNING("Downloading "+a.getDisplayName()+" into crafting manager - // slot "+number+"."); - loadedData[number] = a; - } - number++; - } - } - - // Remove inputs here - ArrayList<ItemStack> mInputArray = new ArrayList<ItemStack>(); - ItemStack allInputs[]; - - for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses) { - if (x.mInventory.length > 0) { - for (ItemStack r : x.mInventory) { - if (r != null) { - mInputArray.add(r); - } - } - } - } - - if (mInputArray.isEmpty()) { - return false; - } else { - List<ItemStack> list = mInputArray; - allInputs = list.toArray(new ItemStack[list.size()]); - - if (allInputs != null && allInputs.length > 0) { - - this.mEUt = 8 * (1 << this.mTier - 1) * (1 << this.mTier - 1); - this.mMaxProgresstime = MathUtils.roundToClosestInt((50 - (5 - * MathUtils.randDouble(((this.mTier - 2) <= 0 ? 1 : (this.mTier - 2)), this.mTier)))); - - Logger.WARNING("MPT: " + mMaxProgresstime + " | " + mEUt); - this.getBaseMetaTileEntity().setActive(true); - - // Setup some vars - int counter = 0; - - ItemStack toUse[] = new ItemStack[9]; - - outerloop: for (ItemStack inputItem : loadedData) { - if (inputItem == null) { - toUse[counter] = null; - continue outerloop; - } - for (ItemStack r : allInputs) { - if (r != null) { - // Utils.LOG_WARNING("Input Bus Inventory Iteration - Found:" - // +r.getDisplayName()+" | "+allInputs.length); - if (GT_Utility.areStacksEqual(r, inputItem)) { - if (this.getBaseMetaTileEntity().isServerSide()) { - toUse[counter] = inputItem; - counter++; - continue outerloop; - } - - } - } - } - counter++; - } - - int mCorrectInputs = 0; - for (ItemStack isValid : toUse) { - if (isValid == null || this.depleteInput(isValid)) { - mCorrectInputs++; - } else { - Logger.WARNING("Input in Slot " + mCorrectInputs + " was not valid."); - } - } - - if (this.mTier > 5) { - this.mMaxProgresstime >>= this.mTier - 5; - } - if (this.mEUt > 0) - this.mEUt = (-this.mEUt); - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - if (mCorrectInputs == 9) { - ItemStack mOutputItem = storedData_Output[0]; - NBTUtils.writeItemsToGtCraftingComponents(mOutputItem, loadedData, true); - this.addOutput(mOutputItem); - this.updateSlots(); - return true; - } else { - return false; - } - - } - } - } - } - // End Debug - catch (Throwable t) { - t.printStackTrace(); - this.mMaxProgresstime = 0; - } - - this.mMaxProgresstime = 0; - return false; - */ - } - - @Override - public String[] getExtraInfoData() { - final String tRunning = (this.mMaxProgresstime > 0 ? "Auto-Crafter running" : "Auto-Crafter stopped"); - final String tMaintainance = (this.getIdealStatus() == this.getRepairStatus() ? "No Maintainance issues" - : "Needs Maintainance"); - String tSpecialText = "" + (60 + 12 * this.mTier) + "% chance to recover disassembled parts."; - String tMode; - if (mMachineMode == MODE.DISASSEMBLY) { - tMode = "§cDisassembly"; - tSpecialText = "" + (60 + 12 * this.mTier) + "% chance to recover disassembled parts."; - } else if (mMachineMode == MODE.ASSEMBLY || mMachineMode == MODE.CIRCUIT) { - tMode = mMachineMode == MODE.ASSEMBLY ? "§aAssembly" : "§eCircuit Assembly"; - if (mLastRecipeToBuffer != null && mLastRecipeToBuffer.mOutputs[0].getDisplayName() != null) { - tSpecialText = "Currently processing: " + mLastRecipeToBuffer.mOutputs[0].getDisplayName(); - } else { - tSpecialText = "Currently processing: Nothing"; - } - } else { - tMode = "§dAuto-Crafting"; - tSpecialText = "Does Auto-Crafter have 9-slot input bus? " + doesCrafterHave9SlotInput(); - } - - return new String[] { "Large Scale Auto-Asesembler v1.01c", tRunning, tMaintainance, "Mode: " + tMode, - tSpecialText }; - } - - private String getMode() { - return this.mMachineMode.name(); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - String mMode = getMode(); - aNBT.setString("mMode", mMode); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - String modeString = aNBT.getString("mMode"); - MODE newMode = MODE.valueOf(modeString); - this.mMachineMode = newMode; - super.loadNBTData(aNBT); - } - - @Override - public void explodeMultiblock() { - AC_Helper_Utils.removeCrafter(this); - super.explodeMultiblock(); - } - - @Override - public void onExplosion() { - AC_Helper_Utils.removeCrafter(this); - super.onExplosion(); - } - - @Override - public void onRemoval() { - AC_Helper_Utils.removeCrafter(this); - super.onRemoval(); - } - - @Override - public void doExplosion(long aExplosionPower) { - AC_Helper_Utils.removeCrafter(this); - super.doExplosion(aExplosionPower); - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "Generic3By3"; - } - +public class GT4Entity_AutoCrafter extends GregtechMeta_MultiBlockBase<GT4Entity_AutoCrafter> + implements ISurvivalConstructable { + + private MODE mMachineMode = MODE.ASSEMBLY; + private byte mTier = 1; + protected GT_Recipe mLastRecipeToBuffer; + private int mCasing; + private IStructureDefinition<GT4Entity_AutoCrafter> STRUCTURE_DEFINITION = null; + + /** The crafting matrix inventory (3x3). */ + public CraftingHelper mInventoryCrafter; + + public static enum MODE { + CRAFTING("CIRCUIT", "ASSEMBLY"), + ASSEMBLY("CRAFTING", "DISASSEMBLY"), + DISASSEMBLY("ASSEMBLY", "CIRCUIT"), + CIRCUIT("DISASSEMBLY", "CRAFTING"); + + private final String lastMode; + private final String nextMode; + + MODE(String previous, String next) { + this.lastMode = previous; + this.nextMode = next; + } + + public MODE nextMode() { + return MODE.valueOf(this.nextMode); + } + + public MODE lastMode() { + return MODE.valueOf(this.lastMode); + } + } + + public void onRightclick(EntityPlayer aPlayer) {} + + public GT4Entity_AutoCrafter(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT4Entity_AutoCrafter(String mName) { + super(mName); + } + + @Override + public String getMachineType() { + String sType = "Assembler, Disassembler, " + + ((CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && !CORE.GTNH) ? "Circuit Assembler" : ""); + return sType; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_AutoCrafter(this.mName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + return super.onRunningTick(aStack); + // return true; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAutoCrafter; + } + + public int getAmountOfOutputs() { + return 1; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Highly Advanced Autocrafter") + .addInfo("Right Click with a Screwdriver to change mode") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Processes two items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Autocrafter Frame", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(0, 10); + } + + @Override + public IStructureDefinition<GT4Entity_AutoCrafter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GT4Entity_AutoCrafter>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GT4Entity_AutoCrafter.class) + .atLeast(InputBus, OutputBus, InputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 12)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + if (checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch()) { + setTier(); + return true; + } else return false; + } + + private static GT_Recipe_Map fCircuitMap; + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (this.mMachineMode == MODE.ASSEMBLY) { + return GT_Recipe.GT_Recipe_Map.sAssemblerRecipes; + } else if (this.mMachineMode == MODE.CIRCUIT && !CORE.GTNH) { + if (fCircuitMap != null) { + return fCircuitMap; + } + GT_Recipe_Map r; + try { + Field f = ReflectionUtils.getField(GT_Recipe.GT_Recipe_Map.class, "sCircuitAssemblerRecipes"); + if (f != null) { + r = (GT_Recipe_Map) f.get(null); + if (r != null) { + fCircuitMap = r; + return r; + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + } + } else if (this.mMachineMode == MODE.DISASSEMBLY || this.mMachineMode == MODE.CRAFTING) { + return null; + } + return GT_Recipe.GT_Recipe_Map.sAssemblerRecipes; + } + + private boolean isModernGT = true; + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (isModernGT && !CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + isModernGT = false; + } + // 5.09 support + if (isModernGT && !CORE.GTNH) { + mMachineMode = mMachineMode.nextMode(); + if (mMachineMode == MODE.CRAFTING) { + PlayerUtils.messagePlayer( + aPlayer, "Running the Auto-Crafter in mode: " + EnumChatFormatting.AQUA + "AutoCrafting"); + } else if (mMachineMode == MODE.ASSEMBLY) { + PlayerUtils.messagePlayer( + aPlayer, "Running the Auto-Crafter in mode: " + EnumChatFormatting.GREEN + "Assembly"); + } else if (mMachineMode == MODE.DISASSEMBLY) { + PlayerUtils.messagePlayer( + aPlayer, "Running the Auto-Crafter in mode: " + EnumChatFormatting.RED + "Disassembly"); + } else { + PlayerUtils.messagePlayer( + aPlayer, "Running the Auto-Crafter in mode: " + EnumChatFormatting.YELLOW + "Circuit Assembly"); + } + } + // 5.08 support + else { + if (mMachineMode.nextMode() == MODE.CIRCUIT) { + mMachineMode = MODE.ASSEMBLY; + } else if (mMachineMode.nextMode() == MODE.CRAFTING) { + mMachineMode = MODE.ASSEMBLY; + } else { + mMachineMode = mMachineMode.nextMode(); + } + + if (mMachineMode == MODE.CRAFTING) { + PlayerUtils.messagePlayer( + aPlayer, + "You are now running the Auto-Crafter in mode: " + EnumChatFormatting.AQUA + "AutoCrafting"); + } else if (mMachineMode == MODE.ASSEMBLY) { + PlayerUtils.messagePlayer( + aPlayer, + "You are now running the Auto-Crafter in mode: " + EnumChatFormatting.GREEN + "Assembly"); + } else { + PlayerUtils.messagePlayer( + aPlayer, + "You are now running the Auto-Crafter in mode: " + EnumChatFormatting.RED + "Disassembly"); + } + } + } + + // @Override + // public boolean checkRecipe(final ItemStack aStack) { + // + // final long tVoltage = this.getMaxInputVoltage(); + // final byte tTier = this.mTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + // + // if (mMachineMode == MODE.DISASSEMBLY) { + // return doDisassembly(); + // } else if (mMachineMode == MODE.CRAFTING) { + // return doCrafting(aStack); + // } else { + // return super.checkRecipeGeneric(getMaxParallelRecipes(), 100, 200); + // } + // } + + private void setTier() { + long tVoltage = getMaxInputVoltage(); + this.mTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + if (mMachineMode == MODE.DISASSEMBLY) { + return doDisassembly(); + } else if (mMachineMode == MODE.CRAFTING) { + return doCrafting(aStack); + } else { + ArrayList<FluidStack> tFluids = getStoredFluids(); + // Logger.MACHINE_INFO("1"); + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + // Logger.MACHINE_INFO("2"); + if (isValidMetaTileEntity(tBus)) { + // Logger.MACHINE_INFO("3"); + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + + Object[] tempArray = tFluids.toArray(new FluidStack[] {}); + FluidStack[] properArray; + properArray = + ((tempArray != null && tempArray.length > 0) ? (FluidStack[]) tempArray : new FluidStack[] {}); + + // Logger.MACHINE_INFO("4"); + if (checkRecipeGeneric( + tBusItems.toArray(new ItemStack[] {}), properArray, getMaxParallelRecipes(), 100, 200, 10000)) + return true; + } + return false; + } + } + + @Override + public int getMaxParallelRecipes() { + return 2 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + public boolean doDisassembly() { + + final ArrayList<ItemStack> tInputList = this.getStoredInputs(); + for (int tInputList_sS = tInputList.size(), i = 0; i < tInputList_sS - 1; ++i) { + for (int j = i + 1; j < tInputList_sS; ++j) { + if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { + if (tInputList.get(i).stackSize < tInputList.get(j).stackSize) { + tInputList.remove(i--); + tInputList_sS = tInputList.size(); + break; + } + tInputList.remove(j--); + tInputList_sS = tInputList.size(); + } + } + } + final ItemStack[] tInputs = tInputList.toArray(new ItemStack[tInputList.size()]); + + ItemStack inputItem = tInputs[0]; + if (tInputs[0].stackSize <= 0) { + tInputs[0] = null; + this.updateSlots(); + } + int outputSlots = this.mOutputBusses.get(0).getSizeInventory(); + + if (this.mOutputBusses.size() > 1) { + outputSlots = 0; + for (GT_MetaTileEntity_Hatch_OutputBus r : this.mOutputBusses) { + outputSlots += r.getSizeInventory(); + } + } + + this.mOutputItems = new ItemStack[outputSlots]; + if (inputItem != null && inputItem.stackSize > 0) { + NBTTagCompound tNBT = inputItem.getTagCompound(); + if (tNBT != null) { + tNBT = tNBT.getCompoundTag("GT.CraftingComponents"); + if (tNBT != null) { + this.mEUt = 16 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + this.mMaxProgresstime = (100 - (8 * this.mTier)); + for (int i = 0; i < this.mOutputItems.length; ++i) { + if (this.getBaseMetaTileEntity().getRandomNumber(100) < 60 + 12 * this.mTier) { + this.mOutputItems[i] = GT_Utility.loadItem(tNBT, "Ingredient." + i); + if (this.mOutputItems[i] != null) { + this.mMaxProgresstime *= (int) 1.5; + } + } + } + + if (this.mTier > 5) { + this.mMaxProgresstime >>= this.mTier - 5; + } + if (this.mEUt > 0) this.mEUt = (-this.mEUt); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + inputItem.stackSize--; + if (inputItem.stackSize <= 0) { + tInputs[0] = null; + } + this.updateSlots(); + return true; + } + } + } + return false; + } + + private boolean doesCrafterHave9SlotInput() { + GT_MetaTileEntity_Hatch_InputBus craftingInput = null; + if (!this.mInputBusses.isEmpty()) { + for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses) { + if (x.mInventory.length == 9) { + craftingInput = x; + } + } + } + // Return if no input hatch set. + if (craftingInput == null) { + Logger.WARNING("Cannot do Auto-Crafting without a 9-slot Input Bus [MV]."); + return false; + + } else { + return true; + } + } + + private boolean doCrafting(ItemStack aStack) { + this.mMaxProgresstime = 0; + return false; // do nothing + /* + try { + // Set Crafting input hatch + if (!doesCrafterHave9SlotInput()) { + return false; + } + + // Read stored data from encrypted data stick. + ItemStack storedData_Output[] = NBTUtils.readItemsFromNBT(aStack, "Output"); + ItemStack storedData_Input[] = NBTUtils.readItemsFromNBT(aStack); + if (storedData_Output != null && storedData_Input != null) { + ItemStack loadedData[] = new ItemStack[9]; + if (storedData_Input.length >= 1) { + int number = 0; + for (ItemStack a : storedData_Input) { + if (a.getItem() == ModItems.ZZZ_Empty) { + // Utils.LOG_WARNING("Allocating free memory into crafting manager slot + // "+number+"."); + loadedData[number] = null; + } else { + // Utils.LOG_WARNING("Downloading "+a.getDisplayName()+" into crafting manager + // slot "+number+"."); + loadedData[number] = a; + } + number++; + } + } + + // Remove inputs here + ArrayList<ItemStack> mInputArray = new ArrayList<ItemStack>(); + ItemStack allInputs[]; + + for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses) { + if (x.mInventory.length > 0) { + for (ItemStack r : x.mInventory) { + if (r != null) { + mInputArray.add(r); + } + } + } + } + + if (mInputArray.isEmpty()) { + return false; + } else { + List<ItemStack> list = mInputArray; + allInputs = list.toArray(new ItemStack[list.size()]); + + if (allInputs != null && allInputs.length > 0) { + + this.mEUt = 8 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + this.mMaxProgresstime = MathUtils.roundToClosestInt((50 - (5 + * MathUtils.randDouble(((this.mTier - 2) <= 0 ? 1 : (this.mTier - 2)), this.mTier)))); + + Logger.WARNING("MPT: " + mMaxProgresstime + " | " + mEUt); + this.getBaseMetaTileEntity().setActive(true); + + // Setup some vars + int counter = 0; + + ItemStack toUse[] = new ItemStack[9]; + + outerloop: for (ItemStack inputItem : loadedData) { + if (inputItem == null) { + toUse[counter] = null; + continue outerloop; + } + for (ItemStack r : allInputs) { + if (r != null) { + // Utils.LOG_WARNING("Input Bus Inventory Iteration - Found:" + // +r.getDisplayName()+" | "+allInputs.length); + if (GT_Utility.areStacksEqual(r, inputItem)) { + if (this.getBaseMetaTileEntity().isServerSide()) { + toUse[counter] = inputItem; + counter++; + continue outerloop; + } + + } + } + } + counter++; + } + + int mCorrectInputs = 0; + for (ItemStack isValid : toUse) { + if (isValid == null || this.depleteInput(isValid)) { + mCorrectInputs++; + } else { + Logger.WARNING("Input in Slot " + mCorrectInputs + " was not valid."); + } + } + + if (this.mTier > 5) { + this.mMaxProgresstime >>= this.mTier - 5; + } + if (this.mEUt > 0) + this.mEUt = (-this.mEUt); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + if (mCorrectInputs == 9) { + ItemStack mOutputItem = storedData_Output[0]; + NBTUtils.writeItemsToGtCraftingComponents(mOutputItem, loadedData, true); + this.addOutput(mOutputItem); + this.updateSlots(); + return true; + } else { + return false; + } + + } + } + } + } + // End Debug + catch (Throwable t) { + t.printStackTrace(); + this.mMaxProgresstime = 0; + } + + this.mMaxProgresstime = 0; + return false; + */ + } + + @Override + public String[] getExtraInfoData() { + final String tRunning = (this.mMaxProgresstime > 0 ? "Auto-Crafter running" : "Auto-Crafter stopped"); + final String tMaintainance = + (this.getIdealStatus() == this.getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance"); + String tSpecialText = "" + (60 + 12 * this.mTier) + "% chance to recover disassembled parts."; + String tMode; + if (mMachineMode == MODE.DISASSEMBLY) { + tMode = "§cDisassembly"; + tSpecialText = "" + (60 + 12 * this.mTier) + "% chance to recover disassembled parts."; + } else if (mMachineMode == MODE.ASSEMBLY || mMachineMode == MODE.CIRCUIT) { + tMode = mMachineMode == MODE.ASSEMBLY ? "§aAssembly" : "§eCircuit Assembly"; + if (mLastRecipeToBuffer != null && mLastRecipeToBuffer.mOutputs[0].getDisplayName() != null) { + tSpecialText = "Currently processing: " + mLastRecipeToBuffer.mOutputs[0].getDisplayName(); + } else { + tSpecialText = "Currently processing: Nothing"; + } + } else { + tMode = "§dAuto-Crafting"; + tSpecialText = "Does Auto-Crafter have 9-slot input bus? " + doesCrafterHave9SlotInput(); + } + + return new String[] { + "Large Scale Auto-Asesembler v1.01c", tRunning, tMaintainance, "Mode: " + tMode, tSpecialText + }; + } + + private String getMode() { + return this.mMachineMode.name(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + String mMode = getMode(); + aNBT.setString("mMode", mMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + String modeString = aNBT.getString("mMode"); + MODE newMode = MODE.valueOf(modeString); + this.mMachineMode = newMode; + super.loadNBTData(aNBT); + } + + @Override + public void explodeMultiblock() { + AC_Helper_Utils.removeCrafter(this); + super.explodeMultiblock(); + } + + @Override + public void onExplosion() { + AC_Helper_Utils.removeCrafter(this); + super.onExplosion(); + } + + @Override + public void onRemoval() { + AC_Helper_Utils.removeCrafter(this); + super.onRemoval(); + } + + @Override + public void doExplosion(long aExplosionPower) { + AC_Helper_Utils.removeCrafter(this); + super.doExplosion(aExplosionPower); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "Generic3By3"; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java index 8f16ea8f83..10f0fc5a5b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java @@ -1,5 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -27,340 +33,341 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GT4Entity_ThermalBoiler extends GregtechMeta_MultiBlockBase<GT4Entity_ThermalBoiler> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GT4Entity_ThermalBoiler> STRUCTURE_DEFINITION = null; - private int mSuperEfficencyIncrease = 0; - - public void onRightclick(EntityPlayer aPlayer) - { - getBaseMetaTileEntity().openGUI(aPlayer, 158); - } - - public GT4Entity_ThermalBoiler(int aID, String aName, String aNameRegional) - { - super(aID, aName, aNameRegional); - } - - public GT4Entity_ThermalBoiler(String mName) { - super(mName); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) - { - return new GT4Entity_ThermalBoiler(this.mName); - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) - { - return true; - } - - @Override - public String getMachineType() { - return "Boiler"; - } - - @Override - public int getDamageToComponent(ItemStack aStack){ - //log("Trying to damage component."); - return ItemList.Component_LavaFilter.get(1L).getClass().isInstance(aStack) ? 1 : 0; - } - - private static Item mLavaFilter; - private static Fluid mLava = null; - private static Fluid mPahoehoe = null; - private static Fluid mSolarSaltHot = null; - - @Override - public boolean checkRecipe(ItemStack aStack) { - this.mSuperEfficencyIncrease=0; - - if (mLavaFilter == null) { - mLavaFilter = ItemList.Component_LavaFilter.getItem(); - } - if (mLava == null) { - mLava = FluidRegistry.LAVA; - } - if (mPahoehoe == null) { - mPahoehoe = FluidUtils.getPahoehoeLava(1).getFluid(); - } - if (mSolarSaltHot == null) { - mSolarSaltHot = MISC_MATERIALS.SOLAR_SALT_HOT.getFluid(); - } - - - - //Try reload new Lava Filter - if (aStack == null) { - ItemStack uStack = this.findItemInInventory(mLavaFilter); - if (uStack != null) { - this.setGUIItemStack(uStack); - aStack = this.getGUIItemStack(); - } - } - - - for (GT_Recipe tRecipe : GTPP_Recipe.GTPP_Recipe_Map.sThermalFuels.mRecipeList) { - FluidStack tFluid = tRecipe.mFluidInputs[0]; - if (tFluid != null) { - - if (tFluid.getFluid() == mLava || tFluid.getFluid() == mPahoehoe) { - if (depleteInput(tFluid)) { - this.mMaxProgresstime = Math.max(1, runtimeBoost(tRecipe.mSpecialValue * 2)); - this.mEfficiencyIncrease = (this.mMaxProgresstime * getEfficiencyIncrease()); - - int loot_MAXCHANCE = 100000; - if (mLavaFilter.getClass().isInstance(aStack.getItem())) { - if ((tRecipe.getOutput(0) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(0))) { - this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(0) }) }; - } - if ((tRecipe.getOutput(1) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(1))) { - this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(1) }) }; - } - if ((tRecipe.getOutput(2) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(2))) { - this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(2) }) }; - } - if ((tRecipe.getOutput(3) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(3))) { - this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(3) }) }; - } - if ((tRecipe.getOutput(4) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(4))) { - this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(4) }) }; - } - if ((tRecipe.getOutput(5) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(5))) { - this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(5) }) }; - } - } - //Give Obsidian without Lava Filter - if (tFluid.getFluid() == mLava){ - if ((tRecipe.getOutput(6) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(6))) { - this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(6) }) }; - } - } - return true; - } - } - else if (tFluid.getFluid() == mSolarSaltHot) { - if (depleteInput(tFluid)) { - this.mMaxProgresstime = tRecipe.mDuration; - this.mEfficiency = 10000; - for (FluidStack aOutput : tRecipe.mFluidOutputs) { - this.addOutput(FluidUtils.getFluidStack(aOutput, aOutput.amount)); - } - return true; - } - } - } - } - this.mMaxProgresstime = 0; - this.mEUt = 0; - return false; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public boolean onRunningTick(ItemStack aStack) { - if (this.mEUt > 0) { - if(this.mSuperEfficencyIncrease>0){ - this.mEfficiency = Math.min(10000, this.mEfficiency + this.mSuperEfficencyIncrease); - } - int tGeneratedEU = (int) (this.mEUt * 2L * this.mEfficiency / 10000L); - if (tGeneratedEU > 0) { - long amount = (tGeneratedEU + 160) / 160; - if (depleteInput(Materials.Water.getFluid(amount)) || depleteInput(GT_ModHandler.getDistilledWater(amount))) { - addOutput(GT_ModHandler.getSteam(tGeneratedEU)); - } else { - explodeMultiblock(); - } - } - return true; - } - return true; - } - - public int getEUt() { - return 400; - } - - public int getEfficiencyIncrease() { - return 12; - } - - int runtimeBoost(int mTime) { - return mTime * 150 / 100; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) - { - return false; - } - - @Override - public int getMaxEfficiency(ItemStack aStack) - { - return 10000; - } - - @Override - public int getPollutionPerSecond(ItemStack aStack) - { - return CORE.ConfigSwitches.pollutionPerSecondMultiThermalBoiler; - } - - public int getAmountOfOutputs() - { - return 7; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Thermal Boiler Controller") - .addInfo("Converts Water & Heat into Steam") - .addInfo("Consult user manual for more information") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front Center") - .addCasingInfo("Thermal Containment Casings", 10) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(1); - } - - @Override - public IStructureDefinition<GT4Entity_ThermalBoiler> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GT4Entity_ThermalBoiler>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GT4Entity_ThermalBoiler.class) - .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) - .casingIndex(TAE.getIndexFromPage(0, 1)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 11))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); - } - - public void damageFilter(){ - ItemStack filter = this.mInventory[1]; - if (filter != null){ - if (filter.getItem() instanceof ItemLavaFilter){ - - long currentUse = ItemLavaFilter.getFilterDamage(filter); - - //Remove broken Filter - if (currentUse >= 100-1){ - this.mInventory[1] = null; - } - else { - //Do Damage - ItemLavaFilter.setFilterDamage(filter, currentUse+1); - } - } - } - - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()){ - // Reload Lava Filter - if (this.getGUIItemStack() == null) { - if (this.mInputBusses.size() > 0) { - for (GT_MetaTileEntity_Hatch_InputBus aBus : this.mInputBusses) { - for (ItemStack aStack : aBus.mInventory) { - if (aStack != null && aStack.getItem() instanceof ItemLavaFilter) { - this.setGUIItemStack(aStack); - } - } - } - } - } - - if (this.mEUt > 0){ - if (aTick % 600L == 0L){ - damageFilter(); - } - } - } - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "Generic3By3"; - } - +public class GT4Entity_ThermalBoiler extends GregtechMeta_MultiBlockBase<GT4Entity_ThermalBoiler> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GT4Entity_ThermalBoiler> STRUCTURE_DEFINITION = null; + private int mSuperEfficencyIncrease = 0; + + public void onRightclick(EntityPlayer aPlayer) { + getBaseMetaTileEntity().openGUI(aPlayer, 158); + } + + public GT4Entity_ThermalBoiler(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT4Entity_ThermalBoiler(String mName) { + super(mName); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_ThermalBoiler(this.mName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public String getMachineType() { + return "Boiler"; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + // log("Trying to damage component."); + return ItemList.Component_LavaFilter.get(1L).getClass().isInstance(aStack) ? 1 : 0; + } + + private static Item mLavaFilter; + private static Fluid mLava = null; + private static Fluid mPahoehoe = null; + private static Fluid mSolarSaltHot = null; + + @Override + public boolean checkRecipe(ItemStack aStack) { + this.mSuperEfficencyIncrease = 0; + + if (mLavaFilter == null) { + mLavaFilter = ItemList.Component_LavaFilter.getItem(); + } + if (mLava == null) { + mLava = FluidRegistry.LAVA; + } + if (mPahoehoe == null) { + mPahoehoe = FluidUtils.getPahoehoeLava(1).getFluid(); + } + if (mSolarSaltHot == null) { + mSolarSaltHot = MISC_MATERIALS.SOLAR_SALT_HOT.getFluid(); + } + + // Try reload new Lava Filter + if (aStack == null) { + ItemStack uStack = this.findItemInInventory(mLavaFilter); + if (uStack != null) { + this.setGUIItemStack(uStack); + aStack = this.getGUIItemStack(); + } + } + + for (GT_Recipe tRecipe : GTPP_Recipe.GTPP_Recipe_Map.sThermalFuels.mRecipeList) { + FluidStack tFluid = tRecipe.mFluidInputs[0]; + if (tFluid != null) { + + if (tFluid.getFluid() == mLava || tFluid.getFluid() == mPahoehoe) { + if (depleteInput(tFluid)) { + this.mMaxProgresstime = Math.max(1, runtimeBoost(tRecipe.mSpecialValue * 2)); + this.mEfficiencyIncrease = (this.mMaxProgresstime * getEfficiencyIncrease()); + + int loot_MAXCHANCE = 100000; + if (mLavaFilter.getClass().isInstance(aStack.getItem())) { + if ((tRecipe.getOutput(0) != null) + && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) + < tRecipe.getOutputChance(0))) { + this.mOutputItems = + new ItemStack[] {GT_Utility.copy(new Object[] {tRecipe.getOutput(0)})}; + } + if ((tRecipe.getOutput(1) != null) + && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) + < tRecipe.getOutputChance(1))) { + this.mOutputItems = + new ItemStack[] {GT_Utility.copy(new Object[] {tRecipe.getOutput(1)})}; + } + if ((tRecipe.getOutput(2) != null) + && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) + < tRecipe.getOutputChance(2))) { + this.mOutputItems = + new ItemStack[] {GT_Utility.copy(new Object[] {tRecipe.getOutput(2)})}; + } + if ((tRecipe.getOutput(3) != null) + && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) + < tRecipe.getOutputChance(3))) { + this.mOutputItems = + new ItemStack[] {GT_Utility.copy(new Object[] {tRecipe.getOutput(3)})}; + } + if ((tRecipe.getOutput(4) != null) + && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) + < tRecipe.getOutputChance(4))) { + this.mOutputItems = + new ItemStack[] {GT_Utility.copy(new Object[] {tRecipe.getOutput(4)})}; + } + if ((tRecipe.getOutput(5) != null) + && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) + < tRecipe.getOutputChance(5))) { + this.mOutputItems = + new ItemStack[] {GT_Utility.copy(new Object[] {tRecipe.getOutput(5)})}; + } + } + // Give Obsidian without Lava Filter + if (tFluid.getFluid() == mLava) { + if ((tRecipe.getOutput(6) != null) + && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) + < tRecipe.getOutputChance(6))) { + this.mOutputItems = + new ItemStack[] {GT_Utility.copy(new Object[] {tRecipe.getOutput(6)})}; + } + } + return true; + } + } else if (tFluid.getFluid() == mSolarSaltHot) { + if (depleteInput(tFluid)) { + this.mMaxProgresstime = tRecipe.mDuration; + this.mEfficiency = 10000; + for (FluidStack aOutput : tRecipe.mFluidOutputs) { + this.addOutput(FluidUtils.getFluidStack(aOutput, aOutput.amount)); + } + return true; + } + } + } + } + this.mMaxProgresstime = 0; + this.mEUt = 0; + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.mEUt > 0) { + if (this.mSuperEfficencyIncrease > 0) { + this.mEfficiency = Math.min(10000, this.mEfficiency + this.mSuperEfficencyIncrease); + } + int tGeneratedEU = (int) (this.mEUt * 2L * this.mEfficiency / 10000L); + if (tGeneratedEU > 0) { + long amount = (tGeneratedEU + 160) / 160; + if (depleteInput(Materials.Water.getFluid(amount)) + || depleteInput(GT_ModHandler.getDistilledWater(amount))) { + addOutput(GT_ModHandler.getSteam(tGeneratedEU)); + } else { + explodeMultiblock(); + } + } + return true; + } + return true; + } + + public int getEUt() { + return 400; + } + + public int getEfficiencyIncrease() { + return 12; + } + + int runtimeBoost(int mTime) { + return mTime * 150 / 100; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiThermalBoiler; + } + + public int getAmountOfOutputs() { + return 7; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Thermal Boiler Controller") + .addInfo("Converts Water & Heat into Steam") + .addInfo("Consult user manual for more information") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Thermal Containment Casings", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(1); + } + + @Override + public IStructureDefinition<GT4Entity_ThermalBoiler> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GT4Entity_ThermalBoiler>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GT4Entity_ThermalBoiler.class) + .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.getIndexFromPage(0, 1)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 11)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + public void damageFilter() { + ItemStack filter = this.mInventory[1]; + if (filter != null) { + if (filter.getItem() instanceof ItemLavaFilter) { + + long currentUse = ItemLavaFilter.getFilterDamage(filter); + + // Remove broken Filter + if (currentUse >= 100 - 1) { + this.mInventory[1] = null; + } else { + // Do Damage + ItemLavaFilter.setFilterDamage(filter, currentUse + 1); + } + } + } + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + // Reload Lava Filter + if (this.getGUIItemStack() == null) { + if (this.mInputBusses.size() > 0) { + for (GT_MetaTileEntity_Hatch_InputBus aBus : this.mInputBusses) { + for (ItemStack aStack : aBus.mInventory) { + if (aStack != null && aStack.getItem() instanceof ItemLavaFilter) { + this.setGUIItemStack(aStack); + } + } + } + } + } + + if (this.mEUt > 0) { + if (aTick % 600L == 0L) { + damageFilter(); + } + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "Generic3By3"; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java index e7dbd49621..2a7fa00352 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java @@ -1,9 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; @@ -28,648 +31,739 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ElementalDataOrbHolder; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - public class GregtechMTE_ElementalDuplicator extends GregtechMeta_MultiBlockBase<GregtechMTE_ElementalDuplicator> { - private final ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder> mReplicatorDataOrbHatches = new ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder>(); - private static final int CASING_TEXTURE_ID = TAE.getIndexFromPage(0, 3); - private int mCasing = 0; - - public GregtechMTE_ElementalDuplicator(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMTE_ElementalDuplicator(final String aName) { - super(aName); - } - - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMTE_ElementalDuplicator(this.mName); - } - - @Override - public String getMachineType() { - return "Replicator"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Produces Elemental Material from UU Matter") - .addInfo("Speed: +100% | EU Usage: 100% | Parallel: 8 * Tier") - .addInfo("Maximum 1x of each bus/hatch.") - .addInfo("Does not require both Output Hatch & Bus") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(9, 6, 9, true) - .addController("Top Center") - .addCasingInfo("Elemental Confinement Shell", 138) - .addCasingInfo("Matter Fabricator Casing", 24) - .addCasingInfo("Particle Containment Casing", 24) - .addCasingInfo("Matter Generation Coil", 24) - .addCasingInfo("High Voltage Current Capacitor", 20) - .addCasingInfo("Resonance Chamber III", 24) - .addCasingInfo("Modulator III", 16) - .addOtherStructurePart("Data Orb Repository", "1x", 1) - .addInputHatch("Any 1 dot hint", 1) - .addOutputBus("Any 1 dot hint", 1) - .addOutputHatch("Any 1 dot hint", 1) - .addEnergyHatch("Any 1 dot hint", 1) - .addMaintenanceHatch("Any 1 dot hint", 1) - .addMufflerHatch("Any 1 dot hint", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - - private static final String STRUCTURE_PIECE_MAIN = "main"; - private IStructureDefinition<GregtechMTE_ElementalDuplicator> STRUCTURE_DEFINITION = null; - - @Override - public IStructureDefinition<GregtechMTE_ElementalDuplicator> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_ElementalDuplicator>builder() - - // h = Hatch - // c = Casing - - // a = MF Casing 1 - // b = Matter Gen Coil - - // d = Current Capacitor - // e = Particle - - // f = Resonance III - // g = Modulator III - - .addShape(STRUCTURE_PIECE_MAIN, (new String[][]{ - {" ccc ", " ccccc ", " ccccccc ", "ccchhhccc", "ccch~hccc", "ccchhhccc", " ccccccc ", " ccccc ", " ccc "}, - {" cac ", " abfba ", " abfgfba ", "cbfgdgfbc", "afgdddgfa", "cbfgdgfbc", " abfgfba ", " abfba ", " cac "}, - {" cec ", " e e ", " e e ", "c d c", "e ddd e", "c d c", " e e ", " e e ", " cec "}, - {" cec ", " e e ", " e e ", "c d c", "e ddd e", "c d c", " e e ", " e e ", " cec "}, - {" cac ", " abfba ", " abfgfba ", "cbfgdgfbc", "afgdddgfa", "cbfgdgfbc", " abfgfba ", " abfba ", " cac "}, - {" ccc ", " ccccc ", " ccccccc ", "ccchhhccc", "ccchhhccc", "ccchhhccc", " ccccccc ", " ccccc ", " ccc "}, - })) - - - .addElement('a', ofBlock(getCasingBlock4(), getCasingMeta6())) - .addElement('b', ofBlock(getCasingBlock4(), getCasingMeta7())) - - .addElement('d', ofBlock(getCasingBlock2(), getCasingMeta2())) - .addElement('e', ofBlock(getCasingBlock2(), getCasingMeta3())) - - .addElement('f', ofBlock(getCasingBlock3(), getCasingMeta4())) - .addElement('g', ofBlock(getCasingBlock3(), getCasingMeta5())) - .addElement('c', lazy(t -> onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) - .addElement('h', lazy(t -> ofChain( - buildHatchAdder(GregtechMTE_ElementalDuplicator.class) - .atLeast(InputHatch, OutputBus, OutputHatch, Maintenance, Muffler, Energy) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .build() - , - buildHatchAdder(GregtechMTE_ElementalDuplicator.class) - .hatchClass(GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.class) - .adder(GregtechMTE_ElementalDuplicator::addDataOrbHatch) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .build() - , - onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())) - ))) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(STRUCTURE_PIECE_MAIN , stackSize, hintsOnly, 4, 4, 0); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - boolean aDidBuild = checkPiece(STRUCTURE_PIECE_MAIN, 4, 4, 0); - if (this.mInputHatches.size() != 1 || (this.mOutputBusses.size() != 1 && this.mOutputHatches.size() !=0) || this.mEnergyHatches.size() != 1 || this.mReplicatorDataOrbHatches.size() != 1) { - return false; - } - log("Casings: "+mCasing); - return aDidBuild && mCasing >= 138 && checkHatch(); - } - - protected static int getCasingTextureIndex() { - return CASING_TEXTURE_ID; - } - - protected static Block getCasingBlock() { - return ModBlocks.blockCasings5Misc; - } - - protected static Block getCasingBlock2() { - return ModBlocks.blockSpecialMultiCasings; - } - - protected static Block getCasingBlock3() { - return ModBlocks.blockSpecialMultiCasings2; - } - - protected static Block getCasingBlock4() { - return ModBlocks.blockCasingsMisc; - } - - protected static int getCasingMeta() { - return 3; - } - - protected static int getCasingMeta2() { - return 12; - } - - protected static int getCasingMeta3() { - return 13; - } - - protected static int getCasingMeta4() { - return 2; - } - - protected static int getCasingMeta5() { - return 6; - } - - protected static int getCasingMeta6() { - return 9; - } - - protected static int getCasingMeta7() { - return 8; - } - - private boolean addDataOrbHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_ElementalDataOrbHolder) { - try { - ((GT_MetaTileEntity_Hatch_ElementalDataOrbHolder) aMetaTileEntity).mRecipeMap = getRecipeMap(); - return addToMachineListInternal(mReplicatorDataOrbHatches, aMetaTileEntity, aBaseCasingIndex); - } - catch (Throwable t) { - t.printStackTrace(); - } - } - } - return false; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return CASING_TEXTURE_ID; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public boolean requiresVanillaGtGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe_Map.sElementalDuplicatorRecipes; - } - - public boolean isCorrectMachinePart(final ItemStack aStack) { - return true; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(getMaxParallelRecipes(), 100, 100); - } - - - @Override - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - GT_Recipe tRecipe = null; - - try { - log("Checking "+aItemInputs.length+" Data Orbs"); - - for (int i=0;i<aItemInputs.length;i++) { - ItemStack aItem = aItemInputs[i]; - log("Found: "+aItem.getDisplayName()); - } - ItemStack aDataOrbStack = null; - recipe : for (GT_Recipe nRecipe : this.getRecipeMap().mRecipeList) { - //log("Checking Recipe for: "+(nRecipe.mOutputs.length > 0 && nRecipe.mOutputs[0] != null ? nRecipe.mOutputs[0].getDisplayName() : nRecipe.mFluidOutputs[0].getLocalizedName())); - ItemStack aTempStack = getSpecialSlotStack(nRecipe); - if (aTempStack != null) { - for (ItemStack aItem : aItemInputs) { - if (nRecipe.mSpecialItems != null) { - if (GT_Utility.areStacksEqual(aTempStack, aItem, false)) { - Materials tMaterial = Element.get(Behaviour_DataOrb.getDataName(aTempStack)).mLinkedMaterials.get(0); - log("Found: "+aTempStack.getDisplayName()+" for "+tMaterial.name()); - aDataOrbStack = aTempStack; - break recipe; - } - } - } - } - } - if (aDataOrbStack != null) { - tRecipe = findRecipe( - getBaseMetaTileEntity(), mLastRecipe, false, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aDataOrbStack, aItemInputs); - if (tRecipe != null) { - Materials tMaterial = Element.get(Behaviour_DataOrb.getDataName(aDataOrbStack)).mLinkedMaterials.get(0); - log("Found recipe for "+tMaterial.name()); - } - else { - log("No Recipe Found"); - } - } - else { - log("Null DO"); - } - - } - catch (Throwable t) { - t.printStackTrace(); - } - - - - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - if (tRecipe == null) { - log("BAD RETURN - 1"); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+aMaxParallelRecipes); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - log("Broke at "+parallelRecipes+"."); - break; - } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - log("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 4; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - log("GOOD RETURN - 1"); - return true; - } - - - @Override - public int getMaxParallelRecipes() { - return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiMolecularTransformer; - } - - public int getDamageToComponent(final ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - // Fix GT bug - if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { - this.getBaseMetaTileEntity().setFrontFacing((byte) 1); - } - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mUpdate == 1 || this.mStartUpCheck == 1) { - this.mReplicatorDataOrbHatches.clear(); - } - } - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override - public ArrayList<ItemStack> getStoredInputs() { - ArrayList<ItemStack> tItems = super.getStoredInputs(); - for (GT_MetaTileEntity_Hatch_ElementalDataOrbHolder tHatch : mReplicatorDataOrbHatches) { - tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - tItems.addAll(tHatch.getInventory()); - } - } - tItems.removeAll(Collections.singleton(null)); - return tItems; - } - - /** - * finds a Recipe matching the aFluid and ItemStack Inputs. - * - * @param aTileEntity an Object representing the current coordinates of the executing Block/Entity/Whatever. This may be null, especially during Startup. - * @param aRecipe in case this is != null it will try to use this Recipe first when looking things up. - * @param aNotUnificated if this is T the Recipe searcher will unificate the ItemStack Inputs - * @param aDontCheckStackSizes if set to false will only return recipes that can be executed at least once with the provided input - * @param aVoltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage - * @param aFluids the Fluid Inputs - * @param aSpecialSlot the content of the Special Slot, the regular Manager doesn't do anything with this, but some custom ones do. - * @param aInputs the Item Inputs - * @return the Recipe it has found or null for no matching Recipe - */ - public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, boolean aDontCheckStackSizes, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) { - - GT_Recipe_Map mRecipeMap = this.getRecipeMap(); - // No Recipes? Well, nothing to be found then. - if (mRecipeMap.mRecipeList.isEmpty()) { - return null; - } - - // Some Recipe Classes require a certain amount of Inputs of certain kinds. Like "at least 1 Fluid + 1 Stack" or "at least 2 Stacks" before they start searching for Recipes. - // This improves Performance massively, especially if people leave things like Circuits, Molds or Shapes in their Machines to select Sub Recipes. - if (GregTech_API.sPostloadFinished) { - if (mRecipeMap.mMinimalInputFluids > 0) { - if (aFluids == null) return null; - int tAmount = 0; - for (FluidStack aFluid : aFluids) if (aFluid != null) tAmount++; - if (tAmount < mRecipeMap.mMinimalInputFluids) return null; - } - if (mRecipeMap.mMinimalInputItems > 0) { - if (aInputs == null) return null; - int tAmount = 0; - for (ItemStack aInput : aInputs) if (aInput != null) tAmount++; - if (tAmount < mRecipeMap.mMinimalInputItems) return null; - } - } - - // Unification happens here in case the Input isn't already unificated. - if (aNotUnificated) { - aInputs = GT_OreDictUnificator.getStackArray(true, (Object[]) aInputs); - } - - // Check the Recipe which has been used last time in order to not have to search for it again, if possible. - if (aRecipe != null) { - ItemStack aRecipeSpecial = getSpecialSlotStack(aRecipe); - if (!aRecipe.mFakeRecipe && aRecipe.mCanBeBuffered && aRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs) && GT_Utility.areStacksEqual(aRecipeSpecial, aSpecialSlot, false) && areDataOrbsEqual(aRecipeSpecial, aSpecialSlot)) { - return aRecipe.mEnabled && aVoltage * mRecipeMap.mAmperage >= aRecipe.mEUt ? aRecipe : null; - } - } - - // Now look for the Recipes inside the Item HashMaps, but only when the Recipes usually have Items. - if (mRecipeMap.mUsualInputCount > 0 && aInputs != null) for (ItemStack tStack : aInputs) - if (tStack != null) { - Collection<GT_Recipe> tRecipes = mRecipeMap.mRecipeItemMap.get(new GT_ItemStack(tStack)); - if (tRecipes != null) { - for (GT_Recipe tRecipe : tRecipes) { - if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { - ItemStack aRecipeSpecial = getSpecialSlotStack(tRecipe); - if (GT_Utility.areStacksEqual(aRecipeSpecial, aSpecialSlot, false) && areDataOrbsEqual(aRecipeSpecial, aSpecialSlot)) { - return tRecipe.mEnabled && aVoltage * mRecipeMap.mAmperage >= tRecipe.mEUt ? tRecipe : null; - } - } - tRecipes = mRecipeMap.mRecipeItemMap.get(new GT_ItemStack(tStack, true)); - } - } - if (tRecipes != null) { - for (GT_Recipe tRecipe : tRecipes) { - if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { - ItemStack aRecipeSpecial = getSpecialSlotStack(tRecipe); - if (GT_Utility.areStacksEqual(aRecipeSpecial, aSpecialSlot, false) && areDataOrbsEqual(aRecipeSpecial, aSpecialSlot)) { - return tRecipe.mEnabled && aVoltage * mRecipeMap.mAmperage >= tRecipe.mEUt ? tRecipe : null; - } - } - } - } - } - - // If the minimal Amount of Items for the Recipe is 0, then it could be a Fluid-Only Recipe, so check that Map too. - if (mRecipeMap.mMinimalInputItems == 0 && aFluids != null) for (FluidStack aFluid : aFluids) - if (aFluid != null) { - Collection<GT_Recipe> - tRecipes = mRecipeMap.mRecipeFluidMap.get(aFluid.getFluid()); - if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) { - if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { - ItemStack aRecipeSpecial = getSpecialSlotStack(tRecipe); - if (GT_Utility.areStacksEqual(aRecipeSpecial, aSpecialSlot, false) && areDataOrbsEqual(aRecipeSpecial, aSpecialSlot)) { - return tRecipe.mEnabled && aVoltage * mRecipeMap.mAmperage >= tRecipe.mEUt ? tRecipe : null; - } - } - } - } - - // And nothing has been found. - return null; - } - - public static ItemStack getSpecialSlotStack(GT_Recipe aRecipe) { - ItemStack aStack = null; - if (aRecipe.mSpecialItems != null) { - if (aRecipe.mSpecialItems instanceof ItemStack[]) { - ItemStack[] aTempStackArray = (ItemStack[]) aRecipe.mSpecialItems; - aStack = aTempStackArray[0]; - } - } - return aStack; - } - - private static boolean areDataOrbsEqual(ItemStack aOrb1, ItemStack aOrb2) { - if (aOrb1 != null && aOrb2 != null) { - Materials tMaterial1 = Element.get(Behaviour_DataOrb.getDataName(aOrb1)).mLinkedMaterials.get(0); - Materials tMaterial2 = Element.get(Behaviour_DataOrb.getDataName(aOrb2)).mLinkedMaterials.get(0); - if (tMaterial1.equals(tMaterial2)) { - return true; - } - } - - return false; - } - + private final ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder> mReplicatorDataOrbHatches = + new ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder>(); + private static final int CASING_TEXTURE_ID = TAE.getIndexFromPage(0, 3); + private int mCasing = 0; + + public GregtechMTE_ElementalDuplicator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_ElementalDuplicator(final String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_ElementalDuplicator(this.mName); + } + + @Override + public String getMachineType() { + return "Replicator"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Produces Elemental Material from UU Matter") + .addInfo("Speed: +100% | EU Usage: 100% | Parallel: 8 * Tier") + .addInfo("Maximum 1x of each bus/hatch.") + .addInfo("Does not require both Output Hatch & Bus") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(9, 6, 9, true) + .addController("Top Center") + .addCasingInfo("Elemental Confinement Shell", 138) + .addCasingInfo("Matter Fabricator Casing", 24) + .addCasingInfo("Particle Containment Casing", 24) + .addCasingInfo("Matter Generation Coil", 24) + .addCasingInfo("High Voltage Current Capacitor", 20) + .addCasingInfo("Resonance Chamber III", 24) + .addCasingInfo("Modulator III", 16) + .addOtherStructurePart("Data Orb Repository", "1x", 1) + .addInputHatch("Any 1 dot hint", 1) + .addOutputBus("Any 1 dot hint", 1) + .addOutputHatch("Any 1 dot hint", 1) + .addEnergyHatch("Any 1 dot hint", 1) + .addMaintenanceHatch("Any 1 dot hint", 1) + .addMufflerHatch("Any 1 dot hint", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + private static final String STRUCTURE_PIECE_MAIN = "main"; + private IStructureDefinition<GregtechMTE_ElementalDuplicator> STRUCTURE_DEFINITION = null; + + @Override + public IStructureDefinition<GregtechMTE_ElementalDuplicator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_ElementalDuplicator>builder() + + // h = Hatch + // c = Casing + + // a = MF Casing 1 + // b = Matter Gen Coil + + // d = Current Capacitor + // e = Particle + + // f = Resonance III + // g = Modulator III + + .addShape(STRUCTURE_PIECE_MAIN, (new String[][] { + { + " ccc ", + " ccccc ", + " ccccccc ", + "ccchhhccc", + "ccch~hccc", + "ccchhhccc", + " ccccccc ", + " ccccc ", + " ccc " + }, + { + " cac ", + " abfba ", + " abfgfba ", + "cbfgdgfbc", + "afgdddgfa", + "cbfgdgfbc", + " abfgfba ", + " abfba ", + " cac " + }, + { + " cec ", + " e e ", + " e e ", + "c d c", + "e ddd e", + "c d c", + " e e ", + " e e ", + " cec " + }, + { + " cec ", + " e e ", + " e e ", + "c d c", + "e ddd e", + "c d c", + " e e ", + " e e ", + " cec " + }, + { + " cac ", + " abfba ", + " abfgfba ", + "cbfgdgfbc", + "afgdddgfa", + "cbfgdgfbc", + " abfgfba ", + " abfba ", + " cac " + }, + { + " ccc ", + " ccccc ", + " ccccccc ", + "ccchhhccc", + "ccchhhccc", + "ccchhhccc", + " ccccccc ", + " ccccc ", + " ccc " + }, + })) + .addElement('a', ofBlock(getCasingBlock4(), getCasingMeta6())) + .addElement('b', ofBlock(getCasingBlock4(), getCasingMeta7())) + .addElement('d', ofBlock(getCasingBlock2(), getCasingMeta2())) + .addElement('e', ofBlock(getCasingBlock2(), getCasingMeta3())) + .addElement('f', ofBlock(getCasingBlock3(), getCasingMeta4())) + .addElement('g', ofBlock(getCasingBlock3(), getCasingMeta5())) + .addElement( + 'c', lazy(t -> onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement( + 'h', + lazy(t -> ofChain( + buildHatchAdder(GregtechMTE_ElementalDuplicator.class) + .atLeast(InputHatch, OutputBus, OutputHatch, Maintenance, Muffler, Energy) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_ElementalDuplicator.class) + .hatchClass(GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.class) + .adder(GregtechMTE_ElementalDuplicator::addDataOrbHatch) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta()))))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 4, 4, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + boolean aDidBuild = checkPiece(STRUCTURE_PIECE_MAIN, 4, 4, 0); + if (this.mInputHatches.size() != 1 + || (this.mOutputBusses.size() != 1 && this.mOutputHatches.size() != 0) + || this.mEnergyHatches.size() != 1 + || this.mReplicatorDataOrbHatches.size() != 1) { + return false; + } + log("Casings: " + mCasing); + return aDidBuild && mCasing >= 138 && checkHatch(); + } + + protected static int getCasingTextureIndex() { + return CASING_TEXTURE_ID; + } + + protected static Block getCasingBlock() { + return ModBlocks.blockCasings5Misc; + } + + protected static Block getCasingBlock2() { + return ModBlocks.blockSpecialMultiCasings; + } + + protected static Block getCasingBlock3() { + return ModBlocks.blockSpecialMultiCasings2; + } + + protected static Block getCasingBlock4() { + return ModBlocks.blockCasingsMisc; + } + + protected static int getCasingMeta() { + return 3; + } + + protected static int getCasingMeta2() { + return 12; + } + + protected static int getCasingMeta3() { + return 13; + } + + protected static int getCasingMeta4() { + return 2; + } + + protected static int getCasingMeta5() { + return 6; + } + + protected static int getCasingMeta6() { + return 9; + } + + protected static int getCasingMeta7() { + return 8; + } + + private boolean addDataOrbHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_ElementalDataOrbHolder) { + try { + ((GT_MetaTileEntity_Hatch_ElementalDataOrbHolder) aMetaTileEntity).mRecipeMap = getRecipeMap(); + return addToMachineListInternal(mReplicatorDataOrbHatches, aMetaTileEntity, aBaseCasingIndex); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + return false; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public boolean requiresVanillaGtGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe_Map.sElementalDuplicatorRecipes; + } + + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), 100, 100); + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = null; + + try { + log("Checking " + aItemInputs.length + " Data Orbs"); + + for (int i = 0; i < aItemInputs.length; i++) { + ItemStack aItem = aItemInputs[i]; + log("Found: " + aItem.getDisplayName()); + } + ItemStack aDataOrbStack = null; + recipe: + for (GT_Recipe nRecipe : this.getRecipeMap().mRecipeList) { + // log("Checking Recipe for: "+(nRecipe.mOutputs.length > 0 && nRecipe.mOutputs[0] != null ? + // nRecipe.mOutputs[0].getDisplayName() : nRecipe.mFluidOutputs[0].getLocalizedName())); + ItemStack aTempStack = getSpecialSlotStack(nRecipe); + if (aTempStack != null) { + for (ItemStack aItem : aItemInputs) { + if (nRecipe.mSpecialItems != null) { + if (GT_Utility.areStacksEqual(aTempStack, aItem, false)) { + Materials tMaterial = Element.get(Behaviour_DataOrb.getDataName(aTempStack)) + .mLinkedMaterials + .get(0); + log("Found: " + aTempStack.getDisplayName() + " for " + tMaterial.name()); + aDataOrbStack = aTempStack; + break recipe; + } + } + } + } + } + if (aDataOrbStack != null) { + tRecipe = findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aDataOrbStack, + aItemInputs); + if (tRecipe != null) { + Materials tMaterial = Element.get(Behaviour_DataOrb.getDataName(aDataOrbStack)) + .mLinkedMaterials + .get(0); + log("Found recipe for " + tMaterial.name()); + } else { + log("No Recipe Found"); + } + } else { + log("Null DO"); + } + + } catch (Throwable t) { + t.printStackTrace(); + } + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + aMaxParallelRecipes); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at " + parallelRecipes + "."); + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 4; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiMolecularTransformer; + } + + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + // Fix GT bug + if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { + this.getBaseMetaTileEntity().setFrontFacing((byte) 1); + } + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mReplicatorDataOrbHatches.clear(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> tItems = super.getStoredInputs(); + for (GT_MetaTileEntity_Hatch_ElementalDataOrbHolder tHatch : mReplicatorDataOrbHatches) { + tHatch.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + tItems.addAll(tHatch.getInventory()); + } + } + tItems.removeAll(Collections.singleton(null)); + return tItems; + } + + /** + * finds a Recipe matching the aFluid and ItemStack Inputs. + * + * @param aTileEntity an Object representing the current coordinates of the executing Block/Entity/Whatever. This may be null, especially during Startup. + * @param aRecipe in case this is != null it will try to use this Recipe first when looking things up. + * @param aNotUnificated if this is T the Recipe searcher will unificate the ItemStack Inputs + * @param aDontCheckStackSizes if set to false will only return recipes that can be executed at least once with the provided input + * @param aVoltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage + * @param aFluids the Fluid Inputs + * @param aSpecialSlot the content of the Special Slot, the regular Manager doesn't do anything with this, but some custom ones do. + * @param aInputs the Item Inputs + * @return the Recipe it has found or null for no matching Recipe + */ + public GT_Recipe findRecipe( + IHasWorldObjectAndCoords aTileEntity, + GT_Recipe aRecipe, + boolean aNotUnificated, + boolean aDontCheckStackSizes, + long aVoltage, + FluidStack[] aFluids, + ItemStack aSpecialSlot, + ItemStack... aInputs) { + + GT_Recipe_Map mRecipeMap = this.getRecipeMap(); + // No Recipes? Well, nothing to be found then. + if (mRecipeMap.mRecipeList.isEmpty()) { + return null; + } + + // Some Recipe Classes require a certain amount of Inputs of certain kinds. Like "at least 1 Fluid + 1 Stack" or + // "at least 2 Stacks" before they start searching for Recipes. + // This improves Performance massively, especially if people leave things like Circuits, Molds or Shapes in + // their Machines to select Sub Recipes. + if (GregTech_API.sPostloadFinished) { + if (mRecipeMap.mMinimalInputFluids > 0) { + if (aFluids == null) return null; + int tAmount = 0; + for (FluidStack aFluid : aFluids) if (aFluid != null) tAmount++; + if (tAmount < mRecipeMap.mMinimalInputFluids) return null; + } + if (mRecipeMap.mMinimalInputItems > 0) { + if (aInputs == null) return null; + int tAmount = 0; + for (ItemStack aInput : aInputs) if (aInput != null) tAmount++; + if (tAmount < mRecipeMap.mMinimalInputItems) return null; + } + } + + // Unification happens here in case the Input isn't already unificated. + if (aNotUnificated) { + aInputs = GT_OreDictUnificator.getStackArray(true, (Object[]) aInputs); + } + + // Check the Recipe which has been used last time in order to not have to search for it again, if possible. + if (aRecipe != null) { + ItemStack aRecipeSpecial = getSpecialSlotStack(aRecipe); + if (!aRecipe.mFakeRecipe + && aRecipe.mCanBeBuffered + && aRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs) + && GT_Utility.areStacksEqual(aRecipeSpecial, aSpecialSlot, false) + && areDataOrbsEqual(aRecipeSpecial, aSpecialSlot)) { + return aRecipe.mEnabled && aVoltage * mRecipeMap.mAmperage >= aRecipe.mEUt ? aRecipe : null; + } + } + + // Now look for the Recipes inside the Item HashMaps, but only when the Recipes usually have Items. + if (mRecipeMap.mUsualInputCount > 0 && aInputs != null) + for (ItemStack tStack : aInputs) + if (tStack != null) { + Collection<GT_Recipe> tRecipes = mRecipeMap.mRecipeItemMap.get(new GT_ItemStack(tStack)); + if (tRecipes != null) { + for (GT_Recipe tRecipe : tRecipes) { + if (!tRecipe.mFakeRecipe + && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { + ItemStack aRecipeSpecial = getSpecialSlotStack(tRecipe); + if (GT_Utility.areStacksEqual(aRecipeSpecial, aSpecialSlot, false) + && areDataOrbsEqual(aRecipeSpecial, aSpecialSlot)) { + return tRecipe.mEnabled && aVoltage * mRecipeMap.mAmperage >= tRecipe.mEUt + ? tRecipe + : null; + } + } + tRecipes = mRecipeMap.mRecipeItemMap.get(new GT_ItemStack(tStack, true)); + } + } + if (tRecipes != null) { + for (GT_Recipe tRecipe : tRecipes) { + if (!tRecipe.mFakeRecipe + && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { + ItemStack aRecipeSpecial = getSpecialSlotStack(tRecipe); + if (GT_Utility.areStacksEqual(aRecipeSpecial, aSpecialSlot, false) + && areDataOrbsEqual(aRecipeSpecial, aSpecialSlot)) { + return tRecipe.mEnabled && aVoltage * mRecipeMap.mAmperage >= tRecipe.mEUt + ? tRecipe + : null; + } + } + } + } + } + + // If the minimal Amount of Items for the Recipe is 0, then it could be a Fluid-Only Recipe, so check that Map + // too. + if (mRecipeMap.mMinimalInputItems == 0 && aFluids != null) + for (FluidStack aFluid : aFluids) + if (aFluid != null) { + Collection<GT_Recipe> tRecipes = mRecipeMap.mRecipeFluidMap.get(aFluid.getFluid()); + if (tRecipes != null) + for (GT_Recipe tRecipe : tRecipes) { + if (!tRecipe.mFakeRecipe + && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { + ItemStack aRecipeSpecial = getSpecialSlotStack(tRecipe); + if (GT_Utility.areStacksEqual(aRecipeSpecial, aSpecialSlot, false) + && areDataOrbsEqual(aRecipeSpecial, aSpecialSlot)) { + return tRecipe.mEnabled && aVoltage * mRecipeMap.mAmperage >= tRecipe.mEUt + ? tRecipe + : null; + } + } + } + } + + // And nothing has been found. + return null; + } + + public static ItemStack getSpecialSlotStack(GT_Recipe aRecipe) { + ItemStack aStack = null; + if (aRecipe.mSpecialItems != null) { + if (aRecipe.mSpecialItems instanceof ItemStack[]) { + ItemStack[] aTempStackArray = (ItemStack[]) aRecipe.mSpecialItems; + aStack = aTempStackArray[0]; + } + } + return aStack; + } + + private static boolean areDataOrbsEqual(ItemStack aOrb1, ItemStack aOrb2) { + if (aOrb1 != null && aOrb2 != null) { + Materials tMaterial1 = Element.get(Behaviour_DataOrb.getDataName(aOrb1)) + .mLinkedMaterials + .get(0); + Materials tMaterial2 = Element.get(Behaviour_DataOrb.getDataName(aOrb2)) + .mLinkedMaterials + .get(0); + if (tMaterial1.equals(tMaterial2)) { + return true; + } + } + + return false; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FastNeutronReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FastNeutronReactor.java index 3941d59edb..0d065f6e4b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FastNeutronReactor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FastNeutronReactor.java @@ -1,19 +1,6 @@ /* package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import gregtech.api.enums.TAE; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.core.util.minecraft.FluidUtils; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; public class GregtechMTE_FastNeutronReactor extends GregtechMeta_MultiBlockBase @@ -39,7 +26,7 @@ extends GregtechMeta_MultiBlockBase @Override public String getCustomGUIResourceName() { return null; - } + } @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) @@ -70,7 +57,7 @@ extends GregtechMeta_MultiBlockBase if (processing_Stage_2()) { if (processing_Stage_3()) { if (processing_Stage_4()) { - + } else { //Stage 4 @@ -88,8 +75,8 @@ extends GregtechMeta_MultiBlockBase //Stage 1 } return false; - } - + } + @Override public int getMaxParallelRecipes() { return 1; @@ -104,7 +91,7 @@ extends GregtechMeta_MultiBlockBase for (GT_MetaTileEntity_Hatch_Input tRecipe : this.mInputHatches) { if (tRecipe.getFluid() != null){ FluidStack tFluid = FluidUtils.getFluidStack(tRecipe.getFluid(), 200); - if (tFluid != null) { + if (tFluid != null) { if (tFluid == GT_ModHandler.getDistilledWater(1)) { if (depleteInput(tFluid)) { this.mMaxProgresstime = Math.max(1, runtimeBoost(8 * 2)); @@ -112,10 +99,10 @@ extends GregtechMeta_MultiBlockBase this.mEfficiencyIncrease = (this.mMaxProgresstime * getEfficiencyIncrease()); return true; } - } - + } + } - } + } } this.mMaxProgresstime = 0; this.mEUt = 0; @@ -150,11 +137,11 @@ extends GregtechMeta_MultiBlockBase } return true; } - + public int getEUt() { return 0; //Default 400 } - + public int getEfficiencyIncrease() { return 0; //Default 12 } @@ -213,7 +200,7 @@ extends GregtechMeta_MultiBlockBase return true; } - public boolean damageFilter(){ + public boolean damageFilter(){ return false; } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java index d378622b00..61468ce100 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java @@ -1,8 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -23,6 +25,9 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.helpers.FlotationRecipeHandler; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -30,430 +35,419 @@ import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase<GregtechMTE_FrothFlotationCell> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMTE_FrothFlotationCell> STRUCTURE_DEFINITION = null; - - public GregtechMTE_FrothFlotationCell(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMTE_FrothFlotationCell(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMTE_FrothFlotationCell(this.mName); - } - - @Override - public String getMachineType() { - return "Flotation Cell"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Process that milled ore!") - .addInfo("You can only ever process one type of material per controller") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 9, 3, true) - .addController("Front Center") - .addCasingInfo("Inconel Reinforced Casing", 68) - .addCasingInfo("Flotation Casing", 52) - .addInputBus("Bottom Casing", 1) - .addInputHatch("Bottom Casing", 1) - .addOutputHatch("Bottom Casing", 1) - .addEnergyHatch("Bottom Casing", 1) - .addMaintenanceHatch("Bottom Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(207)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - return TAE.getIndexFromPage(2, 1); - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe.GTPP_Recipe_Map.sFlotationCellRecipes; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public IStructureDefinition<GregtechMTE_FrothFlotationCell> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_FrothFlotationCell>builder() - .addShape(mName, new String[][]{ - {" ", " ", " X ", " X~X ", " X ", " ", " "}, - {" ", " F ", " FFF ", " FF FF ", " FFF ", " F ", " "}, - {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, - {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, - {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, - {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, - {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, - {" CCC ", " CCCCC ", "CCCCCCC", "CCCCCCC", "CCCCCCC", " CCCCC ", " CCC "}, - {" CCC ", " CCCCC ", "CCCCCCC", "CCCCCCC", "CCCCCCC", " CCCCC ", " CCC "}, - }) - .addElement( - 'C', - buildHatchAdder(GregtechMTE_FrothFlotationCell.class) - .atLeast(InputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) - .casingIndex(TAE.GTPP_INDEX(1)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 1))) - ) - .addElement( - 'F', - ofBlock( - ModBlocks.blockSpecialMultiCasings, 9 - ) - ) - .addElement( - 'X', - ofBlock( - ModBlocks.blockCasings3Misc, 1 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 3, 3, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 3, 3, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 3, 3, 0) && mCasing >= 68 - 4 && checkHatch(); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiFrothFlotationCell; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - // Fix GT bug - if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { - log("Fixing Bad Facing. (GT Bug)"); - this.getBaseMetaTileEntity().setFrontFacing((byte) 1); - } - } - - @Override - public boolean checkRecipe(ItemStack arg0) { - return super.checkRecipeGeneric(); - } - - @Override - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - GT_Recipe tRecipe = findRecipe( - getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - if (tRecipe == null) { - log("BAD RETURN - 1"); - return false; - } - - /* - * - * Material checks - * Makes sure we can only ever use one type of material in this flotation cell. - * We used to depend on Alk's hash, but it's unreliable and user-hostile - * So we're using unlocalized name of material now. - * - */ - Material foundMaterial = FlotationRecipeHandler.getMaterialOfMilledProduct(FlotationRecipeHandler.findMilledStack(tRecipe)); - String foundMaterialName = null; - if (foundMaterial != null) { - foundMaterialName = foundMaterial.getUnlocalizedName(); - } - - if (foundMaterialName == null) { - log("Did not find material from Milled Ore."); - ItemStack milledStack = FlotationRecipeHandler.findMilledStack(tRecipe); - if (milledStack != null) { - log("Found stack: " + milledStack.getDisplayName()); - } - return false; - } - - // Set material locked for this controller - if (lockedMaterialName == null) { - lockedMaterialName = foundMaterialName; - } - - // Check material match - if (!Objects.equals(lockedMaterialName, foundMaterialName)) { - log("Did not find the correct milled type."); - log("Found: "+foundMaterialName); - log("Expected: "+lockedMaterialName); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+aMaxParallelRecipes); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - log("Broke at "+parallelRecipes+"."); - break; - } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - log("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 4; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - log("GOOD RETURN - 1"); - return true; - } - - /* - * Handle NBT - */ - - private String lockedMaterialName = null; - - @Override - public void setItemNBT(NBTTagCompound aNBT) { - if (lockedMaterialName != null) { - aNBT.setString("lockedMaterialName", lockedMaterialName); - } - super.setItemNBT(aNBT); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - if (lockedMaterialName != null) { - aNBT.setString("lockedMaterialName", lockedMaterialName); - } - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - if (aNBT.hasKey("lockedMaterialName", Constants.NBT.TAG_STRING)) { - lockedMaterialName = aNBT.getString("lockedMaterialName"); - } - } - - @Override - public String[] getExtraInfoData() { - return new String[] { - "Locked material: " + lockedMaterialName - }; - } +public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase<GregtechMTE_FrothFlotationCell> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMTE_FrothFlotationCell> STRUCTURE_DEFINITION = null; + + public GregtechMTE_FrothFlotationCell(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_FrothFlotationCell(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_FrothFlotationCell(this.mName); + } + + @Override + public String getMachineType() { + return "Flotation Cell"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Process that milled ore!") + .addInfo("You can only ever process one type of material per controller") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 9, 3, true) + .addController("Front Center") + .addCasingInfo("Inconel Reinforced Casing", 68) + .addCasingInfo("Flotation Casing", 52) + .addInputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addOutputHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(2, 1); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sFlotationCellRecipes; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public IStructureDefinition<GregtechMTE_FrothFlotationCell> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_FrothFlotationCell>builder() + .addShape(mName, new String[][] { + {" ", " ", " X ", " X~X ", " X ", " ", " "}, + {" ", " F ", " FFF ", " FF FF ", " FFF ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" CCC ", " CCCCC ", "CCCCCCC", "CCCCCCC", "CCCCCCC", " CCCCC ", " CCC "}, + {" CCC ", " CCCCC ", "CCCCCCC", "CCCCCCC", "CCCCCCC", " CCCCC ", " CCC "}, + }) + .addElement( + 'C', + buildHatchAdder(GregtechMTE_FrothFlotationCell.class) + .atLeast(InputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(1)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 1)))) + .addElement('F', ofBlock(ModBlocks.blockSpecialMultiCasings, 9)) + .addElement('X', ofBlock(ModBlocks.blockCasings3Misc, 1)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 3, 3, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 3, 3, 0) && mCasing >= 68 - 4 && checkHatch(); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiFrothFlotationCell; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + // Fix GT bug + if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { + log("Fixing Bad Facing. (GT Bug)"); + this.getBaseMetaTileEntity().setFrontFacing((byte) 1); + } + } + + @Override + public boolean checkRecipe(ItemStack arg0) { + return super.checkRecipeGeneric(); + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + /* + * + * Material checks + * Makes sure we can only ever use one type of material in this flotation cell. + * We used to depend on Alk's hash, but it's unreliable and user-hostile + * So we're using unlocalized name of material now. + * + */ + Material foundMaterial = + FlotationRecipeHandler.getMaterialOfMilledProduct(FlotationRecipeHandler.findMilledStack(tRecipe)); + String foundMaterialName = null; + if (foundMaterial != null) { + foundMaterialName = foundMaterial.getUnlocalizedName(); + } + + if (foundMaterialName == null) { + log("Did not find material from Milled Ore."); + ItemStack milledStack = FlotationRecipeHandler.findMilledStack(tRecipe); + if (milledStack != null) { + log("Found stack: " + milledStack.getDisplayName()); + } + return false; + } + + // Set material locked for this controller + if (lockedMaterialName == null) { + lockedMaterialName = foundMaterialName; + } + + // Check material match + if (!Objects.equals(lockedMaterialName, foundMaterialName)) { + log("Did not find the correct milled type."); + log("Found: " + foundMaterialName); + log("Expected: " + lockedMaterialName); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + aMaxParallelRecipes); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at " + parallelRecipes + "."); + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 4; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + /* + * Handle NBT + */ + + private String lockedMaterialName = null; + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + if (lockedMaterialName != null) { + aNBT.setString("lockedMaterialName", lockedMaterialName); + } + super.setItemNBT(aNBT); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + if (lockedMaterialName != null) { + aNBT.setString("lockedMaterialName", lockedMaterialName); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("lockedMaterialName", Constants.NBT.TAG_STRING)) { + lockedMaterialName = aNBT.getString("lockedMaterialName"); + } + } + + @Override + public String[] getExtraInfoData() { + return new String[] {"Locked material: " + lockedMaterialName}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_LargeNaqReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_LargeNaqReactor.java index 1ead7edad5..57529d1900 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_LargeNaqReactor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_LargeNaqReactor.java @@ -1,37 +1,12 @@ /* package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; - -import gregtech.api.GregTech_API; -import gregtech.api.enums.TAE; -import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.block.ModBlocks; -import gtPlusPlus.core.util.minecraft.LangUtils; -import gtPlusPlus.core.util.minecraft.PlayerUtils; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Naquadah; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { public ArrayList<GT_MetaTileEntity_Hatch_Naquadah> mNaqHatches = new ArrayList<GT_MetaTileEntity_Hatch_Naquadah>(); public static String[] mCasingName = new String[5]; - public static String mHatchName = "Naquadah Fuel Hatch"; + public static String mHatchName = "Naquadah Fuel Hatch"; private final int CASING_TEXTURE_ID = TAE.getIndexFromPage(0, 13); private final int META_BaseCasing = 0; //4 @@ -47,7 +22,7 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); - mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); + mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); mHatchName = LangUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 969); } @@ -74,14 +49,14 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { } if (mCasingName[4].toLowerCase().contains(".name")) { mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); - } + } if (mHatchName.toLowerCase().contains(".name")) { mHatchName = LangUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 969); } return new String[]{ "Naquadah reacts violently with potassium, ", "resulting in massive explosions with radioactive potential.", - "Size: 3x4x12, WxHxL", + "Size: 3x4x12, WxHxL", "Bottom Layer: "+mCasingName[0]+"s, (30x min)", "Middle Layer: "+mCasingName[2]+"s (10x), with", " "+mCasingName[3]+"s on either side", @@ -92,7 +67,7 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { "", "1x " + mHatchName + " (Any bottom layer casing)", "1x " + "Maintenance Hatch" + " (Any bottom layer side casing)", - "1x " + "Energy Hatch" + " (Any top layer casing)", + "1x " + "Energy Hatch" + " (Any top layer casing)", }; } @@ -126,7 +101,7 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { public boolean checkRecipe(ItemStack aStack) { return false; - } + } @Override public int getMaxParallelRecipes() { @@ -148,7 +123,7 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { @Override public String getSound() { - return (String) GregTech_API.sSoundList.get(Integer.valueOf(212)); + return (String) GregTech_API.sSoundList.get(Integer.valueOf(212)); } private Block getCasing(int casingID) { @@ -187,7 +162,7 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { int aShieldingCount = 0; int aPipeCount = 0; int aIntegralCasingCount = 0; - int aContainmentChamberCount = 0; + int aContainmentChamberCount = 0; // Bottom Layer aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, -7, xDir, zDir); @@ -241,7 +216,7 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { if (aOwnerName != null && aOwnerName.length() > 0) { aOwner = PlayerUtils.getPlayer(aOwnerName); } - + if (aShieldingCount != 128) { log("Not enough "+mCasingName[4]+"s, require 128."); if (aOwner != null) { @@ -283,7 +258,7 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { PlayerUtils.messagePlayer(aOwner, "Not enough "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s, require 48."); } return false; - } + } log("LNR Formed."); if (aOwner != null) { PlayerUtils.messagePlayer(aOwner, "Large Naquadah Reactor has formed successfully."); @@ -305,7 +280,7 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { return false; } } - } + } public int checkEntireLayer(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { int aCasingCount = 0; @@ -313,48 +288,48 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { for (int z = -4; z < 5; z++) { int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; //Skip the corners if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { continue; - } + } // Skip controller if (aY == 0 && x == 0 && z == 0) { continue; } - + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, true, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { log("Layer has error. Height: "+aY); //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); return 0; } - } - } + } + } return aCasingCount; } - public int checkOuterRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + public int checkOuterRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { int aCasingCount = 0; for (int x = -4; x < 5; x++) { for (int z = -4; z < 5; z++) { int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; //Skip the corners if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { continue; - } + } // If we are on the 5x5 ring, proceed - if ((x > -4 && x < 4 ) && (z > -4 && z < 4)) { + if ((x > -4 && x < 4 ) && (z > -4 && z < 4)) { if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); } else { continue; @@ -365,14 +340,14 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { log("Layer has error. Height: "+aY); //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); return 0; } - } + } } return aCasingCount; } @@ -382,16 +357,16 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { for (int z = -3; z < 4; z++) { int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; //Skip the corners if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { continue; - } + } // If we are on the 5x5 ring, proceed - if ((x > -3 && x < 3 ) && (z > -3 && z < 3)) { + if ((x > -3 && x < 3 ) && (z > -3 && z < 3)) { if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { - //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); } else { continue; @@ -402,51 +377,51 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { log("Layer has error. Height: "+aY); //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); return 0; } - } + } } return aCasingCount; } - + public int checkPipes(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { int aCasingCount = 0; for (int x = -1; x < 2; x++) { for (int z = -1; z < 2; z++) { int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; //Skip the corners if ((x == 1 && z == 1) || (x == -1 && z == -1) || (x == 1 && z == -1) || (x == -1 && z == 1) || (x == 0 && z == 0)) { Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { log("Pipe has error. Height: "+aY); //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); return 0; }; } - } + } } return aCasingCount; } - + public int checkContainmentRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { int aCasingCount = 0; for (int x = -2; x < 3; x++) { for (int z = -2; z < 3; z++) { int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; - int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; //Skip the corners if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { continue; @@ -456,14 +431,14 @@ public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { aCasingCount++; - } - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { log("Layer has error. Height: "+aY); //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); return 0; } - } + } } return aCasingCount; } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_MiniFusionPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_MiniFusionPlant.java index 9c2e3289c3..8f0a2802d4 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_MiniFusionPlant.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_MiniFusionPlant.java @@ -1,37 +1,12 @@ /* package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; - -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.TAE; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; -import gregtech.api.util.GTPP_Recipe; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ControlCore; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Plasma; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { public long currentVoltage = GT_Values.V[7]; public byte currentTier = 8; - + public void upvolt() { byte f = currentTier; if ((f+1) > 10) { @@ -40,10 +15,10 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { else { f++; } - this.currentTier = f; + this.currentTier = f; updateVoltage(); } - + public void downvolt() { byte f = currentTier; if ((f-1) < 8) { @@ -52,19 +27,19 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { else { f--; } - this.currentTier = f; + this.currentTier = f; updateVoltage(); } - + private long updateVoltage() { this.currentVoltage = GT_Values.V[this.currentTier-1]; return currentVoltage; } - + public GregtechMTE_MiniFusionPlant(String aName) { super(aName); } - + public GregtechMTE_MiniFusionPlant(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -101,10 +76,10 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { } return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(10))}; } - + @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { + public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GTPP_Recipe.GTPP_Recipe_Map.sSlowFusionRecipes; } @@ -125,10 +100,10 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { @Override public String[] getTooltip() { - return new String[] { - "Small scale fusion", + return new String[] { + "Small scale fusion", "16x slower than using Multiblock of the same voltage", - //"Input voltage can be changed within the GUI", + //"Input voltage can be changed within the GUI", "Place Input/Output Hatches on sides and bottom", "Power can only be inserted into the back", //e"Power can only be extracted from the top", @@ -155,7 +130,7 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { int tAmount = 0; ForgeDirection aDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()); - + //Require air in front, I think if (!aBaseMetaTileEntity.getAirOffset(xDir2, 0, zDir2)) { Logger.INFO("Did not find air in front"); @@ -168,9 +143,9 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); if (this.addToMachineList(tTileEntity, TAE.GTPP_INDEX(10))) { - tAmount++; + tAmount++; } - } + } } } } @@ -181,7 +156,7 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { @Override public boolean checkRecipe(ItemStack arg0) { - + ArrayList tFluidList = this.getStoredFluids(); int tFluidList_sS = tFluidList.size(); @@ -232,10 +207,10 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { //Logger.INFO("Step "+aStep++); return false; - - - - + + + + //return this.checkRecipeGeneric(this.getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); } @@ -268,15 +243,15 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { @Override public String[] getExtraInfoData() { - String mode = EnumChatFormatting.BLUE + "" + currentVoltage + EnumChatFormatting.RESET; - String aOutput = EnumChatFormatting.BLUE + "" + mEUt + EnumChatFormatting.RESET; + String mode = EnumChatFormatting.BLUE + "" + currentVoltage + EnumChatFormatting.RESET; + String aOutput = EnumChatFormatting.BLUE + "" + mEUt + EnumChatFormatting.RESET; String storedEnergyText; if (this.getEUVar() > maxEUStore()) { storedEnergyText = EnumChatFormatting.RED + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; } else { storedEnergyText = EnumChatFormatting.GREEN + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; } - + return new String[]{ "Stored EU: " + storedEnergyText, "Capacity: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.maxEUStore()) + EnumChatFormatting.RESET, @@ -304,7 +279,7 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { public long getInputTier() { return (long) GT_Utility.getTier(maxEUInput()); } - + @Override public boolean isElectric() { return true; @@ -374,11 +349,11 @@ public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { @Override public int getPollutionPerTick(ItemStack arg0) { return 0; - } + } @Override public GT_MetaTileEntity_Hatch_ControlCore getControlCoreBus() { - GT_MetaTileEntity_Hatch_ControlCore x = new GT_MetaTileEntity_Hatch_ControlCore("", 0, "", null); + GT_MetaTileEntity_Hatch_ControlCore x = new GT_MetaTileEntity_Hatch_ControlCore("", 0, "", null); return (GT_MetaTileEntity_Hatch_ControlCore) x; } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java index de86a097cf..fa8b27dec9 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java @@ -1,6 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.Collection; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.filterByMTETier; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -26,525 +32,531 @@ import gtPlusPlus.core.material.ELEMENT; import gtPlusPlus.core.material.nuclear.NUCLIDE; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import java.util.Collection; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.filterByMTETier; - -public class GregtechMTE_NuclearReactor extends GregtechMeta_MultiBlockBase<GregtechMTE_NuclearReactor> implements ISurvivalConstructable { - - protected int mFuelRemaining = 0; - - private int mCasing; - private IStructureDefinition<GregtechMTE_NuclearReactor> STRUCTURE_DEFINITION = null; - - - public GregtechMTE_NuclearReactor(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMTE_NuclearReactor(final String aName) { - super(aName); - } - - @Override - public long maxEUStore() { - return (640000000L * (Math.min(16, this.mEnergyHatches.size()))) / 16L; - } - - @Override - public String getMachineType() { - return "Reactor"; - } - - @Override - public GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe_Map.sLiquidFluorineThoriumReactorRecipes; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Liquid Fluoride Thorium Reactor.") - .addInfo("Produces Heat & Energy from Radioactive Beta Decay.") - .addInfo("Outputs U233 every 10 seconds, on average") - .addInfo("Input Fluorine and Helium for bonus byproducts") - .addInfo("Input Li2BeF4 and a molten salt as fuel.") - .addInfo("LiFBeF2ThF4UF4, LiFBeF2ZrF4UF4 or LiFBeF2ZrF4U235") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(7, 4, 7, true) - .addController("Bottom Center") - .addCasingInfo("Hastelloy-N Reactor Casing", 27) - .addCasingInfo("Zeron-100 Reactor Shielding", 26) - .addInputHatch("Top or bottom layer edges", 1) - .addOutputHatch("Top or bottom layer edges", 1) - .addDynamoHatch("Top or bottom layer edges", 1) - .addMaintenanceHatch("Top or bottom layer edges", 1) - .addMufflerHatch("Top 3x3", 2) - .addStructureInfo("All dynamos must be IV or LuV tier.") - .addStructureInfo("All other hatches must be IV+ tier.") - .addStructureInfo("3x Output Hatches, 2x Input Hatches, 4x Dynamo Hatches") - .addStructureInfo("2x Maintenance Hatches, 4x Mufflers") - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public String[] getExtraInfoData() { - final String tRunning = (this.mMaxProgresstime>0 ? "Reactor running":"Reactor stopped"); - final String tMaintainance = (this.getIdealStatus() == this.getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance"); - - return new String[]{ - "Liquid Fluoride Thorium Reactor", - tRunning, - tMaintainance, - "Current Output: "+this.mEUt+" EU/t", - "Fuel Remaining: "+this.mFuelRemaining+" Litres", - "Current Efficiency: "+(this.mEfficiency/5)+"%", - "Current Efficiency (Raw): "+(this.mEfficiency), - "It requires you to have 100% Efficiency."}; - } - - @Override - public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aStack) { - return aSide != this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - boolean aWarmedUp = this.mEfficiency == this.getMaxEfficiency(null); - if (!aBaseMetaTileEntity.isActive() || !aWarmedUp){ - if (aSide == aFacing) { - if (aActive) - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), - TextureFactory.builder().addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR_ACTIVE).extFacing().build()}; - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), - TextureFactory.builder().addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR).extFacing().build()}; - } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12))}; - } - else if(aBaseMetaTileEntity.isActive() && aWarmedUp){ - if (aSide == aFacing) { - if (aActive) - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13)), - TextureFactory.builder().addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR_ACTIVE).extFacing().build()}; - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13)), - TextureFactory.builder().addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR).extFacing().build()}; - } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13))}; - } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12))}; - - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "MatterFabricator"; - } - - public final boolean addNuclearReactorEdgeList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo && (((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity).mTier >= 5 && ((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity).mTier <= 6)){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input && ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier >= 5) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output && ((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity).mTier >= 5) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - public final boolean addNuclearReactorTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler && ((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity).mTier >= 5) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public IStructureDefinition<GregtechMTE_NuclearReactor> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_NuclearReactor>builder() - .addShape(mName, transpose(new String[][]{ - {"CCCCCCC", "COOOOOC", "COXXXOC", "COXXXOC", "COXXXOC", "COOOOOC", "CCCCCCC"}, - {"GGGGGGG", "G-----G", "G-----G", "G-----G", "G-----G", "G-----G", "GGGGGGG"}, - {"GGGGGGG", "G-----G", "G-----G", "G-----G", "G-----G", "G-----G", "GGGGGGG"}, - {"CCC~CCC", "COOOOOC", "COOOOOC", "COOOOOC", "COOOOOC", "COOOOOC", "CCCCCCC"}, - })) - .addElement( - 'C', - ofChain( - buildHatchAdder(GregtechMTE_NuclearReactor.class) - .atLeast(Maintenance) - .casingIndex(TAE.GTPP_INDEX(12)) - .dot(1) - .build(), - buildHatchAdder(GregtechMTE_NuclearReactor.class) - .atLeast(InputHatch, OutputHatch) - .adder(GregtechMTE_NuclearReactor::addNuclearReactorEdgeList) - .hatchItemFilterAnd(t -> filterByMTETier(5, Integer.MAX_VALUE)) - .casingIndex(TAE.GTPP_INDEX(12)) - .dot(1) - .build(), - buildHatchAdder(GregtechMTE_NuclearReactor.class) - .atLeast(Dynamo) - .adder(GregtechMTE_NuclearReactor::addNuclearReactorEdgeList) - .hatchItemFilterAnd(t -> filterByMTETier(5, 6)) - .casingIndex(TAE.GTPP_INDEX(12)) - .dot(1) - .build(), - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasingsMisc, 12 - ) - ) - ) - ) - .addElement( - 'X', - buildHatchAdder(GregtechMTE_NuclearReactor.class) - .atLeast(Muffler) - .adder(GregtechMTE_NuclearReactor::addNuclearReactorTopList) - .hatchItemFilterAnd(t -> filterByMTETier(5, Integer.MAX_VALUE)) - .casingIndex(TAE.GTPP_INDEX(12)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 12))) - ) - .addElement( - 'O', - ofBlock( - ModBlocks.blockCasingsMisc, 12 - ) - ) - .addElement( - 'G', - ofBlock( - ModBlocks.blockCasingsMisc, 13 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 3, 3, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 3, 3, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - if (checkPiece(mName, 3, 3, 0) && mCasing >= 27) { - if (mOutputHatches.size() >= 3 && mInputHatches.size() >= 2 && mDynamoHatches.size() == 4 && - mMufflerHatches.size() == 4 && mMaintenanceHatches.size() == 2) { - this.mWrench = true; - this.mScrewdriver = true; - this.mSoftHammer = true; - this.mHardHammer = true; - this.mSolderingTool = true; - this.mCrowbar = true; - this.turnCasingActive(false); - return true; - } - } - return false; - } - - // Alk's Life Lessons from Greg. - /* - [23:41:15] <GregoriusTechneticies> xdir and zdir are x2 and not x3 - [23:41:26] <GregoriusTechneticies> thats you issue - [23:44:33] <Alkalus> mmm? - [23:44:49] <Alkalus> Should they be x3? - [23:44:50] <GregoriusTechneticies> you just do a x2, what is for a 5x5 multiblock - [23:45:01] <GregoriusTechneticies> x3 is for a 7x7 one - [23:45:06] <Alkalus> I have no idea what that value does, tbh.. - [23:45:15] <GregoriusTechneticies> its the offset - [23:45:23] <Alkalus> Debugging checkMachine has been a pain and I usually trash designs that don't work straight up.. - [23:45:28] <GregoriusTechneticies> it determines the horizontal middle of the multiblock - [23:45:47] <GregoriusTechneticies> which is in your case THREE blocks away from the controller - [23:45:51] <Alkalus> Ahh - [23:45:57] <GregoriusTechneticies> and not 2 - [23:46:06] <Alkalus> Noted, thanks :D - */ - - @Override - public boolean isCorrectMachinePart(final ItemStack aStack) { - return true; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerTick(final ItemStack aStack) { - return 0; - } - - @Override - public int getDamageToComponent(final ItemStack aStack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return true; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMTE_NuclearReactor(this.mName); - } - - public boolean turnCasingActive(final boolean status) { - //TODO - if (this.mDynamoHatches != null) { - for (final GT_MetaTileEntity_Hatch_Dynamo hatch : this.mDynamoHatches) { - hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); - } - } - if (this.mMufflerHatches != null) { - for (final GT_MetaTileEntity_Hatch_Muffler hatch : this.mMufflerHatches) { - hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); - } - } - if (this.mOutputHatches != null) { - for (final GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { - hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); - } - } - if (this.mInputHatches != null) { - for (final GT_MetaTileEntity_Hatch_Input hatch : this.mInputHatches) { - hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); - } - } - if (this.mMaintenanceHatches != null) { - for (final GT_MetaTileEntity_Hatch_Maintenance hatch : this.mMaintenanceHatches) { - hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); - } - } - return true; - } - - public FluidStack[] getStoredFluidsAsArray() { - return getStoredFluids().toArray(new FluidStack[0]); - } - - public int getStoredFuel(GT_Recipe aRecipe) { - int aFuelStored = 0; - FluidStack aFuelFluid = null; - for (FluidStack aFluidInput : aRecipe.mFluidInputs) { - if (!aFluidInput.getFluid().equals(NUCLIDE.Li2BeF4.getFluid())) { - aFuelFluid = aFluidInput; - break; - } - } - if (aFuelFluid != null) { - for (GT_MetaTileEntity_Hatch_Input aInputHatch : this.mInputHatches) { - if (aInputHatch.getFluid() != null && aInputHatch.getFluidAmount() > 0) { - if (aInputHatch.getFluid().isFluidEqual(aFuelFluid)) { - aFuelStored += aInputHatch.getFluidAmount(); - } - } - } - } - return aFuelStored; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - // Warm up for 4~ minutes - Logger.WARNING("Checking LFTR recipes."); - if (mEfficiency < this.getMaxEfficiency(null)) { - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - this.mProgresstime = 0; - this.mMaxProgresstime = 1; - this.mEfficiencyIncrease = 2; - Logger.WARNING("Warming Up! "+this.mEfficiency+"/"+this.getMaxEfficiency(null)); - return true; - } - Logger.WARNING("Warmed up, checking LFTR recipes."); - - final FluidStack[] tFluids = getStoredFluidsAsArray(); - final Collection<GT_Recipe> tRecipeList = getRecipeMap().mRecipeList; - if(tFluids.length > 0 && tRecipeList != null && tRecipeList.size() > 0) { //Does input hatch have a LFTR fuel? - Logger.WARNING("Found more than one input fluid and a list of valid recipes."); - // Find a valid recipe - GT_Recipe aFuelProcessing = this.findRecipe(getBaseMetaTileEntity(), mLastRecipe, true, 0, tFluids, new ItemStack[] {}); - if (aFuelProcessing == null) { - Logger.WARNING("Did not find valid recipe for given inputs."); - return false; - } - else { - Logger.WARNING("Found recipe? "+(aFuelProcessing != null ? "true" : "false")); - for (FluidStack aFluidInput : aFuelProcessing.mFluidInputs) { - Logger.WARNING("Using "+aFluidInput.getLocalizedName()); - } - } - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - this.mLastRecipe = aFuelProcessing; - // Deplete Inputs - if (aFuelProcessing.mFluidInputs.length > 0) { - for (FluidStack aInputToConsume : aFuelProcessing.mFluidInputs) { - Logger.WARNING("Depleting "+aInputToConsume.getLocalizedName()+" - "+aInputToConsume.amount+"L"); - this.depleteInput(aInputToConsume); - } - } - // -- Try not to fail after this point - inputs have already been consumed! -- - this.mMaxProgresstime = (int)(aFuelProcessing.mDuration); - this.mEUt = aFuelProcessing.mSpecialValue * 4; - Logger.WARNING("Outputting "+this.mEUt+"eu/t"); - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - Logger.WARNING("Recipe time: "+this.mMaxProgresstime); - mFuelRemaining = getStoredFuel(aFuelProcessing); //Record available fuel - - this.mOutputFluids = aFuelProcessing.mFluidOutputs.clone(); - updateSlots(); - Logger.WARNING("Recipe Good!"); - return true; - } - this.mEUt = 0; - this.mEfficiency = 0; - Logger.WARNING("Recipe Bad!"); - return false; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public void explodeMultiblock() { - this.mInventory[1] = null; - long explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - for (final MetaTileEntity tTileEntity : this.mInputBusses) { - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); - } - for (final MetaTileEntity tTileEntity : this.mOutputBusses) { - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); - } - for (final MetaTileEntity tTileEntity : this.mInputHatches) { - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); - } - for (final MetaTileEntity tTileEntity : this.mOutputHatches) { - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); - } - for (final MetaTileEntity tTileEntity : this.mDynamoHatches) { - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); - } - for (final MetaTileEntity tTileEntity : this.mMufflerHatches) { - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); - } - for (final MetaTileEntity tTileEntity : this.mEnergyHatches) { - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); - } - for (final MetaTileEntity tTileEntity : this.mMaintenanceHatches) { - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); - } - explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); - this.getBaseMetaTileEntity().doExplosion(explodevalue); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.getWorld().isRemote) { - if (aBaseMetaTileEntity.isActive()){ - // Set casings active if we're warmed up. - if (this.mEfficiency == this.getMaxEfficiency(null)){ - this.turnCasingActive(true); - } - else { - this.turnCasingActive(false); - } - } - else { - this.turnCasingActive(false); - } - } - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override - public boolean onRunningTick(ItemStack aStack) { - // See if we're warmed up. - if (this.mEfficiency == this.getMaxEfficiency(null)){ - // Try output some Uranium-233 - if (MathUtils.randInt(1, 300) == 1){ - this.addOutput(ELEMENT.getInstance().URANIUM233.getFluidStack(MathUtils.randInt(1, 10))); - } - - } - return super.onRunningTick(aStack); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mFuelRemaining", this.mFuelRemaining); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - this.mFuelRemaining = aNBT.getInteger("mFuelRemaining"); - super.loadNBTData(aNBT); - } - +public class GregtechMTE_NuclearReactor extends GregtechMeta_MultiBlockBase<GregtechMTE_NuclearReactor> + implements ISurvivalConstructable { + + protected int mFuelRemaining = 0; + + private int mCasing; + private IStructureDefinition<GregtechMTE_NuclearReactor> STRUCTURE_DEFINITION = null; + + public GregtechMTE_NuclearReactor(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_NuclearReactor(final String aName) { + super(aName); + } + + @Override + public long maxEUStore() { + return (640000000L * (Math.min(16, this.mEnergyHatches.size()))) / 16L; + } + + @Override + public String getMachineType() { + return "Reactor"; + } + + @Override + public GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe_Map.sLiquidFluorineThoriumReactorRecipes; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Liquid Fluoride Thorium Reactor.") + .addInfo("Produces Heat & Energy from Radioactive Beta Decay.") + .addInfo("Outputs U233 every 10 seconds, on average") + .addInfo("Input Fluorine and Helium for bonus byproducts") + .addInfo("Input Li2BeF4 and a molten salt as fuel.") + .addInfo("LiFBeF2ThF4UF4, LiFBeF2ZrF4UF4 or LiFBeF2ZrF4U235") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(7, 4, 7, true) + .addController("Bottom Center") + .addCasingInfo("Hastelloy-N Reactor Casing", 27) + .addCasingInfo("Zeron-100 Reactor Shielding", 26) + .addInputHatch("Top or bottom layer edges", 1) + .addOutputHatch("Top or bottom layer edges", 1) + .addDynamoHatch("Top or bottom layer edges", 1) + .addMaintenanceHatch("Top or bottom layer edges", 1) + .addMufflerHatch("Top 3x3", 2) + .addStructureInfo("All dynamos must be IV or LuV tier.") + .addStructureInfo("All other hatches must be IV+ tier.") + .addStructureInfo("3x Output Hatches, 2x Input Hatches, 4x Dynamo Hatches") + .addStructureInfo("2x Maintenance Hatches, 4x Mufflers") + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public String[] getExtraInfoData() { + final String tRunning = (this.mMaxProgresstime > 0 ? "Reactor running" : "Reactor stopped"); + final String tMaintainance = + (this.getIdealStatus() == this.getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance"); + + return new String[] { + "Liquid Fluoride Thorium Reactor", + tRunning, + tMaintainance, + "Current Output: " + this.mEUt + " EU/t", + "Fuel Remaining: " + this.mFuelRemaining + " Litres", + "Current Efficiency: " + (this.mEfficiency / 5) + "%", + "Current Efficiency (Raw): " + (this.mEfficiency), + "It requires you to have 100% Efficiency." + }; + } + + @Override + public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aStack) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + boolean aWarmedUp = this.mEfficiency == this.getMaxEfficiency(null); + if (!aBaseMetaTileEntity.isActive() || !aWarmedUp) { + if (aSide == aFacing) { + if (aActive) + return new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + TextureFactory.builder() + .addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR_ACTIVE) + .extFacing() + .build() + }; + return new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + TextureFactory.builder() + .addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR) + .extFacing() + .build() + }; + } + return new ITexture[] {Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12))}; + } else if (aBaseMetaTileEntity.isActive() && aWarmedUp) { + if (aSide == aFacing) { + if (aActive) + return new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13)), + TextureFactory.builder() + .addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR_ACTIVE) + .extFacing() + .build() + }; + return new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13)), + TextureFactory.builder() + .addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR) + .extFacing() + .build() + }; + } + return new ITexture[] {Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13))}; + } + return new ITexture[] {Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MatterFabricator"; + } + + public final boolean addNuclearReactorEdgeList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo + && (((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity).mTier >= 5 + && ((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity).mTier <= 6)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input + && ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output + && ((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addNuclearReactorTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler + && ((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public IStructureDefinition<GregtechMTE_NuclearReactor> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_NuclearReactor>builder() + .addShape(mName, transpose(new String[][] { + {"CCCCCCC", "COOOOOC", "COXXXOC", "COXXXOC", "COXXXOC", "COOOOOC", "CCCCCCC"}, + {"GGGGGGG", "G-----G", "G-----G", "G-----G", "G-----G", "G-----G", "GGGGGGG"}, + {"GGGGGGG", "G-----G", "G-----G", "G-----G", "G-----G", "G-----G", "GGGGGGG"}, + {"CCC~CCC", "COOOOOC", "COOOOOC", "COOOOOC", "COOOOOC", "COOOOOC", "CCCCCCC"}, + })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMTE_NuclearReactor.class) + .atLeast(Maintenance) + .casingIndex(TAE.GTPP_INDEX(12)) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_NuclearReactor.class) + .atLeast(InputHatch, OutputHatch) + .adder(GregtechMTE_NuclearReactor::addNuclearReactorEdgeList) + .hatchItemFilterAnd(t -> filterByMTETier(5, Integer.MAX_VALUE)) + .casingIndex(TAE.GTPP_INDEX(12)) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_NuclearReactor.class) + .atLeast(Dynamo) + .adder(GregtechMTE_NuclearReactor::addNuclearReactorEdgeList) + .hatchItemFilterAnd(t -> filterByMTETier(5, 6)) + .casingIndex(TAE.GTPP_INDEX(12)) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 12)))) + .addElement( + 'X', + buildHatchAdder(GregtechMTE_NuclearReactor.class) + .atLeast(Muffler) + .adder(GregtechMTE_NuclearReactor::addNuclearReactorTopList) + .hatchItemFilterAnd(t -> filterByMTETier(5, Integer.MAX_VALUE)) + .casingIndex(TAE.GTPP_INDEX(12)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 12)))) + .addElement('O', ofBlock(ModBlocks.blockCasingsMisc, 12)) + .addElement('G', ofBlock(ModBlocks.blockCasingsMisc, 13)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 3, 3, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + if (checkPiece(mName, 3, 3, 0) && mCasing >= 27) { + if (mOutputHatches.size() >= 3 + && mInputHatches.size() >= 2 + && mDynamoHatches.size() == 4 + && mMufflerHatches.size() == 4 + && mMaintenanceHatches.size() == 2) { + this.mWrench = true; + this.mScrewdriver = true; + this.mSoftHammer = true; + this.mHardHammer = true; + this.mSolderingTool = true; + this.mCrowbar = true; + this.turnCasingActive(false); + return true; + } + } + return false; + } + + // Alk's Life Lessons from Greg. + /* + [23:41:15] <GregoriusTechneticies> xdir and zdir are x2 and not x3 + [23:41:26] <GregoriusTechneticies> thats you issue + [23:44:33] <Alkalus> mmm? + [23:44:49] <Alkalus> Should they be x3? + [23:44:50] <GregoriusTechneticies> you just do a x2, what is for a 5x5 multiblock + [23:45:01] <GregoriusTechneticies> x3 is for a 7x7 one + [23:45:06] <Alkalus> I have no idea what that value does, tbh.. + [23:45:15] <GregoriusTechneticies> its the offset + [23:45:23] <Alkalus> Debugging checkMachine has been a pain and I usually trash designs that don't work straight up.. + [23:45:28] <GregoriusTechneticies> it determines the horizontal middle of the multiblock + [23:45:47] <GregoriusTechneticies> which is in your case THREE blocks away from the controller + [23:45:51] <Alkalus> Ahh + [23:45:57] <GregoriusTechneticies> and not 2 + [23:46:06] <Alkalus> Noted, thanks :D + */ + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return true; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_NuclearReactor(this.mName); + } + + public boolean turnCasingActive(final boolean status) { + // TODO + if (this.mDynamoHatches != null) { + for (final GT_MetaTileEntity_Hatch_Dynamo hatch : this.mDynamoHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + if (this.mMufflerHatches != null) { + for (final GT_MetaTileEntity_Hatch_Muffler hatch : this.mMufflerHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch : this.mInputHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + if (this.mMaintenanceHatches != null) { + for (final GT_MetaTileEntity_Hatch_Maintenance hatch : this.mMaintenanceHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + return true; + } + + public FluidStack[] getStoredFluidsAsArray() { + return getStoredFluids().toArray(new FluidStack[0]); + } + + public int getStoredFuel(GT_Recipe aRecipe) { + int aFuelStored = 0; + FluidStack aFuelFluid = null; + for (FluidStack aFluidInput : aRecipe.mFluidInputs) { + if (!aFluidInput.getFluid().equals(NUCLIDE.Li2BeF4.getFluid())) { + aFuelFluid = aFluidInput; + break; + } + } + if (aFuelFluid != null) { + for (GT_MetaTileEntity_Hatch_Input aInputHatch : this.mInputHatches) { + if (aInputHatch.getFluid() != null && aInputHatch.getFluidAmount() > 0) { + if (aInputHatch.getFluid().isFluidEqual(aFuelFluid)) { + aFuelStored += aInputHatch.getFluidAmount(); + } + } + } + } + return aFuelStored; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + // Warm up for 4~ minutes + Logger.WARNING("Checking LFTR recipes."); + if (mEfficiency < this.getMaxEfficiency(null)) { + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + this.mProgresstime = 0; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 2; + Logger.WARNING("Warming Up! " + this.mEfficiency + "/" + this.getMaxEfficiency(null)); + return true; + } + Logger.WARNING("Warmed up, checking LFTR recipes."); + + final FluidStack[] tFluids = getStoredFluidsAsArray(); + final Collection<GT_Recipe> tRecipeList = getRecipeMap().mRecipeList; + if (tFluids.length > 0 && tRecipeList != null && tRecipeList.size() > 0) { // Does input hatch have a LFTR fuel? + Logger.WARNING("Found more than one input fluid and a list of valid recipes."); + // Find a valid recipe + GT_Recipe aFuelProcessing = + this.findRecipe(getBaseMetaTileEntity(), mLastRecipe, true, 0, tFluids, new ItemStack[] {}); + if (aFuelProcessing == null) { + Logger.WARNING("Did not find valid recipe for given inputs."); + return false; + } else { + Logger.WARNING("Found recipe? " + (aFuelProcessing != null ? "true" : "false")); + for (FluidStack aFluidInput : aFuelProcessing.mFluidInputs) { + Logger.WARNING("Using " + aFluidInput.getLocalizedName()); + } + } + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + this.mLastRecipe = aFuelProcessing; + // Deplete Inputs + if (aFuelProcessing.mFluidInputs.length > 0) { + for (FluidStack aInputToConsume : aFuelProcessing.mFluidInputs) { + Logger.WARNING( + "Depleting " + aInputToConsume.getLocalizedName() + " - " + aInputToConsume.amount + "L"); + this.depleteInput(aInputToConsume); + } + } + // -- Try not to fail after this point - inputs have already been consumed! -- + this.mMaxProgresstime = (int) (aFuelProcessing.mDuration); + this.mEUt = aFuelProcessing.mSpecialValue * 4; + Logger.WARNING("Outputting " + this.mEUt + "eu/t"); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + Logger.WARNING("Recipe time: " + this.mMaxProgresstime); + mFuelRemaining = getStoredFuel(aFuelProcessing); // Record available fuel + + this.mOutputFluids = aFuelProcessing.mFluidOutputs.clone(); + updateSlots(); + Logger.WARNING("Recipe Good!"); + return true; + } + this.mEUt = 0; + this.mEfficiency = 0; + Logger.WARNING("Recipe Bad!"); + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void explodeMultiblock() { + this.mInventory[1] = null; + long explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + for (final MetaTileEntity tTileEntity : this.mInputBusses) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mOutputBusses) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mInputHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mOutputHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mDynamoHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mMufflerHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mEnergyHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mMaintenanceHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + this.getBaseMetaTileEntity().doExplosion(explodevalue); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.getWorld().isRemote) { + if (aBaseMetaTileEntity.isActive()) { + // Set casings active if we're warmed up. + if (this.mEfficiency == this.getMaxEfficiency(null)) { + this.turnCasingActive(true); + } else { + this.turnCasingActive(false); + } + } else { + this.turnCasingActive(false); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + // See if we're warmed up. + if (this.mEfficiency == this.getMaxEfficiency(null)) { + // Try output some Uranium-233 + if (MathUtils.randInt(1, 300) == 1) { + this.addOutput(ELEMENT.getInstance().URANIUM233.getFluidStack(MathUtils.randInt(1, 10))); + } + } + return super.onRunningTick(aStack); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mFuelRemaining", this.mFuelRemaining); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mFuelRemaining = aNBT.getInteger("mFuelRemaining"); + super.loadNBTData(aNBT); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityGeneratorArray.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityGeneratorArray.java index 715ef31871..281885bfd0 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityGeneratorArray.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityGeneratorArray.java @@ -1,6 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -18,487 +23,486 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.*; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; - -public class GregtechMetaTileEntityGeneratorArray extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntityGeneratorArray> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntityGeneratorArray> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntityGeneratorArray(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntityGeneratorArray(String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntityGeneratorArray(this.mName); - } - - @Override - public String getMachineType() { - return "Processing Array"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Generator Array") - .addInfo("Runs supplied generators as if placed in the world") - .addInfo("Place up to 16 Single Block GT Generators into the Controller") - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front center") - .addCasingInfo("Robust Tungstensteel Machine Casings", 10) - .addInputBus("Any casing", 1) - .addOutputBus("Any casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addDynamoHatch("Any casing", 1) - .addMaintenanceHatch("Any casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return 48; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "ProcessingArray"; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - this.mMode = getModeFromInventorySlot(this.getGUIItemStack()); - if (this.mMode == MODE_NONE) { - return null; - } - else if (this.mMode == MODE_STEAM) { - return GTPP_Recipe.GTPP_Recipe_Map.sSteamTurbineFuels; - } - else if (this.mMode == MODE_DIESEL) { - return GT_Recipe.GT_Recipe_Map.sDieselFuels; - } - else if (this.mMode == MODE_GAS) { - return GT_Recipe.GT_Recipe_Map.sTurbineFuels; - } - else if (this.mMode == MODE_SEMIFLUID) { - return GTPP_Recipe.GTPP_Recipe_Map.sSemiFluidLiquidFuels; - } - else if (this.mMode == MODE_GEOTHERMAL) { - return GTPP_Recipe.GTPP_Recipe_Map.sThermalFuels; - } - else if (this.mMode == MODE_ROCKETFUEL) { - return GTPP_Recipe.GTPP_Recipe_Map.sRocketFuels; - } - else if (this.mMode == MODE_MAGIC_A) { - return GT_Recipe.GT_Recipe_Map.sMagicFuels; - } - else if (this.mMode == MODE_PLASMA) { - return GT_Recipe.GT_Recipe_Map.sPlasmaFuels; - } - else if (this.mMode == MODE_NAQUADAH) { - return GT_Recipe.GT_Recipe_Map.sFluidNaquadahReactorFuels; - } - return null; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - if (aStack != null && aStack.getUnlocalizedName().startsWith("gt.blockmachines.")) { - return true; - } - return false; - } - - protected int fuelConsumption = 0; - protected int fuelValue = 0; - protected int fuelRemaining = 0; - protected boolean boostEu = false; - - int mMode = 0; - - private final static int MODE_STEAM = 0; - private final static int MODE_DIESEL = 1; - private final static int MODE_GAS = 2; - private final static int MODE_SEMIFLUID = 3; - private final static int MODE_GEOTHERMAL = 4; - private final static int MODE_ROCKETFUEL = 5; - private final static int MODE_MAGIC_A = 6; - private final static int MODE_MAGIC_B_DISABLED = 7; - private final static int MODE_PLASMA = 8; - private final static int MODE_NAQUADAH = 9; - private final static int MODE_NONE = 100; - - private final static int[] ID_STEAM = new int[] {962, 1120, 1121, 1122}; - private final static int[] ID_GAS = new int[] {961, 1115, 1116, 1117}; - private final static int[] ID_DIESEL = new int[] {960, 1110, 1111, 1112}; - private final static int[] ID_SEMIFLUID = new int[] {837, 838, 839}; - private final static int[] ID_GEOTHERMAL = new int[] {830, 831, 832}; - private final static int[] ID_ROCKETFUEL = new int[] {793, 794, 795}; - private final static int[] ID_MAGIC_A = new int[] {1123, 1124, 1125}; - private final static int[] ID_MAGIC_B_DISABLED = new int[] {1127, 1128, 1129, 1130}; - private final static int[] ID_PLASMA = new int[] {1196, 1197, 1198}; - private final static int[] ID_NAQUADAH = new int[] {1190, 1191, 1192}; - - private static final int getModeFromInventorySlot(ItemStack aStack) { - - if (aStack == null) { - return MODE_NONE; - } - - String aItemStackName = aStack == null ? "" : aStack.getUnlocalizedName(); - //Logger.INFO("Item Name: "+aItemStackName+" ("+aStack.getItemDamage()+")"); - if (aItemStackName.toLowerCase().contains("gt.blockmachines")) { - for (int g : ID_STEAM) { - if (aStack.getItemDamage() == g) { - return MODE_STEAM; - } - } - for (int g : ID_GAS) { - if (aStack.getItemDamage() == g) { - return MODE_GAS; - } - } - for (int g : ID_DIESEL) { - if (aStack.getItemDamage() == g) { - return MODE_DIESEL; - } - } - for (int g : ID_SEMIFLUID) { - if (aStack.getItemDamage() == g) { - return MODE_SEMIFLUID; - } - } - for (int g : ID_GEOTHERMAL) { - if (aStack.getItemDamage() == g) { - return MODE_GEOTHERMAL; - } - } - for (int g : ID_ROCKETFUEL) { - if (aStack.getItemDamage() == g) { - return MODE_ROCKETFUEL; - } - } - for (int g : ID_MAGIC_A) { - if (aStack.getItemDamage() == g) { - return MODE_MAGIC_A; - } - } - for (int g : ID_PLASMA) { - if (aStack.getItemDamage() == g) { - return MODE_PLASMA; - } - } - for (int g : ID_NAQUADAH) { - if (aStack.getItemDamage() == g) { - return MODE_NAQUADAH; - } - } - } - return MODE_NONE; - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - return false; - -/** this.resetRecipeMapForAllInputHatches(); - this.mMode = getModeFromInventorySlot(aStack); - if (mMode == MODE_NONE) { - Logger.INFO("Did not find valid generator."); - return false; - } - else { - Logger.INFO("Changed Mode to "+mMode); - } - int aMulti = this.getGUIItemStack() != null ? this.getGUIItemStack().stackSize : 0; - if (aMulti > 16 || aMulti == 0) { - return false; - } - - - - ArrayList<FluidStack> tFluids = this.getStoredFluids(); - - Collection<GT_Recipe> tRecipeList = this.getRecipeMap().mRecipeList; - Logger.INFO("Got Recipe Map"); - if (tFluids.size() > 0 && tRecipeList != null) { - Logger.INFO("Found Fuels for Map."); - Iterator<FluidStack> arg3 = tFluids.iterator(); - int aCount = 0; - while (arg3.hasNext()) { - FluidStack hatchFluid1 = (FluidStack) arg3.next(); - Logger.INFO("Iterating Fluid Found "+(aCount++)+" | "+hatchFluid1.getLocalizedName()); - Iterator<GT_Recipe> arg5 = tRecipeList.iterator(); - - int Hatch = 0; - int totalFuelValue = 0; - while (arg5.hasNext()) { - Logger.INFO("Iterating Recipe "+(Hatch++)); - GT_Recipe aFuel = (GT_Recipe) arg5.next(); - FluidStack tLiquid; - boolean addedFuelOnce = false; - for (int a = 0; a < aMulti; a++) { - if ((tLiquid = GT_Utility.getFluidForFilledItem(aFuel.getRepresentativeInput(0), true)) != null - && hatchFluid1.isFluidEqual(tLiquid)) { - this.fuelConsumption = tLiquid.amount = this.boostEu - ? 4096 / aFuel.mSpecialValue - : 2048 / aFuel.mSpecialValue; - if (this.depleteInput(tLiquid)) { - Logger.INFO("Depleted Fuel"); - this.boostEu = this.depleteInput(Materials.Oxygen.getGas(2L)); - -/*if (!tFluids.contains(Materials.Lubricant.getFluid(1L))) { - Logger.INFO("No Lube."); - return false; - }*/ -/** - if (this.mRuntime % 72 == 0 || this.mRuntime == 0) { - this.depleteInput(Materials.Lubricant.getFluid(this.boostEu ? 2L : 1L)); - } - Logger.INFO("ADDING POWER"); - this.fuelRemaining = hatchFluid1.amount; - totalFuelValue++; - } - } - } - //Do things after consuming Fuel - if (totalFuelValue == aMulti) { - this.fuelValue = aFuel.mSpecialValue*aMulti; - this.mEUt = this.mEfficiency < 2000 ? 0 : aFuel.mSpecialValue*aMulti; - this.mProgresstime = aMulti; - this.mMaxProgresstime = aMulti; - this.mEfficiencyIncrease = 15*aMulti; - return true; - } - } - } - } - - this.mEUt = 0; - this.mEfficiency = 0; - return false; - **/ - } - - public static ItemStack[] clean(final ItemStack[] v) { - List<ItemStack> list = new ArrayList<ItemStack>(Arrays.asList(v)); - list.removeAll(Collections.singleton(null)); - return list.toArray(new ItemStack[list.size()]); - } - - @Override - public IStructureDefinition<GregtechMetaTileEntityGeneratorArray> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntityGeneratorArray>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntityGeneratorArray.class) - .atLeast(InputHatch, OutputHatch, InputBus, OutputBus, Maintenance, Dynamo.or(TTDynamo), Muffler) - .casingIndex(48) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(GregTech_API.sBlockCasings4, 0))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 10; - } - - @Override - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerTick(ItemStack aStack) { - return 0; - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - /** - * Code from single blocks - */ - - public void tryProcessFuelItems(IGregTechTileEntity aBaseMetaTileEntity, ItemStack a) { - if (a != null - && aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() * 20L + this.getMinimumStoredEU() - && GT_Utility.getFluidForFilledItem(a, true) == null) { - int tFuelValue; - tFuelValue = this.getFuelValue(a); - if (tFuelValue > 0) { - ItemStack tEmptyContainer1 = this.getEmptyContainer(a); - if (this.addOutput(tEmptyContainer1)) { - aBaseMetaTileEntity.increaseStoredEnergyUnits((long) tFuelValue, true); - this.depleteInput(a); - PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollutionPerTick(null)); - } - } - } - } - - public void tryProcessFuel(IGregTechTileEntity aBaseMetaTileEntity, long aTick, FluidStack mFluid) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10L == 0L) { - int tFuelValue; - if (mFluid != null) { - tFuelValue = this.getFuelValue(mFluid); - int tEmptyContainer = this.consumedFluidPerOperation(mFluid); - if (tFuelValue > 0 && tEmptyContainer > 0 && mFluid.amount > tEmptyContainer) { - long tFluidAmountToUse = Math.min((long) (mFluid.amount / tEmptyContainer), - (this.maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / (long) tFuelValue); - if (tFluidAmountToUse > 0L && aBaseMetaTileEntity - .increaseStoredEnergyUnits(tFluidAmountToUse * (long) tFuelValue, true)) { - PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollutionPerTick(null)); - mFluid.amount = (int) ((long) mFluid.amount - - tFluidAmountToUse * (long) tEmptyContainer); - } - } - } - - //Check items - } - - if (aBaseMetaTileEntity.isServerSide()) { - aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity - .getUniversalEnergyStored() >= this.maxEUOutput() + this.getMinimumStoredEU()); - } - - } - - public boolean isFluidInputAllowed(FluidStack aFluid) { - return this.getFuelValue(aFluid) > 0; - } - - - public int consumedFluidPerOperation(FluidStack aLiquid) { - return 1; - } - - public int getFuelValue(FluidStack aLiquid) { - if (aLiquid != null && this.getRecipeMap() != null) { - Collection<GT_Recipe> tRecipeList = this.getRecipeMap().mRecipeList; - if (tRecipeList != null) { - Iterator<GT_Recipe> arg3 = tRecipeList.iterator(); - - while (arg3.hasNext()) { - GT_Recipe tFuel = (GT_Recipe) arg3.next(); - FluidStack tLiquid; - if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null - && aLiquid.isFluidEqual(tLiquid)) { - return (int) ((long) tFuel.mSpecialValue * (long) this.mEfficiency - * (long) this.consumedFluidPerOperation(tLiquid) / 100L); - } - } - } - - return 0; - } else { - return 0; - } - } - - public int getFuelValue(ItemStack aStack) { - if (!GT_Utility.isStackInvalid(aStack) && this.getRecipeMap() != null) { - GT_Recipe tFuel = this.getRecipeMap().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, - (FluidStack[]) null, new ItemStack[]{aStack}); - return tFuel != null ? (int) ((long) tFuel.mSpecialValue * 1000L * (long) this.mEfficiency / 100L) : 0; - } else { - return 0; - } - } - - public ItemStack getEmptyContainer(ItemStack aStack) { - if (!GT_Utility.isStackInvalid(aStack) && this.getRecipeMap() != null) { - GT_Recipe tFuel = this.getRecipeMap().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, - (FluidStack[]) null, new ItemStack[]{aStack}); - return tFuel != null - ? GT_Utility.copy(new Object[]{tFuel.getOutput(0)}) - : GT_Utility.getContainerItem(aStack, true); - } else { - return null; - } - } -}
\ No newline at end of file +public class GregtechMetaTileEntityGeneratorArray + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntityGeneratorArray> implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntityGeneratorArray> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntityGeneratorArray(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntityGeneratorArray(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityGeneratorArray(this.mName); + } + + @Override + public String getMachineType() { + return "Processing Array"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Generator Array") + .addInfo("Runs supplied generators as if placed in the world") + .addInfo("Place up to 16 Single Block GT Generators into the Controller") + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Robust Tungstensteel Machine Casings", 10) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addDynamoHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return 48; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ProcessingArray"; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + this.mMode = getModeFromInventorySlot(this.getGUIItemStack()); + if (this.mMode == MODE_NONE) { + return null; + } else if (this.mMode == MODE_STEAM) { + return GTPP_Recipe.GTPP_Recipe_Map.sSteamTurbineFuels; + } else if (this.mMode == MODE_DIESEL) { + return GT_Recipe.GT_Recipe_Map.sDieselFuels; + } else if (this.mMode == MODE_GAS) { + return GT_Recipe.GT_Recipe_Map.sTurbineFuels; + } else if (this.mMode == MODE_SEMIFLUID) { + return GTPP_Recipe.GTPP_Recipe_Map.sSemiFluidLiquidFuels; + } else if (this.mMode == MODE_GEOTHERMAL) { + return GTPP_Recipe.GTPP_Recipe_Map.sThermalFuels; + } else if (this.mMode == MODE_ROCKETFUEL) { + return GTPP_Recipe.GTPP_Recipe_Map.sRocketFuels; + } else if (this.mMode == MODE_MAGIC_A) { + return GT_Recipe.GT_Recipe_Map.sMagicFuels; + } else if (this.mMode == MODE_PLASMA) { + return GT_Recipe.GT_Recipe_Map.sPlasmaFuels; + } else if (this.mMode == MODE_NAQUADAH) { + return GT_Recipe.GT_Recipe_Map.sFluidNaquadahReactorFuels; + } + return null; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + if (aStack != null && aStack.getUnlocalizedName().startsWith("gt.blockmachines.")) { + return true; + } + return false; + } + + protected int fuelConsumption = 0; + protected int fuelValue = 0; + protected int fuelRemaining = 0; + protected boolean boostEu = false; + + int mMode = 0; + + private static final int MODE_STEAM = 0; + private static final int MODE_DIESEL = 1; + private static final int MODE_GAS = 2; + private static final int MODE_SEMIFLUID = 3; + private static final int MODE_GEOTHERMAL = 4; + private static final int MODE_ROCKETFUEL = 5; + private static final int MODE_MAGIC_A = 6; + private static final int MODE_MAGIC_B_DISABLED = 7; + private static final int MODE_PLASMA = 8; + private static final int MODE_NAQUADAH = 9; + private static final int MODE_NONE = 100; + + private static final int[] ID_STEAM = new int[] {962, 1120, 1121, 1122}; + private static final int[] ID_GAS = new int[] {961, 1115, 1116, 1117}; + private static final int[] ID_DIESEL = new int[] {960, 1110, 1111, 1112}; + private static final int[] ID_SEMIFLUID = new int[] {837, 838, 839}; + private static final int[] ID_GEOTHERMAL = new int[] {830, 831, 832}; + private static final int[] ID_ROCKETFUEL = new int[] {793, 794, 795}; + private static final int[] ID_MAGIC_A = new int[] {1123, 1124, 1125}; + private static final int[] ID_MAGIC_B_DISABLED = new int[] {1127, 1128, 1129, 1130}; + private static final int[] ID_PLASMA = new int[] {1196, 1197, 1198}; + private static final int[] ID_NAQUADAH = new int[] {1190, 1191, 1192}; + + private static final int getModeFromInventorySlot(ItemStack aStack) { + + if (aStack == null) { + return MODE_NONE; + } + + String aItemStackName = aStack == null ? "" : aStack.getUnlocalizedName(); + // Logger.INFO("Item Name: "+aItemStackName+" ("+aStack.getItemDamage()+")"); + if (aItemStackName.toLowerCase().contains("gt.blockmachines")) { + for (int g : ID_STEAM) { + if (aStack.getItemDamage() == g) { + return MODE_STEAM; + } + } + for (int g : ID_GAS) { + if (aStack.getItemDamage() == g) { + return MODE_GAS; + } + } + for (int g : ID_DIESEL) { + if (aStack.getItemDamage() == g) { + return MODE_DIESEL; + } + } + for (int g : ID_SEMIFLUID) { + if (aStack.getItemDamage() == g) { + return MODE_SEMIFLUID; + } + } + for (int g : ID_GEOTHERMAL) { + if (aStack.getItemDamage() == g) { + return MODE_GEOTHERMAL; + } + } + for (int g : ID_ROCKETFUEL) { + if (aStack.getItemDamage() == g) { + return MODE_ROCKETFUEL; + } + } + for (int g : ID_MAGIC_A) { + if (aStack.getItemDamage() == g) { + return MODE_MAGIC_A; + } + } + for (int g : ID_PLASMA) { + if (aStack.getItemDamage() == g) { + return MODE_PLASMA; + } + } + for (int g : ID_NAQUADAH) { + if (aStack.getItemDamage() == g) { + return MODE_NAQUADAH; + } + } + } + return MODE_NONE; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + return false; + + /** this.resetRecipeMapForAllInputHatches(); + * this.mMode = getModeFromInventorySlot(aStack); + * if (mMode == MODE_NONE) { + * Logger.INFO("Did not find valid generator."); + * return false; + * } + * else { + * Logger.INFO("Changed Mode to "+mMode); + * } + * int aMulti = this.getGUIItemStack() != null ? this.getGUIItemStack().stackSize : 0; + * if (aMulti > 16 || aMulti == 0) { + * return false; + * } + * + * + * + * ArrayList<FluidStack> tFluids = this.getStoredFluids(); + * + * Collection<GT_Recipe> tRecipeList = this.getRecipeMap().mRecipeList; + * Logger.INFO("Got Recipe Map"); + * if (tFluids.size() > 0 && tRecipeList != null) { + * Logger.INFO("Found Fuels for Map."); + * Iterator<FluidStack> arg3 = tFluids.iterator(); + * int aCount = 0; + * while (arg3.hasNext()) { + * FluidStack hatchFluid1 = (FluidStack) arg3.next(); + * Logger.INFO("Iterating Fluid Found "+(aCount++)+" | "+hatchFluid1.getLocalizedName()); + * Iterator<GT_Recipe> arg5 = tRecipeList.iterator(); + * + * int Hatch = 0; + * int totalFuelValue = 0; + * while (arg5.hasNext()) { + * Logger.INFO("Iterating Recipe "+(Hatch++)); + * GT_Recipe aFuel = (GT_Recipe) arg5.next(); + * FluidStack tLiquid; + * boolean addedFuelOnce = false; + * for (int a = 0; a < aMulti; a++) { + * if ((tLiquid = GT_Utility.getFluidForFilledItem(aFuel.getRepresentativeInput(0), true)) != null + * && hatchFluid1.isFluidEqual(tLiquid)) { + * this.fuelConsumption = tLiquid.amount = this.boostEu + * ? 4096 / aFuel.mSpecialValue + * : 2048 / aFuel.mSpecialValue; + * if (this.depleteInput(tLiquid)) { + * Logger.INFO("Depleted Fuel"); + * this.boostEu = this.depleteInput(Materials.Oxygen.getGas(2L)); + * + * /*if (!tFluids.contains(Materials.Lubricant.getFluid(1L))) { + * Logger.INFO("No Lube."); + * return false; + * }*/ + /** + * if (this.mRuntime % 72 == 0 || this.mRuntime == 0) { + * this.depleteInput(Materials.Lubricant.getFluid(this.boostEu ? 2L : 1L)); + * } + * Logger.INFO("ADDING POWER"); + * this.fuelRemaining = hatchFluid1.amount; + * totalFuelValue++; + * } + * } + * } + * //Do things after consuming Fuel + * if (totalFuelValue == aMulti) { + * this.fuelValue = aFuel.mSpecialValue*aMulti; + * this.mEUt = this.mEfficiency < 2000 ? 0 : aFuel.mSpecialValue*aMulti; + * this.mProgresstime = aMulti; + * this.mMaxProgresstime = aMulti; + * this.mEfficiencyIncrease = 15*aMulti; + * return true; + * } + * } + * } + * } + * + * this.mEUt = 0; + * this.mEfficiency = 0; + * return false; + **/ + } + + public static ItemStack[] clean(final ItemStack[] v) { + List<ItemStack> list = new ArrayList<ItemStack>(Arrays.asList(v)); + list.removeAll(Collections.singleton(null)); + return list.toArray(new ItemStack[list.size()]); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntityGeneratorArray> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntityGeneratorArray>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntityGeneratorArray.class) + .atLeast( + InputHatch, + OutputHatch, + InputBus, + OutputBus, + Maintenance, + Dynamo.or(TTDynamo), + Muffler) + .casingIndex(48) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(GregTech_API.sBlockCasings4, 0)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + /** + * Code from single blocks + */ + public void tryProcessFuelItems(IGregTechTileEntity aBaseMetaTileEntity, ItemStack a) { + if (a != null + && aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() * 20L + this.getMinimumStoredEU() + && GT_Utility.getFluidForFilledItem(a, true) == null) { + int tFuelValue; + tFuelValue = this.getFuelValue(a); + if (tFuelValue > 0) { + ItemStack tEmptyContainer1 = this.getEmptyContainer(a); + if (this.addOutput(tEmptyContainer1)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits((long) tFuelValue, true); + this.depleteInput(a); + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollutionPerTick(null)); + } + } + } + } + + public void tryProcessFuel(IGregTechTileEntity aBaseMetaTileEntity, long aTick, FluidStack mFluid) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10L == 0L) { + int tFuelValue; + if (mFluid != null) { + tFuelValue = this.getFuelValue(mFluid); + int tEmptyContainer = this.consumedFluidPerOperation(mFluid); + if (tFuelValue > 0 && tEmptyContainer > 0 && mFluid.amount > tEmptyContainer) { + long tFluidAmountToUse = Math.min( + (long) (mFluid.amount / tEmptyContainer), + (this.maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / (long) tFuelValue); + if (tFluidAmountToUse > 0L + && aBaseMetaTileEntity.increaseStoredEnergyUnits( + tFluidAmountToUse * (long) tFuelValue, true)) { + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollutionPerTick(null)); + mFluid.amount = (int) ((long) mFluid.amount - tFluidAmountToUse * (long) tEmptyContainer); + } + } + } + + // Check items + } + + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() + && aBaseMetaTileEntity.getUniversalEnergyStored() + >= this.maxEUOutput() + this.getMinimumStoredEU()); + } + } + + public boolean isFluidInputAllowed(FluidStack aFluid) { + return this.getFuelValue(aFluid) > 0; + } + + public int consumedFluidPerOperation(FluidStack aLiquid) { + return 1; + } + + public int getFuelValue(FluidStack aLiquid) { + if (aLiquid != null && this.getRecipeMap() != null) { + Collection<GT_Recipe> tRecipeList = this.getRecipeMap().mRecipeList; + if (tRecipeList != null) { + Iterator<GT_Recipe> arg3 = tRecipeList.iterator(); + + while (arg3.hasNext()) { + GT_Recipe tFuel = (GT_Recipe) arg3.next(); + FluidStack tLiquid; + if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null + && aLiquid.isFluidEqual(tLiquid)) { + return (int) ((long) tFuel.mSpecialValue + * (long) this.mEfficiency + * (long) this.consumedFluidPerOperation(tLiquid) + / 100L); + } + } + } + + return 0; + } else { + return 0; + } + } + + public int getFuelValue(ItemStack aStack) { + if (!GT_Utility.isStackInvalid(aStack) && this.getRecipeMap() != null) { + GT_Recipe tFuel = this.getRecipeMap() + .findRecipe( + this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, (FluidStack[]) null, new ItemStack[] { + aStack + }); + return tFuel != null ? (int) ((long) tFuel.mSpecialValue * 1000L * (long) this.mEfficiency / 100L) : 0; + } else { + return 0; + } + } + + public ItemStack getEmptyContainer(ItemStack aStack) { + if (!GT_Utility.isStackInvalid(aStack) && this.getRecipeMap() != null) { + GT_Recipe tFuel = this.getRecipeMap() + .findRecipe( + this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, (FluidStack[]) null, new ItemStack[] { + aStack + }); + return tFuel != null + ? GT_Utility.copy(new Object[] {tFuel.getOutput(0)}) + : GT_Utility.getContainerItem(aStack, true); + } else { + return null; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java index 5c4278a198..2be790ac16 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java @@ -1,9 +1,11 @@ - package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; -import java.util.HashMap; -import javax.annotation.Nonnull; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTEnergy; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -34,502 +36,578 @@ import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.helpers.TreeFarmHelper; +import java.util.ArrayList; +import java.util.HashMap; +import javax.annotation.Nonnull; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTEnergy; - -public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntityTreeFarm> implements ISurvivalConstructable { - - public static int CASING_TEXTURE_ID; - public static String mCasingName = "Sterile Farm Casing"; -// public static TreeGenerator mTreeData; - public static HashMap<String, ItemStack> sLogCache = new HashMap<>(); - private static final int TICKS_PER_OPERATION = 100; - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntityTreeFarm> STRUCTURE_DEFINITION = null; - - private SAWTOOL mToolType; - private ItemStack mSapling; - private ItemStack mWood; - private float heightModifier = 1.0f; - private float saplingsModifier = 1.0f; - private int girthModifier = 1; - - public GregtechMetaTileEntityTreeFarm(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15); - } - - public GregtechMetaTileEntityTreeFarm(final String aName) { - super(aName); - CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15); - } - - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntityTreeFarm(this.mName); - } - - @Override - public String getMachineType() { - return "Tree Farm"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Converts EU to Logs") - .addInfo("Eu Usage: 100% | Parallel: 1") - .addInfo("Requires a Saw or Chainsaw in GUI slot") - .addInfo("Output multiplier:") - .addInfo("Saw = 1x") - .addInfo("Buzzsaw = 2x") - .addInfo("Chainsaw = 4x") - .addInfo("Add a sapling in the input bus to select wood type output") - .addInfo("Tools can also be fed to the controller via input bus") - .addInfo("The working speed is fixed for 5s") - .addInfo("Production Formula: (2 * tier^2 - 2 * tier + 5) * 5 * saw boost") - .addInfo("When fertilizer is insufficient, sapling production reduced to one-tenth") - .addInfo("Forestry saplings can get increased production") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front center") - .addCasingInfo("Sterile Farm Casing", 8) - .addInputBus("Any casing", 1) - .addOutputBus("Any casing", 1) - .addEnergyHatch("Any casing", 1) - .addMaintenanceHatch("Any casing", 1) - .addMufflerHatch("Any casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return CASING_TEXTURE_ID; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "VacuumFreezer"; - } - - @Override - public boolean isCorrectMachinePart(final ItemStack aStack) { - // is correct part && either not powered tool or have enough power - if (TreeFarmHelper.isValidForGUI(aStack) && GT_MetaGenerated_Tool.getToolDamage(aStack) < GT_MetaGenerated_Tool.getToolMaxDamage(aStack)) { - return GT_ModHandler.isElectricItem(aStack) ? GT_ModHandler.canUseElectricItem(aStack, 32) : true; - } - return false; - } - - /** - * Method used to get the boost based on the ordinal of the saw - * @param sawType type of the saw - * @return an int corresponding to the boost - */ - public int getSawBoost(SAWTOOL sawType){ - switch(sawType){ - case SAW: - return 1; - case BUZZSAW: - return 2; - case CHAINSAW: - return 4; - default: - return 1; - } - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - if (!isCorrectMachinePart(aStack) && !replaceTool()) return false; - if (!checkSapling()) return false; - - this.mToolType = TreeFarmHelper.isCorrectMachinePart(aStack); - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - - int aOutputAmount = ((2 * (tTier * tTier)) - (2 * tTier) + 5) * (TICKS_PER_OPERATION / 20) * getSawBoost(mToolType); - int aFert = hasLiquidFert(); - ItemStack[] toOutput; - - if (aFert > 0) { //Sapling - if (aFert < aOutputAmount) { - aOutputAmount /= 10; - } - int amplifiedOutputAmount = (int) (aOutputAmount * saplingsModifier); - toOutput = new ItemStack[]{ItemUtils.getSimpleStack(mSapling, amplifiedOutputAmount)}; - } else { //Log - int amplifiedOutputAmount = (int) (aOutputAmount * heightModifier * girthModifier); - toOutput = new ItemStack[]{ItemUtils.getSimpleStack(mWood, amplifiedOutputAmount)}; - } - - if (canBufferOutputs(toOutput, new FluidStack[]{}, 1) == 0) { - return false; - } - - if (aFert > 0 && aFert >= aOutputAmount) { - tryConsumeLiquidFert(aOutputAmount); - } - - this.mOutputItems = toOutput; - - this.mMaxProgresstime = TICKS_PER_OPERATION; - this.mEUt = MaterialUtils.getVoltageForTier(tTier); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.tryDamageTool(); - this.updateSlots(); - return true; - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 1, 0) && mCasing >= 8 && checkHatch(); - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntityTreeFarm> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntityTreeFarm>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"C~C", "C-C", "CCC"}, - {"CCC", "CCC", "CCC"}, - })) - .addElement('C', buildHatchAdder(GregtechMetaTileEntityTreeFarm.class) - .atLeast(InputHatch, OutputHatch, InputBus, OutputBus, Maintenance, Energy.or(TTEnergy), Muffler) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 15))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiTreeFarm; - } - - @Override - public int getDamageToComponent(final ItemStack aStack) { - return MathUtils.balance((int) (75 - ((GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).getMass()))), 5, 120); - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - private boolean tryDamageTool() { - GT_ModHandler.damageOrDechargeItem(this.mInventory[1], 1, 32, null); - return replaceTool(); - } - - public boolean replaceTool() { - ItemStack invItem = this.mInventory[1]; - if (isCorrectMachinePart(invItem)) return true; - else { - if (invItem != null) { - this.mInventory[1] = null; - this.addOutput(invItem); - } - - for (ItemStack aStack : getStoredInputs()) { - if (isCorrectMachinePart(aStack)) { - this.mInventory[1] = aStack.copy(); - this.depleteInput(aStack); - return true; - } - } - } - return false; - } - - public boolean checkSapling() { - for (ItemStack uStack : this.getStoredInputs()) { - - if (uStack != null) { - String registryName = Item.itemRegistry.getNameForObject(uStack.getItem()); - ItemStack aWood = sLogCache.get(registryName + ":" + uStack.getItemDamage()); - - if (aWood != null) { - this.heightModifier = 1.0f; - this.saplingsModifier = 1.0f; - this.girthModifier = 1; - - this.mSapling = uStack; - this.mWood = aWood; - return true; - } else { - if (registryName.equals("Forestry:sapling")) { - - ITree tree = TreeManager.treeRoot.getMember(uStack); - - this.heightModifier = Math.max(3 * (tree.getGenome().getHeight() - 1), 0) + 1; - this.saplingsModifier = Math.max(tree.getGenome().getFertility() * 20, 1); - this.girthModifier = tree.getGenome().getGirth(); - boolean fireproof = ((IAlleleBoolean) tree.getGenome().getChromosomes()[EnumTreeChromosome.FIREPROOF.ordinal()].getActiveAllele()).getValue(); - - aWood = sLogCache.get(tree.getIdent() + (fireproof ? "fireproof" : "")); - - this.mSapling = uStack; - this.mWood = aWood; - return true; - } - } - } - } - return false; - } - - public static void loadMapWoodFromSapling() { - - // galaxySpace - mapSaplingToLog("GalaxySpace:barnardaCsapling:1", GT_ModHandler.getModItem("GalaxySpace", "barnardaClog", 1)); // barnarda c - - // minecraft - mapSaplingToLog("minecraft:sapling:0", new ItemStack(Blocks.log, 1, 0)); // oak - mapSaplingToLog("minecraft:sapling:1", new ItemStack(Blocks.log, 1, 1)); // spruce - mapSaplingToLog("minecraft:sapling:2", new ItemStack(Blocks.log, 1, 2)); // birch - mapSaplingToLog("minecraft:sapling:3", new ItemStack(Blocks.log, 1, 3)); // jungle - mapSaplingToLog("minecraft:sapling:4", new ItemStack(Blocks.log2, 1, 0)); // acacia - mapSaplingToLog("minecraft:sapling:5", new ItemStack(Blocks.log2, 1, 1)); // dark oak - - - // ic2 - mapSaplingToLog("IC2:blockRubSapling:0", GT_ModHandler.getModItem("IC2", "blockRubWood", 1)); // rubber - - // natura - mapSaplingToLog("Natura:florasapling:0", GT_ModHandler.getModItem("Natura", "redwood", 1, 1)); // redwood - mapSaplingToLog("Natura:florasapling:1", GT_ModHandler.getModItem("Natura", "tree", 1, 0)); // eucalyptus - mapSaplingToLog("Natura:florasapling:2", GT_ModHandler.getModItem("Natura", "tree", 1, 3)); // hopseed - mapSaplingToLog("Natura:florasapling:3", GT_ModHandler.getModItem("Natura", "tree", 1, 1)); // sakura - mapSaplingToLog("Natura:florasapling:4", GT_ModHandler.getModItem("Natura", "tree", 1, 2)); // ghostwood - mapSaplingToLog("Natura:florasapling:5", GT_ModHandler.getModItem("Natura", "bloodwood", 1, 0)); // bloodwood - mapSaplingToLog("Natura:florasapling:6", GT_ModHandler.getModItem("Natura", "Dark Tree", 1, 0)); // darkwood - mapSaplingToLog("Natura:florasapling:7", GT_ModHandler.getModItem("Natura", "Dark Tree", 1, 1)); // fusewood - - mapSaplingToLog("Natura:Rare Sapling:0", GT_ModHandler.getModItem("Natura", "Rare Tree", 1, 0)); // maple - mapSaplingToLog("Natura:Rare Sapling:1", GT_ModHandler.getModItem("Natura", "Rare Tree", 1, 1)); // silverbell - mapSaplingToLog("Natura:Rare Sapling:2", GT_ModHandler.getModItem("Natura", "Rare Tree", 1, 2)); // amaranth - mapSaplingToLog("Natura:Rare Sapling:3", GT_ModHandler.getModItem("Natura", "Rare Tree", 1, 3)); // tigerwood - mapSaplingToLog("Natura:Rare Sapling:4", GT_ModHandler.getModItem("Natura", "willow", 1, 0)); // willow - - // BOP - mapSaplingToLog("BiomesOPlenty:colorizedSaplings:0", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 0)); // Sacred Oak - mapSaplingToLog("BiomesOPlenty:colorizedSaplings:1", GT_ModHandler.getModItem("BiomesOPlenty", "logs2", 1, 2)); // Mangrove - mapSaplingToLog("BiomesOPlenty:colorizedSaplings:2", GT_ModHandler.getModItem("BiomesOPlenty", "logs2", 1, 3)); // Palm - mapSaplingToLog("BiomesOPlenty:colorizedSaplings:3", GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 0)); // Redwood - mapSaplingToLog("BiomesOPlenty:colorizedSaplings:4", GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 1)); // Willow - mapSaplingToLog("BiomesOPlenty:colorizedSaplings:5", GT_ModHandler.getModItem("BiomesOPlenty", "logs4", 1, 0)); // Pine - mapSaplingToLog("BiomesOPlenty:colorizedSaplings:6", GT_ModHandler.getModItem("BiomesOPlenty", "logs4", 1, 3)); // Mahogany - mapSaplingToLog("BiomesOPlenty:saplings:2", GT_ModHandler.getModItem("BiomesOPlenty", "bamboo", 1, 0)); // Bamboo - mapSaplingToLog("BiomesOPlenty:saplings:3", GT_ModHandler.getModItem("BiomesOPlenty", "logs2", 1, 1)); // Magic - mapSaplingToLog("BiomesOPlenty:saplings:4", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 2)); // Dark - mapSaplingToLog("BiomesOPlenty:saplings:5", GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 2)); // Dying/Dead - mapSaplingToLog("BiomesOPlenty:saplings:6", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 3)); // Fir - mapSaplingToLog("BiomesOPlenty:saplings:7", GT_ModHandler.getModItem("BiomesOPlenty", "logs2", 1, 0)); // Ethereal - mapSaplingToLog("BiomesOPlenty:saplings:10", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 1)); // Pink Cherry - mapSaplingToLog("BiomesOPlenty:saplings:12", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 1)); // White Cherry - mapSaplingToLog("BiomesOPlenty:saplings:13", GT_ModHandler.getModItem("BiomesOPlenty", "logs4", 1, 1)); // Hellbark - mapSaplingToLog("BiomesOPlenty:saplings:14", GT_ModHandler.getModItem("BiomesOPlenty", "logs4", 1, 2)); // Jacaranda - mapSaplingToLog("minecraft:yellow_flower:0", GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 3)); // Giant Flower Stem - mapSaplingToLog("minecraft:red_flower:0", GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 3)); // Giant Flower Stem - - // Witchery - mapSaplingToLog("witchery:witchsapling:0", GT_ModHandler.getModItem("witchery", "witchlog", 1, 0)); // Rowan - mapSaplingToLog("witchery:witchsapling:1", GT_ModHandler.getModItem("witchery", "witchlog", 1, 1)); // Alder - mapSaplingToLog("witchery:witchsapling:2", GT_ModHandler.getModItem("witchery", "witchlog", 1, 2)); // Hawthorn - - - // TConstruct - mapSaplingToLog("TConstruct:slime.sapling:0", GT_ModHandler.getModItem("TConstruct", "slime.gel", 1)); // green slime blocks - - // TaintedMagic - mapSaplingToLog("TaintedMagic:BlockWarpwoodSapling:0", GT_ModHandler.getModItem("TaintedMagic", "BlockWarpwoodLog", 1)); // warpwood - - // Thaumcraft - mapSaplingToLog("Thaumcraft:blockCustomPlant:0", GT_ModHandler.getModItem("Thaumcraft", "blockMagicalLog", 1, 0)); // greatwood - mapSaplingToLog("Thaumcraft:blockCustomPlant:1", GT_ModHandler.getModItem("Thaumcraft", "blockMagicalLog", 1, 1)); // silverwood - - // gt++ - mapSaplingToLog("miscutils:blockRainforestOakSapling:0", GT_ModHandler.getModItem("miscutils", "blockRainforestOakLog", 1)); // rainforest - mapSaplingToLog("miscutils:blockPineSapling:0", GT_ModHandler.getModItem("miscutils", "blockPineLogLog", 1)); // pine - - // Harvestcraft - mapSaplingToLog("harvestcraft:pampistachioSapling:0", new ItemStack(Blocks.log, 1, 3)); // Pistachio - mapSaplingToLog("harvestcraft:pampapayaSapling:0", new ItemStack(Blocks.log, 1, 3)); // Papaya - mapSaplingToLog("harvestcraft:pammapleSapling:0", GT_ModHandler.getModItem("harvestcraft", "pamMaple", 1)); // Maple - mapSaplingToLog("harvestcraft:pamappleSapling:0", new ItemStack(Blocks.log, 1, 0)); // Apple - mapSaplingToLog("harvestcraft:pamdateSapling:0", new ItemStack(Blocks.log, 1, 3)); // Date - mapSaplingToLog("harvestcraft:pamorangeSapling:0", new ItemStack(Blocks.log, 1, 3)); // Orange - mapSaplingToLog("harvestcraft:pamdragonfruitSapling:0", new ItemStack(Blocks.log, 1, 3)); // Dragon fruit - mapSaplingToLog("harvestcraft:pamnutmegSapling:0", new ItemStack(Blocks.log, 1, 0)); // NutMeg - mapSaplingToLog("harvestcraft:pampaperbarkSapling:0", GT_ModHandler.getModItem("harvestcraft", "pamPaperbark", 1)); // Paperbark - mapSaplingToLog("harvestcraft:pammangoSapling:0", new ItemStack(Blocks.log, 1, 3)); // Mango - mapSaplingToLog("harvestcraft:pamavocadoSapling:0", new ItemStack(Blocks.log, 1, 0)); // Avocado - mapSaplingToLog("harvestcraft:pamchestnutSapling:0", new ItemStack(Blocks.log, 1, 0)); // Chestnut - mapSaplingToLog("harvestcraft:pampeppercornSapling:0", new ItemStack(Blocks.log, 1, 3)); // Peppercorn - mapSaplingToLog("harvestcraft:pampecanSapling:0", new ItemStack(Blocks.log, 1, 3)); // Pecan - mapSaplingToLog("harvestcraft:pamcashewSapling:0", new ItemStack(Blocks.log, 1, 3)); // Cashew - mapSaplingToLog("harvestcraft:pamfigSapling:0", new ItemStack(Blocks.log, 1, 3)); // Fig - mapSaplingToLog("harvestcraft:pamoliveSapling:0", new ItemStack(Blocks.log, 1, 3)); // Olive - mapSaplingToLog("harvestcraft:pamcinnamonSapling:0", GT_ModHandler.getModItem("harvestcraft", "pamCinnamon", 1)); // Cinnamon - mapSaplingToLog("harvestcraft:pampeachSapling:0", new ItemStack(Blocks.log, 1, 3)); // Peach - mapSaplingToLog("harvestcraft:pamlemonSapling:0", new ItemStack(Blocks.log, 1, 3)); // Lemon - mapSaplingToLog("harvestcraft:pamvanillabeanSapling:0", new ItemStack(Blocks.log, 1, 3)); // Vanilla - mapSaplingToLog("harvestcraft:pamalmondSapling:0", new ItemStack(Blocks.log, 1, 3)); // Almond - mapSaplingToLog("harvestcraft:pambananaSapling:0", new ItemStack(Blocks.log, 1, 3)); // Banana - mapSaplingToLog("harvestcraft:pamdurianSapling:0", new ItemStack(Blocks.log, 1, 3)); // Durian - mapSaplingToLog("harvestcraft:pamplumSapling:0", new ItemStack(Blocks.log, 1, 0)); // Plum - mapSaplingToLog("harvestcraft:pamlimeSapling:0", new ItemStack(Blocks.log, 1, 3)); // Lime - mapSaplingToLog("harvestcraft:pampearSapling:0", new ItemStack(Blocks.log, 1, 0)); // Pear - mapSaplingToLog("harvestcraft:pamgooseberrySapling:0", new ItemStack(Blocks.log, 1, 0)); // Gooseberry - mapSaplingToLog("harvestcraft:pamcherrySapling:0", new ItemStack(Blocks.log, 1, 0)); // Cherry - mapSaplingToLog("harvestcraft:pampomegranateSapling:0", new ItemStack(Blocks.log, 1, 3)); // Pomegranate - mapSaplingToLog("harvestcraft:pamwalnutSapling:0", new ItemStack(Blocks.log, 1, 0)); // Walnut - mapSaplingToLog("harvestcraft:pampersimmonSapling:0", new ItemStack(Blocks.log, 1, 3)); // Persimmon - mapSaplingToLog("harvestcraft:pamapricotSapling:0", new ItemStack(Blocks.log, 1, 3)); // Apricot - mapSaplingToLog("harvestcraft:pamcoconutSapling:0", new ItemStack(Blocks.log, 1, 3)); // Coconut - mapSaplingToLog("harvestcraft:pamgrapefruitSapling:0", new ItemStack(Blocks.log, 1, 3)); // Grapefruit - mapSaplingToLog("harvestcraft:pamstarfruitSapling:0", new ItemStack(Blocks.log, 1, 3)); // Starfruit - - // Harvest The Nether - mapSaplingToLog("harvestthenether:netherSapling:0", GT_ModHandler.getModItem("harvestthenether", "netherLog", 1)); // Nether - - // The Twilight Forest - mapSaplingToLog("TwilightForest:tile.TFSapling:0", GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 0)); // Sickly Twilight Oak - mapSaplingToLog("TwilightForest:tile.TFSapling:1", GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 1)); // Canopy Tree - mapSaplingToLog("TwilightForest:tile.TFSapling:2", GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 2)); // Twilight Mangrove - mapSaplingToLog("TwilightForest:tile.TFSapling:3", GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 3)); // Darkwood - mapSaplingToLog("TwilightForest:tile.TFSapling:4", GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 0)); // Robust Twilight Oad - mapSaplingToLog("TwilightForest:tile.TFSapling:5", GT_ModHandler.getModItem("TwilightForest", "tile.TFMagicLog", 1, 0)); // Tree of Time - mapSaplingToLog("TwilightForest:tile.TFSapling:6", GT_ModHandler.getModItem("TwilightForest", "tile.TFMagicLog", 1, 1)); // Tree of Trasformation - mapSaplingToLog("TwilightForest:tile.TFSapling:7", GT_ModHandler.getModItem("TwilightForest", "tile.TFMagicLog", 1, 2)); // Miner's Tree - mapSaplingToLog("TwilightForest:tile.TFSapling:8", GT_ModHandler.getModItem("TwilightForest", "tile.TFMagicLog", 1, 3)); // Sorting Tree - mapSaplingToLog("TwilightForest:tile.TFSapling:9", GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 0)); // Rainbow Oak - - // Thaumic Bases - mapSaplingToLog("thaumicbases:goldenOakSapling:0", new ItemStack(Blocks.log, 1, 0)); // Golden Oak - mapSaplingToLog("thaumicbases:goldenOakSapling:1", GT_ModHandler.getModItem("thaumicbases", "genLogs", 1, 0)); // Peaceful - mapSaplingToLog("thaumicbases:goldenOakSapling:2", GT_ModHandler.getModItem("thaumicbases", "genLogs", 1, 1)); // Nether - mapSaplingToLog("thaumicbases:goldenOakSapling:3", GT_ModHandler.getModItem("thaumicbases", "genLogs", 1, 2)); // Ender - - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - public static void mapSaplingToLog(String aSapling, ItemStack aLog) { - ItemStack aSaplingStack = ItemUtils.getItemStackFromFQRN(aSapling, 1); - if (aSaplingStack != null && aLog != null) { - sLogCache.put(aSapling, aLog); - addFakeRecipeToNEI(aSaplingStack, aLog); - } else { - Logger.INFO("Unable to add Tree Growth Simulation for " + aSapling); - } - } - - private static int sRecipeID = 0; - - public static boolean addFakeRecipeToNEI(@Nonnull ItemStack aSapling, ItemStack aLog) { - int aRecipes = GTPP_Recipe_Map.sTreeSimFakeRecipes.mRecipeList.size(); - Logger.INFO("Adding Tree Growth Simulation for " + aSapling.getDisplayName() + " -> " + (aLog == null ? "NULL" : aLog.getDisplayName())); - ItemStack[] aOutput = new ItemStack[]{aLog, aSapling}; - String aOutputs = ItemUtils.getArrayStackNames(aOutput); - Logger.INFO("" + aOutputs); - GTPP_Recipe_Map.sTreeSimFakeRecipes.addFakeRecipe( - false, - new ItemStack[]{aSapling.copy()}, - aOutput, - null, - new int[]{10000, 1000}, - new FluidStack[]{FluidUtils.getFluidStack(ModItems.fluidFertBasic, 1)}, - new FluidStack[]{}, - 1, - sRecipeID++, - 0); - return GTPP_Recipe_Map.sTreeSimFakeRecipes.mRecipeList.size() > aRecipes; - } - - public int hasLiquidFert() { - ArrayList<FluidStack> aFluids = this.getStoredFluids(); - for (FluidStack aFluid : aFluids) { - if (aFluid.getFluid().equals(ModItems.fluidFertBasic)) { - return aFluid.amount; - } - } - return 0; - } - - public boolean tryConsumeLiquidFert(int aFluidAmount) { - return this.depleteInput(FluidUtils.getFluidStack(ModItems.fluidFertBasic, aFluidAmount)); - } +public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntityTreeFarm> + implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + public static String mCasingName = "Sterile Farm Casing"; + // public static TreeGenerator mTreeData; + public static HashMap<String, ItemStack> sLogCache = new HashMap<>(); + private static final int TICKS_PER_OPERATION = 100; + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntityTreeFarm> STRUCTURE_DEFINITION = null; + + private SAWTOOL mToolType; + private ItemStack mSapling; + private ItemStack mWood; + private float heightModifier = 1.0f; + private float saplingsModifier = 1.0f; + private int girthModifier = 1; + + public GregtechMetaTileEntityTreeFarm(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15); + } + + public GregtechMetaTileEntityTreeFarm(final String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15); + } + + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityTreeFarm(this.mName); + } + + @Override + public String getMachineType() { + return "Tree Farm"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Converts EU to Logs") + .addInfo("Eu Usage: 100% | Parallel: 1") + .addInfo("Requires a Saw or Chainsaw in GUI slot") + .addInfo("Output multiplier:") + .addInfo("Saw = 1x") + .addInfo("Buzzsaw = 2x") + .addInfo("Chainsaw = 4x") + .addInfo("Add a sapling in the input bus to select wood type output") + .addInfo("Tools can also be fed to the controller via input bus") + .addInfo("The working speed is fixed for 5s") + .addInfo("Production Formula: (2 * tier^2 - 2 * tier + 5) * 5 * saw boost") + .addInfo("When fertilizer is insufficient, sapling production reduced to one-tenth") + .addInfo("Forestry saplings can get increased production") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Sterile Farm Casing", 8) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "VacuumFreezer"; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + // is correct part && either not powered tool or have enough power + if (TreeFarmHelper.isValidForGUI(aStack) + && GT_MetaGenerated_Tool.getToolDamage(aStack) < GT_MetaGenerated_Tool.getToolMaxDamage(aStack)) { + return GT_ModHandler.isElectricItem(aStack) ? GT_ModHandler.canUseElectricItem(aStack, 32) : true; + } + return false; + } + + /** + * Method used to get the boost based on the ordinal of the saw + * @param sawType type of the saw + * @return an int corresponding to the boost + */ + public int getSawBoost(SAWTOOL sawType) { + switch (sawType) { + case SAW: + return 1; + case BUZZSAW: + return 2; + case CHAINSAW: + return 4; + default: + return 1; + } + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + if (!isCorrectMachinePart(aStack) && !replaceTool()) return false; + if (!checkSapling()) return false; + + this.mToolType = TreeFarmHelper.isCorrectMachinePart(aStack); + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + int aOutputAmount = + ((2 * (tTier * tTier)) - (2 * tTier) + 5) * (TICKS_PER_OPERATION / 20) * getSawBoost(mToolType); + int aFert = hasLiquidFert(); + ItemStack[] toOutput; + + if (aFert > 0) { // Sapling + if (aFert < aOutputAmount) { + aOutputAmount /= 10; + } + int amplifiedOutputAmount = (int) (aOutputAmount * saplingsModifier); + toOutput = new ItemStack[] {ItemUtils.getSimpleStack(mSapling, amplifiedOutputAmount)}; + } else { // Log + int amplifiedOutputAmount = (int) (aOutputAmount * heightModifier * girthModifier); + toOutput = new ItemStack[] {ItemUtils.getSimpleStack(mWood, amplifiedOutputAmount)}; + } + + if (canBufferOutputs(toOutput, new FluidStack[] {}, 1) == 0) { + return false; + } + + if (aFert > 0 && aFert >= aOutputAmount) { + tryConsumeLiquidFert(aOutputAmount); + } + + this.mOutputItems = toOutput; + + this.mMaxProgresstime = TICKS_PER_OPERATION; + this.mEUt = MaterialUtils.getVoltageForTier(tTier); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.tryDamageTool(); + this.updateSlots(); + return true; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 8 && checkHatch(); + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntityTreeFarm> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntityTreeFarm>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntityTreeFarm.class) + .atLeast( + InputHatch, + OutputHatch, + InputBus, + OutputBus, + Maintenance, + Energy.or(TTEnergy), + Muffler) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 15)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiTreeFarm; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return MathUtils.balance( + (int) (75 - ((GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).getMass()))), 5, 120); + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private boolean tryDamageTool() { + GT_ModHandler.damageOrDechargeItem(this.mInventory[1], 1, 32, null); + return replaceTool(); + } + + public boolean replaceTool() { + ItemStack invItem = this.mInventory[1]; + if (isCorrectMachinePart(invItem)) return true; + else { + if (invItem != null) { + this.mInventory[1] = null; + this.addOutput(invItem); + } + + for (ItemStack aStack : getStoredInputs()) { + if (isCorrectMachinePart(aStack)) { + this.mInventory[1] = aStack.copy(); + this.depleteInput(aStack); + return true; + } + } + } + return false; + } + + public boolean checkSapling() { + for (ItemStack uStack : this.getStoredInputs()) { + + if (uStack != null) { + String registryName = Item.itemRegistry.getNameForObject(uStack.getItem()); + ItemStack aWood = sLogCache.get(registryName + ":" + uStack.getItemDamage()); + + if (aWood != null) { + this.heightModifier = 1.0f; + this.saplingsModifier = 1.0f; + this.girthModifier = 1; + + this.mSapling = uStack; + this.mWood = aWood; + return true; + } else { + if (registryName.equals("Forestry:sapling")) { + + ITree tree = TreeManager.treeRoot.getMember(uStack); + + this.heightModifier = Math.max(3 * (tree.getGenome().getHeight() - 1), 0) + 1; + this.saplingsModifier = Math.max(tree.getGenome().getFertility() * 20, 1); + this.girthModifier = tree.getGenome().getGirth(); + boolean fireproof = ((IAlleleBoolean) tree.getGenome() + .getChromosomes()[EnumTreeChromosome.FIREPROOF.ordinal()] + .getActiveAllele()) + .getValue(); + + aWood = sLogCache.get(tree.getIdent() + (fireproof ? "fireproof" : "")); + + this.mSapling = uStack; + this.mWood = aWood; + return true; + } + } + } + } + return false; + } + + public static void loadMapWoodFromSapling() { + + // galaxySpace + mapSaplingToLog( + "GalaxySpace:barnardaCsapling:1", + GT_ModHandler.getModItem("GalaxySpace", "barnardaClog", 1)); // barnarda c + + // minecraft + mapSaplingToLog("minecraft:sapling:0", new ItemStack(Blocks.log, 1, 0)); // oak + mapSaplingToLog("minecraft:sapling:1", new ItemStack(Blocks.log, 1, 1)); // spruce + mapSaplingToLog("minecraft:sapling:2", new ItemStack(Blocks.log, 1, 2)); // birch + mapSaplingToLog("minecraft:sapling:3", new ItemStack(Blocks.log, 1, 3)); // jungle + mapSaplingToLog("minecraft:sapling:4", new ItemStack(Blocks.log2, 1, 0)); // acacia + mapSaplingToLog("minecraft:sapling:5", new ItemStack(Blocks.log2, 1, 1)); // dark oak + + // ic2 + mapSaplingToLog("IC2:blockRubSapling:0", GT_ModHandler.getModItem("IC2", "blockRubWood", 1)); // rubber + + // natura + mapSaplingToLog("Natura:florasapling:0", GT_ModHandler.getModItem("Natura", "redwood", 1, 1)); // redwood + mapSaplingToLog("Natura:florasapling:1", GT_ModHandler.getModItem("Natura", "tree", 1, 0)); // eucalyptus + mapSaplingToLog("Natura:florasapling:2", GT_ModHandler.getModItem("Natura", "tree", 1, 3)); // hopseed + mapSaplingToLog("Natura:florasapling:3", GT_ModHandler.getModItem("Natura", "tree", 1, 1)); // sakura + mapSaplingToLog("Natura:florasapling:4", GT_ModHandler.getModItem("Natura", "tree", 1, 2)); // ghostwood + mapSaplingToLog("Natura:florasapling:5", GT_ModHandler.getModItem("Natura", "bloodwood", 1, 0)); // bloodwood + mapSaplingToLog("Natura:florasapling:6", GT_ModHandler.getModItem("Natura", "Dark Tree", 1, 0)); // darkwood + mapSaplingToLog("Natura:florasapling:7", GT_ModHandler.getModItem("Natura", "Dark Tree", 1, 1)); // fusewood + + mapSaplingToLog("Natura:Rare Sapling:0", GT_ModHandler.getModItem("Natura", "Rare Tree", 1, 0)); // maple + mapSaplingToLog("Natura:Rare Sapling:1", GT_ModHandler.getModItem("Natura", "Rare Tree", 1, 1)); // silverbell + mapSaplingToLog("Natura:Rare Sapling:2", GT_ModHandler.getModItem("Natura", "Rare Tree", 1, 2)); // amaranth + mapSaplingToLog("Natura:Rare Sapling:3", GT_ModHandler.getModItem("Natura", "Rare Tree", 1, 3)); // tigerwood + mapSaplingToLog("Natura:Rare Sapling:4", GT_ModHandler.getModItem("Natura", "willow", 1, 0)); // willow + + // BOP + mapSaplingToLog( + "BiomesOPlenty:colorizedSaplings:0", + GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 0)); // Sacred Oak + mapSaplingToLog( + "BiomesOPlenty:colorizedSaplings:1", + GT_ModHandler.getModItem("BiomesOPlenty", "logs2", 1, 2)); // Mangrove + mapSaplingToLog( + "BiomesOPlenty:colorizedSaplings:2", GT_ModHandler.getModItem("BiomesOPlenty", "logs2", 1, 3)); // Palm + mapSaplingToLog( + "BiomesOPlenty:colorizedSaplings:3", + GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 0)); // Redwood + mapSaplingToLog( + "BiomesOPlenty:colorizedSaplings:4", + GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 1)); // Willow + mapSaplingToLog( + "BiomesOPlenty:colorizedSaplings:5", GT_ModHandler.getModItem("BiomesOPlenty", "logs4", 1, 0)); // Pine + mapSaplingToLog( + "BiomesOPlenty:colorizedSaplings:6", + GT_ModHandler.getModItem("BiomesOPlenty", "logs4", 1, 3)); // Mahogany + mapSaplingToLog( + "BiomesOPlenty:saplings:2", GT_ModHandler.getModItem("BiomesOPlenty", "bamboo", 1, 0)); // Bamboo + mapSaplingToLog("BiomesOPlenty:saplings:3", GT_ModHandler.getModItem("BiomesOPlenty", "logs2", 1, 1)); // Magic + mapSaplingToLog("BiomesOPlenty:saplings:4", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 2)); // Dark + mapSaplingToLog( + "BiomesOPlenty:saplings:5", GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 2)); // Dying/Dead + mapSaplingToLog("BiomesOPlenty:saplings:6", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 3)); // Fir + mapSaplingToLog( + "BiomesOPlenty:saplings:7", GT_ModHandler.getModItem("BiomesOPlenty", "logs2", 1, 0)); // Ethereal + mapSaplingToLog( + "BiomesOPlenty:saplings:10", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 1)); // Pink Cherry + mapSaplingToLog( + "BiomesOPlenty:saplings:12", GT_ModHandler.getModItem("BiomesOPlenty", "logs1", 1, 1)); // White Cherry + mapSaplingToLog( + "BiomesOPlenty:saplings:13", GT_ModHandler.getModItem("BiomesOPlenty", "logs4", 1, 1)); // Hellbark + mapSaplingToLog( + "BiomesOPlenty:saplings:14", GT_ModHandler.getModItem("BiomesOPlenty", "logs4", 1, 2)); // Jacaranda + mapSaplingToLog( + "minecraft:yellow_flower:0", + GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 3)); // Giant Flower Stem + mapSaplingToLog( + "minecraft:red_flower:0", + GT_ModHandler.getModItem("BiomesOPlenty", "logs3", 1, 3)); // Giant Flower Stem + + // Witchery + mapSaplingToLog("witchery:witchsapling:0", GT_ModHandler.getModItem("witchery", "witchlog", 1, 0)); // Rowan + mapSaplingToLog("witchery:witchsapling:1", GT_ModHandler.getModItem("witchery", "witchlog", 1, 1)); // Alder + mapSaplingToLog("witchery:witchsapling:2", GT_ModHandler.getModItem("witchery", "witchlog", 1, 2)); // Hawthorn + + // TConstruct + mapSaplingToLog( + "TConstruct:slime.sapling:0", + GT_ModHandler.getModItem("TConstruct", "slime.gel", 1)); // green slime blocks + + // TaintedMagic + mapSaplingToLog( + "TaintedMagic:BlockWarpwoodSapling:0", + GT_ModHandler.getModItem("TaintedMagic", "BlockWarpwoodLog", 1)); // warpwood + + // Thaumcraft + mapSaplingToLog( + "Thaumcraft:blockCustomPlant:0", + GT_ModHandler.getModItem("Thaumcraft", "blockMagicalLog", 1, 0)); // greatwood + mapSaplingToLog( + "Thaumcraft:blockCustomPlant:1", + GT_ModHandler.getModItem("Thaumcraft", "blockMagicalLog", 1, 1)); // silverwood + + // gt++ + mapSaplingToLog( + "miscutils:blockRainforestOakSapling:0", + GT_ModHandler.getModItem("miscutils", "blockRainforestOakLog", 1)); // rainforest + mapSaplingToLog( + "miscutils:blockPineSapling:0", GT_ModHandler.getModItem("miscutils", "blockPineLogLog", 1)); // pine + + // Harvestcraft + mapSaplingToLog("harvestcraft:pampistachioSapling:0", new ItemStack(Blocks.log, 1, 3)); // Pistachio + mapSaplingToLog("harvestcraft:pampapayaSapling:0", new ItemStack(Blocks.log, 1, 3)); // Papaya + mapSaplingToLog( + "harvestcraft:pammapleSapling:0", GT_ModHandler.getModItem("harvestcraft", "pamMaple", 1)); // Maple + mapSaplingToLog("harvestcraft:pamappleSapling:0", new ItemStack(Blocks.log, 1, 0)); // Apple + mapSaplingToLog("harvestcraft:pamdateSapling:0", new ItemStack(Blocks.log, 1, 3)); // Date + mapSaplingToLog("harvestcraft:pamorangeSapling:0", new ItemStack(Blocks.log, 1, 3)); // Orange + mapSaplingToLog("harvestcraft:pamdragonfruitSapling:0", new ItemStack(Blocks.log, 1, 3)); // Dragon fruit + mapSaplingToLog("harvestcraft:pamnutmegSapling:0", new ItemStack(Blocks.log, 1, 0)); // NutMeg + mapSaplingToLog( + "harvestcraft:pampaperbarkSapling:0", + GT_ModHandler.getModItem("harvestcraft", "pamPaperbark", 1)); // Paperbark + mapSaplingToLog("harvestcraft:pammangoSapling:0", new ItemStack(Blocks.log, 1, 3)); // Mango + mapSaplingToLog("harvestcraft:pamavocadoSapling:0", new ItemStack(Blocks.log, 1, 0)); // Avocado + mapSaplingToLog("harvestcraft:pamchestnutSapling:0", new ItemStack(Blocks.log, 1, 0)); // Chestnut + mapSaplingToLog("harvestcraft:pampeppercornSapling:0", new ItemStack(Blocks.log, 1, 3)); // Peppercorn + mapSaplingToLog("harvestcraft:pampecanSapling:0", new ItemStack(Blocks.log, 1, 3)); // Pecan + mapSaplingToLog("harvestcraft:pamcashewSapling:0", new ItemStack(Blocks.log, 1, 3)); // Cashew + mapSaplingToLog("harvestcraft:pamfigSapling:0", new ItemStack(Blocks.log, 1, 3)); // Fig + mapSaplingToLog("harvestcraft:pamoliveSapling:0", new ItemStack(Blocks.log, 1, 3)); // Olive + mapSaplingToLog( + "harvestcraft:pamcinnamonSapling:0", + GT_ModHandler.getModItem("harvestcraft", "pamCinnamon", 1)); // Cinnamon + mapSaplingToLog("harvestcraft:pampeachSapling:0", new ItemStack(Blocks.log, 1, 3)); // Peach + mapSaplingToLog("harvestcraft:pamlemonSapling:0", new ItemStack(Blocks.log, 1, 3)); // Lemon + mapSaplingToLog("harvestcraft:pamvanillabeanSapling:0", new ItemStack(Blocks.log, 1, 3)); // Vanilla + mapSaplingToLog("harvestcraft:pamalmondSapling:0", new ItemStack(Blocks.log, 1, 3)); // Almond + mapSaplingToLog("harvestcraft:pambananaSapling:0", new ItemStack(Blocks.log, 1, 3)); // Banana + mapSaplingToLog("harvestcraft:pamdurianSapling:0", new ItemStack(Blocks.log, 1, 3)); // Durian + mapSaplingToLog("harvestcraft:pamplumSapling:0", new ItemStack(Blocks.log, 1, 0)); // Plum + mapSaplingToLog("harvestcraft:pamlimeSapling:0", new ItemStack(Blocks.log, 1, 3)); // Lime + mapSaplingToLog("harvestcraft:pampearSapling:0", new ItemStack(Blocks.log, 1, 0)); // Pear + mapSaplingToLog("harvestcraft:pamgooseberrySapling:0", new ItemStack(Blocks.log, 1, 0)); // Gooseberry + mapSaplingToLog("harvestcraft:pamcherrySapling:0", new ItemStack(Blocks.log, 1, 0)); // Cherry + mapSaplingToLog("harvestcraft:pampomegranateSapling:0", new ItemStack(Blocks.log, 1, 3)); // Pomegranate + mapSaplingToLog("harvestcraft:pamwalnutSapling:0", new ItemStack(Blocks.log, 1, 0)); // Walnut + mapSaplingToLog("harvestcraft:pampersimmonSapling:0", new ItemStack(Blocks.log, 1, 3)); // Persimmon + mapSaplingToLog("harvestcraft:pamapricotSapling:0", new ItemStack(Blocks.log, 1, 3)); // Apricot + mapSaplingToLog("harvestcraft:pamcoconutSapling:0", new ItemStack(Blocks.log, 1, 3)); // Coconut + mapSaplingToLog("harvestcraft:pamgrapefruitSapling:0", new ItemStack(Blocks.log, 1, 3)); // Grapefruit + mapSaplingToLog("harvestcraft:pamstarfruitSapling:0", new ItemStack(Blocks.log, 1, 3)); // Starfruit + + // Harvest The Nether + mapSaplingToLog( + "harvestthenether:netherSapling:0", + GT_ModHandler.getModItem("harvestthenether", "netherLog", 1)); // Nether + + // The Twilight Forest + mapSaplingToLog( + "TwilightForest:tile.TFSapling:0", + GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 0)); // Sickly Twilight Oak + mapSaplingToLog( + "TwilightForest:tile.TFSapling:1", + GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 1)); // Canopy Tree + mapSaplingToLog( + "TwilightForest:tile.TFSapling:2", + GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 2)); // Twilight Mangrove + mapSaplingToLog( + "TwilightForest:tile.TFSapling:3", + GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 3)); // Darkwood + mapSaplingToLog( + "TwilightForest:tile.TFSapling:4", + GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 0)); // Robust Twilight Oad + mapSaplingToLog( + "TwilightForest:tile.TFSapling:5", + GT_ModHandler.getModItem("TwilightForest", "tile.TFMagicLog", 1, 0)); // Tree of Time + mapSaplingToLog( + "TwilightForest:tile.TFSapling:6", + GT_ModHandler.getModItem("TwilightForest", "tile.TFMagicLog", 1, 1)); // Tree of Trasformation + mapSaplingToLog( + "TwilightForest:tile.TFSapling:7", + GT_ModHandler.getModItem("TwilightForest", "tile.TFMagicLog", 1, 2)); // Miner's Tree + mapSaplingToLog( + "TwilightForest:tile.TFSapling:8", + GT_ModHandler.getModItem("TwilightForest", "tile.TFMagicLog", 1, 3)); // Sorting Tree + mapSaplingToLog( + "TwilightForest:tile.TFSapling:9", + GT_ModHandler.getModItem("TwilightForest", "tile.TFLog", 1, 0)); // Rainbow Oak + + // Thaumic Bases + mapSaplingToLog("thaumicbases:goldenOakSapling:0", new ItemStack(Blocks.log, 1, 0)); // Golden Oak + mapSaplingToLog( + "thaumicbases:goldenOakSapling:1", + GT_ModHandler.getModItem("thaumicbases", "genLogs", 1, 0)); // Peaceful + mapSaplingToLog( + "thaumicbases:goldenOakSapling:2", GT_ModHandler.getModItem("thaumicbases", "genLogs", 1, 1)); // Nether + mapSaplingToLog( + "thaumicbases:goldenOakSapling:3", GT_ModHandler.getModItem("thaumicbases", "genLogs", 1, 2)); // Ender + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + public static void mapSaplingToLog(String aSapling, ItemStack aLog) { + ItemStack aSaplingStack = ItemUtils.getItemStackFromFQRN(aSapling, 1); + if (aSaplingStack != null && aLog != null) { + sLogCache.put(aSapling, aLog); + addFakeRecipeToNEI(aSaplingStack, aLog); + } else { + Logger.INFO("Unable to add Tree Growth Simulation for " + aSapling); + } + } + + private static int sRecipeID = 0; + + public static boolean addFakeRecipeToNEI(@Nonnull ItemStack aSapling, ItemStack aLog) { + int aRecipes = GTPP_Recipe_Map.sTreeSimFakeRecipes.mRecipeList.size(); + Logger.INFO("Adding Tree Growth Simulation for " + aSapling.getDisplayName() + " -> " + + (aLog == null ? "NULL" : aLog.getDisplayName())); + ItemStack[] aOutput = new ItemStack[] {aLog, aSapling}; + String aOutputs = ItemUtils.getArrayStackNames(aOutput); + Logger.INFO("" + aOutputs); + GTPP_Recipe_Map.sTreeSimFakeRecipes.addFakeRecipe( + false, + new ItemStack[] {aSapling.copy()}, + aOutput, + null, + new int[] {10000, 1000}, + new FluidStack[] {FluidUtils.getFluidStack(ModItems.fluidFertBasic, 1)}, + new FluidStack[] {}, + 1, + sRecipeID++, + 0); + return GTPP_Recipe_Map.sTreeSimFakeRecipes.mRecipeList.size() > aRecipes; + } + + public int hasLiquidFert() { + ArrayList<FluidStack> aFluids = this.getStoredFluids(); + for (FluidStack aFluid : aFluids) { + if (aFluid.getFluid().equals(ModItems.fluidFertBasic)) { + return aFluid.amount; + } + } + return 0; + } + + public boolean tryConsumeLiquidFert(int aFluidAmount) { + return this.depleteInput(FluidUtils.getFluidStack(ModItems.fluidFertBasic, aFluidAmount)); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java index 8c986db704..6781f130b2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java @@ -1,7 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -24,6 +27,8 @@ import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; @@ -32,42 +37,36 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; +public class GregtechMetaTileEntity_AlloyBlastSmelter + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_AlloyBlastSmelter> + implements ISurvivalConstructable { -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_AlloyBlastSmelter extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_AlloyBlastSmelter> implements ISurvivalConstructable { - - private int mMode = 0; - private boolean isUsingControllerCircuit = false; - private boolean isBussesSeparate = false; - private static Item circuit; - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_AlloyBlastSmelter> STRUCTURE_DEFINITION = null; - + private int mMode = 0; + private boolean isUsingControllerCircuit = false; + private boolean isBussesSeparate = false; + private static Item circuit; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_AlloyBlastSmelter> STRUCTURE_DEFINITION = null; - public GregtechMetaTileEntity_AlloyBlastSmelter(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } + public GregtechMetaTileEntity_AlloyBlastSmelter(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } - public GregtechMetaTileEntity_AlloyBlastSmelter(final String aName) { - super(aName); - } + public GregtechMetaTileEntity_AlloyBlastSmelter(final String aName) { + super(aName); + } - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_AlloyBlastSmelter(this.mName); - } + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_AlloyBlastSmelter(this.mName); + } - @Override - public String getMachineType() { - return "Fluid Alloy Cooker"; - } + @Override + public String getMachineType() { + return "Fluid Alloy Cooker"; + } - @Override + @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); aNBT.setBoolean("isBussesSeparate", isBussesSeparate); @@ -79,278 +78,280 @@ public class GregtechMetaTileEntity_AlloyBlastSmelter extends GregtechMeta_Multi isBussesSeparate = aNBT.getBoolean("isBussesSeparate"); } - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Alloy Blast Smelter") - .addInfo("20% Faster than the Electric Blast Furnace") - .addInfo("Allows Complex GT++ alloys to be created") - .addInfo("Accepts only one Energy Hatch") - .addInfo("Circuit for recipe goes in the Input Bus or GUI slot") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 4, 3, true) - .addController("Bottom Center") - .addCasingInfo("Blast Smelter Casings", 10) - .addCasingInfo("Blast Smelter Heat Containment Coils", 16) - .addInputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_AlloyBlastSmelter> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_AlloyBlastSmelter>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"HHH", "H-H", "HHH"}, - {"HHH", "H-H", "HHH"}, - {"C~C", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_AlloyBlastSmelter.class) - .atLeast(InputBus, InputHatch, OutputBus, OutputHatch, Maintenance, Energy, Muffler) - .casingIndex(TAE.GTPP_INDEX(15)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 15))) - ) - .addElement( - 'H', - ofBlock( - ModBlocks.blockCasingsMisc, 14 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 3, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 1, 3, 0) && mCasing >= 10 && mEnergyHatches.size() == 1 && checkHatch(); - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(208)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(15); - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "ElectricBlastFurnace"; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe.GTPP_Recipe_Map.sAlloyBlastSmelterRecipes; - } - - @Override - public boolean isCorrectMachinePart(final ItemStack aStack) { - if (this.getBaseMetaTileEntity().isServerSide()) { - //Get Controller Circuit - if (circuit == null) { - circuit = CI.getNumberedCircuit(0).getItem(); - } - if (aStack != null && aStack.getItem() == circuit) { - this.mMode = aStack.getItemDamage(); - return this.isUsingControllerCircuit = true; - } - else { - if (aStack == null) { - this.isUsingControllerCircuit = false; - return true; //Allowed empty - } - Logger.WARNING("Not circuit in GUI inputs."); - return this.isUsingControllerCircuit = false; - } - } - Logger.WARNING("No Circuit, clientside."); - return this.isUsingControllerCircuit = false; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - - if (this.getBaseMetaTileEntity().isServerSide()) { - - ArrayList<ItemStack> tInputList = null; - //Get Controller Circuit - this.isUsingControllerCircuit = isCorrectMachinePart(aStack); - - final long tVoltage = this.getMaxInputVoltage(); - final byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - ItemStack[] tInputs = null; - final FluidStack[] tFluids = getCompactedFluids(); - GT_Recipe tRecipe = null; - - if (isBussesSeparate) { - for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { - tInputList = new ArrayList<>(); - tBus.mRecipeMap = getRecipeMap(); - - if (isValidMetaTileEntity(tBus)) { - for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) { - tInputList.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); - } - } - } - tInputs = tInputList.toArray(new ItemStack[0]); - tRecipe = GTPP_Recipe.GTPP_Recipe_Map.sAlloyBlastSmelterRecipes.findRecipe(this.getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); - if ((tRecipe != null)) { - break; - } - } - } else { - tInputList = this.getStoredInputs(); - for (int i = 0; i < (tInputList.size() - 1); i++) { - for (int j = i + 1; j < tInputList.size(); j++) { - if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { - if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) { - tInputList.remove(j--); - } else { - tInputList.remove(i--); - break; - } - } - } - } - tInputs = tInputList.toArray(new ItemStack[0]); - tRecipe = GTPP_Recipe.GTPP_Recipe_Map.sAlloyBlastSmelterRecipes.findRecipe(this.getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); - } - - //Validity check - if ((isUsingControllerCircuit && tInputList.size() < 1) || (!isUsingControllerCircuit && tInputList.size() < 2)) { - Logger.WARNING("Not enough inputs."); - return false; - } - else if (isUsingControllerCircuit && tInputList.size() >= 1) { - tInputList.add(CI.getNumberedCircuit(this.mMode)); - } - - if (tInputList.size() > 1) { - if ((tRecipe != null) && (tRecipe.isRecipeInputEqual(true, tFluids, tInputs))) { - Logger.WARNING("Found some Valid Inputs."); - this.mEfficiency = (10000 - ((this.getIdealStatus() - this.getRepairStatus()) * 1000)); - this.mEfficiencyIncrease = 10000; - if (tRecipe.mEUt <= 16) { - this.mEUt = (tRecipe.mEUt * (1 << (tTier - 1)) * (1 << (tTier - 1))); - this.mMaxProgresstime = (tRecipe.mDuration / (1 << (tTier - 1))); - } else { - this.mEUt = tRecipe.mEUt; - this.mMaxProgresstime = tRecipe.mDuration; - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - this.mOutputFluids = new FluidStack[]{tRecipe.getFluidOutput(0)}; - List<ItemStack> tOutPutItems = new ArrayList<ItemStack>(); - for (ItemStack tOut : tRecipe.mOutputs) { - if (ItemUtils.checkForInvalidItems(tOut)) { - tOutPutItems.add(tOut); - } - } - if (tOutPutItems.size() > 0) - this.mOutputItems = tOutPutItems.toArray(new ItemStack[tOutPutItems.size()]); - this.updateSlots(); - return true; - } - } - } - Logger.WARNING("Failed to find some Valid Inputs or Clientside."); - return false; - } - - @Override - public boolean onWireCutterRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - isBussesSeparate = !isBussesSeparate; - GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.machines.separatebus") + " " + isBussesSeparate); + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Alloy Blast Smelter") + .addInfo("20% Faster than the Electric Blast Furnace") + .addInfo("Allows Complex GT++ alloys to be created") + .addInfo("Accepts only one Energy Hatch") + .addInfo("Circuit for recipe goes in the Input Bus or GUI slot") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, true) + .addController("Bottom Center") + .addCasingInfo("Blast Smelter Casings", 10) + .addCasingInfo("Blast Smelter Heat Containment Coils", 16) + .addInputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_AlloyBlastSmelter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_AlloyBlastSmelter>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_AlloyBlastSmelter.class) + .atLeast(InputBus, InputHatch, OutputBus, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(15)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 15)))) + .addElement('H', ofBlock(ModBlocks.blockCasingsMisc, 14)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 3, 0) && mCasing >= 10 && mEnergyHatches.size() == 1 && checkHatch(); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(208)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(15); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ElectricBlastFurnace"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sAlloyBlastSmelterRecipes; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + if (this.getBaseMetaTileEntity().isServerSide()) { + // Get Controller Circuit + if (circuit == null) { + circuit = CI.getNumberedCircuit(0).getItem(); + } + if (aStack != null && aStack.getItem() == circuit) { + this.mMode = aStack.getItemDamage(); + return this.isUsingControllerCircuit = true; + } else { + if (aStack == null) { + this.isUsingControllerCircuit = false; + return true; // Allowed empty + } + Logger.WARNING("Not circuit in GUI inputs."); + return this.isUsingControllerCircuit = false; + } + } + Logger.WARNING("No Circuit, clientside."); + return this.isUsingControllerCircuit = false; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + + if (this.getBaseMetaTileEntity().isServerSide()) { + + ArrayList<ItemStack> tInputList = null; + // Get Controller Circuit + this.isUsingControllerCircuit = isCorrectMachinePart(aStack); + + final long tVoltage = this.getMaxInputVoltage(); + final byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + ItemStack[] tInputs = null; + final FluidStack[] tFluids = getCompactedFluids(); + GT_Recipe tRecipe = null; + + if (isBussesSeparate) { + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + tInputList = new ArrayList<>(); + tBus.mRecipeMap = getRecipeMap(); + + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) { + tInputList.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + } + tInputs = tInputList.toArray(new ItemStack[0]); + tRecipe = GTPP_Recipe.GTPP_Recipe_Map.sAlloyBlastSmelterRecipes.findRecipe( + this.getBaseMetaTileEntity(), + false, + gregtech.api.enums.GT_Values.V[tTier], + tFluids, + tInputs); + if ((tRecipe != null)) { + break; + } + } + } else { + tInputList = this.getStoredInputs(); + for (int i = 0; i < (tInputList.size() - 1); i++) { + for (int j = i + 1; j < tInputList.size(); j++) { + if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { + if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) { + tInputList.remove(j--); + } else { + tInputList.remove(i--); + break; + } + } + } + } + tInputs = tInputList.toArray(new ItemStack[0]); + tRecipe = GTPP_Recipe.GTPP_Recipe_Map.sAlloyBlastSmelterRecipes.findRecipe( + this.getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); + } + + // Validity check + if ((isUsingControllerCircuit && tInputList.size() < 1) + || (!isUsingControllerCircuit && tInputList.size() < 2)) { + Logger.WARNING("Not enough inputs."); + return false; + } else if (isUsingControllerCircuit && tInputList.size() >= 1) { + tInputList.add(CI.getNumberedCircuit(this.mMode)); + } + + if (tInputList.size() > 1) { + if ((tRecipe != null) && (tRecipe.isRecipeInputEqual(true, tFluids, tInputs))) { + Logger.WARNING("Found some Valid Inputs."); + this.mEfficiency = (10000 - ((this.getIdealStatus() - this.getRepairStatus()) * 1000)); + this.mEfficiencyIncrease = 10000; + if (tRecipe.mEUt <= 16) { + this.mEUt = (tRecipe.mEUt * (1 << (tTier - 1)) * (1 << (tTier - 1))); + this.mMaxProgresstime = (tRecipe.mDuration / (1 << (tTier - 1))); + } else { + this.mEUt = tRecipe.mEUt; + this.mMaxProgresstime = tRecipe.mDuration; + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + this.mOutputFluids = new FluidStack[] {tRecipe.getFluidOutput(0)}; + List<ItemStack> tOutPutItems = new ArrayList<ItemStack>(); + for (ItemStack tOut : tRecipe.mOutputs) { + if (ItemUtils.checkForInvalidItems(tOut)) { + tOutPutItems.add(tOut); + } + } + if (tOutPutItems.size() > 0) + this.mOutputItems = tOutPutItems.toArray(new ItemStack[tOutPutItems.size()]); + this.updateSlots(); + return true; + } + } + } + Logger.WARNING("Failed to find some Valid Inputs or Clientside."); + return false; + } + + @Override + public boolean onWireCutterRightClick( + byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + isBussesSeparate = !isBussesSeparate; + GT_Utility.sendChatToPlayer( + aPlayer, StatCollector.translateToLocal("GT5U.machines.separatebus") + " " + isBussesSeparate); return true; } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiABS; - } - - @Override - public int getDamageToComponent(final ItemStack aStack) { - return 0; - } - - @Override - public int getAmountOfOutputs() { - return 2; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiABS; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public int getAmountOfOutputs() { + return 2; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java index 84553fb02c..ec90d8d71d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java @@ -1,6 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -22,6 +26,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -29,435 +34,411 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Cyclotron> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_Cyclotron> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_Cyclotron(int aID, String aName, String aNameRegional, int tier) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_Cyclotron(String aName) { - super(aName); - } - - @Override - public String getMachineType() { - return "Particle Accelerator"; - } - - public int tier(){ - return 5; - } - - @Override - public long maxEUStore() { - return 1800000000L; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); - //return new CONTAINER_Cyclotron(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return super.getClientGUI(aID, aPlayerInventory, aBaseMetaTileEntity); - //return new GUI_Cyclotron(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), Recipe_GT.Gregtech_Recipe_Map.sCyclotronRecipes.mNEIName); - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_Cyclotron(this.mName); - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - return aSide != getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_Cyclotron> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Cyclotron>builder() - .addShape(mName, transpose(new String[][]{ - { - " ", - " hhh ", - " hh hh ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " hh hh ", - " hhh ", - " ", - }, - { - " hhh ", - " hhccchh ", - " hcchhhcch ", - " hchh hhch ", - " hch hch ", - " hch hch ", - "hch hch", - "hch hch", - "hch hch", - " hch hch ", - " hch hch ", - " hchh hhch ", - " hcch~hcch ", - " hhccchh ", - " hhh ", - }, - { - " ", - " hhh ", - " hh hh ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " h h ", - " hh hh ", - " hhh ", - " ", - } - })) - .addElement( - 'h', - buildHatchAdder(GregtechMetaTileEntity_Cyclotron.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) - .casingIndex(44) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta()))) - ) - .addElement( - 'c', - ofBlock( - getCyclotronCoil(), getCyclotronCoilMeta() - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 7, 1, 12); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 7, 1, 12, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 7, 1, 12) && mCasing >= 40 && checkHatch(); - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings2Misc; - } - - public int getCasingMeta() { - return 10; - } - - public Block getCyclotronCoil() { - return ModBlocks.blockCasings2Misc; - } - - public int getCyclotronCoilMeta() { - return 9; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Super Magnetic Speed Shooter") - .addSeparator() - .addInfo("Particles are accelerated over 186 revolutions to 80% light speed") - .addInfo("Can produce a continuous beam current of 2.2 mA at 590 MeV") - .addInfo("Which will be extracted from the Isochronous Cyclotron") - .addSeparator() - .addInfo("Consists of the same layout as a Fusion Reactor") - .addInfo("Any external casing can be a hatch/bus, unlike Fusion") - .addInfo("Cyclotron Machine Casings around Cyclotron Coil Blocks") - .addInfo("All Hatches must be IV or better") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .addCasingInfo("Cyclotron Machine Casings", 40) - .addCasingInfo("Cyclotron Coil", 32) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return getIconOverlay(); - } - - @Override - protected IIconContainer getInactiveOverlay() { - return getIconOverlay(); - } - - @Override - protected int getCasingTextureId() { - return 44; - } - - public IIconContainer getIconOverlay() { - if (this.getBaseMetaTileEntity().isActive()){ - return TexturesGtBlock.Overlay_MatterFab_Active_Animated; - } - return TexturesGtBlock.Overlay_MatterFab_Animated; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - - /*if (CORE.DEVENV) { - return this.checkRecipeGeneric(); - }*/ - this.fixAllMaintenanceIssue(); - - //log("Recipe Check."); - ArrayList<ItemStack> tItemList = getStoredInputs(); - ItemStack[] tItemInputs = tItemList.toArray(new ItemStack[tItemList.size()]); - ArrayList<FluidStack> tInputList = getStoredFluids(); - FluidStack[] tFluidInputs = tInputList.toArray(new FluidStack[tInputList.size()]); - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - - GT_Recipe tRecipe = GTPP_Recipe.GTPP_Recipe_Map.sCyclotronRecipes.findRecipe(getBaseMetaTileEntity(), false, - gregtech.api.enums.GT_Values.V[tTier], tFluidInputs, tItemInputs); - if (tRecipe != null){ - if (tRecipe.isRecipeInputEqual(true, tFluidInputs, tItemInputs)) { - - this.mEfficiency = (10000 - ((getIdealStatus() - getRepairStatus()) * 1000)); - this.mEfficiencyIncrease = 10000; - this.mEUt = tRecipe.mEUt; - this.mMaxProgresstime = tRecipe.mDuration; - - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - final ItemStack[] outputs = new ItemStack[tRecipe.mOutputs.length]; - for (int i = 0; i < tRecipe.mOutputs.length; i++){ - if (this.getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(i)){ - Logger.WARNING("Adding a bonus output"); - outputs[i] = tRecipe.getOutput(i); - } - else { - Logger.WARNING("Adding null output"); - outputs[i] = null; - } - } - - for (ItemStack s : outputs) { - if (s != null) { - if (s.getItem() instanceof IonParticles) { - long aCharge = IonParticles.getChargeState(s); - if (aCharge == 0) { - IonParticles.setChargeState(s, MathUtils.getRandomFromArray(new int[] { - -5, -5, - -4, -4, -4, - -3, -3, -3, -3, -3, - -2, -2, -2, -2, -2, -2, -2, - -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, - 5, 5, 5, - 6, 6})); - } - } - } - } - - this.mOutputItems = outputs; - this.mOutputFluids = new FluidStack[] {tRecipe.getFluidOutput(0)}; - this.updateSlots(); - return true; - } - } - return false; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public boolean onRunningTick(ItemStack aStack) { - if (this.mOutputBusses.size() > 0) { - for (GT_MetaTileEntity_Hatch_OutputBus g : this.mOutputBusses) { - if (g != null) { - for (ItemStack s : g.mInventory) { - if (s != null) { - if (s.getItem() instanceof IonParticles) { - long aCharge = IonParticles.getChargeState(s); - if (aCharge == 0) { - IonParticles.setChargeState(s, MathUtils.getRandomFromArray(new int[] { - -5, -5, - -4, -4, -4, - -3, -3, -3, -3, -3, - -2, -2, -2, -2, -2, -2, -2, - -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, - 5, 5, 5, - 6, 6})); - } - } - } - } - } - } - } - this.fixAllMaintenanceIssue(); - return super.onRunningTick(aStack); - } - - - @Override - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiCyclotron; - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - public String[] getExtraInfoData() { - String tier = tier() == 5 ? "I" : "II"; - float plasmaOut = 0; - int powerRequired = 0; - if (this.mLastRecipe != null) { - powerRequired = this.mLastRecipe.mEUt; - if (this.mLastRecipe.getFluidOutput(0) != null) { - plasmaOut = (float)this.mLastRecipe.getFluidOutput(0).amount / (float)this.mLastRecipe.mDuration; - } - } - - return new String[]{ - "COMET - Compact Cyclotron MK "+tier, - "EU Required: "+powerRequired+"EU/t", - "Stored EU: "+this.getEUVar()+" / "+maxEUStore()}; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @SuppressWarnings("deprecation") - public boolean turnCasingActive(final boolean status) { - if (this.mEnergyHatches != null) { - for (final GT_MetaTileEntity_Hatch_Muffler hatch : this.mMufflerHatches) { - hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; - } - } - if (this.mOutputHatches != null) { - for (final GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { - hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; - } - } - if (this.mInputHatches != null) { - for (final GT_MetaTileEntity_Hatch_Input hatch : this.mInputHatches) { - hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; - } - } - if (this.mMaintenanceHatches != null) { - for (final GT_MetaTileEntity_Hatch_Maintenance hatch : this.mMaintenanceHatches) { - hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; - } - } - return true; - } -}
\ No newline at end of file +public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Cyclotron> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_Cyclotron> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Cyclotron(int aID, String aName, String aNameRegional, int tier) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Cyclotron(String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Particle Accelerator"; + } + + public int tier() { + return 5; + } + + @Override + public long maxEUStore() { + return 1800000000L; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + // return new CONTAINER_Cyclotron(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return super.getClientGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + // return new GUI_Cyclotron(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), + // Recipe_GT.Gregtech_Recipe_Map.sCyclotronRecipes.mNEIName); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Cyclotron(this.mName); + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return aSide != getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Cyclotron> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Cyclotron>builder() + .addShape(mName, transpose(new String[][] { + { + " ", + " hhh ", + " hh hh ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " hh hh ", + " hhh ", + " ", + }, + { + " hhh ", + " hhccchh ", + " hcchhhcch ", + " hchh hhch ", + " hch hch ", + " hch hch ", + "hch hch", + "hch hch", + "hch hch", + " hch hch ", + " hch hch ", + " hchh hhch ", + " hcch~hcch ", + " hhccchh ", + " hhh ", + }, + { + " ", + " hhh ", + " hh hh ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " hh hh ", + " hhh ", + " ", + } + })) + .addElement( + 'h', + buildHatchAdder(GregtechMetaTileEntity_Cyclotron.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(44) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement('c', ofBlock(getCyclotronCoil(), getCyclotronCoilMeta())) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 7, 1, 12); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 7, 1, 12, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 7, 1, 12) && mCasing >= 40 && checkHatch(); + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public int getCasingMeta() { + return 10; + } + + public Block getCyclotronCoil() { + return ModBlocks.blockCasings2Misc; + } + + public int getCyclotronCoilMeta() { + return 9; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Super Magnetic Speed Shooter") + .addSeparator() + .addInfo("Particles are accelerated over 186 revolutions to 80% light speed") + .addInfo("Can produce a continuous beam current of 2.2 mA at 590 MeV") + .addInfo("Which will be extracted from the Isochronous Cyclotron") + .addSeparator() + .addInfo("Consists of the same layout as a Fusion Reactor") + .addInfo("Any external casing can be a hatch/bus, unlike Fusion") + .addInfo("Cyclotron Machine Casings around Cyclotron Coil Blocks") + .addInfo("All Hatches must be IV or better") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addCasingInfo("Cyclotron Machine Casings", 40) + .addCasingInfo("Cyclotron Coil", 32) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return getIconOverlay(); + } + + @Override + protected IIconContainer getInactiveOverlay() { + return getIconOverlay(); + } + + @Override + protected int getCasingTextureId() { + return 44; + } + + public IIconContainer getIconOverlay() { + if (this.getBaseMetaTileEntity().isActive()) { + return TexturesGtBlock.Overlay_MatterFab_Active_Animated; + } + return TexturesGtBlock.Overlay_MatterFab_Animated; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + + /*if (CORE.DEVENV) { + return this.checkRecipeGeneric(); + }*/ + this.fixAllMaintenanceIssue(); + + // log("Recipe Check."); + ArrayList<ItemStack> tItemList = getStoredInputs(); + ItemStack[] tItemInputs = tItemList.toArray(new ItemStack[tItemList.size()]); + ArrayList<FluidStack> tInputList = getStoredFluids(); + FluidStack[] tFluidInputs = tInputList.toArray(new FluidStack[tInputList.size()]); + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + GT_Recipe tRecipe = GTPP_Recipe.GTPP_Recipe_Map.sCyclotronRecipes.findRecipe( + getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluidInputs, tItemInputs); + if (tRecipe != null) { + if (tRecipe.isRecipeInputEqual(true, tFluidInputs, tItemInputs)) { + + this.mEfficiency = (10000 - ((getIdealStatus() - getRepairStatus()) * 1000)); + this.mEfficiencyIncrease = 10000; + this.mEUt = tRecipe.mEUt; + this.mMaxProgresstime = tRecipe.mDuration; + + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + final ItemStack[] outputs = new ItemStack[tRecipe.mOutputs.length]; + for (int i = 0; i < tRecipe.mOutputs.length; i++) { + if (this.getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(i)) { + Logger.WARNING("Adding a bonus output"); + outputs[i] = tRecipe.getOutput(i); + } else { + Logger.WARNING("Adding null output"); + outputs[i] = null; + } + } + + for (ItemStack s : outputs) { + if (s != null) { + if (s.getItem() instanceof IonParticles) { + long aCharge = IonParticles.getChargeState(s); + if (aCharge == 0) { + IonParticles.setChargeState(s, MathUtils.getRandomFromArray(new int[] { + -5, -5, -4, -4, -4, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, + -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6 + })); + } + } + } + } + + this.mOutputItems = outputs; + this.mOutputFluids = new FluidStack[] {tRecipe.getFluidOutput(0)}; + this.updateSlots(); + return true; + } + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.mOutputBusses.size() > 0) { + for (GT_MetaTileEntity_Hatch_OutputBus g : this.mOutputBusses) { + if (g != null) { + for (ItemStack s : g.mInventory) { + if (s != null) { + if (s.getItem() instanceof IonParticles) { + long aCharge = IonParticles.getChargeState(s); + if (aCharge == 0) { + IonParticles.setChargeState(s, MathUtils.getRandomFromArray(new int[] { + -5, -5, -4, -4, -4, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, + -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6 + })); + } + } + } + } + } + } + } + this.fixAllMaintenanceIssue(); + return super.onRunningTick(aStack); + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiCyclotron; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public String[] getExtraInfoData() { + String tier = tier() == 5 ? "I" : "II"; + float plasmaOut = 0; + int powerRequired = 0; + if (this.mLastRecipe != null) { + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; + } + } + + return new String[] { + "COMET - Compact Cyclotron MK " + tier, + "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + this.getEUVar() + " / " + maxEUStore() + }; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @SuppressWarnings("deprecation") + public boolean turnCasingActive(final boolean status) { + if (this.mEnergyHatches != null) { + for (final GT_MetaTileEntity_Hatch_Muffler hatch : this.mMufflerHatches) { + hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { + hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch : this.mInputHatches) { + hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; + } + } + if (this.mMaintenanceHatches != null) { + for (final GT_MetaTileEntity_Hatch_Maintenance hatch : this.mMaintenanceHatches) { + hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; + } + } + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java index d8ccaf13ef..5d817d587e 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java @@ -1,8 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -26,6 +29,9 @@ import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import ic2.core.init.BlocksItems; import ic2.core.init.InternalName; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; @@ -35,578 +41,601 @@ import net.minecraft.util.WeightedRandomFishable; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_IndustrialFishingPond extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialFishingPond> implements ISurvivalConstructable { - - private boolean isUsingControllerCircuit = false; - private static final Item circuit = CI.getNumberedCircuit(0).getItem(); - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialFishingPond> STRUCTURE_DEFINITION = null; - private static final Class<?> cofhWater; - - static { - cofhWater = ReflectionUtils.getClass("cofh.asmhooks.block.BlockWater"); - } - - public GregtechMetaTileEntity_IndustrialFishingPond(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialFishingPond(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialFishingPond(this.mName); - } - - @Override - public String getMachineType() { - return "Fish Trap"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Fishing Pond") - .addInfo("Can process (Tier + 1) * 2 recipes") - .addInfo("Put a numbered circuit into the input bus.") - .addInfo("Circuit 14 for Fish") - .addInfo("Circuit 15 for Junk") - .addInfo("Circuit 16 for Treasure") - .addInfo("Need to be filled with water.") - .addInfo("Will automatically fill water from input hatch.") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(9, 3, 9, true) - .addController("Front Center") - .addCasingInfo("Aquatic Casings", 64) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IAlignmentLimits getInitialAlignmentLimits() { - // fuck - return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialFishingPond> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialFishingPond>builder() - .addShape(mName, transpose(new String[][]{ - {"XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", "X X", "XXXXXXXXX"}, - {"XXXX~XXXX", "X X", "X X", "X X", "X X", "X X", "X X", "X X", "XXXXXXXXX"}, - {"XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX"}, - })) - .addElement( - 'X', - buildHatchAdder(GregtechMetaTileEntity_IndustrialFishingPond.class) - .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta()))) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 4, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 4, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 4, 1, 0) && mCasing >= 64 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER; - } - - @Override - protected int getCasingTextureId() { - return getCasingTextureIndex(); - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return null; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - if (aStack != null) { - log("Found " + aStack.getDisplayName()); - if (aStack.getItem() == circuit) { - this.isUsingControllerCircuit = true; - this.mMode = aStack.getItemDamage(); - log("Found Circuit!"); - } else { - this.isUsingControllerCircuit = false; - } - } else { - this.isUsingControllerCircuit = false; - } - if (!hasGenerateRecipes) { - log("Generating Recipes."); - generateRecipes(); - } - if (hasGenerateRecipes) { - if (!checkForWater()) { - return false; - } - - log("Trying to run recipe."); - ArrayList<ItemStack> tItems = getStoredInputs(); - ArrayList<FluidStack> tFluids = getStoredFluids(); - ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); - FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); - - if (!isUsingControllerCircuit && tItems.size() == 0) { - return false; - } - - return checkRecipeGeneric(tItemInputs, tFluidInputs, getMaxParallelRecipes(), 100, 80, 100); - } - return true; - } - - @Override - public int getMaxParallelRecipes() { - return (2 * (GT_Utility.getTier(this.getMaxInputVoltage())+1)); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialFishingPond; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings3Misc; - } - - public byte getCasingMeta() { - return 0; - } - - public int getCasingTextureIndex() { - return TAE.GTPP_INDEX(32); - } - - public boolean checkForWater() { - - // Get Facing direction - IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); - int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int mCurrentDirectionX; - int mCurrentDirectionZ; - int mOffsetX_Lower = 0; - int mOffsetX_Upper = 0; - int mOffsetZ_Lower = 0; - int mOffsetZ_Upper = 0; - - mCurrentDirectionX = 4; - mCurrentDirectionZ = 4; - - mOffsetX_Lower = -4; - mOffsetX_Upper = 4; - mOffsetZ_Lower = -4; - mOffsetZ_Upper = 4; - - // if (aBaseMetaTileEntity.fac) - - final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX - * mCurrentDirectionX; - final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ - * mCurrentDirectionZ; - - int tAmount = 0; - for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { - for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { - for (int h = 0; h < 2; h++) { - Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); - if (isNotStaticWater(tBlock, tMeta)) { - if (this.getStoredFluids() != null) { - for (FluidStack stored : this.getStoredFluids()) { - if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { - if (stored.amount >= 1000) { - // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); - stored.amount -= 1000; - Block fluidUsed = Blocks.water; - aBaseMetaTileEntity.getWorld().setBlock( - aBaseMetaTileEntity.getXCoord() + xDir + i, - aBaseMetaTileEntity.getYCoord() + h, - aBaseMetaTileEntity.getZCoord() + zDir + j, fluidUsed); - - } - } - } - } - } - tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { - ++tAmount; - // log("Found Water"); - } - } - } - } - - boolean isValidWater = tAmount >= 60; - if (isValidWater) { - log("Filled structure."); - } - else { - log("Did not fill structure."); - } - return isValidWater; - } - - private boolean isNotStaticWater(Block block, byte meta) { - return block == Blocks.air - || block == Blocks.flowing_water - || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) - || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); - } - - private static AutoMap<AutoMap<WeightedRandomFishable>> categories = new AutoMap<AutoMap<WeightedRandomFishable>>(); - private static AutoMap<WeightedRandomFishable> categoryFish = new AutoMap<WeightedRandomFishable>(); - private static AutoMap<WeightedRandomFishable> categoryJunk = new AutoMap<WeightedRandomFishable>(); - private static AutoMap<WeightedRandomFishable> categoryLoot = new AutoMap<WeightedRandomFishable>(); - private static boolean hasGenerateRecipes = false; - private int mMode = 14; - private int mMax = 8; - - private boolean generateRecipes() { - if (!hasGenerateRecipes) { - categories.put(categoryFish); - categories.put(categoryJunk); - categories.put(categoryLoot); - for (WeightedRandomFishable h : FishPondFakeRecipe.fish) { - categoryFish.put(h); - } - for (WeightedRandomFishable h : FishPondFakeRecipe.junk) { - categoryJunk.put(h); - } - for (WeightedRandomFishable h : FishPondFakeRecipe.treasure) { - categoryLoot.put(h); - } - hasGenerateRecipes = true; - return true; - } else { - return true; - } - } - - private int getCircuit(ItemStack[] t) { - if (!this.isUsingControllerCircuit) { - for (ItemStack j : t) { - if (j.getItem() == CI.getNumberedCircuit(0).getItem()) { - // Fish - if (j.getItemDamage() == 14) { - mMax = 8 + (this.getMaxParallelRecipes() - 2); - this.mMode = 14; - break; - } - // Junk - else if (j.getItemDamage() == 15) { - this.mMode = 15; - mMax = 4; - break; - } - // Loot - else if (j.getItemDamage() == 16) { - this.mMode = 16; - mMax = 4; - break; - } else { - this.mMode = 0; - mMax = 0; - break; - } - } else { - this.mMode = 0; - mMax = 0; - break; - } - } - } - return this.mMode; - } - - // reflection map - private static Map<WeightedRandomFishable, ItemStack> reflectiveFishMap = new HashMap<WeightedRandomFishable, ItemStack>(); - - private ItemStack reflectiveFish(WeightedRandomFishable y) { - if (reflectiveFishMap.containsKey(y)) { - return reflectiveFishMap.get(y); - } - ItemStack t; - try { - t = (ItemStack) ReflectionUtils.getField(WeightedRandomFishable.class, "field_150711_b").get(y); - ItemStack k = ItemUtils.getSimpleStack(t, 1); - reflectiveFishMap.put(y, k); - return t; - } catch (IllegalArgumentException | IllegalAccessException e) { - } - return null; - } - - private ItemStack[] generateLoot(int mode) { - ItemStack[] mFishOutput = new ItemStack[this.mMax]; - if (this.mMode == 14) { - for (int k = 0; k < this.mMax; k++) { - if (mFishOutput[k] == null) - for (WeightedRandomFishable g : categoryFish.values()) { - if (MathUtils.randInt(0, (65 - getMaxParallelRecipes())) <= 2) { - ItemStack t = reflectiveFish(g); - if (t != null) { - mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); - } - } - } - } - } else if (this.mMode == 15) { - for (int k = 0; k < this.mMax; k++) { - if (mFishOutput[k] == null) - for (WeightedRandomFishable g : categoryJunk.values()) { - if (MathUtils.randInt(0, 100) <= 1) { - ItemStack t = reflectiveFish(g); - if (t != null) { - mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); - } - } - } - } - } else if (this.mMode == 16) { - for (int k = 0; k < this.mMax; k++) { - if (mFishOutput[k] == null) - for (WeightedRandomFishable g : categoryLoot.values()) { - if (MathUtils.randInt(0, 1000) <= 2) { - ItemStack t = reflectiveFish(g); - if (t != null) { - mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); - } - } - } - } - } else { - mFishOutput = null; - } - return mFishOutput; - } - - @Override - public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, - long aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { - - - - //Control Core to control the Multiblocks behaviour. - int aControlCoreTier = getControlCoreTier(); - - //If no core, return false; - if (aControlCoreTier == 0 && CORE.ConfigSwitches.requireControlCores) { - log("Invalid/No Control Core"); - return false; - } - - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - //Check to see if Voltage Tier > Control Core Tier - if (tTier > aControlCoreTier && CORE.ConfigSwitches.requireControlCores) { - return false; - } - - // Based on the Processing Array. A bit overkill, but very flexible. - getCircuit(aItemInputs); - - /* - * GT_Recipe tRecipe = this.getRecipeMap().findRecipe( getBaseMetaTileEntity(), - * mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, - * aItemInputs); - */ - - ItemStack[] mFishOutput = generateLoot(this.mMode); - mFishOutput = removeNulls(mFishOutput); - GT_Recipe g = new GTPP_Recipe(true, new ItemStack[] {}, mFishOutput, null, new int[] {}, aFluidInputs, mOutputFluids, 200, 16, 0); - aMaxParallelRecipes = this.canBufferOutputs(g, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("No Space"); - return false; - } - - log("Mode: " + this.mMode + " | Is loot valid? " + (mFishOutput != null)); - - int jslot = 0; - for (ItemStack x : mFishOutput) { - if (x != null) { - log( - "Slot " + jslot + " in mFishOutput contains " + x.stackSize + "x " + x.getDisplayName() + "."); - } else { - log("Slot " + jslot + " in mFishOutput was null."); - } - jslot++; - } - - // EU discount - float tRecipeEUt = (8 * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+aMaxParallelRecipes); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - log("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(20 * tTimeFactor * 4); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - - //Only Overclock as high as the control circuit. - byte tTierOld = tTier; - tTier = CORE.ConfigSwitches.requireControlCores ? (byte) aControlCoreTier : tTierOld; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - - log("Recipe Step. [3]"); - // Collect output item types - ItemStack[] tOutputItems = mFishOutput; - - int rslot = 0; - tOutputItems = removeNulls(mFishOutput); - - for (ItemStack x : tOutputItems) { - if (x != null) { - log( - "rSlot " + rslot + " in mFishOutput contains " + x.stackSize + "x " + x.getDisplayName() + "."); - } else { - log("rSlot " + rslot + " in mFishOutput was null."); - } - rslot++; - } - - // Commit outputs - this.mOutputItems = tOutputItems; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - return true; - } - -}
\ No newline at end of file +public class GregtechMetaTileEntity_IndustrialFishingPond + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialFishingPond> + implements ISurvivalConstructable { + + private boolean isUsingControllerCircuit = false; + private static final Item circuit = CI.getNumberedCircuit(0).getItem(); + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialFishingPond> STRUCTURE_DEFINITION = null; + private static final Class<?> cofhWater; + + static { + cofhWater = ReflectionUtils.getClass("cofh.asmhooks.block.BlockWater"); + } + + public GregtechMetaTileEntity_IndustrialFishingPond(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialFishingPond(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialFishingPond(this.mName); + } + + @Override + public String getMachineType() { + return "Fish Trap"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Fishing Pond") + .addInfo("Can process (Tier + 1) * 2 recipes") + .addInfo("Put a numbered circuit into the input bus.") + .addInfo("Circuit 14 for Fish") + .addInfo("Circuit 15 for Junk") + .addInfo("Circuit 16 for Treasure") + .addInfo("Need to be filled with water.") + .addInfo("Will automatically fill water from input hatch.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(9, 3, 9, true) + .addController("Front Center") + .addCasingInfo("Aquatic Casings", 64) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // fuck + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialFishingPond> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialFishingPond>builder() + .addShape(mName, transpose(new String[][] { + { + "XXXXXXXXX", + "X X", + "X X", + "X X", + "X X", + "X X", + "X X", + "X X", + "XXXXXXXXX" + }, + { + "XXXX~XXXX", + "X X", + "X X", + "X X", + "X X", + "X X", + "X X", + "X X", + "XXXXXXXXX" + }, + { + "XXXXXXXXX", + "XXXXXXXXX", + "XXXXXXXXX", + "XXXXXXXXX", + "XXXXXXXXX", + "XXXXXXXXX", + "XXXXXXXXX", + "XXXXXXXXX", + "XXXXXXXXX" + }, + })) + .addElement( + 'X', + buildHatchAdder(GregtechMetaTileEntity_IndustrialFishingPond.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 4, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 4, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 4, 1, 0) && mCasing >= 64 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureIndex(); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + if (aStack != null) { + log("Found " + aStack.getDisplayName()); + if (aStack.getItem() == circuit) { + this.isUsingControllerCircuit = true; + this.mMode = aStack.getItemDamage(); + log("Found Circuit!"); + } else { + this.isUsingControllerCircuit = false; + } + } else { + this.isUsingControllerCircuit = false; + } + if (!hasGenerateRecipes) { + log("Generating Recipes."); + generateRecipes(); + } + if (hasGenerateRecipes) { + if (!checkForWater()) { + return false; + } + + log("Trying to run recipe."); + ArrayList<ItemStack> tItems = getStoredInputs(); + ArrayList<FluidStack> tFluids = getStoredFluids(); + ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); + FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); + + if (!isUsingControllerCircuit && tItems.size() == 0) { + return false; + } + + return checkRecipeGeneric(tItemInputs, tFluidInputs, getMaxParallelRecipes(), 100, 80, 100); + } + return true; + } + + @Override + public int getMaxParallelRecipes() { + return (2 * (GT_Utility.getTier(this.getMaxInputVoltage()) + 1)); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialFishingPond; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public int getCasingTextureIndex() { + return TAE.GTPP_INDEX(32); + } + + public boolean checkForWater() { + + // Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + mCurrentDirectionX = 4; + mCurrentDirectionZ = 4; + + mOffsetX_Lower = -4; + mOffsetX_Upper = 4; + mOffsetZ_Lower = -4; + mOffsetZ_Upper = 4; + + // if (aBaseMetaTileEntity.fac) + + final int xDir = + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * mCurrentDirectionX; + final int zDir = + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; h++) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (isNotStaticWater(tBlock, tMeta)) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = Blocks.water; + aBaseMetaTileEntity + .getWorld() + .setBlock( + aBaseMetaTileEntity.getXCoord() + xDir + i, + aBaseMetaTileEntity.getYCoord() + h, + aBaseMetaTileEntity.getZCoord() + zDir + j, + fluidUsed); + } + } + } + } + } + tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { + ++tAmount; + // log("Found Water"); + } + } + } + } + + boolean isValidWater = tAmount >= 60; + if (isValidWater) { + log("Filled structure."); + } else { + log("Did not fill structure."); + } + return isValidWater; + } + + private boolean isNotStaticWater(Block block, byte meta) { + return block == Blocks.air + || block == Blocks.flowing_water + || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) + || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); + } + + private static AutoMap<AutoMap<WeightedRandomFishable>> categories = new AutoMap<AutoMap<WeightedRandomFishable>>(); + private static AutoMap<WeightedRandomFishable> categoryFish = new AutoMap<WeightedRandomFishable>(); + private static AutoMap<WeightedRandomFishable> categoryJunk = new AutoMap<WeightedRandomFishable>(); + private static AutoMap<WeightedRandomFishable> categoryLoot = new AutoMap<WeightedRandomFishable>(); + private static boolean hasGenerateRecipes = false; + private int mMode = 14; + private int mMax = 8; + + private boolean generateRecipes() { + if (!hasGenerateRecipes) { + categories.put(categoryFish); + categories.put(categoryJunk); + categories.put(categoryLoot); + for (WeightedRandomFishable h : FishPondFakeRecipe.fish) { + categoryFish.put(h); + } + for (WeightedRandomFishable h : FishPondFakeRecipe.junk) { + categoryJunk.put(h); + } + for (WeightedRandomFishable h : FishPondFakeRecipe.treasure) { + categoryLoot.put(h); + } + hasGenerateRecipes = true; + return true; + } else { + return true; + } + } + + private int getCircuit(ItemStack[] t) { + if (!this.isUsingControllerCircuit) { + for (ItemStack j : t) { + if (j.getItem() == CI.getNumberedCircuit(0).getItem()) { + // Fish + if (j.getItemDamage() == 14) { + mMax = 8 + (this.getMaxParallelRecipes() - 2); + this.mMode = 14; + break; + } + // Junk + else if (j.getItemDamage() == 15) { + this.mMode = 15; + mMax = 4; + break; + } + // Loot + else if (j.getItemDamage() == 16) { + this.mMode = 16; + mMax = 4; + break; + } else { + this.mMode = 0; + mMax = 0; + break; + } + } else { + this.mMode = 0; + mMax = 0; + break; + } + } + } + return this.mMode; + } + + // reflection map + private static Map<WeightedRandomFishable, ItemStack> reflectiveFishMap = + new HashMap<WeightedRandomFishable, ItemStack>(); + + private ItemStack reflectiveFish(WeightedRandomFishable y) { + if (reflectiveFishMap.containsKey(y)) { + return reflectiveFishMap.get(y); + } + ItemStack t; + try { + t = (ItemStack) ReflectionUtils.getField(WeightedRandomFishable.class, "field_150711_b") + .get(y); + ItemStack k = ItemUtils.getSimpleStack(t, 1); + reflectiveFishMap.put(y, k); + return t; + } catch (IllegalArgumentException | IllegalAccessException e) { + } + return null; + } + + private ItemStack[] generateLoot(int mode) { + ItemStack[] mFishOutput = new ItemStack[this.mMax]; + if (this.mMode == 14) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) + for (WeightedRandomFishable g : categoryFish.values()) { + if (MathUtils.randInt(0, (65 - getMaxParallelRecipes())) <= 2) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else if (this.mMode == 15) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) + for (WeightedRandomFishable g : categoryJunk.values()) { + if (MathUtils.randInt(0, 100) <= 1) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else if (this.mMode == 16) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) + for (WeightedRandomFishable g : categoryLoot.values()) { + if (MathUtils.randInt(0, 1000) <= 2) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else { + mFishOutput = null; + } + return mFishOutput; + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + + // Control Core to control the Multiblocks behaviour. + int aControlCoreTier = getControlCoreTier(); + + // If no core, return false; + if (aControlCoreTier == 0 && CORE.ConfigSwitches.requireControlCores) { + log("Invalid/No Control Core"); + return false; + } + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + // Check to see if Voltage Tier > Control Core Tier + if (tTier > aControlCoreTier && CORE.ConfigSwitches.requireControlCores) { + return false; + } + + // Based on the Processing Array. A bit overkill, but very flexible. + getCircuit(aItemInputs); + + /* + * GT_Recipe tRecipe = this.getRecipeMap().findRecipe( getBaseMetaTileEntity(), + * mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, + * aItemInputs); + */ + + ItemStack[] mFishOutput = generateLoot(this.mMode); + mFishOutput = removeNulls(mFishOutput); + GT_Recipe g = new GTPP_Recipe( + true, new ItemStack[] {}, mFishOutput, null, new int[] {}, aFluidInputs, mOutputFluids, 200, 16, 0); + aMaxParallelRecipes = this.canBufferOutputs(g, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("No Space"); + return false; + } + + log("Mode: " + this.mMode + " | Is loot valid? " + (mFishOutput != null)); + + int jslot = 0; + for (ItemStack x : mFishOutput) { + if (x != null) { + log("Slot " + jslot + " in mFishOutput contains " + x.stackSize + "x " + x.getDisplayName() + "."); + } else { + log("Slot " + jslot + " in mFishOutput was null."); + } + jslot++; + } + + // EU discount + float tRecipeEUt = (8 * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + aMaxParallelRecipes); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (20 * tTimeFactor * 4); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Only Overclock as high as the control circuit. + byte tTierOld = tTier; + tTier = CORE.ConfigSwitches.requireControlCores ? (byte) aControlCoreTier : tTierOld; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + log("Recipe Step. [3]"); + // Collect output item types + ItemStack[] tOutputItems = mFishOutput; + + int rslot = 0; + tOutputItems = removeNulls(mFishOutput); + + for (ItemStack x : tOutputItems) { + if (x != null) { + log("rSlot " + rslot + " in mFishOutput contains " + x.stackSize + "x " + x.getDisplayName() + "."); + } else { + log("rSlot " + rslot + " in mFishOutput was null."); + } + rslot++; + } + + // Commit outputs + this.mOutputItems = tOutputItems; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java index ef30eacc5b..4ea9075ee5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java @@ -1,8 +1,13 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.enums.GT_Values.E; +import static gregtech.api.enums.GT_Values.RES_PATH_GUI; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -24,6 +29,9 @@ import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -31,501 +39,489 @@ import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.enums.GT_Values.E; -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_IndustrialRockBreaker extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialRockBreaker> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_IndustrialRockBreaker> STRUCTURE_DEFINITION = null; - - - public GregtechMetaTileEntity_IndustrialRockBreaker(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_IndustrialRockBreaker(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_IndustrialRockBreaker(this.mName); - } - - @Override - public String getMachineType() { - return "Rock Breaker"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Industrial Rock Breaker") - .addInfo("Speed: +200% | EU Usage: 75% | Parallel: Tier x 8") - .addInfo("Circuit goes in the GUI slot") - .addInfo("1 = cobble, 2 = stone, 3 = obsidian") - .addInfo("Supply Water/Lava") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 4, 3, true) - .addController("Bottom Center") - .addCasingInfo("Thermal Processing Casing", 9) - .addCasingInfo("Thermal Containment Casing", 16) - .addInputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_IndustrialRockBreaker> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialRockBreaker>builder() - .addShape(mName, transpose(new String[][]{ - {"CCC", "CCC", "CCC"}, - {"HHH", "H-H", "HHH"}, - {"HHH", "H-H", "HHH"}, - {"C~C", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_IndustrialRockBreaker.class) - .atLeast(InputBus, InputHatch, OutputBus, Maintenance, Energy, Muffler) - .casingIndex(TAE.GTPP_INDEX(16)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 0))) - ) - .addElement( - 'H', - ofBlock( - ModBlocks.blockCasings2Misc, 11 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 3, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - boolean aCheckPiece = checkPiece(mName, 1, 3, 0); - boolean aCasingCount = mCasing >= 9; - boolean aCheckHatch = checkHatch(); - log(""+aCheckPiece+", "+aCasingCount+", "+aCheckHatch); - return aCheckPiece && aCasingCount && aCheckHatch; - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(208); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(16); - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public boolean requiresVanillaGtGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return "ElectricBlastFurnace"; - } - - private static final GT_Recipe_Map sFakeRecipeMap = new GT_Recipe_Map(new HashSet<>(0), "gt.recipe.fakerockbreaker", "Rock Breaker", "smelting", RES_PATH_GUI + "basicmachines/E_Furnace", 1, 1, 0, 0, 1, E, 1, E, true, false); - - private static void generateRecipeMap() { - if (sRecipe_Cobblestone == null || sRecipe_SmoothStone == null || sRecipe_Redstone == null) { - generateRecipes(); - } - FluidStack[] aInputFluids = new FluidStack[] {FluidUtils.getWater(1000), FluidUtils.getLava(1000)}; - GT_Recipe aTemp = sRecipe_Cobblestone.copy(); - aTemp.mFluidInputs = aInputFluids; - sFakeRecipeMap.add(aTemp); - aTemp = sRecipe_SmoothStone.copy(); - aTemp.mFluidInputs = aInputFluids; - sFakeRecipeMap.add(aTemp); - aTemp = sRecipe_Redstone.copy(); - aTemp.mFluidInputs = aInputFluids; - sFakeRecipeMap.add(aTemp); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - if (sFakeRecipeMap.mRecipeList.isEmpty()) { - generateRecipeMap(); - } - return sFakeRecipeMap; - } - - @Override - public boolean isCorrectMachinePart(final ItemStack aStack) { - return true; - } - - private static GT_Recipe sRecipe_Cobblestone; - private static GT_Recipe sRecipe_SmoothStone; - private static GT_Recipe sRecipe_Redstone; - - private static final void generateRecipes() { - sRecipe_Cobblestone = new GTPP_Recipe( - false, - new ItemStack[] { - CI.getNumberedCircuit(1) - }, - new ItemStack[] { - ItemUtils.getSimpleStack(Blocks.cobblestone) - }, - null, - new int[] {10000}, - null, - null, - 16, - 32, - 0); - sRecipe_SmoothStone = new GTPP_Recipe( - false, - new ItemStack[] { - CI.getNumberedCircuit(2) - }, - new ItemStack[] { - ItemUtils.getSimpleStack(Blocks.stone) - }, - null, - new int[] {10000}, - null, - null, - 16, - 32, - 0); - sRecipe_Redstone = new GTPP_Recipe( - false, - new ItemStack[] { - CI.getNumberedCircuit(3), - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L) - }, - new ItemStack[] { - ItemUtils.getSimpleStack(Blocks.obsidian) - }, - null, - new int[] {10000}, - null, - null, - 128, - 32, - 0); - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - ArrayList<FluidStack> aFluids = this.getStoredFluids(); - if (!aFluids.isEmpty()) { - boolean aHasWater = false; - boolean aHasLava = false; - for (FluidStack aFluid : aFluids) { - if (aFluid.getFluid() == FluidRegistry.WATER) { - aHasWater = true; - } - else if (aFluid.getFluid() == FluidRegistry.LAVA) { - aHasLava = true; - } - } - ArrayList<ItemStack> aItems = this.getStoredInputs(); - boolean aHasRedstone = false; - if (!aItems.isEmpty()) { - for (ItemStack aItem : aItems) { - if (GT_Utility.areStacksEqual(aItem, GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L))) { - aHasRedstone = true; - break; - } - } - } - - if (!aHasWater || !aHasLava) { - log("BAD RETURN - 0-1"); - return false; - } - ItemStack aGuiCircuit = this.getGUIItemStack(); - if (aGuiCircuit == null || !ItemUtils.isControlCircuit(aGuiCircuit)) { - log("BAD RETURN - 0-2"); - return false; - } - - if (sRecipe_Cobblestone == null || sRecipe_SmoothStone == null || sRecipe_Redstone == null) { - generateRecipes(); - } - - int aCircuit = aGuiCircuit.getItemDamage(); - - GT_Recipe tRecipe = null; - switch (aCircuit) { - case 1: - tRecipe = sRecipe_Cobblestone; - break; - case 2: - tRecipe = sRecipe_SmoothStone; - break; - case 3: - if (aHasRedstone) { - tRecipe = sRecipe_Redstone; - } - break; - } - - if (tRecipe == null) { - log("BAD RETURN - 0-3"); - return false; - } - - // Based on the Processing Array. A bit overkill, but very flexible. - ItemStack[] aItemInputs = aItems.toArray(new ItemStack[aItems.size()]); - FluidStack[] aFluidInputs = new FluidStack[] {}; - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - int aMaxParallelRecipes = getMaxParallelRecipes(); - int aEUPercent = getEuDiscountForParallelism(); - int aSpeedBonusPercent = 200; - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+aMaxParallelRecipes); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tRecipeEUt: "+tRecipeEUt); - - if (aItems.size() > 0 && aCircuit == 3) { - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!this.depleteInput(tRecipe.mInputs[1])) { - break; - } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - } - else if (aCircuit >= 1 && aCircuit <= 2) { - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - } - - log("Broke at "+parallelRecipes+"."); - if (parallelRecipes == 0) { - log("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - log("GOOD RETURN - 1"); - return true; - } - - return false; - } - - @Override - public int getMaxParallelRecipes() { - return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); - } - - @Override - public int getEuDiscountForParallelism() { - return 75; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialRockBreaker; - } - - @Override - public int getDamageToComponent(final ItemStack aStack) { - return 0; - } - - @Override - public int getAmountOfOutputs() { - return 2; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public ArrayList<ItemStack> getStoredInputs() { - ArrayList<ItemStack> aInputs = super.getStoredInputs(); - if (this.hasSlotInGUI() && this.getGUIItemStack() != null) { - aInputs.add(this.getGUIItemStack()); - } - return aInputs; - } +public class GregtechMetaTileEntity_IndustrialRockBreaker + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialRockBreaker> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialRockBreaker> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialRockBreaker(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialRockBreaker(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialRockBreaker(this.mName); + } + + @Override + public String getMachineType() { + return "Rock Breaker"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Rock Breaker") + .addInfo("Speed: +200% | EU Usage: 75% | Parallel: Tier x 8") + .addInfo("Circuit goes in the GUI slot") + .addInfo("1 = cobble, 2 = stone, 3 = obsidian") + .addInfo("Supply Water/Lava") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, true) + .addController("Bottom Center") + .addCasingInfo("Thermal Processing Casing", 9) + .addCasingInfo("Thermal Containment Casing", 16) + .addInputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialRockBreaker> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialRockBreaker>builder() + .addShape(mName, transpose(new String[][] { + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialRockBreaker.class) + .atLeast(InputBus, InputHatch, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(16)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 0)))) + .addElement('H', ofBlock(ModBlocks.blockCasings2Misc, 11)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + boolean aCheckPiece = checkPiece(mName, 1, 3, 0); + boolean aCasingCount = mCasing >= 9; + boolean aCheckHatch = checkHatch(); + log("" + aCheckPiece + ", " + aCasingCount + ", " + aCheckHatch); + return aCheckPiece && aCasingCount && aCheckHatch; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(208); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(16); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ElectricBlastFurnace"; + } + + private static final GT_Recipe_Map sFakeRecipeMap = new GT_Recipe_Map( + new HashSet<>(0), + "gt.recipe.fakerockbreaker", + "Rock Breaker", + "smelting", + RES_PATH_GUI + "basicmachines/E_Furnace", + 1, + 1, + 0, + 0, + 1, + E, + 1, + E, + true, + false); + + private static void generateRecipeMap() { + if (sRecipe_Cobblestone == null || sRecipe_SmoothStone == null || sRecipe_Redstone == null) { + generateRecipes(); + } + FluidStack[] aInputFluids = new FluidStack[] {FluidUtils.getWater(1000), FluidUtils.getLava(1000)}; + GT_Recipe aTemp = sRecipe_Cobblestone.copy(); + aTemp.mFluidInputs = aInputFluids; + sFakeRecipeMap.add(aTemp); + aTemp = sRecipe_SmoothStone.copy(); + aTemp.mFluidInputs = aInputFluids; + sFakeRecipeMap.add(aTemp); + aTemp = sRecipe_Redstone.copy(); + aTemp.mFluidInputs = aInputFluids; + sFakeRecipeMap.add(aTemp); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (sFakeRecipeMap.mRecipeList.isEmpty()) { + generateRecipeMap(); + } + return sFakeRecipeMap; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + private static GT_Recipe sRecipe_Cobblestone; + private static GT_Recipe sRecipe_SmoothStone; + private static GT_Recipe sRecipe_Redstone; + + private static final void generateRecipes() { + sRecipe_Cobblestone = new GTPP_Recipe( + false, + new ItemStack[] {CI.getNumberedCircuit(1)}, + new ItemStack[] {ItemUtils.getSimpleStack(Blocks.cobblestone)}, + null, + new int[] {10000}, + null, + null, + 16, + 32, + 0); + sRecipe_SmoothStone = new GTPP_Recipe( + false, + new ItemStack[] {CI.getNumberedCircuit(2)}, + new ItemStack[] {ItemUtils.getSimpleStack(Blocks.stone)}, + null, + new int[] {10000}, + null, + null, + 16, + 32, + 0); + sRecipe_Redstone = new GTPP_Recipe( + false, + new ItemStack[] { + CI.getNumberedCircuit(3), GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L) + }, + new ItemStack[] {ItemUtils.getSimpleStack(Blocks.obsidian)}, + null, + new int[] {10000}, + null, + null, + 128, + 32, + 0); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + ArrayList<FluidStack> aFluids = this.getStoredFluids(); + if (!aFluids.isEmpty()) { + boolean aHasWater = false; + boolean aHasLava = false; + for (FluidStack aFluid : aFluids) { + if (aFluid.getFluid() == FluidRegistry.WATER) { + aHasWater = true; + } else if (aFluid.getFluid() == FluidRegistry.LAVA) { + aHasLava = true; + } + } + ArrayList<ItemStack> aItems = this.getStoredInputs(); + boolean aHasRedstone = false; + if (!aItems.isEmpty()) { + for (ItemStack aItem : aItems) { + if (GT_Utility.areStacksEqual( + aItem, GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L))) { + aHasRedstone = true; + break; + } + } + } + + if (!aHasWater || !aHasLava) { + log("BAD RETURN - 0-1"); + return false; + } + ItemStack aGuiCircuit = this.getGUIItemStack(); + if (aGuiCircuit == null || !ItemUtils.isControlCircuit(aGuiCircuit)) { + log("BAD RETURN - 0-2"); + return false; + } + + if (sRecipe_Cobblestone == null || sRecipe_SmoothStone == null || sRecipe_Redstone == null) { + generateRecipes(); + } + + int aCircuit = aGuiCircuit.getItemDamage(); + + GT_Recipe tRecipe = null; + switch (aCircuit) { + case 1: + tRecipe = sRecipe_Cobblestone; + break; + case 2: + tRecipe = sRecipe_SmoothStone; + break; + case 3: + if (aHasRedstone) { + tRecipe = sRecipe_Redstone; + } + break; + } + + if (tRecipe == null) { + log("BAD RETURN - 0-3"); + return false; + } + + // Based on the Processing Array. A bit overkill, but very flexible. + ItemStack[] aItemInputs = aItems.toArray(new ItemStack[aItems.size()]); + FluidStack[] aFluidInputs = new FluidStack[] {}; + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + int aMaxParallelRecipes = getMaxParallelRecipes(); + int aEUPercent = getEuDiscountForParallelism(); + int aSpeedBonusPercent = 200; + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + aMaxParallelRecipes); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tRecipeEUt: " + tRecipeEUt); + + if (aItems.size() > 0 && aCircuit == 3) { + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage + // limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!this.depleteInput(tRecipe.mInputs[1])) { + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + } else if (aCircuit >= 1 && aCircuit <= 2) { + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + } + + log("Broke at " + parallelRecipes + "."); + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 75; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialRockBreaker; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public int getAmountOfOutputs() { + return 2; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> aInputs = super.getStoredInputs(); + if (this.hasSlotInGUI() && this.getGUIItemStack() != null) { + aInputs.add(this.getGUIItemStack()); + } + return aInputs; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java index 9a6a416357..a37b4301a2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java @@ -1,6 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.AirIntake; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; import com.google.common.collect.ImmutableMap; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -26,6 +32,7 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEn import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler_Adv; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -34,570 +41,564 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.AirIntake; -import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; - -public class GregtechMetaTileEntity_LargeRocketEngine extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargeRocketEngine> implements ISurvivalConstructable { - protected int fuelConsumption; - protected int fuelValue; - protected int fuelRemaining; - protected int freeFuelTicks = 0; - protected int euProduction = 0; - protected boolean boostEu; - - public static String mLubricantName = "Carbon Dioxide"; - public static String mCoolantName = "Liquid Hydrogen"; - - public static String mCasingName = "Turbodyne Casing"; - public static String mIntakeHatchName = "Tungstensteel Turbine Casing"; - public static String mGearboxName = "Inconel Reinforced Casing"; - - private static Fluid sAirFluid = null; - private static FluidStack sAirFluidStack = null; - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_LargeRocketEngine> STRUCTURE_DEFINITION = null; - - private final static int CASING_ID = TAE.getIndexFromPage(3, 11); - - public GregtechMetaTileEntity_LargeRocketEngine(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - this.fuelConsumption = 0; - this.fuelValue = 0; - this.fuelRemaining = 0; - this.boostEu = false; - setAir(); - } - - public GregtechMetaTileEntity_LargeRocketEngine(final String aName) { - super(aName); - this.fuelConsumption = 0; - this.fuelValue = 0; - this.fuelRemaining = 0; - this.boostEu = false; - setAir(); - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Large Rocket Engine") - .addInfo("Supply Rocket Fuels and 1000L of " + mLubricantName + " per hour") - .addInfo("Produces as much energy as you put fuel in, with optional boosting") - .addInfo("Supply 4L of " + mCoolantName + " per second, per 2100 EU/t to boost") - .addInfo("Takes 3x the amount of fuel and " + mLubricantName + "to run 3x faster") - .addInfo("Consumes 2000L/s of air and pollutes 1500 gibbl/s per 16384 eu/t produced") - .addInfo("If producing more than 18.4k EU/t, fuel will be consumed less efficiently:") - .addInfo("- 75% of max fuel efficiency at 44k EU/t output energy") - .addInfo("- 50% of max fuel efficiency at 105k EU/t output energy") - .addInfo("- 25% of max fuel efficiency at 294k EU/t output energy") - .addInfo("(These thresholds are 3x higher when boosted)") - .addInfo("formula: x = input of energy (10K^(1/3)/ x^(1/3)) * (40K^(1/3)/ x^(1/3))") - .addSeparator() - .beginStructureBlock(3, 3, 10, false) - .addController("Front Center") - .addCasingInfo(mCasingName, 64) - .addCasingInfo(mGearboxName, 8) - .addStructureHint("Air Intake Hatch", 1) - .addInputBus("Side center line", 1) - .addInputHatch("Side center line", 1) - .addMaintenanceHatch("Any Block Touching Inconel Reinforced Casing", 1) - .addDynamoHatch("Top center line", 2) - .addMufflerHatch("Back Center", 3) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_LargeRocketEngine> getStructureDefinition() { - if (this.STRUCTURE_DEFINITION == null) { - this.STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_LargeRocketEngine>builder() - .addShape(this.mName, transpose(new String[][]{ - {"CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC"}, - {"C~C", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "CMC"}, - {"CCC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CCC"}, - })) - .addElement('C', ofBlock(getCasingBlock(), getCasingMeta())) - .addElement('I', ofBlock(getGearboxBlock(), getGearboxMeta())) - // side - .addElement('S', buildHatchAdder(GregtechMetaTileEntity_LargeRocketEngine.class) - .atLeast(ImmutableMap.of(InputBus, 1, InputHatch, 3, Maintenance, 1, AirIntake, 8)) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) - // top - .addElement('T', buildHatchAdder(GregtechMetaTileEntity_LargeRocketEngine.class) - .atLeast(ImmutableMap.of(Dynamo.or(TTDynamo), 1, Maintenance, 1, AirIntake, 8)) - .casingIndex(getCasingTextureIndex()) - .dot(2) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) - .addElement('M', Muffler.newAny(getCasingTextureIndex(), 3)) - .build(); - } - return this.STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(this.mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - this.mCasing = 0; - this.mTecTechDynamoHatches.clear(); - this.mAllDynamoHatches.clear(); - this.mAirIntakes.clear(); - return checkPiece(this.mName, 1, 1, 0) && this.mCasing >= 64 - 48 && this.mAirIntakes.size() >= 8 && checkHatch(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return CASING_ID; - } - - @Override - public boolean isCorrectMachinePart(final ItemStack aStack) { - return this.getMaxEfficiency(aStack) > 0; - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return super.getClientGUI(aID, aPlayerInventory, aBaseMetaTileEntity); - } - - public static void setAir() { - if (sAirFluidStack == null) { - sAirFluidStack = FluidUtils.getFluidStack("air", 1); - } - if (sAirFluid == null && sAirFluidStack != null) { - sAirFluid = sAirFluidStack.getFluid(); - } - } - - public int getAir() { - setAir(); - if (this.mAirIntakes.isEmpty() || this.mAirIntakes.size() <= 0) { - return 0; - } - else { - int totalAir = 0; - for (GT_MetaTileEntity_Hatch_AirIntake u : this.mAirIntakes) { - if (u != null && u.mFluid != null) { - FluidStack f = u.mFluid; - if (f.isFluidEqual(sAirFluidStack)) { - totalAir += f.amount; - } - } - } - return totalAir; - } - } - - @Override - public GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe.GTPP_Recipe_Map.sRocketFuels; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - final ArrayList<FluidStack> tFluids = this.getStoredFluids(); - this.clearRecipeMapForAllInputHatches(); - int aircount = getAir() ; - int aAirToConsume = this.euProduction/100; - if (aircount < aAirToConsume) { - log("Not Enough Air to Run "+aircount); - return false; - } - else { - int aTotalAir = 0; - for (GT_MetaTileEntity_Hatch_AirIntake aAirHatch : this.mAirIntakes) { - if (aAirHatch.mFluid != null) { - aTotalAir += aAirHatch.getFluidAmount(); - } - } - log("Total Air: "+aTotalAir); - if (aTotalAir >= aAirToConsume) { - int aSplitAmount = (aAirToConsume / this.mAirIntakes.size()); - if (aSplitAmount > 0) { - for (GT_MetaTileEntity_Hatch_AirIntake aAirHatch : mAirIntakes) { - boolean hasIntakeAir = aAirHatch.drain(aSplitAmount, true) != null; - if (!hasIntakeAir) { - log("Could not consume Air to run "+aSplitAmount); - this.freeFuelTicks = 0; - return false; - } - log("Consumed Air to run "+aSplitAmount); - } - } - } - } - // reset fuel ticks in case it does not reset when it stops - if (this.freeFuelTicks != 0 && this.mProgresstime == 0 && this.mEfficiency == 0) - this.freeFuelTicks = 0; - - log("Running "+aircount); - log("looking at hatch"); - - - if (tFluids.size() > 0 && getRecipeMap() != null) { - FluidStack aCO2 = MISC_MATERIALS.CARBON_DIOXIDE.getFluidStack(this.boostEu ? 3 : 1); - FluidStack aCO2Fallback = FluidUtils.getWildcardFluidStack("carbondioxide", (this.boostEu ? 3 : 1)); - - - boolean aHasCO2 = false; - for (FluidStack aFluid : tFluids) { - if (aCO2 != null && aFluid.isFluidEqual(aCO2)) { - log("Found CO2 (1)"); - aHasCO2 = true; - break; - } - if (aCO2Fallback != null && aFluid.isFluidEqual(aCO2Fallback)) { - log("Found CO2 (2)"); - aHasCO2 = true; - break; - } - log("Found: "+aFluid.getUnlocalizedName()); - } - if (aHasCO2) { - if (this.mRuntime % 72 == 0 || this.mRuntime == 0) { - if (!consumeCO2()) { - this.freeFuelTicks = 0; - log("Bad Return 1"); - return false; - } - } - } - else { - this.freeFuelTicks = 0; - log("Bad Return 2 | "+aHasCO2+" | "+(aCO2 != null)+" | "+(aCO2Fallback != null)); - return false; - } - if (this.freeFuelTicks == 0) { - this.boostEu = consumeLOH(); - } - for (final FluidStack hatchFluid1 : tFluids) { - if (hatchFluid1.isFluidEqual(sAirFluidStack)) { - continue; - } - if (this.freeFuelTicks == 0) { - for (final GT_Recipe aFuel : getRecipeMap().mRecipeList) { - final FluidStack tLiquid; - tLiquid = aFuel.mFluidInputs[0]; - if (hatchFluid1.isFluidEqual(tLiquid)) { - if (!consumeFuel(aFuel,hatchFluid1.amount)) { - continue; - } - this.fuelValue = aFuel.mSpecialValue * 3; - this.fuelRemaining = hatchFluid1.amount; - this.mEUt = (int) ((this.mEfficiency < 2000) ? 0 : GT_Values.V[5]<<1); - this.mProgresstime = 1; - this.mMaxProgresstime = 1; - this.mEfficiencyIncrease = this.euProduction/2000; - return true; - } - } - } - else { - this.mEfficiencyIncrease = this.euProduction/2000; - this.freeFuelTicks--; - this.mEUt = (int) ((this.mEfficiency < 1000) ? 0 : GT_Values.V[5]<<1); - this.mProgresstime = 1; - this.mMaxProgresstime = 1; - return true; - } - } - } - this.mEUt = 0; - this.mEfficiency = 0; - this.freeFuelTicks = 0; - log("Bad Return 3"); - return false; - } - - /** - * Consumes Fuel if required. Free Fuel Ticks are handled here. - * @param aFuel - * @return - */ - public boolean consumeFuel(GT_Recipe aFuel,int amount) { - amount *= this.boostEu ? 0.3 : 0.9; - this.freeFuelTicks = 0; - int value = aFuel.mSpecialValue * 3; - int energy = value * amount; - if (amount < 5) - return false; - FluidStack tLiquid = FluidUtils.getFluidStack(aFuel.mFluidInputs[0], (this.boostEu ? amount * 3 : amount)); - if (!this.depleteInput(tLiquid)) { - return false; - } - else { - this.fuelConsumption = this.boostEu ? amount * 3 : amount; - this.freeFuelTicks = 20; - setEUProduction(energy); - return true; - } - } - - public void setEUProduction(int energy){ - energy /= 20; - double energyEfficiency; - double tDivideEnergy = Math.cbrt(energy); - if (energy > 10000) { - //cbrt(10 000) / - energyEfficiency = (21.5443469/tDivideEnergy); - if (energy >= 40000) - //cbrt(40 000) / - energyEfficiency *= (34.19951893/tDivideEnergy); - energyEfficiency *= energy; - } - else { - energyEfficiency = energy; - } - this.euProduction = (int) (energyEfficiency * 1.84); - if (this.boostEu) - this.euProduction *= 3; - } - - public boolean consumeCO2() { - if (this.depleteInput(MISC_MATERIALS.CARBON_DIOXIDE.getFluidStack(this.boostEu ? 3 : 1)) || this.depleteInput(FluidUtils.getFluidStack("carbondioxide", (this.boostEu ? 3 : 1)))) { - return true; - } - else { - return false; - } - } - - public boolean consumeLOH() { - int LOHamount = (3 * this.euProduction)/1000; - return this.depleteInput(FluidUtils.getFluidStack(RocketFuels.Liquid_Hydrogen, LOHamount)); //(40 * ((long) euProduction / 10000)) - } - - @Override - public boolean addEnergyOutput(long aEU) { - if (aEU <= 0) { - return true; - } - if (this.mAllDynamoHatches.size() > 0) { - return addEnergyOutputMultipleDynamos(aEU, true); - } - return false; - } - - - @Override - public boolean addEnergyOutputMultipleDynamos(long aEU, boolean aAllowMixedVoltageDynamos) { - int injected = 0; - long totalOutput = 0; - long aFirstVoltageFound = -1; - boolean aFoundMixedDynamos = false; - for (GT_MetaTileEntity_Hatch aDynamo : this.mAllDynamoHatches) { - if( aDynamo == null ) { - return false; - } - if (isValidMetaTileEntity(aDynamo)) { - long aVoltage = aDynamo.maxEUOutput(); - long aTotal = aDynamo.maxAmperesOut() * aVoltage; - // Check against voltage to check when hatch mixing - if (aFirstVoltageFound == -1) { - aFirstVoltageFound = aVoltage; - } - else { - /** - * Calcualtes overclocked ness using long integers - * @param aEUt - recipe EUt - * @param aDuration - recipe Duration - * @param mAmperage - should be 1 ? - */ - //Long time calculation - if (aFirstVoltageFound != aVoltage) { - aFoundMixedDynamos = true; - } - } - totalOutput += aTotal; - } - } - - if (totalOutput < aEU || (aFoundMixedDynamos && !aAllowMixedVoltageDynamos)) { - explodeMultiblock(); - return false; - } - - long leftToInject; - //Long EUt calculation - long aVoltage; - //Isnt too low EUt check? - int aAmpsToInject; - int aRemainder; - - //xEUt *= 4;//this is effect of everclocking - for (GT_MetaTileEntity_Hatch aDynamo : this.mAllDynamoHatches) { - if (isValidMetaTileEntity(aDynamo)) { - leftToInject = aEU - injected; - aVoltage = aDynamo.maxEUOutput(); - aAmpsToInject = (int) (leftToInject / aVoltage); - aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); - long powerGain; - for (int i = 0; i < Math.min(aDynamo.maxAmperesOut(), aAmpsToInject + 1); i++) { - if (i == Math.min(aDynamo.maxAmperesOut(), aAmpsToInject)){ - powerGain = aRemainder; - }else{ - powerGain = aVoltage; - } - aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(powerGain, false); - injected += powerGain; - } - } - } - return injected > 0; - } - - @Override - public boolean onRunningTick(ItemStack aStack) { - if (this.mRuntime%20 == 0) { - if (this.mMufflerHatches.size() == 1 && this.mMufflerHatches.get(0) instanceof GT_MetaTileEntity_Hatch_Muffler_Adv) { - GT_MetaTileEntity_Hatch_Muffler_Adv tMuffler = (GT_MetaTileEntity_Hatch_Muffler_Adv) this.mMufflerHatches.get(0); - if (!tMuffler.hasValidFilter()) { - ArrayList<ItemStack> tInputs = getStoredInputs(); - for (ItemStack tItem : tInputs) { - if (tMuffler.isAirFilter(tItem)) { - tMuffler.mInventory[0] = tItem.copy(); - depleteInput(tItem); - updateSlots(); - break; - } - } - } - } - } - super.onRunningTick(aStack); - return true; - } - - public Block getCasingBlock() { - return ModBlocks.blockCasings4Misc; - } - - public byte getCasingMeta() { - return 11; - } - - public Block getGearboxBlock() { - return ModBlocks.blockCasings3Misc; - } - - public byte getGearboxMeta() { - return 1; - } - - public byte getCasingTextureIndex() { - return (byte) CASING_ID; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_LargeRocketEngine(this.mName); - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setInteger("freeFuelTicks", this.freeFuelTicks); - aNBT.setInteger("euProduction", this.euProduction); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - this.freeFuelTicks = aNBT.getInteger("freeFuelTicks"); - this.euProduction = aNBT.getInteger("euProduction"); - } - - @Override - public int getDamageToComponent(final ItemStack aStack) { - return 1; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return this.euProduction; - } - - @Override - public int getPollutionPerTick(final ItemStack aStack) { - return 75 * ( this.euProduction / 10000); - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return true; - } - - @Override - public String[] getExtraInfoData() { - return new String[] { - "Rocket Engine", - "Current Air: "+getAir(), - "Current Pollution: " + getPollutionPerTick(null), - "Time until next fuel consumption: "+this.freeFuelTicks, - "Current Output: " + this.mEUt * this.mEfficiency / 10000 + " EU/t", - "Fuel Consumption: " + (this.fuelConsumption) + "L/s", - "Fuel Value: " + this.fuelValue + " EU/L", - "Fuel Remaining: " + this.fuelRemaining + " Litres", - "Current Efficiency: " + this.mEfficiency / 100 + "%", - (this.getIdealStatus() == this.getRepairStatus()) ? "No Maintainance issues" : "Needs Maintainance" }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Rocket Engine"; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } +public class GregtechMetaTileEntity_LargeRocketEngine + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargeRocketEngine> + implements ISurvivalConstructable { + protected int fuelConsumption; + protected int fuelValue; + protected int fuelRemaining; + protected int freeFuelTicks = 0; + protected int euProduction = 0; + protected boolean boostEu; + + public static String mLubricantName = "Carbon Dioxide"; + public static String mCoolantName = "Liquid Hydrogen"; + + public static String mCasingName = "Turbodyne Casing"; + public static String mIntakeHatchName = "Tungstensteel Turbine Casing"; + public static String mGearboxName = "Inconel Reinforced Casing"; + + private static Fluid sAirFluid = null; + private static FluidStack sAirFluidStack = null; + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_LargeRocketEngine> STRUCTURE_DEFINITION = null; + + private static final int CASING_ID = TAE.getIndexFromPage(3, 11); + + public GregtechMetaTileEntity_LargeRocketEngine(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + this.fuelConsumption = 0; + this.fuelValue = 0; + this.fuelRemaining = 0; + this.boostEu = false; + setAir(); + } + + public GregtechMetaTileEntity_LargeRocketEngine(final String aName) { + super(aName); + this.fuelConsumption = 0; + this.fuelValue = 0; + this.fuelRemaining = 0; + this.boostEu = false; + setAir(); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Rocket Engine") + .addInfo("Supply Rocket Fuels and 1000L of " + mLubricantName + " per hour") + .addInfo("Produces as much energy as you put fuel in, with optional boosting") + .addInfo("Supply 4L of " + mCoolantName + " per second, per 2100 EU/t to boost") + .addInfo("Takes 3x the amount of fuel and " + mLubricantName + "to run 3x faster") + .addInfo("Consumes 2000L/s of air and pollutes 1500 gibbl/s per 16384 eu/t produced") + .addInfo("If producing more than 18.4k EU/t, fuel will be consumed less efficiently:") + .addInfo("- 75% of max fuel efficiency at 44k EU/t output energy") + .addInfo("- 50% of max fuel efficiency at 105k EU/t output energy") + .addInfo("- 25% of max fuel efficiency at 294k EU/t output energy") + .addInfo("(These thresholds are 3x higher when boosted)") + .addInfo("formula: x = input of energy (10K^(1/3)/ x^(1/3)) * (40K^(1/3)/ x^(1/3))") + .addSeparator() + .beginStructureBlock(3, 3, 10, false) + .addController("Front Center") + .addCasingInfo(mCasingName, 64) + .addCasingInfo(mGearboxName, 8) + .addStructureHint("Air Intake Hatch", 1) + .addInputBus("Side center line", 1) + .addInputHatch("Side center line", 1) + .addMaintenanceHatch("Any Block Touching Inconel Reinforced Casing", 1) + .addDynamoHatch("Top center line", 2) + .addMufflerHatch("Back Center", 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_LargeRocketEngine> getStructureDefinition() { + if (this.STRUCTURE_DEFINITION == null) { + this.STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_LargeRocketEngine>builder() + .addShape(this.mName, transpose(new String[][] { + {"CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC"}, + {"C~C", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "CMC"}, + {"CCC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CCC"}, + })) + .addElement('C', ofBlock(getCasingBlock(), getCasingMeta())) + .addElement('I', ofBlock(getGearboxBlock(), getGearboxMeta())) + // side + .addElement( + 'S', + buildHatchAdder(GregtechMetaTileEntity_LargeRocketEngine.class) + .atLeast(ImmutableMap.of(InputBus, 1, InputHatch, 3, Maintenance, 1, AirIntake, 8)) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + // top + .addElement( + 'T', + buildHatchAdder(GregtechMetaTileEntity_LargeRocketEngine.class) + .atLeast(ImmutableMap.of(Dynamo.or(TTDynamo), 1, Maintenance, 1, AirIntake, 8)) + .casingIndex(getCasingTextureIndex()) + .dot(2) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement('M', Muffler.newAny(getCasingTextureIndex(), 3)) + .build(); + } + return this.STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(this.mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + this.mCasing = 0; + this.mTecTechDynamoHatches.clear(); + this.mAllDynamoHatches.clear(); + this.mAirIntakes.clear(); + return checkPiece(this.mName, 1, 1, 0) + && this.mCasing >= 64 - 48 + && this.mAirIntakes.size() >= 8 + && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_ID; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return this.getMaxEfficiency(aStack) > 0; + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return super.getClientGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + } + + public static void setAir() { + if (sAirFluidStack == null) { + sAirFluidStack = FluidUtils.getFluidStack("air", 1); + } + if (sAirFluid == null && sAirFluidStack != null) { + sAirFluid = sAirFluidStack.getFluid(); + } + } + + public int getAir() { + setAir(); + if (this.mAirIntakes.isEmpty() || this.mAirIntakes.size() <= 0) { + return 0; + } else { + int totalAir = 0; + for (GT_MetaTileEntity_Hatch_AirIntake u : this.mAirIntakes) { + if (u != null && u.mFluid != null) { + FluidStack f = u.mFluid; + if (f.isFluidEqual(sAirFluidStack)) { + totalAir += f.amount; + } + } + } + return totalAir; + } + } + + @Override + public GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sRocketFuels; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + final ArrayList<FluidStack> tFluids = this.getStoredFluids(); + this.clearRecipeMapForAllInputHatches(); + int aircount = getAir(); + int aAirToConsume = this.euProduction / 100; + if (aircount < aAirToConsume) { + log("Not Enough Air to Run " + aircount); + return false; + } else { + int aTotalAir = 0; + for (GT_MetaTileEntity_Hatch_AirIntake aAirHatch : this.mAirIntakes) { + if (aAirHatch.mFluid != null) { + aTotalAir += aAirHatch.getFluidAmount(); + } + } + log("Total Air: " + aTotalAir); + if (aTotalAir >= aAirToConsume) { + int aSplitAmount = (aAirToConsume / this.mAirIntakes.size()); + if (aSplitAmount > 0) { + for (GT_MetaTileEntity_Hatch_AirIntake aAirHatch : mAirIntakes) { + boolean hasIntakeAir = aAirHatch.drain(aSplitAmount, true) != null; + if (!hasIntakeAir) { + log("Could not consume Air to run " + aSplitAmount); + this.freeFuelTicks = 0; + return false; + } + log("Consumed Air to run " + aSplitAmount); + } + } + } + } + // reset fuel ticks in case it does not reset when it stops + if (this.freeFuelTicks != 0 && this.mProgresstime == 0 && this.mEfficiency == 0) this.freeFuelTicks = 0; + + log("Running " + aircount); + log("looking at hatch"); + + if (tFluids.size() > 0 && getRecipeMap() != null) { + FluidStack aCO2 = MISC_MATERIALS.CARBON_DIOXIDE.getFluidStack(this.boostEu ? 3 : 1); + FluidStack aCO2Fallback = FluidUtils.getWildcardFluidStack("carbondioxide", (this.boostEu ? 3 : 1)); + + boolean aHasCO2 = false; + for (FluidStack aFluid : tFluids) { + if (aCO2 != null && aFluid.isFluidEqual(aCO2)) { + log("Found CO2 (1)"); + aHasCO2 = true; + break; + } + if (aCO2Fallback != null && aFluid.isFluidEqual(aCO2Fallback)) { + log("Found CO2 (2)"); + aHasCO2 = true; + break; + } + log("Found: " + aFluid.getUnlocalizedName()); + } + if (aHasCO2) { + if (this.mRuntime % 72 == 0 || this.mRuntime == 0) { + if (!consumeCO2()) { + this.freeFuelTicks = 0; + log("Bad Return 1"); + return false; + } + } + } else { + this.freeFuelTicks = 0; + log("Bad Return 2 | " + aHasCO2 + " | " + (aCO2 != null) + " | " + (aCO2Fallback != null)); + return false; + } + if (this.freeFuelTicks == 0) { + this.boostEu = consumeLOH(); + } + for (final FluidStack hatchFluid1 : tFluids) { + if (hatchFluid1.isFluidEqual(sAirFluidStack)) { + continue; + } + if (this.freeFuelTicks == 0) { + for (final GT_Recipe aFuel : getRecipeMap().mRecipeList) { + final FluidStack tLiquid; + tLiquid = aFuel.mFluidInputs[0]; + if (hatchFluid1.isFluidEqual(tLiquid)) { + if (!consumeFuel(aFuel, hatchFluid1.amount)) { + continue; + } + this.fuelValue = aFuel.mSpecialValue * 3; + this.fuelRemaining = hatchFluid1.amount; + this.mEUt = (int) ((this.mEfficiency < 2000) ? 0 : GT_Values.V[5] << 1); + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = this.euProduction / 2000; + return true; + } + } + } else { + this.mEfficiencyIncrease = this.euProduction / 2000; + this.freeFuelTicks--; + this.mEUt = (int) ((this.mEfficiency < 1000) ? 0 : GT_Values.V[5] << 1); + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + return true; + } + } + } + this.mEUt = 0; + this.mEfficiency = 0; + this.freeFuelTicks = 0; + log("Bad Return 3"); + return false; + } + + /** + * Consumes Fuel if required. Free Fuel Ticks are handled here. + * @param aFuel + * @return + */ + public boolean consumeFuel(GT_Recipe aFuel, int amount) { + amount *= this.boostEu ? 0.3 : 0.9; + this.freeFuelTicks = 0; + int value = aFuel.mSpecialValue * 3; + int energy = value * amount; + if (amount < 5) return false; + FluidStack tLiquid = FluidUtils.getFluidStack(aFuel.mFluidInputs[0], (this.boostEu ? amount * 3 : amount)); + if (!this.depleteInput(tLiquid)) { + return false; + } else { + this.fuelConsumption = this.boostEu ? amount * 3 : amount; + this.freeFuelTicks = 20; + setEUProduction(energy); + return true; + } + } + + public void setEUProduction(int energy) { + energy /= 20; + double energyEfficiency; + double tDivideEnergy = Math.cbrt(energy); + if (energy > 10000) { + // cbrt(10 000) / + energyEfficiency = (21.5443469 / tDivideEnergy); + if (energy >= 40000) + // cbrt(40 000) / + energyEfficiency *= (34.19951893 / tDivideEnergy); + energyEfficiency *= energy; + } else { + energyEfficiency = energy; + } + this.euProduction = (int) (energyEfficiency * 1.84); + if (this.boostEu) this.euProduction *= 3; + } + + public boolean consumeCO2() { + if (this.depleteInput(MISC_MATERIALS.CARBON_DIOXIDE.getFluidStack(this.boostEu ? 3 : 1)) + || this.depleteInput(FluidUtils.getFluidStack("carbondioxide", (this.boostEu ? 3 : 1)))) { + return true; + } else { + return false; + } + } + + public boolean consumeLOH() { + int LOHamount = (3 * this.euProduction) / 1000; + return this.depleteInput(FluidUtils.getFluidStack( + RocketFuels.Liquid_Hydrogen, LOHamount)); // (40 * ((long) euProduction / 10000)) + } + + @Override + public boolean addEnergyOutput(long aEU) { + if (aEU <= 0) { + return true; + } + if (this.mAllDynamoHatches.size() > 0) { + return addEnergyOutputMultipleDynamos(aEU, true); + } + return false; + } + + @Override + public boolean addEnergyOutputMultipleDynamos(long aEU, boolean aAllowMixedVoltageDynamos) { + int injected = 0; + long totalOutput = 0; + long aFirstVoltageFound = -1; + boolean aFoundMixedDynamos = false; + for (GT_MetaTileEntity_Hatch aDynamo : this.mAllDynamoHatches) { + if (aDynamo == null) { + return false; + } + if (isValidMetaTileEntity(aDynamo)) { + long aVoltage = aDynamo.maxEUOutput(); + long aTotal = aDynamo.maxAmperesOut() * aVoltage; + // Check against voltage to check when hatch mixing + if (aFirstVoltageFound == -1) { + aFirstVoltageFound = aVoltage; + } else { + /** + * Calcualtes overclocked ness using long integers + * @param aEUt - recipe EUt + * @param aDuration - recipe Duration + * @param mAmperage - should be 1 ? + */ + // Long time calculation + if (aFirstVoltageFound != aVoltage) { + aFoundMixedDynamos = true; + } + } + totalOutput += aTotal; + } + } + + if (totalOutput < aEU || (aFoundMixedDynamos && !aAllowMixedVoltageDynamos)) { + explodeMultiblock(); + return false; + } + + long leftToInject; + // Long EUt calculation + long aVoltage; + // Isnt too low EUt check? + int aAmpsToInject; + int aRemainder; + + // xEUt *= 4;//this is effect of everclocking + for (GT_MetaTileEntity_Hatch aDynamo : this.mAllDynamoHatches) { + if (isValidMetaTileEntity(aDynamo)) { + leftToInject = aEU - injected; + aVoltage = aDynamo.maxEUOutput(); + aAmpsToInject = (int) (leftToInject / aVoltage); + aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); + long powerGain; + for (int i = 0; i < Math.min(aDynamo.maxAmperesOut(), aAmpsToInject + 1); i++) { + if (i == Math.min(aDynamo.maxAmperesOut(), aAmpsToInject)) { + powerGain = aRemainder; + } else { + powerGain = aVoltage; + } + aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(powerGain, false); + injected += powerGain; + } + } + } + return injected > 0; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.mRuntime % 20 == 0) { + if (this.mMufflerHatches.size() == 1 + && this.mMufflerHatches.get(0) instanceof GT_MetaTileEntity_Hatch_Muffler_Adv) { + GT_MetaTileEntity_Hatch_Muffler_Adv tMuffler = + (GT_MetaTileEntity_Hatch_Muffler_Adv) this.mMufflerHatches.get(0); + if (!tMuffler.hasValidFilter()) { + ArrayList<ItemStack> tInputs = getStoredInputs(); + for (ItemStack tItem : tInputs) { + if (tMuffler.isAirFilter(tItem)) { + tMuffler.mInventory[0] = tItem.copy(); + depleteInput(tItem); + updateSlots(); + break; + } + } + } + } + } + super.onRunningTick(aStack); + return true; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + public byte getCasingMeta() { + return 11; + } + + public Block getGearboxBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getGearboxMeta() { + return 1; + } + + public byte getCasingTextureIndex() { + return (byte) CASING_ID; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_LargeRocketEngine(this.mName); + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("freeFuelTicks", this.freeFuelTicks); + aNBT.setInteger("euProduction", this.euProduction); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.freeFuelTicks = aNBT.getInteger("freeFuelTicks"); + this.euProduction = aNBT.getInteger("euProduction"); + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 1; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return this.euProduction; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 75 * (this.euProduction / 10000); + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return true; + } + + @Override + public String[] getExtraInfoData() { + return new String[] { + "Rocket Engine", + "Current Air: " + getAir(), + "Current Pollution: " + getPollutionPerTick(null), + "Time until next fuel consumption: " + this.freeFuelTicks, + "Current Output: " + this.mEUt * this.mEfficiency / 10000 + " EU/t", + "Fuel Consumption: " + (this.fuelConsumption) + "L/s", + "Fuel Value: " + this.fuelValue + " EU/L", + "Fuel Remaining: " + this.fuelRemaining + " Litres", + "Current Efficiency: " + this.mEfficiency / 100 + "%", + (this.getIdealStatus() == this.getRepairStatus()) ? "No Maintainance issues" : "Needs Maintainance" + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Rocket Engine"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java index 37d5cb422c..ec3f85014e 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java @@ -1,6 +1,14 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Dynamo; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -22,6 +30,7 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -29,337 +38,311 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.Dynamo; -import static gregtech.api.enums.GT_HatchElement.InputHatch; -import static gregtech.api.enums.GT_HatchElement.Maintenance; -import static gregtech.api.enums.GT_HatchElement.Muffler; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; - -public class GregtechMetaTileEntity_LargeSemifluidGenerator extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargeSemifluidGenerator> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_LargeSemifluidGenerator> STRUCTURE_DEFINITION = null; - - protected int fuelConsumption = 0; - protected int fuelValue = 0; - protected int fuelRemaining = 0; - protected boolean boostEu = false; - - public GregtechMetaTileEntity_LargeSemifluidGenerator(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_LargeSemifluidGenerator(String aName) { - super(aName); - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Large Semifluid Generator") - .addInfo("Engine Intake Casings must not be obstructed in front (only air blocks)") - .addInfo("Supply Semifluid Fuels and 2000L of Lubricant per hour to run.") - .addInfo("Supply 80L of Oxygen per second to boost output (optional).") - .addInfo("Default: Produces 2048EU/t at 100% efficiency") - .addInfo("Boosted: Produces 6144EU/t at 150% efficiency") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 3, 4, false) - .addController("Front Center") - .addCasingInfo("Stable Titanium Machine Casing", 16) - .addCasingInfo("Steel Gear Box Machine Casing", 2) - .addCasingInfo("Engine Intake Machine Casing", 8) - .addInputHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .addDynamoHatch("Back Center", 2) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE_ACTIVE; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE; - } - - @Override - protected int getCasingTextureId() { - return 50; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - return getMaxEfficiency(aStack) > 0; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeDieselEngine.png"); - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - ArrayList<FluidStack> tFluids = getStoredFluids(); - - // Check for lubricant and oxygen first, so we can compute costs ahead of time. - // This will allow us to check costs without needing to actually try to deplete fluids - // (wasting earlier fluids in the check if later fluids turn out to be insufficient). - FluidStack lubricant = Materials.Lubricant.getFluid(0L); - FluidStack oxygen = Materials.Oxygen.getGas(0L); - for (FluidStack hatchFluid : tFluids) { - if (hatchFluid.isFluidEqual(lubricant)) { - lubricant.amount = Math.max(lubricant.amount, hatchFluid.amount); - } else if (hatchFluid.isFluidEqual(oxygen)) { - oxygen.amount = Math.max(oxygen.amount, hatchFluid.amount); - } - } - boostEu = oxygen.amount >= 4L; - long lubricantCost = boostEu ? 2L : 1L; - if (lubricant.amount < lubricantCost) { - return false; - } - - for (FluidStack hatchFluid : tFluids) { //Loops through hatches - GT_Recipe aFuel = GTPP_Recipe_Map.sSemiFluidLiquidFuels.findFuel(hatchFluid); - if (aFuel == null) { - // Not a valid semi-fluid fuel. - continue; - } - - int newEUt = boostEu ? 4096 : 2048; - fuelConsumption = newEUt / aFuel.mSpecialValue; //Calc fuel consumption - FluidStack tLiquid = new FluidStack(hatchFluid.getFluid(), fuelConsumption); - if(depleteInput(tLiquid)) { //Deplete that amount - // We checked beforehand, so both of these depletions should succeed. - // But check the return values anyway just to be safe. - if (boostEu) { - if (!depleteInput(Materials.Oxygen.getGas(4L))) { - return false; - } - } - //Deplete Lubricant. 2000L should = 1 hour of runtime (if baseEU = 2048) - if(mRuntime % 72 == 0 || mRuntime == 0) { - if(!depleteInput(Materials.Lubricant.getFluid(lubricantCost))) { - return false; - } - } - - fuelValue = aFuel.mSpecialValue; - fuelRemaining = hatchFluid.amount; //Record available fuel - this.mEUt = mEfficiency < 2000 ? 0 : newEUt; //Output 0 if startup is less than 20% - this.mProgresstime = 1; - this.mMaxProgresstime = 1; - this.mEfficiencyIncrease = 15; - return true; - } - } - - this.mEUt = 0; - this.mEfficiency = 0; - return false; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_LargeSemifluidGenerator> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_LargeSemifluidGenerator>builder() - .addShape(mName, transpose(new String[][]{ - {"III", "CCC", "CCC", "CCC"}, - {"I~I", "CGC", "CGC", "CMC"}, - {"III", "CCC", "CCC", "CCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_LargeSemifluidGenerator.class) - .atLeast(Muffler, InputHatch, Maintenance) - .casingIndex(getCasingTextureIndex()) - .dot(1) - .buildAndChain(onElementPass( - x -> ++x.mCasing, - ofBlock( - getCasingBlock(), getCasingMeta() - ) - ) - ) - ) - .addElement( - 'G', - ofBlock( - getGearboxBlock(), getGearboxMeta() - ) - ) - .addElement( - 'I', - ofBlock( - getIntakeBlock(), getIntakeMeta() - ) - ) - .addElement( - 'M', - Dynamo.or(TTDynamo).newAny(getCasingTextureIndex(), 2) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mDynamoHatches.clear(); - return checkPiece(mName, 1, 1, 0) && mCasing >= 16 && checkHatch(); - } - - public final boolean addLargeSemifluidGeneratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - public final boolean addLargeSemifluidGeneratorBackList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo || this.isThisHatchMultiDynamo(aTileEntity)){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - public Block getCasingBlock() { - return GregTech_API.sBlockCasings4; - } - - public byte getCasingMeta() { - return 2; - } - - public Block getIntakeBlock() { - return GregTech_API.sBlockCasings4; - } - - public byte getIntakeMeta() { - return 13; - } - - public Block getGearboxBlock() { - return GregTech_API.sBlockCasings2; - } - - public byte getGearboxMeta() { - return 3; - } - - public byte getCasingTextureIndex() { - return 50; - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_LargeSemifluidGenerator(this.mName); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 1; - } - - public int getMaxEfficiency(ItemStack aStack) { - return boostEu ? 15000 : 10000; - } - - @Override - public int getPollutionPerSecond(ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiLargeSemiFluidGenerator; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return true; - } - - @Override - public String[] getExtraInfoData() { - return new String[]{ - "Large Semifluid Generator", - "Current Output: " + mEUt * mEfficiency / 10000 + " EU/t", - "Fuel Consumption: " + fuelConsumption + "L/t", - "Fuel Value: " + fuelValue + " EU/L", - "Fuel Remaining: " + fuelRemaining + " Litres", - "Current Efficiency: " + (mEfficiency / 100) + "%", - getIdealStatus() == getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance"}; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Semifluid Generator"; - } - - @Override - public int getMaxParallelRecipes() { - return 0; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } +public class GregtechMetaTileEntity_LargeSemifluidGenerator + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargeSemifluidGenerator> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_LargeSemifluidGenerator> STRUCTURE_DEFINITION = null; + + protected int fuelConsumption = 0; + protected int fuelValue = 0; + protected int fuelRemaining = 0; + protected boolean boostEu = false; + + public GregtechMetaTileEntity_LargeSemifluidGenerator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_LargeSemifluidGenerator(String aName) { + super(aName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Semifluid Generator") + .addInfo("Engine Intake Casings must not be obstructed in front (only air blocks)") + .addInfo("Supply Semifluid Fuels and 2000L of Lubricant per hour to run.") + .addInfo("Supply 80L of Oxygen per second to boost output (optional).") + .addInfo("Default: Produces 2048EU/t at 100% efficiency") + .addInfo("Boosted: Produces 6144EU/t at 150% efficiency") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 4, false) + .addController("Front Center") + .addCasingInfo("Stable Titanium Machine Casing", 16) + .addCasingInfo("Steel Gear Box Machine Casing", 2) + .addCasingInfo("Engine Intake Machine Casing", 8) + .addInputHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .addDynamoHatch("Back Center", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE; + } + + @Override + protected int getCasingTextureId() { + return 50; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeDieselEngine.png"); + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + ArrayList<FluidStack> tFluids = getStoredFluids(); + + // Check for lubricant and oxygen first, so we can compute costs ahead of time. + // This will allow us to check costs without needing to actually try to deplete fluids + // (wasting earlier fluids in the check if later fluids turn out to be insufficient). + FluidStack lubricant = Materials.Lubricant.getFluid(0L); + FluidStack oxygen = Materials.Oxygen.getGas(0L); + for (FluidStack hatchFluid : tFluids) { + if (hatchFluid.isFluidEqual(lubricant)) { + lubricant.amount = Math.max(lubricant.amount, hatchFluid.amount); + } else if (hatchFluid.isFluidEqual(oxygen)) { + oxygen.amount = Math.max(oxygen.amount, hatchFluid.amount); + } + } + boostEu = oxygen.amount >= 4L; + long lubricantCost = boostEu ? 2L : 1L; + if (lubricant.amount < lubricantCost) { + return false; + } + + for (FluidStack hatchFluid : tFluids) { // Loops through hatches + GT_Recipe aFuel = GTPP_Recipe_Map.sSemiFluidLiquidFuels.findFuel(hatchFluid); + if (aFuel == null) { + // Not a valid semi-fluid fuel. + continue; + } + + int newEUt = boostEu ? 4096 : 2048; + fuelConsumption = newEUt / aFuel.mSpecialValue; // Calc fuel consumption + FluidStack tLiquid = new FluidStack(hatchFluid.getFluid(), fuelConsumption); + if (depleteInput(tLiquid)) { // Deplete that amount + // We checked beforehand, so both of these depletions should succeed. + // But check the return values anyway just to be safe. + if (boostEu) { + if (!depleteInput(Materials.Oxygen.getGas(4L))) { + return false; + } + } + // Deplete Lubricant. 2000L should = 1 hour of runtime (if baseEU = 2048) + if (mRuntime % 72 == 0 || mRuntime == 0) { + if (!depleteInput(Materials.Lubricant.getFluid(lubricantCost))) { + return false; + } + } + + fuelValue = aFuel.mSpecialValue; + fuelRemaining = hatchFluid.amount; // Record available fuel + this.mEUt = mEfficiency < 2000 ? 0 : newEUt; // Output 0 if startup is less than 20% + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 15; + return true; + } + } + + this.mEUt = 0; + this.mEfficiency = 0; + return false; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_LargeSemifluidGenerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_LargeSemifluidGenerator>builder() + .addShape(mName, transpose(new String[][] { + {"III", "CCC", "CCC", "CCC"}, + {"I~I", "CGC", "CGC", "CMC"}, + {"III", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_LargeSemifluidGenerator.class) + .atLeast(Muffler, InputHatch, Maintenance) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass( + x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement('G', ofBlock(getGearboxBlock(), getGearboxMeta())) + .addElement('I', ofBlock(getIntakeBlock(), getIntakeMeta())) + .addElement('M', Dynamo.or(TTDynamo).newAny(getCasingTextureIndex(), 2)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mDynamoHatches.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 16 && checkHatch(); + } + + public final boolean addLargeSemifluidGeneratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addLargeSemifluidGeneratorBackList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo || this.isThisHatchMultiDynamo(aTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public Block getCasingBlock() { + return GregTech_API.sBlockCasings4; + } + + public byte getCasingMeta() { + return 2; + } + + public Block getIntakeBlock() { + return GregTech_API.sBlockCasings4; + } + + public byte getIntakeMeta() { + return 13; + } + + public Block getGearboxBlock() { + return GregTech_API.sBlockCasings2; + } + + public byte getGearboxMeta() { + return 3; + } + + public byte getCasingTextureIndex() { + return 50; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_LargeSemifluidGenerator(this.mName); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + public int getMaxEfficiency(ItemStack aStack) { + return boostEu ? 15000 : 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiLargeSemiFluidGenerator; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return true; + } + + @Override + public String[] getExtraInfoData() { + return new String[] { + "Large Semifluid Generator", + "Current Output: " + mEUt * mEfficiency / 10000 + " EU/t", + "Fuel Consumption: " + fuelConsumption + "L/t", + "Fuel Value: " + fuelValue + " EU/L", + "Fuel Remaining: " + fuelRemaining + " Litres", + "Current Efficiency: " + (mEfficiency / 100) + "%", + getIdealStatus() == getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance" + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Semifluid Generator"; + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java index f629c27b24..39f2958dfb 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java @@ -1,8 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -26,6 +29,9 @@ import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_MatterFab; import gtPlusPlus.xmod.gregtech.api.gui.GUI_MatterFab; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -34,648 +40,660 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_MassFabricator> implements ISurvivalConstructable { - - public static int sUUAperUUM = 1; - public static int sUUASpeedBonus = 4; - public static int sDurationMultiplier = 3200; - - public int mMatterProduced = 0; - public int mScrapProduced = 0; - public int mAmplifierProduced = 0; - public int mScrapUsed = 0; - public int mAmplifierUsed = 0; - - public static String mCasingName1 = "Matter Fabricator Casing"; - public static String mCasingName2 = "Containment Casing"; - public static String mCasingName3 = "Matter Generation Coil"; - - private int mMode = 0; - - private final static int MODE_SCRAP = 1; - private final static int MODE_UU = 0; - - public static boolean sRequiresUUA = false; - private static FluidStack[] mUU = new FluidStack[2]; - private static ItemStack mScrap[] = new ItemStack[2]; - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_MassFabricator> STRUCTURE_DEFINITION = null; - - public int getAmplifierUsed(){ - return this.mAmplifierUsed; - } - - public int getMatterProduced(){ - return this.mMatterProduced; - } - - public int getScrapProduced(){ - return this.mScrapProduced; - } - - public GregtechMetaTileEntity_MassFabricator(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_MassFabricator(final String aName) { - super(aName); - } - - @Override - public String getMachineType() { - return "Mass Fabricator / Recycler"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Matter Fabricator") - .addInfo("Speed: +0% | EU Usage: 80%") - .addInfo("Parallel: Scrap = 64 | UU = 8 * Tier") - .addInfo("Produces UU-A, UU-M & Scrap") - .addInfo("Change mode with screwdriver") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(5, 4, 5, true) - .addController("Front Center") - .addCasingInfo(mCasingName3, 9) - .addCasingInfo(mCasingName2, 24) - .addCasingInfo(mCasingName1, 40) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .addOutputHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .addMaintenanceHatch("Any Casing", 1) - .addMufflerHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_MatterFab_Active_Animated; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_MatterFab_Animated; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(9); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "MatterFabricator"; - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_MatterFab(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MatterFabricator.png"); - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_MatterFab(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public void onConfigLoad(final GT_Config aConfig) { - super.onConfigLoad(aConfig); - sDurationMultiplier = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUM_Duration_Multiplier", sDurationMultiplier); - sUUAperUUM = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_per_UUM", sUUAperUUM); - sUUASpeedBonus = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_Speed_Bonus", sUUASpeedBonus); - sRequiresUUA = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_Requirement", sRequiresUUA); - //Materials.UUAmplifier.mChemicalFormula = ("Mass Fabricator Eff/Speed Bonus: x" + sUUASpeedBonus); - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - ArrayList<ItemStack> tItems = getStoredInputs(); - ArrayList<FluidStack> tFluids = getStoredFluids(); - ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); - FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); - init(); - return checkRecipeGeneric(tItemInputs, tFluidInputs, 4, 80, 00, 10000); - } - - public static boolean sInit = false; - - public static void init() { - if (!sInit) { - if (mScrap[0] == null) { - mScrap[0] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrap")); - } - if (mScrap[1] == null) { - mScrap[1] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrapbox")); - } - if (mUU[0] == null) { - mUU[0] = Materials.UUAmplifier.getFluid(100); - } - if (mUU[1] == null) { - mUU[1] = Materials.UUMatter.getFluid(100); - } - sInit = true; - } - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_MassFabricator> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_MassFabricator>builder() - .addShape(mName, transpose(new String[][]{ - {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, - {"CGGGC", "G---G", "G---G", "G---G", "CGGGC"}, - {"CGGGC", "G---G", "G---G", "G---G", "CGGGC"}, - {"CC~CC", "CHHHC", "CHHHC", "CHHHC", "CCCCC"}, - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_MassFabricator.class) - .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) - .casingIndex(TAE.GTPP_INDEX(9)) - .dot(1) - .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 9))) - ) - .addElement( - 'H', - ofBlock( - ModBlocks.blockCasingsMisc, 8 - ) - ) - .addElement( - 'G', - ofBlock( - ModBlocks.blockCasings3Misc, 15 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 2, 3, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 2, 3, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - return checkPiece(mName, 2, 3, 0) && mCasing >= 40 && checkHatch(); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiMassFabricator; - } - - @Override - public int getAmountOfOutputs() { - return 10; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_MassFabricator(this.mName); - } - - /** - * Special Recipe Handling - */ - - - @Override - public GT_Recipe_Map getRecipeMap() { - return this.mMode == MODE_SCRAP ? GT_Recipe_Map.sRecyclerRecipes : GTPP_Recipe.GTPP_Recipe_Map.sMatterFab2Recipes; - //return Recipe_GT.Gregtech_Recipe_Map.sMatterFab2Recipes; - } - - @Override - public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, long aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { - if (this.mMode == MODE_SCRAP) { - return checkRecipeScrap(aItemInputs, aFluidInputs, getMaxParallelRecipes(), getEuDiscountForParallelism(), aSpeedBonusPercent, aOutputChanceRoll); - } - else { - return checkRecipeUU(aItemInputs, aFluidInputs, getMaxParallelRecipes(), getEuDiscountForParallelism(), aSpeedBonusPercent, aOutputChanceRoll); - } - } - - public boolean checkRecipeScrap( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, int aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll) { - - if (aItemInputs == null || aItemInputs.length <= 0) { - return false; - } - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - ItemStack aPotentialOutput = GT_ModHandler.getRecyclerOutput(GT_Utility.copyAmount(1, aItemInputs[0]), 0); - GT_Recipe tRecipe = new GTPP_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(1, aItemInputs[0])}, aPotentialOutput == null ? null : new ItemStack[]{aPotentialOutput}, null, new int[]{2000}, null, null, 40, MaterialUtils.getVoltageForTier(1), 0); - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - int parallelRecipes = 0; - // Count recipes to do in parallel, consuming input items and fluids and - // considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - break; - } - log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ". "); - tTotalEUt += tRecipeEUt; - } - log("Broke at " + parallelRecipes + "."); - if (parallelRecipes > 0) { - // -- Try not to fail after this point - inputs have already been - // consumed! -- - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe - // duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); - this.mEUt = (int) Math.ceil(tTotalEUt); - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } - else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 4; - } - } - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - tOutputItems = removeNulls(tOutputItems); - for (ItemStack aOutputStack : tOutputItems) { - if (aOutputStack != null) { - mScrapProduced += aOutputStack.stackSize; - } - } - // Sanitize item stack size, splitting any stacks greater than max - // stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) - tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - // Commit outputs - this.mOutputItems = tOutputItems; - updateSlots(); - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - return true; - } - return false; - } - - public boolean checkRecipeUU( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, int aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll) { - - - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - GT_Recipe tRecipe = findRecipe( - getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - if (tRecipe == null) { - log("BAD RETURN - 1"); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+aMaxParallelRecipes); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, false, aFluidInputs, aItemInputs)) { - break; - } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - log("Broke at "+parallelRecipes+"."); - if (parallelRecipes == 0) { - log("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 4; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - - int aMatterProduced = 0; - int aAmplifierProduced = 0; - int aScrapUsed = 0; - int aAmplifierUsed = 0; - - for (int i=0; i<parallelRecipes; i++) { - //Logger.INFO("Trying to bump stats "+i); - for (ItemStack aInput : tRecipe.mInputs) { - if (aInput != null && GT_Utility.areStacksEqual(aInput, mScrap[0], true)) { - aScrapUsed += aInput.stackSize; - //Logger.INFO("Found Scrap to use."); - } - } - for (FluidStack aInput : tRecipe.mFluidInputs) { - if (aInput != null && GT_Utility.areFluidsEqual(aInput, mUU[0], true)) { - aAmplifierUsed += aInput.amount; - //Logger.INFO("Found UU-A to use."); - } - } - for (FluidStack aOutput : tRecipe.mFluidOutputs) { - if (aOutput != null && GT_Utility.areFluidsEqual(aOutput, mUU[0], true)) { - aAmplifierProduced += aOutput.amount; - //Logger.INFO("Found UU-A as Output."); - } - if (aOutput != null && GT_Utility.areFluidsEqual(aOutput, mUU[1], true)) { - aMatterProduced += aOutput.amount; - //Logger.INFO("Found UU-M as Output."); - } - } - } - - this.mMatterProduced += aMatterProduced; - this.mAmplifierProduced += aAmplifierProduced; - this.mScrapUsed += aScrapUsed; - this.mAmplifierUsed += aAmplifierUsed; - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - log("GOOD RETURN - 1"); - return true; - - } - - @Override - public int getMaxParallelRecipes() { - return this.mMode == MODE_SCRAP ? 64 : 8 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); - } - - @Override - public int getEuDiscountForParallelism() { - return 80; - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - int aMode = this.mMode + 1; - if (aMode > 1) { - this.mMode = MODE_UU; - PlayerUtils.messagePlayer(aPlayer, "Mode ["+this.mMode+"]: Matter/AmpliFabricator"); - } - else if (aMode == 1) { - this.mMode = MODE_SCRAP; - PlayerUtils.messagePlayer(aPlayer, "Mode ["+this.mMode+"]: Recycler"); - } - else { - this.mMode = MODE_SCRAP; - PlayerUtils.messagePlayer(aPlayer, "Mode ["+this.mMode+"]: Recycler"); - } - GT_Recipe_Map r = this.getRecipeMap(); - final Collection<GT_Recipe> x = r.mRecipeList; - Logger.INFO("Dumping " + r.mUnlocalizedName + " Recipes for Debug. size: "+x.size()); - for (final GT_Recipe newBo : x) { - Logger.INFO("========================"); - Logger.INFO("Dumping Input: " + ItemUtils.getArrayStackNames(newBo.mInputs)); - Logger.INFO("Dumping Inputs " + ItemUtils.getFluidArrayStackNames(newBo.mFluidInputs)); - Logger.INFO("Dumping Duration: " + newBo.mDuration); - Logger.INFO("Dumping EU/t: " + newBo.mEUt); - Logger.INFO("Dumping Output: " + ItemUtils.getArrayStackNames(newBo.mOutputs)); - Logger.INFO("Dumping Output: " + ItemUtils.getFluidArrayStackNames(newBo.mFluidOutputs)); - Logger.INFO("========================"); - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mScrapProduced", mScrapProduced); - aNBT.setInteger("mAmplifierProduced", mAmplifierProduced); - aNBT.setInteger("mMatterProduced", mMatterProduced); - aNBT.setInteger("mScrapUsed", mScrapUsed); - aNBT.setInteger("mAmplifierUsed", mAmplifierUsed); - aNBT.setInteger("mMode", mMode); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mScrapProduced = aNBT.getInteger("mScrapProduced"); - mAmplifierProduced = aNBT.getInteger("mAmplifierProduced"); - mMatterProduced = aNBT.getInteger("mMatterProduced"); - mScrapUsed = aNBT.getInteger("mScrapUsed"); - mAmplifierUsed = aNBT.getInteger("mAmplifierUsed"); - mMode = aNBT.getInteger("mMode"); - super.loadNBTData(aNBT); - } - -}
\ No newline at end of file +public class GregtechMetaTileEntity_MassFabricator + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_MassFabricator> implements ISurvivalConstructable { + + public static int sUUAperUUM = 1; + public static int sUUASpeedBonus = 4; + public static int sDurationMultiplier = 3200; + + public int mMatterProduced = 0; + public int mScrapProduced = 0; + public int mAmplifierProduced = 0; + public int mScrapUsed = 0; + public int mAmplifierUsed = 0; + + public static String mCasingName1 = "Matter Fabricator Casing"; + public static String mCasingName2 = "Containment Casing"; + public static String mCasingName3 = "Matter Generation Coil"; + + private int mMode = 0; + + private static final int MODE_SCRAP = 1; + private static final int MODE_UU = 0; + + public static boolean sRequiresUUA = false; + private static FluidStack[] mUU = new FluidStack[2]; + private static ItemStack mScrap[] = new ItemStack[2]; + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_MassFabricator> STRUCTURE_DEFINITION = null; + + public int getAmplifierUsed() { + return this.mAmplifierUsed; + } + + public int getMatterProduced() { + return this.mMatterProduced; + } + + public int getScrapProduced() { + return this.mScrapProduced; + } + + public GregtechMetaTileEntity_MassFabricator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_MassFabricator(final String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Mass Fabricator / Recycler"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Matter Fabricator") + .addInfo("Speed: +0% | EU Usage: 80%") + .addInfo("Parallel: Scrap = 64 | UU = 8 * Tier") + .addInfo("Produces UU-A, UU-M & Scrap") + .addInfo("Change mode with screwdriver") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 4, 5, true) + .addController("Front Center") + .addCasingInfo(mCasingName3, 9) + .addCasingInfo(mCasingName2, 24) + .addCasingInfo(mCasingName1, 40) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_MatterFab_Active_Animated; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_MatterFab_Animated; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(9); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MatterFabricator"; + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_MatterFab(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MatterFabricator.png"); + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_MatterFab(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void onConfigLoad(final GT_Config aConfig) { + super.onConfigLoad(aConfig); + sDurationMultiplier = aConfig.get( + ConfigCategories.machineconfig, "Massfabricator.UUM_Duration_Multiplier", sDurationMultiplier); + sUUAperUUM = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_per_UUM", sUUAperUUM); + sUUASpeedBonus = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_Speed_Bonus", sUUASpeedBonus); + sRequiresUUA = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_Requirement", sRequiresUUA); + // Materials.UUAmplifier.mChemicalFormula = ("Mass Fabricator Eff/Speed Bonus: x" + sUUASpeedBonus); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + ArrayList<ItemStack> tItems = getStoredInputs(); + ArrayList<FluidStack> tFluids = getStoredFluids(); + ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); + FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); + init(); + return checkRecipeGeneric(tItemInputs, tFluidInputs, 4, 80, 00, 10000); + } + + public static boolean sInit = false; + + public static void init() { + if (!sInit) { + if (mScrap[0] == null) { + mScrap[0] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrap")); + } + if (mScrap[1] == null) { + mScrap[1] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrapbox")); + } + if (mUU[0] == null) { + mUU[0] = Materials.UUAmplifier.getFluid(100); + } + if (mUU[1] == null) { + mUU[1] = Materials.UUMatter.getFluid(100); + } + sInit = true; + } + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_MassFabricator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_MassFabricator>builder() + .addShape(mName, transpose(new String[][] { + {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, + {"CGGGC", "G---G", "G---G", "G---G", "CGGGC"}, + {"CGGGC", "G---G", "G---G", "G---G", "CGGGC"}, + {"CC~CC", "CHHHC", "CHHHC", "CHHHC", "CCCCC"}, + })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_MassFabricator.class) + .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(9)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 9)))) + .addElement('H', ofBlock(ModBlocks.blockCasingsMisc, 8)) + .addElement('G', ofBlock(ModBlocks.blockCasings3Misc, 15)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 2, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 2, 3, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 3, 0) && mCasing >= 40 && checkHatch(); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiMassFabricator; + } + + @Override + public int getAmountOfOutputs() { + return 10; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_MassFabricator(this.mName); + } + + /** + * Special Recipe Handling + */ + @Override + public GT_Recipe_Map getRecipeMap() { + return this.mMode == MODE_SCRAP + ? GT_Recipe_Map.sRecyclerRecipes + : GTPP_Recipe.GTPP_Recipe_Map.sMatterFab2Recipes; + // return Recipe_GT.Gregtech_Recipe_Map.sMatterFab2Recipes; + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + if (this.mMode == MODE_SCRAP) { + return checkRecipeScrap( + aItemInputs, + aFluidInputs, + getMaxParallelRecipes(), + getEuDiscountForParallelism(), + aSpeedBonusPercent, + aOutputChanceRoll); + } else { + return checkRecipeUU( + aItemInputs, + aFluidInputs, + getMaxParallelRecipes(), + getEuDiscountForParallelism(), + aSpeedBonusPercent, + aOutputChanceRoll); + } + } + + public boolean checkRecipeScrap( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + int aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + + if (aItemInputs == null || aItemInputs.length <= 0) { + return false; + } + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + ItemStack aPotentialOutput = GT_ModHandler.getRecyclerOutput(GT_Utility.copyAmount(1, aItemInputs[0]), 0); + GT_Recipe tRecipe = new GTPP_Recipe( + false, + new ItemStack[] {GT_Utility.copyAmount(1, aItemInputs[0])}, + aPotentialOutput == null ? null : new ItemStack[] {aPotentialOutput}, + null, + new int[] {2000}, + null, + null, + 40, + MaterialUtils.getVoltageForTier(1), + 0); + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and + // considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ". "); + tTotalEUt += tRecipeEUt; + } + log("Broke at " + parallelRecipes + "."); + if (parallelRecipes > 0) { + // -- Try not to fail after this point - inputs have already been + // consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe + // duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + this.mEUt = (int) Math.ceil(tTotalEUt); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 4; + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + tOutputItems = removeNulls(tOutputItems); + for (ItemStack aOutputStack : tOutputItems) { + if (aOutputStack != null) { + mScrapProduced += aOutputStack.stackSize; + } + } + // Sanitize item stack size, splitting any stacks greater than max + // stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + // Commit outputs + this.mOutputItems = tOutputItems; + updateSlots(); + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + return true; + } + return false; + } + + public boolean checkRecipeUU( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + int aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + aMaxParallelRecipes); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, false, aFluidInputs, aItemInputs)) { + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + log("Broke at " + parallelRecipes + "."); + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 4; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + int aMatterProduced = 0; + int aAmplifierProduced = 0; + int aScrapUsed = 0; + int aAmplifierUsed = 0; + + for (int i = 0; i < parallelRecipes; i++) { + // Logger.INFO("Trying to bump stats "+i); + for (ItemStack aInput : tRecipe.mInputs) { + if (aInput != null && GT_Utility.areStacksEqual(aInput, mScrap[0], true)) { + aScrapUsed += aInput.stackSize; + // Logger.INFO("Found Scrap to use."); + } + } + for (FluidStack aInput : tRecipe.mFluidInputs) { + if (aInput != null && GT_Utility.areFluidsEqual(aInput, mUU[0], true)) { + aAmplifierUsed += aInput.amount; + // Logger.INFO("Found UU-A to use."); + } + } + for (FluidStack aOutput : tRecipe.mFluidOutputs) { + if (aOutput != null && GT_Utility.areFluidsEqual(aOutput, mUU[0], true)) { + aAmplifierProduced += aOutput.amount; + // Logger.INFO("Found UU-A as Output."); + } + if (aOutput != null && GT_Utility.areFluidsEqual(aOutput, mUU[1], true)) { + aMatterProduced += aOutput.amount; + // Logger.INFO("Found UU-M as Output."); + } + } + } + + this.mMatterProduced += aMatterProduced; + this.mAmplifierProduced += aAmplifierProduced; + this.mScrapUsed += aScrapUsed; + this.mAmplifierUsed += aAmplifierUsed; + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + @Override + public int getMaxParallelRecipes() { + return this.mMode == MODE_SCRAP ? 64 : 8 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); + } + + @Override + public int getEuDiscountForParallelism() { + return 80; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + int aMode = this.mMode + 1; + if (aMode > 1) { + this.mMode = MODE_UU; + PlayerUtils.messagePlayer(aPlayer, "Mode [" + this.mMode + "]: Matter/AmpliFabricator"); + } else if (aMode == 1) { + this.mMode = MODE_SCRAP; + PlayerUtils.messagePlayer(aPlayer, "Mode [" + this.mMode + "]: Recycler"); + } else { + this.mMode = MODE_SCRAP; + PlayerUtils.messagePlayer(aPlayer, "Mode [" + this.mMode + "]: Recycler"); + } + GT_Recipe_Map r = this.getRecipeMap(); + final Collection<GT_Recipe> x = r.mRecipeList; + Logger.INFO("Dumping " + r.mUnlocalizedName + " Recipes for Debug. size: " + x.size()); + for (final GT_Recipe newBo : x) { + Logger.INFO("========================"); + Logger.INFO("Dumping Input: " + ItemUtils.getArrayStackNames(newBo.mInputs)); + Logger.INFO("Dumping Inputs " + ItemUtils.getFluidArrayStackNames(newBo.mFluidInputs)); + Logger.INFO("Dumping Duration: " + newBo.mDuration); + Logger.INFO("Dumping EU/t: " + newBo.mEUt); + Logger.INFO("Dumping Output: " + ItemUtils.getArrayStackNames(newBo.mOutputs)); + Logger.INFO("Dumping Output: " + ItemUtils.getFluidArrayStackNames(newBo.mFluidOutputs)); + Logger.INFO("========================"); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mScrapProduced", mScrapProduced); + aNBT.setInteger("mAmplifierProduced", mAmplifierProduced); + aNBT.setInteger("mMatterProduced", mMatterProduced); + aNBT.setInteger("mScrapUsed", mScrapUsed); + aNBT.setInteger("mAmplifierUsed", mAmplifierUsed); + aNBT.setInteger("mMode", mMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mScrapProduced = aNBT.getInteger("mScrapProduced"); + mAmplifierProduced = aNBT.getInteger("mAmplifierProduced"); + mMatterProduced = aNBT.getInteger("mMatterProduced"); + mScrapUsed = aNBT.getInteger("mScrapUsed"); + mAmplifierUsed = aNBT.getInteger("mAmplifierUsed"); + mMode = aNBT.getInteger("mMode"); + super.loadNBTData(aNBT); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java index c404efd1cb..a83f19fa74 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java @@ -1,5 +1,13 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.filterByMTETier; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -20,240 +28,213 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.Gregtech import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.filterByMTETier; - -public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Refinery> implements ISurvivalConstructable { - - private int mCasing; - private IStructureDefinition<GregtechMetaTileEntity_Refinery> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_Refinery(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_Refinery(final String aName) { - super(aName); - } - - @Override - public String getMachineType() { - return "Fuel Refinery"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Fission Fuel Processing Unit") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(3, 9, 3, false) - .addController("Bottom Center") - .addCasingInfo("Hastelloy-X Structural Casing", 7) - .addCasingInfo("Incoloy-DS Fluid Containment Block", 5) - .addCasingInfo("Zeron-100 Reactor Shielding", 4) - .addCasingInfo("Hastelloy-N Sealant Blocks", 17) - .addInputHatch("Base platform", 1) - .addOutputHatch("Base platform", 1) - .addOutputBus("Base platform", 1) - .addMufflerHatch("Base platform", 1) - .addMaintenanceHatch("Base platform", 1) - .addEnergyHatch("Base platform", 1) - .addStructureInfo("Muffler's Tier must be LuV+") - .addStructureInfo("4x Input Hatches, 2x Output Hatches, 1x Output Bus") - .addStructureInfo("1x Muffler, 1x Maintenance Hatch, 1x Energy Hatch") - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - protected IIconContainer getActiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER; - } - - @Override - protected int getCasingTextureId() { - return TAE.GTPP_INDEX(18); - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return "MatterFabricator"; - } - - @Override - public GT_Recipe_Map getRecipeMap() { - return GTPP_Recipe.GTPP_Recipe_Map.sFissionFuelProcessing; - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - //this.resetRecipeMapForAllInputHatches(); - for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { - g.mRecipeMap = null; - } - boolean ab = super.checkRecipeGeneric(); - //Logger.INFO("Did Recipe? "+ab); - return ab; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public boolean addMufflerToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler && ((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity).mTier >= 6) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_Refinery> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Refinery>builder() - .addShape(mName, transpose(new String[][]{ - {" ", " N ", " "}, - {" N ", "NIN", " N "}, - {" N ", "NIN", " N "}, - {" N ", "NIN", " N "}, - {" Z ", "ZIZ", " Z "}, - {" N ", "NIN", " N "}, - {"XXX", "XXX", "XXX"}, - {"X~X", "XXX", "XXX"}, - })) - .addElement( - 'X', - ofChain( - buildHatchAdder(GregtechMetaTileEntity_Refinery.class) - .atLeast(Energy, Maintenance, OutputHatch, OutputBus, InputHatch) - .casingIndex(TAE.GTPP_INDEX(18)) - .dot(1) - .build(), - buildHatchAdder(GregtechMetaTileEntity_Refinery.class) - .atLeast(Muffler) - .adder(GregtechMetaTileEntity_Refinery::addMufflerToMachineList) - .hatchItemFilterAnd(t -> filterByMTETier(6, Integer.MAX_VALUE)) - .casingIndex(TAE.GTPP_INDEX(18)) - .dot(1) - .build(), - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasings2Misc, 2 - ) - ) - ) - ) - .addElement( - 'I', - ofBlock( - ModBlocks.blockCasings2Misc, 3 - ) - ) - .addElement( - 'N', - ofBlock( - ModBlocks.blockCasings2Misc, 1 - ) - ) - .addElement( - 'Z', - ofBlock( - ModBlocks.blockCasingsMisc, 13 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 1, 7, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 1, 7, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - if (checkPiece(mName, 1, 7, 0) && mCasing >= 7) { - if (this.mInputHatches.size() == 4 && this.mOutputHatches.size() == 2 && - this.mOutputBusses.size() == 1 && this.mMufflerHatches.size() == 1 && - this.mMaintenanceHatches.size() == 1 && this.mEnergyHatches.size() == 1) { - this.resetRecipeMapForAllInputHatches(this.getRecipeMap()); - return true; - } - } - return false; - } - - @Override - public boolean isCorrectMachinePart(final ItemStack aStack) { - return true; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiRefinery; - } - - @Override - public int getDamageToComponent(final ItemStack aStack) { - return 0; - } - - public int getAmountOfOutputs() { - return 5; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_Refinery(this.mName); - } - +public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Refinery> + implements ISurvivalConstructable { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_Refinery> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Refinery(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Refinery(final String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Fuel Refinery"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Fission Fuel Processing Unit") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 9, 3, false) + .addController("Bottom Center") + .addCasingInfo("Hastelloy-X Structural Casing", 7) + .addCasingInfo("Incoloy-DS Fluid Containment Block", 5) + .addCasingInfo("Zeron-100 Reactor Shielding", 4) + .addCasingInfo("Hastelloy-N Sealant Blocks", 17) + .addInputHatch("Base platform", 1) + .addOutputHatch("Base platform", 1) + .addOutputBus("Base platform", 1) + .addMufflerHatch("Base platform", 1) + .addMaintenanceHatch("Base platform", 1) + .addEnergyHatch("Base platform", 1) + .addStructureInfo("Muffler's Tier must be LuV+") + .addStructureInfo("4x Input Hatches, 2x Output Hatches, 1x Output Bus") + .addStructureInfo("1x Muffler, 1x Maintenance Hatch, 1x Energy Hatch") + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(18); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MatterFabricator"; + } + + @Override + public GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sFissionFuelProcessing; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + // this.resetRecipeMapForAllInputHatches(); + for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { + g.mRecipeMap = null; + } + boolean ab = super.checkRecipeGeneric(); + // Logger.INFO("Did Recipe? "+ab); + return ab; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean addMufflerToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler + && ((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity).mTier >= 6) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Refinery> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Refinery>builder() + .addShape(mName, transpose(new String[][] { + {" ", " N ", " "}, + {" N ", "NIN", " N "}, + {" N ", "NIN", " N "}, + {" N ", "NIN", " N "}, + {" Z ", "ZIZ", " Z "}, + {" N ", "NIN", " N "}, + {"XXX", "XXX", "XXX"}, + {"X~X", "XXX", "XXX"}, + })) + .addElement( + 'X', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_Refinery.class) + .atLeast(Energy, Maintenance, OutputHatch, OutputBus, InputHatch) + .casingIndex(TAE.GTPP_INDEX(18)) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_Refinery.class) + .atLeast(Muffler) + .adder(GregtechMetaTileEntity_Refinery::addMufflerToMachineList) + .hatchItemFilterAnd(t -> filterByMTETier(6, Integer.MAX_VALUE)) + .casingIndex(TAE.GTPP_INDEX(18)) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 2)))) + .addElement('I', ofBlock(ModBlocks.blockCasings2Misc, 3)) + .addElement('N', ofBlock(ModBlocks.blockCasings2Misc, 1)) + .addElement('Z', ofBlock(ModBlocks.blockCasingsMisc, 13)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 7, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 7, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + if (checkPiece(mName, 1, 7, 0) && mCasing >= 7) { + if (this.mInputHatches.size() == 4 + && this.mOutputHatches.size() == 2 + && this.mOutputBusses.size() == 1 + && this.mMufflerHatches.size() == 1 + && this.mMaintenanceHatches.size() == 1 + && this.mEnergyHatches.size() == 1) { + this.resetRecipeMapForAllInputHatches(this.getRecipeMap()); + return true; + } + } + return false; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiRefinery; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public int getAmountOfOutputs() { + return 5; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Refinery(this.mName); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java index 7d7789b0b6..1a98737700 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java @@ -1,6 +1,12 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -23,6 +29,7 @@ import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.tileentities.misc.TileEntitySolarHeater; +import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -32,703 +39,787 @@ import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static gregtech.api.enums.GT_HatchElement.InputHatch; -import static gregtech.api.enums.GT_HatchElement.Maintenance; -import static gregtech.api.enums.GT_HatchElement.OutputHatch; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; - -public class GregtechMetaTileEntity_SolarTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_SolarTower> implements ISurvivalConstructable { - - //862 - private static final int mCasingTextureID = TAE.getIndexFromPage(3, 9); - private int mHeatLevel = 0; - private int mCasing1; - private int mCasing2; - private int mCasing3; - private int mCasing4; - - - public ArrayList<TileEntitySolarHeater> mSolarHeaters = new ArrayList<TileEntitySolarHeater>(); - - - public GregtechMetaTileEntity_SolarTower(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_SolarTower(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_SolarTower(this.mName); - } - - @Override - public String getMachineType() { - return "Solar Tower"; - } - - @Override - protected final GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Contributing Green Energy towards the future") - .addInfo("Input: "+MISC_MATERIALS.SOLAR_SALT_COLD.getLocalizedName()) - .addInfo("Output: "+MISC_MATERIALS.SOLAR_SALT_HOT.getLocalizedName()) - .addInfo("Surround with rings of Solar Heaters") - .addInfo("Each ring increases tier") - .addInfo("1 = 1, 2 = 2, 3 = 4, 4 = 8, 5 = 16") - .addInfo("Tier decreases heating time and allows more salt to be processed") - .addSeparator() - .beginStructureBlock(6, 27, 6, false) - .addController("Top Middle") - .addCasingInfo("Structural Solar Casing", 229) - .addCasingInfo("Thermally Insulated Casing", 60) - .addCasingInfo("Salt Containment Casing", 66) - .addCasingInfo("Thermal Containment Casing", 60) - .addInputHatch("Any 2 dot hint(min 1)", 2) - .addOutputHatch("Any 2 dot hint(min 1)", 2) - .addMaintenanceHatch("Any 2 dot hint", 2) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - private static final String STRUCTURE_PIECE_BASE = "base"; - private static final String STRUCTURE_PIECE_TOWER = "tower"; - private static final String STRUCTURE_PIECE_TOP = "top"; - - private static final String[] STRUCTURE_PIECE_SOLAR_HEATER_RING = {"ring1", "ring2", "ring3", "ring4", "ring5"}; - private static final String SOLAR_HEATER_RING_1 = STRUCTURE_PIECE_SOLAR_HEATER_RING[0]; - private static final String SOLAR_HEATER_RING_2 = STRUCTURE_PIECE_SOLAR_HEATER_RING[1]; - private static final String SOLAR_HEATER_RING_3 = STRUCTURE_PIECE_SOLAR_HEATER_RING[2]; - private static final String SOLAR_HEATER_RING_4 = STRUCTURE_PIECE_SOLAR_HEATER_RING[3]; - private static final String SOLAR_HEATER_RING_5 = STRUCTURE_PIECE_SOLAR_HEATER_RING[4]; - - private static final ClassValue<IStructureDefinition<GregtechMetaTileEntity_SolarTower>> STRUCTURE_DEFINITION = new ClassValue<IStructureDefinition<GregtechMetaTileEntity_SolarTower>>() { - @Override - protected IStructureDefinition<GregtechMetaTileEntity_SolarTower> computeValue(Class<?> type) { - return StructureDefinition.<GregtechMetaTileEntity_SolarTower>builder() - - // s = salt - // c = thermal containment - // i = thermal insulated - // t = solar structural - // h = hatch - // g = solar heater - - .addShape(STRUCTURE_PIECE_TOP, (new String[][]{ - {" ", " ", " ~ ", " ", " "}, - {" ", " s ", " sss ", " s ", " "}, - {" c ", " ccc ", "ccscc", " ccc ", " c "}, - {" c ", " ccc ", "ccscc", " ccc ", " c "}, - {" c ", " ccc ", "ccscc", " ccc ", " c "}, - {" c ", " ccc ", "ccscc", " ccc ", " c "}, - {" c ", " ccc ", "ccscc", " ccc ", " c "}, - })) - .addShape(STRUCTURE_PIECE_TOWER, (new String[][]{ - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - {" i ", "isi", " i "}, - })) - .addShape(STRUCTURE_PIECE_BASE, (new String[][]{ - {" ", " ", " t ", " ttt ", " ttstt ", " ttssstt ", " ttstt ", " ttt ", " t ", " ", " "}, - {" ", " ", " t ", " ttt ", " tssst ", " ttssstt ", " tssst ", " ttt ", " t ", " ", " "}, - {" ", " t ", " ttt ", " ttttt ", " ttssstt ", " tttsssttt ", " ttssstt ", " ttttt ", " ttt ", " t ", " "}, - {" ", " t ", " ttt ", " ttttt ", " ttssstt ", " tttsssttt ", " ttssstt ", " ttttt ", " ttt ", " t ", " "}, - {" hhh ", " ttttt ", " ttttttt ", " ttttttttt ", "htttsssttth", "htttsssttth", "htttsssttth", " ttttttttt ", " ttttttt ", " ttttt ", " hhh "}, - {" hhh ", " ttttt ", " ttttttt ", " ttttttttt ", "httttttttth", "httttttttth", "httttttttth", " ttttttttt ", " ttttttt ", " ttttt ", " hhh "}, - })) - - - .addShape(SOLAR_HEATER_RING_1, (new String[][]{ - { - " ggggg ", - " g g ", - " g g ", - " g g ", - " g g ", - "g g", - "g g", - "g g", - "g g", - "g g", - " g g ", - " g g ", - " g g ", - " g g ", - " ggggg ", - }})) - .addShape(SOLAR_HEATER_RING_2, (new String[][]{ - { - " ggggggggg ", - " g g ", - " g g ", - " g g ", - " g g ", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - " g g ", - " g g ", - " g g ", - " g g ", - " ggggggggg ", - }})) - .addShape(SOLAR_HEATER_RING_3, (new String[][]{ - { - " ggggggggggggg ", - " g g ", - " g g ", - " g g ", - " g g ", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - " g g ", - " g g ", - " g g ", - " g g ", - " ggggggggggggg ", - }})) - .addShape(SOLAR_HEATER_RING_4, (new String[][]{ - { - " ggggggggggggggggg ", - " g g ", - " g g ", - " g g ", - " g g ", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - " g g ", - " g g ", - " g g ", - " g g ", - " ggggggggggggggggg ", - }})) - .addShape(SOLAR_HEATER_RING_5, (new String[][]{ - { - " ggggggggggggggggggggg ", - " g g ", - " g g ", - " g g ", - " g g ", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - "g g", - " g g ", - " g g ", - " g g ", - " g g ", - " ggggggggggggggggggggg ", - }})) - - .addElement('g', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_SolarTower.class) - .hatchClass(TileEntitySolarHeater.class) - .adder(GregtechMetaTileEntity_SolarTower::addSolarHeater) - // use a positive casing index to make adder builder happy - .casingIndex(1) - .dot(1) - .continueIfSuccess() - .build())) - .addElement('t', lazy(t -> onElementPass(x -> ++x.mCasing1, ofBlock(t.getCasingBlock(), t.getCasingMeta())))) - .addElement('i', lazy(t -> onElementPass(x -> ++x.mCasing2, ofBlock(t.getCasingBlock(), t.getCasingMeta2())))) - .addElement('s', lazy(t -> onElementPass(x -> ++x.mCasing3, ofBlock(t.getCasingBlock(), t.getCasingMeta3())))) - .addElement('c', lazy(t -> onElementPass(x -> ++x.mCasing4, ofBlock(t.getCasingBlock2(), t.getCasingMeta4())))) - .addElement('h', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_SolarTower.class) - .atLeast(InputHatch, OutputHatch, Maintenance) - .casingIndex(t.getCasingTextureIndex()) - .dot(2) - .buildAndChain(onElementPass(x -> ++x.mCasing1, ofBlock(t.getCasingBlock(), t.getCasingMeta())))) - ) - .build(); - } - }; - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - resetSolarHeaters(); - this.mMaintenanceHatches.clear(); - this.mInputHatches.clear(); - this.mOutputHatches.clear(); - mCasing1 = 0; - mCasing2 = 0; - mCasing3 = 0; - mCasing4 = 0; - - boolean aStructureTop = checkPiece(STRUCTURE_PIECE_TOP, 2, 2, 0); - log("Top Check: "+aStructureTop); - boolean aStructureTower = checkPiece(STRUCTURE_PIECE_TOWER, 1, 1, -7); - log("Tower Check: "+aStructureTower); - boolean aStructureBase = checkPiece(STRUCTURE_PIECE_BASE, 5, 5, -22); - log("Base Check: "+aStructureBase); - boolean aCasingCount1 = mCasing1 >= 229; - boolean aCasingCount2 = mCasing2 == 60; - boolean aCasingCount3 = mCasing3 == 66; - boolean aCasingCount4 = mCasing4 == 60; - boolean aAllStructure = aStructureTop && aStructureTower && aStructureBase; - boolean aAllCasings = aCasingCount1 && aCasingCount2 && aCasingCount3 && aCasingCount4; - if (!aAllCasings || !aAllStructure || - mMaintenanceHatches.size() != 1 || - mInputHatches.size() < 1 || - mOutputHatches.size() < 1 - ) { - log("Bad Hatches - Solar Heaters: "+mSolarHeaters.size()+ - ", Maint: "+mMaintenanceHatches.size()+ - ", Input Hatches: "+mInputHatches.size()+ - ", Output Hatches: "+mOutputHatches.size()+ - ", Top: "+aStructureTop+ - ", Tower: "+aStructureTower+ - ", Base: "+aStructureBase+ - ", Casing Count: "+aCasingCount1+" | Found: "+mCasing1+ - ", Casing Count: "+aCasingCount2+" | Found: "+mCasing2+ - ", Casing Count: "+aCasingCount3+" | Found: "+mCasing3+ - ", Casing Count: "+aCasingCount4+" | Found: "+mCasing4); - return false; - } - log("Built "+this.getLocalName()+" with "+mCasing1+" Structural Solar casings, "+mCasing2+" Thermally Insulated casings, "+mCasing3+" Salt Containment casings, "+mCasing4+" Thermal Containment casings."); - return aAllCasings && aAllStructure; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - // Tower - buildPiece(STRUCTURE_PIECE_TOP, stackSize, hintsOnly, 2, 2, 0); - buildPiece(STRUCTURE_PIECE_TOWER, stackSize, hintsOnly, 1, 1, -7); - buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 5, 5, -22); - - //Solar Heaters - if (stackSize.stackSize >= 1) { - buildPiece(SOLAR_HEATER_RING_1, stackSize, hintsOnly, 7, 7, -27); - if (stackSize.stackSize >= 2) { - buildPiece(SOLAR_HEATER_RING_2, stackSize, hintsOnly, 9, 9, -27); - if (stackSize.stackSize >= 3) { - buildPiece(SOLAR_HEATER_RING_3, stackSize, hintsOnly, 11, 11, -27); - if (stackSize.stackSize >= 4) { - buildPiece(SOLAR_HEATER_RING_4, stackSize, hintsOnly, 13, 13, -27); - if (stackSize.stackSize >= 5) { - buildPiece(SOLAR_HEATER_RING_5, stackSize, hintsOnly, 15, 15, -27); - } - } - } - } - } - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - int built; - int realBudget = elementBudget >= 200 ? elementBudget : Math.min(200, elementBudget * 2); - // Tower - built = survivialBuildPiece(STRUCTURE_PIECE_TOP, stackSize, 2, 2, 0, realBudget, source, actor, false, true); - if (built >= 0) return built; - built = survivialBuildPiece(STRUCTURE_PIECE_TOWER, stackSize, 1, 1, -7, realBudget, source, actor, false, true); - if (built >= 0) return built; - built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 5, 5, -22, realBudget, source, actor, false, true); - if (built >= 0) return built; - - //Solar Heaters - if (stackSize.stackSize < 1) return -1; - built = survivialBuildPiece(SOLAR_HEATER_RING_1, stackSize, 7, 7, -27, realBudget, source, actor, false, true); - if (built >= 0) return built; - if (stackSize.stackSize < 2) return -1; - built = survivialBuildPiece(SOLAR_HEATER_RING_2, stackSize, 9, 9, -27, realBudget, source, actor, false, true); - if (built >= 0) return built; - if (stackSize.stackSize < 3) return -1; - built = survivialBuildPiece(SOLAR_HEATER_RING_3, stackSize, 11, 11, -27, realBudget, source, actor, false, true); - if (built >= 0) return built; - if (stackSize.stackSize < 4) return -1; - built = survivialBuildPiece(SOLAR_HEATER_RING_4, stackSize, 13, 13, -27, realBudget, source, actor, false, true); - if (built >= 0) return built; - if (stackSize.stackSize < 5) return -1; - return survivialBuildPiece(SOLAR_HEATER_RING_5, stackSize, 15, 15, -27, realBudget, source, actor, false, true); - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_SolarTower> getStructureDefinition() { - return STRUCTURE_DEFINITION.get(getClass()); - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(212)); - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == 0 || aSide == 1) { - if (aActive) - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), - TextureFactory.builder().addIcon(TexturesGtBlock.Overlay_Machine_Controller_Default_Active).extFacing().build()}; - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), - TextureFactory.builder().addIcon(TexturesGtBlock.Overlay_Machine_Controller_Default).extFacing().build()}; - } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12))}; - } - - @Override - public boolean hasSlotInGUI() { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return null; - } - - private int getHeaterTier() { - int aSolarHeaterCounter = this.mSolarHeaters.size(); - if (aSolarHeaterCounter > 0) { - if (aSolarHeaterCounter == 36) { - return 1; - } - else if (aSolarHeaterCounter == 88) { - return 2; - } - else if (aSolarHeaterCounter == 156) { - return 4; - } - else if (aSolarHeaterCounter == 240) { - return 8; - } - else if (aSolarHeaterCounter == 340) { - return 16; - } - } - return 0; - } - - private int getHeaterCountForTier(int aTier) { - switch (aTier) { - case 1: - return 36; - case 2: - return 88; - case 4: - return 156; - case 8: - return 240; - case 16: - return 340; - default: - return 0; - } - } - - public boolean getConnectedSolarReflectors(){ - - this.mSolarHeaters.clear(); - int aRing = 1; - - if (this.mSolarHeaters.size() < 36) { - // 15x15 - boolean aRing1 = checkPiece(SOLAR_HEATER_RING_1, 7, 7, -27); - if (aRing1) { - //log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); - } - } - if (this.mSolarHeaters.size() < 88) { - // 17x17 - boolean aRing2 = checkPiece(SOLAR_HEATER_RING_2, 9, 9, -27); - if (aRing2) { - //log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); - } - } - if (this.mSolarHeaters.size() < 156) { - // 19x19 - boolean aRing3 = checkPiece(SOLAR_HEATER_RING_3, 11, 11, -27); - if (aRing3) { - //log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); - } - } - if (this.mSolarHeaters.size() < 240) { - // 21x21 - boolean aRing4 = checkPiece(SOLAR_HEATER_RING_4, 13, 13, -27); - if (aRing4) { - //log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); - } - } - if (this.mSolarHeaters.size() < 340) { - // 23x23 - boolean aRing5 = checkPiece(SOLAR_HEATER_RING_5, 15, 15, -27); - if (aRing5) { - //log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); - } - } - return mSolarHeaters.size() > 0; - } - - private boolean addSolarHeater(IGregTechTileEntity aTileEntity, int a) { - if (aTileEntity == null) { - return false; - } - else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof TileEntitySolarHeater) { - TileEntitySolarHeater mTile = (TileEntitySolarHeater) aMetaTileEntity; - if (!mTile.hasSolarTower() && mTile.canSeeSky()) { - //Logger.INFO("Found Solar Reflector, Injecting Data."); - mTile.setSolarTower(this); - return this.mSolarHeaters.add(mTile); - } - } - } - return false; - } - - private Fluid mColdSalt = null; - private Fluid mHotSalt = null; - - @Override - public boolean checkRecipe(final ItemStack aStack) { - this.mEfficiencyIncrease = 10; - this.mMaxProgresstime = 100; - - if (this.mSolarHeaters.isEmpty() || this.mSolarHeaters.size() < 340 || this.getTotalRuntimeInTicks() % 200 == 0) { - getConnectedSolarReflectors(); - } - - int aTier = getHeaterTier(); - int aHeaters = getHeaterCountForTier(aTier); - - //Manage Heat every 5s - //Add Heat First, if sources available - if (aHeaters > 0) { - for (int i = 0; i < aHeaters; i++) { - Math.min((this.mHeatLevel += aTier), 20000); - } - } - - //Remove Heat, based on time of day - if (mHeatLevel > 0) { - if (mHeatLevel > 20000) { - this.mHeatLevel = 20000; - } - } - World w = this.getBaseMetaTileEntity().getWorld(); - if (w != null) { - int aRemovalFactor = 0; - if (w.isDaytime()) { - aRemovalFactor = 1; - } - else { - aRemovalFactor = 8; - } - for (int i = 0; i<MathUtils.randInt((aHeaters/10), aHeaters); i++){ - this.mHeatLevel -= aRemovalFactor; - } - } - - if (this.mEfficiency == this.getMaxEfficiency(null) && this.mHeatLevel >= 10000) { - if (mColdSalt == null) { - mColdSalt = MISC_MATERIALS.SOLAR_SALT_COLD.getFluid(); - } - if (mHotSalt == null) { - mHotSalt = MISC_MATERIALS.SOLAR_SALT_HOT.getFluid(); - } - ArrayList<FluidStack> aFluids = this.getStoredFluids(); - for (FluidStack aFluid : aFluids) { - if (aFluid.getFluid().equals(mColdSalt)) { - if (aFluid.amount >= (aTier * 1000)) { - this.depleteInput(FluidUtils.getFluidStack(mColdSalt, (aTier * 1000))); - this.addOutput(FluidUtils.getFluidStack(mHotSalt, (aTier * 1000))); - break; - } - } - } - } - - - return true; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public void startProcess() { - this.sendLoopStart((byte) 1); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerTick(final ItemStack aStack) { - return 0; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - public Block getCasingBlock() { - return ModBlocks.blockSpecialMultiCasings; - } - - public Block getCasingBlock2() { - return ModBlocks.blockCasings2Misc; - } - - public byte getCasingMeta() { - return 6; - } - - - public byte getCasingMeta2() { - return 8; - } - - - public byte getCasingMeta3() { - return 7; - } - - public byte getCasingMeta4() { - return 11; - } - - public byte getCasingTextureIndex() { - return (byte) mCasingTextureID; - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - - - - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("mHeatLevel", mHeatLevel); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - mHeatLevel = aNBT.getInteger("mHeatLevel"); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - // Fix GT bug - if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { - this.getBaseMetaTileEntity().setFrontFacing((byte) 1); - } - } - - @Override - public void onRemoval() { - resetSolarHeaters(); - super.onRemoval(); - } - - private void resetSolarHeaters() { - for (TileEntitySolarHeater aTile : this.mSolarHeaters) { - aTile.clearSolarTower(); - } - this.mSolarHeaters.clear(); - } - - @Override - public String[] getExtraInfoData() { - return new String[] { - "Internal Heat Level: "+this.mHeatLevel, - "Connected Solar Reflectors: "+this.mSolarHeaters.size() - }; - } - +public class GregtechMetaTileEntity_SolarTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_SolarTower> + implements ISurvivalConstructable { + + // 862 + private static final int mCasingTextureID = TAE.getIndexFromPage(3, 9); + private int mHeatLevel = 0; + private int mCasing1; + private int mCasing2; + private int mCasing3; + private int mCasing4; + + public ArrayList<TileEntitySolarHeater> mSolarHeaters = new ArrayList<TileEntitySolarHeater>(); + + public GregtechMetaTileEntity_SolarTower(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_SolarTower(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_SolarTower(this.mName); + } + + @Override + public String getMachineType() { + return "Solar Tower"; + } + + @Override + protected final GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Contributing Green Energy towards the future") + .addInfo("Input: " + MISC_MATERIALS.SOLAR_SALT_COLD.getLocalizedName()) + .addInfo("Output: " + MISC_MATERIALS.SOLAR_SALT_HOT.getLocalizedName()) + .addInfo("Surround with rings of Solar Heaters") + .addInfo("Each ring increases tier") + .addInfo("1 = 1, 2 = 2, 3 = 4, 4 = 8, 5 = 16") + .addInfo("Tier decreases heating time and allows more salt to be processed") + .addSeparator() + .beginStructureBlock(6, 27, 6, false) + .addController("Top Middle") + .addCasingInfo("Structural Solar Casing", 229) + .addCasingInfo("Thermally Insulated Casing", 60) + .addCasingInfo("Salt Containment Casing", 66) + .addCasingInfo("Thermal Containment Casing", 60) + .addInputHatch("Any 2 dot hint(min 1)", 2) + .addOutputHatch("Any 2 dot hint(min 1)", 2) + .addMaintenanceHatch("Any 2 dot hint", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + private static final String STRUCTURE_PIECE_BASE = "base"; + private static final String STRUCTURE_PIECE_TOWER = "tower"; + private static final String STRUCTURE_PIECE_TOP = "top"; + + private static final String[] STRUCTURE_PIECE_SOLAR_HEATER_RING = {"ring1", "ring2", "ring3", "ring4", "ring5"}; + private static final String SOLAR_HEATER_RING_1 = STRUCTURE_PIECE_SOLAR_HEATER_RING[0]; + private static final String SOLAR_HEATER_RING_2 = STRUCTURE_PIECE_SOLAR_HEATER_RING[1]; + private static final String SOLAR_HEATER_RING_3 = STRUCTURE_PIECE_SOLAR_HEATER_RING[2]; + private static final String SOLAR_HEATER_RING_4 = STRUCTURE_PIECE_SOLAR_HEATER_RING[3]; + private static final String SOLAR_HEATER_RING_5 = STRUCTURE_PIECE_SOLAR_HEATER_RING[4]; + + private static final ClassValue<IStructureDefinition<GregtechMetaTileEntity_SolarTower>> STRUCTURE_DEFINITION = + new ClassValue<IStructureDefinition<GregtechMetaTileEntity_SolarTower>>() { + @Override + protected IStructureDefinition<GregtechMetaTileEntity_SolarTower> computeValue(Class<?> type) { + return StructureDefinition.<GregtechMetaTileEntity_SolarTower>builder() + + // s = salt + // c = thermal containment + // i = thermal insulated + // t = solar structural + // h = hatch + // g = solar heater + + .addShape(STRUCTURE_PIECE_TOP, (new String[][] { + {" ", " ", " ~ ", " ", " "}, + {" ", " s ", " sss ", " s ", " "}, + {" c ", " ccc ", "ccscc", " ccc ", " c "}, + {" c ", " ccc ", "ccscc", " ccc ", " c "}, + {" c ", " ccc ", "ccscc", " ccc ", " c "}, + {" c ", " ccc ", "ccscc", " ccc ", " c "}, + {" c ", " ccc ", "ccscc", " ccc ", " c "}, + })) + .addShape(STRUCTURE_PIECE_TOWER, (new String[][] { + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + {" i ", "isi", " i "}, + })) + .addShape(STRUCTURE_PIECE_BASE, (new String[][] { + { + " ", + " ", + " t ", + " ttt ", + " ttstt ", + " ttssstt ", + " ttstt ", + " ttt ", + " t ", + " ", + " " + }, + { + " ", + " ", + " t ", + " ttt ", + " tssst ", + " ttssstt ", + " tssst ", + " ttt ", + " t ", + " ", + " " + }, + { + " ", + " t ", + " ttt ", + " ttttt ", + " ttssstt ", + " tttsssttt ", + " ttssstt ", + " ttttt ", + " ttt ", + " t ", + " " + }, + { + " ", + " t ", + " ttt ", + " ttttt ", + " ttssstt ", + " tttsssttt ", + " ttssstt ", + " ttttt ", + " ttt ", + " t ", + " " + }, + { + " hhh ", + " ttttt ", + " ttttttt ", + " ttttttttt ", + "htttsssttth", + "htttsssttth", + "htttsssttth", + " ttttttttt ", + " ttttttt ", + " ttttt ", + " hhh " + }, + { + " hhh ", + " ttttt ", + " ttttttt ", + " ttttttttt ", + "httttttttth", + "httttttttth", + "httttttttth", + " ttttttttt ", + " ttttttt ", + " ttttt ", + " hhh " + }, + })) + .addShape(SOLAR_HEATER_RING_1, (new String[][] { + { + " ggggg ", + " g g ", + " g g ", + " g g ", + " g g ", + "g g", + "g g", + "g g", + "g g", + "g g", + " g g ", + " g g ", + " g g ", + " g g ", + " ggggg ", + } + })) + .addShape(SOLAR_HEATER_RING_2, (new String[][] { + { + " ggggggggg ", + " g g ", + " g g ", + " g g ", + " g g ", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + " g g ", + " g g ", + " g g ", + " g g ", + " ggggggggg ", + } + })) + .addShape(SOLAR_HEATER_RING_3, (new String[][] { + { + " ggggggggggggg ", + " g g ", + " g g ", + " g g ", + " g g ", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + " g g ", + " g g ", + " g g ", + " g g ", + " ggggggggggggg ", + } + })) + .addShape(SOLAR_HEATER_RING_4, (new String[][] { + { + " ggggggggggggggggg ", + " g g ", + " g g ", + " g g ", + " g g ", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + " g g ", + " g g ", + " g g ", + " g g ", + " ggggggggggggggggg ", + } + })) + .addShape(SOLAR_HEATER_RING_5, (new String[][] { + { + " ggggggggggggggggggggg ", + " g g ", + " g g ", + " g g ", + " g g ", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + "g g", + " g g ", + " g g ", + " g g ", + " g g ", + " ggggggggggggggggggggg ", + } + })) + .addElement('g', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_SolarTower.class) + .hatchClass(TileEntitySolarHeater.class) + .adder(GregtechMetaTileEntity_SolarTower::addSolarHeater) + // use a positive casing index to make adder builder happy + .casingIndex(1) + .dot(1) + .continueIfSuccess() + .build())) + .addElement( + 't', + lazy(t -> onElementPass( + x -> ++x.mCasing1, ofBlock(t.getCasingBlock(), t.getCasingMeta())))) + .addElement( + 'i', + lazy(t -> onElementPass( + x -> ++x.mCasing2, ofBlock(t.getCasingBlock(), t.getCasingMeta2())))) + .addElement( + 's', + lazy(t -> onElementPass( + x -> ++x.mCasing3, ofBlock(t.getCasingBlock(), t.getCasingMeta3())))) + .addElement( + 'c', + lazy(t -> onElementPass( + x -> ++x.mCasing4, ofBlock(t.getCasingBlock2(), t.getCasingMeta4())))) + .addElement('h', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_SolarTower.class) + .atLeast(InputHatch, OutputHatch, Maintenance) + .casingIndex(t.getCasingTextureIndex()) + .dot(2) + .buildAndChain(onElementPass( + x -> ++x.mCasing1, ofBlock(t.getCasingBlock(), t.getCasingMeta()))))) + .build(); + } + }; + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + resetSolarHeaters(); + this.mMaintenanceHatches.clear(); + this.mInputHatches.clear(); + this.mOutputHatches.clear(); + mCasing1 = 0; + mCasing2 = 0; + mCasing3 = 0; + mCasing4 = 0; + + boolean aStructureTop = checkPiece(STRUCTURE_PIECE_TOP, 2, 2, 0); + log("Top Check: " + aStructureTop); + boolean aStructureTower = checkPiece(STRUCTURE_PIECE_TOWER, 1, 1, -7); + log("Tower Check: " + aStructureTower); + boolean aStructureBase = checkPiece(STRUCTURE_PIECE_BASE, 5, 5, -22); + log("Base Check: " + aStructureBase); + boolean aCasingCount1 = mCasing1 >= 229; + boolean aCasingCount2 = mCasing2 == 60; + boolean aCasingCount3 = mCasing3 == 66; + boolean aCasingCount4 = mCasing4 == 60; + boolean aAllStructure = aStructureTop && aStructureTower && aStructureBase; + boolean aAllCasings = aCasingCount1 && aCasingCount2 && aCasingCount3 && aCasingCount4; + if (!aAllCasings + || !aAllStructure + || mMaintenanceHatches.size() != 1 + || mInputHatches.size() < 1 + || mOutputHatches.size() < 1) { + log("Bad Hatches - Solar Heaters: " + mSolarHeaters.size() + ", Maint: " + + mMaintenanceHatches.size() + ", Input Hatches: " + + mInputHatches.size() + ", Output Hatches: " + + mOutputHatches.size() + ", Top: " + + aStructureTop + ", Tower: " + + aStructureTower + ", Base: " + + aStructureBase + ", Casing Count: " + + aCasingCount1 + " | Found: " + mCasing1 + ", Casing Count: " + + aCasingCount2 + " | Found: " + mCasing2 + ", Casing Count: " + + aCasingCount3 + " | Found: " + mCasing3 + ", Casing Count: " + + aCasingCount4 + " | Found: " + mCasing4); + return false; + } + log("Built " + this.getLocalName() + " with " + mCasing1 + " Structural Solar casings, " + mCasing2 + + " Thermally Insulated casings, " + mCasing3 + " Salt Containment casings, " + mCasing4 + + " Thermal Containment casings."); + return aAllCasings && aAllStructure; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + // Tower + buildPiece(STRUCTURE_PIECE_TOP, stackSize, hintsOnly, 2, 2, 0); + buildPiece(STRUCTURE_PIECE_TOWER, stackSize, hintsOnly, 1, 1, -7); + buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 5, 5, -22); + + // Solar Heaters + if (stackSize.stackSize >= 1) { + buildPiece(SOLAR_HEATER_RING_1, stackSize, hintsOnly, 7, 7, -27); + if (stackSize.stackSize >= 2) { + buildPiece(SOLAR_HEATER_RING_2, stackSize, hintsOnly, 9, 9, -27); + if (stackSize.stackSize >= 3) { + buildPiece(SOLAR_HEATER_RING_3, stackSize, hintsOnly, 11, 11, -27); + if (stackSize.stackSize >= 4) { + buildPiece(SOLAR_HEATER_RING_4, stackSize, hintsOnly, 13, 13, -27); + if (stackSize.stackSize >= 5) { + buildPiece(SOLAR_HEATER_RING_5, stackSize, hintsOnly, 15, 15, -27); + } + } + } + } + } + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + int built; + int realBudget = elementBudget >= 200 ? elementBudget : Math.min(200, elementBudget * 2); + // Tower + built = survivialBuildPiece(STRUCTURE_PIECE_TOP, stackSize, 2, 2, 0, realBudget, source, actor, false, true); + if (built >= 0) return built; + built = survivialBuildPiece(STRUCTURE_PIECE_TOWER, stackSize, 1, 1, -7, realBudget, source, actor, false, true); + if (built >= 0) return built; + built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 5, 5, -22, realBudget, source, actor, false, true); + if (built >= 0) return built; + + // Solar Heaters + if (stackSize.stackSize < 1) return -1; + built = survivialBuildPiece(SOLAR_HEATER_RING_1, stackSize, 7, 7, -27, realBudget, source, actor, false, true); + if (built >= 0) return built; + if (stackSize.stackSize < 2) return -1; + built = survivialBuildPiece(SOLAR_HEATER_RING_2, stackSize, 9, 9, -27, realBudget, source, actor, false, true); + if (built >= 0) return built; + if (stackSize.stackSize < 3) return -1; + built = survivialBuildPiece( + SOLAR_HEATER_RING_3, stackSize, 11, 11, -27, realBudget, source, actor, false, true); + if (built >= 0) return built; + if (stackSize.stackSize < 4) return -1; + built = survivialBuildPiece( + SOLAR_HEATER_RING_4, stackSize, 13, 13, -27, realBudget, source, actor, false, true); + if (built >= 0) return built; + if (stackSize.stackSize < 5) return -1; + return survivialBuildPiece(SOLAR_HEATER_RING_5, stackSize, 15, 15, -27, realBudget, source, actor, false, true); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SolarTower> getStructureDefinition() { + return STRUCTURE_DEFINITION.get(getClass()); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(212)); + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == 0 || aSide == 1) { + if (aActive) + return new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + TextureFactory.builder() + .addIcon(TexturesGtBlock.Overlay_Machine_Controller_Default_Active) + .extFacing() + .build() + }; + return new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + TextureFactory.builder() + .addIcon(TexturesGtBlock.Overlay_Machine_Controller_Default) + .extFacing() + .build() + }; + } + return new ITexture[] {Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + private int getHeaterTier() { + int aSolarHeaterCounter = this.mSolarHeaters.size(); + if (aSolarHeaterCounter > 0) { + if (aSolarHeaterCounter == 36) { + return 1; + } else if (aSolarHeaterCounter == 88) { + return 2; + } else if (aSolarHeaterCounter == 156) { + return 4; + } else if (aSolarHeaterCounter == 240) { + return 8; + } else if (aSolarHeaterCounter == 340) { + return 16; + } + } + return 0; + } + + private int getHeaterCountForTier(int aTier) { + switch (aTier) { + case 1: + return 36; + case 2: + return 88; + case 4: + return 156; + case 8: + return 240; + case 16: + return 340; + default: + return 0; + } + } + + public boolean getConnectedSolarReflectors() { + + this.mSolarHeaters.clear(); + int aRing = 1; + + if (this.mSolarHeaters.size() < 36) { + // 15x15 + boolean aRing1 = checkPiece(SOLAR_HEATER_RING_1, 7, 7, -27); + if (aRing1) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + if (this.mSolarHeaters.size() < 88) { + // 17x17 + boolean aRing2 = checkPiece(SOLAR_HEATER_RING_2, 9, 9, -27); + if (aRing2) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + if (this.mSolarHeaters.size() < 156) { + // 19x19 + boolean aRing3 = checkPiece(SOLAR_HEATER_RING_3, 11, 11, -27); + if (aRing3) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + if (this.mSolarHeaters.size() < 240) { + // 21x21 + boolean aRing4 = checkPiece(SOLAR_HEATER_RING_4, 13, 13, -27); + if (aRing4) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + if (this.mSolarHeaters.size() < 340) { + // 23x23 + boolean aRing5 = checkPiece(SOLAR_HEATER_RING_5, 15, 15, -27); + if (aRing5) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + return mSolarHeaters.size() > 0; + } + + private boolean addSolarHeater(IGregTechTileEntity aTileEntity, int a) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof TileEntitySolarHeater) { + TileEntitySolarHeater mTile = (TileEntitySolarHeater) aMetaTileEntity; + if (!mTile.hasSolarTower() && mTile.canSeeSky()) { + // Logger.INFO("Found Solar Reflector, Injecting Data."); + mTile.setSolarTower(this); + return this.mSolarHeaters.add(mTile); + } + } + } + return false; + } + + private Fluid mColdSalt = null; + private Fluid mHotSalt = null; + + @Override + public boolean checkRecipe(final ItemStack aStack) { + this.mEfficiencyIncrease = 10; + this.mMaxProgresstime = 100; + + if (this.mSolarHeaters.isEmpty() + || this.mSolarHeaters.size() < 340 + || this.getTotalRuntimeInTicks() % 200 == 0) { + getConnectedSolarReflectors(); + } + + int aTier = getHeaterTier(); + int aHeaters = getHeaterCountForTier(aTier); + + // Manage Heat every 5s + // Add Heat First, if sources available + if (aHeaters > 0) { + for (int i = 0; i < aHeaters; i++) { + Math.min((this.mHeatLevel += aTier), 20000); + } + } + + // Remove Heat, based on time of day + if (mHeatLevel > 0) { + if (mHeatLevel > 20000) { + this.mHeatLevel = 20000; + } + } + World w = this.getBaseMetaTileEntity().getWorld(); + if (w != null) { + int aRemovalFactor = 0; + if (w.isDaytime()) { + aRemovalFactor = 1; + } else { + aRemovalFactor = 8; + } + for (int i = 0; i < MathUtils.randInt((aHeaters / 10), aHeaters); i++) { + this.mHeatLevel -= aRemovalFactor; + } + } + + if (this.mEfficiency == this.getMaxEfficiency(null) && this.mHeatLevel >= 10000) { + if (mColdSalt == null) { + mColdSalt = MISC_MATERIALS.SOLAR_SALT_COLD.getFluid(); + } + if (mHotSalt == null) { + mHotSalt = MISC_MATERIALS.SOLAR_SALT_HOT.getFluid(); + } + ArrayList<FluidStack> aFluids = this.getStoredFluids(); + for (FluidStack aFluid : aFluids) { + if (aFluid.getFluid().equals(mColdSalt)) { + if (aFluid.amount >= (aTier * 1000)) { + this.depleteInput(FluidUtils.getFluidStack(mColdSalt, (aTier * 1000))); + this.addOutput(FluidUtils.getFluidStack(mHotSalt, (aTier * 1000))); + break; + } + } + } + } + + return true; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockSpecialMultiCasings; + } + + public Block getCasingBlock2() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 6; + } + + public byte getCasingMeta2() { + return 8; + } + + public byte getCasingMeta3() { + return 7; + } + + public byte getCasingMeta4() { + return 11; + } + + public byte getCasingTextureIndex() { + return (byte) mCasingTextureID; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {} + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mHeatLevel", mHeatLevel); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mHeatLevel = aNBT.getInteger("mHeatLevel"); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + // Fix GT bug + if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { + this.getBaseMetaTileEntity().setFrontFacing((byte) 1); + } + } + + @Override + public void onRemoval() { + resetSolarHeaters(); + super.onRemoval(); + } + + private void resetSolarHeaters() { + for (TileEntitySolarHeater aTile : this.mSolarHeaters) { + aTile.clearSolarTower(); + } + this.mSolarHeaters.clear(); + } + + @Override + public String[] getExtraInfoData() { + return new String[] { + "Internal Heat Level: " + this.mHeatLevel, "Connected Solar Reflectors: " + this.mSolarHeaters.size() + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java index 312c58722e..f7e60432c8 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java @@ -1,7 +1,14 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.algae; -import java.util.ArrayList; -import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -28,6 +35,8 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_AlgaeFarm; import ic2.core.init.BlocksItems; import ic2.core.init.InternalName; +import java.util.ArrayList; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; @@ -36,469 +45,479 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static gregtech.api.enums.GT_HatchElement.InputBus; -import static gregtech.api.enums.GT_HatchElement.InputHatch; -import static gregtech.api.enums.GT_HatchElement.OutputBus; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase<GregtechMTE_AlgaePondBase> implements ISurvivalConstructable { - - private int mLevel = -1; - private int mCasing; - private IStructureDefinition<GregtechMTE_AlgaePondBase> STRUCTURE_DEFINITION = null; - private int checkMeta; - private int minTierOfHatch; - private static final Class<?> cofhWater; - - static { - cofhWater = ReflectionUtils.getClass("cofh.asmhooks.block.BlockWater"); - } - - public GregtechMTE_AlgaePondBase(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMTE_AlgaePondBase(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMTE_AlgaePondBase(this.mName); - } - - @Override - public String getMachineType() { - return "Algae Pond"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Grows Algae!") - .addInfo("Controller Block for the Algae Farm") - .addInfo("Provide compost to boost production by one tier") - .addInfo("Does not require power or maintenance") - .addInfo("All Machine Casings must be the same tier, this dictates machine speed.") - .addInfo("All Buses/Hatches must, at least, match the tier of the Casings") - .addInfo("Fill Input Hatch with Water to fill the inside of the multiblock.") - .addPollutionAmount(getPollutionPerSecond(null)) - .addSeparator() - .beginStructureBlock(9, 3, 9, true) - .addController("Front Center") - .addCasingInfo("Machine Casings", 64) - .addCasingInfo("Sterile Farm Casings", 34) - .addInputBus("Any Casing", 1) - .addOutputBus("Any Casing", 1) - .addInputHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - public void setMeta(int meta) { - checkMeta = meta; - } - - public int getMeta() { - return checkMeta; - } - - @Override - public IStructureDefinition<GregtechMTE_AlgaePondBase> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_AlgaePondBase>builder() - .addShape(mName, transpose(new String[][]{ - {"XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", "X X", "XXXXXXXXX"}, - {"XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", "X X", "XXXXXXXXX"}, - {"CCCC~CCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC"}, - })) - .addElement( - 'C', - ofChain( - buildHatchAdder(GregtechMTE_AlgaePondBase.class) - .atLeast(InputHatch, InputBus, OutputBus) - .casingIndex(TAE.getIndexFromPage(1, 15)) - .dot(1) - .build(), - onElementPass( - x -> ++x.mCasing, - addTieredBlock( - GregTech_API.sBlockCasings1, GregtechMTE_AlgaePondBase::setMeta, GregtechMTE_AlgaePondBase::getMeta, 10 - ) - ) - ) - ) - .addElement( - 'X', - ofBlock( - ModBlocks.blockCasings2Misc, 15 - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 4, 2, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 4, 2, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mLevel = 0; - checkMeta = 0; - minTierOfHatch = 100; - if (checkPiece(mName, 4, 2, 0) && mCasing >= 64 && checkMeta > 0) { - mLevel = checkMeta - 1; - return mLevel <= minTierOfHatch; - } - return false; - } - - @Override - protected IAlignmentLimits getInitialAlignmentLimits() { - // fuck - return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(207)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Default; - } - - @Override - protected int getCasingTextureId() { - int aID = TAE.getIndexFromPage(1, 15); - if (mLevel > -1) { - aID = mLevel; - } - return aID; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return null; - } - - @Override - public int getMaxParallelRecipes() { - return 2; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - public boolean checkForWater() { - - // Get Facing direction - IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); - int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int mCurrentDirectionX; - int mCurrentDirectionZ; - int mOffsetX_Lower = 0; - int mOffsetX_Upper = 0; - int mOffsetZ_Lower = 0; - int mOffsetZ_Upper = 0; - - mCurrentDirectionX = 4; - mCurrentDirectionZ = 4; - - mOffsetX_Lower = -4; - mOffsetX_Upper = 4; - mOffsetZ_Lower = -4; - mOffsetZ_Upper = 4; - - // if (aBaseMetaTileEntity.fac) - - final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX - * mCurrentDirectionX; - final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ - * mCurrentDirectionZ; - - int tAmount = 0; - for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { - for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { - for (int h = 0; h < 2; h++) { - Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); - if (isNotStaticWater(tBlock, tMeta)) { - if (this.getStoredFluids() != null) { - for (FluidStack stored : this.getStoredFluids()) { - if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { - if (stored.amount >= 1000) { - // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); - stored.amount -= 1000; - Block fluidUsed = Blocks.water; - aBaseMetaTileEntity.getWorld().setBlock( - aBaseMetaTileEntity.getXCoord() + xDir + i, - aBaseMetaTileEntity.getYCoord() + h, - aBaseMetaTileEntity.getZCoord() + zDir + j, fluidUsed); - - } - } - } - } - } - tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { - ++tAmount; - // Logger.INFO("Found Water"); - } - } - } - } - - boolean isValidWater = tAmount >= 49; - - if (isValidWater) { - Logger.INFO("Filled structure."); - return true; - } - else { - return false; - } - } - - private boolean isNotStaticWater(Block block, byte meta) { - return block == Blocks.air - || block == Blocks.flowing_water - || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) - || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerSecond(final ItemStack aStack) { - return CORE.ConfigSwitches.pollutionPerSecondMultiAlgaePond; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - this.fixAllMaintenanceIssue(); - // Silly Client Syncing - if (aBaseMetaTileEntity.isClientSide()) { - this.mLevel = getCasingTier(); - } - - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); - } - - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - - if (this.mLevel < 0) { - Logger.INFO("Bad Tier."); - return false; - } - - if (!checkForWater()) { - Logger.INFO("Not enough Water."); - return false; - } - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - Logger.INFO("Running checkRecipeGeneric(0)"); - - GT_Recipe tRecipe = RecipeLoader_AlgaeFarm.getTieredRecipeFromCache(this.mLevel, isUsingCompost(aItemInputs)); - - this.mLastRecipe = tRecipe; - - if (tRecipe == null) { - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - return false; - } - if (tRecipe.mInputs.length > 0) { - for (ItemStack aInputToConsume : tRecipe.mInputs) { - this.depleteInput(aInputToConsume); - } - } - - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - this.mMaxProgresstime = (int)(tRecipe.mDuration); - this.mEUt = 0; - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - Logger.INFO("Recipe time: "+this.mMaxProgresstime); - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= aMaxParallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < aMaxParallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - Logger.INFO("GOOD RETURN - 1"); - return true; - - } - - private boolean isUsingCompost(ItemStack[] aItemInputs) { - ItemStack aCompost = ItemUtils.getSimpleStack(AgriculturalChem.mCompost, 1); - for (ItemStack i : aItemInputs) { - if (GT_Utility.areStacksEqual(aCompost, i)) { - if (i.stackSize >= 8) { - return true; - } - } - } - return false; - } - - - private int getCasingTier() { - if (this.getBaseMetaTileEntity().getWorld() == null) { - return 0; - } - try { - Block aInitStructureCheck; - int aInitStructureCheckMeta; - IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(xDir, -1, zDir); - aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir, -1, zDir); - if (aInitStructureCheck == GregTech_API.sBlockCasings1) { - return aInitStructureCheckMeta; - } - return 0; - } - catch (Throwable t) { - t.printStackTrace(); - return 0; - } - } - - - +public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase<GregtechMTE_AlgaePondBase> + implements ISurvivalConstructable { + + private int mLevel = -1; + private int mCasing; + private IStructureDefinition<GregtechMTE_AlgaePondBase> STRUCTURE_DEFINITION = null; + private int checkMeta; + private int minTierOfHatch; + private static final Class<?> cofhWater; + + static { + cofhWater = ReflectionUtils.getClass("cofh.asmhooks.block.BlockWater"); + } + + public GregtechMTE_AlgaePondBase(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_AlgaePondBase(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_AlgaePondBase(this.mName); + } + + @Override + public String getMachineType() { + return "Algae Pond"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Grows Algae!") + .addInfo("Controller Block for the Algae Farm") + .addInfo("Provide compost to boost production by one tier") + .addInfo("Does not require power or maintenance") + .addInfo("All Machine Casings must be the same tier, this dictates machine speed.") + .addInfo("All Buses/Hatches must, at least, match the tier of the Casings") + .addInfo("Fill Input Hatch with Water to fill the inside of the multiblock.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(9, 3, 9, true) + .addController("Front Center") + .addCasingInfo("Machine Casings", 64) + .addCasingInfo("Sterile Farm Casings", 34) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + public void setMeta(int meta) { + checkMeta = meta; + } + + public int getMeta() { + return checkMeta; + } + + @Override + public IStructureDefinition<GregtechMTE_AlgaePondBase> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_AlgaePondBase>builder() + .addShape(mName, transpose(new String[][] { + { + "XXXXXXXXX", + "X X", + "X X", + "X X", + "X X", + "X X", + "X X", + "X X", + "XXXXXXXXX" + }, + { + "XXXXXXXXX", + "X X", + "X X", + "X X", + "X X", + "X X", + "X X", + "X X", + "XXXXXXXXX" + }, + { + "CCCC~CCCC", + "CCCCCCCCC", + "CCCCCCCCC", + "CCCCCCCCC", + "CCCCCCCCC", + "CCCCCCCCC", + "CCCCCCCCC", + "CCCCCCCCC", + "CCCCCCCCC" + }, + })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMTE_AlgaePondBase.class) + .atLeast(InputHatch, InputBus, OutputBus) + .casingIndex(TAE.getIndexFromPage(1, 15)) + .dot(1) + .build(), + onElementPass( + x -> ++x.mCasing, + addTieredBlock( + GregTech_API.sBlockCasings1, + GregtechMTE_AlgaePondBase::setMeta, + GregtechMTE_AlgaePondBase::getMeta, + 10)))) + .addElement('X', ofBlock(ModBlocks.blockCasings2Misc, 15)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 4, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 4, 2, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mLevel = 0; + checkMeta = 0; + minTierOfHatch = 100; + if (checkPiece(mName, 4, 2, 0) && mCasing >= 64 && checkMeta > 0) { + mLevel = checkMeta - 1; + return mLevel <= minTierOfHatch; + } + return false; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // fuck + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + int aID = TAE.getIndexFromPage(1, 15); + if (mLevel > -1) { + aID = mLevel; + } + return aID; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + @Override + public int getMaxParallelRecipes() { + return 2; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + public boolean checkForWater() { + + // Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + mCurrentDirectionX = 4; + mCurrentDirectionZ = 4; + + mOffsetX_Lower = -4; + mOffsetX_Upper = 4; + mOffsetZ_Lower = -4; + mOffsetZ_Upper = 4; + + // if (aBaseMetaTileEntity.fac) + + final int xDir = + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * mCurrentDirectionX; + final int zDir = + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; h++) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (isNotStaticWater(tBlock, tMeta)) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = Blocks.water; + aBaseMetaTileEntity + .getWorld() + .setBlock( + aBaseMetaTileEntity.getXCoord() + xDir + i, + aBaseMetaTileEntity.getYCoord() + h, + aBaseMetaTileEntity.getZCoord() + zDir + j, + fluidUsed); + } + } + } + } + } + tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { + ++tAmount; + // Logger.INFO("Found Water"); + } + } + } + } + + boolean isValidWater = tAmount >= 49; + + if (isValidWater) { + Logger.INFO("Filled structure."); + return true; + } else { + return false; + } + } + + private boolean isNotStaticWater(Block block, byte meta) { + return block == Blocks.air + || block == Blocks.flowing_water + || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) + || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAlgaePond; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + this.fixAllMaintenanceIssue(); + // Silly Client Syncing + if (aBaseMetaTileEntity.isClientSide()) { + this.mLevel = getCasingTier(); + } + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); + } + + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + + if (this.mLevel < 0) { + Logger.INFO("Bad Tier."); + return false; + } + + if (!checkForWater()) { + Logger.INFO("Not enough Water."); + return false; + } + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + Logger.INFO("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = RecipeLoader_AlgaeFarm.getTieredRecipeFromCache(this.mLevel, isUsingCompost(aItemInputs)); + + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + return false; + } + if (tRecipe.mInputs.length > 0) { + for (ItemStack aInputToConsume : tRecipe.mInputs) { + this.depleteInput(aInputToConsume); + } + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + this.mMaxProgresstime = (int) (tRecipe.mDuration); + this.mEUt = 0; + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + Logger.INFO("Recipe time: " + this.mMaxProgresstime); + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= aMaxParallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < aMaxParallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.INFO("GOOD RETURN - 1"); + return true; + } + + private boolean isUsingCompost(ItemStack[] aItemInputs) { + ItemStack aCompost = ItemUtils.getSimpleStack(AgriculturalChem.mCompost, 1); + for (ItemStack i : aItemInputs) { + if (GT_Utility.areStacksEqual(aCompost, i)) { + if (i.stackSize >= 8) { + return true; + } + } + } + return false; + } + + private int getCasingTier() { + if (this.getBaseMetaTileEntity().getWorld() == null) { + return 0; + } + try { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(xDir, -1, zDir); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir, -1, zDir); + if (aInitStructureCheck == GregTech_API.sBlockCasings1) { + return aInitStructureCheckMeta; + } + return 0; + } catch (Throwable t) { + t.printStackTrace(); + return 0; + } + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform1.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform1.java index 018120d614..875c449f2d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform1.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform1.java @@ -1,11 +1,6 @@ /* package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.bedrock; -import gregtech.api.enums.TAE; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gtPlusPlus.core.material.ALLOY; -import gtPlusPlus.core.material.Material; public class GregtechMetaTileEntity_BedrockMiningPlatform1 extends GregtechMetaTileEntity_BedrockMiningPlatformBase { public GregtechMetaTileEntity_BedrockMiningPlatform1(final int aID, final String aName, final String aNameRegional) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform2.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform2.java index 6b97cb7ee2..f67ecfe87f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform2.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform2.java @@ -1,11 +1,6 @@ /* package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.bedrock; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; - -import gtPlusPlus.core.material.ELEMENT; -import gtPlusPlus.core.material.Material; public class GregtechMetaTileEntity_BedrockMiningPlatform2 extends GregtechMetaTileEntity_BedrockMiningPlatformBase { public GregtechMetaTileEntity_BedrockMiningPlatform2(final int aID, final String aName, final String aNameRegional) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatformBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatformBase.java index b74f2459a3..50c10bab0d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatformBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatformBase.java @@ -32,653 +32,608 @@ import net.minecraftforge.common.util.ForgeDirection; public abstract class GregtechMetaTileEntity_BedrockMiningPlatformBase extends GregtechMeta_MultiBlockBase { - protected double mProductionModifier = 0; - - - private static final ItemStack miningPipe; - private static final ItemStack miningPipeTip; - - private Block casingBlock; - private int casingMeta; - // private int frameMeta; - private int casingTextureIndex; - - private ForgeDirection back; - - private int xDrill; - private int yDrill; - private int zDrill; - - private int[] xCenter = new int[5]; - private int[] zCenter = new int[5]; - - public GregtechMetaTileEntity_BedrockMiningPlatformBase(final int aID, final String aName, - final String aNameRegional) { - super(aID, aName, aNameRegional); - this.initFields(); - } - - public GregtechMetaTileEntity_BedrockMiningPlatformBase(final String aName) { - super(aName); - this.initFields(); - } - - private void initFields() { - this.casingBlock = this.getCasingBlockItem().getBlock(); - this.casingMeta = this.getCasingBlockItem().get(0L, new Object[0]).getItemDamage(); - this.casingTextureIndex = this.getCasingTextureIndex(); - } - - @Override - protected IIconContainer getActiveOverlay() { - return Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_FRONT_ACTIVE; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_FRONT; - } - - @Override - protected int getCasingTextureId() { - return this.casingTextureIndex; - } - - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, - final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), - "OreDrillingPlant.png"); - } - - - public int getAmountOfOutputs() { - return 1; - } - - public void saveNBTData(final NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setDouble("mProductionModifier", mProductionModifier); - } - - public void loadNBTData(final NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - this.mProductionModifier = aNBT.getDouble("mProductionModifier"); - } - - public boolean checkRecipe(final ItemStack aStack) { - //this.setElectricityStats(); - - - if (true) { - return false; - } - - boolean[] didWork = new boolean[5]; - - if (!this.tryConsumeDrillingFluid()) { - Logger.INFO("No drilling Fluid."); - return false; - } - - if (MathUtils.isNumberEven((int) this.mProductionModifier)) { - if (!this.tryConsumePyrotheum()) { - Logger.INFO("No tryConsumePyrotheum Fluid."); - return false; - } - else { - mProductionModifier++; - } - } - else { - if (!this.tryConsumeCryotheum()) { - Logger.INFO("No tryConsumeCryotheum Fluid."); - return false; - } - else { - mProductionModifier++; - } - } - - for (int i = 0; i < 5; i++) { - process(); - didWork[i] = true; - } - - // Fail recipe handling if one pipe didn't handle properly, to try again - // next run. - for (boolean y : didWork) { - if (!y) { - Logger.INFO("[Bedrock Miner] Fail [x]"); - return false; - } - } - - this.mEUt = -8000; - this.mMaxProgresstime = 1; - this.mEfficiencyIncrease = 10000; - - return true; - } - - private boolean isEnergyEnough() { - long requiredEnergy = 512L + this.getMaxInputVoltage() * 4L; - for (final GT_MetaTileEntity_Hatch_Energy energyHatch : this.mEnergyHatches) { - requiredEnergy -= energyHatch.getEUVar(); - if (requiredEnergy <= 0L) { - return true; - } - } - return false; - } - - private void setElectricityStats() { - //this.mEfficiency = this.getCurrentEfficiency((ItemStack) null); - this.mEfficiencyIncrease = 10000; - final int overclock = 8 << GT_Utility.getTier(this.getMaxInputVoltage()); - //this.mEUt = -12 * overclock * overclock; - Logger.INFO("Trying to set EU to "+(12 * overclock * overclock)); - int mCombinedAvgTime = 0; - for (int g = 0; g < 5; g++) { - mCombinedAvgTime += this.getBaseProgressTime() / overclock; - } - Logger.INFO("Trying to set Max Time to "+(mCombinedAvgTime)); - //this.mMaxProgresstime = (mCombinedAvgTime / 5); - } - - private boolean tryConsumeDrillingFluid() { - boolean consumed = false; - boolean g = (this.getBaseMetaTileEntity().getWorld().getTotalWorldTime() % 2 == 0); - consumed = (g ? tryConsumePyrotheum() : tryConsumeCryotheum()); - if (consumed) { - //increaseProduction(g ? 2 : 1); - } - else { - //lowerProduction(g ? 5 : 3); - } - return consumed; - } - - private boolean tryConsumePyrotheum() { - return this.depleteInput(FluidUtils.getFluidStack("pyrotheum", 4)); - } - - private boolean tryConsumeCryotheum() { - return this.depleteInput(FluidUtils.getFluidStack("cryotheum", 4)); - } - - private void putMiningPipesFromInputsInController() { - final int maxPipes = 64; - if (this.isHasMiningPipes(maxPipes)) { - return; - } - ItemStack pipes = this.getStackInSlot(1); - for (final ItemStack storedItem : this.getStoredInputs()) { - if (!storedItem.isItemEqual(GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe)) { - continue; - } - if (pipes == null) { - this.setInventorySlotContents(1, - GT_Utility.copy(new Object[] { GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe })); - pipes = this.getStackInSlot(1); - } - if (pipes.stackSize == maxPipes) { - break; - } - final int needPipes = maxPipes - pipes.stackSize; - final int transferPipes = (storedItem.stackSize < needPipes) ? storedItem.stackSize : needPipes; - final ItemStack itemStack = pipes; - itemStack.stackSize += transferPipes; - final ItemStack itemStack2 = storedItem; - itemStack2.stackSize -= transferPipes; - } - this.updateSlots(); - } - - - - private boolean isHasMiningPipes(final int minCount) { - final ItemStack pipe = this.getStackInSlot(1); - return pipe != null && pipe.stackSize > minCount - 1 - && pipe.isItemEqual(GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe); - } - - public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { - this.updateCoordinates(); - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - int tAmount = 0; - if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { - return false; - } else { - - Block aCasing = Block.getBlockFromItem(getCasingBlockItem().getItem()); - - for (int i = -1; i < 2; ++i) { - for (int j = -1; j < 2; ++j) { - for (int h = -1; h < 2; ++h) { - if (h != 0 || (xDir + i != 0 || zDir + j != 0) && (i != 0 || j != 0)) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, - h, zDir + j); - Block aBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - int aMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); - - if (!this.addToMachineList(tTileEntity, 48)) { - if (aBlock != aCasing) { - Logger.INFO("Found Bad Casing"); - return false; - } - if (aMeta != 3) { - Logger.INFO("Found Bad Meta"); - return false; - } - } - ++tAmount; - - - - /*if (!isValidBlockForStructure(tTileEntity, 48, true, aBlock, aMeta, sBlockCasings4, 0)) { - Logger.INFO("Bad centrifuge casing"); - return false; - }*/ - - } - } - } - } - return tAmount >= 10; - } - - } - - private void updateCoordinates() { - this.xDrill = this.getBaseMetaTileEntity().getXCoord(); - this.yDrill = this.getBaseMetaTileEntity().getYCoord()-1; - this.zDrill = this.getBaseMetaTileEntity().getZCoord(); - this.back = ForgeDirection.getOrientation((int) this.getBaseMetaTileEntity().getBackFacing()); - - // Middle - this.xCenter[0] = this.xDrill + this.back.offsetX; - this.zCenter[0] = this.zDrill + this.back.offsetZ; - - this.xCenter[1] = xCenter[0] + 1; - this.zCenter[1] = zCenter[0]; - - this.xCenter[2] = xCenter[0] - 1; - this.zCenter[2] = zCenter[0]; - - this.xCenter[3] = xCenter[0]; - this.zCenter[3] = zCenter[0] + 1; - - this.xCenter[4] = xCenter[0]; - this.zCenter[4] = zCenter[0] - 1; - - } - - public boolean isCorrectMachinePart(final ItemStack aStack) { - return true; - } - - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - public int getPollutionPerTick(final ItemStack aStack) { - return 0; - } - - public int getDamageToComponent(final ItemStack aStack) { - return 0; - } - - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - protected GregtechItemList getCasingBlockItem() { - return GregtechItemList.Casing_BedrockMiner; - } - - protected abstract Material getFrameMaterial(); - - protected abstract int getCasingTextureIndex(); - - protected abstract int getRadiusInChunks(); - - protected abstract int getMinTier(); - - protected abstract int getBaseProgressTime(); - - protected String[] getDescriptionInternal(final String tierSuffix) { - final String casings = this.getCasingBlockItem().get(0L, new Object[0]).getDisplayName(); - return new String[] { - "Controller Block for the Experimental Deep Earth Drilling Platform - MK " - + ((tierSuffix != null) ? tierSuffix : ""), - "Size(WxHxD): 3x7x3, Controller (Front middle bottom)", "3x1x3 Base of " + casings, - "1x3x1 " + casings + " pillar (Center of base)", - "1x3x1 " + this.getFrameMaterial().getLocalizedName() + " Frame Boxes (Each pillar side and on top)", - "2x Input Hatch (Any bottom layer casing)", - "1x Input Bus for mining pipes (Any bottom layer casing; not necessary)", - "1x Output Bus (Any bottom layer casing)", "1x Maintenance Hatch (Any bottom layer casing)", - "1x " + GT_Values.VN[this.getMinTier()] + "+ Energy Hatch (Any bottom layer casing)", - "Radius is " + (this.getRadiusInChunks() << 4) + " blocks", - "Every tick, this machine altenates betweem consumption of Pyrotheum & Cryotheum", - "Pyrotheum is used to bore through the Mantle of the world", - "Cryotheum is used to keep the internal components cool",}; - } - - static { - miningPipe = GT_ModHandler.getIC2Item("miningPipe", 0L); - miningPipeTip = GT_ModHandler.getIC2Item("miningPipeTip", 0L); - } - - - - - - - - - - - - - - - - - - - - - - - - - - private AutoMap<ItemStack> mOutputs; - - public void process() { - ItemStack aOutput = generateOutputWithchance(); - if (aOutput != null) { - this.addOutput(aOutput); - Logger.INFO("Mined some "+aOutput.getDisplayName()); - } - this.updateSlots(); - } - - public ItemStack generateOutputWithchance() { - int aChance = MathUtils.randInt(0, 7500); - if (aChance < 100) { - return generateOutput(); - } - else { - return null; - } - } - - public ItemStack generateOutput() { - AutoMap<ItemStack> aData = generateOreForOutput(); - int aMax = aData.size()-1; - return aData.get(MathUtils.randInt(0, aMax)); - } - - /** - * Here we generate valid ores and also a basic loot set - */ - - public AutoMap<ItemStack> generateOreForOutput() { - - if (mOutputs != null) { - return mOutputs; - } - - AutoMap<GT_Worldgen_GT_Ore_Layer> aOverWorldOres = MiningUtils.getOresForDim(0); - AutoMap<GT_Worldgen_GT_Ore_Layer> aNetherOres = MiningUtils.getOresForDim(-1); - AutoMap<GT_Worldgen_GT_Ore_Layer> aEndOres = MiningUtils.getOresForDim(1); - - AutoMap<ItemStack> aTempMap = new AutoMap<ItemStack>(); - Block tOreBlock = GregTech_API.sBlockOres1; - Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Initial]"); - - for (GT_Worldgen_GT_Ore_Layer layer : aOverWorldOres) { - if (layer.mEnabled) { - ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); - ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); - ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); - ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); - aTempMap.put(aTempOreStack1); - aTempMap.put(aTempOreStack2); - aTempMap.put(aTempOreStack3); - aTempMap.put(aTempOreStack4); - aTempMap.put(aTempOreStack1); - aTempMap.put(aTempOreStack2); - aTempMap.put(aTempOreStack3); - aTempMap.put(aTempOreStack4); - aTempMap.put(aTempOreStack1); - aTempMap.put(aTempOreStack2); - aTempMap.put(aTempOreStack3); - aTempMap.put(aTempOreStack4); - } - } - Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Overworld]"); - for (GT_Worldgen_GT_Ore_Layer layer : aNetherOres) { - if (layer.mEnabled) { - ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); - ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); - ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); - ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); - aTempMap.put(aTempOreStack1); - aTempMap.put(aTempOreStack2); - aTempMap.put(aTempOreStack3); - aTempMap.put(aTempOreStack4); - aTempMap.put(aTempOreStack1); - aTempMap.put(aTempOreStack2); - aTempMap.put(aTempOreStack3); - aTempMap.put(aTempOreStack4); - } - } - Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Nether]"); - for (GT_Worldgen_GT_Ore_Layer layer : aEndOres) { - if (layer.mEnabled) { - ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); - ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); - ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); - ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); - aTempMap.put(aTempOreStack1); - aTempMap.put(aTempOreStack2); - aTempMap.put(aTempOreStack3); - aTempMap.put(aTempOreStack4); - } - } - Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [End]"); - - addOreTypeToMap(ELEMENT.getInstance().IRON, 200, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().COPPER, 175, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().TIN, 150, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().GOLD, 150, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().SILVER, 110, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().NICKEL, 40, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().ZINC, 40, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().LEAD, 40, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().ALUMINIUM, 30, aTempMap); - addOreTypeToMap(ELEMENT.getInstance().THORIUM, 20, aTempMap); - Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Extra Common Ores]"); - - AutoMap<Pair<String, Integer>> mMixedOreData = new AutoMap<Pair<String, Integer>>(); - mMixedOreData.put(new Pair<String, Integer>("oreRuby", 30)); - mMixedOreData.put(new Pair<String, Integer>("oreSapphire", 25)); - mMixedOreData.put(new Pair<String, Integer>("oreEmerald", 25)); - mMixedOreData.put(new Pair<String, Integer>("oreLapis", 40)); - mMixedOreData.put(new Pair<String, Integer>("oreRedstone", 40)); - - if (LoadedMods.Thaumcraft || (OreDictUtils.containsValidEntries("oreAmber") && OreDictUtils.containsValidEntries("oreCinnabar"))) { - mMixedOreData.put(new Pair<String, Integer>("oreAmber", 20)); - mMixedOreData.put(new Pair<String, Integer>("oreCinnabar", 20)); - } - if (LoadedMods.Railcraft || OreDictUtils.containsValidEntries("oreSaltpeter")) { - mMixedOreData.put(new Pair<String, Integer>("oreSaltpeter", 10)); - } - if (LoadedMods.IndustrialCraft2 || OreDictUtils.containsValidEntries("oreUranium")) { - mMixedOreData.put(new Pair<String, Integer>("oreUranium", 10)); - } - if (OreDictUtils.containsValidEntries("oreSulfur")) { - mMixedOreData.put(new Pair<String, Integer>("oreSulfur", 15)); - } - if (OreDictUtils.containsValidEntries("oreSilicon")) { - mMixedOreData.put(new Pair<String, Integer>("oreSilicon", 15)); - } - if (OreDictUtils.containsValidEntries("oreApatite")) { - mMixedOreData.put(new Pair<String, Integer>("oreApatite", 25)); - } - - mMixedOreData.put(new Pair<String, Integer>("oreFirestone", 2)); - mMixedOreData.put(new Pair<String, Integer>("oreBismuth", 20)); - mMixedOreData.put(new Pair<String, Integer>("oreLithium", 20)); - mMixedOreData.put(new Pair<String, Integer>("oreManganese", 20)); - mMixedOreData.put(new Pair<String, Integer>("oreBeryllium", 20)); - mMixedOreData.put(new Pair<String, Integer>("oreCoal", 75)); - mMixedOreData.put(new Pair<String, Integer>("oreLignite", 75)); - mMixedOreData.put(new Pair<String, Integer>("oreSalt", 15)); - mMixedOreData.put(new Pair<String, Integer>("oreCalcite", 15)); - mMixedOreData.put(new Pair<String, Integer>("oreBauxite", 20)); - mMixedOreData.put(new Pair<String, Integer>("oreAlmandine", 15)); - mMixedOreData.put(new Pair<String, Integer>("oreGraphite", 25)); - mMixedOreData.put(new Pair<String, Integer>("oreGlauconite", 15)); - mMixedOreData.put(new Pair<String, Integer>("orePyrolusite", 15)); - mMixedOreData.put(new Pair<String, Integer>("oreGrossular", 15)); - mMixedOreData.put(new Pair<String, Integer>("oreTantalite", 15)); - - for (Pair<String, Integer> g : mMixedOreData) { - for (int i=0; i<g.getValue();i++) { - aTempMap.put(ItemUtils.getItemStackOfAmountFromOreDict(g.getKey(), 1)); - } - } - Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Extra Mixed Ores]"); - - - addOreTypeToMap(ELEMENT.STANDALONE.RUNITE, 2, aTempMap); - addOreTypeToMap(ELEMENT.STANDALONE.GRANITE, 8, aTempMap); - Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [OSRS Ores]"); - - - AutoMap<Material> aMyOreMaterials = new AutoMap<Material>(); - aMyOreMaterials.add(ORES.CROCROITE); - aMyOreMaterials.add(ORES.GEIKIELITE); - aMyOreMaterials.add(ORES.NICHROMITE); - aMyOreMaterials.add(ORES.TITANITE); - aMyOreMaterials.add(ORES.ZIMBABWEITE); - aMyOreMaterials.add(ORES.ZIRCONILITE); - aMyOreMaterials.add(ORES.GADOLINITE_CE); - aMyOreMaterials.add(ORES.GADOLINITE_Y); - aMyOreMaterials.add(ORES.LEPERSONNITE); - aMyOreMaterials.add(ORES.SAMARSKITE_Y); - aMyOreMaterials.add(ORES.SAMARSKITE_YB); - aMyOreMaterials.add(ORES.XENOTIME); - aMyOreMaterials.add(ORES.YTTRIAITE); - aMyOreMaterials.add(ORES.YTTRIALITE); - aMyOreMaterials.add(ORES.YTTROCERITE); - aMyOreMaterials.add(ORES.ZIRCON); - aMyOreMaterials.add(ORES.POLYCRASE); - aMyOreMaterials.add(ORES.ZIRCOPHYLLITE); - aMyOreMaterials.add(ORES.ZIRKELITE); - aMyOreMaterials.add(ORES.LANTHANITE_LA); - aMyOreMaterials.add(ORES.LANTHANITE_CE); - aMyOreMaterials.add(ORES.LANTHANITE_ND); - aMyOreMaterials.add(ORES.AGARDITE_Y); - aMyOreMaterials.add(ORES.AGARDITE_CD); - aMyOreMaterials.add(ORES.AGARDITE_LA); - aMyOreMaterials.add(ORES.AGARDITE_ND); - aMyOreMaterials.add(ORES.HIBONITE); - aMyOreMaterials.add(ORES.CERITE); - aMyOreMaterials.add(ORES.FLUORCAPHITE); - aMyOreMaterials.add(ORES.FLORENCITE); - aMyOreMaterials.add(ORES.CRYOLITE); - aMyOreMaterials.add(ORES.LAUTARITE); - aMyOreMaterials.add(ORES.LAFOSSAITE); - aMyOreMaterials.add(ORES.DEMICHELEITE_BR); - aMyOreMaterials.add(ORES.COMANCHEITE); - aMyOreMaterials.add(ORES.PERROUDITE); - aMyOreMaterials.add(ORES.HONEAITE); - aMyOreMaterials.add(ORES.ALBURNITE); - aMyOreMaterials.add(ORES.MIESSIITE); - aMyOreMaterials.add(ORES.KASHINITE); - aMyOreMaterials.add(ORES.IRARSITE); - aMyOreMaterials.add(ORES.RADIOBARITE); - aMyOreMaterials.add(ORES.DEEP_EARTH_REACTOR_FUEL_DEPOSIT); - - for (Material aOreType : aMyOreMaterials) { - if (aOreType == ORES.DEEP_EARTH_REACTOR_FUEL_DEPOSIT || aOreType == ORES.RADIOBARITE) { - addOreTypeToMap(aOreType, 4, aTempMap); - } - else { - addOreTypeToMap(aOreType, 7, aTempMap); - } - } - - //Cleanup Map - Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [GT++]"); - AutoMap<ItemStack> aCleanUp = new AutoMap<ItemStack>(); - for (ItemStack verify : aTempMap) { - if (!ItemUtils.checkForInvalidItems(verify)) { - aCleanUp.put(verify); - } - } - Logger.INFO("Cleanup Map contains "+aCleanUp.size()+" values."); - for (ItemStack remove : aCleanUp) { - aTempMap.remove(remove); - } - - //Generate Massive Map - AutoMap<ItemStack> aFinalMap = new AutoMap<ItemStack>(); - for (ItemStack aTempItem : aTempMap) { - int aTempMulti = MathUtils.randInt(20, 50); - for (int i=0;i<aTempMulti;i++) { - aFinalMap.put(aTempItem.copy()); - } - } - Logger.INFO("Final Ore Map contains "+aFinalMap.size()+" values."); - mOutputs = aFinalMap; - return mOutputs; - } - - - private static void addOreTypeToMap(Material aMaterial, int aAmount, AutoMap<ItemStack> aMap) { - for (int i=0; i<aAmount;i++) { - aMap.add(aMaterial.getOre(1)); - } - } - - - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Miner"; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - - - - - - -}
\ No newline at end of file + protected double mProductionModifier = 0; + + private static final ItemStack miningPipe; + private static final ItemStack miningPipeTip; + + private Block casingBlock; + private int casingMeta; + // private int frameMeta; + private int casingTextureIndex; + + private ForgeDirection back; + + private int xDrill; + private int yDrill; + private int zDrill; + + private int[] xCenter = new int[5]; + private int[] zCenter = new int[5]; + + public GregtechMetaTileEntity_BedrockMiningPlatformBase( + final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + this.initFields(); + } + + public GregtechMetaTileEntity_BedrockMiningPlatformBase(final String aName) { + super(aName); + this.initFields(); + } + + private void initFields() { + this.casingBlock = this.getCasingBlockItem().getBlock(); + this.casingMeta = this.getCasingBlockItem().get(0L, new Object[0]).getItemDamage(); + this.casingTextureIndex = this.getCasingTextureIndex(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_FRONT_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_FRONT; + } + + @Override + protected int getCasingTextureId() { + return this.casingTextureIndex; + } + + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "OreDrillingPlant.png"); + } + + public int getAmountOfOutputs() { + return 1; + } + + public void saveNBTData(final NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setDouble("mProductionModifier", mProductionModifier); + } + + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mProductionModifier = aNBT.getDouble("mProductionModifier"); + } + + public boolean checkRecipe(final ItemStack aStack) { + // this.setElectricityStats(); + + if (true) { + return false; + } + + boolean[] didWork = new boolean[5]; + + if (!this.tryConsumeDrillingFluid()) { + Logger.INFO("No drilling Fluid."); + return false; + } + + if (MathUtils.isNumberEven((int) this.mProductionModifier)) { + if (!this.tryConsumePyrotheum()) { + Logger.INFO("No tryConsumePyrotheum Fluid."); + return false; + } else { + mProductionModifier++; + } + } else { + if (!this.tryConsumeCryotheum()) { + Logger.INFO("No tryConsumeCryotheum Fluid."); + return false; + } else { + mProductionModifier++; + } + } + + for (int i = 0; i < 5; i++) { + process(); + didWork[i] = true; + } + + // Fail recipe handling if one pipe didn't handle properly, to try again + // next run. + for (boolean y : didWork) { + if (!y) { + Logger.INFO("[Bedrock Miner] Fail [x]"); + return false; + } + } + + this.mEUt = -8000; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 10000; + + return true; + } + + private boolean isEnergyEnough() { + long requiredEnergy = 512L + this.getMaxInputVoltage() * 4L; + for (final GT_MetaTileEntity_Hatch_Energy energyHatch : this.mEnergyHatches) { + requiredEnergy -= energyHatch.getEUVar(); + if (requiredEnergy <= 0L) { + return true; + } + } + return false; + } + + private void setElectricityStats() { + // this.mEfficiency = this.getCurrentEfficiency((ItemStack) null); + this.mEfficiencyIncrease = 10000; + final int overclock = 8 << GT_Utility.getTier(this.getMaxInputVoltage()); + // this.mEUt = -12 * overclock * overclock; + Logger.INFO("Trying to set EU to " + (12 * overclock * overclock)); + int mCombinedAvgTime = 0; + for (int g = 0; g < 5; g++) { + mCombinedAvgTime += this.getBaseProgressTime() / overclock; + } + Logger.INFO("Trying to set Max Time to " + (mCombinedAvgTime)); + // this.mMaxProgresstime = (mCombinedAvgTime / 5); + } + + private boolean tryConsumeDrillingFluid() { + boolean consumed = false; + boolean g = (this.getBaseMetaTileEntity().getWorld().getTotalWorldTime() % 2 == 0); + consumed = (g ? tryConsumePyrotheum() : tryConsumeCryotheum()); + if (consumed) { + // increaseProduction(g ? 2 : 1); + } else { + // lowerProduction(g ? 5 : 3); + } + return consumed; + } + + private boolean tryConsumePyrotheum() { + return this.depleteInput(FluidUtils.getFluidStack("pyrotheum", 4)); + } + + private boolean tryConsumeCryotheum() { + return this.depleteInput(FluidUtils.getFluidStack("cryotheum", 4)); + } + + private void putMiningPipesFromInputsInController() { + final int maxPipes = 64; + if (this.isHasMiningPipes(maxPipes)) { + return; + } + ItemStack pipes = this.getStackInSlot(1); + for (final ItemStack storedItem : this.getStoredInputs()) { + if (!storedItem.isItemEqual(GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe)) { + continue; + } + if (pipes == null) { + this.setInventorySlotContents( + 1, GT_Utility.copy(new Object[] {GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe})); + pipes = this.getStackInSlot(1); + } + if (pipes.stackSize == maxPipes) { + break; + } + final int needPipes = maxPipes - pipes.stackSize; + final int transferPipes = (storedItem.stackSize < needPipes) ? storedItem.stackSize : needPipes; + final ItemStack itemStack = pipes; + itemStack.stackSize += transferPipes; + final ItemStack itemStack2 = storedItem; + itemStack2.stackSize -= transferPipes; + } + this.updateSlots(); + } + + private boolean isHasMiningPipes(final int minCount) { + final ItemStack pipe = this.getStackInSlot(1); + return pipe != null + && pipe.stackSize > minCount - 1 + && pipe.isItemEqual(GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe); + } + + public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + this.updateCoordinates(); + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + int tAmount = 0; + if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { + return false; + } else { + + Block aCasing = Block.getBlockFromItem(getCasingBlockItem().getItem()); + + for (int i = -1; i < 2; ++i) { + for (int j = -1; j < 2; ++j) { + for (int h = -1; h < 2; ++h) { + if (h != 0 || (xDir + i != 0 || zDir + j != 0) && (i != 0 || j != 0)) { + IGregTechTileEntity tTileEntity = + aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); + Block aBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + + if (!this.addToMachineList(tTileEntity, 48)) { + if (aBlock != aCasing) { + Logger.INFO("Found Bad Casing"); + return false; + } + if (aMeta != 3) { + Logger.INFO("Found Bad Meta"); + return false; + } + } + ++tAmount; + + /*if (!isValidBlockForStructure(tTileEntity, 48, true, aBlock, aMeta, sBlockCasings4, 0)) { + Logger.INFO("Bad centrifuge casing"); + return false; + }*/ + + } + } + } + } + return tAmount >= 10; + } + } + + private void updateCoordinates() { + this.xDrill = this.getBaseMetaTileEntity().getXCoord(); + this.yDrill = this.getBaseMetaTileEntity().getYCoord() - 1; + this.zDrill = this.getBaseMetaTileEntity().getZCoord(); + this.back = + ForgeDirection.getOrientation((int) this.getBaseMetaTileEntity().getBackFacing()); + + // Middle + this.xCenter[0] = this.xDrill + this.back.offsetX; + this.zCenter[0] = this.zDrill + this.back.offsetZ; + + this.xCenter[1] = xCenter[0] + 1; + this.zCenter[1] = zCenter[0]; + + this.xCenter[2] = xCenter[0] - 1; + this.zCenter[2] = zCenter[0]; + + this.xCenter[3] = xCenter[0]; + this.zCenter[3] = zCenter[0] + 1; + + this.xCenter[4] = xCenter[0]; + this.zCenter[4] = zCenter[0] - 1; + } + + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + protected GregtechItemList getCasingBlockItem() { + return GregtechItemList.Casing_BedrockMiner; + } + + protected abstract Material getFrameMaterial(); + + protected abstract int getCasingTextureIndex(); + + protected abstract int getRadiusInChunks(); + + protected abstract int getMinTier(); + + protected abstract int getBaseProgressTime(); + + protected String[] getDescriptionInternal(final String tierSuffix) { + final String casings = this.getCasingBlockItem().get(0L, new Object[0]).getDisplayName(); + return new String[] { + "Controller Block for the Experimental Deep Earth Drilling Platform - MK " + + ((tierSuffix != null) ? tierSuffix : ""), + "Size(WxHxD): 3x7x3, Controller (Front middle bottom)", + "3x1x3 Base of " + casings, + "1x3x1 " + casings + " pillar (Center of base)", + "1x3x1 " + this.getFrameMaterial().getLocalizedName() + " Frame Boxes (Each pillar side and on top)", + "2x Input Hatch (Any bottom layer casing)", + "1x Input Bus for mining pipes (Any bottom layer casing; not necessary)", + "1x Output Bus (Any bottom layer casing)", + "1x Maintenance Hatch (Any bottom layer casing)", + "1x " + GT_Values.VN[this.getMinTier()] + "+ Energy Hatch (Any bottom layer casing)", + "Radius is " + (this.getRadiusInChunks() << 4) + " blocks", + "Every tick, this machine altenates betweem consumption of Pyrotheum & Cryotheum", + "Pyrotheum is used to bore through the Mantle of the world", + "Cryotheum is used to keep the internal components cool", + }; + } + + static { + miningPipe = GT_ModHandler.getIC2Item("miningPipe", 0L); + miningPipeTip = GT_ModHandler.getIC2Item("miningPipeTip", 0L); + } + + private AutoMap<ItemStack> mOutputs; + + public void process() { + ItemStack aOutput = generateOutputWithchance(); + if (aOutput != null) { + this.addOutput(aOutput); + Logger.INFO("Mined some " + aOutput.getDisplayName()); + } + this.updateSlots(); + } + + public ItemStack generateOutputWithchance() { + int aChance = MathUtils.randInt(0, 7500); + if (aChance < 100) { + return generateOutput(); + } else { + return null; + } + } + + public ItemStack generateOutput() { + AutoMap<ItemStack> aData = generateOreForOutput(); + int aMax = aData.size() - 1; + return aData.get(MathUtils.randInt(0, aMax)); + } + + /** + * Here we generate valid ores and also a basic loot set + */ + public AutoMap<ItemStack> generateOreForOutput() { + + if (mOutputs != null) { + return mOutputs; + } + + AutoMap<GT_Worldgen_GT_Ore_Layer> aOverWorldOres = MiningUtils.getOresForDim(0); + AutoMap<GT_Worldgen_GT_Ore_Layer> aNetherOres = MiningUtils.getOresForDim(-1); + AutoMap<GT_Worldgen_GT_Ore_Layer> aEndOres = MiningUtils.getOresForDim(1); + + AutoMap<ItemStack> aTempMap = new AutoMap<ItemStack>(); + Block tOreBlock = GregTech_API.sBlockOres1; + Logger.INFO("Ore Map contains " + aTempMap.size() + " values. [Initial]"); + + for (GT_Worldgen_GT_Ore_Layer layer : aOverWorldOres) { + if (layer.mEnabled) { + ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); + ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); + ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); + ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + } + } + Logger.INFO("Ore Map contains " + aTempMap.size() + " values. [Overworld]"); + for (GT_Worldgen_GT_Ore_Layer layer : aNetherOres) { + if (layer.mEnabled) { + ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); + ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); + ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); + ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + } + } + Logger.INFO("Ore Map contains " + aTempMap.size() + " values. [Nether]"); + for (GT_Worldgen_GT_Ore_Layer layer : aEndOres) { + if (layer.mEnabled) { + ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); + ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); + ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); + ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + } + } + Logger.INFO("Ore Map contains " + aTempMap.size() + " values. [End]"); + + addOreTypeToMap(ELEMENT.getInstance().IRON, 200, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().COPPER, 175, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().TIN, 150, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().GOLD, 150, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().SILVER, 110, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().NICKEL, 40, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().ZINC, 40, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().LEAD, 40, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().ALUMINIUM, 30, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().THORIUM, 20, aTempMap); + Logger.INFO("Ore Map contains " + aTempMap.size() + " values. [Extra Common Ores]"); + + AutoMap<Pair<String, Integer>> mMixedOreData = new AutoMap<Pair<String, Integer>>(); + mMixedOreData.put(new Pair<String, Integer>("oreRuby", 30)); + mMixedOreData.put(new Pair<String, Integer>("oreSapphire", 25)); + mMixedOreData.put(new Pair<String, Integer>("oreEmerald", 25)); + mMixedOreData.put(new Pair<String, Integer>("oreLapis", 40)); + mMixedOreData.put(new Pair<String, Integer>("oreRedstone", 40)); + + if (LoadedMods.Thaumcraft + || (OreDictUtils.containsValidEntries("oreAmber") + && OreDictUtils.containsValidEntries("oreCinnabar"))) { + mMixedOreData.put(new Pair<String, Integer>("oreAmber", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreCinnabar", 20)); + } + if (LoadedMods.Railcraft || OreDictUtils.containsValidEntries("oreSaltpeter")) { + mMixedOreData.put(new Pair<String, Integer>("oreSaltpeter", 10)); + } + if (LoadedMods.IndustrialCraft2 || OreDictUtils.containsValidEntries("oreUranium")) { + mMixedOreData.put(new Pair<String, Integer>("oreUranium", 10)); + } + if (OreDictUtils.containsValidEntries("oreSulfur")) { + mMixedOreData.put(new Pair<String, Integer>("oreSulfur", 15)); + } + if (OreDictUtils.containsValidEntries("oreSilicon")) { + mMixedOreData.put(new Pair<String, Integer>("oreSilicon", 15)); + } + if (OreDictUtils.containsValidEntries("oreApatite")) { + mMixedOreData.put(new Pair<String, Integer>("oreApatite", 25)); + } + + mMixedOreData.put(new Pair<String, Integer>("oreFirestone", 2)); + mMixedOreData.put(new Pair<String, Integer>("oreBismuth", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreLithium", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreManganese", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreBeryllium", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreCoal", 75)); + mMixedOreData.put(new Pair<String, Integer>("oreLignite", 75)); + mMixedOreData.put(new Pair<String, Integer>("oreSalt", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreCalcite", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreBauxite", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreAlmandine", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreGraphite", 25)); + mMixedOreData.put(new Pair<String, Integer>("oreGlauconite", 15)); + mMixedOreData.put(new Pair<String, Integer>("orePyrolusite", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreGrossular", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreTantalite", 15)); + + for (Pair<String, Integer> g : mMixedOreData) { + for (int i = 0; i < g.getValue(); i++) { + aTempMap.put(ItemUtils.getItemStackOfAmountFromOreDict(g.getKey(), 1)); + } + } + Logger.INFO("Ore Map contains " + aTempMap.size() + " values. [Extra Mixed Ores]"); + + addOreTypeToMap(ELEMENT.STANDALONE.RUNITE, 2, aTempMap); + addOreTypeToMap(ELEMENT.STANDALONE.GRANITE, 8, aTempMap); + Logger.INFO("Ore Map contains " + aTempMap.size() + " values. [OSRS Ores]"); + + AutoMap<Material> aMyOreMaterials = new AutoMap<Material>(); + aMyOreMaterials.add(ORES.CROCROITE); + aMyOreMaterials.add(ORES.GEIKIELITE); + aMyOreMaterials.add(ORES.NICHROMITE); + aMyOreMaterials.add(ORES.TITANITE); + aMyOreMaterials.add(ORES.ZIMBABWEITE); + aMyOreMaterials.add(ORES.ZIRCONILITE); + aMyOreMaterials.add(ORES.GADOLINITE_CE); + aMyOreMaterials.add(ORES.GADOLINITE_Y); + aMyOreMaterials.add(ORES.LEPERSONNITE); + aMyOreMaterials.add(ORES.SAMARSKITE_Y); + aMyOreMaterials.add(ORES.SAMARSKITE_YB); + aMyOreMaterials.add(ORES.XENOTIME); + aMyOreMaterials.add(ORES.YTTRIAITE); + aMyOreMaterials.add(ORES.YTTRIALITE); + aMyOreMaterials.add(ORES.YTTROCERITE); + aMyOreMaterials.add(ORES.ZIRCON); + aMyOreMaterials.add(ORES.POLYCRASE); + aMyOreMaterials.add(ORES.ZIRCOPHYLLITE); + aMyOreMaterials.add(ORES.ZIRKELITE); + aMyOreMaterials.add(ORES.LANTHANITE_LA); + aMyOreMaterials.add(ORES.LANTHANITE_CE); + aMyOreMaterials.add(ORES.LANTHANITE_ND); + aMyOreMaterials.add(ORES.AGARDITE_Y); + aMyOreMaterials.add(ORES.AGARDITE_CD); + aMyOreMaterials.add(ORES.AGARDITE_LA); + aMyOreMaterials.add(ORES.AGARDITE_ND); + aMyOreMaterials.add(ORES.HIBONITE); + aMyOreMaterials.add(ORES.CERITE); + aMyOreMaterials.add(ORES.FLUORCAPHITE); + aMyOreMaterials.add(ORES.FLORENCITE); + aMyOreMaterials.add(ORES.CRYOLITE); + aMyOreMaterials.add(ORES.LAUTARITE); + aMyOreMaterials.add(ORES.LAFOSSAITE); + aMyOreMaterials.add(ORES.DEMICHELEITE_BR); + aMyOreMaterials.add(ORES.COMANCHEITE); + aMyOreMaterials.add(ORES.PERROUDITE); + aMyOreMaterials.add(ORES.HONEAITE); + aMyOreMaterials.add(ORES.ALBURNITE); + aMyOreMaterials.add(ORES.MIESSIITE); + aMyOreMaterials.add(ORES.KASHINITE); + aMyOreMaterials.add(ORES.IRARSITE); + aMyOreMaterials.add(ORES.RADIOBARITE); + aMyOreMaterials.add(ORES.DEEP_EARTH_REACTOR_FUEL_DEPOSIT); + + for (Material aOreType : aMyOreMaterials) { + if (aOreType == ORES.DEEP_EARTH_REACTOR_FUEL_DEPOSIT || aOreType == ORES.RADIOBARITE) { + addOreTypeToMap(aOreType, 4, aTempMap); + } else { + addOreTypeToMap(aOreType, 7, aTempMap); + } + } + + // Cleanup Map + Logger.INFO("Ore Map contains " + aTempMap.size() + " values. [GT++]"); + AutoMap<ItemStack> aCleanUp = new AutoMap<ItemStack>(); + for (ItemStack verify : aTempMap) { + if (!ItemUtils.checkForInvalidItems(verify)) { + aCleanUp.put(verify); + } + } + Logger.INFO("Cleanup Map contains " + aCleanUp.size() + " values."); + for (ItemStack remove : aCleanUp) { + aTempMap.remove(remove); + } + + // Generate Massive Map + AutoMap<ItemStack> aFinalMap = new AutoMap<ItemStack>(); + for (ItemStack aTempItem : aTempMap) { + int aTempMulti = MathUtils.randInt(20, 50); + for (int i = 0; i < aTempMulti; i++) { + aFinalMap.put(aTempItem.copy()); + } + } + Logger.INFO("Final Ore Map contains " + aFinalMap.size() + " values."); + mOutputs = aFinalMap; + return mOutputs; + } + + private static void addOreTypeToMap(Material aMaterial, int aAmount, AutoMap<ItemStack> aMap) { + for (int i = 0; i < aAmount; i++) { + aMap.add(aMaterial.getOre(1)); + } + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Miner"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java index 77916eb9f4..87442949a5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java @@ -1,11 +1,13 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.chemplant; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.IntStream; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.withChannel; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.filterByMTETier; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -32,953 +34,995 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.GT_MetaTileEntity_Hatch_Catalysts; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.tuple.Pair; - - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.withChannel; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.filterByMTETier; -import static gregtech.api.util.GT_StructureUtility.ofCoil; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; -public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<GregtechMTE_ChemicalPlant> implements ISurvivalConstructable { - - private int mSolidCasingTier = 0; - private int mMachineCasingTier = 0; - private int mPipeCasingTier = 0; - private int mCoilTier = 0; - private HeatingCoilLevel checkCoil; - private int[] checkCasing = new int[8]; - private int checkMachine; - private int checkPipe; - private int maxTierOfHatch; - private int mCasing; - private IStructureDefinition<GregtechMTE_ChemicalPlant> STRUCTURE_DEFINITION = null; - - private final ArrayList<GT_MetaTileEntity_Hatch_Catalysts> mCatalystBuses = new ArrayList<GT_MetaTileEntity_Hatch_Catalysts>(); - - private static final HashMap<Integer, Triplet<Block, Integer, Integer>> mTieredBlockRegistry = new HashMap<>(); - - public GregtechMTE_ChemicalPlant(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMTE_ChemicalPlant(final String aName) { - super(aName); - } - - public static boolean registerMachineCasingForTier(int aTier, Block aBlock, int aMeta, int aCasingTextureID) { - Triplet<Block, Integer, Integer> aCasingData = new Triplet<Block, Integer, Integer>(aBlock, aMeta, aCasingTextureID); - if (mTieredBlockRegistry.containsKey(aTier)) { - CORE.crash("Tried to register a Machine casing for tier "+aTier+" to the Chemical Plant, however this tier already contains one."); - } - mTieredBlockRegistry.put(aTier, aCasingData); - return true; - } - - private static int getCasingTextureIdForTier(int aTier) { - if (!mTieredBlockRegistry.containsKey(aTier)) { - return 10; - } - int aCasingID = mTieredBlockRegistry.get(aTier).getValue_3(); - //Logger.INFO("Found casing texture ID "+aCasingID+" for tier "+aTier); - return aCasingID; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMTE_ChemicalPlant(this.mName); - } - - @Override - public String getMachineType() { - return "Chemical Plant"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the Chemical Plant") - .addInfo("Heavy Industry, now right at your doorstep!") - .addInfo("Please read the user manual for more information on construction and usage") - .addSeparator() - .addController("Bottom Center") - .addStructureHint("Catalyst Housing", 1) - .addInputBus("Bottom Casing", 1) - .addOutputBus("Bottom Casing", 1) - .addInputHatch("Bottom Casing", 1) - .addOutputHatch("Bottom Casing", 1) - .addEnergyHatch("Bottom Casing", 1) - .addMaintenanceHatch("Bottom Casing", 1) - .addSubChannelUsage("casing", "metal machine casing") - .addSubChannelUsage("machine", "tier machine casing") - .addSubChannelUsage("coil", "heating coil blocks") - .addSubChannelUsage("pipe", "pipe casing blocks") - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - public void setMachineMeta(int meta) { - checkMachine = meta; - } - - public int getMachineMeta() { - return checkMachine; - } - - public void setPipeMeta(int meta) { - checkPipe = meta; - } - - public int getPipeMeta() { - return checkPipe; - } - - public void setCoilMeta(HeatingCoilLevel meta) { - checkCoil = meta; - } - - public HeatingCoilLevel getCoilMeta() { - return checkCoil; - } - - public int coilTier(int meta) { - switch (meta) { - case 0: return 1; - case 1: return 2; - case 2: return 3; - case 3: return 4; - case 4: return 5; - case 5: return 7; - case 6: return 8; - case 7: return 10; - case 8: return 11; - case 9: return 6; - case 10: return 9; - case 11: return 12; - case 12: return 13; - case 13: return 14; - default: return 0; - } - } - - @Override - public IStructureDefinition<GregtechMTE_ChemicalPlant> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - IStructureElement<GregtechMTE_ChemicalPlant> allCasingsElement = withChannel( - "casing", - ofChain( - IntStream.range(0, 8) - .mapToObj(GregtechMTE_ChemicalPlant::ofSolidCasing) - .collect(Collectors.toList()) - ) - ); - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_ChemicalPlant>builder() - .addShape(mName, transpose(new String[][]{ - {"XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX"}, - {"X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X"}, - {"X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X"}, - {"X X", " ", " HHH ", " HHH ", " HHH ", " ", "X X"}, - {"X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X"}, - {"X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X"}, - {"CCC~CCC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CCCCCCC"}, - })) - .addElement( - 'C', - ofChain( - buildHatchAdder(GregtechMTE_ChemicalPlant.class) - .atLeast(Maintenance) - .casingIndex(getCasingTextureID()) - .dot(1) - .build(), - buildHatchAdder(GregtechMTE_ChemicalPlant.class) - .atLeast(InputHatch, OutputHatch, InputBus, OutputBus) - .adder(GregtechMTE_ChemicalPlant::addChemicalPlantList) - .hatchItemFilterAnd((t, s) -> filterByMTETier(Integer.MIN_VALUE, s.stackSize >= 10 ? Integer.MAX_VALUE : s.stackSize)) - .casingIndex(getCasingTextureID()) - .dot(1) - .build(), - buildHatchAdder(GregtechMTE_ChemicalPlant.class) - .hatchClass(GT_MetaTileEntity_Hatch_Catalysts.class) - .adder(GregtechMTE_ChemicalPlant::addChemicalPlantList) - .casingIndex(getCasingTextureID()) - .dot(1) - .build(), - allCasingsElement - ) - ) - .addElement( - 'X', - allCasingsElement - ) - .addElement( - 'M', - withChannel( - "machine", - addTieredBlock( - GregTech_API.sBlockCasings1, GregtechMTE_ChemicalPlant::setMachineMeta, GregtechMTE_ChemicalPlant::getMachineMeta, 10 - ) - ) - ) - .addElement( - 'H', - withChannel( - "coil", - ofCoil(GregtechMTE_ChemicalPlant::setCoilMeta, GregtechMTE_ChemicalPlant::getCoilMeta) - ) - ) - .addElement( - 'P', - withChannel( - "pipe", - addTieredBlock( - GregTech_API.sBlockCasings2, GregtechMTE_ChemicalPlant::setPipeMeta, GregtechMTE_ChemicalPlant::getPipeMeta, 12, 16 - ) - ) - ) - .build(); - } - return STRUCTURE_DEFINITION; - } - - private static IStructureElement<GregtechMTE_ChemicalPlant> ofSolidCasing(int aIndex) { - return new IStructureElement<GregtechMTE_ChemicalPlant>() { - @Override - public boolean check(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z) { - if (check(aIndex, world, x, y, z)) { - t.checkCasing[aIndex]++; - t.mCasing++; - return true; - } - else return false; - } - - private boolean check(int aIndex, World world, int x, int y, int z) { - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - Block target = mTieredBlockRegistry.get(aIndex).getValue_1(); - int targetMeta = mTieredBlockRegistry.get(aIndex).getValue_2(); - return target.equals(block) && meta == targetMeta; - } - - int getIndex(int size) { - if (size > 8) size = 8; - return size - 1; - } - - @Override - public boolean spawnHint(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2()); - return true; - } - - @Override - public boolean placeBlock(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z, ItemStack trigger) { - return world.setBlock(x, y, z, mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2(), 3); - } - - @Override - public PlaceResult survivalPlaceBlock(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z, ItemStack trigger, IItemSource s, EntityPlayerMP actor, Consumer<IChatComponent> chatter) { - if (check(getIndex(trigger.stackSize), world, x, y, z)) return PlaceResult.SKIP; - return StructureUtility.survivalPlaceBlock(mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2(), world, x, y, z, s, actor, chatter); - } - }; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(mName , stackSize, hintsOnly, 3, 6, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - return survivialBuildPiece(mName, stackSize, 3, 6, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - for (int i = 0; i < 8; i++) { - checkCasing[i] = 0; - } - checkPipe = 0; - checkMachine = 0; - mSolidCasingTier = 0; - mMachineCasingTier = 0; - mPipeCasingTier = 0; - mCoilTier = 0; - mCatalystBuses.clear(); - if (checkPiece(mName, 3, 6, 0) && mCasing >= 70) { - for (int i = 0; i < 8; i++) { - if (checkCasing[i] == mCasing) { - mSolidCasingTier = i; - } - else if (checkCasing[i] > 0) - return false; - } - mMachineCasingTier = checkMachine - 1; - mPipeCasingTier = checkPipe - 12; - mCoilTier = checkCoil.getTier(); - getBaseMetaTileEntity().sendBlockEvent(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, getUpdateData()); - updateHatchTexture(); - return mMachineCasingTier >= 9 || mMachineCasingTier >= maxTierOfHatch; - } - return false; - } - - public void updateHatchTexture() { - for (GT_MetaTileEntity_Hatch h : mCatalystBuses) h.updateTexture(getCasingTextureID()); - for (GT_MetaTileEntity_Hatch h : mInputBusses) h.updateTexture(getCasingTextureID()); - for (GT_MetaTileEntity_Hatch h : mMaintenanceHatches) h.updateTexture(getCasingTextureID()); - for (GT_MetaTileEntity_Hatch h : mEnergyHatches) h.updateTexture(getCasingTextureID()); - for (GT_MetaTileEntity_Hatch h : mOutputBusses) h.updateTexture(getCasingTextureID()); - for (GT_MetaTileEntity_Hatch h : mInputHatches) h.updateTexture(getCasingTextureID()); - for (GT_MetaTileEntity_Hatch h : mOutputHatches) h.updateTexture(getCasingTextureID()); - } - - public final boolean addChemicalPlantList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Catalysts){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ - maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier); - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ - maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity).mTier); - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { - maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity).mTier); - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { - maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier); - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { - maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity).mTier); - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - return false; - } - - @Override - public String getSound() { - return GregTech_API.sSoundList.get(Integer.valueOf(207)); - } - - @Override - protected IIconContainer getActiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; - } - - @Override - protected IIconContainer getInactiveOverlay() { - return TexturesGtBlock.Overlay_Machine_Controller_Advanced; - } - - @Override - protected int getCasingTextureId() { - return getCasingTextureID(); - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - if (GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList.size() == 0) { - generateRecipes(); - } - return GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT; - } - - public static void generateRecipes() { - for (GT_Recipe i : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlantRecipes.mRecipeList) { - GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.add(i); - } - } - - @Override - public int getMaxParallelRecipes() { - return 2 * getPipeCasingTier(); - } - - @Override - public int getEuDiscountForParallelism() { - return 100; - } - - private int getSolidCasingTier() { - return this.mSolidCasingTier; - } - - private int getMachineCasingTier() { - return mMachineCasingTier; - } - - private int getPipeCasingTier() { - return mPipeCasingTier; - } - - private int getCasingTextureID() { - // Check the Tier Client Side - int aTier = mSolidCasingTier; - return getCasingTextureIdForTier(aTier); - } - - public boolean addToMachineList(IGregTechTileEntity aTileEntity) { - int aMaxTier = getMachineCasingTier(); - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock) { - GT_MetaTileEntity_TieredMachineBlock aMachineBlock = (GT_MetaTileEntity_TieredMachineBlock) aMetaTileEntity; - int aTileTier = aMachineBlock.mTier; - if (aTileTier > aMaxTier) { - log("Hatch tier too high."); - return false; - } - else { - return addToMachineList(aTileEntity, getCasingTextureID()); - } - } - else { - log("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. - return false; - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("mSolidCasingTier", this.mSolidCasingTier); - aNBT.setInteger("mMachineCasingTier", this.mMachineCasingTier); - aNBT.setInteger("mPipeCasingTier", this.mPipeCasingTier); - aNBT.setInteger("mCoilTier", this.mCoilTier); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - mSolidCasingTier = aNBT.getInteger("mSolidCasingTier"); - mMachineCasingTier = aNBT.getInteger("mMachineCasingTier"); - mPipeCasingTier = aNBT.getInteger("mPipeCasingTier"); - mCoilTier = aNBT.getInteger("mCoilTier"); - } - - @Override - public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Catalysts) { - log("Found GT_MetaTileEntity_Hatch_Catalysts"); - return addToMachineListInternal(mCatalystBuses, aMetaTileEntity, aBaseCasingIndex); - } - return super.addToMachineList(aTileEntity, aBaseCasingIndex); - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerTick(final ItemStack aStack) { - return 0; - } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - // Same speed bonus as pyro oven - public int getSpeedBonus() { - return 50 * (this.mCoilTier - 1); - } - - public int getMaxCatalystDurability() { - return 50; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mUpdate == 1 || this.mStartUpCheck == 1) { - this.mCatalystBuses.clear(); - } - } - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - @Override - public byte getUpdateData() { - return (byte) mSolidCasingTier; - } - - @Override - public void receiveClientEvent(byte aEventID, byte aValue) { - super.receiveClientEvent(aEventID, aValue); - if (aEventID == GregTechTileClientEvents.CHANGE_CUSTOM_DATA && (aValue & 0x80) == 0) { - // received an update data from above method - // if no &0x80 clause it might catch the noop texture page event - mSolidCasingTier = aValue; - } - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), getSpeedBonus()); - } - - @Override - public boolean checkRecipeGeneric(int aMaxParallelRecipes, long aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { - ArrayList<ItemStack> tItems = getStoredInputs(); - ArrayList<FluidStack> tFluids = getStoredFluids(); - ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); - FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); - return checkRecipeGeneric(tItemInputs, tFluidInputs, aMaxParallelRecipes, aEUPercent, aSpeedBonusPercent, aOutputChanceRoll); - } - - @Override - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - - // Based on the Processing Array. A bit overkill, but very flexible. - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - //GT_Recipe tRecipe = findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - GT_Recipe tRecipe = findRecipe(mLastRecipe, gregtech.api.enums.GT_Values.V[tTier], getSolidCasingTier(), aItemInputs, aFluidInputs); - - if (tRecipe == null) { - log("BAD RETURN - 1"); - return false; - } - - // checks if it has a catalyst - ItemStack tCatalystRecipe = null; - boolean aDoesRecipeNeedCatalyst = false; - for (ItemStack aInputItem : tRecipe.mInputs) { - if (ItemUtils.isCatalyst(aInputItem)) { - aDoesRecipeNeedCatalyst = true; - break; - } - } - if (aDoesRecipeNeedCatalyst) { - tCatalystRecipe = findCatalyst(aItemInputs, tRecipe.mInputs); - if (tCatalystRecipe == null) { - log("does not have catalyst"); - return false; - } - if (mCatalystBuses.size() != 1) { - log("does not have correct number of catalyst hatches. (Required 1, found "+mCatalystBuses.size()+")"); - return false; - } - } - - - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - if (tRecipe.mSpecialValue > this.mSolidCasingTier) { - log("solid tier is too low"); - return false; - } - - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); - if (aMaxParallelRecipes == 0) { - log("BAD RETURN - 2"); - return false; - } - - // checks if it has enough catalyst durability - ArrayList<ItemStack>tCatalysts = null; - int tMaxParallelCatalyst = aMaxParallelRecipes; - if (tCatalystRecipe != null) { - tCatalysts = new ArrayList<ItemStack>(); - tMaxParallelCatalyst = getCatalysts(aItemInputs, tCatalystRecipe, aMaxParallelRecipes, tCatalysts); - log("Can process "+tMaxParallelCatalyst+" recipes. If less than "+aMaxParallelRecipes+", catalyst does not have enough durability."); - } - - if (tMaxParallelCatalyst == 0) { - log("found not enough catalysts"); - return false; - } - - // EU discount - float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - log("aEUPercent "+aEUPercent); - log("mEUt "+tRecipe.mEUt); - - int parallelRecipes = 0; - - log("parallelRecipes: "+parallelRecipes); - log("aMaxParallelRecipes: "+tMaxParallelCatalyst); - log("tTotalEUt: "+tTotalEUt); - log("tVoltage: "+tVoltage); - log("tEnergy: "+tEnergy); - log("tRecipeEUt: "+tRecipeEUt); - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < tMaxParallelCatalyst && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - log("Broke at "+parallelRecipes+"."); - break; - } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; - } - - if (parallelRecipes == 0) { - log("BAD RETURN - 3"); - return false; - } - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); - - this.mEUt = (int)Math.ceil(tTotalEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < parallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; - } - } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); - } - } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } - - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Damage catalyst once all is said and done. - if (tCatalystRecipe != null) { - log("damaging catalyst"); - damageCatalyst(tCatalystRecipe, parallelRecipes); - } - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - for (GT_MetaTileEntity_Hatch_Catalysts h : mCatalystBuses) { - h.updateSlots(); - h.tryFillUsageSlots(); - } - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - log("GOOD RETURN - 1"); - return true; - } - - private static final HashMap<Long, AutoMap<GT_Recipe>> mTieredRecipeMap = new HashMap<Long, AutoMap<GT_Recipe>>(); - private static final AutoMap<GT_Recipe> aTier0Recipes = new AutoMap<GT_Recipe>(); - private static final AutoMap<GT_Recipe> aTier1Recipes = new AutoMap<GT_Recipe>(); - private static final AutoMap<GT_Recipe> aTier2Recipes = new AutoMap<GT_Recipe>(); - private static final AutoMap<GT_Recipe> aTier3Recipes = new AutoMap<GT_Recipe>(); - private static final AutoMap<GT_Recipe> aTier4Recipes = new AutoMap<GT_Recipe>(); - private static final AutoMap<GT_Recipe> aTier5Recipes = new AutoMap<GT_Recipe>(); - private static final AutoMap<GT_Recipe> aTier6Recipes = new AutoMap<GT_Recipe>(); - private static final AutoMap<GT_Recipe> aTier7Recipes = new AutoMap<GT_Recipe>(); - private static boolean mInitRecipeCache = false; - - private static void initRecipeCaches() { - if (!mInitRecipeCache) { - mTieredRecipeMap.put((long) 0, aTier0Recipes); - mTieredRecipeMap.put((long) 1, aTier1Recipes); - mTieredRecipeMap.put((long) 2, aTier2Recipes); - mTieredRecipeMap.put((long) 3, aTier3Recipes); - mTieredRecipeMap.put((long) 4, aTier4Recipes); - mTieredRecipeMap.put((long) 5, aTier5Recipes); - mTieredRecipeMap.put((long) 6, aTier6Recipes); - mTieredRecipeMap.put((long) 7, aTier7Recipes); - for (GT_Recipe aRecipe : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList) { - if (aRecipe != null) { - switch (aRecipe.mSpecialValue) { - case 0: - aTier0Recipes.add(aRecipe); - continue; - case 1: - aTier1Recipes.add(aRecipe); - continue; - case 2: - aTier2Recipes.add(aRecipe); - continue; - case 3: - aTier3Recipes.add(aRecipe); - continue; - case 4: - aTier4Recipes.add(aRecipe); - continue; - case 5: - aTier5Recipes.add(aRecipe); - continue; - case 6: - aTier6Recipes.add(aRecipe); - continue; - case 7: - aTier7Recipes.add(aRecipe); - continue; - } - } - } - mInitRecipeCache = true; - } - } - - public GT_Recipe findRecipe(final GT_Recipe aRecipe, final long aVoltage, final long aSpecialValue, ItemStack[] aInputs, final FluidStack[] aFluids) { - if (!mInitRecipeCache) { - initRecipeCaches(); - } - if (this.getRecipeMap().mRecipeList.isEmpty()) { - log("No Recipes in Map to search through."); - return null; - } - else { - log("Checking tier "+aSpecialValue+" recipes and below. Using Input Voltage of "+aVoltage+"V."); - log("We have "+aInputs.length+" Items and "+aFluids.length+" Fluids."); - // Try check the cached recipe first - if (aRecipe != null) { - if (aRecipe.isRecipeInputEqual(false, aFluids, aInputs)) { - if (aRecipe.mEUt <= aVoltage) { - Logger.INFO("Using cached recipe."); - return aRecipe; - } - } - } - - // Get all recipes for the tier - AutoMap<AutoMap<GT_Recipe>> aMasterMap = new AutoMap<AutoMap<GT_Recipe>>(); - for (long i=0;i<=aSpecialValue;i++) { - aMasterMap.add(mTieredRecipeMap.get(i)); - } - GT_Recipe aFoundRecipe = null; - - // Iterate the tiers recipes until we find the one with all inputs matching - master : for (AutoMap<GT_Recipe> aTieredMap : aMasterMap) { - for (GT_Recipe aRecipeToCheck : aTieredMap) { - if (aRecipeToCheck.isRecipeInputEqual(false, aFluids, aInputs)) { - log("Found recipe with matching inputs!"); - if (aRecipeToCheck.mSpecialValue <= aSpecialValue) { - if (aRecipeToCheck.mEUt <= aVoltage) { - aFoundRecipe = aRecipeToCheck; - break master; - } - } - } - } - } - - // If we found a recipe, return it - if (aFoundRecipe != null) { - log("Found valid recipe."); - return aFoundRecipe; - } - } - log("Did not find valid recipe."); - return null; - } - - private int getCatalysts(ItemStack[] aItemInputs, ItemStack aRecipeCatalyst, int aMaxParrallel, ArrayList<ItemStack> aOutPut) { - int allowedParallel = 0; - for (final ItemStack aInput : aItemInputs) { - if (aRecipeCatalyst.isItemEqual(aInput)) { - int aDurabilityRemaining = getMaxCatalystDurability() - getDamage(aInput); - return Math.min(aMaxParrallel, aDurabilityRemaining); - } - } - return allowedParallel; - } - - private ItemStack findCatalyst(ItemStack[] aItemInputs, ItemStack[] aRecipeInputs) { - if (aItemInputs != null) { - for (final ItemStack aInput : aItemInputs) { - if (aInput != null) { - if (ItemUtils.isCatalyst(aInput)) { - for (ItemStack aRecipeInput : aRecipeInputs) { - if (GT_Utility.areStacksEqual(aRecipeInput, aInput, true)) { - return aInput; - } - } - } - } - } - } - return null; - } - - - private void damageCatalyst(ItemStack aStack, int parallelRecipes) { - for (int i=0; i<parallelRecipes; i++){ - // Awakened Draconium Coils with Tungstensteel Pipe Casings (or above) no longer consume catalysts. - if (this.mCoilTier >= 10 && this.mPipeCasingTier >= 4) { - log("not consuming catalyst"); - } - else if (MathUtils.randFloat(0, 10000000)/10000000f < (1.2f - (0.2 * this.mPipeCasingTier))) { - int damage = getDamage(aStack) + 1; - log("damage catalyst "+damage); - if (damage >= getMaxCatalystDurability()) { - log("consume catalyst"); - addOutput(CI.getEmptyCatalyst(1)); - aStack.stackSize -= 1; - } - else { - log("damaging catalyst"); - setDamage(aStack, damage); - } - } - else { - log("not consuming catalyst"); - } - } - } - - private int getDamage(ItemStack aStack) { - return ItemGenericChemBase.getCatalystDamage(aStack); - } - - private void setDamage(ItemStack aStack,int aAmount) { - ItemGenericChemBase.setCatalystDamage(aStack, aAmount); - } - - /* - * Catalyst Handling - */ - @Override - public ArrayList<ItemStack> getStoredInputs() { - ArrayList<ItemStack> tItems = super.getStoredInputs(); - if (this.hasSlotInGUI() && this.getGUIItemStack() != null) { - tItems.add(this.getGUIItemStack()); - } - for (GT_MetaTileEntity_Hatch_Catalysts tHatch : mCatalystBuses) { - tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - AutoMap<ItemStack> aHatchContent = tHatch.getContentUsageSlots(); - if (!aHatchContent.isEmpty()) { - tItems.addAll(aHatchContent); - } - } - } - return tItems; - } +public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<GregtechMTE_ChemicalPlant> + implements ISurvivalConstructable { + + private int mSolidCasingTier = 0; + private int mMachineCasingTier = 0; + private int mPipeCasingTier = 0; + private int mCoilTier = 0; + private HeatingCoilLevel checkCoil; + private int[] checkCasing = new int[8]; + private int checkMachine; + private int checkPipe; + private int maxTierOfHatch; + private int mCasing; + private IStructureDefinition<GregtechMTE_ChemicalPlant> STRUCTURE_DEFINITION = null; + + private final ArrayList<GT_MetaTileEntity_Hatch_Catalysts> mCatalystBuses = + new ArrayList<GT_MetaTileEntity_Hatch_Catalysts>(); + + private static final HashMap<Integer, Triplet<Block, Integer, Integer>> mTieredBlockRegistry = new HashMap<>(); + + public GregtechMTE_ChemicalPlant(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_ChemicalPlant(final String aName) { + super(aName); + } + + public static boolean registerMachineCasingForTier(int aTier, Block aBlock, int aMeta, int aCasingTextureID) { + Triplet<Block, Integer, Integer> aCasingData = + new Triplet<Block, Integer, Integer>(aBlock, aMeta, aCasingTextureID); + if (mTieredBlockRegistry.containsKey(aTier)) { + CORE.crash("Tried to register a Machine casing for tier " + aTier + + " to the Chemical Plant, however this tier already contains one."); + } + mTieredBlockRegistry.put(aTier, aCasingData); + return true; + } + + private static int getCasingTextureIdForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return 10; + } + int aCasingID = mTieredBlockRegistry.get(aTier).getValue_3(); + // Logger.INFO("Found casing texture ID "+aCasingID+" for tier "+aTier); + return aCasingID; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_ChemicalPlant(this.mName); + } + + @Override + public String getMachineType() { + return "Chemical Plant"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Chemical Plant") + .addInfo("Heavy Industry, now right at your doorstep!") + .addInfo("Please read the user manual for more information on construction and usage") + .addSeparator() + .addController("Bottom Center") + .addStructureHint("Catalyst Housing", 1) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addOutputHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addSubChannelUsage("casing", "metal machine casing") + .addSubChannelUsage("machine", "tier machine casing") + .addSubChannelUsage("coil", "heating coil blocks") + .addSubChannelUsage("pipe", "pipe casing blocks") + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + public void setMachineMeta(int meta) { + checkMachine = meta; + } + + public int getMachineMeta() { + return checkMachine; + } + + public void setPipeMeta(int meta) { + checkPipe = meta; + } + + public int getPipeMeta() { + return checkPipe; + } + + public void setCoilMeta(HeatingCoilLevel meta) { + checkCoil = meta; + } + + public HeatingCoilLevel getCoilMeta() { + return checkCoil; + } + + public int coilTier(int meta) { + switch (meta) { + case 0: + return 1; + case 1: + return 2; + case 2: + return 3; + case 3: + return 4; + case 4: + return 5; + case 5: + return 7; + case 6: + return 8; + case 7: + return 10; + case 8: + return 11; + case 9: + return 6; + case 10: + return 9; + case 11: + return 12; + case 12: + return 13; + case 13: + return 14; + default: + return 0; + } + } + + @Override + public IStructureDefinition<GregtechMTE_ChemicalPlant> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + IStructureElement<GregtechMTE_ChemicalPlant> allCasingsElement = withChannel( + "casing", + ofChain(IntStream.range(0, 8) + .mapToObj(GregtechMTE_ChemicalPlant::ofSolidCasing) + .collect(Collectors.toList()))); + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_ChemicalPlant>builder() + .addShape(mName, transpose(new String[][] { + {"XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX"}, + {"X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X"}, + {"X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X"}, + {"X X", " ", " HHH ", " HHH ", " HHH ", " ", "X X"}, + {"X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X"}, + {"X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X"}, + {"CCC~CCC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CCCCCCC"}, + })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMTE_ChemicalPlant.class) + .atLeast(Maintenance) + .casingIndex(getCasingTextureID()) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_ChemicalPlant.class) + .atLeast(InputHatch, OutputHatch, InputBus, OutputBus) + .adder(GregtechMTE_ChemicalPlant::addChemicalPlantList) + .hatchItemFilterAnd((t, s) -> filterByMTETier( + Integer.MIN_VALUE, + s.stackSize >= 10 ? Integer.MAX_VALUE : s.stackSize)) + .casingIndex(getCasingTextureID()) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_ChemicalPlant.class) + .hatchClass(GT_MetaTileEntity_Hatch_Catalysts.class) + .adder(GregtechMTE_ChemicalPlant::addChemicalPlantList) + .casingIndex(getCasingTextureID()) + .dot(1) + .build(), + allCasingsElement)) + .addElement('X', allCasingsElement) + .addElement( + 'M', + withChannel( + "machine", + addTieredBlock( + GregTech_API.sBlockCasings1, + GregtechMTE_ChemicalPlant::setMachineMeta, + GregtechMTE_ChemicalPlant::getMachineMeta, + 10))) + .addElement( + 'H', + withChannel( + "coil", + ofCoil( + GregtechMTE_ChemicalPlant::setCoilMeta, + GregtechMTE_ChemicalPlant::getCoilMeta))) + .addElement( + 'P', + withChannel( + "pipe", + addTieredBlock( + GregTech_API.sBlockCasings2, + GregtechMTE_ChemicalPlant::setPipeMeta, + GregtechMTE_ChemicalPlant::getPipeMeta, + 12, + 16))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + private static IStructureElement<GregtechMTE_ChemicalPlant> ofSolidCasing(int aIndex) { + return new IStructureElement<GregtechMTE_ChemicalPlant>() { + @Override + public boolean check(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z) { + if (check(aIndex, world, x, y, z)) { + t.checkCasing[aIndex]++; + t.mCasing++; + return true; + } else return false; + } + + private boolean check(int aIndex, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + Block target = mTieredBlockRegistry.get(aIndex).getValue_1(); + int targetMeta = mTieredBlockRegistry.get(aIndex).getValue_2(); + return target.equals(block) && meta == targetMeta; + } + + int getIndex(int size) { + if (size > 8) size = 8; + return size - 1; + } + + @Override + public boolean spawnHint(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle( + world, + x, + y, + z, + mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), + mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2()); + return true; + } + + @Override + public boolean placeBlock( + GregtechMTE_ChemicalPlant t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock( + x, + y, + z, + mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), + mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2(), + 3); + } + + @Override + public PlaceResult survivalPlaceBlock( + GregtechMTE_ChemicalPlant t, + World world, + int x, + int y, + int z, + ItemStack trigger, + IItemSource s, + EntityPlayerMP actor, + Consumer<IChatComponent> chatter) { + if (check(getIndex(trigger.stackSize), world, x, y, z)) return PlaceResult.SKIP; + return StructureUtility.survivalPlaceBlock( + mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), + mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2(), + world, + x, + y, + z, + s, + actor, + chatter); + } + }; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 3, 6, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 3, 6, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + for (int i = 0; i < 8; i++) { + checkCasing[i] = 0; + } + checkPipe = 0; + checkMachine = 0; + mSolidCasingTier = 0; + mMachineCasingTier = 0; + mPipeCasingTier = 0; + mCoilTier = 0; + mCatalystBuses.clear(); + if (checkPiece(mName, 3, 6, 0) && mCasing >= 70) { + for (int i = 0; i < 8; i++) { + if (checkCasing[i] == mCasing) { + mSolidCasingTier = i; + } else if (checkCasing[i] > 0) return false; + } + mMachineCasingTier = checkMachine - 1; + mPipeCasingTier = checkPipe - 12; + mCoilTier = checkCoil.getTier(); + getBaseMetaTileEntity().sendBlockEvent(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, getUpdateData()); + updateHatchTexture(); + return mMachineCasingTier >= 9 || mMachineCasingTier >= maxTierOfHatch; + } + return false; + } + + public void updateHatchTexture() { + for (GT_MetaTileEntity_Hatch h : mCatalystBuses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mInputBusses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mMaintenanceHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mEnergyHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mOutputBusses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mInputHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mOutputHatches) h.updateTexture(getCasingTextureID()); + } + + public final boolean addChemicalPlantList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Catalysts) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureID(); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList.size() == 0) { + generateRecipes(); + } + return GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT; + } + + public static void generateRecipes() { + for (GT_Recipe i : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlantRecipes.mRecipeList) { + GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.add(i); + } + } + + @Override + public int getMaxParallelRecipes() { + return 2 * getPipeCasingTier(); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + private int getSolidCasingTier() { + return this.mSolidCasingTier; + } + + private int getMachineCasingTier() { + return mMachineCasingTier; + } + + private int getPipeCasingTier() { + return mPipeCasingTier; + } + + private int getCasingTextureID() { + // Check the Tier Client Side + int aTier = mSolidCasingTier; + return getCasingTextureIdForTier(aTier); + } + + public boolean addToMachineList(IGregTechTileEntity aTileEntity) { + int aMaxTier = getMachineCasingTier(); + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock) { + GT_MetaTileEntity_TieredMachineBlock aMachineBlock = (GT_MetaTileEntity_TieredMachineBlock) aMetaTileEntity; + int aTileTier = aMachineBlock.mTier; + if (aTileTier > aMaxTier) { + log("Hatch tier too high."); + return false; + } else { + return addToMachineList(aTileEntity, getCasingTextureID()); + } + } else { + log("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. + return false; + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mSolidCasingTier", this.mSolidCasingTier); + aNBT.setInteger("mMachineCasingTier", this.mMachineCasingTier); + aNBT.setInteger("mPipeCasingTier", this.mPipeCasingTier); + aNBT.setInteger("mCoilTier", this.mCoilTier); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mSolidCasingTier = aNBT.getInteger("mSolidCasingTier"); + mMachineCasingTier = aNBT.getInteger("mMachineCasingTier"); + mPipeCasingTier = aNBT.getInteger("mPipeCasingTier"); + mCoilTier = aNBT.getInteger("mCoilTier"); + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Catalysts) { + log("Found GT_MetaTileEntity_Hatch_Catalysts"); + return addToMachineListInternal(mCatalystBuses, aMetaTileEntity, aBaseCasingIndex); + } + return super.addToMachineList(aTileEntity, aBaseCasingIndex); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + // Same speed bonus as pyro oven + public int getSpeedBonus() { + return 50 * (this.mCoilTier - 1); + } + + public int getMaxCatalystDurability() { + return 50; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mCatalystBuses.clear(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public byte getUpdateData() { + return (byte) mSolidCasingTier; + } + + @Override + public void receiveClientEvent(byte aEventID, byte aValue) { + super.receiveClientEvent(aEventID, aValue); + if (aEventID == GregTechTileClientEvents.CHANGE_CUSTOM_DATA && (aValue & 0x80) == 0) { + // received an update data from above method + // if no &0x80 clause it might catch the noop texture page event + mSolidCasingTier = aValue; + } + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), getSpeedBonus()); + } + + @Override + public boolean checkRecipeGeneric( + int aMaxParallelRecipes, long aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { + ArrayList<ItemStack> tItems = getStoredInputs(); + ArrayList<FluidStack> tFluids = getStoredFluids(); + ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); + FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); + return checkRecipeGeneric( + tItemInputs, tFluidInputs, aMaxParallelRecipes, aEUPercent, aSpeedBonusPercent, aOutputChanceRoll); + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + // GT_Recipe tRecipe = findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, + // gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + GT_Recipe tRecipe = findRecipe( + mLastRecipe, gregtech.api.enums.GT_Values.V[tTier], getSolidCasingTier(), aItemInputs, aFluidInputs); + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + // checks if it has a catalyst + ItemStack tCatalystRecipe = null; + boolean aDoesRecipeNeedCatalyst = false; + for (ItemStack aInputItem : tRecipe.mInputs) { + if (ItemUtils.isCatalyst(aInputItem)) { + aDoesRecipeNeedCatalyst = true; + break; + } + } + if (aDoesRecipeNeedCatalyst) { + tCatalystRecipe = findCatalyst(aItemInputs, tRecipe.mInputs); + if (tCatalystRecipe == null) { + log("does not have catalyst"); + return false; + } + if (mCatalystBuses.size() != 1) { + log("does not have correct number of catalyst hatches. (Required 1, found " + mCatalystBuses.size() + + ")"); + return false; + } + } + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe.mSpecialValue > this.mSolidCasingTier) { + log("solid tier is too low"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // checks if it has enough catalyst durability + ArrayList<ItemStack> tCatalysts = null; + int tMaxParallelCatalyst = aMaxParallelRecipes; + if (tCatalystRecipe != null) { + tCatalysts = new ArrayList<ItemStack>(); + tMaxParallelCatalyst = getCatalysts(aItemInputs, tCatalystRecipe, aMaxParallelRecipes, tCatalysts); + log("Can process " + tMaxParallelCatalyst + " recipes. If less than " + aMaxParallelRecipes + + ", catalyst does not have enough durability."); + } + + if (tMaxParallelCatalyst == 0) { + log("found not enough catalysts"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + log("aEUPercent " + aEUPercent); + log("mEUt " + tRecipe.mEUt); + + int parallelRecipes = 0; + + log("parallelRecipes: " + parallelRecipes); + log("aMaxParallelRecipes: " + tMaxParallelCatalyst); + log("tTotalEUt: " + tTotalEUt); + log("tVoltage: " + tVoltage); + log("tEnergy: " + tEnergy); + log("tRecipeEUt: " + tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < tMaxParallelCatalyst && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at " + parallelRecipes + "."); + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Damage catalyst once all is said and done. + if (tCatalystRecipe != null) { + log("damaging catalyst"); + damageCatalyst(tCatalystRecipe, parallelRecipes); + } + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + for (GT_MetaTileEntity_Hatch_Catalysts h : mCatalystBuses) { + h.updateSlots(); + h.tryFillUsageSlots(); + } + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + private static final HashMap<Long, AutoMap<GT_Recipe>> mTieredRecipeMap = new HashMap<Long, AutoMap<GT_Recipe>>(); + private static final AutoMap<GT_Recipe> aTier0Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier1Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier2Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier3Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier4Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier5Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier6Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier7Recipes = new AutoMap<GT_Recipe>(); + private static boolean mInitRecipeCache = false; + + private static void initRecipeCaches() { + if (!mInitRecipeCache) { + mTieredRecipeMap.put((long) 0, aTier0Recipes); + mTieredRecipeMap.put((long) 1, aTier1Recipes); + mTieredRecipeMap.put((long) 2, aTier2Recipes); + mTieredRecipeMap.put((long) 3, aTier3Recipes); + mTieredRecipeMap.put((long) 4, aTier4Recipes); + mTieredRecipeMap.put((long) 5, aTier5Recipes); + mTieredRecipeMap.put((long) 6, aTier6Recipes); + mTieredRecipeMap.put((long) 7, aTier7Recipes); + for (GT_Recipe aRecipe : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList) { + if (aRecipe != null) { + switch (aRecipe.mSpecialValue) { + case 0: + aTier0Recipes.add(aRecipe); + continue; + case 1: + aTier1Recipes.add(aRecipe); + continue; + case 2: + aTier2Recipes.add(aRecipe); + continue; + case 3: + aTier3Recipes.add(aRecipe); + continue; + case 4: + aTier4Recipes.add(aRecipe); + continue; + case 5: + aTier5Recipes.add(aRecipe); + continue; + case 6: + aTier6Recipes.add(aRecipe); + continue; + case 7: + aTier7Recipes.add(aRecipe); + continue; + } + } + } + mInitRecipeCache = true; + } + } + + public GT_Recipe findRecipe( + final GT_Recipe aRecipe, + final long aVoltage, + final long aSpecialValue, + ItemStack[] aInputs, + final FluidStack[] aFluids) { + if (!mInitRecipeCache) { + initRecipeCaches(); + } + if (this.getRecipeMap().mRecipeList.isEmpty()) { + log("No Recipes in Map to search through."); + return null; + } else { + log("Checking tier " + aSpecialValue + " recipes and below. Using Input Voltage of " + aVoltage + "V."); + log("We have " + aInputs.length + " Items and " + aFluids.length + " Fluids."); + // Try check the cached recipe first + if (aRecipe != null) { + if (aRecipe.isRecipeInputEqual(false, aFluids, aInputs)) { + if (aRecipe.mEUt <= aVoltage) { + Logger.INFO("Using cached recipe."); + return aRecipe; + } + } + } + + // Get all recipes for the tier + AutoMap<AutoMap<GT_Recipe>> aMasterMap = new AutoMap<AutoMap<GT_Recipe>>(); + for (long i = 0; i <= aSpecialValue; i++) { + aMasterMap.add(mTieredRecipeMap.get(i)); + } + GT_Recipe aFoundRecipe = null; + + // Iterate the tiers recipes until we find the one with all inputs matching + master: + for (AutoMap<GT_Recipe> aTieredMap : aMasterMap) { + for (GT_Recipe aRecipeToCheck : aTieredMap) { + if (aRecipeToCheck.isRecipeInputEqual(false, aFluids, aInputs)) { + log("Found recipe with matching inputs!"); + if (aRecipeToCheck.mSpecialValue <= aSpecialValue) { + if (aRecipeToCheck.mEUt <= aVoltage) { + aFoundRecipe = aRecipeToCheck; + break master; + } + } + } + } + } + + // If we found a recipe, return it + if (aFoundRecipe != null) { + log("Found valid recipe."); + return aFoundRecipe; + } + } + log("Did not find valid recipe."); + return null; + } + + private int getCatalysts( + ItemStack[] aItemInputs, ItemStack aRecipeCatalyst, int aMaxParrallel, ArrayList<ItemStack> aOutPut) { + int allowedParallel = 0; + for (final ItemStack aInput : aItemInputs) { + if (aRecipeCatalyst.isItemEqual(aInput)) { + int aDurabilityRemaining = getMaxCatalystDurability() - getDamage(aInput); + return Math.min(aMaxParrallel, aDurabilityRemaining); + } + } + return allowedParallel; + } + + private ItemStack findCatalyst(ItemStack[] aItemInputs, ItemStack[] aRecipeInputs) { + if (aItemInputs != null) { + for (final ItemStack aInput : aItemInputs) { + if (aInput != null) { + if (ItemUtils.isCatalyst(aInput)) { + for (ItemStack aRecipeInput : aRecipeInputs) { + if (GT_Utility.areStacksEqual(aRecipeInput, aInput, true)) { + return aInput; + } + } + } + } + } + } + return null; + } + + private void damageCatalyst(ItemStack aStack, int parallelRecipes) { + for (int i = 0; i < parallelRecipes; i++) { + // Awakened Draconium Coils with Tungstensteel Pipe Casings (or above) no longer consume catalysts. + if (this.mCoilTier >= 10 && this.mPipeCasingTier >= 4) { + log("not consuming catalyst"); + } else if (MathUtils.randFloat(0, 10000000) / 10000000f < (1.2f - (0.2 * this.mPipeCasingTier))) { + int damage = getDamage(aStack) + 1; + log("damage catalyst " + damage); + if (damage >= getMaxCatalystDurability()) { + log("consume catalyst"); + addOutput(CI.getEmptyCatalyst(1)); + aStack.stackSize -= 1; + } else { + log("damaging catalyst"); + setDamage(aStack, damage); + } + } else { + log("not consuming catalyst"); + } + } + } + + private int getDamage(ItemStack aStack) { + return ItemGenericChemBase.getCatalystDamage(aStack); + } + + private void setDamage(ItemStack aStack, int aAmount) { + ItemGenericChemBase.setCatalystDamage(aStack, aAmount); + } + + /* + * Catalyst Handling + */ + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> tItems = super.getStoredInputs(); + if (this.hasSlotInGUI() && this.getGUIItemStack() != null) { + tItems.add(this.getGUIItemStack()); + } + for (GT_MetaTileEntity_Hatch_Catalysts tHatch : mCatalystBuses) { + tHatch.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + AutoMap<ItemStack> aHatchContent = tHatch.getContentUsageSlots(); + if (!aHatchContent.isEmpty()) { + tItems.addAll(aHatchContent); + } + } + } + return tItems; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Gas.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Gas.java index c6342827da..68cfc44527 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Gas.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Gas.java @@ -2,8 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.t import static gtPlusPlus.core.lib.CORE.RANDOM; -import java.util.ArrayList; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -11,6 +9,7 @@ import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; +import java.util.ArrayList; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; @@ -22,7 +21,6 @@ public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbin super(aID, aName, aNameRegional); } - public GT_MTE_LargeTurbine_Gas(String aName) { super(aName); } @@ -42,24 +40,23 @@ public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbin return 58; } - - @Override - protected boolean requiresOutputHatch() { - return false; - } + @Override + protected boolean requiresOutputHatch() { + return false; + } @Override public int getPollutionPerSecond(ItemStack aStack) { return 4000; } - + public int getFuelValue(FluidStack aLiquid) { if (aLiquid == null) { - return 0; + return 0; } GT_Recipe tFuel = GT_Recipe_Map.sTurbineFuels.findFuel(aLiquid); if (tFuel != null) { - return tFuel.mSpecialValue; + return tFuel.mSpecialValue; } return 0; } @@ -70,9 +67,11 @@ public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbin int tEU = 0; int actualOptimalFlow = 0; - FluidStack firstFuelType = new FluidStack(aFluids.get(0), 0); // Identify a SINGLE type of fluid to process. Doesn't matter which one. Ignore the rest! + FluidStack firstFuelType = new FluidStack( + aFluids.get(0), + 0); // Identify a SINGLE type of fluid to process. Doesn't matter which one. Ignore the rest! int fuelValue = getFuelValue(firstFuelType); - //log("Fuel Value of "+aFluids.get(0).getLocalizedName()+" is "+fuelValue+"eu"); + // log("Fuel Value of "+aFluids.get(0).getLocalizedName()+" is "+fuelValue+"eu"); if (aOptFlow < fuelValue) { // turbine too weak and/or fuel too powerful // at least consume 1L @@ -86,14 +85,18 @@ public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbin actualOptimalFlow = GT_Utility.safeInt((long) aOptFlow / fuelValue); this.realOptFlow = actualOptimalFlow; - int remainingFlow = GT_Utility.safeInt((long) (actualOptimalFlow * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + int remainingFlow = GT_Utility.safeInt((long) (actualOptimalFlow + * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for + // multi-hatch scenarios. int flow = 0; int totalFlow = 0; storedFluid = 0; for (FluidStack aFluid : aFluids) { if (aFluid.isFluidEqual(firstFuelType)) { - flow = Math.min(aFluid.amount, remainingFlow); // try to use up to 125% of optimal flow w/o exceeding remainingFlow + flow = Math.min( + aFluid.amount, + remainingFlow); // try to use up to 125% of optimal flow w/o exceeding remainingFlow depleteInput(new FluidStack(aFluid, flow)); // deplete that amount this.storedFluid += aFluid.amount; remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches @@ -103,11 +106,11 @@ public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbin if (totalFlow <= 0) return 0; tEU = GT_Utility.safeInt((long) totalFlow * fuelValue); - //log("Total Flow: "+totalFlow); - //log("Real Optimal Flow: "+actualOptimalFlow); - //log("Flow: "+flow); - //log("Remaining Flow: "+remainingFlow); - + // log("Total Flow: "+totalFlow); + // log("Real Optimal Flow: "+actualOptimalFlow); + // log("Flow: "+flow); + // log("Remaining Flow: "+remainingFlow); + if (totalFlow == actualOptimalFlow) { tEU = GT_Utility.safeInt((long) tEU * (long) aBaseEff / 10000L); } else { @@ -117,7 +120,6 @@ public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbin } return tEU; - } return 0; } @@ -126,7 +128,7 @@ public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbin public int getDamageToComponent(ItemStack aStack) { return (RANDOM.nextInt(4) == 0) ? 0 : 1; } - + @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); @@ -137,34 +139,33 @@ public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbin super.loadNBTData(aNBT); } - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Large Gas Turbine"; - } + @Override + public String getCustomGUIResourceName() { + return null; + } - @Override - protected String getTurbineType() { - return "Gas"; - } + @Override + public String getMachineType() { + return "Large Gas Turbine"; + } - @Override - protected String getCasingName() { - return "Reinforced Gas Turbine Casing"; - } + @Override + protected String getTurbineType() { + return "Gas"; + } - @Override - protected ITexture getTextureFrontFace() { - return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS5); - } + @Override + protected String getCasingName() { + return "Reinforced Gas Turbine Casing"; + } - @Override - protected ITexture getTextureFrontFaceActive() { - return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE5); - } + @Override + protected ITexture getTextureFrontFace() { + return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS5); + } + @Override + protected ITexture getTextureFrontFaceActive() { + return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE5); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java index 3427b40819..517c32441a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; -import java.util.ArrayList; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -9,9 +7,10 @@ import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_Utility; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Turbine; -import gregtech.api.util.GT_Utility; +import java.util.ArrayList; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; @@ -23,7 +22,6 @@ public class GT_MTE_LargeTurbine_Plasma extends GregtechMetaTileEntity_LargerTur super(aID, aName, aNameRegional); } - public GT_MTE_LargeTurbine_Plasma(String aName) { super(aName); } @@ -43,139 +41,156 @@ public class GT_MTE_LargeTurbine_Plasma extends GregtechMetaTileEntity_LargerTur return 60; } - @Override - protected boolean requiresOutputHatch() { - return true; - } + @Override + protected boolean requiresOutputHatch() { + return true; + } @Override public int getPollutionPerSecond(ItemStack aStack) { return 0; } - + public int getFuelValue(FluidStack aLiquid) { if (aLiquid == null) { - return 0; + return 0; } GT_Recipe tFuel = GT_Recipe_Map.sPlasmaFuels.findFuel(aLiquid); if (tFuel != null) { - return tFuel.mSpecialValue; + return tFuel.mSpecialValue; } return 0; } - @Override - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - - try { - ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); - if (aEmptyTurbineRotorHatches.size() > 0) { - log("Found "+aEmptyTurbineRotorHatches.size()+" Assemblies without Turbine."); - hatch : for (GT_MetaTileEntity_Hatch_Turbine aHatch : aEmptyTurbineRotorHatches) { - ArrayList<ItemStack> aTurbines = getAllBufferedTurbines(); - for (ItemStack aTurbineItem : aTurbines) { - if (aTurbineItem == null) { - continue; - } - if (aHatch.insertTurbine(aTurbineItem.copy())) { - boolean aDidDeplete = depleteTurbineFromStock(aTurbineItem); - log("Put Turbine into Assembly - "+aDidDeplete); - continue hatch; - } - } - } - } - - if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { - log("BAD RETURN - 1"); - stopMachine(); - return false; - } - - ArrayList<FluidStack> tFluids = getStoredFluids(); - - if (tFluids.size() > 0) { - if (baseEff == 0 || optFlow == 0 || counter >= 512 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled() - || this.getBaseMetaTileEntity().hasInventoryBeenModified()) { - counter = 0; - float aTotalBaseEff = 0; - float aTotalOptimalFlow = 0; - ItemStack aStack = getFullTurbineAssemblies().get(0).getTurbine(); - for (int i = 0; i< getSpeedMultiplier(); i++) { - if (i == 0) { - aTotalBaseEff += GT_Utility.safeInt((long) ((5F + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack)) * 1000F)); - } - aTotalOptimalFlow += GT_Utility.safeInt((long) Math.max(Float.MIN_NORMAL, - ((GT_MetaGenerated_Tool) aStack.getItem()).getToolStats(aStack).getSpeedMultiplier() - * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed - * 50)); - } - - baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); - optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); - if(optFlow<=0 || baseEff<=0){ - log("Running checkRecipeGeneric(bad-1)"); - stopMachine();//in case the turbine got removed - return false; - } - } else { - counter++; - } - } - - // How much the turbine should be producing with this flow - int newPower = fluidIntoPower(tFluids, optFlow, baseEff); - int difference = newPower - this.mEUt; // difference between current output and new output - - // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the difference in power level (per tick) - // This is how much the turbine can actually change during this tick - int maxChangeAllowed = Math.max(200, GT_Utility.safeInt((long) Math.abs(difference) / 5)); - - if (Math.abs(difference) > maxChangeAllowed) { // If this difference is too big, use the maximum allowed change - int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. - this.mEUt += change; // Apply the change - } - else { - this.mEUt = newPower; - } - if (this.mEUt <= 0) { - this.mEUt=0; - this.mEfficiency=0; - log("Running checkRecipeGeneric(bad-2)"); - return false; - } else { - this.mMaxProgresstime = 20; - this.mEfficiencyIncrease = 200; - // Overvoltage is handled inside the MultiBlockBase when pushing out to dynamos. no need to do it here. - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - //log("GOOD RETURN - Making: "+this.mEUt+" EU/t"); - return true; - } - } - catch (Throwable t) { - t.printStackTrace(); - } - return false; - } + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + + try { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); + if (aEmptyTurbineRotorHatches.size() > 0) { + log("Found " + aEmptyTurbineRotorHatches.size() + " Assemblies without Turbine."); + hatch: + for (GT_MetaTileEntity_Hatch_Turbine aHatch : aEmptyTurbineRotorHatches) { + ArrayList<ItemStack> aTurbines = getAllBufferedTurbines(); + for (ItemStack aTurbineItem : aTurbines) { + if (aTurbineItem == null) { + continue; + } + if (aHatch.insertTurbine(aTurbineItem.copy())) { + boolean aDidDeplete = depleteTurbineFromStock(aTurbineItem); + log("Put Turbine into Assembly - " + aDidDeplete); + continue hatch; + } + } + } + } + + if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { + log("BAD RETURN - 1"); + stopMachine(); + return false; + } + + ArrayList<FluidStack> tFluids = getStoredFluids(); + + if (tFluids.size() > 0) { + if (baseEff == 0 + || optFlow == 0 + || counter >= 512 + || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled() + || this.getBaseMetaTileEntity().hasInventoryBeenModified()) { + counter = 0; + float aTotalBaseEff = 0; + float aTotalOptimalFlow = 0; + ItemStack aStack = getFullTurbineAssemblies().get(0).getTurbine(); + for (int i = 0; i < getSpeedMultiplier(); i++) { + if (i == 0) { + aTotalBaseEff += GT_Utility.safeInt((long) + ((5F + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack)) + * 1000F)); + } + aTotalOptimalFlow += GT_Utility.safeInt((long) Math.max( + Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStack.getItem()) + .getToolStats(aStack) + .getSpeedMultiplier() + * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed + * 50)); + } + + baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); + optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); + if (optFlow <= 0 || baseEff <= 0) { + log("Running checkRecipeGeneric(bad-1)"); + stopMachine(); // in case the turbine got removed + return false; + } + } else { + counter++; + } + } + + // How much the turbine should be producing with this flow + int newPower = fluidIntoPower(tFluids, optFlow, baseEff); + int difference = newPower - this.mEUt; // difference between current output and new output + + // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the + // difference in power level (per tick) + // This is how much the turbine can actually change during this tick + int maxChangeAllowed = Math.max(200, GT_Utility.safeInt((long) Math.abs(difference) / 5)); + + if (Math.abs(difference) + > maxChangeAllowed) { // If this difference is too big, use the maximum allowed change + int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. + this.mEUt += change; // Apply the change + } else { + this.mEUt = newPower; + } + if (this.mEUt <= 0) { + this.mEUt = 0; + this.mEfficiency = 0; + log("Running checkRecipeGeneric(bad-2)"); + return false; + } else { + this.mMaxProgresstime = 20; + this.mEfficiencyIncrease = 200; + // Overvoltage is handled inside the MultiBlockBase when pushing out to dynamos. no need to do it here. + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + // log("GOOD RETURN - Making: "+this.mEUt+" EU/t"); + return true; + } + } catch (Throwable t) { + t.printStackTrace(); + } + return false; + } @Override int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff) { if (aFluids.size() >= 1) { - aOptFlow *= 800;//CHANGED THINGS HERE, check recipe runs once per 20 ticks + aOptFlow *= 800; // CHANGED THINGS HERE, check recipe runs once per 20 ticks int tEU = 0; int actualOptimalFlow = 0; - FluidStack firstFuelType = new FluidStack(aFluids.get(0), 0); // Identify a SINGLE type of fluid to process. Doesn't matter which one. Ignore the rest! + FluidStack firstFuelType = new FluidStack( + aFluids.get(0), + 0); // Identify a SINGLE type of fluid to process. Doesn't matter which one. Ignore the rest! int fuelValue = getFuelValue(firstFuelType); actualOptimalFlow = GT_Utility.safeInt((long) Math.ceil((double) aOptFlow / (double) fuelValue)); this.realOptFlow = actualOptimalFlow; // For scanner info - int remainingFlow = GT_Utility.safeInt((long) (actualOptimalFlow * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + int remainingFlow = GT_Utility.safeInt((long) (actualOptimalFlow + * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for + // multi-hatch scenarios. int flow = 0; int totalFlow = 0; @@ -204,7 +219,7 @@ public class GT_MTE_LargeTurbine_Plasma extends GregtechMetaTileEntity_LargerTur if (totalFlow <= 0) return 0; tEU = GT_Utility.safeInt((long) ((fuelValue / 20D) * (double) totalFlow)); - //GT_FML_LOGGER.info(totalFlow+" : "+fuelValue+" : "+aOptFlow+" : "+actualOptimalFlow+" : "+tEU); + // GT_FML_LOGGER.info(totalFlow+" : "+fuelValue+" : "+aOptFlow+" : "+actualOptimalFlow+" : "+tEU); if (totalFlow == actualOptimalFlow) { tEU = GT_Utility.safeInt((long) (aBaseEff / 10000D * tEU)); @@ -216,7 +231,6 @@ public class GT_MTE_LargeTurbine_Plasma extends GregtechMetaTileEntity_LargerTur } return tEU; - } return 0; } @@ -226,35 +240,33 @@ public class GT_MTE_LargeTurbine_Plasma extends GregtechMetaTileEntity_LargerTur return 1; } - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Large Plasma Turbine"; - } - - - @Override - protected String getTurbineType() { - return "Plasma"; - } - - @Override - protected String getCasingName() { - return "Reinforced Plasma Turbine Casing"; - } - - @Override - protected ITexture getTextureFrontFace() { - return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU5); - } - - @Override - protected ITexture getTextureFrontFaceActive() { - return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE5); - } + @Override + public String getCustomGUIResourceName() { + return null; + } + @Override + public String getMachineType() { + return "Large Plasma Turbine"; + } + + @Override + protected String getTurbineType() { + return "Plasma"; + } + + @Override + protected String getCasingName() { + return "Reinforced Plasma Turbine Casing"; + } + + @Override + protected ITexture getTextureFrontFace() { + return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU5); + } + + @Override + protected ITexture getTextureFrontFaceActive() { + return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE5); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java index 2f72b8b54c..248359a80b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; -import java.util.ArrayList; - import gregtech.GT_Mod; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -12,6 +10,7 @@ import gregtech.api.util.GT_Utility; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -21,7 +20,7 @@ import net.minecraftforge.fluids.FluidStack; public class GT_MTE_LargeTurbine_SHSteam extends GregtechMetaTileEntity_LargerTurbineBase { public boolean achievement = false; - private boolean looseFit=false; + private boolean looseFit = false; public GT_MTE_LargeTurbine_SHSteam(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -46,42 +45,44 @@ public class GT_MTE_LargeTurbine_SHSteam extends GregtechMetaTileEntity_LargerTu return 59; } - @Override - protected boolean requiresOutputHatch() { - return true; - } + @Override + protected boolean requiresOutputHatch() { + return true; + } @Override public int getPollutionPerSecond(ItemStack aStack) { return 0; } - @Override - public int getFuelValue(FluidStack aLiquid) { - return 0; - } + @Override + public int getFuelValue(FluidStack aLiquid) { + return 0; + } @Override int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff) { - if(looseFit) { - aOptFlow*=4; - if(aBaseEff>10000){ - aOptFlow*=Math.pow(1.1f,((aBaseEff-7500)/10000F)*20f); - aBaseEff=7500; - }else if(aBaseEff>7500){ - aOptFlow*=Math.pow(1.1f,((aBaseEff-7500)/10000F)*20f); - aBaseEff*=0.75f; - }else{ - aBaseEff*=0.75f; + if (looseFit) { + aOptFlow *= 4; + if (aBaseEff > 10000) { + aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); + aBaseEff = 7500; + } else if (aBaseEff > 7500) { + aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); + aBaseEff *= 0.75f; + } else { + aBaseEff *= 0.75f; } } int tEU = 0; int totalFlow = 0; // Byproducts are based on actual flow int flow = 0; - int remainingFlow = MathUtils.safeInt((long)(aOptFlow * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + int remainingFlow = MathUtils.safeInt((long) (aOptFlow + * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for + // multi-hatch scenarios. this.realOptFlow = aOptFlow; - storedFluid=0; + storedFluid = 0; for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { String fluidName = aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)); if (fluidName.equals("ic2.fluidSuperheatedSteam")) { @@ -92,25 +93,32 @@ public class GT_MTE_LargeTurbine_SHSteam extends GregtechMetaTileEntity_LargerTu totalFlow += flow; // track total input used if (!achievement) { try { - GT_Mod.achievements.issueAchievement(this.getBaseMetaTileEntity().getWorld().getPlayerEntityByName(this.getBaseMetaTileEntity().getOwnerName()), "efficientsteam"); + GT_Mod.achievements.issueAchievement( + this.getBaseMetaTileEntity() + .getWorld() + .getPlayerEntityByName( + this.getBaseMetaTileEntity().getOwnerName()), + "efficientsteam"); } catch (Exception e) { } achievement = true; } - }else if(fluidName.equals("fluid.steam") || fluidName.equals("ic2.fluidSteam") || fluidName.equals("fluid.mfr.steam.still.name")){ + } else if (fluidName.equals("fluid.steam") + || fluidName.equals("ic2.fluidSteam") + || fluidName.equals("fluid.mfr.steam.still.name")) { depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); } } - if(totalFlow<=0)return 0; + if (totalFlow <= 0) return 0; tEU = totalFlow; addOutput(GT_ModHandler.getSteam(totalFlow)); if (totalFlow != aOptFlow) { - float efficiency = 1.0f - Math.abs((totalFlow - aOptFlow) / (float)aOptFlow); - //if(totalFlow>aOptFlow){efficiency = 1.0f;} + float efficiency = 1.0f - Math.abs((totalFlow - aOptFlow) / (float) aOptFlow); + // if(totalFlow>aOptFlow){efficiency = 1.0f;} tEU *= efficiency; - tEU = Math.max(1, MathUtils.safeInt((long)tEU * (long)aBaseEff / 10000L)); + tEU = Math.max(1, MathUtils.safeInt((long) tEU * (long) aBaseEff / 10000L)); } else { - tEU = MathUtils.safeInt((long)tEU * (long)aBaseEff / 10000L); + tEU = MathUtils.safeInt((long) tEU * (long) aBaseEff / 10000L); } return tEU; @@ -118,75 +126,73 @@ public class GT_MTE_LargeTurbine_SHSteam extends GregtechMetaTileEntity_LargerTu @Override public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - //Using a screwdriver to change modes should allow for any combination of Slow/Fast and Tight/Loose Mode - //Whenever there's a mode switch, there will be two messages on the player chat - //The two messages specify which two modes the turbine is on after the change - //(Tight/Loose changes on every action, Slow/Fast changes every other action, all pairs are cycled this way) + // Using a screwdriver to change modes should allow for any combination of Slow/Fast and Tight/Loose Mode + // Whenever there's a mode switch, there will be two messages on the player chat + // The two messages specify which two modes the turbine is on after the change + // (Tight/Loose changes on every action, Slow/Fast changes every other action, all pairs are cycled this way) if (aSide == getBaseMetaTileEntity().getFrontFacing()) { - looseFit^=true; - GT_Utility.sendChatToPlayer(aPlayer, looseFit ? "Fitting is Loose (Higher Flow)" : "Fitting is Tight (Higher Efficiency)"); + looseFit ^= true; + GT_Utility.sendChatToPlayer( + aPlayer, looseFit ? "Fitting is Loose (Higher Flow)" : "Fitting is Tight (Higher Efficiency)"); } if (looseFit) { super.onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ); - } - else if (mFastMode) { + } else if (mFastMode) { PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); - } - else { + } else { PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); } } @Override public int getDamageToComponent(ItemStack aStack) { - return (looseFit && CORE.RANDOM.nextInt(4)==0)?0:1; + return (looseFit && CORE.RANDOM.nextInt(4) == 0) ? 0 : 1; } - + public boolean isLooseMode() { - return looseFit; - } - + return looseFit; + } + @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); - aNBT.setBoolean("turbineFitting",looseFit); + aNBT.setBoolean("turbineFitting", looseFit); } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - looseFit=aNBT.getBoolean("turbineFitting"); + looseFit = aNBT.getBoolean("turbineFitting"); } - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Large Super-heated Steam Turbine"; - } + @Override + public String getCustomGUIResourceName() { + return null; + } - @Override - protected String getTurbineType() { - return "Super-heated Steam"; - } + @Override + public String getMachineType() { + return "Large Super-heated Steam Turbine"; + } - @Override - protected String getCasingName() { - return "Reinforced HP Steam Turbine Casing"; - } + @Override + protected String getTurbineType() { + return "Super-heated Steam"; + } - @Override - protected ITexture getTextureFrontFace() { - return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI5); - } + @Override + protected String getCasingName() { + return "Reinforced HP Steam Turbine Casing"; + } - @Override - protected ITexture getTextureFrontFaceActive() { - return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE5); - } + @Override + protected ITexture getTextureFrontFace() { + return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI5); + } + @Override + protected ITexture getTextureFrontFaceActive() { + return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE5); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java index 9d5139f0a3..e15f0f3181 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java @@ -2,8 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.t import static gtPlusPlus.core.lib.CORE.RANDOM; -import java.util.ArrayList; - import gregtech.GT_Mod; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -13,6 +11,7 @@ import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -23,13 +22,12 @@ public class GT_MTE_LargeTurbine_Steam extends GregtechMetaTileEntity_LargerTurb private float water; private boolean achievement = false; - private boolean looseFit=false; + private boolean looseFit = false; public GT_MTE_LargeTurbine_Steam(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } - public GT_MTE_LargeTurbine_Steam(String aName) { super(aName); } @@ -49,10 +47,10 @@ public class GT_MTE_LargeTurbine_Steam extends GregtechMetaTileEntity_LargerTurb return 16; } - @Override - protected boolean requiresOutputHatch() { - return true; - } + @Override + protected boolean requiresOutputHatch() { + return true; + } @Override public int getPollutionPerSecond(ItemStack aStack) { @@ -65,59 +63,70 @@ public class GT_MTE_LargeTurbine_Steam extends GregtechMetaTileEntity_LargerTurb water = water - usage; return usage; } - + public int getFuelValue(FluidStack aLiquid) { return 0; } @Override int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff) { - if(looseFit) { - aOptFlow*=4; - if(aBaseEff>10000){ - aOptFlow*=Math.pow(1.1f,((aBaseEff-7500)/10000F)*20f); - aBaseEff=7500; - }else if(aBaseEff>7500){ - aOptFlow*=Math.pow(1.1f,((aBaseEff-7500)/10000F)*20f); - aBaseEff*=0.75f; - }else{ - aBaseEff*=0.75f; + if (looseFit) { + aOptFlow *= 4; + if (aBaseEff > 10000) { + aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); + aBaseEff = 7500; + } else if (aBaseEff > 7500) { + aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); + aBaseEff *= 0.75f; + } else { + aBaseEff *= 0.75f; } } int tEU = 0; int totalFlow = 0; // Byproducts are based on actual flow int flow = 0; - int remainingFlow = MathUtils.safeInt((long)(aOptFlow * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + int remainingFlow = MathUtils.safeInt((long) (aOptFlow + * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for + // multi-hatch scenarios. this.realOptFlow = aOptFlow; - storedFluid=0; - for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { // loop through each hatch; extract inputs and track totals. + storedFluid = 0; + for (int i = 0; + i < aFluids.size() && remainingFlow > 0; + i++) { // loop through each hatch; extract inputs and track totals. String fluidName = aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)); - if (fluidName.equals("fluid.steam") || fluidName.equals("ic2.fluidSteam") || fluidName.equals("fluid.mfr.steam.still.name")) { + if (fluidName.equals("fluid.steam") + || fluidName.equals("ic2.fluidSteam") + || fluidName.equals("fluid.mfr.steam.still.name")) { flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount this.storedFluid += aFluids.get(i).amount; remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches totalFlow += flow; // track total input used if (!achievement) { - GT_Mod.achievements.issueAchievement(this.getBaseMetaTileEntity().getWorld().getPlayerEntityByName(this.getBaseMetaTileEntity().getOwnerName()), "muchsteam"); + GT_Mod.achievements.issueAchievement( + this.getBaseMetaTileEntity() + .getWorld() + .getPlayerEntityByName( + this.getBaseMetaTileEntity().getOwnerName()), + "muchsteam"); achievement = true; } - }else if(fluidName.equals("ic2.fluidSuperheatedSteam")){ + } else if (fluidName.equals("ic2.fluidSuperheatedSteam")) { depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); } } - if(totalFlow<=0)return 0; + if (totalFlow <= 0) return 0; tEU = totalFlow; int waterToOutput = useWater(totalFlow / 160.0f); addOutput(GT_ModHandler.getDistilledWater(waterToOutput)); if (totalFlow != aOptFlow) { - float efficiency = 1.0f - Math.abs((totalFlow - aOptFlow) / (float)aOptFlow); - //if(totalFlow>aOptFlow){efficiency = 1.0f;} + float efficiency = 1.0f - Math.abs((totalFlow - aOptFlow) / (float) aOptFlow); + // if(totalFlow>aOptFlow){efficiency = 1.0f;} tEU *= efficiency; - tEU = Math.max(1, MathUtils.safeInt((long)tEU * (long)aBaseEff / 20000L)); + tEU = Math.max(1, MathUtils.safeInt((long) tEU * (long) aBaseEff / 20000L)); } else { - tEU = MathUtils.safeInt((long)tEU * (long)aBaseEff / 20000L); + tEU = MathUtils.safeInt((long) tEU * (long) aBaseEff / 20000L); } return tEU; @@ -125,75 +134,73 @@ public class GT_MTE_LargeTurbine_Steam extends GregtechMetaTileEntity_LargerTurb @Override public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - //Using a screwdriver to change modes should allow for any combination of Slow/Fast and Tight/Loose Mode - //Whenever there's a mode switch, there will be two messages on the player chat - //The two messages specify which two modes the turbine is on after the change - //(Tight/Loose changes on every action, Slow/Fast changes every other action, all pairs are cycled this way) + // Using a screwdriver to change modes should allow for any combination of Slow/Fast and Tight/Loose Mode + // Whenever there's a mode switch, there will be two messages on the player chat + // The two messages specify which two modes the turbine is on after the change + // (Tight/Loose changes on every action, Slow/Fast changes every other action, all pairs are cycled this way) if (aSide == getBaseMetaTileEntity().getFrontFacing()) { - looseFit^=true; - GT_Utility.sendChatToPlayer(aPlayer, looseFit ? "Fitting: Loose - More Flow" : "Fitting: Tight - More Efficiency"); + looseFit ^= true; + GT_Utility.sendChatToPlayer( + aPlayer, looseFit ? "Fitting: Loose - More Flow" : "Fitting: Tight - More Efficiency"); } if (looseFit) { super.onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ); - } - else if (mFastMode) { + } else if (mFastMode) { PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); - } - else { + } else { PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); } } @Override public int getDamageToComponent(ItemStack aStack) { - return (looseFit && RANDOM.nextInt(4)==0)?0:1; + return (looseFit && RANDOM.nextInt(4) == 0) ? 0 : 1; } - + public boolean isLooseMode() { - return looseFit; - } - + return looseFit; + } + @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); - aNBT.setBoolean("turbineFitting",looseFit); + aNBT.setBoolean("turbineFitting", looseFit); } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - looseFit=aNBT.getBoolean("turbineFitting"); + looseFit = aNBT.getBoolean("turbineFitting"); } - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public String getMachineType() { - return "Large Steam Turbine"; - } + @Override + public String getCustomGUIResourceName() { + return null; + } - @Override - protected String getTurbineType() { - return "Steam"; - } + @Override + public String getMachineType() { + return "Large Steam Turbine"; + } - @Override - protected String getCasingName() { - return "Reinforced Steam Turbine Casing"; - } + @Override + protected String getTurbineType() { + return "Steam"; + } - @Override - protected ITexture getTextureFrontFace() { - return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST5); - } + @Override + protected String getCasingName() { + return "Reinforced Steam Turbine Casing"; + } - @Override - protected ITexture getTextureFrontFaceActive() { - return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE5); - } + @Override + protected ITexture getTextureFrontFace() { + return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST5); + } + @Override + protected ITexture getTextureFrontFaceActive() { + return new GT_RenderedTexture(gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE5); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java index 70b72bb60d..009b5c8f43 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java @@ -1,6 +1,10 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; -import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.enums.GT_HatchElement.*; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; @@ -31,6 +35,7 @@ import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Turbine; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -41,764 +46,806 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; +public abstract class GregtechMetaTileEntity_LargerTurbineBase + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargerTurbineBase> + implements ISurvivalConstructable { -import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; + protected int baseEff = 0; + protected int optFlow = 0; + protected double realOptFlow = 0; + protected int storedFluid = 0; + protected int counter = 0; + protected boolean mFastMode = false; + protected double mufflerReduction = 1; + + public ITexture frontFace; + public ITexture frontFaceActive; + + public ArrayList<GT_MetaTileEntity_Hatch_Turbine> mTurbineRotorHatches = + new ArrayList<GT_MetaTileEntity_Hatch_Turbine>(); + + public GregtechMetaTileEntity_LargerTurbineBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + frontFace = getTextureFrontFace(); + frontFaceActive = getTextureFrontFaceActive(); + } + + public GregtechMetaTileEntity_LargerTurbineBase(String aName) { + super(aName); + frontFace = getTextureFrontFace(); + frontFaceActive = getTextureFrontFaceActive(); + } + + protected abstract ITexture getTextureFrontFace(); + + protected abstract ITexture getTextureFrontFaceActive(); + + protected abstract String getTurbineType(); + + protected abstract String getCasingName(); + + protected abstract boolean requiresOutputHatch(); + + @Override + protected final GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the XL " + getTurbineType() + " Turbine") + .addInfo("Runs as fast as 16 Large Turbines of the same type, takes the space of 12") + .addInfo("Right-click with screwdriver to enable Fast Mode, to run it even faster") + .addInfo("Optimal flow will increase or decrease accordingly on mode switch") + .addInfo("Fast Mode increases speed to 48x instead of 16x, with some penalties") + .addInfo("Maintenance problems and turbine damage happen 12x as often in Fast Mode") + .addInfo("XL Steam Turbines can use Loose Mode with either Slow or Fast Mode") + .addPollutionAmount(getPollutionPerSecond(null)) + .addInfo("Pollution is 3x higher in Fast Mode") + .addSeparator() + .beginStructureBlock(7, 9, 7, false) + .addController("Top Middle") + .addCasingInfo(getCasingName(), 360) + .addOtherStructurePart("Rotor Assembly", "Any 1 dot hint", 1) + .addInputBus("Any 4 dot hint (min 1)", 4) + .addInputHatch("Any 4 dot hint(min 1)", 4); + if (requiresOutputHatch()) { + tt.addOutputHatch("Any 4 dot hint(min 1)", 4); + } + tt.addDynamoHatch("Any 4 dot hint(min 1)", 4).addMaintenanceHatch("Any 4 dot hint(min 1)", 4); + if (requiresMufflers()) { + tt.addMufflerHatch("Any 7 dot hint (x4)", 7); + } + tt.toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static final ClassValue<IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase>> + STRUCTURE_DEFINITION = new ClassValue<IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase>>() { + @Override + protected IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase> computeValue(Class<?> type) { + return StructureDefinition.<GregtechMetaTileEntity_LargerTurbineBase>builder() + // c = turbine casing + // s = turbine shaft + // t = turbine housing + // h = dynamo/maint + // m = muffler + .addShape(STRUCTURE_PIECE_MAIN, (new String[][] { + {"ccchccc", "ccccccc", "ccmmmcc", "ccm~mcc", "ccmmmcc", "ccccccc", "ccchccc"}, + {"ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc"}, + {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, + {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, + {"ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc"}, + {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, + {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, + {"ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc"}, + {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, + })) + .addElement('c', lazy(t -> ofBlock(t.getCasingBlock(), t.getCasingMeta()))) + .addElement('s', lazy(t -> ofBlock(t.getCasingBlock(), t.getTurbineShaftMeta()))) + .addElement('t', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class) + .adder(GregtechMetaTileEntity_LargerTurbineBase::addTurbineHatch) + .hatchClass(GT_MetaTileEntity_Hatch_Turbine.class) + .casingIndex(t.getCasingTextureIndex()) + .dot(1) + .build())) + .addElement('h', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class) + .atLeast(InputBus, InputHatch, OutputHatch, Dynamo.or(TTDynamo), Maintenance) + .casingIndex(t.getCasingTextureIndex()) + .dot(4) + .buildAndChain(t.getCasingBlock(), t.getCasingMeta()))) + .addElement('m', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class) + .atLeast(Muffler) + .casingIndex(t.getCasingTextureIndex()) + .dot(7) + .buildAndChain(t.getCasingBlock(), t.getCasingMeta()))) + .build(); + } + }; + + @Override + public IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase> getStructureDefinition() { + return STRUCTURE_DEFINITION.get(getClass()); + } + + private boolean requiresMufflers() { + if (!PollutionUtils.isPollutionEnabled()) { + return false; + } + return getPollutionPerSecond(null) > 0; + } + + public final double getMufflerReduction() { + double totalReduction = 0; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { + if (isValidMetaTileEntity(tHatch)) { + totalReduction += ((double) tHatch.calculatePollutionReduction(100)) / 100; + } + } + return totalReduction / 4; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + this.mDynamoHatches.clear(); + this.mTecTechDynamoHatches.clear(); + this.mTurbineRotorHatches.clear(); + this.mMaintenanceHatches.clear(); + if (requiresMufflers()) { + this.mMufflerHatches.clear(); + } + this.mInputBusses.clear(); + this.mInputHatches.clear(); + if (requiresOutputHatch()) { + this.mOutputHatches.clear(); + } + // we do not check for casing count here. the bare minimal is 372 but we only require 360 + boolean aStructure = checkPiece(STRUCTURE_PIECE_MAIN, 3, 3, 0); + log("Structure Check: " + aStructure); + if (mTurbineRotorHatches.size() != 12 + || mMaintenanceHatches.size() != 1 + || (mDynamoHatches.size() < 1 && mTecTechDynamoHatches.size() < 1) + || (requiresMufflers() && mMufflerHatches.size() != 4) + || mInputBusses.size() < 1 + || mInputHatches.size() < 1 + || (requiresOutputHatch() && mOutputHatches.size() < 1)) { + log("Bad Hatches - Turbine Housings: " + mTurbineRotorHatches.size() + ", Maint: " + + mMaintenanceHatches.size() + ", Dynamo: " + + mDynamoHatches.size() + ", Muffler: " + + mMufflerHatches.size() + ", Input Buses: " + + mInputBusses.size() + ", Input Hatches: " + + mInputHatches.size() + ", Output Hatches: " + + mOutputHatches.size()); + return false; + } + mufflerReduction = getMufflerReduction(); + return aStructure; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + int realBudget = elementBudget >= 200 ? elementBudget : Math.min(200, elementBudget * 2); + return survivialBuildPiece(mName, stackSize, 1, 3, 3, realBudget, source, actor, false, true); + } + + public boolean addTurbineHatch(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine) { + log("Found GT_MetaTileEntity_Hatch_Turbine"); + updateTexture(aTileEntity, aBaseCasingIndex); + GT_MetaTileEntity_Hatch_Turbine aTurbineHatch = (GT_MetaTileEntity_Hatch_Turbine) aMetaTileEntity; + IGregTechTileEntity g = this.getBaseMetaTileEntity(); + if (aTurbineHatch.setController(new BlockPos(g.getXCoord(), g.getYCoord(), g.getZCoord(), g.getWorld()))) { + boolean aDidAdd = this.mTurbineRotorHatches.add(aTurbineHatch); + Logger.INFO("Injected Controller into Turbine Assembly. Found: " + this.mTurbineRotorHatches.size()); + return aDidAdd; + } else { + Logger.INFO("Failed to inject controller into Turbine Assembly Hatch."); + } + } + log("Bad Turbine Housing"); + return false; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeTurbine.png"); + } + + public final Block getCasingBlock() { + return ModBlocks.blockSpecialMultiCasings; + } + + @Override + public final boolean hasSlotInGUI() { + return true; + } + + public abstract int getCasingMeta(); + + public byte getTurbineShaftMeta() { + return 0; + } + + public abstract byte getCasingTextureIndex(); + + public abstract int getFuelValue(FluidStack aLiquid); + + public static boolean isValidTurbine(ItemStack aTurbine) { + return (aTurbine != null + && aTurbine.getItem() instanceof GT_MetaGenerated_Tool + && aTurbine.getItemDamage() >= 170 + && aTurbine.getItemDamage() <= 176); + } + + protected ArrayList<ItemStack> getAllBufferedTurbines() { + ArrayList<ItemStack> aTurbinesInStorage = new ArrayList<>(); + for (GT_MetaTileEntity_Hatch_InputBus aBus : this.mInputBusses) { + if (isValidMetaTileEntity(aBus)) { + for (ItemStack aContent : aBus.mInventory) { + if (isValidTurbine(aContent)) { + aTurbinesInStorage.add(aContent); + } + } + } + } + return aTurbinesInStorage; + } + + public boolean areAllTurbinesTheSame() { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aTurbineAssemblies = getFullTurbineAssemblies(); + if (aTurbineAssemblies.size() < 12) { + log("Found " + aTurbineAssemblies.size() + ", expected 12."); + return false; + } + AutoMap<Materials> aTurbineMats = new AutoMap<>(); + AutoMap<Integer> aTurbineSizes = new AutoMap<>(); + for (GT_MetaTileEntity_Hatch_Turbine aHatch : aTurbineAssemblies) { + aTurbineMats.add(GT_MetaGenerated_Tool.getPrimaryMaterial(aHatch.getTurbine())); + aTurbineSizes.add(getTurbineSize(aHatch.getTurbine())); + } + Materials aBaseMat = aTurbineMats.get(0); + int aBaseSize = aTurbineSizes.get(0); + for (int aSize : aTurbineSizes) { + if (aBaseSize != aSize) { + return false; + } + } + for (Materials aMat : aTurbineMats) { + if (aBaseMat != aMat) { + return false; + } + } + return true; + } + + public static int getTurbineSize(ItemStack aTurbine) { + if (isValidTurbine(aTurbine)) { + if (aTurbine.getItemDamage() >= 170 && aTurbine.getItemDamage() < 172) { + return 1; + } else if (aTurbine.getItemDamage() >= 172 && aTurbine.getItemDamage() < 174) { + return 2; + } else if (aTurbine.getItemDamage() >= 174 && aTurbine.getItemDamage() < 176) { + return 3; + } else if (aTurbine.getItemDamage() >= 176 && aTurbine.getItemDamage() < 178) { + return 4; + } + } + return 0; + } + + public static String getTurbineSizeString(int aSize) { + switch (aSize) { + case 1: + return "Small Turbine"; + case 2: + return "Turbine"; + case 3: + return "Large Turbine"; + case 4: + return "Huge Turbine"; + default: + return ""; + } + } + + protected ArrayList<GT_MetaTileEntity_Hatch_Turbine> getEmptyTurbineAssemblies() { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = + new ArrayList<GT_MetaTileEntity_Hatch_Turbine>(); + // log("Checking "+mTurbineRotorHatches.size()+" Assemblies for empties."); + for (GT_MetaTileEntity_Hatch_Turbine aTurbineHatch : this.mTurbineRotorHatches) { + if (!aTurbineHatch.hasTurbine()) { + // log("Found Assembly without Turbine."); + aEmptyTurbineRotorHatches.add(aTurbineHatch); + } + } + return aEmptyTurbineRotorHatches; + } + + protected ArrayList<GT_MetaTileEntity_Hatch_Turbine> getFullTurbineAssemblies() { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aTurbineRotorHatches = + new ArrayList<GT_MetaTileEntity_Hatch_Turbine>(); + // log("Checking "+mTurbineRotorHatches.size()+" Assemblies for Turbines."); + for (GT_MetaTileEntity_Hatch_Turbine aTurbineHatch : this.mTurbineRotorHatches) { + if (aTurbineHatch.hasTurbine()) { + // log("Found Assembly with Turbine."); + aTurbineRotorHatches.add(aTurbineHatch); + } + } + return aTurbineRotorHatches; + } + + protected boolean depleteTurbineFromStock(ItemStack aTurbine) { + for (GT_MetaTileEntity_Hatch_InputBus aInputBus : this.mInputBusses) { + for (int slot = 0; slot < aInputBus.mInventory.length; slot++) { + ItemStack aStack = aInputBus.getStackInSlot(slot); + if (aStack != null && GT_Utility.areStacksEqual(aStack, aTurbine)) { + aInputBus.setInventorySlotContents(slot, null); + updateSlots(); + return true; + } + } + } + return false; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + log("1"); + return checkRecipeGeneric( + new ItemStack[] {}, getStoredFluids().toArray(new FluidStack[] {}), 1, 100, 100, 10000); + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + + try { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); + if (aEmptyTurbineRotorHatches.size() > 0) { + log("Found " + aEmptyTurbineRotorHatches.size() + " Assemblies without Turbine."); + hatch: + for (GT_MetaTileEntity_Hatch_Turbine aHatch : aEmptyTurbineRotorHatches) { + ArrayList<ItemStack> aTurbines = getAllBufferedTurbines(); + for (ItemStack aTurbineItem : aTurbines) { + if (aTurbineItem == null) { + continue; + } + if (aHatch.insertTurbine(aTurbineItem.copy())) { + boolean aDidDeplete = depleteTurbineFromStock(aTurbineItem); + log("Put Turbine into Assembly - " + aDidDeplete); + continue hatch; + } + } + } + } + + if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { + log("BAD RETURN - 1"); + stopMachine(); + return false; + } + + ArrayList<FluidStack> tFluids = getStoredFluids(); + + if (tFluids.size() > 0) { + if (baseEff == 0 + || optFlow == 0 + || counter >= 512 + || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled() + || this.getBaseMetaTileEntity().hasInventoryBeenModified()) { + counter = 0; + + // log("Running checkRecipeGeneric(1)"); + float aTotalBaseEff = 0; + float aTotalOptimalFlow = 0; + + ItemStack aStack = getFullTurbineAssemblies().get(0).getTurbine(); + for (int i = 0; i < getSpeedMultiplier(); i++) { + if (i == 0) { + aTotalBaseEff += GT_Utility.safeInt((long) + ((5F + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack)) + * 1000F)); + // log("Bumped base eff to "+aTotalBaseEff); + } + aTotalOptimalFlow += GT_Utility.safeInt((long) Math.max( + Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStack.getItem()) + .getToolStats(aStack) + .getSpeedMultiplier() + * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed + * 50)); + // log("Bumped base optimal flow to "+aTotalOptimalFlow); + } + + // log("Running checkRecipeGeneric(2)"); + // log("Total base eff: "+aTotalBaseEff); + // log("Total base optimal flow: "+aTotalOptimalFlow); + baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); + optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); + // log("Total eff: "+baseEff); + // log("Total optimal flow: "+optFlow); + if (optFlow <= 0 || baseEff <= 0) { + log("Running checkRecipeGeneric(bad-1)"); + stopMachine(); // in case the turbine got removed + return false; + } + } else { + counter++; + } + } + + // log("Total eff: "+baseEff); + // log("Total optimal flow: "+optFlow); + + // How much the turbine should be producing with this flow + int newPower = fluidIntoPower(tFluids, optFlow, baseEff); + // log("Bumped newPower to "+newPower); + // log("New Power: "+newPower); + int difference = newPower - this.mEUt; // difference between current output and new output + // log("diff: "+difference); + + // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the + // difference in power level (per tick) + // This is how much the turbine can actually change during this tick + int maxChangeAllowed = Math.max(10, GT_Utility.safeInt((long) Math.abs(difference) / 100)); + // log("Max Change Allowed: "+maxChangeAllowed); + + if (Math.abs(difference) + > maxChangeAllowed) { // If this difference is too big, use the maximum allowed change + int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. + this.mEUt += change; // Apply the change + // log("Applied power change."); + } else { + this.mEUt = newPower; + // log("Using same value."); + } + if (this.mEUt <= 0) { + this.mEUt = 0; + this.mEfficiency = 0; + log("Running checkRecipeGeneric(bad-2)"); + // stopMachine(); + return false; + } else { + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 10; + // Overvoltage is handled inside the MultiBlockBase when pushing out to dynamos. no need to do it here. + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + // log("GOOD RETURN - Making: "+this.mEUt+" EU/t"); + return true; + } + } catch (Throwable t) { + t.printStackTrace(); + } + return false; + } + + public boolean doRandomMaintenanceDamage() { + if (getMaxParallelRecipes() == 0 || getRepairStatus() == 0) { + stopMachine(); + return false; + } + if (mRuntime++ > 1000) { + mRuntime = 0; + + if (getBaseMetaTileEntity().getRandomNumber(6000) < getMaintenanceThreshold()) { + switch (getBaseMetaTileEntity().getRandomNumber(6)) { + case 0: + mWrench = false; + break; + case 1: + mScrewdriver = false; + break; + case 2: + mSoftHammer = false; + break; + case 3: + mHardHammer = false; + break; + case 4: + mSolderingTool = false; + break; + case 5: + mCrowbar = false; + break; + } + } + for (GT_MetaTileEntity_Hatch_Turbine aHatch : getFullTurbineAssemblies()) { + // This cycle depletes durability from the turbine rotors. + // The amount of times it is run depends on turbineDamageMultiplier + // In XL turbines, durability loss is around 5.2-5.3x faster than in singles + // To compensate for that, the mEU/t scaling is divided by 5 to make it only slightly faster + for (int i = 0; i < getTurbineDamageMultiplier(); i++) { + aHatch.damageTurbine(mEUt / 5, damageFactorLow, damageFactorHigh); + } + } + } + return true; + } + + @Override + public int getMaxParallelRecipes() { + return (getFullTurbineAssemblies().size()); + } + + abstract int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff); + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + public int getMaxEfficiency(ItemStack aStack) { + return this.getMaxParallelRecipes() == 12 ? 10000 : 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + public boolean isLooseMode() { + return false; + } + + @Override + public String[] getExtraInfoData() { + int mPollutionReduction = (int) (100 * mufflerReduction); + + String tRunning = mMaxProgresstime > 0 + ? EnumChatFormatting.GREEN + + StatCollector.translateToLocal("GT5U.turbine.running.true") + + EnumChatFormatting.RESET + : EnumChatFormatting.RED + + StatCollector.translateToLocal("GT5U.turbine.running.false") + + EnumChatFormatting.RESET; + + String tMaintainance = getIdealStatus() == getRepairStatus() + ? EnumChatFormatting.GREEN + + StatCollector.translateToLocal("GT5U.turbine.maintenance.false") + + EnumChatFormatting.RESET + : EnumChatFormatting.RED + + StatCollector.translateToLocal("GT5U.turbine.maintenance.true") + + EnumChatFormatting.RESET; + int tDura = 0; + + StringBuilder aTurbineDamage = new StringBuilder(); + for (GT_MetaTileEntity_Hatch_Turbine aHatch : this.getFullTurbineAssemblies()) { + ItemStack aTurbine = aHatch.getTurbine(); + tDura = MathUtils.safeInt((long) (100.0f + / GT_MetaGenerated_Tool.getToolMaxDamage(aTurbine) + * (GT_MetaGenerated_Tool.getToolDamage(aTurbine)) + + 1)); + aTurbineDamage + .append(EnumChatFormatting.RED) + .append(tDura) + .append(EnumChatFormatting.RESET) + .append("% | "); + } + + long storedEnergy = 0; + long maxEnergy = 0; + for (GT_MetaTileEntity_Hatch_Dynamo tHatch : mDynamoHatches) { + if (isValidMetaTileEntity(tHatch)) { + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); + } + } + + boolean aIsSteam = this.getClass().getName().toLowerCase().contains("steam"); + + String[] ret = new String[] { + // 8 Lines available for information panels + tRunning + ": " + EnumChatFormatting.RED + mEUt + EnumChatFormatting.RESET + " EU/t", + tMaintainance, + StatCollector.translateToLocal("GT5U.turbine.efficiency") + ": " + EnumChatFormatting.YELLOW + + (mEfficiency / 100F) + EnumChatFormatting.RESET + "%", + StatCollector.translateToLocal("GT5U.multiblock.energy") + ": " + EnumChatFormatting.GREEN + + Long.toString(storedEnergy) + EnumChatFormatting.RESET + " EU / " + EnumChatFormatting.YELLOW + + Long.toString(maxEnergy) + EnumChatFormatting.RESET + " EU", + StatCollector.translateToLocal("GT5U.turbine.flow") + ": " + EnumChatFormatting.YELLOW + + MathUtils.safeInt((long) realOptFlow) + EnumChatFormatting.RESET + " L/t" + + EnumChatFormatting.YELLOW + " (" + + (isLooseMode() + ? StatCollector.translateToLocal("GT5U.turbine.loose") + : StatCollector.translateToLocal("GT5U.turbine.tight")) + + ")", + StatCollector.translateToLocal("GT5U.turbine.fuel") + ": " + EnumChatFormatting.GOLD + storedFluid + + EnumChatFormatting.RESET + "L", + StatCollector.translateToLocal("GT5U.turbine.dmg") + ": " + aTurbineDamage, + StatCollector.translateToLocal("GT5U.multiblock.pollution") + ": " + EnumChatFormatting.GREEN + + mPollutionReduction + EnumChatFormatting.RESET + " %" + }; + if (!aIsSteam) + ret[4] = StatCollector.translateToLocal("GT5U.turbine.flow") + ": " + EnumChatFormatting.YELLOW + + MathUtils.safeInt((long) realOptFlow) + EnumChatFormatting.RESET + " L/t"; + return ret; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + public boolean polluteEnvironment(int aPollutionLevel) { + if (this.requiresMufflers()) { + mPollution += aPollutionLevel * getPollutionMultiplier() * mufflerReduction; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { + if (isValidMetaTileEntity(tHatch)) { + if (mPollution >= 10000) { + if (PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10000)) { + mPollution -= 10000; + } + } else { + break; + } + } + } + return mPollution < 10000; + } + return true; + } + + @Override + public long maxAmperesOut() { + // This should not be a hard limit, due to TecTech dynamos + if (mFastMode) { + return 64; + } else { + return 16; + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mFastMode", mFastMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mFastMode = aNBT.getBoolean("mFastMode"); + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mFastMode = Utils.invertBoolean(mFastMode); + if (mFastMode) { + PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); + } + } + + @Override + public final ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[1][aColorIndex + 1], + aFacing == aSide + ? getFrontFacingTurbineTexture(aActive) + : Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex()) + }; + } + + protected ITexture getFrontFacingTurbineTexture(boolean isActive) { + if (isActive) { + return frontFaceActive; + } + return frontFace; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (mUpdate == 1 || mStartUpCheck == 1) { + log("Cleared Rotor Assemblies."); + this.mTurbineRotorHatches.clear(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.maxProgresstime() > 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + enableAllTurbineHatches(); + } + if (this.maxProgresstime() <= 0) { + stopMachine(); + } + } + + @Override + public void startProcess() { + super.startProcess(); + enableAllTurbineHatches(); + } + + @Override + public void stopMachine() { + baseEff = 0; + optFlow = 0; + disableAllTurbineHatches(); + super.stopMachine(); + } + + @Override + public void onRemoval() { + super.onRemoval(); + for (GT_MetaTileEntity_Hatch_Turbine h : this.mTurbineRotorHatches) { + h.clearController(); + } + disableAllTurbineHatches(); + this.mTurbineRotorHatches.clear(); + } + + public void enableAllTurbineHatches() { + updateTurbineHatches(this.isMachineRunning()); + } + + public void disableAllTurbineHatches() { + updateTurbineHatches(false); + } + + private Long mLastHatchUpdate; + + public int updateTurbineHatches(boolean aState) { + int aUpdated = 0; + if (mLastHatchUpdate == null) { + mLastHatchUpdate = System.currentTimeMillis() / 1000; + } + if (this.mTurbineRotorHatches.isEmpty() || ((System.currentTimeMillis() / 1000) - mLastHatchUpdate) <= 2) { + return 0; + } + for (GT_MetaTileEntity_Hatch_Turbine h : this.mTurbineRotorHatches) { + h.setActive(aState); + aUpdated++; + } + + mLastHatchUpdate = System.currentTimeMillis() / 1000; + return aUpdated; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + // Fix GT bug + if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { + log("Fixing Bad Facing. (GT Bug)"); + this.getBaseMetaTileEntity().setFrontFacing((byte) 1); + } + } -public abstract class GregtechMetaTileEntity_LargerTurbineBase extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargerTurbineBase> implements ISurvivalConstructable { - - protected int baseEff = 0; - protected int optFlow = 0; - protected double realOptFlow = 0; - protected int storedFluid = 0; - protected int counter = 0; - protected boolean mFastMode = false; - protected double mufflerReduction = 1; - - public ITexture frontFace; - public ITexture frontFaceActive; - - - public ArrayList<GT_MetaTileEntity_Hatch_Turbine> mTurbineRotorHatches = new ArrayList<GT_MetaTileEntity_Hatch_Turbine>(); - - - public GregtechMetaTileEntity_LargerTurbineBase(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - frontFace = getTextureFrontFace(); - frontFaceActive = getTextureFrontFaceActive(); - - } - public GregtechMetaTileEntity_LargerTurbineBase(String aName) { - super(aName); - frontFace = getTextureFrontFace(); - frontFaceActive = getTextureFrontFaceActive(); - } - - - protected abstract ITexture getTextureFrontFace(); - - protected abstract ITexture getTextureFrontFaceActive(); - - protected abstract String getTurbineType(); - - protected abstract String getCasingName(); - - protected abstract boolean requiresOutputHatch(); - - @Override - protected final GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Controller Block for the XL "+getTurbineType()+" Turbine") - .addInfo("Runs as fast as 16 Large Turbines of the same type, takes the space of 12") - .addInfo("Right-click with screwdriver to enable Fast Mode, to run it even faster") - .addInfo("Optimal flow will increase or decrease accordingly on mode switch") - .addInfo("Fast Mode increases speed to 48x instead of 16x, with some penalties") - .addInfo("Maintenance problems and turbine damage happen 12x as often in Fast Mode") - .addInfo("XL Steam Turbines can use Loose Mode with either Slow or Fast Mode") - .addPollutionAmount(getPollutionPerSecond(null)) - .addInfo("Pollution is 3x higher in Fast Mode") - .addSeparator() - .beginStructureBlock(7, 9, 7, false) - .addController("Top Middle") - .addCasingInfo(getCasingName(), 360) - .addOtherStructurePart("Rotor Assembly", "Any 1 dot hint", 1) - .addInputBus("Any 4 dot hint (min 1)", 4) - .addInputHatch("Any 4 dot hint(min 1)", 4); - if (requiresOutputHatch()) { - tt.addOutputHatch("Any 4 dot hint(min 1)", 4); - } - tt.addDynamoHatch("Any 4 dot hint(min 1)", 4) - .addMaintenanceHatch("Any 4 dot hint(min 1)", 4); - if (requiresMufflers()) { - tt.addMufflerHatch("Any 7 dot hint (x4)", 7); - } - tt.toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - private static final String STRUCTURE_PIECE_MAIN = "main"; - private static final ClassValue<IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase>> STRUCTURE_DEFINITION = new ClassValue<IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase>>() { - @Override - protected IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase> computeValue(Class<?> type) { - return StructureDefinition.<GregtechMetaTileEntity_LargerTurbineBase>builder() - // c = turbine casing - // s = turbine shaft - // t = turbine housing - // h = dynamo/maint - // m = muffler - .addShape(STRUCTURE_PIECE_MAIN, (new String[][]{ - {"ccchccc", "ccccccc", "ccmmmcc", "ccm~mcc", "ccmmmcc", "ccccccc", "ccchccc"}, - {"ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc"}, - {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, - {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, - {"ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc"}, - {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, - {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, - {"ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc"}, - {"ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc"}, - })) - - .addElement('c', lazy(t -> ofBlock(t.getCasingBlock(), t.getCasingMeta()))) - .addElement('s', lazy(t -> ofBlock(t.getCasingBlock(), t.getTurbineShaftMeta()))) - .addElement('t', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class) - .adder(GregtechMetaTileEntity_LargerTurbineBase::addTurbineHatch) - .hatchClass(GT_MetaTileEntity_Hatch_Turbine.class) - .casingIndex(t.getCasingTextureIndex()) - .dot(1) - .build())) - .addElement('h', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class) - .atLeast(InputBus, InputHatch, OutputHatch, Dynamo.or(TTDynamo), Maintenance) - .casingIndex(t.getCasingTextureIndex()) - .dot(4) - .buildAndChain(t.getCasingBlock(), t.getCasingMeta()))) - .addElement('m', lazy(t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class) - .atLeast(Muffler) - .casingIndex(t.getCasingTextureIndex()) - .dot(7) - .buildAndChain(t.getCasingBlock(), t.getCasingMeta()))) - .build(); - } - }; - - @Override - public IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase> getStructureDefinition() { - return STRUCTURE_DEFINITION.get(getClass()); - } - - private boolean requiresMufflers() { - if (!PollutionUtils.isPollutionEnabled()) { - return false; - } - return getPollutionPerSecond(null) > 0; - } - - public final double getMufflerReduction() { - double totalReduction = 0; - for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - totalReduction += ((double) tHatch.calculatePollutionReduction(100)) / 100; - } - } - return totalReduction / 4; - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - this.mDynamoHatches.clear(); - this.mTecTechDynamoHatches.clear(); - this.mTurbineRotorHatches.clear(); - this.mMaintenanceHatches.clear(); - if (requiresMufflers()) { - this.mMufflerHatches.clear(); - } - this.mInputBusses.clear(); - this.mInputHatches.clear(); - if (requiresOutputHatch()) { - this.mOutputHatches.clear(); - } - // we do not check for casing count here. the bare minimal is 372 but we only require 360 - boolean aStructure = checkPiece(STRUCTURE_PIECE_MAIN, 3, 3, 0); - log("Structure Check: "+aStructure); - if (mTurbineRotorHatches.size() != 12 || - mMaintenanceHatches.size() != 1 || - (mDynamoHatches.size() < 1 && mTecTechDynamoHatches.size() < 1) || - (requiresMufflers() && mMufflerHatches.size() != 4) || - mInputBusses.size() < 1 || - mInputHatches.size() < 1 || - (requiresOutputHatch() && mOutputHatches.size() < 1) - ) { - log("Bad Hatches - Turbine Housings: "+mTurbineRotorHatches.size()+ - ", Maint: "+mMaintenanceHatches.size()+ - ", Dynamo: "+mDynamoHatches.size()+ - ", Muffler: "+mMufflerHatches.size()+ - ", Input Buses: "+mInputBusses.size()+ - ", Input Hatches: "+mInputHatches.size()+ - ", Output Hatches: "+mOutputHatches.size()); - return false; - } - mufflerReduction = getMufflerReduction(); - return aStructure; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 3, 3, 0); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - int realBudget = elementBudget >= 200 ? elementBudget : Math.min(200, elementBudget * 2); - return survivialBuildPiece(mName, stackSize, 1, 3, 3, realBudget, source, actor, false, true); - } - - public boolean addTurbineHatch(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine) { - log("Found GT_MetaTileEntity_Hatch_Turbine"); - updateTexture(aTileEntity, aBaseCasingIndex); - GT_MetaTileEntity_Hatch_Turbine aTurbineHatch = (GT_MetaTileEntity_Hatch_Turbine) aMetaTileEntity; - IGregTechTileEntity g = this.getBaseMetaTileEntity(); - if (aTurbineHatch.setController(new BlockPos(g.getXCoord(), g.getYCoord(), g.getZCoord(), g.getWorld()))) { - boolean aDidAdd = this.mTurbineRotorHatches.add(aTurbineHatch); - Logger.INFO("Injected Controller into Turbine Assembly. Found: "+this.mTurbineRotorHatches.size()); - return aDidAdd; - } - else { - Logger.INFO("Failed to inject controller into Turbine Assembly Hatch."); - } - } - log("Bad Turbine Housing"); - return false; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - return getMaxEfficiency(aStack) > 0; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeTurbine.png"); - } - - public final Block getCasingBlock() { - return ModBlocks.blockSpecialMultiCasings; - } - - @Override - public final boolean hasSlotInGUI() { - return true; - } - - public abstract int getCasingMeta(); - - public byte getTurbineShaftMeta() { - return 0; - } - - public abstract byte getCasingTextureIndex(); - - public abstract int getFuelValue(FluidStack aLiquid); - - public static boolean isValidTurbine(ItemStack aTurbine) { - return (aTurbine !=null && aTurbine.getItem() instanceof GT_MetaGenerated_Tool && aTurbine.getItemDamage() >= 170 && aTurbine.getItemDamage() <= 176); - } - - protected ArrayList<ItemStack> getAllBufferedTurbines(){ - ArrayList<ItemStack> aTurbinesInStorage = new ArrayList<>(); - for (GT_MetaTileEntity_Hatch_InputBus aBus: this.mInputBusses) { - if (isValidMetaTileEntity(aBus)) { - for (ItemStack aContent : aBus.mInventory) { - if (isValidTurbine(aContent)) { - aTurbinesInStorage.add(aContent); - } - } - } - } - return aTurbinesInStorage; - } - - public boolean areAllTurbinesTheSame() { - ArrayList<GT_MetaTileEntity_Hatch_Turbine> aTurbineAssemblies = getFullTurbineAssemblies(); - if (aTurbineAssemblies.size() < 12) { - log("Found "+aTurbineAssemblies.size()+", expected 12."); - return false; - } - AutoMap<Materials> aTurbineMats = new AutoMap<>(); - AutoMap<Integer> aTurbineSizes = new AutoMap<>(); - for (GT_MetaTileEntity_Hatch_Turbine aHatch : aTurbineAssemblies) { - aTurbineMats.add(GT_MetaGenerated_Tool.getPrimaryMaterial(aHatch.getTurbine())); - aTurbineSizes.add(getTurbineSize(aHatch.getTurbine())); - } - Materials aBaseMat = aTurbineMats.get(0); - int aBaseSize = aTurbineSizes.get(0); - for (int aSize : aTurbineSizes) { - if (aBaseSize != aSize) { - return false; - } - } - for (Materials aMat : aTurbineMats) { - if (aBaseMat != aMat) { - return false; - } - } - return true; - } - - public static int getTurbineSize(ItemStack aTurbine) { - if (isValidTurbine(aTurbine)) { - if (aTurbine.getItemDamage() >= 170 && aTurbine.getItemDamage() < 172) { - return 1; - } - else if (aTurbine.getItemDamage() >= 172 && aTurbine.getItemDamage() < 174) { - return 2; - } - else if (aTurbine.getItemDamage() >= 174 && aTurbine.getItemDamage() < 176) { - return 3; - } - else if (aTurbine.getItemDamage() >= 176 && aTurbine.getItemDamage() < 178) { - return 4; - } - } - return 0; - } - - public static String getTurbineSizeString(int aSize) { - switch (aSize) { - case 1: - return "Small Turbine"; - case 2: - return "Turbine"; - case 3: - return "Large Turbine"; - case 4: - return "Huge Turbine"; - default: - return ""; - } - } - - protected ArrayList<GT_MetaTileEntity_Hatch_Turbine> getEmptyTurbineAssemblies() { - ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = new ArrayList<GT_MetaTileEntity_Hatch_Turbine>(); - //log("Checking "+mTurbineRotorHatches.size()+" Assemblies for empties."); - for (GT_MetaTileEntity_Hatch_Turbine aTurbineHatch : this.mTurbineRotorHatches) { - if (!aTurbineHatch.hasTurbine()) { - //log("Found Assembly without Turbine."); - aEmptyTurbineRotorHatches.add(aTurbineHatch); - } - } - return aEmptyTurbineRotorHatches; - } - - protected ArrayList<GT_MetaTileEntity_Hatch_Turbine> getFullTurbineAssemblies() { - ArrayList<GT_MetaTileEntity_Hatch_Turbine> aTurbineRotorHatches = new ArrayList<GT_MetaTileEntity_Hatch_Turbine>(); - //log("Checking "+mTurbineRotorHatches.size()+" Assemblies for Turbines."); - for (GT_MetaTileEntity_Hatch_Turbine aTurbineHatch : this.mTurbineRotorHatches) { - if (aTurbineHatch.hasTurbine()) { - //log("Found Assembly with Turbine."); - aTurbineRotorHatches.add(aTurbineHatch); - } - } - return aTurbineRotorHatches; - } - - protected boolean depleteTurbineFromStock(ItemStack aTurbine) { - for (GT_MetaTileEntity_Hatch_InputBus aInputBus : this.mInputBusses) { - for (int slot = 0; slot < aInputBus.mInventory.length; slot++) { - ItemStack aStack = aInputBus.getStackInSlot(slot); - if (aStack != null && GT_Utility.areStacksEqual(aStack, aTurbine)) { - aInputBus.setInventorySlotContents(slot, null); - updateSlots(); - return true; - } - } - } - return false; - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - log("1"); - return checkRecipeGeneric(new ItemStack[] {}, getStoredFluids().toArray(new FluidStack[] {}), 1, 100, 100, 10000); - } - - @Override - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - - try { - ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); - if (aEmptyTurbineRotorHatches.size() > 0) { - log("Found "+aEmptyTurbineRotorHatches.size()+" Assemblies without Turbine."); - hatch : for (GT_MetaTileEntity_Hatch_Turbine aHatch : aEmptyTurbineRotorHatches) { - ArrayList<ItemStack> aTurbines = getAllBufferedTurbines(); - for (ItemStack aTurbineItem : aTurbines) { - if (aTurbineItem == null) { - continue; - } - if (aHatch.insertTurbine(aTurbineItem.copy())) { - boolean aDidDeplete = depleteTurbineFromStock(aTurbineItem); - log("Put Turbine into Assembly - "+aDidDeplete); - continue hatch; - } - } - } - } - - if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { - log("BAD RETURN - 1"); - stopMachine(); - return false; - } - - ArrayList<FluidStack> tFluids = getStoredFluids(); - - if (tFluids.size() > 0) { - if (baseEff == 0 || optFlow == 0 || counter >= 512 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled() - || this.getBaseMetaTileEntity().hasInventoryBeenModified()) { - counter = 0; - - //log("Running checkRecipeGeneric(1)"); - float aTotalBaseEff = 0; - float aTotalOptimalFlow = 0; - - ItemStack aStack = getFullTurbineAssemblies().get(0).getTurbine(); - for (int i = 0; i< getSpeedMultiplier(); i++) { - if (i == 0) { - aTotalBaseEff += GT_Utility.safeInt((long) ((5F + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack)) * 1000F)); - //log("Bumped base eff to "+aTotalBaseEff); - } - aTotalOptimalFlow += GT_Utility.safeInt((long) Math.max(Float.MIN_NORMAL, - ((GT_MetaGenerated_Tool) aStack.getItem()).getToolStats(aStack).getSpeedMultiplier() - * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed - * 50)); - //log("Bumped base optimal flow to "+aTotalOptimalFlow); - } - - //log("Running checkRecipeGeneric(2)"); - //log("Total base eff: "+aTotalBaseEff); - //log("Total base optimal flow: "+aTotalOptimalFlow); - baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); - optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); - //log("Total eff: "+baseEff); - //log("Total optimal flow: "+optFlow); - if(optFlow<=0 || baseEff<=0){ - log("Running checkRecipeGeneric(bad-1)"); - stopMachine();//in case the turbine got removed - return false; - } - } else { - counter++; - } - } - - //log("Total eff: "+baseEff); - //log("Total optimal flow: "+optFlow); - - // How much the turbine should be producing with this flow - int newPower = fluidIntoPower(tFluids, optFlow, baseEff); - //log("Bumped newPower to "+newPower); - //log("New Power: "+newPower); - int difference = newPower - this.mEUt; // difference between current output and new output - //log("diff: "+difference); - - // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the difference in power level (per tick) - // This is how much the turbine can actually change during this tick - int maxChangeAllowed = Math.max(10, GT_Utility.safeInt((long)Math.abs(difference)/100)); - //log("Max Change Allowed: "+maxChangeAllowed); - - if (Math.abs(difference) > maxChangeAllowed) { // If this difference is too big, use the maximum allowed change - int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. - this.mEUt += change; // Apply the change - //log("Applied power change."); - } - else { - this.mEUt = newPower; - //log("Using same value."); - } - if (this.mEUt <= 0) { - this.mEUt=0; - this.mEfficiency=0; - log("Running checkRecipeGeneric(bad-2)"); - //stopMachine(); - return false; - } else { - this.mMaxProgresstime = 1; - this.mEfficiencyIncrease = 10; - // Overvoltage is handled inside the MultiBlockBase when pushing out to dynamos. no need to do it here. - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - //log("GOOD RETURN - Making: "+this.mEUt+" EU/t"); - return true; - } - } - catch (Throwable t) { - t.printStackTrace(); - } - return false; - } - - public boolean doRandomMaintenanceDamage() { - if (getMaxParallelRecipes() == 0 || getRepairStatus() == 0) { - stopMachine(); - return false; - } - if (mRuntime++ > 1000) { - mRuntime = 0; - - if (getBaseMetaTileEntity().getRandomNumber(6000) < getMaintenanceThreshold()) { - switch (getBaseMetaTileEntity().getRandomNumber(6)) { - case 0: - mWrench = false; - break; - case 1: - mScrewdriver = false; - break; - case 2: - mSoftHammer = false; - break; - case 3: - mHardHammer = false; - break; - case 4: - mSolderingTool = false; - break; - case 5: - mCrowbar = false; - break; - } - } - for (GT_MetaTileEntity_Hatch_Turbine aHatch : getFullTurbineAssemblies()) { - // This cycle depletes durability from the turbine rotors. - // The amount of times it is run depends on turbineDamageMultiplier - // In XL turbines, durability loss is around 5.2-5.3x faster than in singles - // To compensate for that, the mEU/t scaling is divided by 5 to make it only slightly faster - for (int i = 0; i < getTurbineDamageMultiplier(); i++) { - aHatch.damageTurbine(mEUt / 5, damageFactorLow, damageFactorHigh); - } - } - } - return true; - } - - @Override - public int getMaxParallelRecipes() { - return (getFullTurbineAssemblies().size()); - } - - abstract int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff); - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 1; - } - - public int getMaxEfficiency(ItemStack aStack) { - return this.getMaxParallelRecipes() == 12 ? 10000 : 0; - } - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - public boolean isLooseMode() { - return false; - } - - @Override - public String[] getExtraInfoData() { - int mPollutionReduction=(int) (100 * mufflerReduction); - - String tRunning = mMaxProgresstime > 0 ? - EnumChatFormatting.GREEN+StatCollector.translateToLocal("GT5U.turbine.running.true")+EnumChatFormatting.RESET : - EnumChatFormatting.RED+StatCollector.translateToLocal("GT5U.turbine.running.false")+EnumChatFormatting.RESET; - - String tMaintainance = getIdealStatus() == getRepairStatus() ? - EnumChatFormatting.GREEN+StatCollector.translateToLocal("GT5U.turbine.maintenance.false")+EnumChatFormatting.RESET : - EnumChatFormatting.RED+StatCollector.translateToLocal("GT5U.turbine.maintenance.true")+EnumChatFormatting.RESET ; - int tDura = 0; - - StringBuilder aTurbineDamage = new StringBuilder(); - for (GT_MetaTileEntity_Hatch_Turbine aHatch : this.getFullTurbineAssemblies()) { - ItemStack aTurbine = aHatch.getTurbine(); - tDura = MathUtils.safeInt((long)(100.0f / GT_MetaGenerated_Tool.getToolMaxDamage(aTurbine) * (GT_MetaGenerated_Tool.getToolDamage(aTurbine))+1)); - aTurbineDamage.append(EnumChatFormatting.RED).append(tDura).append(EnumChatFormatting.RESET).append("% | "); - } - - long storedEnergy=0; - long maxEnergy=0; - for(GT_MetaTileEntity_Hatch_Dynamo tHatch : mDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU(); - maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity(); - } - } - - boolean aIsSteam = this.getClass().getName().toLowerCase().contains("steam"); - - String[] ret = new String[]{ - // 8 Lines available for information panels - tRunning + ": " + EnumChatFormatting.RED+mEUt+EnumChatFormatting.RESET+" EU/t", - tMaintainance, - StatCollector.translateToLocal("GT5U.turbine.efficiency")+": "+EnumChatFormatting.YELLOW+(mEfficiency/100F)+EnumChatFormatting.RESET+"%", - StatCollector.translateToLocal("GT5U.multiblock.energy")+": " + EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET +" EU / "+ - EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET +" EU", - StatCollector.translateToLocal("GT5U.turbine.flow")+": "+EnumChatFormatting.YELLOW+MathUtils.safeInt((long)realOptFlow)+EnumChatFormatting.RESET+" L/t" + - EnumChatFormatting.YELLOW+" ("+(isLooseMode()?StatCollector.translateToLocal("GT5U.turbine.loose"):StatCollector.translateToLocal("GT5U.turbine.tight"))+")", - StatCollector.translateToLocal("GT5U.turbine.fuel")+": "+EnumChatFormatting.GOLD+storedFluid+EnumChatFormatting.RESET+"L", - StatCollector.translateToLocal("GT5U.turbine.dmg")+": "+aTurbineDamage, - StatCollector.translateToLocal("GT5U.multiblock.pollution")+": "+ EnumChatFormatting.GREEN + mPollutionReduction+ EnumChatFormatting.RESET+" %" - }; - if (!aIsSteam) - ret[4]=StatCollector.translateToLocal("GT5U.turbine.flow")+": "+EnumChatFormatting.YELLOW+MathUtils.safeInt((long)realOptFlow)+EnumChatFormatting.RESET+" L/t"; - return ret; - - - } - - @Override - public boolean isGivingInformation() { - return true; - } - - - public boolean polluteEnvironment(int aPollutionLevel) { - if (this.requiresMufflers()) { - mPollution += aPollutionLevel * getPollutionMultiplier() * mufflerReduction; - for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (mPollution >= 10000) { - if (PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10000)) { - mPollution -= 10000; - } - } else { - break; - } - } - } - return mPollution < 10000; - } - return true; - } - @Override - public long maxAmperesOut() { - // This should not be a hard limit, due to TecTech dynamos - if (mFastMode) { - return 64; - } - else { - return 16; - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("mFastMode", mFastMode); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mFastMode = aNBT.getBoolean("mFastMode"); - super.loadNBTData(aNBT); - } - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - mFastMode = Utils.invertBoolean(mFastMode); - if (mFastMode){ - PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); - } - } - - @Override - public final ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[1][aColorIndex + 1], aFacing == aSide ? getFrontFacingTurbineTexture(aActive) : Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex())}; - } - - protected ITexture getFrontFacingTurbineTexture(boolean isActive) { - if (isActive) { - return frontFaceActive; - } - return frontFace; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (mUpdate == 1 || mStartUpCheck == 1) { - log("Cleared Rotor Assemblies."); - this.mTurbineRotorHatches.clear(); - } - } - super.onPostTick(aBaseMetaTileEntity, aTick); - if (this.maxProgresstime() > 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { - enableAllTurbineHatches(); - } - if (this.maxProgresstime() <= 0) { - stopMachine(); - } - - } - @Override - public void startProcess() { - super.startProcess(); - enableAllTurbineHatches(); - } - - @Override - public void stopMachine() { - baseEff = 0; - optFlow = 0; - disableAllTurbineHatches(); - super.stopMachine(); - } - - @Override - public void onRemoval() { - super.onRemoval(); - for (GT_MetaTileEntity_Hatch_Turbine h : this.mTurbineRotorHatches) { - h.clearController(); - } - disableAllTurbineHatches(); - this.mTurbineRotorHatches.clear(); - } - - public void enableAllTurbineHatches() { - updateTurbineHatches(this.isMachineRunning()); - } - - public void disableAllTurbineHatches() { - updateTurbineHatches(false); - } - - private Long mLastHatchUpdate; - public int updateTurbineHatches(boolean aState) { - int aUpdated = 0; - if (mLastHatchUpdate == null) { - mLastHatchUpdate = System.currentTimeMillis()/1000; - } - if (this.mTurbineRotorHatches.isEmpty() || ((System.currentTimeMillis()/1000)-mLastHatchUpdate) <= 2) { - return 0; - } - for (GT_MetaTileEntity_Hatch_Turbine h : this.mTurbineRotorHatches) { - h.setActive(aState); - aUpdated++; - } - - mLastHatchUpdate = System.currentTimeMillis()/1000; - return aUpdated; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - // Fix GT bug - if (this.getBaseMetaTileEntity().getFrontFacing() != 1) { - log("Fixing Bad Facing. (GT Bug)"); - this.getBaseMetaTileEntity().setFrontFacing((byte) 1); - } - } - /** * Called every tick the Machine runs */ @@ -810,24 +857,24 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends GregtechM return false; } - @Override - public boolean addEnergyOutput(long aEU) { - if (aEU <= 0) { - return true; - } - if (this.mAllDynamoHatches.size() > 0) { - return addEnergyOutputMultipleDynamos(aEU, true); - } - return false; - } - + @Override + public boolean addEnergyOutput(long aEU) { + if (aEU <= 0) { + return true; + } + if (this.mAllDynamoHatches.size() > 0) { + return addEnergyOutputMultipleDynamos(aEU, true); + } + return false; + } + public boolean addEnergyOutputMultipleDynamos(long aEU, boolean aAllowMixedVoltageDynamos) { int injected = 0; long totalOutput = 0; long aFirstVoltageFound = -1; boolean aFoundMixedDynamos = false; for (GT_MetaTileEntity_Hatch aDynamo : mAllDynamoHatches) { - if(aDynamo == null) { + if (aDynamo == null) { return false; } if (isValidMetaTileEntity(aDynamo)) { @@ -836,8 +883,7 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends GregtechM // Check against voltage to check when hatch mixing if (aFirstVoltageFound == -1) { aFirstVoltageFound = aVoltage; - } - else { + } else { if (aFirstVoltageFound != aVoltage) { aFoundMixedDynamos = true; } @@ -857,33 +903,33 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends GregtechM aVoltage = aDynamo.maxEUOutput(); aAmpsToInject = (int) (leftToInject / aVoltage); aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); - ampsOnCurrentHatch= (int) Math.min(aDynamo.maxAmperesOut(), aAmpsToInject); + ampsOnCurrentHatch = (int) Math.min(aDynamo.maxAmperesOut(), aAmpsToInject); for (int i = 0; i < ampsOnCurrentHatch; i++) { aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(aVoltage, false); } - injected+=aVoltage*ampsOnCurrentHatch; - if(aRemainder>0 && ampsOnCurrentHatch<aDynamo.maxAmperesOut()){ + injected += aVoltage * ampsOnCurrentHatch; + if (aRemainder > 0 && ampsOnCurrentHatch < aDynamo.maxAmperesOut()) { aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(aRemainder, false); - injected+=aRemainder; + injected += aRemainder; } } } return injected > 0; } - public int getSpeedMultiplier() { - return mFastMode ? 48 : 16; - } + public int getSpeedMultiplier() { + return mFastMode ? 48 : 16; + } - public int getMaintenanceThreshold() { - return mFastMode ? 12 : 1; - } + public int getMaintenanceThreshold() { + return mFastMode ? 12 : 1; + } - public int getPollutionMultiplier() { - return mFastMode ? 3 : 1; - } + public int getPollutionMultiplier() { + return mFastMode ? 3 : 1; + } - public int getTurbineDamageMultiplier() { - return mFastMode ? 3 : 1; - } + public int getTurbineDamageMultiplier() { + return mFastMode ? 3 : 1; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_MultiTank.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_MultiTank.java index 6ed14eb2a9..4ec9d0347f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_MultiTank.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_MultiTank.java @@ -1,33 +1,6 @@ /* package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.storage; -import java.util.ArrayList; -import java.util.Arrays; - -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.TAE; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.Pair; -import gtPlusPlus.core.block.ModBlocks; -import gtPlusPlus.core.util.minecraft.FluidUtils; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_MultiTank extends GregtechMeta_MultiBlockBase { @@ -46,7 +19,7 @@ extends GregtechMeta_MultiBlockBase { public String getMachineType() { return "Fluid Tank"; } - + @Override public String[] getExtraInfoData() { final ArrayList<GT_MetaTileEntity_Hatch_Energy> mTier = this.mEnergyHatches; @@ -77,545 +50,545 @@ extends GregtechMeta_MultiBlockBase { super.saveNBTData(aNBT); */ /*final NBTTagCompound gtCraftingComponentsTag = aNBT.getCompoundTag("GT.CraftingComponents"); - if (gtCraftingComponentsTag != null){ - - Utils.LOG_WARNING("Got Crafting Tag"); - - if (this.internalStorageTank != null){ - Utils.LOG_WARNING("mFluid was not null, Saving TileEntity NBT data."); - - gtCraftingComponentsTag.setString("xFluid", this.internalStorageTank.getFluid().getName()); - gtCraftingComponentsTag.setInteger("xAmount", this.internalStorageTank.amount); - gtCraftingComponentsTag.setLong("xAmountMax", this.maximumFluidStorage); - - aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); - } - else { - Utils.LOG_WARNING("mFluid was null, Saving TileEntity NBT data."); - gtCraftingComponentsTag.removeTag("xFluid"); - gtCraftingComponentsTag.removeTag("xAmount"); - gtCraftingComponentsTag.removeTag("xAmountMax"); - gtCraftingComponentsTag.setLong("xAmountMax", this.maximumFluidStorage); - - - aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); - } - }*//* - - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - */ -/*final NBTTagCompound gtCraftingComponentsTag = aNBT.getCompoundTag("GT.CraftingComponents"); - String xFluid = null; - int xAmount = 0; - if (gtCraftingComponentsTag.hasNoTags()){ - if (this.internalStorageTank != null){ - Utils.LOG_WARNING("mFluid was not null, Creating TileEntity NBT data."); - gtCraftingComponentsTag.setInteger("xAmount", this.internalStorageTank.amount); - gtCraftingComponentsTag.setString("xFluid", this.internalStorageTank.getFluid().getName()); - aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); - } - } - else { - - //internalCraftingComponentsTag = gtCraftingComponentsTag.getCompoundTag("backupTag"); - - if (gtCraftingComponentsTag.hasKey("xFluid")){ - Utils.LOG_WARNING("xFluid was not null, Loading TileEntity NBT data."); - xFluid = gtCraftingComponentsTag.getString("xFluid"); - } - if (gtCraftingComponentsTag.hasKey("xAmount")){ - Utils.LOG_WARNING("xAmount was not null, Loading TileEntity NBT data."); - xAmount = gtCraftingComponentsTag.getInteger("xAmount"); - } - if ((xFluid != null) && (xAmount != 0)){ - Utils.LOG_WARNING("Setting Internal Tank, loading "+xAmount+"L of "+xFluid); - this.setInternalTank(xFluid, xAmount); - } - }*//* +if (gtCraftingComponentsTag != null){ - } - - private boolean setInternalTank(final String fluidName, final int amount){ - final FluidStack temp = FluidUtils.getFluidStack(fluidName, amount); - if (temp != null){ - if (this.internalStorageTank == null){ - this.internalStorageTank = temp; - Logger.WARNING(temp.getFluid().getName()+" Amount: "+temp.amount+"L"); - } - else{ - Logger.WARNING("Retained Fluid."); - Logger.WARNING(this.internalStorageTank.getFluid().getName()+" Amxount: "+this.internalStorageTank.amount+"L"); - } - this.markDirty(); - return true; - } - return false; - } + Utils.LOG_WARNING("Got Crafting Tag"); - @Override - public void onLeftclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - this.tryForceNBTUpdate(); - super.onLeftclick(aBaseMetaTileEntity, aPlayer); - } + if (this.internalStorageTank != null){ + Utils.LOG_WARNING("mFluid was not null, Saving TileEntity NBT data."); - @Override - public boolean onWrenchRightClick(final byte aSide, final byte aWrenchingSide, final EntityPlayer aPlayer, final float aX, final float aY, final float aZ) { - this.tryForceNBTUpdate(); - return super.onWrenchRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); - } + gtCraftingComponentsTag.setString("xFluid", this.internalStorageTank.getFluid().getName()); + gtCraftingComponentsTag.setInteger("xAmount", this.internalStorageTank.amount); + gtCraftingComponentsTag.setLong("xAmountMax", this.maximumFluidStorage); - @Override - public void onRemoval() { - this.tryForceNBTUpdate(); - super.onRemoval(); + aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); } + else { + Utils.LOG_WARNING("mFluid was null, Saving TileEntity NBT data."); + gtCraftingComponentsTag.removeTag("xFluid"); + gtCraftingComponentsTag.removeTag("xAmount"); + gtCraftingComponentsTag.removeTag("xAmountMax"); + gtCraftingComponentsTag.setLong("xAmountMax", this.maximumFluidStorage); - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - - if ((this.internalStorageTank != null) && this.internalStorageTank.amount >= this.maximumFluidStorage){ - if (this.internalStorageTank.amount > this.maximumFluidStorage){ - this.internalStorageTank.amount = this.maximumFluidStorage; - } - this.stopMachine(); - } - - if (this.mInternalSaveClock != 20){ - this.mInternalSaveClock++; - } - else { - this.mInternalSaveClock = 0; - this.tryForceNBTUpdate(); - } - + aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); } +}*//* - public GregtechMetaTileEntity_MultiTank(final String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_MultiTank(this.mName); - } + } - @Override - public String[] getTooltip() { - return new String[]{ - "Controller Block for the Multitank", - "Size: 3xHx3 (Block behind controller must be air)", - "Structure must be at least 4 blocks tall, maximum 20.", - "Each casing within the structure adds 128000L storage.", - "Multitank Exterior Casings (16 at least!)", - "Controller (front centered)", - "1x Input hatch", - "1x Output hatch", - "1x Energy Hatch", - }; + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + */ +/*final NBTTagCompound gtCraftingComponentsTag = aNBT.getCompoundTag("GT.CraftingComponents"); +String xFluid = null; +int xAmount = 0; +if (gtCraftingComponentsTag.hasNoTags()){ + if (this.internalStorageTank != null){ + Utils.LOG_WARNING("mFluid was not null, Creating TileEntity NBT data."); + gtCraftingComponentsTag.setInteger("xAmount", this.internalStorageTank.amount); + gtCraftingComponentsTag.setString("xFluid", this.internalStorageTank.getFluid().getName()); + aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); } +} +else { - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(11)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Screen_Logo : TexturesGtBlock.Overlay_Machine_Screen_Logo)}; - } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(11))}; - } + //internalCraftingComponentsTag = gtCraftingComponentsTag.getCompoundTag("backupTag"); - @Override - public boolean hasSlotInGUI() { - return false; + if (gtCraftingComponentsTag.hasKey("xFluid")){ + Utils.LOG_WARNING("xFluid was not null, Loading TileEntity NBT data."); + xFluid = gtCraftingComponentsTag.getString("xFluid"); } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return null; + if (gtCraftingComponentsTag.hasKey("xAmount")){ + Utils.LOG_WARNING("xAmount was not null, Loading TileEntity NBT data."); + xAmount = gtCraftingComponentsTag.getInteger("xAmount"); } - - @Override - public boolean isFacingValid(final byte aFacing) { - return aFacing > 1; + if ((xFluid != null) && (xAmount != 0)){ + Utils.LOG_WARNING("Setting Internal Tank, loading "+xAmount+"L of "+xFluid); + this.setInternalTank(xFluid, xAmount); } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - - final ArrayList<ItemStack> tInputList = this.getStoredInputs(); - for (int i = 0; i < (tInputList.size() - 1); i++) { - for (int j = i + 1; j < tInputList.size(); j++) { - if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { - if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) { - tInputList.remove(j--); - } else { - tInputList.remove(i--); - break; - } - } - } - } - final ItemStack[] tInputs = Arrays.copyOfRange(tInputList.toArray(new ItemStack[tInputList.size()]), 0, 2); - - final ArrayList<FluidStack> tFluidList = this.getStoredFluids(); - for (int i = 0; i < (tFluidList.size() - 1); i++) { - for (int j = i + 1; j < tFluidList.size(); j++) { - if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { - if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { - tFluidList.remove(j--); - } else { - tFluidList.remove(i--); - break; - } - } - } - } - final FluidStack[] tFluids = Arrays.copyOfRange(tFluidList.toArray(new FluidStack[1]), 0, 1); - - if (tFluids.length >= 2){ - Logger.WARNING("Bad"); - return false; - } - - final ArrayList<Pair<GT_MetaTileEntity_Hatch_Input, Boolean>> rList = new ArrayList<>(); - int slotInputCount = 0; - for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { - boolean containsFluid = false; - if (isValidMetaTileEntity(tHatch)) { - slotInputCount++; - for (int i=0; i<tHatch.getBaseMetaTileEntity().getSizeInventory(); i++) { - if (tHatch.canTankBeEmptied()){containsFluid=true;} - } - rList.add(new Pair<>(tHatch, containsFluid)); - } - } - if ((tFluids.length <= 0) || (slotInputCount > 1)){ - Logger.WARNING("Bad"); - return false; - } - - Logger.WARNING("Okay - 2"); - if (this.internalStorageTank == null){ - Logger.WARNING("Okay - 3"); - if ((rList.get(0).getKey().mFluid != null) && (rList.get(0).getKey().mFluid.amount > 0)){ - Logger.WARNING("Okay - 4"); - Logger.WARNING("Okay - 1"+" rList.get(0).getKey().mFluid.amount: "+rList.get(0).getKey().mFluid.amount */ +}*//* + + } + + private boolean setInternalTank(final String fluidName, final int amount){ + final FluidStack temp = FluidUtils.getFluidStack(fluidName, amount); + if (temp != null){ + if (this.internalStorageTank == null){ + this.internalStorageTank = temp; + Logger.WARNING(temp.getFluid().getName()+" Amount: "+temp.amount+"L"); + } + else{ + Logger.WARNING("Retained Fluid."); + Logger.WARNING(this.internalStorageTank.getFluid().getName()+" Amxount: "+this.internalStorageTank.amount+"L"); + } + this.markDirty(); + return true; + } + return false; + } + + @Override + public void onLeftclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + this.tryForceNBTUpdate(); + super.onLeftclick(aBaseMetaTileEntity, aPlayer); + } + + @Override + public boolean onWrenchRightClick(final byte aSide, final byte aWrenchingSide, final EntityPlayer aPlayer, final float aX, final float aY, final float aZ) { + this.tryForceNBTUpdate(); + return super.onWrenchRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); + } + + @Override + public void onRemoval() { + this.tryForceNBTUpdate(); + super.onRemoval(); + } + + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + if ((this.internalStorageTank != null) && this.internalStorageTank.amount >= this.maximumFluidStorage){ + if (this.internalStorageTank.amount > this.maximumFluidStorage){ + this.internalStorageTank.amount = this.maximumFluidStorage; + } + this.stopMachine(); + } + + if (this.mInternalSaveClock != 20){ + this.mInternalSaveClock++; + } + else { + this.mInternalSaveClock = 0; + this.tryForceNBTUpdate(); + } + + } + + public GregtechMetaTileEntity_MultiTank(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_MultiTank(this.mName); + } + + @Override + public String[] getTooltip() { + return new String[]{ + "Controller Block for the Multitank", + "Size: 3xHx3 (Block behind controller must be air)", + "Structure must be at least 4 blocks tall, maximum 20.", + "Each casing within the structure adds 128000L storage.", + "Multitank Exterior Casings (16 at least!)", + "Controller (front centered)", + "1x Input hatch", + "1x Output hatch", + "1x Energy Hatch", + }; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(11)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Screen_Logo : TexturesGtBlock.Overlay_Machine_Screen_Logo)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(11))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing > 1; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + + final ArrayList<ItemStack> tInputList = this.getStoredInputs(); + for (int i = 0; i < (tInputList.size() - 1); i++) { + for (int j = i + 1; j < tInputList.size(); j++) { + if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { + if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) { + tInputList.remove(j--); + } else { + tInputList.remove(i--); + break; + } + } + } + } + final ItemStack[] tInputs = Arrays.copyOfRange(tInputList.toArray(new ItemStack[tInputList.size()]), 0, 2); + + final ArrayList<FluidStack> tFluidList = this.getStoredFluids(); + for (int i = 0; i < (tFluidList.size() - 1); i++) { + for (int j = i + 1; j < tFluidList.size(); j++) { + if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { + if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { + tFluidList.remove(j--); + } else { + tFluidList.remove(i--); + break; + } + } + } + } + final FluidStack[] tFluids = Arrays.copyOfRange(tFluidList.toArray(new FluidStack[1]), 0, 1); + + if (tFluids.length >= 2){ + Logger.WARNING("Bad"); + return false; + } + + final ArrayList<Pair<GT_MetaTileEntity_Hatch_Input, Boolean>> rList = new ArrayList<>(); + int slotInputCount = 0; + for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { + boolean containsFluid = false; + if (isValidMetaTileEntity(tHatch)) { + slotInputCount++; + for (int i=0; i<tHatch.getBaseMetaTileEntity().getSizeInventory(); i++) { + if (tHatch.canTankBeEmptied()){containsFluid=true;} + } + rList.add(new Pair<>(tHatch, containsFluid)); + } + } + if ((tFluids.length <= 0) || (slotInputCount > 1)){ + Logger.WARNING("Bad"); + return false; + } + + Logger.WARNING("Okay - 2"); + if (this.internalStorageTank == null){ + Logger.WARNING("Okay - 3"); + if ((rList.get(0).getKey().mFluid != null) && (rList.get(0).getKey().mFluid.amount > 0)){ + Logger.WARNING("Okay - 4"); + Logger.WARNING("Okay - 1"+" rList.get(0).getKey().mFluid.amount: "+rList.get(0).getKey().mFluid.amount */ /*+" internalStorageTank:"+internalStorageTank.amount*//* -); - final FluidStack tempFluidStack = rList.get(0).getKey().mFluid; - final Fluid tempFluid = tempFluidStack.getFluid(); - this.internalStorageTank = FluidUtils.getFluidStack(tempFluid.getName(), tempFluidStack.amount); - rList.get(0).getKey().mFluid.amount = 0; - Logger.WARNING("Okay - 1.1"+" rList.get(0).getKey().mFluid.amount: "+rList.get(0).getKey().mFluid.amount +" internalStorageTank:"+this.internalStorageTank.amount); - return true; - } - Logger.WARNING("No Fluid in hatch."); - return false; - } - else if (this.internalStorageTank.isFluidEqual(rList.get(0).getKey().mFluid)){ - Logger.WARNING("Storing "+rList.get(0).getKey().mFluid.amount+"L"); - Logger.WARNING("Contains "+this.internalStorageTank.amount+"L"); - - - int tempAdd = 0; - tempAdd = rList.get(0).getKey().getFluidAmount(); - rList.get(0).getKey().mFluid = null; - Logger.WARNING("adding "+tempAdd); - this.internalStorageTank.amount = this.internalStorageTank.amount + tempAdd; - Logger.WARNING("Tank now Contains "+this.internalStorageTank.amount+"L of "+this.internalStorageTank.getFluid().getName()+"."); - - - //Utils.LOG_WARNING("Tank"); - return true; - } - else { - final FluidStack superTempFluidStack = rList.get(0).getKey().mFluid; - Logger.WARNING("is input fluid equal to stored fluid? "+(this.internalStorageTank.isFluidEqual(superTempFluidStack))); - if (superTempFluidStack != null) { - Logger.WARNING("Input hatch[0] Contains "+superTempFluidStack.amount+"L of "+superTempFluidStack.getFluid().getName()+"."); - } - Logger.WARNING("Large Multi-Tank Contains "+this.internalStorageTank.amount+"L of "+this.internalStorageTank.getFluid().getName()+"."); - - if (this.internalStorageTank.amount <= 0){ - Logger.WARNING("Internal Tank is empty, sitting idle."); - return false; - } - - if ((this.mOutputHatches.get(0).mFluid == null) || this.mOutputHatches.isEmpty() || (this.mOutputHatches.get(0).mFluid.isFluidEqual(this.internalStorageTank) && (this.mOutputHatches.get(0).mFluid.amount < this.mOutputHatches.get(0).getCapacity()))){ - Logger.WARNING("Okay - 3"); - final int tempCurrentStored = this.internalStorageTank.amount; - int tempResult = 0; - final int tempHatchSize = this.mOutputHatches.get(0).getCapacity(); - final int tempHatchCurrentHolding = this.mOutputHatches.get(0).getFluidAmount(); - final int tempHatchRemainingSpace = tempHatchSize - tempHatchCurrentHolding; - final FluidStack tempOutputFluid = this.internalStorageTank; - if (tempHatchRemainingSpace <= 0){ - return false; - } - Logger.WARNING("Okay - 3.1.x"+" hatchCapacity: "+tempHatchSize +" tempCurrentStored: "+tempCurrentStored+" output hatch holds: "+tempHatchCurrentHolding+" tank has "+tempHatchRemainingSpace+"L of space left."); - - if (tempHatchSize >= tempHatchRemainingSpace){ - Logger.WARNING("Okay - 3.1.1"+" hatchCapacity: "+tempHatchSize +" tempCurrentStored: "+tempCurrentStored+" output hatch holds: "+tempHatchCurrentHolding+" tank has "+tempHatchRemainingSpace+"L of space left."); - - int adder; - if ((tempCurrentStored > 0) && (tempCurrentStored <= tempHatchSize)){ - adder = tempCurrentStored; - if (adder >= tempHatchRemainingSpace){ - adder = tempHatchRemainingSpace; - } - } - else { - adder = 0; - if (tempCurrentStored >= tempHatchRemainingSpace){ - adder = tempHatchRemainingSpace; - } - } - - tempResult = adder; - tempOutputFluid.amount = tempResult; - Logger.WARNING("Okay - 3.1.2"+" result: "+tempResult +" tempCurrentStored: "+tempCurrentStored + " filling output hatch with: "+tempOutputFluid.amount+"L of "+tempOutputFluid.getFluid().getName()); - this.mOutputHatches.get(0).fill(tempOutputFluid, true); - //mOutputHatches.get(0).mFluid.amount = tempResult; - this.internalStorageTank.amount = (tempCurrentStored-adder); - Logger.WARNING("Okay - 3.1.3"+" internalTankStorage: "+this.internalStorageTank.amount +"L | output hatch contains: "+this.mOutputHatches.get(0).mFluid.amount+"L of "+this.mOutputHatches.get(0).mFluid.getFluid().getName()); - */ + ); + final FluidStack tempFluidStack = rList.get(0).getKey().mFluid; + final Fluid tempFluid = tempFluidStack.getFluid(); + this.internalStorageTank = FluidUtils.getFluidStack(tempFluid.getName(), tempFluidStack.amount); + rList.get(0).getKey().mFluid.amount = 0; + Logger.WARNING("Okay - 1.1"+" rList.get(0).getKey().mFluid.amount: "+rList.get(0).getKey().mFluid.amount +" internalStorageTank:"+this.internalStorageTank.amount); + return true; + } + Logger.WARNING("No Fluid in hatch."); + return false; + } + else if (this.internalStorageTank.isFluidEqual(rList.get(0).getKey().mFluid)){ + Logger.WARNING("Storing "+rList.get(0).getKey().mFluid.amount+"L"); + Logger.WARNING("Contains "+this.internalStorageTank.amount+"L"); + + + int tempAdd = 0; + tempAdd = rList.get(0).getKey().getFluidAmount(); + rList.get(0).getKey().mFluid = null; + Logger.WARNING("adding "+tempAdd); + this.internalStorageTank.amount = this.internalStorageTank.amount + tempAdd; + Logger.WARNING("Tank now Contains "+this.internalStorageTank.amount+"L of "+this.internalStorageTank.getFluid().getName()+"."); + + + //Utils.LOG_WARNING("Tank"); + return true; + } + else { + final FluidStack superTempFluidStack = rList.get(0).getKey().mFluid; + Logger.WARNING("is input fluid equal to stored fluid? "+(this.internalStorageTank.isFluidEqual(superTempFluidStack))); + if (superTempFluidStack != null) { + Logger.WARNING("Input hatch[0] Contains "+superTempFluidStack.amount+"L of "+superTempFluidStack.getFluid().getName()+"."); + } + Logger.WARNING("Large Multi-Tank Contains "+this.internalStorageTank.amount+"L of "+this.internalStorageTank.getFluid().getName()+"."); + + if (this.internalStorageTank.amount <= 0){ + Logger.WARNING("Internal Tank is empty, sitting idle."); + return false; + } + + if ((this.mOutputHatches.get(0).mFluid == null) || this.mOutputHatches.isEmpty() || (this.mOutputHatches.get(0).mFluid.isFluidEqual(this.internalStorageTank) && (this.mOutputHatches.get(0).mFluid.amount < this.mOutputHatches.get(0).getCapacity()))){ + Logger.WARNING("Okay - 3"); + final int tempCurrentStored = this.internalStorageTank.amount; + int tempResult = 0; + final int tempHatchSize = this.mOutputHatches.get(0).getCapacity(); + final int tempHatchCurrentHolding = this.mOutputHatches.get(0).getFluidAmount(); + final int tempHatchRemainingSpace = tempHatchSize - tempHatchCurrentHolding; + final FluidStack tempOutputFluid = this.internalStorageTank; + if (tempHatchRemainingSpace <= 0){ + return false; + } + Logger.WARNING("Okay - 3.1.x"+" hatchCapacity: "+tempHatchSize +" tempCurrentStored: "+tempCurrentStored+" output hatch holds: "+tempHatchCurrentHolding+" tank has "+tempHatchRemainingSpace+"L of space left."); + + if (tempHatchSize >= tempHatchRemainingSpace){ + Logger.WARNING("Okay - 3.1.1"+" hatchCapacity: "+tempHatchSize +" tempCurrentStored: "+tempCurrentStored+" output hatch holds: "+tempHatchCurrentHolding+" tank has "+tempHatchRemainingSpace+"L of space left."); + + int adder; + if ((tempCurrentStored > 0) && (tempCurrentStored <= tempHatchSize)){ + adder = tempCurrentStored; + if (adder >= tempHatchRemainingSpace){ + adder = tempHatchRemainingSpace; + } + } + else { + adder = 0; + if (tempCurrentStored >= tempHatchRemainingSpace){ + adder = tempHatchRemainingSpace; + } + } + + tempResult = adder; + tempOutputFluid.amount = tempResult; + Logger.WARNING("Okay - 3.1.2"+" result: "+tempResult +" tempCurrentStored: "+tempCurrentStored + " filling output hatch with: "+tempOutputFluid.amount+"L of "+tempOutputFluid.getFluid().getName()); + this.mOutputHatches.get(0).fill(tempOutputFluid, true); + //mOutputHatches.get(0).mFluid.amount = tempResult; + this.internalStorageTank.amount = (tempCurrentStored-adder); + Logger.WARNING("Okay - 3.1.3"+" internalTankStorage: "+this.internalStorageTank.amount +"L | output hatch contains: "+this.mOutputHatches.get(0).mFluid.amount+"L of "+this.mOutputHatches.get(0).mFluid.getFluid().getName()); + */ /*if (internalStorageTank.amount <= 0) - internalStorageTank = null;*//* - - } - Logger.WARNING("Tank ok."); - return true; - } - } - //this.getBaseMetaTileEntity().(tFluids[0].amount, true); - Logger.WARNING("Tank"); - return false; - } - - @Override - public int getMaxParallelRecipes() { - return 1; +internalStorageTank = null;*//* + + } + Logger.WARNING("Tank ok."); + return true; + } + } + //this.getBaseMetaTileEntity().(tFluids[0].amount, true); + Logger.WARNING("Tank"); + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { + Logger.WARNING("Must be hollow."); + return false; + } + int tAmount = 0; + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int h = -1; h < 19; h++) { + if ((h != 0) || ((((xDir + i) != 0) || ((zDir + j) != 0)) && ((i != 0) || (j != 0)))) { + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); + if ((!this.addMaintenanceToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addOutputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addEnergyInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11)))) { + if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != ModBlocks.blockCasingsMisc) { + if (h < 3){ + Logger.WARNING("Casing Expected."); + return false; + } + else if (h >= 3){ + //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); + } + } + if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j) != 11) { + if (h < 3){ + Logger.WARNING("Wrong Meta."); + return false; + } + else if (h >= 3){ + //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); + } + } + if (h < 3){ + tAmount++; + } + else if (h >= 3){ + if ((aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) == Blocks.air) || aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j).getUnlocalizedName().contains("residual")){ + Logger.WARNING("Found air"); + } + else { + Logger.WARNING("Layer "+(h+2)+" is complete. Adding "+(64000*9)+"L storage to the tank."); + tAmount++; + } + } + } + } + } + } + } + this.multiblockCasingCount = (short) tAmount; + this.maximumFluidStorage = getMaximumTankStorage(tAmount); + Logger.INFO("Your Multitank can be 20 blocks tall."); + Logger.INFO("Casings Count: "+this.multiblockCasingCount+" Valid Multiblock: "+(tAmount >= 16)+" Tank Storage Capacity:"+this.maximumFluidStorage+"L"); + this.tryForceNBTUpdate(); + return tAmount >= 16; + } + + */ +/*public int countCasings() { + Utils.LOG_INFO("Counting Machine Casings"); + try{ + if (this.getBaseMetaTileEntity().getWorld() == null){ + Utils.LOG_INFO("Tile Entity's world was null for casing count."); + return 0; } - - @Override - public int getEuDiscountForParallelism() { + if (this.getBaseMetaTileEntity() == null){ + Utils.LOG_INFO("Tile Entity was null for casing count."); return 0; } - - @Override - public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { - final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { - Logger.WARNING("Must be hollow."); - return false; - } - int tAmount = 0; - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - for (int h = -1; h < 19; h++) { - if ((h != 0) || ((((xDir + i) != 0) || ((zDir + j) != 0)) && ((i != 0) || (j != 0)))) { - final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); - if ((!this.addMaintenanceToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addOutputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addEnergyInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11)))) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != ModBlocks.blockCasingsMisc) { - if (h < 3){ - Logger.WARNING("Casing Expected."); - return false; - } - else if (h >= 3){ - //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); - } + } catch(NullPointerException r){ + Utils.LOG_INFO("Null Pointer Exception caught."); + return 0; + } + int xDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetZ; + if (!this.getBaseMetaTileEntity().getAirOffset(xDir, 0, zDir)) { + Utils.LOG_INFO("Failed due to air being misplaced."); + Utils.LOG_WARNING("Must be hollow."); + return 0; + } + int tAmount = 0; + Utils.LOG_INFO("Casing Count set to 0."); + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int h = -1; h < 19; h++) { + if ((h != 0) || (((xDir + i != 0) || (zDir + j != 0)) && ((i != 0) || (j != 0)))) { + IGregTechTileEntity tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityOffset(xDir + i, h, zDir + j); + if ((!addMaintenanceToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addOutputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addEnergyInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11)))) { + if (this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j) != ModBlocks.blockCasingsMisc) { + if (h < 3){ + Utils.LOG_WARNING("Casing Expected."); + return 0; } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j) != 11) { - if (h < 3){ - Logger.WARNING("Wrong Meta."); - return false; - } - else if (h >= 3){ - //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); - } + else if (h >= 3){ + //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); } + } + if (this.getBaseMetaTileEntity().getMetaIDOffset(xDir + i, h, zDir + j) != 11) { if (h < 3){ - tAmount++; + Utils.LOG_WARNING("Wrong Meta."); + return 0; } else if (h >= 3){ - if ((aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) == Blocks.air) || aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j).getUnlocalizedName().contains("residual")){ - Logger.WARNING("Found air"); - } - else { - Logger.WARNING("Layer "+(h+2)+" is complete. Adding "+(64000*9)+"L storage to the tank."); - tAmount++; - } + //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); } } - } - } - } - } - this.multiblockCasingCount = (short) tAmount; - this.maximumFluidStorage = getMaximumTankStorage(tAmount); - Logger.INFO("Your Multitank can be 20 blocks tall."); - Logger.INFO("Casings Count: "+this.multiblockCasingCount+" Valid Multiblock: "+(tAmount >= 16)+" Tank Storage Capacity:"+this.maximumFluidStorage+"L"); - this.tryForceNBTUpdate(); - return tAmount >= 16; - } - - */ -/*public int countCasings() { - Utils.LOG_INFO("Counting Machine Casings"); - try{ - if (this.getBaseMetaTileEntity().getWorld() == null){ - Utils.LOG_INFO("Tile Entity's world was null for casing count."); - return 0; - } - if (this.getBaseMetaTileEntity() == null){ - Utils.LOG_INFO("Tile Entity was null for casing count."); - return 0; - } - } catch(NullPointerException r){ - Utils.LOG_INFO("Null Pointer Exception caught."); - return 0; - } - int xDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetZ; - if (!this.getBaseMetaTileEntity().getAirOffset(xDir, 0, zDir)) { - Utils.LOG_INFO("Failed due to air being misplaced."); - Utils.LOG_WARNING("Must be hollow."); - return 0; - } - int tAmount = 0; - Utils.LOG_INFO("Casing Count set to 0."); - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - for (int h = -1; h < 19; h++) { - if ((h != 0) || (((xDir + i != 0) || (zDir + j != 0)) && ((i != 0) || (j != 0)))) { - IGregTechTileEntity tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityOffset(xDir + i, h, zDir + j); - if ((!addMaintenanceToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addOutputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addEnergyInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11)))) { - if (this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j) != ModBlocks.blockCasingsMisc) { - if (h < 3){ - Utils.LOG_WARNING("Casing Expected."); - return 0; - } - else if (h >= 3){ - //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); - } - } - if (this.getBaseMetaTileEntity().getMetaIDOffset(xDir + i, h, zDir + j) != 11) { - if (h < 3){ - Utils.LOG_WARNING("Wrong Meta."); - return 0; - } - else if (h >= 3){ - //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); - } + if (h < 3){ + tAmount++; + } + else if (h >= 3){ + if (this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j) == Blocks.air || this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j).getUnlocalizedName().contains("residual")){ + Utils.LOG_WARNING("Found air"); } - if (h < 3){ + else { + Utils.LOG_WARNING("Layer "+(h+2)+" is complete. Adding "+(64000*9)+"L storage to the tank."); tAmount++; } - else if (h >= 3){ - if (this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j) == Blocks.air || this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j).getUnlocalizedName().contains("residual")){ - Utils.LOG_WARNING("Found air"); - } - else { - Utils.LOG_WARNING("Layer "+(h+2)+" is complete. Adding "+(64000*9)+"L storage to the tank."); - tAmount++; - } - } } } } } } - Utils.LOG_INFO("Finished counting."); - multiblockCasingCount = (short) tAmount; - //Utils.LOG_INFO("Your Multitank can be 20 blocks tall."); - Utils.LOG_INFO("Casings Count: "+tAmount+" Valid Multiblock: "+(tAmount >= 16)+" Tank Storage Capacity:"+getMaximumTankStorage(tAmount)+"L"); - return tAmount; - }*//* - - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerTick(final ItemStack aStack) { - return 5; } - - @Override - public int getAmountOfOutputs() { - return 1; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { + Utils.LOG_INFO("Finished counting."); + multiblockCasingCount = (short) tAmount; + //Utils.LOG_INFO("Your Multitank can be 20 blocks tall."); + Utils.LOG_INFO("Casings Count: "+tAmount+" Valid Multiblock: "+(tAmount >= 16)+" Tank Storage Capacity:"+getMaximumTankStorage(tAmount)+"L"); + return tAmount; +}*//* + + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 5; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private static short getStorageMultiplier(final int casingCount){ + final int tsm = 1*casingCount; + if (tsm <= 0){ + return 1; + } + return (short) tsm; + } + + private static int getMaximumTankStorage(final int casingCount){ + final int multiplier = getStorageMultiplier(casingCount); + final int tempTankStorageMax = 128000*multiplier; + if (tempTankStorageMax <= 0){return 128000;} + return tempTankStorageMax; + } + + private boolean tryForceNBTUpdate(){ + */ +/* +//Block is invalid. +if ((this == null) || (this.getBaseMetaTileEntity() == null)){ + Utils.LOG_WARNING("Block was not valid for saving data."); + return false; +} + +//Don't need this to run clientside. +if (!this.getBaseMetaTileEntity().isServerSide()) { + return false; +} + +//Internal Tag was not valid. +try{ + if (this.internalCraftingComponentsTag == null){ + Utils.LOG_WARNING("Internal NBT data tag was null."); return false; } +} catch (final NullPointerException x){ + Utils.LOG_WARNING("Caught null NBT."); +} - private static short getStorageMultiplier(final int casingCount){ - final int tsm = 1*casingCount; - if (tsm <= 0){ - return 1; - } - return (short) tsm; - } - - private static int getMaximumTankStorage(final int casingCount){ - final int multiplier = getStorageMultiplier(casingCount); - final int tempTankStorageMax = 128000*multiplier; - if (tempTankStorageMax <= 0){return 128000;} - return tempTankStorageMax; - } - - private boolean tryForceNBTUpdate(){ -*/ -/* - //Block is invalid. - if ((this == null) || (this.getBaseMetaTileEntity() == null)){ - Utils.LOG_WARNING("Block was not valid for saving data."); - return false; - } - - //Don't need this to run clientside. - if (!this.getBaseMetaTileEntity().isServerSide()) { - return false; - } - - //Internal Tag was not valid. - try{ - if (this.internalCraftingComponentsTag == null){ - Utils.LOG_WARNING("Internal NBT data tag was null."); - return false; - } - } catch (final NullPointerException x){ - Utils.LOG_WARNING("Caught null NBT."); - } +//Internal tag was valid. +this.saveNBTData(this.internalCraftingComponentsTag); - //Internal tag was valid. - this.saveNBTData(this.internalCraftingComponentsTag); +//Mark block for update +int x,y,z = 0; +x = this.getBaseMetaTileEntity().getXCoord(); +y = this.getBaseMetaTileEntity().getYCoord(); +z = this.getBaseMetaTileEntity().getZCoord(); +this.getBaseMetaTileEntity().getWorld().markBlockForUpdate(x, y, z); - //Mark block for update - int x,y,z = 0; - x = this.getBaseMetaTileEntity().getXCoord(); - y = this.getBaseMetaTileEntity().getYCoord(); - z = this.getBaseMetaTileEntity().getZCoord(); - this.getBaseMetaTileEntity().getWorld().markBlockForUpdate(x, y, z); +//Mark block dirty, let chunk know it's data has changed and it must be saved to disk. (Albeit slowly) +this.getBaseMetaTileEntity().markDirty();*//* - //Mark block dirty, let chunk know it's data has changed and it must be saved to disk. (Albeit slowly) - this.getBaseMetaTileEntity().markDirty();*//* - - return true; - } -}*/ + return true; + } + }*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 57f0b83100..3f62a67101 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -1,6 +1,13 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.storage; -import java.util.function.Consumer; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static gregtech.api.enums.GT_HatchElement.Dynamo; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTEnergy; import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -31,6 +38,7 @@ import gtPlusPlus.preloader.asm.AsmConfig; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_PowerSubStation; import gtPlusPlus.xmod.gregtech.api.gui.GUI_PowerSubStation; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import java.util.function.Consumer; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -42,750 +50,767 @@ import net.minecraft.util.IChatComponent; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants.NBT; - -import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; -import static gregtech.api.enums.GT_HatchElement.Dynamo; -import static gregtech.api.enums.GT_HatchElement.Energy; -import static gregtech.api.enums.GT_HatchElement.Maintenance; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; -import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; -import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTEnergy; - -public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_PowerSubStationController> implements ISurvivalConstructable { - - private static enum TopState { - MayBeTop, - Top, - NotTop - } - protected long mAverageEuUsage = 0; - protected final MovingAverageLong mAverageEuAdded = new MovingAverageLong(20); - protected final MovingAverageLong mAverageEuConsumed = new MovingAverageLong(20); - protected long mTotalEnergyAdded = 0; - protected long mTotalEnergyConsumed = 0; - protected long mTotalEnergyLost = 0; - protected boolean mIsOutputtingPower = false; - protected long mBatteryCapacity = 0; - - private final int ENERGY_TAX = 5; - - private int mCasing; - private int[] cellCount = new int[6]; - private TopState topState = TopState.MayBeTop; - private static IStructureDefinition<GregtechMetaTileEntity_PowerSubStationController> STRUCTURE_DEFINITION = null; - - public GregtechMetaTileEntity_PowerSubStationController(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_PowerSubStationController(final String aName) { - super(aName); - } - - @Override - public String getMachineType() { - return "Energy Buffer"; - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType(getMachineType()) - .addInfo("Consumes " + this.ENERGY_TAX + "% of the average voltage of all energy type hatches") - .addInfo("Does not require maintenance") - .addInfo("Can be built with variable height between " + (CELL_HEIGHT_MIN + 2) + "-" + (CELL_HEIGHT_MAX + 2) + "") - .addInfo("Hatches can be placed nearly anywhere") - .addInfo("HV Energy/Dynamo Hatches are the lowest tier you can use") - .addInfo("Supports voltages >= UHV using MAX tier components.") - .addSeparator() - .addController("Bottom Center") - .addCasingInfo("Sub-Station External Casings", 10) - .addDynamoHatch("Any Casing", 1) - .addEnergyHatch("Any Casing", 1) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(24)), - new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER)}; - } - if (aSide == this.getBaseMetaTileEntity().getBackFacing()) { - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(24)), - mIsOutputtingPower ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[(int) this.getOutputTier()] : Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[(int) this.getInputTier()]}; - } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(23))}; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - //if (mBatteryCapacity <= 0) return false; - if (!aBaseMetaTileEntity.isClientSide()) { - aBaseMetaTileEntity.openGUI(aPlayer); - } - return true; - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_PowerSubStation(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "Ergon Energy - Sub Station"); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_PowerSubStation(aPlayerInventory, aBaseMetaTileEntity); - } - - private void checkMachineProblem(String msg, int xOff, int yOff, int zOff) { - final IGregTechTileEntity te = this.getBaseMetaTileEntity(); - final Block tBlock = te.getBlockOffset(xOff, yOff, zOff); - final byte tMeta = te.getMetaIDOffset(xOff, yOff, zOff); - String name = tBlock.getLocalizedName(); - String problem = msg + ": (" + xOff + ", " + yOff + ", " + zOff + ") " + name + ":" + tMeta; - checkMachineProblem(problem); - } - private void checkMachineProblem(String msg) { - if (!AsmConfig.disableAllLogging) { - Logger.INFO("Power Sub-Station problem: " + msg); - } - } - - public static int getCellTier(Block aBlock, int aMeta) { - if (aBlock == ModBlocks.blockCasings2Misc && aMeta == 7) { - return 4; - } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 4) { - return 5; - } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 5) { - return 6; - } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 6) { - return 7; - } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 7) { - return 8; - } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 8) { - return 9; - } else { - return -1; - } - } - - public static int getMetaFromTier(int tier) { - if (tier == 4) return 7; - if (tier >= 5 && tier <= 9) return tier - 1; - return 0; - } - - public static Block getBlockFromTier(int tier) { - switch (tier) { - case 4: return ModBlocks.blockCasings2Misc; - case 5: case 6: case 7: case 8: case 9: return ModBlocks.blockCasings3Misc; - default: return null; - } - } - - public static int getMaxHatchTier(int aCellTier) { - switch(aCellTier) { - case 9: - return GT_Values.VOLTAGE_NAMES[9].equals("Ultimate High Voltage") ? 15 : 9; - default: - if (aCellTier < 4) { - return 0; - } - else { - return aCellTier; - } - } - } - - public static final int CELL_HEIGHT_MAX = 16; - public static final int CELL_HEIGHT_MIN = 2; - - @Override - public IStructureDefinition<GregtechMetaTileEntity_PowerSubStationController> getStructureDefinition() { - if (STRUCTURE_DEFINITION == null) { - STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_PowerSubStationController>builder() - .addShape(mName + "bottom", transpose(new String[][]{ - {"CC~CC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"} - })) - .addShape(mName + "layer", transpose(new String[][]{ - {"CCCCC", "CIIIC", "CIIIC", "CIIIC", "CCCCC"} - })) - .addShape(mName + "mid", transpose(new String[][]{ - {"CCCCC", "CHHHC", "CHHHC", "CHHHC", "CCCCC"} - })) - .addShape(mName + "top", transpose(new String[][]{ - {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"} - })) - .addElement( - 'C', - buildHatchAdder(GregtechMetaTileEntity_PowerSubStationController.class) - .atLeast(Energy.or(TTEnergy), Dynamo.or(TTDynamo), Maintenance) - .casingIndex(TAE.GTPP_INDEX(24)) - .dot(1) - .buildAndChain( - onElementPass( - x -> ++x.mCasing, - ofBlock( - ModBlocks.blockCasings2Misc, 8 - ) - ) - ) - ) - .addElement( - 'I', - ofChain( - onlyIf( - x -> x.topState != TopState.NotTop, - onElementPass( - x -> x.topState = TopState.Top, - ofHatchAdderOptional(GregtechMetaTileEntity_PowerSubStationController::addPowerSubStationList, TAE.GTPP_INDEX(24), 1, ModBlocks.blockCasings2Misc, 8) - ) - ), - onlyIf( - x -> x.topState != TopState.Top, - onElementPass( - x -> x.topState = TopState.NotTop, - ofChain( - onElementPass( - x -> ++x.cellCount[0], - ofCell(4) - ), - onElementPass( - x -> ++x.cellCount[1], - ofCell(5) - ), - onElementPass( - x -> ++x.cellCount[2], - ofCell(6) - ), - onElementPass( - x -> ++x.cellCount[3], - ofCell(7) - ), - onElementPass( - x -> ++x.cellCount[4], - ofCell(8) - ), - onElementPass( - x -> ++x.cellCount[5], - ofCell(9) - ) - ) - ) - ) - ) - ) - .addElement('H', ofCell(4)) - .build(); - } - return STRUCTURE_DEFINITION; - } - - public static <T> IStructureElement<T> ofCell(int aIndex) { - return new IStructureElement<T>() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - int tier = getCellTier(block, meta); - return aIndex == tier; - } - - public int getIndex(int size) { - if (size > 6) size = 6; - return size + 3; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, getBlockFromTier(getIndex(trigger.stackSize)), getMetaFromTier(getIndex(trigger.stackSize))); - return true; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return world.setBlock(x, y, z, getBlockFromTier(getIndex(trigger.stackSize)), getMetaFromTier(getIndex(trigger.stackSize)), 3); - } - - @Override - public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, IItemSource s, EntityPlayerMP actor, Consumer<IChatComponent> chatter) { - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - int tier = getCellTier(block, meta); - if (tier >= 0) return PlaceResult.SKIP; - return StructureUtility.survivalPlaceBlock(getBlockFromTier(getIndex(trigger.stackSize)), getMetaFromTier(getIndex(trigger.stackSize)), world, x, y, z, s, actor, chatter); - } - }; - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - int layer = Math.min(stackSize.stackSize + 3, 18); - log("Layer: "+layer); - log("Building 0"); - buildPiece(mName + "bottom" , stackSize, hintsOnly, 2, 0, 0); - log("Built 0"); - for (int i = 1; i < layer - 1; i++) { - log("Building "+i); - buildPiece(mName + "mid", stackSize, hintsOnly, 2, i, 0); - log("Built "+i); - } - log("Building "+(layer - 1)); - buildPiece(mName + "top", stackSize, hintsOnly, 2, layer - 1, 0); - log("Built "+(layer - 1)); - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { - if (mMachine) return -1; - int layer = Math.min(stackSize.stackSize + 3, 18); - int built; - built = survivialBuildPiece(mName + "bottom", stackSize, 2, 0, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - for (int i = 1; i < layer - 1; i++) { - built = survivialBuildPiece(mName + "mid", stackSize, 2, i, 0, elementBudget, source, actor, false, true); - if (built >= 0) return built; - } - return survivialBuildPiece(mName + "top", stackSize, 2, layer - 1, 0, elementBudget, source, actor, false, true); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - mCasing = 0; - mEnergyHatches.clear(); - mDynamoHatches.clear(); - mTecTechEnergyHatches.clear(); - mTecTechDynamoHatches.clear(); - mAllEnergyHatches.clear(); - mAllDynamoHatches.clear(); - for (int i = 0; i < 6; i++) { - cellCount[i] = 0; - } - log("Checking 0"); - if (!checkPiece(mName + "bottom", 2, 0, 0)) { - log("Failed on Layer 0"); - return false; - } - log("Pass 0"); - int layer = 1; - topState = TopState.MayBeTop; - while (true) { - if (!checkPiece(mName + "layer", 2, layer, 0)) - return false; - layer ++; - if (topState == TopState.Top) - break; // top found, break out - topState = TopState.MayBeTop; - if (layer > 18) - return false; // too many layers - } - int level = 0; - for (int i = 0; i < 6; i++) { - if (cellCount[i] != 0) { - if (level == 0) { - level = i + 4; - } - else { - return false; - } - } - } - int tier = getMaxHatchTier(level); - long volSum = 0; - for (GT_MetaTileEntity_Hatch hatch : mAllDynamoHatches) { - if (hatch.mTier > tier || hatch.mTier < 3) { - return false; - } - volSum += (8L << (hatch.mTier * 2)); - } - for (GT_MetaTileEntity_Hatch hatch : mAllEnergyHatches) { - if (hatch.mTier > tier || hatch.mTier < 3) { - return false; - } - volSum += (8L << (hatch.mTier * 2)); - } - mBatteryCapacity = getCapacityFromCellTier(level) * cellCount[level - 4]; - if (mAllEnergyHatches.size() + mAllDynamoHatches.size() > 0) { - mAverageEuUsage = volSum / (mAllEnergyHatches.size() + mAllDynamoHatches.size()); - } - else mAverageEuUsage = 0; - fixAllMaintenanceIssue(); - return true; - } - - public final boolean addPowerSubStationList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - else if (LoadedMods.TecTech) { - if (isThisHatchMultiDynamo(aMetaTileEntity)) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } else if (isThisHatchMultiEnergy(aMetaTileEntity)) { - return addToMachineList(aTileEntity, aBaseCasingIndex); - } - } - } - return false; - } - - // Define storage capacity of smallest cell tier (EV) and compute higher tiers from it - private static final long CELL_TIER_EV_CAPACITY = 100 * 1000 * 1000; - private static final long CELL_TIER_MULTIPLIER = 4; // each tier's capacity is this many times the previous tier - - public static long getCapacityFromCellTier(int aOverallCellTier) { - // Use integer math instead of `Math.pow` to avoid range/precision errors - if (aOverallCellTier < 4) return 0; - aOverallCellTier -= 4; - long capacity = CELL_TIER_EV_CAPACITY; - while (aOverallCellTier > 0) { - capacity *= CELL_TIER_MULTIPLIER; - aOverallCellTier--; - } - return capacity; - } - - @Override - public int getMaxEfficiency(final ItemStack aStack) { - return 10000; - } - - @Override - public boolean explodesOnComponentBreak(final ItemStack aStack) { - return false; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_PowerSubStationController(this.mName); - } - - //mTotalEnergyAdded - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setLong("mAverageEuUsage", this.mAverageEuUsage); - this.mAverageEuAdded.write(aNBT, "mAverageEuAdded"); - this.mAverageEuConsumed.write(aNBT, "mAverageEuConsumed"); - - //Usage Stats - aNBT.setLong("mTotalEnergyAdded", this.mTotalEnergyAdded); - aNBT.setLong("mTotalEnergyLost", this.mTotalEnergyLost); - aNBT.setLong("mTotalEnergyConsumed", this.mTotalEnergyConsumed); - aNBT.setLong("mTotalRunTime", this.mTotalRunTime); - aNBT.setBoolean("mIsOutputtingPower", this.mIsOutputtingPower); - aNBT.setLong("mBatteryCapacity", this.mBatteryCapacity); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - - // Best not to get a long if the Tag Map is holding an int - if (aNBT.hasKey("mAverageEuUsage")) { - this.mAverageEuUsage = aNBT.getLong("mAverageEuUsage"); - } - switch (aNBT.func_150299_b("mAverageEuAdded")) { - case NBT.TAG_BYTE_ARRAY: - this.mAverageEuAdded.read(aNBT, "mAverageEuAdded"); - break; - case NBT.TAG_LONG: - this.mAverageEuAdded.set(aNBT.getLong("mAverageEuAdded")); - break; - } - switch (aNBT.func_150299_b("mAverageEuConsumed")) { - case NBT.TAG_BYTE_ARRAY: - this.mAverageEuConsumed.read(aNBT, "mAverageEuConsumed"); - break; - case NBT.TAG_LONG: - this.mAverageEuConsumed.set(aNBT.getLong("mAverageEuConsumed")); - break; - } - - //Usage Stats - this.mTotalEnergyAdded = aNBT.getLong("mTotalEnergyAdded"); - this.mTotalEnergyLost = aNBT.getLong("mTotalEnergyLost"); - this.mTotalEnergyConsumed = aNBT.getLong("mTotalEnergyConsumed"); - this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); - - this.mIsOutputtingPower = aNBT.getBoolean("mIsOutputtingPower"); - - this.mBatteryCapacity = aNBT.getLong("mBatteryCapacity"); - - super.loadNBTData(aNBT); - } - - @Override - public boolean checkRecipe(final ItemStack aStack) { - this.mProgresstime = 0; - this.mMaxProgresstime = 200; - this.mEUt = 0; - this.mEfficiencyIncrease = 10000; - this.fixAllMaintenanceIssue(); - return true; - } - - @Override - public int getMaxParallelRecipes() { - return 1; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - private long drawEnergyFromHatch(MetaTileEntity aHatch) { - if (!isValidMetaTileEntity(aHatch)) { - return 0; - } - - long stored = aHatch.getEUVar(); - long voltage = aHatch.maxEUInput() * aHatch.maxAmperesIn(); - - if (voltage > stored) { - return 0; - } - - if (this.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false)) { - aHatch.setEUVar((stored - voltage)); - this.mTotalEnergyAdded += voltage; - return voltage; - } - return 0; - } - - private long addEnergyToHatch(MetaTileEntity aHatch) { - if (!isValidMetaTileEntity(aHatch)) { - return 0; - } - - long voltage = aHatch.maxEUOutput() * aHatch.maxAmperesOut(); - - if (aHatch.getEUVar() > aHatch.maxEUStore() - voltage) { - return 0; - } - - if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(voltage, false)) { - aHatch.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false); - this.mTotalEnergyConsumed+=voltage; - return voltage; - } - return 0; - } - - private long computeEnergyTax() { - float mTax = mAverageEuUsage * (ENERGY_TAX / 100f); - - // Increase tax up to 2x if machine is not fully repaired - mTax = mTax * (1f + (10000f - mEfficiency) / 10000f); - - return MathUtils.roundToClosestLong(mTax); - } - - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - this.fixAllMaintenanceIssue(); - } - - @Override - public boolean onRunningTick(ItemStack aStack) { - // First, decay overcharge (1% of stored energy plus 1000 EU per tick) - if (this.getEUVar() > this.mBatteryCapacity) { - long energy = (long) (this.getEUVar() * 0.990f) - 1000; - this.setEUVar(energy); - } - - // Pay Tax - long mDecrease = computeEnergyTax(); - this.mTotalEnergyLost += Math.min(mDecrease, this.getEUVar()); - this.setEUVar(Math.max(0, this.getEUVar() - mDecrease)); - - long aInputAverage = 0; - long aOutputAverage = 0; - // Input Power - for (GT_MetaTileEntity_Hatch THatch : this.mDischargeHatches) { - aInputAverage += drawEnergyFromHatch(THatch); - } - for (GT_MetaTileEntity_Hatch tHatch : this.mAllEnergyHatches) { - aInputAverage += drawEnergyFromHatch(tHatch); - } - - // Output Power - for (GT_MetaTileEntity_Hatch THatch : this.mChargeHatches) { - aOutputAverage += addEnergyToHatch(THatch); - } - for (GT_MetaTileEntity_Hatch tHatch : this.mAllDynamoHatches) { - aOutputAverage += addEnergyToHatch(tHatch); - } - // reset progress time - mProgresstime = 0; - - this.mAverageEuAdded.sample(aInputAverage); - this.mAverageEuConsumed.sample(aOutputAverage); - - return true; - - } - - @Override - public boolean drainEnergyInput(long aEU) { - // Not applicable to this machine - return true; - } - - @Override - public boolean addEnergyOutput(long aEU) { - // Not applicable to this machine - return true; - } - - @Override - public long maxEUStore() { - return mBatteryCapacity; - } - - @Override - public long getMinimumStoredEU() { - return 0; - } - - @Override - public String[] getExtraInfoData() { - String mode; - if (mIsOutputtingPower) { - mode = EnumChatFormatting.GOLD + "Output" + EnumChatFormatting.RESET; - } else { - mode = EnumChatFormatting.BLUE + "Input" + EnumChatFormatting.RESET; - } - - String storedEnergyText; - if (this.getEUVar() > this.mBatteryCapacity) { - storedEnergyText = EnumChatFormatting.RED + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; - } else { - storedEnergyText = EnumChatFormatting.GREEN + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; - } - - int errorCode = this.getBaseMetaTileEntity().getErrorDisplayID(); - boolean mMaint = (errorCode != 0); - - return new String[]{ - "Ergon Energy - District Sub-Station", - "Stored EU: " + storedEnergyText, - "Capacity: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.maxEUStore()) + EnumChatFormatting.RESET, - "Running Costs: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(this.computeEnergyTax()) + EnumChatFormatting.RESET + " EU/t", - "Controller Mode: " + mode, - "Requires Maintenance: " + (!mMaint ? EnumChatFormatting.GREEN : EnumChatFormatting.RED)+ mMaint + EnumChatFormatting.RESET +" | Code: ["+(!mMaint ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + errorCode + EnumChatFormatting.RESET +"]", - "----------------------", - "Stats for Nerds", - "Average Input: " + EnumChatFormatting.BLUE + this.mAverageEuAdded + EnumChatFormatting.RESET + " EU", - "Average Output: " + EnumChatFormatting.GOLD + this.mAverageEuConsumed + EnumChatFormatting.RESET + " EU", - "Total Input: " + EnumChatFormatting.BLUE + GT_Utility.formatNumbers(this.mTotalEnergyAdded) + EnumChatFormatting.RESET + " EU", - "Total Output: " + EnumChatFormatting.GOLD + GT_Utility.formatNumbers(this.mTotalEnergyConsumed) + EnumChatFormatting.RESET + " EU", - "Total Costs: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(this.mTotalEnergyLost) + EnumChatFormatting.RESET + " EU", - }; - } - - @Override - public void explodeMultiblock() { - // TODO Auto-generated method stub - super.explodeMultiblock(); - } - - @Override - public void doExplosion(long aExplosionPower) { - // TODO Auto-generated method stub - super.doExplosion(aExplosionPower); - } - - @Override - public long getMaxInputVoltage() { - return 32768; - } - - @Override - public boolean isElectric() { - return true; - } - - @Override - public boolean isEnetInput() { - return !mIsOutputtingPower; - } - - @Override - public boolean isEnetOutput() { - return mIsOutputtingPower; - } - - @Override - public boolean isInputFacing(byte aSide) { - return (aSide == this.getBaseMetaTileEntity().getBackFacing() && !mIsOutputtingPower); - } - - @Override - public boolean isOutputFacing(byte aSide) { - return (aSide == this.getBaseMetaTileEntity().getBackFacing() && mIsOutputtingPower); - } - - @Override - public long maxAmperesIn() { - return 32; - } - - @Override - public long maxAmperesOut() { - return 32; - } - - @Override - public long maxEUInput() { - return 32768; - } - - @Override - public long maxEUOutput() { - return 32768; - } - - public final long getAverageEuAdded() { - return this.mAverageEuAdded.get(); - } - - public final long getAverageEuConsumed() { - return this.mAverageEuConsumed.get(); - } - - @Override - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - mIsOutputtingPower = Utils.invertBoolean(mIsOutputtingPower); - if (mIsOutputtingPower) { - PlayerUtils.messagePlayer(aPlayer, "Sub-Station is now outputting power from the controller."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Sub-Station is now inputting power into the controller."); - } - } - -}
\ No newline at end of file +public class GregtechMetaTileEntity_PowerSubStationController + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_PowerSubStationController> + implements ISurvivalConstructable { + + private static enum TopState { + MayBeTop, + Top, + NotTop + } + + protected long mAverageEuUsage = 0; + protected final MovingAverageLong mAverageEuAdded = new MovingAverageLong(20); + protected final MovingAverageLong mAverageEuConsumed = new MovingAverageLong(20); + protected long mTotalEnergyAdded = 0; + protected long mTotalEnergyConsumed = 0; + protected long mTotalEnergyLost = 0; + protected boolean mIsOutputtingPower = false; + protected long mBatteryCapacity = 0; + + private final int ENERGY_TAX = 5; + + private int mCasing; + private int[] cellCount = new int[6]; + private TopState topState = TopState.MayBeTop; + private static IStructureDefinition<GregtechMetaTileEntity_PowerSubStationController> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_PowerSubStationController( + final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_PowerSubStationController(final String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Energy Buffer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Consumes " + this.ENERGY_TAX + "% of the average voltage of all energy type hatches") + .addInfo("Does not require maintenance") + .addInfo("Can be built with variable height between " + (CELL_HEIGHT_MIN + 2) + "-" + + (CELL_HEIGHT_MAX + 2) + "") + .addInfo("Hatches can be placed nearly anywhere") + .addInfo("HV Energy/Dynamo Hatches are the lowest tier you can use") + .addInfo("Supports voltages >= UHV using MAX tier components.") + .addSeparator() + .addController("Bottom Center") + .addCasingInfo("Sub-Station External Casings", 10) + .addDynamoHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(24)), + new GT_RenderedTexture( + aActive + ? Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE + : Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER) + }; + } + if (aSide == this.getBaseMetaTileEntity().getBackFacing()) { + return new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(24)), + mIsOutputtingPower + ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[(int) this.getOutputTier()] + : Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[(int) this.getInputTier()] + }; + } + return new ITexture[] {Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(23))}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + // if (mBatteryCapacity <= 0) return false; + if (!aBaseMetaTileEntity.isClientSide()) { + aBaseMetaTileEntity.openGUI(aPlayer); + } + return true; + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_PowerSubStation( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "Ergon Energy - Sub Station"); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_PowerSubStation(aPlayerInventory, aBaseMetaTileEntity); + } + + private void checkMachineProblem(String msg, int xOff, int yOff, int zOff) { + final IGregTechTileEntity te = this.getBaseMetaTileEntity(); + final Block tBlock = te.getBlockOffset(xOff, yOff, zOff); + final byte tMeta = te.getMetaIDOffset(xOff, yOff, zOff); + String name = tBlock.getLocalizedName(); + String problem = msg + ": (" + xOff + ", " + yOff + ", " + zOff + ") " + name + ":" + tMeta; + checkMachineProblem(problem); + } + + private void checkMachineProblem(String msg) { + if (!AsmConfig.disableAllLogging) { + Logger.INFO("Power Sub-Station problem: " + msg); + } + } + + public static int getCellTier(Block aBlock, int aMeta) { + if (aBlock == ModBlocks.blockCasings2Misc && aMeta == 7) { + return 4; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 4) { + return 5; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 5) { + return 6; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 6) { + return 7; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 7) { + return 8; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 8) { + return 9; + } else { + return -1; + } + } + + public static int getMetaFromTier(int tier) { + if (tier == 4) return 7; + if (tier >= 5 && tier <= 9) return tier - 1; + return 0; + } + + public static Block getBlockFromTier(int tier) { + switch (tier) { + case 4: + return ModBlocks.blockCasings2Misc; + case 5: + case 6: + case 7: + case 8: + case 9: + return ModBlocks.blockCasings3Misc; + default: + return null; + } + } + + public static int getMaxHatchTier(int aCellTier) { + switch (aCellTier) { + case 9: + return GT_Values.VOLTAGE_NAMES[9].equals("Ultimate High Voltage") ? 15 : 9; + default: + if (aCellTier < 4) { + return 0; + } else { + return aCellTier; + } + } + } + + public static final int CELL_HEIGHT_MAX = 16; + public static final int CELL_HEIGHT_MIN = 2; + + @Override + public IStructureDefinition<GregtechMetaTileEntity_PowerSubStationController> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_PowerSubStationController>builder() + .addShape( + mName + "bottom", transpose(new String[][] {{"CC~CC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}})) + .addShape( + mName + "layer", transpose(new String[][] {{"CCCCC", "CIIIC", "CIIIC", "CIIIC", "CCCCC"}})) + .addShape(mName + "mid", transpose(new String[][] {{"CCCCC", "CHHHC", "CHHHC", "CHHHC", "CCCCC"}})) + .addShape(mName + "top", transpose(new String[][] {{"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}})) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_PowerSubStationController.class) + .atLeast(Energy.or(TTEnergy), Dynamo.or(TTDynamo), Maintenance) + .casingIndex(TAE.GTPP_INDEX(24)) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 8)))) + .addElement( + 'I', + ofChain( + onlyIf( + x -> x.topState != TopState.NotTop, + onElementPass( + x -> x.topState = TopState.Top, + ofHatchAdderOptional( + GregtechMetaTileEntity_PowerSubStationController + ::addPowerSubStationList, + TAE.GTPP_INDEX(24), + 1, + ModBlocks.blockCasings2Misc, + 8))), + onlyIf( + x -> x.topState != TopState.Top, + onElementPass( + x -> x.topState = TopState.NotTop, + ofChain( + onElementPass(x -> ++x.cellCount[0], ofCell(4)), + onElementPass(x -> ++x.cellCount[1], ofCell(5)), + onElementPass(x -> ++x.cellCount[2], ofCell(6)), + onElementPass(x -> ++x.cellCount[3], ofCell(7)), + onElementPass(x -> ++x.cellCount[4], ofCell(8)), + onElementPass(x -> ++x.cellCount[5], ofCell(9))))))) + .addElement('H', ofCell(4)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public static <T> IStructureElement<T> ofCell(int aIndex) { + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + int tier = getCellTier(block, meta); + return aIndex == tier; + } + + public int getIndex(int size) { + if (size > 6) size = 6; + return size + 3; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle( + world, + x, + y, + z, + getBlockFromTier(getIndex(trigger.stackSize)), + getMetaFromTier(getIndex(trigger.stackSize))); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock( + x, + y, + z, + getBlockFromTier(getIndex(trigger.stackSize)), + getMetaFromTier(getIndex(trigger.stackSize)), + 3); + } + + @Override + public PlaceResult survivalPlaceBlock( + T t, + World world, + int x, + int y, + int z, + ItemStack trigger, + IItemSource s, + EntityPlayerMP actor, + Consumer<IChatComponent> chatter) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + int tier = getCellTier(block, meta); + if (tier >= 0) return PlaceResult.SKIP; + return StructureUtility.survivalPlaceBlock( + getBlockFromTier(getIndex(trigger.stackSize)), + getMetaFromTier(getIndex(trigger.stackSize)), + world, + x, + y, + z, + s, + actor, + chatter); + } + }; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + int layer = Math.min(stackSize.stackSize + 3, 18); + log("Layer: " + layer); + log("Building 0"); + buildPiece(mName + "bottom", stackSize, hintsOnly, 2, 0, 0); + log("Built 0"); + for (int i = 1; i < layer - 1; i++) { + log("Building " + i); + buildPiece(mName + "mid", stackSize, hintsOnly, 2, i, 0); + log("Built " + i); + } + log("Building " + (layer - 1)); + buildPiece(mName + "top", stackSize, hintsOnly, 2, layer - 1, 0); + log("Built " + (layer - 1)); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) { + if (mMachine) return -1; + int layer = Math.min(stackSize.stackSize + 3, 18); + int built; + built = survivialBuildPiece(mName + "bottom", stackSize, 2, 0, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + for (int i = 1; i < layer - 1; i++) { + built = survivialBuildPiece(mName + "mid", stackSize, 2, i, 0, elementBudget, source, actor, false, true); + if (built >= 0) return built; + } + return survivialBuildPiece( + mName + "top", stackSize, 2, layer - 1, 0, elementBudget, source, actor, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mEnergyHatches.clear(); + mDynamoHatches.clear(); + mTecTechEnergyHatches.clear(); + mTecTechDynamoHatches.clear(); + mAllEnergyHatches.clear(); + mAllDynamoHatches.clear(); + for (int i = 0; i < 6; i++) { + cellCount[i] = 0; + } + log("Checking 0"); + if (!checkPiece(mName + "bottom", 2, 0, 0)) { + log("Failed on Layer 0"); + return false; + } + log("Pass 0"); + int layer = 1; + topState = TopState.MayBeTop; + while (true) { + if (!checkPiece(mName + "layer", 2, layer, 0)) return false; + layer++; + if (topState == TopState.Top) break; // top found, break out + topState = TopState.MayBeTop; + if (layer > 18) return false; // too many layers + } + int level = 0; + for (int i = 0; i < 6; i++) { + if (cellCount[i] != 0) { + if (level == 0) { + level = i + 4; + } else { + return false; + } + } + } + int tier = getMaxHatchTier(level); + long volSum = 0; + for (GT_MetaTileEntity_Hatch hatch : mAllDynamoHatches) { + if (hatch.mTier > tier || hatch.mTier < 3) { + return false; + } + volSum += (8L << (hatch.mTier * 2)); + } + for (GT_MetaTileEntity_Hatch hatch : mAllEnergyHatches) { + if (hatch.mTier > tier || hatch.mTier < 3) { + return false; + } + volSum += (8L << (hatch.mTier * 2)); + } + mBatteryCapacity = getCapacityFromCellTier(level) * cellCount[level - 4]; + if (mAllEnergyHatches.size() + mAllDynamoHatches.size() > 0) { + mAverageEuUsage = volSum / (mAllEnergyHatches.size() + mAllDynamoHatches.size()); + } else mAverageEuUsage = 0; + fixAllMaintenanceIssue(); + return true; + } + + public final boolean addPowerSubStationList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (LoadedMods.TecTech) { + if (isThisHatchMultiDynamo(aMetaTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (isThisHatchMultiEnergy(aMetaTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + } + return false; + } + + // Define storage capacity of smallest cell tier (EV) and compute higher tiers from it + private static final long CELL_TIER_EV_CAPACITY = 100 * 1000 * 1000; + private static final long CELL_TIER_MULTIPLIER = 4; // each tier's capacity is this many times the previous tier + + public static long getCapacityFromCellTier(int aOverallCellTier) { + // Use integer math instead of `Math.pow` to avoid range/precision errors + if (aOverallCellTier < 4) return 0; + aOverallCellTier -= 4; + long capacity = CELL_TIER_EV_CAPACITY; + while (aOverallCellTier > 0) { + capacity *= CELL_TIER_MULTIPLIER; + aOverallCellTier--; + } + return capacity; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_PowerSubStationController(this.mName); + } + + // mTotalEnergyAdded + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setLong("mAverageEuUsage", this.mAverageEuUsage); + this.mAverageEuAdded.write(aNBT, "mAverageEuAdded"); + this.mAverageEuConsumed.write(aNBT, "mAverageEuConsumed"); + + // Usage Stats + aNBT.setLong("mTotalEnergyAdded", this.mTotalEnergyAdded); + aNBT.setLong("mTotalEnergyLost", this.mTotalEnergyLost); + aNBT.setLong("mTotalEnergyConsumed", this.mTotalEnergyConsumed); + aNBT.setLong("mTotalRunTime", this.mTotalRunTime); + aNBT.setBoolean("mIsOutputtingPower", this.mIsOutputtingPower); + aNBT.setLong("mBatteryCapacity", this.mBatteryCapacity); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + + // Best not to get a long if the Tag Map is holding an int + if (aNBT.hasKey("mAverageEuUsage")) { + this.mAverageEuUsage = aNBT.getLong("mAverageEuUsage"); + } + switch (aNBT.func_150299_b("mAverageEuAdded")) { + case NBT.TAG_BYTE_ARRAY: + this.mAverageEuAdded.read(aNBT, "mAverageEuAdded"); + break; + case NBT.TAG_LONG: + this.mAverageEuAdded.set(aNBT.getLong("mAverageEuAdded")); + break; + } + switch (aNBT.func_150299_b("mAverageEuConsumed")) { + case NBT.TAG_BYTE_ARRAY: + this.mAverageEuConsumed.read(aNBT, "mAverageEuConsumed"); + break; + case NBT.TAG_LONG: + this.mAverageEuConsumed.set(aNBT.getLong("mAverageEuConsumed")); + break; + } + + // Usage Stats + this.mTotalEnergyAdded = aNBT.getLong("mTotalEnergyAdded"); + this.mTotalEnergyLost = aNBT.getLong("mTotalEnergyLost"); + this.mTotalEnergyConsumed = aNBT.getLong("mTotalEnergyConsumed"); + this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); + + this.mIsOutputtingPower = aNBT.getBoolean("mIsOutputtingPower"); + + this.mBatteryCapacity = aNBT.getLong("mBatteryCapacity"); + + super.loadNBTData(aNBT); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + this.mProgresstime = 0; + this.mMaxProgresstime = 200; + this.mEUt = 0; + this.mEfficiencyIncrease = 10000; + this.fixAllMaintenanceIssue(); + return true; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + private long drawEnergyFromHatch(MetaTileEntity aHatch) { + if (!isValidMetaTileEntity(aHatch)) { + return 0; + } + + long stored = aHatch.getEUVar(); + long voltage = aHatch.maxEUInput() * aHatch.maxAmperesIn(); + + if (voltage > stored) { + return 0; + } + + if (this.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false)) { + aHatch.setEUVar((stored - voltage)); + this.mTotalEnergyAdded += voltage; + return voltage; + } + return 0; + } + + private long addEnergyToHatch(MetaTileEntity aHatch) { + if (!isValidMetaTileEntity(aHatch)) { + return 0; + } + + long voltage = aHatch.maxEUOutput() * aHatch.maxAmperesOut(); + + if (aHatch.getEUVar() > aHatch.maxEUStore() - voltage) { + return 0; + } + + if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(voltage, false)) { + aHatch.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false); + this.mTotalEnergyConsumed += voltage; + return voltage; + } + return 0; + } + + private long computeEnergyTax() { + float mTax = mAverageEuUsage * (ENERGY_TAX / 100f); + + // Increase tax up to 2x if machine is not fully repaired + mTax = mTax * (1f + (10000f - mEfficiency) / 10000f); + + return MathUtils.roundToClosestLong(mTax); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + this.fixAllMaintenanceIssue(); + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + // First, decay overcharge (1% of stored energy plus 1000 EU per tick) + if (this.getEUVar() > this.mBatteryCapacity) { + long energy = (long) (this.getEUVar() * 0.990f) - 1000; + this.setEUVar(energy); + } + + // Pay Tax + long mDecrease = computeEnergyTax(); + this.mTotalEnergyLost += Math.min(mDecrease, this.getEUVar()); + this.setEUVar(Math.max(0, this.getEUVar() - mDecrease)); + + long aInputAverage = 0; + long aOutputAverage = 0; + // Input Power + for (GT_MetaTileEntity_Hatch THatch : this.mDischargeHatches) { + aInputAverage += drawEnergyFromHatch(THatch); + } + for (GT_MetaTileEntity_Hatch tHatch : this.mAllEnergyHatches) { + aInputAverage += drawEnergyFromHatch(tHatch); + } + + // Output Power + for (GT_MetaTileEntity_Hatch THatch : this.mChargeHatches) { + aOutputAverage += addEnergyToHatch(THatch); + } + for (GT_MetaTileEntity_Hatch tHatch : this.mAllDynamoHatches) { + aOutputAverage += addEnergyToHatch(tHatch); + } + // reset progress time + mProgresstime = 0; + + this.mAverageEuAdded.sample(aInputAverage); + this.mAverageEuConsumed.sample(aOutputAverage); + + return true; + } + + @Override + public boolean drainEnergyInput(long aEU) { + // Not applicable to this machine + return true; + } + + @Override + public boolean addEnergyOutput(long aEU) { + // Not applicable to this machine + return true; + } + + @Override + public long maxEUStore() { + return mBatteryCapacity; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public String[] getExtraInfoData() { + String mode; + if (mIsOutputtingPower) { + mode = EnumChatFormatting.GOLD + "Output" + EnumChatFormatting.RESET; + } else { + mode = EnumChatFormatting.BLUE + "Input" + EnumChatFormatting.RESET; + } + + String storedEnergyText; + if (this.getEUVar() > this.mBatteryCapacity) { + storedEnergyText = + EnumChatFormatting.RED + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; + } else { + storedEnergyText = + EnumChatFormatting.GREEN + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; + } + + int errorCode = this.getBaseMetaTileEntity().getErrorDisplayID(); + boolean mMaint = (errorCode != 0); + + return new String[] { + "Ergon Energy - District Sub-Station", + "Stored EU: " + storedEnergyText, + "Capacity: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.maxEUStore()) + + EnumChatFormatting.RESET, + "Running Costs: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(this.computeEnergyTax()) + + EnumChatFormatting.RESET + " EU/t", + "Controller Mode: " + mode, + "Requires Maintenance: " + (!mMaint ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + mMaint + + EnumChatFormatting.RESET + " | Code: [" + + (!mMaint ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + errorCode + + EnumChatFormatting.RESET + "]", + "----------------------", + "Stats for Nerds", + "Average Input: " + EnumChatFormatting.BLUE + this.mAverageEuAdded + EnumChatFormatting.RESET + " EU", + "Average Output: " + EnumChatFormatting.GOLD + this.mAverageEuConsumed + EnumChatFormatting.RESET + " EU", + "Total Input: " + EnumChatFormatting.BLUE + GT_Utility.formatNumbers(this.mTotalEnergyAdded) + + EnumChatFormatting.RESET + " EU", + "Total Output: " + EnumChatFormatting.GOLD + GT_Utility.formatNumbers(this.mTotalEnergyConsumed) + + EnumChatFormatting.RESET + " EU", + "Total Costs: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(this.mTotalEnergyLost) + + EnumChatFormatting.RESET + " EU", + }; + } + + @Override + public void explodeMultiblock() { + // TODO Auto-generated method stub + super.explodeMultiblock(); + } + + @Override + public void doExplosion(long aExplosionPower) { + // TODO Auto-generated method stub + super.doExplosion(aExplosionPower); + } + + @Override + public long getMaxInputVoltage() { + return 32768; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isEnetInput() { + return !mIsOutputtingPower; + } + + @Override + public boolean isEnetOutput() { + return mIsOutputtingPower; + } + + @Override + public boolean isInputFacing(byte aSide) { + return (aSide == this.getBaseMetaTileEntity().getBackFacing() && !mIsOutputtingPower); + } + + @Override + public boolean isOutputFacing(byte aSide) { + return (aSide == this.getBaseMetaTileEntity().getBackFacing() && mIsOutputtingPower); + } + + @Override + public long maxAmperesIn() { + return 32; + } + + @Override + public long maxAmperesOut() { + return 32; + } + + @Override + public long maxEUInput() { + return 32768; + } + + @Override + public long maxEUOutput() { + return 32768; + } + + public final long getAverageEuAdded() { + return this.mAverageEuAdded.get(); + } + + public final long getAverageEuConsumed() { + return this.mAverageEuConsumed.get(); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mIsOutputtingPower = Utils.invertBoolean(mIsOutputtingPower); + if (mIsOutputtingPower) { + PlayerUtils.messagePlayer(aPlayer, "Sub-Station is now outputting power from the controller."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Sub-Station is now inputting power into the controller."); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java index 67999087f3..4a24de7c5a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java @@ -3,9 +3,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.misc; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes; -import java.util.ArrayList; -import java.util.Collections; - import Ic2ExpReactorPlanner.SimulationData; import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; @@ -26,6 +23,8 @@ import gtPlusPlus.xmod.gregtech.api.gui.computer.GT_GUIContainer_ComputerCube; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.computer.GT_Computercube_Description; import gtPlusPlus.xmod.gregtech.common.computer.GT_Computercube_Simulator; +import java.util.ArrayList; +import java.util.Collections; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; @@ -37,884 +36,929 @@ import net.minecraft.world.World; public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank { - public static int MODE_MAIN = 0; - public static int MODE_REACTOR_PLANNER = 1; - public static int MODE_SCANNER = 2; - public static int MODE_CENTRIFUGE = 3; - public static int MODE_FUSION = 4; - public static int MODE_INFO = 5; - public static int MODE_ELECTROLYZER = 6; - - public static boolean mSeedscanner = true; + public static int MODE_MAIN = 0; + public static int MODE_REACTOR_PLANNER = 1; + public static int MODE_SCANNER = 2; + public static int MODE_CENTRIFUGE = 3; + public static int MODE_FUSION = 4; + public static int MODE_INFO = 5; + public static int MODE_ELECTROLYZER = 6; + + public static boolean mSeedscanner = true; + + public static boolean mReactorplanner = true; + + public static ArrayList<GT_ItemStack> sReactorList; + + public boolean mStarted = false; + + public int mMode = 0; + + public int mHeat = 0; + + public long mEUOut = 0; + + public int mMaxHeat = 1; + + public long mEU = 0; + + public int mProgress = 0; + public int mMaxProgress = 0; + + public int mEUTimer = 0; + + public int mEULast1 = 0; + + public int mEULast2 = 0; + + public int mEULast3 = 0; + + public int mEULast4 = 0; + + public float mHEM = 1.0F, mExplosionStrength = 0.0F; + + public String mFusionOutput = ""; + + private boolean mNeedsUpdate; + + private GT_Computercube_Simulator mSimulator; + + public GT_TileEntity_ComputerCube(final int aID, final String aDescription) { + super(aID, "computer.cube", "Computer Cube MKII", 5, 114, aDescription); + } + + public GT_TileEntity_ComputerCube(final String aName, final String aDescription, final ITexture[][][] aTextures) { + super(aName, 5, 114, aDescription, aTextures); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + Logger.INFO("CC-Sever ID: " + aID); + return new GT_Container_ComputerCube(aPlayerInventory, aBaseMetaTileEntity, mMode); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + Logger.INFO("CC-Client ID: " + aID); + return new GT_GUIContainer_ComputerCube(aPlayerInventory, aBaseMetaTileEntity, mMode); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Built in Reactor Planner", + "Built in Scanner", + "Built in Info-Bank", + "Displays Fusion Recipes", + CORE.GT_Tooltip + }; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer, mMode); + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_TileEntity_ComputerCube(this.mName, this.mDescription, this.mTextures); + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + ItemStack tStack = aPlayer.getCurrentEquippedItem(); + if (tStack != null && ItemList.Tool_DataOrb.isStackEqual(tStack)) { + return false; + } + return true; + } + + public final GT_Computercube_Simulator getSimulator() { + return this.mSimulator; + } + + public final void setSimulator(GT_Computercube_Simulator mSimulator) { + this.mSimulator = mSimulator; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isInputFacing(byte aDirection) { + return true; + } + + @Override + public long maxAmperesIn() { + return 4; + } + + @Override + public long maxEUInput() { + return GT_Values.V[4]; + } + + @Override + public long maxEUStore() { + return GT_Values.V[5] * 1024; + } + + @Override + public boolean ownerControl() { + return false; + } + + @Override + public int getSizeInventory() { + return 114; + } + + @Override + public boolean isValidSlot(int aIndex) { + return (aIndex > 53 && aIndex < 58); + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + public void saveNuclearReactor() { + for (int i = 0; i < 54; i++) { + if (this.mInventory[i] == null) { + this.mInventory[i + 59] = null; + } else { + this.mInventory[i + 59] = this.mInventory[i].copy(); + } + } + } + + public void loadNuclearReactor() { + for (int i = 0; i < 54; i++) { + if (this.mInventory[i + 59] == null) { + this.mInventory[i] = null; + } else { + this.mInventory[i] = this.mInventory[i + 59].copy(); + } + } + } + + public int getXCoord() { + return this.getBaseMetaTileEntity().getXCoord(); + } + + public int getYCoord() { + return this.getBaseMetaTileEntity().getYCoord(); + } + + public int getZCoord() { + return this.getBaseMetaTileEntity().getZCoord(); + } + + public void reset() { + this.mEU = 0; + this.mHeat = 0; + this.mEUOut = 0; + this.mMaxHeat = 10000; + this.mHEM = 1.0F; + this.mExplosionStrength = 0.0F; + this.mProgress = 0; + this.mMaxProgress = 0; + this.mFusionOutput = ""; + this.mInventory[113] = null; + int i; + for (i = 0; i < 54; i++) { + this.mInventory[i] = null; + this.mInventory[i + 59] = null; + } + for (i = 54; i < 58; i++) { + if (this.mInventory[i] != null) { + if (!this.getWorld().isRemote) + this.getWorld().spawnEntityInWorld((Entity) new EntityItem( + this.getWorld(), + this.getXCoord() + 0.5D, + this.getYCoord() + 0.5D, + this.getZCoord() + 0.5D, + this.mInventory[i])); + this.mInventory[i] = null; + } + } + } + + public void switchModeForward() { + int aTempMode = mMode; + aTempMode++; + if (aTempMode == MODE_ELECTROLYZER || aTempMode == MODE_CENTRIFUGE) { + aTempMode++; + } + if (aTempMode >= 7) { + aTempMode = 0; + } + mMode = aTempMode; + switchMode(); + } + + public void switchModeBackward() { + int aTempMode = mMode; + aTempMode--; + if (aTempMode == MODE_ELECTROLYZER || aTempMode == MODE_CENTRIFUGE) { + aTempMode--; + } + if (aTempMode < 0) { + aTempMode = 6; + } + mMode = aTempMode; + switchMode(); + } + + private void switchMode() { + reset(); + if (this.mMode == MODE_REACTOR_PLANNER && !mReactorplanner) { + switchMode(); + return; + } + if (this.mMode == MODE_SCANNER && !mSeedscanner) { + switchMode(); + return; + } + if (this.mMode == MODE_CENTRIFUGE) { + showCentrifugeRecipe(0); + } + if (this.mMode == MODE_FUSION) { + showFusionRecipe(0); + } + if (this.mMode == MODE_INFO) { + showDescription(0); + } + if (this.mMode == MODE_ELECTROLYZER) { + showElectrolyzerRecipe(0); + } + this.getWorld() + .addBlockEvent( + this.getXCoord(), + this.getYCoord(), + this.getZCoord(), + GregTech_API.sBlockMachines, + 10, + this.mMode); + this.getWorld() + .addBlockEvent( + this.getXCoord(), + this.getYCoord(), + this.getZCoord(), + GregTech_API.sBlockMachines, + 11, + this.mMaxHeat); + } + + public void showDescription(int aIndex) { + this.mExplosionStrength = 0.0F; + if (GT_Computercube_Description.sDescriptions.isEmpty()) { + return; + } + if (aIndex >= GT_Computercube_Description.sDescriptions.size() || aIndex < 0) aIndex = 0; + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[0] == null) { + this.mInventory[59] = null; + } else { + this.mInventory[59] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[0].copy(); + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[1] == null) { + this.mInventory[60] = null; + } else { + this.mInventory[60] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[1].copy(); + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[2] == null) { + this.mInventory[61] = null; + } else { + this.mInventory[61] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[2].copy(); + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[3] == null) { + this.mInventory[62] = null; + } else { + this.mInventory[62] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[3].copy(); + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[4] == null) { + this.mInventory[63] = null; + } else { + this.mInventory[63] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[4].copy(); + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[5] == null) { + this.mInventory[64] = null; + } else { + this.mInventory[64] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[5].copy(); + this.mExplosionStrength = 100.0F; + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[6] == null) { + this.mInventory[65] = null; + } else { + this.mInventory[65] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[6].copy(); + this.mExplosionStrength = 100.0F; + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[7] == null) { + this.mInventory[66] = null; + } else { + this.mInventory[66] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[7].copy(); + this.mExplosionStrength = 100.0F; + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[8] == null) { + this.mInventory[67] = null; + } else { + this.mInventory[67] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[8].copy(); + this.mExplosionStrength = 100.0F; + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[9] == null) { + this.mInventory[68] = null; + } else { + this.mInventory[68] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[9].copy(); + this.mExplosionStrength = 100.0F; + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[10] == null) { + this.mInventory[69] = null; + } else { + this.mInventory[69] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[10].copy(); + this.mExplosionStrength = 100.0F; + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[11] == null) { + this.mInventory[70] = null; + } else { + this.mInventory[70] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[11].copy(); + this.mExplosionStrength = 100.0F; + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[12] == null) { + this.mInventory[71] = null; + } else { + this.mInventory[71] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[12].copy(); + this.mExplosionStrength = 100.0F; + } + if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[13] == null) { + this.mInventory[72] = null; + } else { + this.mInventory[72] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)) + .mStacks[13].copy(); + this.mExplosionStrength = 100.0F; + } + this.mMaxHeat = aIndex; + this.getWorld() + .addBlockEvent( + this.getXCoord(), + this.getYCoord(), + this.getZCoord(), + GregTech_API.sBlockMachines, + 11, + this.mMaxHeat); + } + + public void switchDescriptionPageForward() { + if (++this.mMaxHeat >= GT_Computercube_Description.sDescriptions.size()) this.mMaxHeat = 0; + showDescription(this.mMaxHeat); + } + + public void switchDescriptionPageBackward() { + if (--this.mMaxHeat < 0) this.mMaxHeat = GT_Computercube_Description.sDescriptions.size() - 1; + showDescription(this.mMaxHeat); + } + + public void showCentrifugeRecipe(int aIndex) { + /* + if (aIndex >= GT_Recipe_Map.sCentrifugeRecipes.mRecipeList.size() || aIndex < 0) + aIndex = 0; + GT_Recipe tRecipe = GT_Recipe_Map.sCentrifugeRecipes.mRecipeList.get(aIndex); + if (tRecipe != null) { + if (tRecipe.mInput1 == null) { + this.mInventory[59] = null; + } + else { + this.mInventory[59] = tRecipe.mInput1.copy(); + } + if (tRecipe.mInput2 == null) { + this.mInventory[60] = null; + } + else { + this.mInventory[60] = tRecipe.mInput2.copy(); + } + if (tRecipe.mOutput1 == null) { + this.mInventory[61] = null; + } + else { + this.mInventory[61] = tRecipe.mOutput1.copy(); + } + if (tRecipe.mOutput2 == null) { + this.mInventory[62] = null; + } + else { + this.mInventory[62] = tRecipe.mOutput2.copy(); + } + if (tRecipe.mOutput3 == null) { + this.mInventory[63] = null; + } + else { + this.mInventory[63] = tRecipe.mOutput3.copy(); + } + if (tRecipe.mOutput4 == null) { + this.mInventory[64] = null; + } + else { + this.mInventory[64] = tRecipe.mOutput4.copy(); + } + this.mEU = tRecipe.mDuration * 5; + this.mMaxHeat = aIndex; + } + this.getWorld().addBlockEvent(this.xCoord, this.yCoord, this.zCoord, (GregTech_API.sBlockList[1]).field_71990_ca, 11, this.mMaxHeat); + */ } + + public void switchCentrifugePageForward() { + if (++this.mMaxHeat >= GT_Recipe_Map.sCentrifugeRecipes.mRecipeList.size()) this.mMaxHeat = 0; + // showCentrifugeRecipe(this.mMaxHeat); + } + + public void switchCentrifugePageBackward() { + if (--this.mMaxHeat < 0) this.mMaxHeat = GT_Recipe_Map.sCentrifugeRecipes.mRecipeList.size() - 1; + // showCentrifugeRecipe(this.mMaxHeat); + } + + public void showElectrolyzerRecipe(int aIndex) { + /* + if (aIndex >= GT_Recipe_Map.sElectrolyzerRecipes.mRecipeList.size() || aIndex < 0) + aIndex = 0; + GT_Recipe tRecipe = GT_Recipe_Map.sElectrolyzerRecipes.get(aIndex); + if (tRecipe != null) { + if (tRecipe.mInput1 == null) { + this.mInventory[59] = null; + } + else { + this.mInventory[59] = tRecipe.mInput1.copy(); + } + if (tRecipe.mInput2 == null) { + this.mInventory[60] = null; + } + else { + this.mInventory[60] = tRecipe.mInput2.copy(); + } + if (tRecipe.mOutput1 == null) { + this.mInventory[61] = null; + } + else { + this.mInventory[61] = tRecipe.mOutput1.copy(); + } + if (tRecipe.mOutput2 == null) { + this.mInventory[62] = null; + } + else { + this.mInventory[62] = tRecipe.mOutput2.copy(); + } + if (tRecipe.mOutput3 == null) { + this.mInventory[63] = null; + } + else { + this.mInventory[63] = tRecipe.mOutput3.copy(); + } + if (tRecipe.mOutput4 == null) { + this.mInventory[64] = null; + } + else { + this.mInventory[64] = tRecipe.mOutput4.copy(); + } + this.mEU = tRecipe.mDuration * tRecipe.mEUt; + this.mMaxHeat = aIndex; + } + this.getWorld().addBlockEvent(this.xCoord, this.yCoord, this.zCoord, (GregTech_API.sBlockList[1]).field_71990_ca, 11, this.mMaxHeat); + */ } + + public void switchElectrolyzerPageForward() { + if (++this.mMaxHeat >= GT_Recipe_Map.sElectrolyzerRecipes.mRecipeList.size()) this.mMaxHeat = 0; + showElectrolyzerRecipe(this.mMaxHeat); + } - public static boolean mReactorplanner = true; - - public static ArrayList<GT_ItemStack> sReactorList; + public void switchElectrolyzerPageBackward() { + if (--this.mMaxHeat < 0) this.mMaxHeat = GT_Recipe_Map.sElectrolyzerRecipes.mRecipeList.size() - 1; + showElectrolyzerRecipe(this.mMaxHeat); + } + + public static ArrayList<GT_Recipe> sFusionReactorRecipes = new ArrayList<GT_Recipe>(); + + public void showFusionRecipe(int aIndex) { + + if (sFusionReactorRecipes.isEmpty()) { + for (GT_Recipe aRecipe : GT_Recipe_Map.sFusionRecipes.mRecipeList) { + sFusionReactorRecipes.add(aRecipe); + } + Collections.sort(sFusionReactorRecipes); + } + + if (aIndex >= sFusionReactorRecipes.size() || aIndex < 0) { + aIndex = 0; + } + GT_Recipe tRecipe = sFusionReactorRecipes.get(aIndex); + if (tRecipe != null) { + if (tRecipe.mFluidInputs[0] == null) { + this.mInventory[59] = null; + } else { + this.mInventory[59] = GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[0], true); + } + if (tRecipe.mFluidInputs[1] == null) { + this.mInventory[60] = null; + } else { + this.mInventory[60] = GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[1], true); + } + if (tRecipe.mFluidOutputs[0] == null) { + this.mInventory[61] = null; + } else { + this.mInventory[61] = GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[0], true); + } + this.mEU = tRecipe.mSpecialValue; + this.mEUOut = tRecipe.mEUt; + this.mHeat = tRecipe.mDuration; + this.mMaxHeat = aIndex; + this.mFusionOutput = tRecipe.mFluidOutputs[0].getLocalizedName(); + } + this.getWorld() + .addBlockEvent( + this.getXCoord(), + this.getYCoord(), + this.getZCoord(), + GregTech_API.sBlockMachines, + 11, + this.mMaxHeat); + } + + public void switchFusionPageForward() { + if (++this.mMaxHeat >= sFusionReactorRecipes.size()) this.mMaxHeat = 0; + showFusionRecipe(this.mMaxHeat); + } + + public void switchFusionPageBackward() { + if (--this.mMaxHeat < 0) this.mMaxHeat = sFusionReactorRecipes.size() - 1; + showFusionRecipe(this.mMaxHeat); + } + + public void switchNuclearReactor() { + if (this.mStarted) { + stopNuclearReactor(); + } else { + startNuclearReactor(); + } + } + + public void startNuclearReactor() { + this.mStarted = true; + this.mHeat = 0; + this.mEU = 0; + mSimulator.simulate(); + } + + public void stopNuclearReactor() { + this.mStarted = false; + mSimulator.simulate(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mMode", this.mMode); + aNBT.setInteger("mProgress", this.mProgress); + aNBT.setInteger("mMaxProgress", this.mMaxProgress); + aNBT.setBoolean("mStarted", this.mStarted); + int[] aSplitLong1 = MathUtils.splitLongIntoTwoIntegers(mEU); + aNBT.setInteger("mEU1", aSplitLong1[0]); + aNBT.setInteger("mEU2", aSplitLong1[1]); + aNBT.setInteger("mHeat", this.mHeat); + int[] aSplitLong2 = MathUtils.splitLongIntoTwoIntegers(mEUOut); + aNBT.setInteger("mEUOut1", aSplitLong2[0]); + aNBT.setInteger("mEUOut2", aSplitLong2[1]); + aNBT.setInteger("mMaxHeat", this.mMaxHeat); + aNBT.setFloat("mHEM", this.mHEM); + aNBT.setFloat("mExplosionStrength", this.mExplosionStrength); + aNBT.setString("mFusionOutput", this.mFusionOutput); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mMode = aNBT.getInteger("mMode"); + this.mProgress = aNBT.getInteger("mProgress"); + this.mMaxProgress = aNBT.getInteger("mMaxProgress"); + this.mStarted = aNBT.getBoolean("mStarted"); + int partA = aNBT.getInteger("mEU1"); + int partB = aNBT.getInteger("mEU2"); + this.mEU = MathUtils.combineTwoIntegersToLong(partA, partB); + this.mHeat = aNBT.getInteger("mHeat"); + partA = aNBT.getInteger("mEUOut1"); + partB = aNBT.getInteger("mEUOut2"); + this.mEUOut = MathUtils.combineTwoIntegersToLong(partA, partB); + this.mMaxHeat = aNBT.getInteger("mMaxHeat"); + this.mHEM = aNBT.getFloat("mHEM"); + this.mExplosionStrength = aNBT.getFloat("mExplosionStrength"); + this.mFusionOutput = aNBT.getString("mFusionOutput"); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (mSimulator == null) { + mSimulator = new GT_Computercube_Simulator(this); + } + if (this.getBaseMetaTileEntity().isClientSide()) { + this.getWorld().markBlockForUpdate(this.getXCoord(), this.getYCoord(), this.getZCoord()); + this.mNeedsUpdate = false; + } else { + this.mNeedsUpdate = false; + } + if (this.getBaseMetaTileEntity().isServerSide()) { + if (this.mMode == MODE_SCANNER) { + /*if (this.mInventory[55] == null) { + this.mInventory[55] = this.mInventory[54]; + this.mInventory[54] = null; + }*/ + if (this.mInventory[57] == null) { + this.mInventory[57] = this.mInventory[56]; + this.mInventory[56] = null; + } + + // 54 - 55 || 56 - 57 + // Do scanny bits + if (mSeedscanner && this.mMode == MODE_SCANNER) { + /*if (doScan(this.mInventory[55]) == 4) { + if ((this.mInventory[57] != null) && (this.mInventory[57].getUnlocalizedName().equals("gt.metaitem.01.32707"))) { + GT_Mod.instance.achievements.issueAchievement(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "scanning"); + } + }*/ + /*if (this.mEU > 0) { + if (!this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(this.mEU, false)) { + this.mProgress = 0; + } + }*/ + } + + /*if (mSeedscanner && this.mInventory[55] != null && GT_Utility.areStacksEqual(this.mInventory[55], Ic2Items.cropSeed, true) && this.mInventory[55].getTagCompound() != null) { + if (this.mInventory[55].getTagCompound().getByte("scan") < 4) { + if (this.mProgress >= 100) { + this.mInventory[55].getTagCompound().setByte("scan", (byte) 4); + this.mProgress = 0; + } + else if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(100, false)) { + this.mProgress++; + } + } + else { + this.mProgress = 0; + if (this.mInventory[56] == null) { + this.mInventory[56] = this.mInventory[55]; + this.mInventory[55] = null; + } + } + } + else { + this.mProgress = 0; + if (this.mInventory[56] == null) { + this.mInventory[56] = this.mInventory[55]; + this.mInventory[55] = null; + } + }*/ + } + + if (this.mMode == MODE_REACTOR_PLANNER + && mReactorplanner + && this.mSimulator != null + && this.mSimulator.simulator != null + && this.mSimulator.simulatedReactor != null) { + SimulationData aData = this.mSimulator.simulator.getData(); + if (aData != null && aData.totalReactorTicks > 0 && this.mProgress != aData.totalReactorTicks) { + Logger.INFO("Updating Variables"); + this.mEU = aData.avgEUoutput; + this.mEUOut = (aData.totalEUoutput / aData.totalReactorTicks); + this.mHeat = aData.avgHUoutput; + this.mMaxHeat = aData.maxHUoutput; + this.mExplosionStrength = aData.explosionPower; + this.mHEM = (float) aData.hullHeating; + this.mProgress = aData.totalReactorTicks; + } + } + + if (aTick % 20L == 0L) { + this.getWorld() + .addBlockEvent( + this.getXCoord(), + this.getYCoord(), + this.getZCoord(), + GregTech_API.sBlockMachines, + 10, + this.mMode); + this.getWorld() + .addBlockEvent( + this.getXCoord(), + this.getYCoord(), + this.getZCoord(), + GregTech_API.sBlockMachines, + 11, + this.mMaxHeat); + } + } + } + + @Override + public void receiveClientEvent(byte aEventID, byte aValue) { + super.receiveClientEvent(aEventID, aValue); + if (this.getWorld().isRemote) + switch (aEventID) { + case 10: + this.mNeedsUpdate = true; + this.mMode = aValue; + break; + case 11: + this.mMaxHeat = aValue; + break; + } + return; + } + + @Override + public void onValueUpdate(byte aValue) { + super.onValueUpdate(aValue); + this.mNeedsUpdate = true; + } + + @Override + public void onMachineBlockUpdate() { + super.onMachineBlockUpdate(); + this.mNeedsUpdate = true; + } + + @Override + public boolean canInsertItem(int i, ItemStack itemstack, int j) { + return (this.mMode == MODE_SCANNER) ? ((i == 54 || i == 55)) : false; + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) { + return (this.mMode == MODE_SCANNER) ? ((i == 56 || i == 57)) : false; + } + + public World getWorld() { + return this.getBaseMetaTileEntity().getWorld(); + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return false; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getSides(i); + rTextures[2][i + 1] = this.getSides(i); + rTextures[3][i + 1] = this.getSides(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getSides(i); + rTextures[7][i + 1] = this.getSides(i); + rTextures[8][i + 1] = this.getSides(i); + rTextures[9][i + 1] = this.getSides(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_3)}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Computer_Cube)}; + } + + protected static final int DID_NOT_FIND_RECIPE = 0, + FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS = 1, + FOUND_AND_SUCCESSFULLY_USED_RECIPE = 2; - public boolean mStarted = false; - - public int mMode = 0; - - public int mHeat = 0; - - public long mEUOut = 0; - - public int mMaxHeat = 1; - - public long mEU = 0; - - public int mProgress = 0; - public int mMaxProgress = 0; - - public int mEUTimer = 0; - - public int mEULast1 = 0; - - public int mEULast2 = 0; - - public int mEULast3 = 0; - - public int mEULast4 = 0; - - public float mHEM = 1.0F, mExplosionStrength = 0.0F; - - public String mFusionOutput = ""; - - private boolean mNeedsUpdate; - - private GT_Computercube_Simulator mSimulator; - - public GT_TileEntity_ComputerCube(final int aID, final String aDescription) { - super(aID, "computer.cube", "Computer Cube MKII", 5, 114, aDescription); - } - - public GT_TileEntity_ComputerCube(final String aName, final String aDescription, final ITexture[][][] aTextures) { - super(aName, 5, 114, aDescription, aTextures); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - Logger.INFO("CC-Sever ID: "+aID); - return new GT_Container_ComputerCube(aPlayerInventory, aBaseMetaTileEntity, mMode); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - Logger.INFO("CC-Client ID: "+aID); - return new GT_GUIContainer_ComputerCube(aPlayerInventory, aBaseMetaTileEntity, mMode); - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - "Built in Reactor Planner", - "Built in Scanner", - "Built in Info-Bank", - "Displays Fusion Recipes", - CORE.GT_Tooltip}; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer, mMode); - return true; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_TileEntity_ComputerCube(this.mName, this.mDescription, this.mTextures); - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - ItemStack tStack = aPlayer.getCurrentEquippedItem(); - if (tStack != null && ItemList.Tool_DataOrb.isStackEqual(tStack)) { - return false; - } - return true; - } - - public final GT_Computercube_Simulator getSimulator() { - return this.mSimulator; - } - - public final void setSimulator(GT_Computercube_Simulator mSimulator) { - this.mSimulator = mSimulator; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isInputFacing(byte aDirection) { - return true; - } - - @Override - public long maxAmperesIn() { - return 4; - } - - @Override - public long maxEUInput() { - return GT_Values.V[4]; - } - - @Override - public long maxEUStore() { - return GT_Values.V[5] * 1024; - } - - @Override - public boolean ownerControl() { - return false; - } - - @Override - public int getSizeInventory() { - return 114; - } - - @Override - public boolean isValidSlot(int aIndex) { - return (aIndex > 53 && aIndex < 58); - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - public void saveNuclearReactor() { - for (int i = 0; i < 54; i++) { - if (this.mInventory[i] == null) { - this.mInventory[i + 59] = null; - } - else { - this.mInventory[i + 59] = this.mInventory[i].copy(); - } - } - } - - public void loadNuclearReactor() { - for (int i = 0; i < 54; i++) { - if (this.mInventory[i + 59] == null) { - this.mInventory[i] = null; - } - else { - this.mInventory[i] = this.mInventory[i + 59].copy(); - } - } - } - - public int getXCoord() { - return this.getBaseMetaTileEntity().getXCoord(); - } - - public int getYCoord() { - return this.getBaseMetaTileEntity().getYCoord(); - } - - public int getZCoord() { - return this.getBaseMetaTileEntity().getZCoord(); - } - - public void reset() { - this.mEU = 0; - this.mHeat = 0; - this.mEUOut = 0; - this.mMaxHeat = 10000; - this.mHEM = 1.0F; - this.mExplosionStrength = 0.0F; - this.mProgress = 0; - this.mMaxProgress = 0; - this.mFusionOutput = ""; - this.mInventory[113] = null; - int i; - for (i = 0; i < 54; i++) { - this.mInventory[i] = null; - this.mInventory[i + 59] = null; - } - for (i = 54; i < 58; i++) { - if (this.mInventory[i] != null) { - if (!this.getWorld().isRemote) - this.getWorld().spawnEntityInWorld((Entity) new EntityItem(this.getWorld(), this.getXCoord() + 0.5D, this.getYCoord() + 0.5D, this.getZCoord() + 0.5D, this.mInventory[i])); - this.mInventory[i] = null; - } - } - } - - public void switchModeForward() { - int aTempMode = mMode; - aTempMode++; - if (aTempMode == MODE_ELECTROLYZER ||aTempMode == MODE_CENTRIFUGE) { - aTempMode++; - } - if (aTempMode >= 7) { - aTempMode = 0; - } - mMode = aTempMode; - switchMode(); - } - - public void switchModeBackward() { - int aTempMode = mMode; - aTempMode--; - if (aTempMode == MODE_ELECTROLYZER ||aTempMode == MODE_CENTRIFUGE) { - aTempMode--; - } - if (aTempMode < 0) { - aTempMode = 6; - } - mMode = aTempMode; - switchMode(); - } - - private void switchMode() { - reset(); - if (this.mMode == MODE_REACTOR_PLANNER && !mReactorplanner) { - switchMode(); - return; - } - if (this.mMode == MODE_SCANNER && !mSeedscanner) { - switchMode(); - return; - } - if (this.mMode == MODE_CENTRIFUGE) { - showCentrifugeRecipe(0); - } - if (this.mMode == MODE_FUSION) { - showFusionRecipe(0); - } - if (this.mMode == MODE_INFO) { - showDescription(0); - } - if (this.mMode == MODE_ELECTROLYZER) { - showElectrolyzerRecipe(0); - } - this.getWorld().addBlockEvent(this.getXCoord(), this.getYCoord(), this.getZCoord(), GregTech_API.sBlockMachines, 10, this.mMode); - this.getWorld().addBlockEvent(this.getXCoord(), this.getYCoord(), this.getZCoord(), GregTech_API.sBlockMachines, 11, this.mMaxHeat); - } - - public void showDescription(int aIndex) { - this.mExplosionStrength = 0.0F; - if (GT_Computercube_Description.sDescriptions.isEmpty()) { - return; - } - if (aIndex >= GT_Computercube_Description.sDescriptions.size() || aIndex < 0) - aIndex = 0; - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[0] == null) { - this.mInventory[59] = null; - } - else { - this.mInventory[59] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[0].copy(); - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[1] == null) { - this.mInventory[60] = null; - } - else { - this.mInventory[60] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[1].copy(); - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[2] == null) { - this.mInventory[61] = null; - } - else { - this.mInventory[61] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[2].copy(); - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[3] == null) { - this.mInventory[62] = null; - } - else { - this.mInventory[62] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[3].copy(); - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[4] == null) { - this.mInventory[63] = null; - } - else { - this.mInventory[63] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[4].copy(); - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[5] == null) { - this.mInventory[64] = null; - } - else { - this.mInventory[64] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[5].copy(); - this.mExplosionStrength = 100.0F; - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[6] == null) { - this.mInventory[65] = null; - } - else { - this.mInventory[65] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[6].copy(); - this.mExplosionStrength = 100.0F; - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[7] == null) { - this.mInventory[66] = null; - } - else { - this.mInventory[66] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[7].copy(); - this.mExplosionStrength = 100.0F; - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[8] == null) { - this.mInventory[67] = null; - } - else { - this.mInventory[67] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[8].copy(); - this.mExplosionStrength = 100.0F; - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[9] == null) { - this.mInventory[68] = null; - } - else { - this.mInventory[68] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[9].copy(); - this.mExplosionStrength = 100.0F; - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[10] == null) { - this.mInventory[69] = null; - } - else { - this.mInventory[69] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[10].copy(); - this.mExplosionStrength = 100.0F; - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[11] == null) { - this.mInventory[70] = null; - } - else { - this.mInventory[70] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[11].copy(); - this.mExplosionStrength = 100.0F; - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[12] == null) { - this.mInventory[71] = null; - } - else { - this.mInventory[71] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[12].copy(); - this.mExplosionStrength = 100.0F; - } - if (((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[13] == null) { - this.mInventory[72] = null; - } - else { - this.mInventory[72] = ((GT_Computercube_Description) GT_Computercube_Description.sDescriptions.get(aIndex)).mStacks[13].copy(); - this.mExplosionStrength = 100.0F; - } - this.mMaxHeat = aIndex; - this.getWorld().addBlockEvent(this.getXCoord(), this.getYCoord(), this.getZCoord(), GregTech_API.sBlockMachines, 11, this.mMaxHeat); - } - - public void switchDescriptionPageForward() { - if (++this.mMaxHeat >= GT_Computercube_Description.sDescriptions.size()) - this.mMaxHeat = 0; - showDescription(this.mMaxHeat); - } - - public void switchDescriptionPageBackward() { - if (--this.mMaxHeat < 0) - this.mMaxHeat = GT_Computercube_Description.sDescriptions.size() - 1; - showDescription(this.mMaxHeat); - } - - public void showCentrifugeRecipe(int aIndex) { - /* - if (aIndex >= GT_Recipe_Map.sCentrifugeRecipes.mRecipeList.size() || aIndex < 0) - aIndex = 0; - GT_Recipe tRecipe = GT_Recipe_Map.sCentrifugeRecipes.mRecipeList.get(aIndex); - if (tRecipe != null) { - if (tRecipe.mInput1 == null) { - this.mInventory[59] = null; - } - else { - this.mInventory[59] = tRecipe.mInput1.copy(); - } - if (tRecipe.mInput2 == null) { - this.mInventory[60] = null; - } - else { - this.mInventory[60] = tRecipe.mInput2.copy(); - } - if (tRecipe.mOutput1 == null) { - this.mInventory[61] = null; - } - else { - this.mInventory[61] = tRecipe.mOutput1.copy(); - } - if (tRecipe.mOutput2 == null) { - this.mInventory[62] = null; - } - else { - this.mInventory[62] = tRecipe.mOutput2.copy(); - } - if (tRecipe.mOutput3 == null) { - this.mInventory[63] = null; - } - else { - this.mInventory[63] = tRecipe.mOutput3.copy(); - } - if (tRecipe.mOutput4 == null) { - this.mInventory[64] = null; - } - else { - this.mInventory[64] = tRecipe.mOutput4.copy(); - } - this.mEU = tRecipe.mDuration * 5; - this.mMaxHeat = aIndex; - } - this.getWorld().addBlockEvent(this.xCoord, this.yCoord, this.zCoord, (GregTech_API.sBlockList[1]).field_71990_ca, 11, this.mMaxHeat); - */} - - public void switchCentrifugePageForward() { - if (++this.mMaxHeat >= GT_Recipe_Map.sCentrifugeRecipes.mRecipeList.size()) - this.mMaxHeat = 0; - // showCentrifugeRecipe(this.mMaxHeat); - } - - public void switchCentrifugePageBackward() { - if (--this.mMaxHeat < 0) - this.mMaxHeat = GT_Recipe_Map.sCentrifugeRecipes.mRecipeList.size() - 1; - // showCentrifugeRecipe(this.mMaxHeat); - } - - public void showElectrolyzerRecipe(int aIndex) { - /* - if (aIndex >= GT_Recipe_Map.sElectrolyzerRecipes.mRecipeList.size() || aIndex < 0) - aIndex = 0; - GT_Recipe tRecipe = GT_Recipe_Map.sElectrolyzerRecipes.get(aIndex); - if (tRecipe != null) { - if (tRecipe.mInput1 == null) { - this.mInventory[59] = null; - } - else { - this.mInventory[59] = tRecipe.mInput1.copy(); - } - if (tRecipe.mInput2 == null) { - this.mInventory[60] = null; - } - else { - this.mInventory[60] = tRecipe.mInput2.copy(); - } - if (tRecipe.mOutput1 == null) { - this.mInventory[61] = null; - } - else { - this.mInventory[61] = tRecipe.mOutput1.copy(); - } - if (tRecipe.mOutput2 == null) { - this.mInventory[62] = null; - } - else { - this.mInventory[62] = tRecipe.mOutput2.copy(); - } - if (tRecipe.mOutput3 == null) { - this.mInventory[63] = null; - } - else { - this.mInventory[63] = tRecipe.mOutput3.copy(); - } - if (tRecipe.mOutput4 == null) { - this.mInventory[64] = null; - } - else { - this.mInventory[64] = tRecipe.mOutput4.copy(); - } - this.mEU = tRecipe.mDuration * tRecipe.mEUt; - this.mMaxHeat = aIndex; - } - this.getWorld().addBlockEvent(this.xCoord, this.yCoord, this.zCoord, (GregTech_API.sBlockList[1]).field_71990_ca, 11, this.mMaxHeat); - */} - - public void switchElectrolyzerPageForward() { - if (++this.mMaxHeat >= GT_Recipe_Map.sElectrolyzerRecipes.mRecipeList.size()) - this.mMaxHeat = 0; - showElectrolyzerRecipe(this.mMaxHeat); - } - - public void switchElectrolyzerPageBackward() { - if (--this.mMaxHeat < 0) - this.mMaxHeat = GT_Recipe_Map.sElectrolyzerRecipes.mRecipeList.size() - 1; - showElectrolyzerRecipe(this.mMaxHeat); - } - - public static ArrayList<GT_Recipe> sFusionReactorRecipes = new ArrayList<GT_Recipe>(); - - public void showFusionRecipe(int aIndex) { - - if (sFusionReactorRecipes.isEmpty()) { - for (GT_Recipe aRecipe : GT_Recipe_Map.sFusionRecipes.mRecipeList) { - sFusionReactorRecipes.add(aRecipe); - } - Collections.sort(sFusionReactorRecipes); - } - - if (aIndex >= sFusionReactorRecipes.size() || aIndex < 0) { - aIndex = 0; - } - GT_Recipe tRecipe = sFusionReactorRecipes.get(aIndex); - if (tRecipe != null) { - if (tRecipe.mFluidInputs[0] == null) { - this.mInventory[59] = null; - } - else { - this.mInventory[59] = GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[0], true); - } - if (tRecipe.mFluidInputs[1] == null) { - this.mInventory[60] = null; - } - else { - this.mInventory[60] = GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[1], true); - } - if (tRecipe.mFluidOutputs[0] == null) { - this.mInventory[61] = null; - } - else { - this.mInventory[61] = GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[0], true); - } - this.mEU = tRecipe.mSpecialValue; - this.mEUOut = tRecipe.mEUt; - this.mHeat = tRecipe.mDuration; - this.mMaxHeat = aIndex; - this.mFusionOutput = tRecipe.mFluidOutputs[0].getLocalizedName(); - } - this.getWorld().addBlockEvent(this.getXCoord(), this.getYCoord(), this.getZCoord(), GregTech_API.sBlockMachines, 11, this.mMaxHeat); - } - - public void switchFusionPageForward() { - if (++this.mMaxHeat >= sFusionReactorRecipes.size()) - this.mMaxHeat = 0; - showFusionRecipe(this.mMaxHeat); - } - - public void switchFusionPageBackward() { - if (--this.mMaxHeat < 0) - this.mMaxHeat = sFusionReactorRecipes.size() - 1; - showFusionRecipe(this.mMaxHeat); - } - - public void switchNuclearReactor() { - if (this.mStarted) { - stopNuclearReactor(); - } - else { - startNuclearReactor(); - } - } - - public void startNuclearReactor() { - this.mStarted = true; - this.mHeat = 0; - this.mEU = 0; - mSimulator.simulate(); - } - - public void stopNuclearReactor() { - this.mStarted = false; - mSimulator.simulate(); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("mMode", this.mMode); - aNBT.setInteger("mProgress", this.mProgress); - aNBT.setInteger("mMaxProgress", this.mMaxProgress); - aNBT.setBoolean("mStarted", this.mStarted); - int[] aSplitLong1 = MathUtils.splitLongIntoTwoIntegers(mEU); - aNBT.setInteger("mEU1", aSplitLong1[0]); - aNBT.setInteger("mEU2", aSplitLong1[1]); - aNBT.setInteger("mHeat", this.mHeat); - int[] aSplitLong2 = MathUtils.splitLongIntoTwoIntegers(mEUOut); - aNBT.setInteger("mEUOut1", aSplitLong2[0]); - aNBT.setInteger("mEUOut2", aSplitLong2[1]); - aNBT.setInteger("mMaxHeat", this.mMaxHeat); - aNBT.setFloat("mHEM", this.mHEM); - aNBT.setFloat("mExplosionStrength", this.mExplosionStrength); - aNBT.setString("mFusionOutput", this.mFusionOutput); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - this.mMode = aNBT.getInteger("mMode"); - this.mProgress = aNBT.getInteger("mProgress"); - this.mMaxProgress = aNBT.getInteger("mMaxProgress"); - this.mStarted = aNBT.getBoolean("mStarted"); - int partA = aNBT.getInteger("mEU1"); - int partB = aNBT.getInteger("mEU2"); - this.mEU = MathUtils.combineTwoIntegersToLong(partA, partB); - this.mHeat = aNBT.getInteger("mHeat"); - partA = aNBT.getInteger("mEUOut1"); - partB = aNBT.getInteger("mEUOut2"); - this.mEUOut = MathUtils.combineTwoIntegersToLong(partA, partB); - this.mMaxHeat = aNBT.getInteger("mMaxHeat"); - this.mHEM = aNBT.getFloat("mHEM"); - this.mExplosionStrength = aNBT.getFloat("mExplosionStrength"); - this.mFusionOutput = aNBT.getString("mFusionOutput"); - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - - if (mSimulator == null) { - mSimulator = new GT_Computercube_Simulator(this); - } - if(this.getBaseMetaTileEntity().isClientSide()) { - this.getWorld().markBlockForUpdate(this.getXCoord(), this.getYCoord(), this.getZCoord()); - this.mNeedsUpdate = false; - } - else { - this.mNeedsUpdate = false; - } - if (this.getBaseMetaTileEntity().isServerSide()) { - if (this.mMode == MODE_SCANNER) { - /*if (this.mInventory[55] == null) { - this.mInventory[55] = this.mInventory[54]; - this.mInventory[54] = null; - }*/ - if (this.mInventory[57] == null) { - this.mInventory[57] = this.mInventory[56]; - this.mInventory[56] = null; - } - - // 54 - 55 || 56 - 57 - // Do scanny bits - if (mSeedscanner && this.mMode == MODE_SCANNER) { - /*if (doScan(this.mInventory[55]) == 4) { - if ((this.mInventory[57] != null) && (this.mInventory[57].getUnlocalizedName().equals("gt.metaitem.01.32707"))) { - GT_Mod.instance.achievements.issueAchievement(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "scanning"); - } - }*/ - /*if (this.mEU > 0) { - if (!this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(this.mEU, false)) { - this.mProgress = 0; - } - }*/ - } - - /*if (mSeedscanner && this.mInventory[55] != null && GT_Utility.areStacksEqual(this.mInventory[55], Ic2Items.cropSeed, true) && this.mInventory[55].getTagCompound() != null) { - if (this.mInventory[55].getTagCompound().getByte("scan") < 4) { - if (this.mProgress >= 100) { - this.mInventory[55].getTagCompound().setByte("scan", (byte) 4); - this.mProgress = 0; - } - else if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(100, false)) { - this.mProgress++; - } - } - else { - this.mProgress = 0; - if (this.mInventory[56] == null) { - this.mInventory[56] = this.mInventory[55]; - this.mInventory[55] = null; - } - } - } - else { - this.mProgress = 0; - if (this.mInventory[56] == null) { - this.mInventory[56] = this.mInventory[55]; - this.mInventory[55] = null; - } - }*/ - } - - if (this.mMode == MODE_REACTOR_PLANNER && mReactorplanner && this.mSimulator != null && this.mSimulator.simulator != null && this.mSimulator.simulatedReactor != null) { - SimulationData aData = this.mSimulator.simulator.getData(); - if (aData != null && aData.totalReactorTicks > 0 && this.mProgress != aData.totalReactorTicks) { - Logger.INFO("Updating Variables"); - this.mEU = aData.avgEUoutput; - this.mEUOut = (aData.totalEUoutput / aData.totalReactorTicks); - this.mHeat = aData.avgHUoutput; - this.mMaxHeat = aData.maxHUoutput; - this.mExplosionStrength = aData.explosionPower; - this.mHEM = (float) aData.hullHeating; - this.mProgress = aData.totalReactorTicks; - } - } - - if (aTick % 20L == 0L) { - this.getWorld().addBlockEvent(this.getXCoord(), this.getYCoord(), this.getZCoord(), GregTech_API.sBlockMachines, 10, this.mMode); - this.getWorld().addBlockEvent(this.getXCoord(), this.getYCoord(), this.getZCoord(), GregTech_API.sBlockMachines, 11, this.mMaxHeat); - } - } - } - - @Override - public void receiveClientEvent(byte aEventID, byte aValue) { - super.receiveClientEvent(aEventID, aValue); - if (this.getWorld().isRemote) - switch (aEventID) { - case 10 : - this.mNeedsUpdate = true; - this.mMode = aValue; - break; - case 11 : - this.mMaxHeat = aValue; - break; - } - return; - } - - @Override - public void onValueUpdate(byte aValue) { - super.onValueUpdate(aValue); - this.mNeedsUpdate = true; - } - - @Override - public void onMachineBlockUpdate() { - super.onMachineBlockUpdate(); - this.mNeedsUpdate = true; - } - - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return (this.mMode == MODE_SCANNER) ? ((i == 54 || i == 55)) : false; - } - - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return (this.mMode == MODE_SCANNER) ? ((i == 56 || i == 57)) : false; - } - - public World getWorld() { - return this.getBaseMetaTileEntity().getWorld(); - } - - @Override - public boolean doesFillContainers() { - return false; - } - - @Override - public boolean doesEmptyContainers() { - return false; - } - - @Override - public boolean canTankBeFilled() { - return false; - } - - @Override - public boolean canTankBeEmptied() { - return false; - } - - @Override - public boolean displaysItemStack() { - return false; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getSides(i); - rTextures[2][i + 1] = this.getSides(i); - rTextures[3][i + 1] = this.getSides(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFront(i); - rTextures[6][i + 1] = this.getSides(i); - rTextures[7][i + 1] = this.getSides(i); - rTextures[8][i + 1] = this.getSides(i); - rTextures[9][i + 1] = this.getSides(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_3)}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Computer_Cube)}; - } - - protected static final int - DID_NOT_FIND_RECIPE = 0, - FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS = 1, - FOUND_AND_SUCCESSFULLY_USED_RECIPE = 2; - /** * Calcualtes overclocked ness using long integers * @param aEUt - recipe EUt * @param aDuration - recipe Duration */ protected void calculateOverclockedNess(int aEUt, int aDuration) { - if(mTier==0){ - //Long time calculation - long xMaxProgresstime = ((long)aDuration)<<1; - if(xMaxProgresstime>Integer.MAX_VALUE-1){ - //make impossible if too long - mEU=Integer.MAX_VALUE-1; - mMaxProgress=Integer.MAX_VALUE-1; - }else{ - mEU=aEUt>>2; - mMaxProgress=(int)xMaxProgresstime; + if (mTier == 0) { + // Long time calculation + long xMaxProgresstime = ((long) aDuration) << 1; + if (xMaxProgresstime > Integer.MAX_VALUE - 1) { + // make impossible if too long + mEU = Integer.MAX_VALUE - 1; + mMaxProgress = Integer.MAX_VALUE - 1; + } else { + mEU = aEUt >> 2; + mMaxProgress = (int) xMaxProgresstime; } - }else{ - //Long EUt calculation - long xEUt=aEUt; - //Isnt too low EUt check? + } else { + // Long EUt calculation + long xEUt = aEUt; + // Isnt too low EUt check? long tempEUt = Math.max(xEUt, V[1]); mMaxProgress = aDuration; - while (tempEUt <= V[mTier -1] * (long)this.maxAmperesIn()) { - tempEUt<<=2;//this actually controls overclocking - //xEUt *= 4;//this is effect of everclocking - mMaxProgress>>=1;//this is effect of overclocking - xEUt = mMaxProgress==0 ? xEUt>>1 : xEUt<<2;//U know, if the time is less than 1 tick make the machine use 2x less power + while (tempEUt <= V[mTier - 1] * (long) this.maxAmperesIn()) { + tempEUt <<= 2; // this actually controls overclocking + // xEUt *= 4;//this is effect of everclocking + mMaxProgress >>= 1; // this is effect of overclocking + xEUt = mMaxProgress == 0 + ? xEUt >> 1 + : xEUt << 2; // U know, if the time is less than 1 tick make the machine use 2x less power } - if(xEUt>Integer.MAX_VALUE-1){ - mEU = Integer.MAX_VALUE-1; - mMaxProgress = Integer.MAX_VALUE-1; - }else{ - mEU = (int)xEUt; - if(mEU==0) - mEU = 1; - if(mMaxProgress==0) - mMaxProgress = 1;//set time to 1 tick + if (xEUt > Integer.MAX_VALUE - 1) { + mEU = Integer.MAX_VALUE - 1; + mMaxProgress = Integer.MAX_VALUE - 1; + } else { + mEU = (int) xEUt; + if (mEU == 0) mEU = 1; + if (mMaxProgress == 0) mMaxProgress = 1; // set time to 1 tick } } } - + public int doScan(ItemStack aInput) { - if (this.mMode != MODE_SCANNER) { - return DID_NOT_FIND_RECIPE; - } + if (this.mMode != MODE_SCANNER) { + return DID_NOT_FIND_RECIPE; + } ItemStack aStack = aInput; if (this.mInventory[56] != null) { return DID_NOT_FIND_RECIPE; } else if ((GT_Utility.isStackValid(aStack)) && (aStack.stackSize > 0)) { - - + if (ItemList.IC2_Crop_Seeds.isStackEqual(aStack, true, true)) { NBTTagCompound tNBT = aStack.getTagCompound(); if (tNBT == null) { @@ -923,7 +967,7 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank { if (tNBT.getByte("scan") < 4) { tNBT.setByte("scan", (byte) 4); calculateOverclockedNess(8, 160); - //In case recipe is too OP for that machine + // In case recipe is too OP for that machine if (mMaxProgress == Integer.MAX_VALUE - 1 && mEU == Integer.MAX_VALUE - 1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; } else { @@ -935,20 +979,24 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank { this.mInventory[57].setTagCompound(tNBT); return 2; } - - + if (ItemList.Tool_DataOrb.isStackEqual(getSpecialSlot(), false, true)) { if (ItemList.Tool_DataOrb.isStackEqual(aStack, false, true)) { aStack.stackSize -= 1; this.mInventory[57] = GT_Utility.copyAmount(1L, getSpecialSlot()); calculateOverclockedNess(30, 512); - //In case recipe is too OP for that machine + // In case recipe is too OP for that machine if (mMaxProgress == Integer.MAX_VALUE - 1 && mEU == Integer.MAX_VALUE - 1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; return 2; } ItemData tData = GT_OreDictUnificator.getAssociation(aStack); - if ((tData != null) && ((tData.mPrefix == OrePrefixes.dust) || (tData.mPrefix == OrePrefixes.cell)) && (tData.mMaterial.mMaterial.mElement != null) && (!tData.mMaterial.mMaterial.mElement.mIsIsotope) && (tData.mMaterial.mMaterial != Materials.Magic) && (tData.mMaterial.mMaterial.getMass() > 0L)) { + if ((tData != null) + && ((tData.mPrefix == OrePrefixes.dust) || (tData.mPrefix == OrePrefixes.cell)) + && (tData.mMaterial.mMaterial.mElement != null) + && (!tData.mMaterial.mMaterial.mElement.mIsIsotope) + && (tData.mMaterial.mMaterial != Materials.Magic) + && (tData.mMaterial.mMaterial.getMass() > 0L)) { getSpecialSlot().stackSize -= 1; aStack.stackSize -= 1; @@ -956,20 +1004,19 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank { Behaviour_DataOrb.setDataTitle(this.mInventory[57], "Elemental-Scan"); Behaviour_DataOrb.setDataName(this.mInventory[57], tData.mMaterial.mMaterial.mElement.name()); calculateOverclockedNess(30, GT_Utility.safeInt(tData.mMaterial.mMaterial.getMass() * 8192L)); - //In case recipe is too OP for that machine + // In case recipe is too OP for that machine if (mMaxProgress == Integer.MAX_VALUE - 1 && mEU == Integer.MAX_VALUE - 1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; return 2; } } - - + if (ItemList.Tool_DataStick.isStackEqual(getSpecialSlot(), false, true)) { if (ItemList.Tool_DataStick.isStackEqual(aStack, false, true)) { aStack.stackSize -= 1; this.mInventory[57] = GT_Utility.copyAmount(1L, getSpecialSlot()); calculateOverclockedNess(30, 128); - //In case recipe is too OP for that machine + // In case recipe is too OP for that machine if (mMaxProgress == Integer.MAX_VALUE - 1 && mEU == Integer.MAX_VALUE - 1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; return 2; @@ -981,7 +1028,7 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank { this.mInventory[57] = GT_Utility.copyAmount(1L, getSpecialSlot()); this.mInventory[57].setTagCompound(aStack.getTagCompound()); calculateOverclockedNess(30, 128); - //In case recipe is too OP for that machine + // In case recipe is too OP for that machine if (mMaxProgress == Integer.MAX_VALUE - 1 && mEU == Integer.MAX_VALUE - 1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; return 2; @@ -991,16 +1038,16 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank { aStack.stackSize -= 1; this.mInventory[57] = GT_Utility.copyAmount(1L, getSpecialSlot()); - this.mInventory[57].setTagCompound(GT_Utility.getNBTContainingShort(new NBTTagCompound(), "map_id", (short) aStack.getItemDamage())); + this.mInventory[57].setTagCompound(GT_Utility.getNBTContainingShort( + new NBTTagCompound(), "map_id", (short) aStack.getItemDamage())); calculateOverclockedNess(30, 128); - //In case recipe is too OP for that machine + // In case recipe is too OP for that machine if (mMaxProgress == Integer.MAX_VALUE - 1 && mEU == Integer.MAX_VALUE - 1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; return 2; } + } - } - if (ItemList.Tool_DataStick.isStackEqual(getSpecialSlot(), false, true) && aStack != null) { for (GT_Recipe.GT_Recipe_AssemblyLine tRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { if (GT_Utility.areStacksEqual(tRecipe.mResearchItem, aStack, true)) { @@ -1014,39 +1061,32 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank { if (failScanner) { return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; } - String s = tRecipe.mOutput.getDisplayName(); if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { s = GT_Assemblyline_Server.lServerNames.get(tRecipe.mOutput.getDisplayName()); - if (s == null) - s = tRecipe.mOutput.getDisplayName(); + if (s == null) s = tRecipe.mOutput.getDisplayName(); } this.mInventory[57] = GT_Utility.copyAmount(1L, getSpecialSlot()); - // Use Assline Utils if (GT_AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(this.mInventory[57], tRecipe)) { - aStack.stackSize -= 1; + aStack.stackSize -= 1; calculateOverclockedNess(30, tRecipe.mResearchTime); - //In case recipe is too OP for that machine + // In case recipe is too OP for that machine if (mMaxProgress == Integer.MAX_VALUE - 1 && mEU == Integer.MAX_VALUE - 1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; getSpecialSlot().stackSize -= 1; return 2; } - } } } - } return 0; } - private ItemStack getSpecialSlot() { - return this.mInventory[54]; - } - - + private ItemStack getSpecialSlot() { + return this.mInventory[54]; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/TileEntitySolarHeater.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/TileEntitySolarHeater.java index 4b73bba6df..cc1592cdaa 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/TileEntitySolarHeater.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/TileEntitySolarHeater.java @@ -8,341 +8,359 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachi import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GregtechMetaTileEntity_SolarTower; -import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; public class TileEntitySolarHeater extends GT_MetaTileEntity_TieredMachineBlock { - public boolean mHasTower = false; - private GregtechMetaTileEntity_SolarTower mTower = null; - - private int mTX, mTY, mTZ; - private Byte mRequiredFacing; - - public TileEntitySolarHeater(final int aID, final String aName, final String aNameRegional, final int aTier, - final String aDescription, final int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); - } - - public TileEntitySolarHeater(final String aName, final int aTier, final String aDescription, - final ITexture[][][] aTextures, final int aSlotCount) { - super(aName, aTier, aSlotCount, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[] { - this.mDescription, - "Point me at a Solar Tower", - CORE.GT_Tooltip }; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 - : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex - + 1]; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) }; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top) }; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LuV) }; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) }; - } - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) }; - } - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top) }; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LuV) }; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), - new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) }; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new TileEntitySolarHeater(this.mName, this.mTier, this.mDescription, this.mTextures, 0); - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public String[] getInfoData() { - return new String[] { - this.getLocalName(), - "Testificate" - }; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { - return false; - } - - public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { - return false; - } - - @Override - public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { - return new int[] {}; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(final int p_70301_1_) { - return null; - } - - @Override - public long maxEUStore() { - return 0; - } - - @Override - public int getCapacity() { - return 0; - } - - @Override - public long maxEUInput() { - return 0; - } - - @Override - public long maxEUOutput() { - return 0; - } - - @Override - public long maxAmperesIn() { - return 0; - } - - @Override - public long maxAmperesOut() { - return 0; - } - - @Override - public boolean isElectric() { - return false; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return false; - } - - @Override - public boolean isFacingValid(final byte aFacing) { - return aFacing >= 2; - } - - @Override - public boolean isEnetInput() { - return false; - } - - @Override - public boolean isEnetOutput() { - return false; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("mHasTower", mHasTower); - if (mHasTower) { - aNBT.setInteger("mTX", mTX); - aNBT.setInteger("mTY", mTY); - aNBT.setInteger("mTZ", mTZ); - } - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - this.mHasTower = aNBT.getBoolean("mHasTower"); - if (this.mHasTower) { - if (aNBT.hasKey("mTX")) - this.mTX = aNBT.getInteger("mTX"); - if (aNBT.hasKey("mTY")) - this.mTY = aNBT.getInteger("mTY"); - if (aNBT.hasKey("mTZ")) - this.mTZ = aNBT.getInteger("mTZ"); - } - } - - @Override - public long getInputTier() { - return 0; - } - - @Override - public long getOutputTier() { - return 0; - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - return false; - } - - @Override - public void onExplosion() { - - } - - public boolean hasSolarTower() { - return mHasTower; - } - - public GregtechMetaTileEntity_SolarTower getSolarTower() { - if (this.mHasTower) { - return mTower; - } - return null; - } - - public boolean canSeeSky() { - if (this.getBaseMetaTileEntity().getWorld().canBlockSeeTheSky(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord())) { - return true; - } - return false; - } - - - public boolean setSolarTower(GregtechMetaTileEntity_SolarTower aTowerTile) { - if (!hasSolarTower()) { - this.mTX = aTowerTile.getBaseMetaTileEntity().getXCoord(); - this.mTY = (int) aTowerTile.getBaseMetaTileEntity().getYCoord(); - this.mTZ = aTowerTile.getBaseMetaTileEntity().getZCoord(); - this.mHasTower = true; - this.mTower = aTowerTile; - return true; - } - return false; - } - - public boolean clearSolarTower() { - if (mHasTower || mRequiredFacing != null || this.mTower != null) { - this.mTX = 0; - this.mTY = 0; - this.mTZ = 0; - this.mRequiredFacing = null; - this.mTower = null; - this.mHasTower = false; - return true; - } - return false; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - - } - - @Override - public void onRemoval() { - super.onRemoval(); - } - - @Override - public boolean isOutputFacing(byte aSide) { - return aSide > 1; - } - - @Override - public boolean isInputFacing(byte aSide) { - return false; - } - - @Override - public long getMinimumStoredEU() { - return 0; - } - - @Override - public void onFacingChange() { - super.onFacingChange(); - } - - @Override - public void doExplosion(long aExplosionPower) { - - } + public boolean mHasTower = false; + private GregtechMetaTileEntity_SolarTower mTower = null; + + private int mTX, mTY, mTZ; + private Byte mRequiredFacing; + + public TileEntitySolarHeater( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public TileEntitySolarHeater( + final String aName, + final int aTier, + final String aDescription, + final ITexture[][][] aTextures, + final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "Point me at a Solar Tower", CORE.GT_Tooltip}; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top)}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LuV) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top)}; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LuV) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) + }; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new TileEntitySolarHeater(this.mName, this.mTier, this.mDescription, this.mTextures, 0); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + return new String[] {this.getLocalName(), "Testificate"}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public long maxEUStore() { + return 0; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing >= 2; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mHasTower", mHasTower); + if (mHasTower) { + aNBT.setInteger("mTX", mTX); + aNBT.setInteger("mTY", mTY); + aNBT.setInteger("mTZ", mTZ); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mHasTower = aNBT.getBoolean("mHasTower"); + if (this.mHasTower) { + if (aNBT.hasKey("mTX")) this.mTX = aNBT.getInteger("mTX"); + if (aNBT.hasKey("mTY")) this.mTY = aNBT.getInteger("mTY"); + if (aNBT.hasKey("mTZ")) this.mTZ = aNBT.getInteger("mTZ"); + } + } + + @Override + public long getInputTier() { + return 0; + } + + @Override + public long getOutputTier() { + return 0; + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return false; + } + + @Override + public void onExplosion() {} + + public boolean hasSolarTower() { + return mHasTower; + } + + public GregtechMetaTileEntity_SolarTower getSolarTower() { + if (this.mHasTower) { + return mTower; + } + return null; + } + + public boolean canSeeSky() { + if (this.getBaseMetaTileEntity() + .getWorld() + .canBlockSeeTheSky( + this.getBaseMetaTileEntity().getXCoord(), + this.getBaseMetaTileEntity().getYCoord(), + this.getBaseMetaTileEntity().getZCoord())) { + return true; + } + return false; + } + + public boolean setSolarTower(GregtechMetaTileEntity_SolarTower aTowerTile) { + if (!hasSolarTower()) { + this.mTX = aTowerTile.getBaseMetaTileEntity().getXCoord(); + this.mTY = (int) aTowerTile.getBaseMetaTileEntity().getYCoord(); + this.mTZ = aTowerTile.getBaseMetaTileEntity().getZCoord(); + this.mHasTower = true; + this.mTower = aTowerTile; + return true; + } + return false; + } + + public boolean clearSolarTower() { + if (mHasTower || mRequiredFacing != null || this.mTower != null) { + this.mTX = 0; + this.mTY = 0; + this.mTZ = 0; + this.mRequiredFacing = null; + this.mTower = null; + this.mHasTower = false; + return true; + } + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onRemoval() { + super.onRemoval(); + } + + @Override + public boolean isOutputFacing(byte aSide) { + return aSide > 1; + } + + @Override + public boolean isInputFacing(byte aSide) { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public void onFacingChange() { + super.onFacingChange(); + } + + @Override + public void doExplosion(long aExplosionPower) {} } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneBase.java index 9bb2443683..2f88c6a784 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneBase.java @@ -12,110 +12,128 @@ import net.minecraft.nbt.NBTTagCompound; public abstract class GT_MetaTileEntity_RedstoneBase extends GT_MetaTileEntity_TieredMachineBlock { - protected int mOpenerCount; - - public GT_MetaTileEntity_RedstoneBase(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, String aDescription, ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); - } - - public GT_MetaTileEntity_RedstoneBase(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, String[] aDescription, ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); - } - - public GT_MetaTileEntity_RedstoneBase(String aName, int aTier, int aInvSlotCount, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aInvSlotCount, aDescription, aTextures); - } - - public GT_MetaTileEntity_RedstoneBase(String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aInvSlotCount, aDescription, aTextures); - } - - @Override - public final boolean isSimpleMachine() { - return false; - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - return aSide != getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public final boolean isValidSlot(int aIndex) { - return false; - } - - @Override - public final boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public final boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public abstract void saveNBTData(NBTTagCompound aNBT); - - @Override - public abstract void loadNBTData(NBTTagCompound aNBT); - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - return false; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, gregtech.api.interfaces.tileentity.IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, gregtech.api.interfaces.tileentity.IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - @Override - public final void onOpenGUI() { - super.onOpenGUI(); - mOpenerCount++; - } - - @Override - public final void onCloseGUI() { - super.onCloseGUI(); - mOpenerCount--; - } - - public boolean hasRedstoneSignal() { - if (getBaseMetaTileEntity().getStrongestRedstone() > 0) { - return true; - } - for (byte i=0;i<6;i++) { - if (getBaseMetaTileEntity().getOutputRedstoneSignal(i) > 0) { - return true; - } - } - return false; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - CORE.GT_Tooltip - }; - } - + protected int mOpenerCount; + + public GT_MetaTileEntity_RedstoneBase( + int aID, + String aName, + String aNameRegional, + int aTier, + int aInvSlotCount, + String aDescription, + ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); + } + + public GT_MetaTileEntity_RedstoneBase( + int aID, + String aName, + String aNameRegional, + int aTier, + int aInvSlotCount, + String[] aDescription, + ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); + } + + public GT_MetaTileEntity_RedstoneBase( + String aName, int aTier, int aInvSlotCount, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + public GT_MetaTileEntity_RedstoneBase( + String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public final boolean isSimpleMachine() { + return false; + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return aSide != getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public final boolean isValidSlot(int aIndex) { + return false; + } + + @Override + public final boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public final boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public abstract void saveNBTData(NBTTagCompound aNBT); + + @Override + public abstract void loadNBTData(NBTTagCompound aNBT); + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + return false; + } + + @Override + public Object getServerGUI( + int aID, + InventoryPlayer aPlayerInventory, + gregtech.api.interfaces.tileentity.IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public Object getClientGUI( + int aID, + InventoryPlayer aPlayerInventory, + gregtech.api.interfaces.tileentity.IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public final void onOpenGUI() { + super.onOpenGUI(); + mOpenerCount++; + } + + @Override + public final void onCloseGUI() { + super.onCloseGUI(); + mOpenerCount--; + } + + public boolean hasRedstoneSignal() { + if (getBaseMetaTileEntity().getStrongestRedstone() > 0) { + return true; + } + for (byte i = 0; i < 6; i++) { + if (getBaseMetaTileEntity().getOutputRedstoneSignal(i) > 0) { + return true; + } + } + return false; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, CORE.GT_Tooltip}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneButtonPanel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneButtonPanel.java index 0c0cc44d93..3cf868a998 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneButtonPanel.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneButtonPanel.java @@ -12,196 +12,250 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_RedstoneButtonPanel extends GT_MetaTileEntity_RedstoneBase { - - public byte mRedstoneStrength = 0, mType = 0, mUpdate = 0; - - public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[64]; - - static { - for (int i=0;i<64;i++) { - sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/ButtonPanel/"+i); - } - } - - public GT_MetaTileEntity_RedstoneButtonPanel(int aID) { - super(aID, "redstone.button.panel", "Button Panel", 5, 0, "Right-click with Screwdriver to change Button Design"); - } - - public GT_MetaTileEntity_RedstoneButtonPanel(final String aName, String aDescription, final ITexture[][][] aTextures) { - super(aName, 5, 0, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneButtonPanel(this.mName, mDescription, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setByte("mRedstoneStrength", mRedstoneStrength); - aNBT.setByte("mType", mType); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mRedstoneStrength = aNBT.getByte("mRedstoneStrength"); - mType = aNBT.getByte("mType"); - } - - @Override - public void onValueUpdate(byte aValue) { - mRedstoneStrength = (byte)(aValue & 15); - mType = (byte)(aValue >>> 4); - } - - @Override - public byte getUpdateData() { - return (byte)((mRedstoneStrength & 15) | (mType << 4)); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { - if (aSide == getBaseMetaTileEntity().getFrontFacing()) { - if (getBaseMetaTileEntity().isServerSide()) { - mUpdate = 2; - switch (mType) { - case 0: default: - switch (aSide) { - case 0: case 1: - mRedstoneStrength = (byte)((byte)( aX*4) + 4 * (byte)( aZ*4)); - break; - case 2: - mRedstoneStrength = (byte)((byte)(4-aX*4) + 4 * (byte)(4-aY*4)); - break; - case 3: - mRedstoneStrength = (byte)((byte)( aX*4) + 4 * (byte)(4-aY*4)); - break; - case 4: - mRedstoneStrength = (byte)((byte)( aZ*4) + 4 * (byte)(4-aY*4)); - break; - case 5: - mRedstoneStrength = (byte)((byte)(4-aZ*4) + 4 * (byte)(4-aY*4)); - break; - } - break; - case 1: - switch (aSide) { - case 0: case 1: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << (((byte)( aX*2) + 2 * (byte)( aZ*2))))); - break; - case 2: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << (((byte)(2-aX*2) + 2 * (byte)(2-aY*2))))); - break; - case 3: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << (((byte)( aX*2) + 2 * (byte)(2-aY*2))))); - break; - case 4: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << (((byte)( aZ*2) + 2 * (byte)(2-aY*2))))); - break; - case 5: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << (((byte)(2-aZ*2) + 2 * (byte)(2-aY*2))))); - break; - } - break; - case 2: - switch (aSide) { - case 0: case 1: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << ((byte)( aZ*4)))); - break; - case 2: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << ((byte)(4-aY*4)))); - break; - case 3: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << ((byte)(4-aY*4)))); - break; - case 4: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << ((byte)(4-aY*4)))); - break; - case 5: - mRedstoneStrength = (byte)(mRedstoneStrength ^ (1 << ((byte)(4-aY*4)))); - break; - } - break; - } - } - return true; - } - return false; - } - - @Override + + public byte mRedstoneStrength = 0, mType = 0, mUpdate = 0; + + public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[64]; + + static { + for (int i = 0; i < 64; i++) { + sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/ButtonPanel/" + i); + } + } + + public GT_MetaTileEntity_RedstoneButtonPanel(int aID) { + super( + aID, + "redstone.button.panel", + "Button Panel", + 5, + 0, + "Right-click with Screwdriver to change Button Design"); + } + + public GT_MetaTileEntity_RedstoneButtonPanel( + final String aName, String aDescription, final ITexture[][][] aTextures) { + super(aName, 5, 0, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_RedstoneButtonPanel(this.mName, mDescription, this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mRedstoneStrength", mRedstoneStrength); + aNBT.setByte("mType", mType); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mRedstoneStrength = aNBT.getByte("mRedstoneStrength"); + mType = aNBT.getByte("mType"); + } + + @Override + public void onValueUpdate(byte aValue) { + mRedstoneStrength = (byte) (aValue & 15); + mType = (byte) (aValue >>> 4); + } + + @Override + public byte getUpdateData() { + return (byte) ((mRedstoneStrength & 15) | (mType << 4)); + } + + @Override + public boolean onRightclick( + IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + if (aSide == getBaseMetaTileEntity().getFrontFacing()) { + if (getBaseMetaTileEntity().isServerSide()) { + mUpdate = 2; + switch (mType) { + case 0: + default: + switch (aSide) { + case 0: + case 1: + mRedstoneStrength = (byte) ((byte) (aX * 4) + 4 * (byte) (aZ * 4)); + break; + case 2: + mRedstoneStrength = (byte) ((byte) (4 - aX * 4) + 4 * (byte) (4 - aY * 4)); + break; + case 3: + mRedstoneStrength = (byte) ((byte) (aX * 4) + 4 * (byte) (4 - aY * 4)); + break; + case 4: + mRedstoneStrength = (byte) ((byte) (aZ * 4) + 4 * (byte) (4 - aY * 4)); + break; + case 5: + mRedstoneStrength = (byte) ((byte) (4 - aZ * 4) + 4 * (byte) (4 - aY * 4)); + break; + } + break; + case 1: + switch (aSide) { + case 0: + case 1: + mRedstoneStrength = + (byte) (mRedstoneStrength ^ (1 << (((byte) (aX * 2) + 2 * (byte) (aZ * 2))))); + break; + case 2: + mRedstoneStrength = (byte) + (mRedstoneStrength ^ (1 << (((byte) (2 - aX * 2) + 2 * (byte) (2 - aY * 2))))); + break; + case 3: + mRedstoneStrength = (byte) + (mRedstoneStrength ^ (1 << (((byte) (aX * 2) + 2 * (byte) (2 - aY * 2))))); + break; + case 4: + mRedstoneStrength = (byte) + (mRedstoneStrength ^ (1 << (((byte) (aZ * 2) + 2 * (byte) (2 - aY * 2))))); + break; + case 5: + mRedstoneStrength = (byte) + (mRedstoneStrength ^ (1 << (((byte) (2 - aZ * 2) + 2 * (byte) (2 - aY * 2))))); + break; + } + break; + case 2: + switch (aSide) { + case 0: + case 1: + mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (aZ * 4)))); + break; + case 2: + mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); + break; + case 3: + mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); + break; + case 4: + mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); + break; + case 5: + mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); + break; + } + break; + } + } + return true; + } + return false; + } + + @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (getBaseMetaTileEntity().isServerSide()) { - getBaseMetaTileEntity().setGenericRedstoneOutput(true); - if (mUpdate > 0) { - mUpdate--; - } - else if (getBaseMetaTileEntity().isAllowedToWork()) { - mRedstoneStrength = 0; - } - for (byte i = 0; i < 6; i++) { - getBaseMetaTileEntity().setStrongOutputRedstoneSignal(i, i == getBaseMetaTileEntity().getFrontFacing()?(byte)0:mRedstoneStrength); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(i, i == getBaseMetaTileEntity().getFrontFacing()?(byte)0:mRedstoneStrength); - } - } - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (aSide == getBaseMetaTileEntity().getFrontFacing()) mType=(byte)((mType+1)%3); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getSides(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFront(i); - rTextures[6][i + 1] = this.getSidesActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], new GT_RenderedTexture(sIconList[mType*16+mRedstoneStrength])}; - } - return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Main_Off)}; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Main_On)}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Main_Off)}; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Main_On)}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Main_Off)}; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Main_On)}; - } + if (getBaseMetaTileEntity().isServerSide()) { + getBaseMetaTileEntity().setGenericRedstoneOutput(true); + if (mUpdate > 0) { + mUpdate--; + } else if (getBaseMetaTileEntity().isAllowedToWork()) { + mRedstoneStrength = 0; + } + for (byte i = 0; i < 6; i++) { + getBaseMetaTileEntity() + .setStrongOutputRedstoneSignal( + i, i == getBaseMetaTileEntity().getFrontFacing() ? (byte) 0 : mRedstoneStrength); + getBaseMetaTileEntity() + .setInternalOutputRedstoneSignal( + i, i == getBaseMetaTileEntity().getFrontFacing() ? (byte) 0 : mRedstoneStrength); + } + } + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aSide == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 3); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getSides(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getSidesActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], + new GT_RenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) + }; + } + return this.mTextures[ + (aActive || hasRedstoneSignal() ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Main_Off) + }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Main_On) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Main_Off) + }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Main_On) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Main_Off) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Main_On) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneCircuitBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneCircuitBlock.java index 379345ec6a..caba805f65 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneCircuitBlock.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneCircuitBlock.java @@ -1,11 +1,7 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; -import java.util.*; - import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; -import gregtech.api.enums.Textures; -import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.IRedstoneCircuitBlock; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; @@ -17,6 +13,7 @@ import gregtech.api.util.*; import gtPlusPlus.xmod.gregtech.api.gui.computer.GT_Container_RedstoneCircuitBlock; import gtPlusPlus.xmod.gregtech.api.gui.computer.GT_GUIContainer_RedstoneCircuitBlock; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.*; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -24,475 +21,482 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -public class GT_MetaTileEntity_RedstoneCircuitBlock extends GT_MetaTileEntity_RedstoneBase implements IRedstoneCircuitBlock { - - public int mGate = 0, mGateData[] = new int[]{0, 0, 0, 0, 0, 0, 0, 0}; - public boolean bOutput = true; - - public GT_MetaTileEntity_RedstoneCircuitBlock(int aID) { - super(aID, "redstone.circuit", "Redstone Circuit Block", 1, 5, "Computes Redstone"); - } - - public GT_MetaTileEntity_RedstoneCircuitBlock(final String aName, String aDescription, final ITexture[][][] aTextures) { - super(aName, 1, 5, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneCircuitBlock(this.mName, mDescription, this.mTextures); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_RedstoneCircuitBlock(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_RedstoneCircuitBlock(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public boolean hasSidedRedstoneOutputBehavior() { - return true; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isInputFacing(byte aSide) { - return !this.isOutputFacing(aSide); - } - - @Override - public boolean isElectric() { - return true; - } - - @Override - public boolean isPneumatic() { - return false; - } - - @Override - public boolean isSteampowered() { - return false; - } - - @Override - public boolean isOutputFacing(byte aSide) { - return aSide == this.getOutputFacing(); - } - - @Override - public long getMinimumStoredEU() { - return 512; - } - - @Override - public long maxEUInput() { - return GT_Values.V[1]; - } - - @Override - public long maxEUOutput() { - return bOutput ? GT_Values.V[1] : 0; - } - - @Override - public long maxAmperesIn() { - return 2; - } - - @Override - public long maxAmperesOut() { - return 1; - } - - @Override - public int getSizeInventory() { - return 5; - } - - @Override - public long maxEUStore() { - return GT_Values.V[3] * 1024; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer, 147); - return true; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mGate", mGate); - aNBT.setIntArray("mGateData", mGateData); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mGate = aNBT.getInteger("mGate"); - mGateData = aNBT.getIntArray("mGateData"); - if (mGateData.length != 8) - mGateData = new int[]{0, 0, 0, 0, 0, 0, 0, 0}; - } - - public void switchOutput() { - bOutput = !bOutput; - } - - public void switchGateForward(boolean aShift) { - try { - Set<Integer> tKeys = GregTech_API.sCircuitryBehaviors.keySet(); - ArrayList<Integer> tList = new ArrayList<Integer>(); - tList.addAll(tKeys); - if (tList.size() <= 0) - return; - Collections.sort(tList); - if (!GregTech_API.sCircuitryBehaviors.containsKey(mGate)) - mGate = tList.get(0); - int tIndex = Collections.binarySearch(tList, mGate); - tIndex += aShift ? 16 : 1; - while (tIndex >= tList.size()) - tIndex -= tList.size(); - mGate = tList.get(tIndex); - switchGate(); - } - catch (Throwable e) { - GT_Log.err.print(e); - } - } - - public void switchGateBackward(boolean aShift) { - try { - Set<Integer> tKeys = GregTech_API.sCircuitryBehaviors.keySet(); - ArrayList<Integer> tList = new ArrayList<Integer>(); - tList.addAll(tKeys); - if (tList.size() <= 0) - return; - Collections.sort(tList); - if (!GregTech_API.sCircuitryBehaviors.containsKey(mGate)) - mGate = tList.get(0); - int tIndex = Collections.binarySearch(tList, mGate); - tIndex -= aShift ? 16 : 1; - while (tIndex < 0) - tIndex += tList.size(); - mGate = tList.get(tIndex); - switchGate(); - } - catch (Throwable e) { - GT_Log.err.print(e); - } - } - - @Override - public void onFacingChange() { - resetRedstone(); - } - - private void resetRedstone() { - getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 0, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 1, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 2, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 3, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 4, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 5, (byte) 0); - } - - public void changeGateData(int aIndex, int aValue) { - mGateData[aIndex] += aValue; - validateGateData(); - } - - public void stackGateData(int aIndex, ItemStack aStack) { - mGateData[aIndex] = GT_Utility.stackToInt(aStack); - validateGateData(); - } - - private void switchGate() { - resetRedstone(); - for (int i = 0; i < mGateData.length; i++) - mGateData[i] = 0; - GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tBehaviour != null) - try { - tBehaviour.initParameters(mGateData, this); - } - catch (Throwable e) { - GT_Log.err.print(e); - } - validateGateData(); - } - - private void validateGateData() { - GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tBehaviour != null) - try { - tBehaviour.validateParameters(mGateData, this); - } - catch (Throwable e) { - GT_Log.err.print(e); - } - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - getBaseMetaTileEntity().setGenericRedstoneOutput(true); - validateGateData(); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - getBaseMetaTileEntity().setGenericRedstoneOutput(true); - if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { - mInventory[0] = mInventory[1] = mInventory[2] = mInventory[3] = mInventory[4] = null; - if (getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU()) { - if (getBaseMetaTileEntity().isActive()) { - GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tBehaviour != null) { - try { - tBehaviour.onTick(mGateData, this); - if (tBehaviour.displayItemStack(mGateData, this, 0)) - mInventory[1] = getCoverByID(mGateData[0]); - if (tBehaviour.displayItemStack(mGateData, this, 1)) - mInventory[2] = getCoverByID(mGateData[1]); - if (tBehaviour.displayItemStack(mGateData, this, 2)) - mInventory[3] = getCoverByID(mGateData[2]); - if (tBehaviour.displayItemStack(mGateData, this, 3)) - mInventory[4] = getCoverByID(mGateData[3]); - } - catch (Throwable e) { - GT_Log.err.print(e); - } - } - } - getBaseMetaTileEntity().setErrorDisplayID(0); - } - else { - getBaseMetaTileEntity().setErrorDisplayID(1); - } - } - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - //Only Calc server-side - if (!this.getBaseMetaTileEntity().isServerSide()) { - return; - } - //Emit Redstone - for (byte i=0;i<6;i++) { - byte aRedstone = getBaseMetaTileEntity().getOutputRedstoneSignal(i); - this.getBaseMetaTileEntity().setInternalOutputRedstoneSignal(i, aRedstone); - } - - } - - @Override - public final boolean hasRedstoneSignal() { - for (byte i=0;i<6;i++) { - if (getBaseMetaTileEntity().getOutputRedstoneSignal(i) > 0) { - return true; - } - } - return false; - } - - @Override - public boolean allowGeneralRedstoneOutput() { - return true; - } - - /** The Item List for Covers */ - public static final Map<Integer, ItemStack> sCoversItems = new HashMap<Integer, ItemStack>(); - - private static void initCovers() { - for (GT_ItemStack aKey : GregTech_API.sCovers.keySet()) { - ItemStack aStack = aKey.toStack().copy(); - if (aStack != null) { - sCoversItems.put(GT_Utility.stackToInt(aStack), aStack); - } - } - } - - public static ItemStack getCoverByID(int aStack) { - if (sCoversItems.isEmpty()) { - initCovers(); - } - return sCoversItems.get(Integer.valueOf(aStack)); - } - - @Override - public byte getOutputFacing() { - return getBaseMetaTileEntity().getBackFacing(); - } - - @Override - public boolean setRedstone(byte aStrength, byte aSide) { - if (getOutputRedstone(aSide) != aStrength) { - if (getBaseMetaTileEntity().decreaseStoredEnergyUnits(1, false)) { - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(aSide, aStrength); - getBaseMetaTileEntity().setErrorDisplayID(0); - return true; - } - else { - getBaseMetaTileEntity().setErrorDisplayID(1); - return false; - } - } - return false; - } - - /* @Override - public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { - if (aSide == getOutputFacing()) { - if (aSide == 0) - return aRedstone ? 56 : 54; - if (aSide == 1) - return aRedstone ? 53 : 52; - return aRedstone ? 94 : 93; - } - if (aSide == 0) - return aRedstone ? 60 : 59; - if (aSide == 1) - return aRedstone ? 58 : 57; - return aRedstone ? 62 : 61; - }*/ - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public byte getOutputRedstone(byte aSide) { - return getBaseMetaTileEntity().getOutputRedstoneSignal(aSide); - } - - @Override - public byte getInputRedstone(byte aSide) { - return getBaseMetaTileEntity().getInternalInputRedstoneSignal(aSide); - } - - @Override - public Block getBlockAtSide(byte aSide) { - return getBaseMetaTileEntity().getBlockAtSide(aSide); - } - - @Override - public byte getMetaIDAtSide(byte aSide) { - return getBaseMetaTileEntity().getMetaIDAtSide(aSide); - } - - @Override - public TileEntity getTileEntityAtSide(byte aSide) { - return getBaseMetaTileEntity().getTileEntityAtSide(aSide); - } - - @Override - public int getRandom(int aRange) { - return getBaseMetaTileEntity().getRandomNumber(aRange); - } - - @Override - public GT_CoverBehavior getCover(byte aSide) { - return getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide); - } - - @Override - public int getCoverID(byte aSide) { - return getBaseMetaTileEntity().getCoverIDAtSide(aSide); - } - - @Override - public int getCoverVariable(byte aSide) { - return getBaseMetaTileEntity().getCoverDataAtSide(aSide); - } - - @Override - public ICoverable getOwnTileEntity() { - return getBaseMetaTileEntity(); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getSides(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getSidesActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex - + 1]; - } - - private GT_RenderedTexture getBase() { - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Off)}; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_On)}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[] {getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off), new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red)}; - } - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[] {getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On), new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red_Redstone)}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Off)}; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_On)}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off)}; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On)}; - } - +public class GT_MetaTileEntity_RedstoneCircuitBlock extends GT_MetaTileEntity_RedstoneBase + implements IRedstoneCircuitBlock { + + public int mGate = 0, mGateData[] = new int[] {0, 0, 0, 0, 0, 0, 0, 0}; + public boolean bOutput = true; + + public GT_MetaTileEntity_RedstoneCircuitBlock(int aID) { + super(aID, "redstone.circuit", "Redstone Circuit Block", 1, 5, "Computes Redstone"); + } + + public GT_MetaTileEntity_RedstoneCircuitBlock( + final String aName, String aDescription, final ITexture[][][] aTextures) { + super(aName, 1, 5, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_RedstoneCircuitBlock(this.mName, mDescription, this.mTextures); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_RedstoneCircuitBlock(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_RedstoneCircuitBlock(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public boolean hasSidedRedstoneOutputBehavior() { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isInputFacing(byte aSide) { + return !this.isOutputFacing(aSide); + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isPneumatic() { + return false; + } + + @Override + public boolean isSteampowered() { + return false; + } + + @Override + public boolean isOutputFacing(byte aSide) { + return aSide == this.getOutputFacing(); + } + + @Override + public long getMinimumStoredEU() { + return 512; + } + + @Override + public long maxEUInput() { + return GT_Values.V[1]; + } + + @Override + public long maxEUOutput() { + return bOutput ? GT_Values.V[1] : 0; + } + + @Override + public long maxAmperesIn() { + return 2; + } + + @Override + public long maxAmperesOut() { + return 1; + } + + @Override + public int getSizeInventory() { + return 5; + } + + @Override + public long maxEUStore() { + return GT_Values.V[3] * 1024; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer, 147); + return true; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mGate", mGate); + aNBT.setIntArray("mGateData", mGateData); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mGate = aNBT.getInteger("mGate"); + mGateData = aNBT.getIntArray("mGateData"); + if (mGateData.length != 8) mGateData = new int[] {0, 0, 0, 0, 0, 0, 0, 0}; + } + + public void switchOutput() { + bOutput = !bOutput; + } + + public void switchGateForward(boolean aShift) { + try { + Set<Integer> tKeys = GregTech_API.sCircuitryBehaviors.keySet(); + ArrayList<Integer> tList = new ArrayList<Integer>(); + tList.addAll(tKeys); + if (tList.size() <= 0) return; + Collections.sort(tList); + if (!GregTech_API.sCircuitryBehaviors.containsKey(mGate)) mGate = tList.get(0); + int tIndex = Collections.binarySearch(tList, mGate); + tIndex += aShift ? 16 : 1; + while (tIndex >= tList.size()) tIndex -= tList.size(); + mGate = tList.get(tIndex); + switchGate(); + } catch (Throwable e) { + GT_Log.err.print(e); + } + } + + public void switchGateBackward(boolean aShift) { + try { + Set<Integer> tKeys = GregTech_API.sCircuitryBehaviors.keySet(); + ArrayList<Integer> tList = new ArrayList<Integer>(); + tList.addAll(tKeys); + if (tList.size() <= 0) return; + Collections.sort(tList); + if (!GregTech_API.sCircuitryBehaviors.containsKey(mGate)) mGate = tList.get(0); + int tIndex = Collections.binarySearch(tList, mGate); + tIndex -= aShift ? 16 : 1; + while (tIndex < 0) tIndex += tList.size(); + mGate = tList.get(tIndex); + switchGate(); + } catch (Throwable e) { + GT_Log.err.print(e); + } + } + + @Override + public void onFacingChange() { + resetRedstone(); + } + + private void resetRedstone() { + getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 0, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 1, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 2, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 3, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 4, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal((byte) 5, (byte) 0); + } + + public void changeGateData(int aIndex, int aValue) { + mGateData[aIndex] += aValue; + validateGateData(); + } + + public void stackGateData(int aIndex, ItemStack aStack) { + mGateData[aIndex] = GT_Utility.stackToInt(aStack); + validateGateData(); + } + + private void switchGate() { + resetRedstone(); + for (int i = 0; i < mGateData.length; i++) mGateData[i] = 0; + GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); + if (tBehaviour != null) + try { + tBehaviour.initParameters(mGateData, this); + } catch (Throwable e) { + GT_Log.err.print(e); + } + validateGateData(); + } + + private void validateGateData() { + GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); + if (tBehaviour != null) + try { + tBehaviour.validateParameters(mGateData, this); + } catch (Throwable e) { + GT_Log.err.print(e); + } + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + getBaseMetaTileEntity().setGenericRedstoneOutput(true); + validateGateData(); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + getBaseMetaTileEntity().setGenericRedstoneOutput(true); + if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { + mInventory[0] = mInventory[1] = mInventory[2] = mInventory[3] = mInventory[4] = null; + if (getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU()) { + if (getBaseMetaTileEntity().isActive()) { + GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); + if (tBehaviour != null) { + try { + tBehaviour.onTick(mGateData, this); + if (tBehaviour.displayItemStack(mGateData, this, 0)) + mInventory[1] = getCoverByID(mGateData[0]); + if (tBehaviour.displayItemStack(mGateData, this, 1)) + mInventory[2] = getCoverByID(mGateData[1]); + if (tBehaviour.displayItemStack(mGateData, this, 2)) + mInventory[3] = getCoverByID(mGateData[2]); + if (tBehaviour.displayItemStack(mGateData, this, 3)) + mInventory[4] = getCoverByID(mGateData[3]); + } catch (Throwable e) { + GT_Log.err.print(e); + } + } + } + getBaseMetaTileEntity().setErrorDisplayID(0); + } else { + getBaseMetaTileEntity().setErrorDisplayID(1); + } + } + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + // Only Calc server-side + if (!this.getBaseMetaTileEntity().isServerSide()) { + return; + } + // Emit Redstone + for (byte i = 0; i < 6; i++) { + byte aRedstone = getBaseMetaTileEntity().getOutputRedstoneSignal(i); + this.getBaseMetaTileEntity().setInternalOutputRedstoneSignal(i, aRedstone); + } + } + + @Override + public final boolean hasRedstoneSignal() { + for (byte i = 0; i < 6; i++) { + if (getBaseMetaTileEntity().getOutputRedstoneSignal(i) > 0) { + return true; + } + } + return false; + } + + @Override + public boolean allowGeneralRedstoneOutput() { + return true; + } + + /** The Item List for Covers */ + public static final Map<Integer, ItemStack> sCoversItems = new HashMap<Integer, ItemStack>(); + + private static void initCovers() { + for (GT_ItemStack aKey : GregTech_API.sCovers.keySet()) { + ItemStack aStack = aKey.toStack().copy(); + if (aStack != null) { + sCoversItems.put(GT_Utility.stackToInt(aStack), aStack); + } + } + } + + public static ItemStack getCoverByID(int aStack) { + if (sCoversItems.isEmpty()) { + initCovers(); + } + return sCoversItems.get(Integer.valueOf(aStack)); + } + + @Override + public byte getOutputFacing() { + return getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean setRedstone(byte aStrength, byte aSide) { + if (getOutputRedstone(aSide) != aStrength) { + if (getBaseMetaTileEntity().decreaseStoredEnergyUnits(1, false)) { + getBaseMetaTileEntity().setInternalOutputRedstoneSignal(aSide, aStrength); + getBaseMetaTileEntity().setErrorDisplayID(0); + return true; + } else { + getBaseMetaTileEntity().setErrorDisplayID(1); + return false; + } + } + return false; + } + + /* @Override + public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { + if (aSide == getOutputFacing()) { + if (aSide == 0) + return aRedstone ? 56 : 54; + if (aSide == 1) + return aRedstone ? 53 : 52; + return aRedstone ? 94 : 93; + } + if (aSide == 0) + return aRedstone ? 60 : 59; + if (aSide == 1) + return aRedstone ? 58 : 57; + return aRedstone ? 62 : 61; + }*/ + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public byte getOutputRedstone(byte aSide) { + return getBaseMetaTileEntity().getOutputRedstoneSignal(aSide); + } + + @Override + public byte getInputRedstone(byte aSide) { + return getBaseMetaTileEntity().getInternalInputRedstoneSignal(aSide); + } + + @Override + public Block getBlockAtSide(byte aSide) { + return getBaseMetaTileEntity().getBlockAtSide(aSide); + } + + @Override + public byte getMetaIDAtSide(byte aSide) { + return getBaseMetaTileEntity().getMetaIDAtSide(aSide); + } + + @Override + public TileEntity getTileEntityAtSide(byte aSide) { + return getBaseMetaTileEntity().getTileEntityAtSide(aSide); + } + + @Override + public int getRandom(int aRange) { + return getBaseMetaTileEntity().getRandomNumber(aRange); + } + + @Override + public GT_CoverBehavior getCover(byte aSide) { + return getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide); + } + + @Override + public int getCoverID(byte aSide) { + return getBaseMetaTileEntity().getCoverIDAtSide(aSide); + } + + @Override + public int getCoverVariable(byte aSide) { + return getBaseMetaTileEntity().getCoverDataAtSide(aSide); + } + + @Override + public ICoverable getOwnTileEntity() { + return getBaseMetaTileEntity(); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getSides(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getSidesActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive || hasRedstoneSignal() ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + private GT_RenderedTexture getBase() { + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Off)}; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] {getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_On)}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + getBase(), + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off), + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red) + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + getBase(), + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On), + new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red_Redstone) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Off)}; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] {getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_On)}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off)}; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] {getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On)}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneLamp.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneLamp.java index 81517c83b9..dfb844654b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneLamp.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneLamp.java @@ -10,66 +10,67 @@ import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_RedstoneLamp extends GT_MetaTileEntity_RedstoneBase { - public byte mRedstoneStrength = 0, mType = 0; - public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[2]; - - static { - sIconList[0] = new CustomIcon("TileEntities/gt4/redstone/Lamp/off"); - sIconList[1] = new CustomIcon("TileEntities/gt4/redstone/Lamp/on"); - } - - public GT_MetaTileEntity_RedstoneLamp(int aID) { - super(aID, "redstone.lamp", "Redstone Controlled Lamp", 0, 0, "Redstone Controlled Lamp"); - } + public byte mRedstoneStrength = 0, mType = 0; + public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[2]; + + static { + sIconList[0] = new CustomIcon("TileEntities/gt4/redstone/Lamp/off"); + sIconList[1] = new CustomIcon("TileEntities/gt4/redstone/Lamp/on"); + } + + public GT_MetaTileEntity_RedstoneLamp(int aID) { + super(aID, "redstone.lamp", "Redstone Controlled Lamp", 0, 0, "Redstone Controlled Lamp"); + } + + public GT_MetaTileEntity_RedstoneLamp(final String aName, String aDescription, final ITexture[][][] aTextures) { + super(aName, 0, 0, aDescription, aTextures); + } - public GT_MetaTileEntity_RedstoneLamp(final String aName, String aDescription, final ITexture[][][] aTextures) { - super(aName, 0, 0, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneLamp(this.mName, mDescription, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - - } - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { - getBaseMetaTileEntity().setLightValue(getBaseMetaTileEntity().getStrongestRedstone()); - getBaseMetaTileEntity().setActive(getBaseMetaTileEntity().getStrongestRedstone()>0); - } + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_RedstoneLamp(this.mName, mDescription, this.mTextures); } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getSides(i); - rTextures[1][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 1 : 0)][aColorIndex + 1]; - } + @Override + public void saveNBTData(NBTTagCompound aNBT) {} + + @Override + public void loadNBTData(NBTTagCompound aNBT) {} - public ITexture[] getSides(final byte aColor) { - return new ITexture[] {new GT_RenderedTexture(sIconList[0])}; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] {new GT_RenderedTexture(sIconList[1])}; - } - + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { + getBaseMetaTileEntity().setLightValue(getBaseMetaTileEntity().getStrongestRedstone()); + getBaseMetaTileEntity().setActive(getBaseMetaTileEntity().getStrongestRedstone() > 0); + } + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getSides(i); + rTextures[1][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[(aActive ? 1 : 0)][aColorIndex + 1]; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(sIconList[0])}; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(sIconList[1])}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthDisplay.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthDisplay.java index 1f65385793..3b07f8b3ff 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthDisplay.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthDisplay.java @@ -1,7 +1,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; import gregtech.api.enums.Textures; -import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -14,131 +13,164 @@ import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_RedstoneStrengthDisplay extends GT_MetaTileEntity_RedstoneBase { - public byte mRedstoneStrength = 0, mType = 0; - public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[144]; - - static { - for (int i=0;i<144;i++) { - sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/Display/"+i); - } - } - - public GT_MetaTileEntity_RedstoneStrengthDisplay(int aID, String aUnlocal, String aLocal, String aDescription) { - super(aID, aUnlocal, aLocal, 5, 0, aDescription); - } - - public GT_MetaTileEntity_RedstoneStrengthDisplay(final String aName, String aDescription, final ITexture[][][] aTextures) { - super(aName, 5, 0, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneStrengthDisplay(this.mName, mDescription, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setByte("mRedstoneStrength", mRedstoneStrength); - aNBT.setByte("mType", mType); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mRedstoneStrength = aNBT.getByte("mRedstoneStrength"); - mType = aNBT.getByte("mType"); - } - - @Override - public void onValueUpdate(byte aValue) { - mRedstoneStrength = (byte) (aValue & 15); - mType = (byte) (aValue >>> 4); - } - - @Override - public byte getUpdateData() { - return (byte) ((mRedstoneStrength & 15) | (mType << 4)); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { - mRedstoneStrength = getBaseMetaTileEntity().getStrongestRedstone(); - } - } - - /*@Override - public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { - if (aSide == 0) - return aRedstone ? 60 : 59; - if (aSide == 1) - return aRedstone ? 58 : 57; - return aRedstone ? 62 : 61; - }*/ - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (aSide == getBaseMetaTileEntity().getFrontFacing()) - mType = (byte) ((mType + 1) % 6); - } - - /*@Override - public IIcon getTextureIcon(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { - return aSide == aFacing ? sIconList[mType * 16 + mRedstoneStrength] : null; - }*/ - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getSides(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFront(i); - rTextures[6][i + 1] = this.getSidesActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], new GT_RenderedTexture(sIconList[mType * 16 + mRedstoneStrength])}; - } - return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Off)}; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_On)}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Off)}; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_On)}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off)}; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On)}; - } - + public byte mRedstoneStrength = 0, mType = 0; + public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[144]; + + static { + for (int i = 0; i < 144; i++) { + sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/Display/" + i); + } + } + + public GT_MetaTileEntity_RedstoneStrengthDisplay(int aID, String aUnlocal, String aLocal, String aDescription) { + super(aID, aUnlocal, aLocal, 5, 0, aDescription); + } + + public GT_MetaTileEntity_RedstoneStrengthDisplay( + final String aName, String aDescription, final ITexture[][][] aTextures) { + super(aName, 5, 0, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_RedstoneStrengthDisplay(this.mName, mDescription, this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mRedstoneStrength", mRedstoneStrength); + aNBT.setByte("mType", mType); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mRedstoneStrength = aNBT.getByte("mRedstoneStrength"); + mType = aNBT.getByte("mType"); + } + + @Override + public void onValueUpdate(byte aValue) { + mRedstoneStrength = (byte) (aValue & 15); + mType = (byte) (aValue >>> 4); + } + + @Override + public byte getUpdateData() { + return (byte) ((mRedstoneStrength & 15) | (mType << 4)); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { + mRedstoneStrength = getBaseMetaTileEntity().getStrongestRedstone(); + } + } + + /*@Override + public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { + if (aSide == 0) + return aRedstone ? 60 : 59; + if (aSide == 1) + return aRedstone ? 58 : 57; + return aRedstone ? 62 : 61; + }*/ + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aSide == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 6); + } + + /*@Override + public IIcon getTextureIcon(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { + return aSide == aFacing ? sIconList[mType * 16 + mRedstoneStrength] : null; + }*/ + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getSides(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getSidesActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], + new GT_RenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) + }; + } + return this.mTextures[ + (aActive || hasRedstoneSignal() ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Off) + }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_On) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Off) + }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_On) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthScale.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthScale.java index efa3763370..8945f3f7b5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthScale.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthScale.java @@ -12,39 +12,54 @@ import net.minecraft.entity.player.EntityPlayer; public class GT_MetaTileEntity_RedstoneStrengthScale extends GT_MetaTileEntity_RedstoneStrengthDisplay { - public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[32]; - - static { - for (int i=0;i<32;i++) { - sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/Scale/"+i); - } - } - - public GT_MetaTileEntity_RedstoneStrengthScale(int aID) { - super(aID, "redstone.display.scale", "Redstone Scale", "Redstone Strength on a Scale"); - } - - public GT_MetaTileEntity_RedstoneStrengthScale(final String aName, String aDescription, final ITexture[][][] aTextures) { - super(aName, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneStrengthScale(this.mName, mDescription, this.mTextures); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (aSide == getBaseMetaTileEntity().getFrontFacing()) - mType = (byte) ((mType + 1) % 2); - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], new GT_RenderedTexture(sIconList[mType * 16 + mRedstoneStrength])}; - } - return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } + public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[32]; + static { + for (int i = 0; i < 32; i++) { + sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/Scale/" + i); + } + } + + public GT_MetaTileEntity_RedstoneStrengthScale(int aID) { + super(aID, "redstone.display.scale", "Redstone Scale", "Redstone Strength on a Scale"); + } + + public GT_MetaTileEntity_RedstoneStrengthScale( + final String aName, String aDescription, final ITexture[][][] aTextures) { + super(aName, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_RedstoneStrengthScale(this.mName, mDescription, this.mTextures); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aSide == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 2); + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], + new GT_RenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) + }; + } + return this.mTextures[ + (aActive || hasRedstoneSignal() ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_AdvancedCraftingTable.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_AdvancedCraftingTable.java index 0b815bfae7..bb9865c8e5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_AdvancedCraftingTable.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_AdvancedCraftingTable.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage; -import java.util.ArrayList; - import gregtech.api.enums.GT_Values; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -17,6 +15,7 @@ import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.gui.workbench.GT_Container_AdvancedWorkbench; import gtPlusPlus.xmod.gregtech.api.gui.workbench.GT_GUIContainer_AdvancedWorkbench; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -25,527 +24,547 @@ import net.minecraft.nbt.NBTTagList; public class GT_MetaTileEntity_AdvancedCraftingTable extends GT_MetaTileEntity_BasicTank { - public boolean mFlushMode = false; - - protected String mLocalName; - - public GT_MetaTileEntity_AdvancedCraftingTable(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription) { - super(aID, aName, aNameRegional, aTier, 35, aDescription); - mLocalName = aNameRegional; - } - - public GT_MetaTileEntity_AdvancedCraftingTable(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, 35, aDescription, aTextures); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_AdvancedWorkbench(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_AdvancedWorkbench(aPlayerInventory, aBaseMetaTileEntity, mLocalName); - } - - @Override - public boolean isTransformerUpgradable() { - return true; - } - @Override - public boolean isSimpleMachine() { - return true; - } - @Override - public boolean isValidSlot(int aIndex) { - return aIndex < 31 || aIndex > 32; - } - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - @Override - public boolean isEnetInput() { - return isElectric(); - } - @Override - public boolean isInputFacing(byte aSide) { - return true; - } - @Override - public long maxEUInput() { - return isElectric() ? GT_Values.V[3] : 0; - } - @Override - public long maxEUStore() { - return isElectric() ? GT_Values.V[3] * 1024 : 0; - } - - @Override - public boolean isElectric() { - return isAdvanced(); - } - - @Override - public boolean isPneumatic() { - return false; - } - - @Override - public boolean isSteampowered() { - return false; - } - - @Override - public long maxAmperesIn() { - return isElectric() ? 2 : 0; - } - - @Override - public long getMinimumStoredEU() { - return isElectric() ? GT_Values.V[3] * 2 : 0; - } - - @Override - public int getSizeInventory() { - return 35; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_AdvancedCraftingTable(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public boolean doesFillContainers() { - return false; - } - @Override - public boolean doesEmptyContainers() { - return false; - } - @Override - public boolean canTankBeFilled() { - return true; - } - @Override - public boolean canTankBeEmptied() { - return true; - } - @Override - public boolean displaysItemStack() { - return false; - } - @Override - public boolean displaysStackSize() { - return false; - } - - public void sortIntoTheInputSlots() { - for (byte i = 21; i < 30; i++) - if (mInventory[i] != null) { - if (mInventory[i].stackSize == 0) { - mInventory[i] = null; - } - if (mInventory[i] != null) - for (byte j = 0; j < 16; j++) { - if (GT_Utility.areStacksEqual( - mInventory[i], mInventory[j] - )) { - GT_Utility.moveStackFromSlotAToSlotB( - getBaseMetaTileEntity(), getBaseMetaTileEntity(), i, j, (byte) 64, (byte) 1, (byte) 64, (byte) 1 - ); - } - } - if (mInventory[i] != null) - for (byte j = 0; j < 16; j++) { - if (mInventory[j] == null) { - GT_Utility.moveStackFromSlotAToSlotB( - getBaseMetaTileEntity(), getBaseMetaTileEntity(), i, j, (byte) 64, (byte) 1, (byte) 64, (byte) 1 - ); - } - } - } - } - - private void fillLiquidContainers() { - for (byte i = 16; i < 21 && mFluid != null; i++) { - ItemStack tOutput = GT_Utility.fillFluidContainer(mFluid, mInventory[i], false, true); - if (tOutput != null) { - if (mInventory[i].stackSize == 1) { - mFluid.amount -= GT_Utility.getFluidForFilledItem( - tOutput, true - ).amount * tOutput.stackSize; - mInventory[i] = tOutput; - } - else - for (byte j = 16; j < 21; j++) { - if (mInventory[j] == null || (GT_Utility.areStacksEqual( - tOutput, mInventory[j] - ) && mInventory[j].stackSize - + tOutput.stackSize <= tOutput.getMaxStackSize())) { - mFluid.amount -= GT_Utility.getFluidForFilledItem( - tOutput, true - ).amount * tOutput.stackSize; - getBaseMetaTileEntity().decrStackSize(i, 1); - if (mInventory[j] == null) { - mInventory[j] = tOutput; - } - else { - mInventory[j].stackSize++; - } - break; - } - } - if (mFluid != null && mFluid.amount <= 0) - mFluid = null; - } - } - if (mFluid != null && mFluid.amount <= 0) - mFluid = null; - } - - public void setBluePrint(ItemStack aStack) { - if (aStack == null) { - aStack = mInventory[30]; - Logger.INFO("Using Slot 30 supply."); - } - if (mInventory[31] == null || aStack == null || aStack.getItem() == null - || aStack.getItemDamage() != 0 || aStack.stackSize != 1 - || !(aStack.getItem() instanceof ItemBlueprint)) { - try { - Logger.INFO( - "Could not set Blueprint. Slot 31: " - + (mInventory[31] != null ? mInventory[31].getDisplayName() : "Null") - + ", aStack: "+(aStack != null ? aStack.getDisplayName() : "Null") - + ", Damage: "+(aStack != null ? aStack.getItemDamage() : "Null")); - } - catch (Throwable t) { - t.printStackTrace(); - } - return; - } - if (!aStack.getTagCompound().hasKey("Inventory")) { - NBTTagCompound tNBT = new NBTTagCompound(); - NBTTagList tNBT_ItemList = new NBTTagList(); - for (int i = 0; i < 9; i++) { - ItemStack tStack = mInventory[i + 21]; - if (tStack != null) { - NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("Slot", (byte) i); - tStack.writeToNBT(tag); - tNBT_ItemList.appendTag(tag); - } - } - tNBT.setTag("Inventory", tNBT_ItemList); - tNBT.setBoolean("mBlueprint", true); - tNBT.setInteger("mID", MathUtils.randInt(1, Short.MAX_VALUE)); - tNBT.setString("mName", mInventory[31].getDisplayName()); - aStack.setTagCompound(tNBT); - Logger.INFO("Set NBT of crafting table to Stack in slot 30."); - } - else { - Logger.INFO("Blueprint already has recipe tags."); - } - - } - - public ItemStack getCraftingOutput() { - if (mInventory[30] != null && mInventory[30].getItem() != null - && mInventory[30].getItemDamage() == 0 - && mInventory[30].hasTagCompound() && mInventory[30].getItem() instanceof ItemBlueprint) { - //Logger.INFO("Getting Blueprint Data in slot 30. "+mInventory[30].getDisplayName()); - NBTTagCompound tNBT = mInventory[30].getTagCompound(); - NBTTagList tNBT_ItemList = tNBT.getTagList("Blueprint", 10); - for (int i = 0; i < tNBT_ItemList.tagCount() && i < 9; i++) { - NBTTagCompound tag = (NBTTagCompound) tNBT_ItemList.getCompoundTagAt( - i - ); - byte slot = tag.getByte("Slot"); - if (slot >= 0 && slot < 9 && mInventory[slot + 21] == null) { - mInventory[slot + 21] = GT_Utility.loadItem(tag); - if (mInventory[slot + 21] != null) - mInventory[slot + 21].stackSize = 0; - } - } - } - mInventory[31] = GT_ModHandler.getAllRecipeOutput( - getBaseMetaTileEntity().getWorld(), new ItemStack[]{ - mInventory[21], mInventory[22], mInventory[23], - mInventory[24], mInventory[25], mInventory[26], - mInventory[27], mInventory[28], mInventory[29] - } - ); - return mInventory[31]; - } - - public boolean canDoCraftingOutput() { - if (mInventory[31] == null) - return false; - for (ItemStack tStack : recipeContent()) { - if (tStack.stackSize > getAmountOf(tStack)) { - return false; - } - } - return true; - } - - private int getAmountOf(ItemStack aStack) { - int tAmount = 0; - for (byte i = 0; i < 30 && tAmount < 9; i++) { - if (GT_Utility.areStacksOrToolsEqual(aStack, mInventory[i])) { - tAmount += mInventory[i].stackSize; - } - } - return tAmount; - } - - private ArrayList<ItemStack> recipeContent() { - ArrayList<ItemStack> tList = new ArrayList<ItemStack>(); - for (byte i = 21; i < 30; i++) { - if (mInventory[i] != null) { - boolean temp = false; - for (byte j = 0; j < tList.size(); j++) { - if (GT_Utility.areStacksOrToolsEqual( - mInventory[i], tList.get(j) - )) { - tList.get(j).stackSize++; - temp = true; - break; - } - } - if (!temp) - tList.add(GT_Utility.copy(1, mInventory[i])); - } - } - return tList; - } - - public ItemStack consumeMaterials(EntityPlayer aPlayer, ItemStack aHoldStack) { - if (mInventory[31] == null) - return aHoldStack; - if (aHoldStack != null) { - if (!GT_Utility.areStacksEqual(aHoldStack, mInventory[31])) - return aHoldStack; - if (aHoldStack.stackSize - + mInventory[31].stackSize > aHoldStack.getMaxStackSize()) - return aHoldStack; - } - for (byte i = 21; i < 30; i++) - if (mInventory[i] != null) { - for (byte j = 0; j <= i; j++) { - if (j < 21 || j == i) { - if (GT_Utility.areStacksOrToolsEqual( - mInventory[i], mInventory[j] - ) && mInventory[j].stackSize > 0) { - ItemStack tStack = GT_Utility.getContainerItem( - mInventory[j], true - ); - if (tStack == null - || (tStack.isItemStackDamageable() - && tStack.getItemDamage() >= tStack.getMaxDamage())) { - getBaseMetaTileEntity().decrStackSize(j, 1); - } - else if (mInventory[j].stackSize == 1) { - mInventory[j] = tStack; - } - else { - getBaseMetaTileEntity().decrStackSize(j, 1); - for (byte k = 0; k < 21; k++) { - if (mInventory[k] == null) { - mInventory[k] = tStack; - break; - } - else { - if (GT_Utility.areStacksEqual( - tStack, mInventory[k] - )) { - if (tStack.stackSize - + mInventory[k].stackSize <= mInventory[k].getMaxStackSize()) { - mInventory[k].stackSize += tStack.stackSize; - break; - } - } - } - } - } - break; - } - } - } - } - if (aHoldStack == null) { - aHoldStack = GT_Utility.copy(mInventory[31]); - aHoldStack.onCrafting( - getBaseMetaTileEntity().getWorld(), aPlayer, mInventory[31].stackSize - ); - } - else { - aHoldStack.stackSize += mInventory[31].stackSize; - aHoldStack.onCrafting( - getBaseMetaTileEntity().getWorld(), aPlayer, mInventory[31].stackSize - ); - } - - fillLiquidContainers(); - - return aHoldStack; - } - - @Override - public int rechargerSlotStartIndex() { - return 16; - } - - @Override - public int rechargerSlotCount() { - return 5; - } - - @Override - public long getOutputTier() { - return GT_Utility.getTier(getBaseMetaTileEntity().getInputVoltage()); - } - - @Override - public int getCapacity() { - return 64000; - } - - @Override - public int getTankPressure() { - return -100; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aIndex == 33 || (mFlushMode && aIndex >= 21 && aIndex < 30); - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - if (aIndex < 16) { - for (byte i = 0; i < 16; i++) - if (GT_Utility.areStacksOrToolsEqual(aStack, mInventory[i])) - return aIndex == i; - return true; - } - return false; - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - getCraftingOutput(); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (getBaseMetaTileEntity().isServerSide()) { - if (getBaseMetaTileEntity().hasInventoryBeenModified()) - getCraftingOutput(); - fillLiquidContainers(); - if (mFlushMode) { - mFlushMode = false; - for (byte i = 21; i < 30; i++) { - if (mInventory[i] != null) { - if (mInventory[i].stackSize == 0) { - mInventory[i] = null; - } - else { - mFlushMode = true; - break; - } - } - } - } - } - /*if (aTick % 100 == 0) { - for (int i = 0; i < this.mInventory.length; i++) { - ItemStack aSlot = mInventory[i]; - Logger.INFO("Slot "+i+" "+(aSlot != null ? "contains "+aSlot.getDisplayName() : "is empty")); - } - }*/ - } - - @Override - public String[] getDescription() { - return new String[] { - isAdvanced() ? "For the very large Projects" : "For the smaller Projects", - "Hold Shift in GUI to see slot usage", - this.mDescription, - CORE.GT_Tooltip }; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFront(i); - rTextures[6][i + 1] = this.getBack(i); - rTextures[7][i + 1] = this.getBottom(i); - rTextures[8][i + 1] = this.getTop(i); - rTextures[9][i + 1] = this.getSides(i); - } - return rTextures; - } - - protected boolean isAdvanced() { - return true; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 - : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex - + 1]; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] { isAdvanced() ? new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Side) : new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Side)}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[] { isAdvanced() ? new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Side) : new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Side)}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { isAdvanced() ? new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Bottom) : new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Bottom)}; - } - - public ITexture[] getTop(final byte aColor) { - if (isAdvanced()) { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Top), - new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) }; - } - else { - return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Top), - new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Crafting_Overlay) }; - } - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { isAdvanced() ? new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Side) : new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Side)}; - } - + public boolean mFlushMode = false; + + protected String mLocalName; + + public GT_MetaTileEntity_AdvancedCraftingTable( + final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription) { + super(aID, aName, aNameRegional, aTier, 35, aDescription); + mLocalName = aNameRegional; + } + + public GT_MetaTileEntity_AdvancedCraftingTable( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 35, aDescription, aTextures); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_AdvancedWorkbench(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_AdvancedWorkbench(aPlayerInventory, aBaseMetaTileEntity, mLocalName); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return aIndex < 31 || aIndex > 32; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isEnetInput() { + return isElectric(); + } + + @Override + public boolean isInputFacing(byte aSide) { + return true; + } + + @Override + public long maxEUInput() { + return isElectric() ? GT_Values.V[3] : 0; + } + + @Override + public long maxEUStore() { + return isElectric() ? GT_Values.V[3] * 1024 : 0; + } + + @Override + public boolean isElectric() { + return isAdvanced(); + } + + @Override + public boolean isPneumatic() { + return false; + } + + @Override + public boolean isSteampowered() { + return false; + } + + @Override + public long maxAmperesIn() { + return isElectric() ? 2 : 0; + } + + @Override + public long getMinimumStoredEU() { + return isElectric() ? GT_Values.V[3] * 2 : 0; + } + + @Override + public int getSizeInventory() { + return 35; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_AdvancedCraftingTable(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return true; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + public void sortIntoTheInputSlots() { + for (byte i = 21; i < 30; i++) + if (mInventory[i] != null) { + if (mInventory[i].stackSize == 0) { + mInventory[i] = null; + } + if (mInventory[i] != null) + for (byte j = 0; j < 16; j++) { + if (GT_Utility.areStacksEqual(mInventory[i], mInventory[j])) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + i, + j, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + if (mInventory[i] != null) + for (byte j = 0; j < 16; j++) { + if (mInventory[j] == null) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + i, + j, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + } + } + + private void fillLiquidContainers() { + for (byte i = 16; i < 21 && mFluid != null; i++) { + ItemStack tOutput = GT_Utility.fillFluidContainer(mFluid, mInventory[i], false, true); + if (tOutput != null) { + if (mInventory[i].stackSize == 1) { + mFluid.amount -= GT_Utility.getFluidForFilledItem(tOutput, true).amount * tOutput.stackSize; + mInventory[i] = tOutput; + } else + for (byte j = 16; j < 21; j++) { + if (mInventory[j] == null + || (GT_Utility.areStacksEqual(tOutput, mInventory[j]) + && mInventory[j].stackSize + tOutput.stackSize <= tOutput.getMaxStackSize())) { + mFluid.amount -= GT_Utility.getFluidForFilledItem(tOutput, true).amount * tOutput.stackSize; + getBaseMetaTileEntity().decrStackSize(i, 1); + if (mInventory[j] == null) { + mInventory[j] = tOutput; + } else { + mInventory[j].stackSize++; + } + break; + } + } + if (mFluid != null && mFluid.amount <= 0) mFluid = null; + } + } + if (mFluid != null && mFluid.amount <= 0) mFluid = null; + } + + public void setBluePrint(ItemStack aStack) { + if (aStack == null) { + aStack = mInventory[30]; + Logger.INFO("Using Slot 30 supply."); + } + if (mInventory[31] == null + || aStack == null + || aStack.getItem() == null + || aStack.getItemDamage() != 0 + || aStack.stackSize != 1 + || !(aStack.getItem() instanceof ItemBlueprint)) { + try { + Logger.INFO("Could not set Blueprint. Slot 31: " + + (mInventory[31] != null ? mInventory[31].getDisplayName() : "Null") + + ", aStack: " + (aStack != null ? aStack.getDisplayName() : "Null") + + ", Damage: " + (aStack != null ? aStack.getItemDamage() : "Null")); + } catch (Throwable t) { + t.printStackTrace(); + } + return; + } + if (!aStack.getTagCompound().hasKey("Inventory")) { + NBTTagCompound tNBT = new NBTTagCompound(); + NBTTagList tNBT_ItemList = new NBTTagList(); + for (int i = 0; i < 9; i++) { + ItemStack tStack = mInventory[i + 21]; + if (tStack != null) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setByte("Slot", (byte) i); + tStack.writeToNBT(tag); + tNBT_ItemList.appendTag(tag); + } + } + tNBT.setTag("Inventory", tNBT_ItemList); + tNBT.setBoolean("mBlueprint", true); + tNBT.setInteger("mID", MathUtils.randInt(1, Short.MAX_VALUE)); + tNBT.setString("mName", mInventory[31].getDisplayName()); + aStack.setTagCompound(tNBT); + Logger.INFO("Set NBT of crafting table to Stack in slot 30."); + } else { + Logger.INFO("Blueprint already has recipe tags."); + } + } + + public ItemStack getCraftingOutput() { + if (mInventory[30] != null + && mInventory[30].getItem() != null + && mInventory[30].getItemDamage() == 0 + && mInventory[30].hasTagCompound() + && mInventory[30].getItem() instanceof ItemBlueprint) { + // Logger.INFO("Getting Blueprint Data in slot 30. "+mInventory[30].getDisplayName()); + NBTTagCompound tNBT = mInventory[30].getTagCompound(); + NBTTagList tNBT_ItemList = tNBT.getTagList("Blueprint", 10); + for (int i = 0; i < tNBT_ItemList.tagCount() && i < 9; i++) { + NBTTagCompound tag = (NBTTagCompound) tNBT_ItemList.getCompoundTagAt(i); + byte slot = tag.getByte("Slot"); + if (slot >= 0 && slot < 9 && mInventory[slot + 21] == null) { + mInventory[slot + 21] = GT_Utility.loadItem(tag); + if (mInventory[slot + 21] != null) mInventory[slot + 21].stackSize = 0; + } + } + } + mInventory[31] = + GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), new ItemStack[] { + mInventory[21], mInventory[22], mInventory[23], + mInventory[24], mInventory[25], mInventory[26], + mInventory[27], mInventory[28], mInventory[29] + }); + return mInventory[31]; + } + + public boolean canDoCraftingOutput() { + if (mInventory[31] == null) return false; + for (ItemStack tStack : recipeContent()) { + if (tStack.stackSize > getAmountOf(tStack)) { + return false; + } + } + return true; + } + + private int getAmountOf(ItemStack aStack) { + int tAmount = 0; + for (byte i = 0; i < 30 && tAmount < 9; i++) { + if (GT_Utility.areStacksOrToolsEqual(aStack, mInventory[i])) { + tAmount += mInventory[i].stackSize; + } + } + return tAmount; + } + + private ArrayList<ItemStack> recipeContent() { + ArrayList<ItemStack> tList = new ArrayList<ItemStack>(); + for (byte i = 21; i < 30; i++) { + if (mInventory[i] != null) { + boolean temp = false; + for (byte j = 0; j < tList.size(); j++) { + if (GT_Utility.areStacksOrToolsEqual(mInventory[i], tList.get(j))) { + tList.get(j).stackSize++; + temp = true; + break; + } + } + if (!temp) tList.add(GT_Utility.copy(1, mInventory[i])); + } + } + return tList; + } + + public ItemStack consumeMaterials(EntityPlayer aPlayer, ItemStack aHoldStack) { + if (mInventory[31] == null) return aHoldStack; + if (aHoldStack != null) { + if (!GT_Utility.areStacksEqual(aHoldStack, mInventory[31])) return aHoldStack; + if (aHoldStack.stackSize + mInventory[31].stackSize > aHoldStack.getMaxStackSize()) return aHoldStack; + } + for (byte i = 21; i < 30; i++) + if (mInventory[i] != null) { + for (byte j = 0; j <= i; j++) { + if (j < 21 || j == i) { + if (GT_Utility.areStacksOrToolsEqual(mInventory[i], mInventory[j]) + && mInventory[j].stackSize > 0) { + ItemStack tStack = GT_Utility.getContainerItem(mInventory[j], true); + if (tStack == null + || (tStack.isItemStackDamageable() + && tStack.getItemDamage() >= tStack.getMaxDamage())) { + getBaseMetaTileEntity().decrStackSize(j, 1); + } else if (mInventory[j].stackSize == 1) { + mInventory[j] = tStack; + } else { + getBaseMetaTileEntity().decrStackSize(j, 1); + for (byte k = 0; k < 21; k++) { + if (mInventory[k] == null) { + mInventory[k] = tStack; + break; + } else { + if (GT_Utility.areStacksEqual(tStack, mInventory[k])) { + if (tStack.stackSize + mInventory[k].stackSize + <= mInventory[k].getMaxStackSize()) { + mInventory[k].stackSize += tStack.stackSize; + break; + } + } + } + } + } + break; + } + } + } + } + if (aHoldStack == null) { + aHoldStack = GT_Utility.copy(mInventory[31]); + aHoldStack.onCrafting(getBaseMetaTileEntity().getWorld(), aPlayer, mInventory[31].stackSize); + } else { + aHoldStack.stackSize += mInventory[31].stackSize; + aHoldStack.onCrafting(getBaseMetaTileEntity().getWorld(), aPlayer, mInventory[31].stackSize); + } + + fillLiquidContainers(); + + return aHoldStack; + } + + @Override + public int rechargerSlotStartIndex() { + return 16; + } + + @Override + public int rechargerSlotCount() { + return 5; + } + + @Override + public long getOutputTier() { + return GT_Utility.getTier(getBaseMetaTileEntity().getInputVoltage()); + } + + @Override + public int getCapacity() { + return 64000; + } + + @Override + public int getTankPressure() { + return -100; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aIndex == 33 || (mFlushMode && aIndex >= 21 && aIndex < 30); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + if (aIndex < 16) { + for (byte i = 0; i < 16; i++) + if (GT_Utility.areStacksOrToolsEqual(aStack, mInventory[i])) return aIndex == i; + return true; + } + return false; + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + getCraftingOutput(); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (getBaseMetaTileEntity().isServerSide()) { + if (getBaseMetaTileEntity().hasInventoryBeenModified()) getCraftingOutput(); + fillLiquidContainers(); + if (mFlushMode) { + mFlushMode = false; + for (byte i = 21; i < 30; i++) { + if (mInventory[i] != null) { + if (mInventory[i].stackSize == 0) { + mInventory[i] = null; + } else { + mFlushMode = true; + break; + } + } + } + } + } + /*if (aTick % 100 == 0) { + for (int i = 0; i < this.mInventory.length; i++) { + ItemStack aSlot = mInventory[i]; + Logger.INFO("Slot "+i+" "+(aSlot != null ? "contains "+aSlot.getDisplayName() : "is empty")); + } + }*/ + } + + @Override + public String[] getDescription() { + return new String[] { + isAdvanced() ? "For the very large Projects" : "For the smaller Projects", + "Hold Shift in GUI to see slot usage", + this.mDescription, + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getBack(i); + rTextures[7][i + 1] = this.getBottom(i); + rTextures[8][i + 1] = this.getTop(i); + rTextures[9][i + 1] = this.getSides(i); + } + return rTextures; + } + + protected boolean isAdvanced() { + return true; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + isAdvanced() + ? new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Side) + : new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Side) + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + isAdvanced() + ? new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Side) + : new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Side) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + isAdvanced() + ? new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Bottom) + : new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Bottom) + }; + } + + public ITexture[] getTop(final byte aColor) { + if (isAdvanced()) { + return new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Top), + new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) + }; + } else { + return new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Top), + new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Crafting_Overlay) + }; + } + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + isAdvanced() + ? new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Side) + : new GT_RenderedTexture(TexturesGtBlock.Casing_Workbench_Side) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_BronzeCraftingTable.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_BronzeCraftingTable.java index f421d391c0..9e21e51f07 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_BronzeCraftingTable.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_BronzeCraftingTable.java @@ -5,79 +5,82 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_ItemStack; -import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.workbench.GT_Container_BronzeWorkbench; import gtPlusPlus.xmod.gregtech.api.gui.workbench.GT_GUIContainer_BronzeWorkbench; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_BronzeCraftingTable extends GT_MetaTileEntity_AdvancedCraftingTable { - - public GT_MetaTileEntity_BronzeCraftingTable(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription) { - super(aID, aName, aNameRegional, aTier, aDescription); - } - public GT_MetaTileEntity_BronzeCraftingTable(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_BronzeWorkbench(aPlayerInventory, aBaseMetaTileEntity); - } + public GT_MetaTileEntity_BronzeCraftingTable( + final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription) { + super(aID, aName, aNameRegional, aTier, aDescription); + } + + public GT_MetaTileEntity_BronzeCraftingTable( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BronzeWorkbench(aPlayerInventory, aBaseMetaTileEntity, mLocalName); - } - - @Override - public boolean isTransformerUpgradable() { - return false; - } - - @Override - public boolean isInputFacing(byte aSide) { - return false; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_BronzeCraftingTable(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @SuppressWarnings("deprecation") - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - return GregTech_API.getCoverBehavior(aStack.toStack()).isSimpleCover(); - } + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_BronzeWorkbench(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_BronzeWorkbench(aPlayerInventory, aBaseMetaTileEntity, mLocalName); + } - @Override + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public boolean isInputFacing(byte aSide) { + return false; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_BronzeCraftingTable(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @SuppressWarnings("deprecation") + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return GregTech_API.getCoverBehavior(aStack.toStack()).isSimpleCover(); + } + + @Override public int rechargerSlotStartIndex() { - return 0; + return 0; } - - @Override + + @Override public int rechargerSlotCount() { - return 0; + return 0; + } + + @Override + public int getCapacity() { + return 16000; + } + + @Override + protected boolean isAdvanced() { + return false; } - - @Override - public int getCapacity() { - return 16000; - } - - @Override - protected boolean isAdvanced() { - return false; - } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_ConnectableCrate.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_ConnectableCrate.java index a3c11d486b..1c0e682b62 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_ConnectableCrate.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_ConnectableCrate.java @@ -1,12 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage; -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; - import gregtech.api.GregTech_API; import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.ITexture; @@ -16,7 +9,6 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; - import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.lib.CORE; @@ -24,551 +16,554 @@ import gtPlusPlus.core.util.data.ArrayUtils; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_SuperChest; import gtPlusPlus.xmod.gregtech.api.gui.GUI_SuperChest; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; public class GT_MetaTileEntity_ConnectableCrate extends GT_MetaTileEntity_TieredMachineBlock { - /*sides.put(getUp()); - sides.put(getDown()); - sides.put(getXPos()); - sides.put(getXNeg()); - sides.put(getZPos()); - sides.put(getZNeg());*/ - - public int mItemCount = 0; - public ItemStack mItemStack = null; - private final static double mStorageFactor = 2; - - //Meta Tile ID - public final static int mCrateID = 955; - - //Sides - public final static int SIDE_Up = 0; - public final static int SIDE_Down = 1; - public final static int SIDE_XPos = 2; - public final static int SIDE_XNeg = 3; - public final static int SIDE_ZPos = 4; - public final static int SIDE_ZNeg = 5; - public final static int[] SIDES = new int[] {SIDE_Up, SIDE_Down, SIDE_XPos, SIDE_XNeg, SIDE_ZPos, SIDE_ZNeg}; - - //Neighbour Cache - private GT_MetaTileEntity_ConnectableCrate[] mNeighbourCache = new GT_MetaTileEntity_ConnectableCrate[6]; - //Cached Crate Location - private BlockPos mCurrentPos = null; - //Master Crate Position - protected BlockPos mMasterCrateLocation = null; - //Is Master? - protected boolean mIsMaster = false; - //Is Connected? - protected boolean mIsConnected[] = new boolean[] {false, false, false, false, false, false}; - //How many are connected? - protected int mConnectedCount = 0; - //Map of connected locations - protected AutoMap<String> mConnectedCache = new AutoMap<String>(); - - - public GT_MetaTileEntity_ConnectableCrate(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 3, - "This Crate stores " + (int) (Math.pow(6.0D, (double) aTier) * mStorageFactor) + " Items", new ITexture[0]); - } - - public GT_MetaTileEntity_ConnectableCrate(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - CORE.GT_Tooltip}; - } - - public boolean isSimpleMachine() { - return true; - } - - public boolean isFacingValid(byte aFacing) { - return true; - } - - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - public boolean isValidSlot(int aIndex) { - return true; - } - - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_ConnectableCrate(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - public int getOppositeSide(int side) { - if (side == SIDE_Up) { - return SIDE_Down; - } - else if (side == SIDE_Down) { - return SIDE_Up; - } - else if (side == SIDE_XNeg) { - return SIDE_XPos; - } - else if (side == SIDE_XPos) { - return SIDE_XNeg; - } - else if (side == SIDE_ZNeg) { - return SIDE_ZPos; - } - else { - return SIDE_ZNeg; - } - } - - public boolean calculateOwnershipIfConnected() { - if (mCurrentPos == null) { - mCurrentPos = new BlockPos(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord(), this.getBaseMetaTileEntity().getWorld()); - } - AutoMap<BlockPos> n = mCurrentPos.getSurroundingBlocks(); - int p = 0; - for (BlockPos i : n) { - if (i != null) { - if (doesSideContainCrate(p)) { - GT_MetaTileEntity_ConnectableCrate yu = getCrateAtBlockPos(i); - if (yu != null) { - mNeighbourCache[p] = yu; - } - } - } - p++; - } - - int e4 = 0; - if (mNeighbourCache.length > 0) { - for (GT_MetaTileEntity_ConnectableCrate e : mNeighbourCache) { - this.mConnectedCount = this.mConnectedCache.size(); - if (e != null) { - //First, we check if this Crate is a Master, if not, continue checking what it is. - if (this.mIsMaster) { - //So this other Crate is also a master? Which is more Powerful - if (e.mIsMaster) { - //This crate holds more connected, it becomes master now. - if (this.mConnectedCount > e.mConnectedCount) { - e.mIsMaster = false; - e.mMasterCrateLocation = this.mCurrentPos; - if (!e.mIsConnected[getOppositeSide(e4)]) { - e.mIsConnected[getOppositeSide(e4)] = true; - } - if (!this.mIsConnected[e4]) { - this.mIsConnected[e4] = true; - } - this.mConnectedCache = ArrayUtils.mergeTwoMaps(this.mConnectedCache, e.mConnectedCache); - continue; - } - //Other crate held more connected, it is now master. - else { - this.mIsMaster = false; - this.mMasterCrateLocation = e.mCurrentPos; - if (!this.mIsConnected[e4]) { - this.mIsConnected[e4] = true; - } - if (!e.mIsConnected[getOppositeSide(e4)]) { - e.mIsConnected[getOppositeSide(e4)] = true; - } - e.mConnectedCache = ArrayUtils.mergeTwoMaps(e.mConnectedCache, this.mConnectedCache); - //Best wipe our cache of connected blocks then, since they no longer hold value. - mConnectedCache.clear(); - continue; - } - } - //Other Crate was not a Master, but we are, time to inherit it into our connection hivemind. - else { - //It would appear this controller has another master, time to query it. - if (e.mMasterCrateLocation != null && !e.mMasterCrateLocation.getUniqueIdentifier().equalsIgnoreCase(this.mMasterCrateLocation.getUniqueIdentifier())) { - GT_MetaTileEntity_ConnectableCrate gM = getCrateAtBlockPos(e.mMasterCrateLocation); - if (gM != null) { - //Lets compare controller strengths - int gM_Owned = gM.mConnectedCount; - //We are stronger, let's inherit it. - if (this.mConnectedCount > gM_Owned) { - e.mIsMaster = false; - e.mMasterCrateLocation = this.mCurrentPos; - gM.mIsMaster = false; - gM.mMasterCrateLocation = this.mCurrentPos; - if (!e.mIsConnected[getOppositeSide(e4)]) { - e.mIsConnected[getOppositeSide(e4)] = true; - } - if (!this.mIsConnected[e4]) { - this.mIsConnected[e4] = true; - } - this.mConnectedCache = ArrayUtils.mergeTwoMaps(this.mConnectedCache, gM.mConnectedCache); - continue; - } - //We lost, time to submit to a new master crate - else { - this.mIsMaster = false; - this.mMasterCrateLocation = e.mMasterCrateLocation; - if (!this.mIsConnected[e4]) { - this.mIsConnected[e4] = true; - } - if (!e.mIsConnected[getOppositeSide(e4)]) { - e.mIsConnected[getOppositeSide(e4)] = true; - } - gM.mConnectedCache = ArrayUtils.mergeTwoMaps(gM.mConnectedCache, this.mConnectedCache); - //Best wipe our cache of connected blocks then, since they no longer hold value. - mConnectedCache.clear(); - continue; - } - } - else { - //Could not get the Tile Entity for the Other Master Crate.. Guess I can just ignore this case for now~ TODO - continue; - } - } - //Either the other crate has no known Master or it is already this crate. - else { - //The other crate has no master, time to inherit. - if (e.mMasterCrateLocation == null || (!e.mIsConnected[getOppositeSide(e4)])) { - e.mMasterCrateLocation = this.mCurrentPos; - if (!e.mIsConnected[getOppositeSide(e4)]) { - e.mIsConnected[getOppositeSide(e4)] = true; - } - if (!this.mIsConnected[e4]) { - this.mIsConnected[e4] = true; - } - mConnectedCache.put(e.mCurrentPos.getUniqueIdentifier()); - continue; - } - else { - //Do nothing, we own this Crate already :) - continue; - } - - - } - } - } - - //We are not a Storage Master Crate, into a brave new world we go - else { - //Best wipe our cache of connected blocks then, since they no longer hold value. - mConnectedCache.clear(); - - //Dang, the other crate is a master, time to get incorporated. - if (e.mIsMaster) { - this.mIsMaster = false; - this.mMasterCrateLocation = e.mCurrentPos; - this.mIsConnected[e4] = true; - if (!e.mIsConnected[e4]) { - e.mIsConnected[e4] = true; - } - if (e.mMasterCrateLocation == null) { - e.mMasterCrateLocation = e.mCurrentPos; - } - e.mConnectedCache.put(this.mCurrentPos.getUniqueIdentifier()); - continue; - } - //So the Crate we Checked is not a Master, so let's see if it knows where one is - else { - //So, this Crate we have found knows about a master - if (e.mMasterCrateLocation != null) { - GT_MetaTileEntity_ConnectableCrate gM = getCrateAtBlockPos(e.mMasterCrateLocation); - //Found the master crate - if (gM != null) { - this.mIsMaster = false; - this.mMasterCrateLocation = e.mMasterCrateLocation; - if (!this.mIsConnected[e4]) { - this.mIsConnected[e4] = true; - } - if (!e.mIsConnected[getOppositeSide(e4)]) { - e.mIsConnected[getOppositeSide(e4)] = true; - } - gM.mConnectedCache.put(this.mCurrentPos.getUniqueIdentifier()); - continue; - } - else { - //Could not get the Tile Entity for the Other Master Crate.. Guess I can just ignore this case for now~ TODO - continue; - } - } - //This crate has no master, not going to check if it's connected. - else { - this.mIsMaster = true; - this.mMasterCrateLocation = this.mCurrentPos; - e.mIsMaster = false; - e.mMasterCrateLocation = this.mCurrentPos; - if (!e.mIsConnected[getOppositeSide(e4)]) { - e.mIsConnected[getOppositeSide(e4)] = true; - } - if (!this.mIsConnected[e4]) { - this.mIsConnected[e4] = true; - } - mConnectedCache.put(e.mCurrentPos.getUniqueIdentifier()); - continue; - } - } - } - } - e4++; - } - return true; - } - else { - return false; - } - - - - - } - - public boolean doesSideContainCrate(int side) { - return checkSideForDataType(0, side); - } - - public boolean isCrateAtSideController(int side) { - return checkSideForDataType(1, side); - } - - private boolean checkSideForDataType(int aType, int aSide) { - BlockPos mPosToCheck = - aSide == SIDE_Up ? mCurrentPos.getUp() : - aSide == SIDE_Down ? mCurrentPos.getDown() : - aSide == SIDE_XPos ? mCurrentPos.getXPos() : - aSide == SIDE_XNeg ? mCurrentPos.getXNeg() : - aSide == SIDE_ZPos ? mCurrentPos.getZPos() : - mCurrentPos.getZNeg(); - GT_MetaTileEntity_ConnectableCrate g = getCrateAtBlockPos(mPosToCheck); - if (g != null) { - if (aType == 0) { - return true; - } - else { - if (g.mIsMaster) { - return true; - } - } - } - return false; - } - - public GT_MetaTileEntity_ConnectableCrate getCrateAtBlockPos(BlockPos pos) { - if (pos != null) { - Block b = pos.getBlockAtPos(); - int m = pos.getMetaAtPos(); - TileEntity t = pos.world.getTileEntity(pos.xPos, pos.yPos, pos.zPos); - if (b != null && t != null) { - if (b == GregTech_API.sBlockMachines && m == mCrateID) { - if (t instanceof IGregTechTileEntity) { - IGregTechTileEntity g = (IGregTechTileEntity) t; - final IMetaTileEntity aMetaTileEntity = g.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return null; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_ConnectableCrate) { - return ((GT_MetaTileEntity_ConnectableCrate) aMetaTileEntity); - - } - } - } - } - } - return null; - } - - - - - - - - - - - - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } else { - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - } - - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_SuperChest(aPlayerInventory, aBaseMetaTileEntity); - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_SuperChest(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); - } - - - - - - - - - - - - - - - - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (this.getBaseMetaTileEntity().isServerSide() && this.getBaseMetaTileEntity().isAllowedToWork()) { - if (this.getItemCount() <= 0) { - this.mItemStack = null; - this.mItemCount = 0; - } - - if (this.mItemStack == null && this.mInventory[0] != null) { - this.mItemStack = this.mInventory[0].copy(); - } - - if (this.mInventory[0] != null && this.mItemCount < this.getMaxItemCount() - && GT_Utility.areStacksEqual(this.mInventory[0], this.mItemStack)) { - this.mItemCount += this.mInventory[0].stackSize; - if (this.mItemCount > this.getMaxItemCount()) { - this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount(); - this.mItemCount = this.getMaxItemCount(); - } else { - this.mInventory[0] = null; - } - } - - if (this.mInventory[1] == null && this.mItemStack != null) { - this.mInventory[1] = this.mItemStack.copy(); - this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); - this.mItemCount -= this.mInventory[1].stackSize; - } else if (this.mItemCount > 0 && GT_Utility.areStacksEqual(this.mInventory[1], this.mItemStack) - && this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) { - int tmp = Math.min(this.mItemCount, - this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize); - this.mInventory[1].stackSize += tmp; - this.mItemCount -= tmp; - } - - if (this.mItemStack != null) { - this.mInventory[2] = this.mItemStack.copy(); - this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); - } else { - this.mInventory[2] = null; - } - } - - } - - private int getItemCount() { - return this.mItemCount; - } - - public void setItemCount(int aCount) { - this.mItemCount = aCount; - } - - public int getProgresstime() { - return this.mItemCount + (this.mInventory[0] == null ? 0 : this.mInventory[0].stackSize) - + (this.mInventory[1] == null ? 0 : this.mInventory[1].stackSize); - } - - public int maxProgresstime() { - return this.getMaxItemCount(); - } - - public int getMaxItemCount() { - return (int) (Math.pow(6.0D, (double) this.mTier) * mStorageFactor - 128.0D); - } - - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aIndex == 1; - } - - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aIndex == 0 && (this.mInventory[0] == null || GT_Utility.areStacksEqual(this.mInventory[0], aStack)); - } - - public String[] getInfoData() { - return this.mItemStack == null - ? new String[]{"Super Storage Chest", "Stored Items:", "No Items", Integer.toString(0), - Integer.toString(this.getMaxItemCount())} - : new String[]{"Super Storage Chest", "Stored Items:", this.mItemStack.getDisplayName(), - Integer.toString(this.mItemCount), Integer.toString(this.getMaxItemCount())}; - } - - public boolean isGivingInformation() { - return true; - } - - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mItemCount", this.mItemCount); - if (this.mItemStack != null) { - aNBT.setTag("mItemStack", this.mItemStack.writeToNBT(new NBTTagCompound())); - } - aNBT.setString("mMasterCrateLocation", mMasterCrateLocation.getUniqueIdentifier()); - aNBT.setBoolean("mIsMaster", mIsMaster); - for (int y=0;y<this.mIsConnected.length;y++) { - aNBT.setBoolean("mIsConnected"+y, mIsConnected[y]); - } - aNBT.setInteger("mConnectedCount", mConnectedCount); - } - - public void loadNBTData(NBTTagCompound aNBT) { - if (aNBT.hasKey("mItemCount")) { - this.mItemCount = aNBT.getInteger("mItemCount"); - } - if (aNBT.hasKey("mItemStack")) { - this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")); - } - if (aNBT.hasKey("mMasterCrateLocation")) { - this.mMasterCrateLocation = BlockPos.generateBlockPos(aNBT.getString("mMasterCrateLocation")); - } - if (aNBT.hasKey("mIsMaster")) { - this.mIsMaster = aNBT.getBoolean("mIsMaster"); - } - - for (int y=0;y<this.mIsConnected.length;y++) { - if (aNBT.hasKey("mIsConnected"+y)) { - this.mIsConnected[y] = aNBT.getBoolean("mIsConnected"+y); - } - } - - if (aNBT.hasKey("mConnectedCount")) { - this.mConnectedCount = aNBT.getInteger("mConnectedCount"); - } - - } - - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, - boolean aActive, boolean aRedstone) { - return aBaseMetaTileEntity.getFrontFacing() == 0 && aSide == 4 - ? new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.TEXTURE_CASING_AMAZON), - new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST)} - : (aSide == aBaseMetaTileEntity.getFrontFacing() - ? new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.TEXTURE_CASING_AMAZON), - new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST)} - : new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.TEXTURE_CASING_AMAZON)}); - } - - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - return new ITexture[0][0][0]; - } - - @Override - public void onExplosion() { - // TODO Auto-generated method stub - super.onExplosion(); - } - - @Override - public void onRemoval() { - // TODO Auto-generated method stub - super.onRemoval(); - } - - @Override - public void onMachineBlockUpdate() { - // TODO Auto-generated method stub - super.onMachineBlockUpdate(); - } -}
\ No newline at end of file + /*sides.put(getUp()); + sides.put(getDown()); + sides.put(getXPos()); + sides.put(getXNeg()); + sides.put(getZPos()); + sides.put(getZNeg());*/ + + public int mItemCount = 0; + public ItemStack mItemStack = null; + private static final double mStorageFactor = 2; + + // Meta Tile ID + public static final int mCrateID = 955; + + // Sides + public static final int SIDE_Up = 0; + public static final int SIDE_Down = 1; + public static final int SIDE_XPos = 2; + public static final int SIDE_XNeg = 3; + public static final int SIDE_ZPos = 4; + public static final int SIDE_ZNeg = 5; + public static final int[] SIDES = new int[] {SIDE_Up, SIDE_Down, SIDE_XPos, SIDE_XNeg, SIDE_ZPos, SIDE_ZNeg}; + + // Neighbour Cache + private GT_MetaTileEntity_ConnectableCrate[] mNeighbourCache = new GT_MetaTileEntity_ConnectableCrate[6]; + // Cached Crate Location + private BlockPos mCurrentPos = null; + // Master Crate Position + protected BlockPos mMasterCrateLocation = null; + // Is Master? + protected boolean mIsMaster = false; + // Is Connected? + protected boolean mIsConnected[] = new boolean[] {false, false, false, false, false, false}; + // How many are connected? + protected int mConnectedCount = 0; + // Map of connected locations + protected AutoMap<String> mConnectedCache = new AutoMap<String>(); + + public GT_MetaTileEntity_ConnectableCrate(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 3, + "This Crate stores " + (int) (Math.pow(6.0D, (double) aTier) * mStorageFactor) + " Items", + new ITexture[0]); + } + + public GT_MetaTileEntity_ConnectableCrate(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, CORE.GT_Tooltip}; + } + + public boolean isSimpleMachine() { + return true; + } + + public boolean isFacingValid(byte aFacing) { + return true; + } + + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + public boolean isValidSlot(int aIndex) { + return true; + } + + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_ConnectableCrate(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + public int getOppositeSide(int side) { + if (side == SIDE_Up) { + return SIDE_Down; + } else if (side == SIDE_Down) { + return SIDE_Up; + } else if (side == SIDE_XNeg) { + return SIDE_XPos; + } else if (side == SIDE_XPos) { + return SIDE_XNeg; + } else if (side == SIDE_ZNeg) { + return SIDE_ZPos; + } else { + return SIDE_ZNeg; + } + } + + public boolean calculateOwnershipIfConnected() { + if (mCurrentPos == null) { + mCurrentPos = new BlockPos( + this.getBaseMetaTileEntity().getXCoord(), + this.getBaseMetaTileEntity().getYCoord(), + this.getBaseMetaTileEntity().getZCoord(), + this.getBaseMetaTileEntity().getWorld()); + } + AutoMap<BlockPos> n = mCurrentPos.getSurroundingBlocks(); + int p = 0; + for (BlockPos i : n) { + if (i != null) { + if (doesSideContainCrate(p)) { + GT_MetaTileEntity_ConnectableCrate yu = getCrateAtBlockPos(i); + if (yu != null) { + mNeighbourCache[p] = yu; + } + } + } + p++; + } + + int e4 = 0; + if (mNeighbourCache.length > 0) { + for (GT_MetaTileEntity_ConnectableCrate e : mNeighbourCache) { + this.mConnectedCount = this.mConnectedCache.size(); + if (e != null) { + // First, we check if this Crate is a Master, if not, continue checking what it is. + if (this.mIsMaster) { + // So this other Crate is also a master? Which is more Powerful + if (e.mIsMaster) { + // This crate holds more connected, it becomes master now. + if (this.mConnectedCount > e.mConnectedCount) { + e.mIsMaster = false; + e.mMasterCrateLocation = this.mCurrentPos; + if (!e.mIsConnected[getOppositeSide(e4)]) { + e.mIsConnected[getOppositeSide(e4)] = true; + } + if (!this.mIsConnected[e4]) { + this.mIsConnected[e4] = true; + } + this.mConnectedCache = ArrayUtils.mergeTwoMaps(this.mConnectedCache, e.mConnectedCache); + continue; + } + // Other crate held more connected, it is now master. + else { + this.mIsMaster = false; + this.mMasterCrateLocation = e.mCurrentPos; + if (!this.mIsConnected[e4]) { + this.mIsConnected[e4] = true; + } + if (!e.mIsConnected[getOppositeSide(e4)]) { + e.mIsConnected[getOppositeSide(e4)] = true; + } + e.mConnectedCache = ArrayUtils.mergeTwoMaps(e.mConnectedCache, this.mConnectedCache); + // Best wipe our cache of connected blocks then, since they no longer hold value. + mConnectedCache.clear(); + continue; + } + } + // Other Crate was not a Master, but we are, time to inherit it into our connection hivemind. + else { + // It would appear this controller has another master, time to query it. + if (e.mMasterCrateLocation != null + && !e.mMasterCrateLocation + .getUniqueIdentifier() + .equalsIgnoreCase(this.mMasterCrateLocation.getUniqueIdentifier())) { + GT_MetaTileEntity_ConnectableCrate gM = getCrateAtBlockPos(e.mMasterCrateLocation); + if (gM != null) { + // Lets compare controller strengths + int gM_Owned = gM.mConnectedCount; + // We are stronger, let's inherit it. + if (this.mConnectedCount > gM_Owned) { + e.mIsMaster = false; + e.mMasterCrateLocation = this.mCurrentPos; + gM.mIsMaster = false; + gM.mMasterCrateLocation = this.mCurrentPos; + if (!e.mIsConnected[getOppositeSide(e4)]) { + e.mIsConnected[getOppositeSide(e4)] = true; + } + if (!this.mIsConnected[e4]) { + this.mIsConnected[e4] = true; + } + this.mConnectedCache = + ArrayUtils.mergeTwoMaps(this.mConnectedCache, gM.mConnectedCache); + continue; + } + // We lost, time to submit to a new master crate + else { + this.mIsMaster = false; + this.mMasterCrateLocation = e.mMasterCrateLocation; + if (!this.mIsConnected[e4]) { + this.mIsConnected[e4] = true; + } + if (!e.mIsConnected[getOppositeSide(e4)]) { + e.mIsConnected[getOppositeSide(e4)] = true; + } + gM.mConnectedCache = + ArrayUtils.mergeTwoMaps(gM.mConnectedCache, this.mConnectedCache); + // Best wipe our cache of connected blocks then, since they no longer hold + // value. + mConnectedCache.clear(); + continue; + } + } else { + // Could not get the Tile Entity for the Other Master Crate.. Guess I can just + // ignore this case for now~ TODO + continue; + } + } + // Either the other crate has no known Master or it is already this crate. + else { + // The other crate has no master, time to inherit. + if (e.mMasterCrateLocation == null || (!e.mIsConnected[getOppositeSide(e4)])) { + e.mMasterCrateLocation = this.mCurrentPos; + if (!e.mIsConnected[getOppositeSide(e4)]) { + e.mIsConnected[getOppositeSide(e4)] = true; + } + if (!this.mIsConnected[e4]) { + this.mIsConnected[e4] = true; + } + mConnectedCache.put(e.mCurrentPos.getUniqueIdentifier()); + continue; + } else { + // Do nothing, we own this Crate already :) + continue; + } + } + } + } + + // We are not a Storage Master Crate, into a brave new world we go + else { + // Best wipe our cache of connected blocks then, since they no longer hold value. + mConnectedCache.clear(); + + // Dang, the other crate is a master, time to get incorporated. + if (e.mIsMaster) { + this.mIsMaster = false; + this.mMasterCrateLocation = e.mCurrentPos; + this.mIsConnected[e4] = true; + if (!e.mIsConnected[e4]) { + e.mIsConnected[e4] = true; + } + if (e.mMasterCrateLocation == null) { + e.mMasterCrateLocation = e.mCurrentPos; + } + e.mConnectedCache.put(this.mCurrentPos.getUniqueIdentifier()); + continue; + } + // So the Crate we Checked is not a Master, so let's see if it knows where one is + else { + // So, this Crate we have found knows about a master + if (e.mMasterCrateLocation != null) { + GT_MetaTileEntity_ConnectableCrate gM = getCrateAtBlockPos(e.mMasterCrateLocation); + // Found the master crate + if (gM != null) { + this.mIsMaster = false; + this.mMasterCrateLocation = e.mMasterCrateLocation; + if (!this.mIsConnected[e4]) { + this.mIsConnected[e4] = true; + } + if (!e.mIsConnected[getOppositeSide(e4)]) { + e.mIsConnected[getOppositeSide(e4)] = true; + } + gM.mConnectedCache.put(this.mCurrentPos.getUniqueIdentifier()); + continue; + } else { + // Could not get the Tile Entity for the Other Master Crate.. Guess I can just + // ignore this case for now~ TODO + continue; + } + } + // This crate has no master, not going to check if it's connected. + else { + this.mIsMaster = true; + this.mMasterCrateLocation = this.mCurrentPos; + e.mIsMaster = false; + e.mMasterCrateLocation = this.mCurrentPos; + if (!e.mIsConnected[getOppositeSide(e4)]) { + e.mIsConnected[getOppositeSide(e4)] = true; + } + if (!this.mIsConnected[e4]) { + this.mIsConnected[e4] = true; + } + mConnectedCache.put(e.mCurrentPos.getUniqueIdentifier()); + continue; + } + } + } + } + e4++; + } + return true; + } else { + return false; + } + } + + public boolean doesSideContainCrate(int side) { + return checkSideForDataType(0, side); + } + + public boolean isCrateAtSideController(int side) { + return checkSideForDataType(1, side); + } + + private boolean checkSideForDataType(int aType, int aSide) { + BlockPos mPosToCheck = aSide == SIDE_Up + ? mCurrentPos.getUp() + : aSide == SIDE_Down + ? mCurrentPos.getDown() + : aSide == SIDE_XPos + ? mCurrentPos.getXPos() + : aSide == SIDE_XNeg + ? mCurrentPos.getXNeg() + : aSide == SIDE_ZPos ? mCurrentPos.getZPos() : mCurrentPos.getZNeg(); + GT_MetaTileEntity_ConnectableCrate g = getCrateAtBlockPos(mPosToCheck); + if (g != null) { + if (aType == 0) { + return true; + } else { + if (g.mIsMaster) { + return true; + } + } + } + return false; + } + + public GT_MetaTileEntity_ConnectableCrate getCrateAtBlockPos(BlockPos pos) { + if (pos != null) { + Block b = pos.getBlockAtPos(); + int m = pos.getMetaAtPos(); + TileEntity t = pos.world.getTileEntity(pos.xPos, pos.yPos, pos.zPos); + if (b != null && t != null) { + if (b == GregTech_API.sBlockMachines && m == mCrateID) { + if (t instanceof IGregTechTileEntity) { + IGregTechTileEntity g = (IGregTechTileEntity) t; + final IMetaTileEntity aMetaTileEntity = g.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return null; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_ConnectableCrate) { + return ((GT_MetaTileEntity_ConnectableCrate) aMetaTileEntity); + } + } + } + } + } + return null; + } + + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } else { + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + } + + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_SuperChest(aPlayerInventory, aBaseMetaTileEntity); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_SuperChest(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); + } + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (this.getBaseMetaTileEntity().isServerSide() + && this.getBaseMetaTileEntity().isAllowedToWork()) { + if (this.getItemCount() <= 0) { + this.mItemStack = null; + this.mItemCount = 0; + } + + if (this.mItemStack == null && this.mInventory[0] != null) { + this.mItemStack = this.mInventory[0].copy(); + } + + if (this.mInventory[0] != null + && this.mItemCount < this.getMaxItemCount() + && GT_Utility.areStacksEqual(this.mInventory[0], this.mItemStack)) { + this.mItemCount += this.mInventory[0].stackSize; + if (this.mItemCount > this.getMaxItemCount()) { + this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount(); + this.mItemCount = this.getMaxItemCount(); + } else { + this.mInventory[0] = null; + } + } + + if (this.mInventory[1] == null && this.mItemStack != null) { + this.mInventory[1] = this.mItemStack.copy(); + this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + this.mItemCount -= this.mInventory[1].stackSize; + } else if (this.mItemCount > 0 + && GT_Utility.areStacksEqual(this.mInventory[1], this.mItemStack) + && this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) { + int tmp = + Math.min(this.mItemCount, this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize); + this.mInventory[1].stackSize += tmp; + this.mItemCount -= tmp; + } + + if (this.mItemStack != null) { + this.mInventory[2] = this.mItemStack.copy(); + this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + } else { + this.mInventory[2] = null; + } + } + } + + private int getItemCount() { + return this.mItemCount; + } + + public void setItemCount(int aCount) { + this.mItemCount = aCount; + } + + public int getProgresstime() { + return this.mItemCount + + (this.mInventory[0] == null ? 0 : this.mInventory[0].stackSize) + + (this.mInventory[1] == null ? 0 : this.mInventory[1].stackSize); + } + + public int maxProgresstime() { + return this.getMaxItemCount(); + } + + public int getMaxItemCount() { + return (int) (Math.pow(6.0D, (double) this.mTier) * mStorageFactor - 128.0D); + } + + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aIndex == 1; + } + + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aIndex == 0 && (this.mInventory[0] == null || GT_Utility.areStacksEqual(this.mInventory[0], aStack)); + } + + public String[] getInfoData() { + return this.mItemStack == null + ? new String[] { + "Super Storage Chest", + "Stored Items:", + "No Items", + Integer.toString(0), + Integer.toString(this.getMaxItemCount()) + } + : new String[] { + "Super Storage Chest", + "Stored Items:", + this.mItemStack.getDisplayName(), + Integer.toString(this.mItemCount), + Integer.toString(this.getMaxItemCount()) + }; + } + + public boolean isGivingInformation() { + return true; + } + + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mItemCount", this.mItemCount); + if (this.mItemStack != null) { + aNBT.setTag("mItemStack", this.mItemStack.writeToNBT(new NBTTagCompound())); + } + aNBT.setString("mMasterCrateLocation", mMasterCrateLocation.getUniqueIdentifier()); + aNBT.setBoolean("mIsMaster", mIsMaster); + for (int y = 0; y < this.mIsConnected.length; y++) { + aNBT.setBoolean("mIsConnected" + y, mIsConnected[y]); + } + aNBT.setInteger("mConnectedCount", mConnectedCount); + } + + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("mItemCount")) { + this.mItemCount = aNBT.getInteger("mItemCount"); + } + if (aNBT.hasKey("mItemStack")) { + this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")); + } + if (aNBT.hasKey("mMasterCrateLocation")) { + this.mMasterCrateLocation = BlockPos.generateBlockPos(aNBT.getString("mMasterCrateLocation")); + } + if (aNBT.hasKey("mIsMaster")) { + this.mIsMaster = aNBT.getBoolean("mIsMaster"); + } + + for (int y = 0; y < this.mIsConnected.length; y++) { + if (aNBT.hasKey("mIsConnected" + y)) { + this.mIsConnected[y] = aNBT.getBoolean("mIsConnected" + y); + } + } + + if (aNBT.hasKey("mConnectedCount")) { + this.mConnectedCount = aNBT.getInteger("mConnectedCount"); + } + } + + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + return aBaseMetaTileEntity.getFrontFacing() == 0 && aSide == 4 + ? new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.TEXTURE_CASING_AMAZON), + new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST) + } + : (aSide == aBaseMetaTileEntity.getFrontFacing() + ? new ITexture[] { + new GT_RenderedTexture(TexturesGtBlock.TEXTURE_CASING_AMAZON), + new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST) + } + : new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.TEXTURE_CASING_AMAZON)}); + } + + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + return new ITexture[0][0][0]; + } + + @Override + public void onExplosion() { + // TODO Auto-generated method stub + super.onExplosion(); + } + + @Override + public void onRemoval() { + // TODO Auto-generated method stub + super.onRemoval(); + } + + @Override + public void onMachineBlockUpdate() { + // TODO Auto-generated method stub + super.onMachineBlockUpdate(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java index 951b4223dc..b5dcd8cd73 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java @@ -1,10 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -15,185 +10,213 @@ import gregtech.api.util.GT_Utility; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_SuperChest; import gtPlusPlus.xmod.gregtech.api.gui.GUI_SuperChest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_TieredChest extends GT_MetaTileEntity_TieredMachineBlock { - public int mItemCount = 0; - public ItemStack mItemStack = null; - private final static double mStorageFactor = (270000.0D/16); - - public GT_MetaTileEntity_TieredChest(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 3, - "This Chest stores " + (int) (Math.pow(6.0D, (double) aTier) * mStorageFactor) + " Items", new ITexture[0]); - } - - public GT_MetaTileEntity_TieredChest(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - /*public GT_MetaTileEntity_TieredChest(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - }*/ - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - CORE.GT_Tooltip}; - } - - public boolean isSimpleMachine() { - return true; - } - - public boolean isFacingValid(byte aFacing) { - return true; - } - - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - public boolean isValidSlot(int aIndex) { - return true; - } - - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_TieredChest(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } else { - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - } - - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_SuperChest(aPlayerInventory, aBaseMetaTileEntity); - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_SuperChest(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); - } - - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (this.getBaseMetaTileEntity().isServerSide() && this.getBaseMetaTileEntity().isAllowedToWork()) { - if (this.getItemCount() <= 0) { - this.mItemStack = null; - this.mItemCount = 0; - } - - if (this.mItemStack == null && this.mInventory[0] != null) { - this.mItemStack = this.mInventory[0].copy(); - } - - if (this.mInventory[0] != null && this.mItemCount < this.getMaxItemCount() - && GT_Utility.areStacksEqual(this.mInventory[0], this.mItemStack)) { - this.mItemCount += this.mInventory[0].stackSize; - if (this.mItemCount > this.getMaxItemCount()) { - this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount(); - this.mItemCount = this.getMaxItemCount(); - } else { - this.mInventory[0] = null; - } - } - - if (this.mInventory[1] == null && this.mItemStack != null) { - this.mInventory[1] = this.mItemStack.copy(); - this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); - this.mItemCount -= this.mInventory[1].stackSize; - } else if (this.mItemCount > 0 && GT_Utility.areStacksEqual(this.mInventory[1], this.mItemStack) - && this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) { - int tmp = Math.min(this.mItemCount, - this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize); - this.mInventory[1].stackSize += tmp; - this.mItemCount -= tmp; - } - - if (this.mItemStack != null) { - this.mInventory[2] = this.mItemStack.copy(); - this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); - } else { - this.mInventory[2] = null; - } - } - - } - - private int getItemCount() { - return this.mItemCount; - } - - public void setItemCount(int aCount) { - this.mItemCount = aCount; - } - - public int getProgresstime() { - return this.mItemCount + (this.mInventory[0] == null ? 0 : this.mInventory[0].stackSize) - + (this.mInventory[1] == null ? 0 : this.mInventory[1].stackSize); - } - - public int maxProgresstime() { - return this.getMaxItemCount(); - } - - public int getMaxItemCount() { - return (int) (Math.pow(6.0D, (double) this.mTier) * mStorageFactor - 128.0D); - } - - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aIndex == 1; - } - - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aIndex == 0 && (this.mInventory[0] == null || GT_Utility.areStacksEqual(this.mInventory[0], aStack)); - } - - public String[] getInfoData() { - return this.mItemStack == null - ? new String[]{"Super Storage Chest", "Stored Items:", "No Items", Integer.toString(0), - Integer.toString(this.getMaxItemCount())} - : new String[]{"Super Storage Chest", "Stored Items:", this.mItemStack.getDisplayName(), - Integer.toString(this.mItemCount), Integer.toString(this.getMaxItemCount())}; - } - - public boolean isGivingInformation() { - return true; - } - - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mItemCount", this.mItemCount); - if (this.mItemStack != null) { - aNBT.setTag("mItemStack", this.mItemStack.writeToNBT(new NBTTagCompound())); - } - - } - - public void loadNBTData(NBTTagCompound aNBT) { - if (aNBT.hasKey("mItemCount")) { - this.mItemCount = aNBT.getInteger("mItemCount"); - } - - if (aNBT.hasKey("mItemStack")) { - this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")); - } - - } - - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, - boolean aActive, boolean aRedstone) { - return aBaseMetaTileEntity.getFrontFacing() == 0 && aSide == 4 - ? new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], - new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST)} - : (aSide == aBaseMetaTileEntity.getFrontFacing() - ? new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], - new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST)} - : new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]}); - } - - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - return new ITexture[0][0][0]; - } -}
\ No newline at end of file + public int mItemCount = 0; + public ItemStack mItemStack = null; + private static final double mStorageFactor = (270000.0D / 16); + + public GT_MetaTileEntity_TieredChest(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 3, + "This Chest stores " + (int) (Math.pow(6.0D, (double) aTier) * mStorageFactor) + " Items", + new ITexture[0]); + } + + public GT_MetaTileEntity_TieredChest(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + /*public GT_MetaTileEntity_TieredChest(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + }*/ + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, CORE.GT_Tooltip}; + } + + public boolean isSimpleMachine() { + return true; + } + + public boolean isFacingValid(byte aFacing) { + return true; + } + + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + public boolean isValidSlot(int aIndex) { + return true; + } + + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TieredChest(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } else { + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + } + + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_SuperChest(aPlayerInventory, aBaseMetaTileEntity); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_SuperChest(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); + } + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (this.getBaseMetaTileEntity().isServerSide() + && this.getBaseMetaTileEntity().isAllowedToWork()) { + if (this.getItemCount() <= 0) { + this.mItemStack = null; + this.mItemCount = 0; + } + + if (this.mItemStack == null && this.mInventory[0] != null) { + this.mItemStack = this.mInventory[0].copy(); + } + + if (this.mInventory[0] != null + && this.mItemCount < this.getMaxItemCount() + && GT_Utility.areStacksEqual(this.mInventory[0], this.mItemStack)) { + this.mItemCount += this.mInventory[0].stackSize; + if (this.mItemCount > this.getMaxItemCount()) { + this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount(); + this.mItemCount = this.getMaxItemCount(); + } else { + this.mInventory[0] = null; + } + } + + if (this.mInventory[1] == null && this.mItemStack != null) { + this.mInventory[1] = this.mItemStack.copy(); + this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + this.mItemCount -= this.mInventory[1].stackSize; + } else if (this.mItemCount > 0 + && GT_Utility.areStacksEqual(this.mInventory[1], this.mItemStack) + && this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) { + int tmp = + Math.min(this.mItemCount, this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize); + this.mInventory[1].stackSize += tmp; + this.mItemCount -= tmp; + } + + if (this.mItemStack != null) { + this.mInventory[2] = this.mItemStack.copy(); + this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + } else { + this.mInventory[2] = null; + } + } + } + + private int getItemCount() { + return this.mItemCount; + } + + public void setItemCount(int aCount) { + this.mItemCount = aCount; + } + + public int getProgresstime() { + return this.mItemCount + + (this.mInventory[0] == null ? 0 : this.mInventory[0].stackSize) + + (this.mInventory[1] == null ? 0 : this.mInventory[1].stackSize); + } + + public int maxProgresstime() { + return this.getMaxItemCount(); + } + + public int getMaxItemCount() { + return (int) (Math.pow(6.0D, (double) this.mTier) * mStorageFactor - 128.0D); + } + + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aIndex == 1; + } + + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aIndex == 0 && (this.mInventory[0] == null || GT_Utility.areStacksEqual(this.mInventory[0], aStack)); + } + + public String[] getInfoData() { + return this.mItemStack == null + ? new String[] { + "Super Storage Chest", + "Stored Items:", + "No Items", + Integer.toString(0), + Integer.toString(this.getMaxItemCount()) + } + : new String[] { + "Super Storage Chest", + "Stored Items:", + this.mItemStack.getDisplayName(), + Integer.toString(this.mItemCount), + Integer.toString(this.getMaxItemCount()) + }; + } + + public boolean isGivingInformation() { + return true; + } + + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mItemCount", this.mItemCount); + if (this.mItemStack != null) { + aNBT.setTag("mItemStack", this.mItemStack.writeToNBT(new NBTTagCompound())); + } + } + + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("mItemCount")) { + this.mItemCount = aNBT.getInteger("mItemCount"); + } + + if (aNBT.hasKey("mItemStack")) { + this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")); + } + } + + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + return aBaseMetaTileEntity.getFrontFacing() == 0 && aSide == 4 + ? new ITexture[] { + BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], + new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST) + } + : (aSide == aBaseMetaTileEntity.getFrontFacing() + ? new ITexture[] { + BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], + new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST) + } + : new ITexture[] {BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]}); + } + + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + return new ITexture[0][0][0]; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredTank.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredTank.java index ef7fe829d4..22537dc5cf 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredTank.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredTank.java @@ -1,8 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -10,151 +7,172 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.objects.GT_RenderedTexture; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.preloader.asm.AsmConfig; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_TieredTank extends GT_MetaTileEntity_BasicTank { - public GT_MetaTileEntity_TieredTank(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier, 3, "Stores " + ((int) (Math.pow(2, aTier) * 32000)) + "L of fluid"); - } - - public GT_MetaTileEntity_TieredTank(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, 3, "Stores " + ((int) (Math.pow(2, aTier) * 32000)) + "L of fluid", aTextures); - } - - @Override - public String[] getDescription() { - String[] aTip; - - String aTankPortableness = "portable"; - - if (this.mFluid == null) { - aTip = new String[] {this.mDescription, "A "+aTankPortableness+" tank.", CORE.GT_Tooltip}; - } - else { - aTip = new String[] {this.mDescription, "A "+aTankPortableness+" tank.", "Fluid: "+mFluid.getLocalizedName()+" "+mFluid.amount+"L", CORE.GT_Tooltip}; - } - return aTip; - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - return new ITexture[0][0][0]; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return aSide == 1 ? new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_POTIONBREWER_ACTIVE)} : new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_POTIONBREWER)}; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(final byte aFacing) { - return true; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public final byte getUpdateData() { - return 0x00; - } - - @Override - public boolean doesFillContainers() { - return true; - } - - @Override - public boolean doesEmptyContainers() { - return true; - } - - @Override - public boolean canTankBeFilled() { - return true; - } - - @Override - public boolean canTankBeEmptied() { - return true; - } - - @Override - public String[] getInfoData() { - - if (this.mFluid == null) { - return new String[]{ - GT_Values.VOLTAGE_NAMES[this.mTier]+" Fluid Tank", - "Stored Fluid:", - "No Fluid", - Integer.toString(0) + "L", - Integer.toString(this.getCapacity()) + "L"}; - } - return new String[]{ - GT_Values.VOLTAGE_NAMES[this.mTier]+" Fluid Tank", - "Stored Fluid:", - this.mFluid.getLocalizedName(), - Integer.toString(this.mFluid.amount) + "L", - Integer.toString(this.getCapacity()) + "L"}; - } - - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_TieredTank(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public int getCapacity() { - return (int) (Math.pow(2, this.mTier) * 32000); - } - - @Override - public int getTankPressure() { - return 100; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()){ - //setVars(); - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public boolean displaysItemStack() { - return true; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - @Override - public void setItemNBT(NBTTagCompound aNBT) { - if (CORE.NBT_PERSISTENCY_PATCH_APPLIED) { - if (mFluid != null){ - Logger.WARNING("Setting item fluid nbt"); - aNBT.setTag("mFluid", mFluid.writeToNBT(new NBTTagCompound())); - if (aNBT.hasKey("mFluid")) { - Logger.WARNING("Set mFluid to NBT."); - } - } - } - } - -}
\ No newline at end of file + public GT_MetaTileEntity_TieredTank( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier, 3, "Stores " + ((int) (Math.pow(2, aTier) * 32000)) + "L of fluid"); + } + + public GT_MetaTileEntity_TieredTank( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 3, "Stores " + ((int) (Math.pow(2, aTier) * 32000)) + "L of fluid", aTextures); + } + + @Override + public String[] getDescription() { + String[] aTip; + + String aTankPortableness = "portable"; + + if (this.mFluid == null) { + aTip = new String[] {this.mDescription, "A " + aTankPortableness + " tank.", CORE.GT_Tooltip}; + } else { + aTip = new String[] { + this.mDescription, + "A " + aTankPortableness + " tank.", + "Fluid: " + mFluid.getLocalizedName() + " " + mFluid.amount + "L", + CORE.GT_Tooltip + }; + } + return aTip; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + return new ITexture[0][0][0]; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return aSide == 1 + ? new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_POTIONBREWER_ACTIVE) + } + : new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_POTIONBREWER) + }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public final byte getUpdateData() { + return 0x00; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return true; + } + + @Override + public String[] getInfoData() { + + if (this.mFluid == null) { + return new String[] { + GT_Values.VOLTAGE_NAMES[this.mTier] + " Fluid Tank", + "Stored Fluid:", + "No Fluid", + Integer.toString(0) + "L", + Integer.toString(this.getCapacity()) + "L" + }; + } + return new String[] { + GT_Values.VOLTAGE_NAMES[this.mTier] + " Fluid Tank", + "Stored Fluid:", + this.mFluid.getLocalizedName(), + Integer.toString(this.mFluid.amount) + "L", + Integer.toString(this.getCapacity()) + "L" + }; + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TieredTank(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public int getCapacity() { + return (int) (Math.pow(2, this.mTier) * 32000); + } + + @Override + public int getTankPressure() { + return 100; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + // setVars(); + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public boolean displaysItemStack() { + return true; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + if (CORE.NBT_PERSISTENCY_PATCH_APPLIED) { + if (mFluid != null) { + Logger.WARNING("Setting item fluid nbt"); + aNBT.setTag("mFluid", mFluid.writeToNBT(new NBTTagCompound())); + if (aNBT.hasKey("mFluid")) { + Logger.WARNING("Set mFluid to NBT."); + } + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java index e18f5d4bfc..775c10666e 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java @@ -24,396 +24,507 @@ import net.minecraft.world.World; public class GregtechMetaEnergyBuffer extends GregtechMetaTileEntity { - protected byte aCurrentOutputAmperage = 4; - - public GregtechMetaEnergyBuffer(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); - } - - public GregtechMetaEnergyBuffer(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { - super(aName, aTier, aSlotCount, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[] {this.mDescription, - "Defaults 4A In/Out", - "Change output Amperage with a screwdriver", - "Now Portable!", - CORE.GT_Tooltip}; - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCover) { - if (aSide != this.getBaseMetaTileEntity().getFrontFacing()) { - return true; - } - return super.allowCoverOnSide(aSide, aCover); - } - - /* - * MACHINE_STEEL_SIDE - */ - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFrontActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; - } - - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange)}; - } - - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange)}; - } - - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Screen_Logo)}; - } - - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange)}; - } - - - public ITexture[] getFrontActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; - } - - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange)}; - } - - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange)}; - } - - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Screen_Logo)}; - } - - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange)}; - } - - /*@Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[2][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = new ITexture[] { new GT_RenderedTexture( - Textures.BlockIcons.MACHINE_HEATPROOFCASING) }; - rTextures[1][i + 1] = new ITexture[] { - new GT_RenderedTexture( - Textures.BlockIcons.MACHINE_HEATPROOFCASING), - mInventory.length > 4 ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier] - : Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; - } - return rTextures; - }*/ - - /* - * @Override public ITexture[][][] getTextureSet(ITexture[] aTextures) { - * ITexture[][][] rTextures = new ITexture[5][17][]; for (byte i = -1; i < - * 16; i = (byte) (i + 1)) { ITexture[] tmp0 = { new GT_RenderedTexture( - * Textures.BlockIcons.MACHINE_STEEL_BOTTOM, Dyes.getModulation(i, - * Dyes._NULL.mRGBa)) }; rTextures[0][(i + 1)] = tmp0; ITexture[] tmp1 = { - * new GT_RenderedTexture( Textures.BlockIcons.MACHINE_STEEL_TOP) }; - * rTextures[1][(i + 1)] = tmp1; ITexture[] tmp2 = { new GT_RenderedTexture( - * Textures.BlockIcons.MACHINE_STEEL_SIDE, Dyes.getModulation(i, - * Dyes._NULL.mRGBa)), new - * GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) }; rTextures[2][(i + - * 1)] = tmp2; ITexture[] tmp4 = { new GT_RenderedTexture( - * Textures.BlockIcons.MACHINE_STEEL_SIDE, Dyes.getModulation(i, - * Dyes._NULL.mRGBa)), new - * GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT) }; rTextures[3][(i + - * 1)] = tmp4; ITexture[] tmp5 = { new GT_RenderedTexture( - * Textures.BlockIcons.MACHINE_STEEL_SIDE, Dyes.getModulation(i, - * Dyes._NULL.mRGBa)), new GT_RenderedTexture( - * Textures.BlockIcons.BOILER_FRONT_ACTIVE) }; rTextures[4][(i + 1)] = tmp5; - * } return rTextures; } - */ - - /*@Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return mTextures[aSide == aFacing ? 1 : 0][aColorIndex+1]; - }*/ - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaEnergyBuffer(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); - } - - @Override public boolean isSimpleMachine() {return false;} - @Override public boolean isElectric() {return true;} - @Override public boolean isValidSlot(final int aIndex) {return true;} - @Override public boolean isFacingValid(final byte aFacing) {return true;} - @Override public boolean isEnetInput() {return true;} - @Override public boolean isEnetOutput() {return true;} - @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} - @Override public boolean isTeleporterCompatible() {return false;} - @Override public long getMinimumStoredEU() {return V[this.mTier]*2;} - @Override public long maxEUStore() {return V[this.mTier]*250000;} - - @Override - public long maxEUInput() { - return V[this.mTier]; - } - - @Override - public long maxEUOutput() { - return V[this.mTier]; - } - - @Override - public long maxAmperesIn() { - return aCurrentOutputAmperage; - } - - @Override - public long maxAmperesOut() { - return aCurrentOutputAmperage; - } - @Override public int rechargerSlotStartIndex() {return 0;} - @Override public int dechargerSlotStartIndex() {return 0;} - @Override public int rechargerSlotCount() {return 0;} - @Override public int dechargerSlotCount() {return 0;} - @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} - @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} - @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setByte("aCurrentOutputAmperage", aCurrentOutputAmperage); - if (CORE.NBT_PERSISTENCY_PATCH_APPLIED) { - long aEU = this.getBaseMetaTileEntity().getStoredEU(); - if (aEU > 0){ - aNBT.setLong("aStoredEU", aEU); - if (aNBT.hasKey("aStoredEU")) { - Logger.WARNING("Set aStoredEU to NBT."); - } - } - } - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - aCurrentOutputAmperage = aNBT.getByte("aCurrentOutputAmperage"); - if (aNBT.hasKey("aStoredEU")) { - this.setEUVar(aNBT.getLong("aStoredEU")); - } - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - Logger.WARNING("Right Click on MTE by Player"); - if (aBaseMetaTileEntity.isClientSide()) - { - return true; - //aBaseMetaTileEntity.openGUI(aPlayer); - } - - Logger.WARNING("MTE is Client-side"); - this.showEnergy(aPlayer.getEntityWorld(), aPlayer); - return true; - } - - protected void showEnergy(final World worldIn, final EntityPlayer playerIn){ - final long tempStorage = this.getBaseMetaTileEntity().getStoredEU(); - final double c = ((double) tempStorage / this.maxEUStore()) * 100; - final double roundOff = Math.round(c * 100.00) / 100.00; - PlayerUtils.messagePlayer(playerIn, "Energy: " + GT_Utility.formatNumbers(tempStorage) + " EU at "+V[this.mTier]+"v ("+roundOff+"%)"); - PlayerUtils.messagePlayer(playerIn, "Amperage: " + GT_Utility.formatNumbers(maxAmperesOut())+"A"); - - } - //Utils.LOG_WARNING("Begin Show Energy"); - /* - * - //Utils.LOG_INFO("getProgresstime: "+tempStorage+" maxProgresstime: "+maxEUStore()+" C: "+c); - Utils.LOG_INFO("getProgressTime: "+getProgresstime()); - Utils.LOG_INFO("maxProgressTime: "+maxProgresstime()); - Utils.LOG_INFO("getMinimumStoredEU: "+getMinimumStoredEU()); - Utils.LOG_INFO("maxEUStore: "+maxEUStore());*/ - /*final long d = (tempStorage * 100L) / maxEUStore(); - Utils.LOG_INFO("getProgresstime: "+tempStorage+" maxProgresstime: "+maxEUStore()+" D: "+d); - final double roundOff2 = Math.round(d * 100.00) / 100.00; - Utils.messagePlayer(playerIn, "Energy: " + tempStorage + " EU at "+V[mTier]+"v ("+roundOff2+"%)"); - Utils.LOG_WARNING("Making new instance of Guihandler"); - GuiHandler block = new GuiHandler(); - Utils.LOG_WARNING("Guihandler.toString(): "+block.toString()); - block.getClientGuiElement(1, playerIn, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);*/ - - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return false; - } - - @Override - public String[] getInfoData() { - String cur = GT_Utility.formatNumbers(this.getBaseMetaTileEntity().getStoredEU()); - String max = GT_Utility.formatNumbers(this.getBaseMetaTileEntity().getEUCapacity()); - - // Right-align current storage with maximum storage - String fmt = String.format("%%%ds", max.length()); - cur = String.format(fmt, cur); - - return new String[] { - cur+" EU stored", - max+" EU capacity"}; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { - return new int[] {}; - } - - @Override - public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { - return false; - } - - @Override - public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { - return false; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(final int p_70301_1_) { - return null; - } - - @Override - public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { - return null; - } - - @Override - public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { - } - - @Override - public String getInventoryName() { - return super.getInventoryName(); - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - @Override - public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { - return false; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { - return false; - } - - @Override - public void setItemNBT(NBTTagCompound aNBT) { - if (CORE.NBT_PERSISTENCY_PATCH_APPLIED) { - aNBT.setByte("aCurrentOutputAmperage", aCurrentOutputAmperage); - long aEU = this.getBaseMetaTileEntity().getStoredEU(); - if (aEU > 0){ - aNBT.setLong("aStoredEU", aEU); - if (aNBT.hasKey("aStoredEU")) { - Logger.WARNING("Set aStoredEU to NBT."); - } - } - } - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - byte aTest = (byte) (aCurrentOutputAmperage + 1); - if (aTest > 16 || aTest <= 0 ) { - aTest = 1; - } - aCurrentOutputAmperage = aTest; - PlayerUtils.messagePlayer(aPlayer, "Now handling "+aCurrentOutputAmperage+" Amps."); - } - - - - - - -}
\ No newline at end of file + protected byte aCurrentOutputAmperage = 4; + + public GregtechMetaEnergyBuffer( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaEnergyBuffer( + final String aName, + final int aTier, + final String aDescription, + final ITexture[][][] aTextures, + final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Defaults 4A In/Out", + "Change output Amperage with a screwdriver", + "Now Portable!", + CORE.GT_Tooltip + }; + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCover) { + if (aSide != this.getBaseMetaTileEntity().getFrontFacing()) { + return true; + } + return super.allowCoverOnSide(aSide, aCover); + } + + /* + * MACHINE_STEEL_SIDE + */ + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return this.mTextures[ + (aActive ? 5 : 0) + + (aSide == aFacing + ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) + ? 1 + : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][ + aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Screen_Logo) + }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Screen_Logo) + }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) + }; + } + + /*@Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[2][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = new ITexture[] { new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_HEATPROOFCASING) }; + rTextures[1][i + 1] = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_HEATPROOFCASING), + mInventory.length > 4 ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier] + : Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; + } + return rTextures; + }*/ + + /* + * @Override public ITexture[][][] getTextureSet(ITexture[] aTextures) { + * ITexture[][][] rTextures = new ITexture[5][17][]; for (byte i = -1; i < + * 16; i = (byte) (i + 1)) { ITexture[] tmp0 = { new GT_RenderedTexture( + * Textures.BlockIcons.MACHINE_STEEL_BOTTOM, Dyes.getModulation(i, + * Dyes._NULL.mRGBa)) }; rTextures[0][(i + 1)] = tmp0; ITexture[] tmp1 = { + * new GT_RenderedTexture( Textures.BlockIcons.MACHINE_STEEL_TOP) }; + * rTextures[1][(i + 1)] = tmp1; ITexture[] tmp2 = { new GT_RenderedTexture( + * Textures.BlockIcons.MACHINE_STEEL_SIDE, Dyes.getModulation(i, + * Dyes._NULL.mRGBa)), new + * GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) }; rTextures[2][(i + + * 1)] = tmp2; ITexture[] tmp4 = { new GT_RenderedTexture( + * Textures.BlockIcons.MACHINE_STEEL_SIDE, Dyes.getModulation(i, + * Dyes._NULL.mRGBa)), new + * GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT) }; rTextures[3][(i + + * 1)] = tmp4; ITexture[] tmp5 = { new GT_RenderedTexture( + * Textures.BlockIcons.MACHINE_STEEL_SIDE, Dyes.getModulation(i, + * Dyes._NULL.mRGBa)), new GT_RenderedTexture( + * Textures.BlockIcons.BOILER_FRONT_ACTIVE) }; rTextures[4][(i + 1)] = tmp5; + * } return rTextures; } + */ + + /*@Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + return mTextures[aSide == aFacing ? 1 : 0][aColorIndex+1]; + }*/ + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaEnergyBuffer( + this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return V[this.mTier] * 2; + } + + @Override + public long maxEUStore() { + return V[this.mTier] * 250000; + } + + @Override + public long maxEUInput() { + return V[this.mTier]; + } + + @Override + public long maxEUOutput() { + return V[this.mTier]; + } + + @Override + public long maxAmperesIn() { + return aCurrentOutputAmperage; + } + + @Override + public long maxAmperesOut() { + return aCurrentOutputAmperage; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setByte("aCurrentOutputAmperage", aCurrentOutputAmperage); + if (CORE.NBT_PERSISTENCY_PATCH_APPLIED) { + long aEU = this.getBaseMetaTileEntity().getStoredEU(); + if (aEU > 0) { + aNBT.setLong("aStoredEU", aEU); + if (aNBT.hasKey("aStoredEU")) { + Logger.WARNING("Set aStoredEU to NBT."); + } + } + } + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + aCurrentOutputAmperage = aNBT.getByte("aCurrentOutputAmperage"); + if (aNBT.hasKey("aStoredEU")) { + this.setEUVar(aNBT.getLong("aStoredEU")); + } + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + Logger.WARNING("Right Click on MTE by Player"); + if (aBaseMetaTileEntity.isClientSide()) { + return true; + // aBaseMetaTileEntity.openGUI(aPlayer); + } + + Logger.WARNING("MTE is Client-side"); + this.showEnergy(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + protected void showEnergy(final World worldIn, final EntityPlayer playerIn) { + final long tempStorage = this.getBaseMetaTileEntity().getStoredEU(); + final double c = ((double) tempStorage / this.maxEUStore()) * 100; + final double roundOff = Math.round(c * 100.00) / 100.00; + PlayerUtils.messagePlayer( + playerIn, + "Energy: " + GT_Utility.formatNumbers(tempStorage) + " EU at " + V[this.mTier] + "v (" + roundOff + + "%)"); + PlayerUtils.messagePlayer(playerIn, "Amperage: " + GT_Utility.formatNumbers(maxAmperesOut()) + "A"); + } + // Utils.LOG_WARNING("Begin Show Energy"); + /* + * + //Utils.LOG_INFO("getProgresstime: "+tempStorage+" maxProgresstime: "+maxEUStore()+" C: "+c); + Utils.LOG_INFO("getProgressTime: "+getProgresstime()); + Utils.LOG_INFO("maxProgressTime: "+maxProgresstime()); + Utils.LOG_INFO("getMinimumStoredEU: "+getMinimumStoredEU()); + Utils.LOG_INFO("maxEUStore: "+maxEUStore());*/ + /*final long d = (tempStorage * 100L) / maxEUStore(); + Utils.LOG_INFO("getProgresstime: "+tempStorage+" maxProgresstime: "+maxEUStore()+" D: "+d); + final double roundOff2 = Math.round(d * 100.00) / 100.00; + Utils.messagePlayer(playerIn, "Energy: " + tempStorage + " EU at "+V[mTier]+"v ("+roundOff2+"%)"); + Utils.LOG_WARNING("Making new instance of Guihandler"); + GuiHandler block = new GuiHandler(); + Utils.LOG_WARNING("Guihandler.toString(): "+block.toString()); + block.getClientGuiElement(1, playerIn, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);*/ + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + String cur = GT_Utility.formatNumbers(this.getBaseMetaTileEntity().getStoredEU()); + String max = GT_Utility.formatNumbers(this.getBaseMetaTileEntity().getEUCapacity()); + + // Right-align current storage with maximum storage + String fmt = String.format("%%%ds", max.length()); + cur = String.format(fmt, cur); + + return new String[] {cur + " EU stored", max + " EU capacity"}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return super.getInventoryName(); + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + if (CORE.NBT_PERSISTENCY_PATCH_APPLIED) { + aNBT.setByte("aCurrentOutputAmperage", aCurrentOutputAmperage); + long aEU = this.getBaseMetaTileEntity().getStoredEU(); + if (aEU > 0) { + aNBT.setLong("aStoredEU", aEU); + if (aNBT.hasKey("aStoredEU")) { + Logger.WARNING("Set aStoredEU to NBT."); + } + } + } + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + byte aTest = (byte) (aCurrentOutputAmperage + 1); + if (aTest > 16 || aTest <= 0) { + aTest = 1; + } + aCurrentOutputAmperage = aTest; + PlayerUtils.messagePlayer(aPlayer, "Now handling " + aCurrentOutputAmperage + " Amps."); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaSafeBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaSafeBlock.java index 63042d4702..064312fae2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaSafeBlock.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaSafeBlock.java @@ -1,62 +1,71 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage; -import net.minecraft.entity.player.InventoryPlayer; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_RenderedTexture; - import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_SafeBlock; import gtPlusPlus.xmod.gregtech.api.gui.GUI_SafeBlock; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.machines.GregtechMetaSafeBlockBase; +import net.minecraft.entity.player.InventoryPlayer; + +public class GregtechMetaSafeBlock extends GregtechMetaSafeBlockBase { + + public GregtechMetaSafeBlock(final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier, 28, "Protecting your items from sticky fingers."); + } + + public GregtechMetaSafeBlock( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final int aInvSlotCount, + final String aDescription) { + super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription); + } + + public GregtechMetaSafeBlock( + final String aName, + final int aTier, + final int aInvSlotCount, + final String aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, CORE.GT_Tooltip}; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaSafeBlock( + this.mName, this.mTier, this.mInventory.length, this.mDescription, this.mTextures); + } + + @Override + public ITexture getOverlayIcon() { + return new GT_RenderedTexture(Textures.BlockIcons.VOID); + } + + @Override + public boolean isValidSlot(final int aIndex) { + return aIndex < (this.mInventory.length - 1); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_SafeBlock(aPlayerInventory, aBaseMetaTileEntity); + } -public class GregtechMetaSafeBlock -extends GregtechMetaSafeBlockBase { - - public GregtechMetaSafeBlock(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier, 28, "Protecting your items from sticky fingers."); - } - - public GregtechMetaSafeBlock(final int aID, final String aName, final String aNameRegional, final int aTier, final int aInvSlotCount, final String aDescription) { - super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription); - } - - public GregtechMetaSafeBlock(final String aName, final int aTier, final int aInvSlotCount, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aInvSlotCount, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - CORE.GT_Tooltip}; - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaSafeBlock(this.mName, this.mTier, this.mInventory.length, this.mDescription, this.mTextures); - } - - @Override - public ITexture getOverlayIcon() { - return new GT_RenderedTexture(Textures.BlockIcons.VOID); - } - - @Override - public boolean isValidSlot(final int aIndex) { - return aIndex < (this.mInventory.length - 1); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_SafeBlock(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_SafeBlock(aPlayerInventory, aBaseMetaTileEntity); - } + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_SafeBlock(aPlayerInventory, aBaseMetaTileEntity); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/creative/GT_MetaTileEntity_InfiniteItemHolder.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/creative/GT_MetaTileEntity_InfiniteItemHolder.java index fb37f33055..1ca167925c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/creative/GT_MetaTileEntity_InfiniteItemHolder.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/creative/GT_MetaTileEntity_InfiniteItemHolder.java @@ -1,9 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage.creative; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -11,95 +7,95 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.sys.KeyboardUtils; import gtPlusPlus.xmod.gregtech.common.tileentities.storage.GT_MetaTileEntity_TieredChest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_InfiniteItemHolder extends GT_MetaTileEntity_TieredChest { - public GT_MetaTileEntity_InfiniteItemHolder(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier); - } - - public GT_MetaTileEntity_InfiniteItemHolder(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - CORE.GT_Tooltip}; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.getWorld().isRemote) { - return false; - } - - if (!KeyboardUtils.isShiftKeyDown()) { - if (this.mItemStack == null) { - if (aPlayer.getHeldItem() != null) { - this.mItemStack = aPlayer.getHeldItem().copy(); - this.mItemCount = Short.MAX_VALUE; - aPlayer.setCurrentItemOrArmor(0, null); - PlayerUtils.messagePlayer(aPlayer, "Now holding "+this.mItemStack.getDisplayName()+" x"+Short.MAX_VALUE+"."); - return true; - } - } - else { - if (aPlayer.getHeldItem() == null) { - aPlayer.entityDropItem(mItemStack, 1); - this.mItemStack = null; - this.mItemCount = 0; - PlayerUtils.messagePlayer(aPlayer, "Emptying."); - return true; - } - } - } - - PlayerUtils.messagePlayer(aPlayer, "Currently holding: "+(this.mItemStack != null ? this.mItemStack.getDisplayName() : "Nothing")+" x"+this.mItemCount); - return true; - //return super.onRightclick(aBaseMetaTileEntity, aPlayer); - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (mItemStack != null) { - setItemCount(0); - } - super.onPostTick(aBaseMetaTileEntity, aTimer); - } - - @Override - public void setItemCount(int aCount) { - super.setItemCount(Short.MAX_VALUE); - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return true; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_InfiniteItemHolder(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - - - - + public GT_MetaTileEntity_InfiniteItemHolder(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_InfiniteItemHolder( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, CORE.GT_Tooltip}; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.getWorld().isRemote) { + return false; + } + + if (!KeyboardUtils.isShiftKeyDown()) { + if (this.mItemStack == null) { + if (aPlayer.getHeldItem() != null) { + this.mItemStack = aPlayer.getHeldItem().copy(); + this.mItemCount = Short.MAX_VALUE; + aPlayer.setCurrentItemOrArmor(0, null); + PlayerUtils.messagePlayer( + aPlayer, "Now holding " + this.mItemStack.getDisplayName() + " x" + Short.MAX_VALUE + "."); + return true; + } + } else { + if (aPlayer.getHeldItem() == null) { + aPlayer.entityDropItem(mItemStack, 1); + this.mItemStack = null; + this.mItemCount = 0; + PlayerUtils.messagePlayer(aPlayer, "Emptying."); + return true; + } + } + } + + PlayerUtils.messagePlayer( + aPlayer, + "Currently holding: " + (this.mItemStack != null ? this.mItemStack.getDisplayName() : "Nothing") + " x" + + this.mItemCount); + return true; + // return super.onRightclick(aBaseMetaTileEntity, aPlayer); + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (mItemStack != null) { + setItemCount(0); + } + super.onPostTick(aBaseMetaTileEntity, aTimer); + } + + @Override + public void setItemCount(int aCount) { + super.setItemCount(Short.MAX_VALUE); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return true; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_InfiniteItemHolder(this.mName, this.mTier, this.mDescription, this.mTextures); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java index 43d5cffe82..18e95861b3 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java @@ -1,10 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage.shelving; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.enums.*; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -14,346 +9,366 @@ import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; import gregtech.common.items.GT_MetaGenerated_Tool_01; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.sys.KeyboardUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class GT4Entity_Shelf extends GT_MetaTileEntity_BasicHull_NonElectric { - public byte mType = 0; - public String mOldDesc = ""; - public boolean mLocked = false; - protected byte mIndex = (byte) MathUtils.randInt(1, 3); - public static GT_RenderedTexture texBottom = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_bottom")); - public static GT_RenderedTexture texTop = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_top")); - public static GT_RenderedTexture texSide = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_side")); - public static GT_RenderedTexture texSideCabinet = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_side_cabinet")); - - public GT4Entity_Shelf(final int aID, final String aName, final String aNameRegional, final String aDescription) { - super(aID, aName, aNameRegional, 0, aDescription); - mOldDesc = aDescription; - } - - public GT4Entity_Shelf(final String aName, final String aDescription, final ITexture[][][] aTextures) { - super(aName, 0, aDescription, aTextures); - mOldDesc = aDescription; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - public int getInvSize() { - return 1; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - if (this.getBaseMetaTileEntity().getOwnerName().equalsIgnoreCase(aPlayer.getDisplayName())) { - return true; - } - PlayerUtils.messagePlayer(aPlayer, "This container belongs to "+this.getBaseMetaTileEntity().getOwnerName()+"."); - return false; - } - - @Override - public boolean ownerControl() { - return false; - } - - @Override - public boolean isEnetOutput() { - return false; - } - - @Override - public boolean isEnetInput() { - return false; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return aSide != this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public boolean isInputFacing(byte aSide) { - return false; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aTile, EntityPlayer aPlayer) { - if (aTile.isClientSide()) { - return true; - } - ItemStack tStack = aPlayer.inventory.getStackInSlot(aPlayer.inventory.currentItem); - if (tStack == null) { - if (KeyboardUtils.isCtrlKeyDown()) { - if (this.mInventory[0] != null) { - PlayerUtils.messagePlayer(aPlayer, "Contains "+this.mInventory[0].getDisplayName()+" x"+this.mInventory[0].stackSize+"."); - } - return false; - } - else { - if ((this.mInventory[0] != null) && (this.mInventory[0].stackSize > 0)) { - if (!this.mLocked) { - PlayerUtils.messagePlayer(aPlayer, "Removed "+this.mInventory[0].getDisplayName()+" x"+this.mInventory[0].stackSize+"."); - aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, this.mInventory[0]); - getBaseMetaTileEntity().setInventorySlotContents(0, null); - this.mType = 0; - return true; - } - else { - PlayerUtils.messagePlayer(aPlayer, "This container is locked. It belongs to "+aTile.getOwnerName()+"."); - return false; - } - } - return false; - } - } - else if (tStack != null && this.mInventory[0] == null) { - - if (KeyboardUtils.isCtrlKeyDown() || GT_MetaGenerated_Tool_01.class.isInstance(tStack.getItem())) { - return false; - } - PlayerUtils.messagePlayer(aPlayer, "Stored "+tStack.getDisplayName()+" x"+tStack.stackSize+"."); - aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, null); - getBaseMetaTileEntity().setInventorySlotContents(0, tStack); - this.mType = (byte) MathUtils.randInt(1, 3); - return true; - } - else { - if (this.mInventory[0] == null) { - this.mType = 0; - } - return super.onRightclick(aTile, aPlayer); - } - } - - @Override - public void onLeftclick(IGregTechTileEntity aTile,EntityPlayer aPlayer) { - if ((this.mInventory[0] != null) && (this.mInventory[0].stackSize > 0)) { - ItemStack tOutput = GT_Utility.copy(new Object[] { this.mInventory[0] }); - if (!aPlayer.isSneaking()) { - tOutput.stackSize = 1; - } - getBaseMetaTileEntity().decrStackSize(0, tOutput.stackSize); - EntityItem tEntity = new EntityItem(getBaseMetaTileEntity().getWorld(), - getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1) + 0.5D, - getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1) + 0.5D, - getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1) + 0.5D, tOutput); - tEntity.motionX = 0.0D; - tEntity.motionY = 0.0D; - tEntity.motionZ = 0.0D; - getBaseMetaTileEntity().getWorld().spawnEntityInWorld(tEntity); - if (this.mInventory[0] == null) { - this.mType = 0; - } - } - super.onLeftclick(aTile, aPlayer); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT4Entity_Shelf(this.mName, this.mDescription, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) {//mLocked - aNBT.setInteger("mType", this.mType); - aNBT.setBoolean("mLocked", this.mLocked); - aNBT.setByte("mIndex", this.mIndex); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - if (aNBT.hasKey("mIndex")) { - this.mType = ((byte) aNBT.getInteger("mType")); - } - if (aNBT.hasKey("mIndex")) { - this.mLocked = (aNBT.getBoolean("mLocked")); - } - if (aNBT.hasKey("mIndex")) { - this.mIndex = aNBT.getByte("mIndex"); - } - } - - @Override - public void onValueUpdate(byte aValue) { - this.mType = aValue; - } - - @Override - public byte getUpdateData() { - return this.mType; - } - - @Override - public String[] getDescription() { - return new String[] { - mOldDesc, - "Decorative Item Storage", - "Right click to store/remove something", - "Ctrl + Rmb to check contents", - "Ctrl + Rmb with a screwdriver to lock", - }; - } - - @Override - public byte getTileEntityBaseType() { - return 0; - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - //return aSide != getBaseMetaTileEntity().getFrontFacing(); - return false; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity p0, int p1, byte p2, ItemStack p3) { - return true; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity p0, int p1, byte p2, ItemStack p3) { - return false; - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[7][17][]; - for (byte i = -1; i < 16; i = (byte) (i + 1)) { - ITexture[] tmp0 = {this.getBottom((byte) 0)[0]}; - rTextures[0][(i + 1)] = tmp0; - ITexture[] tmp1 = { this.getTop((byte) 0)[0]}; - rTextures[1][(i + 1)] = tmp1; - ITexture[] tmp2 = { this.getSides((byte) 0)[0]}; - rTextures[2][(i + 1)] = tmp2; - ITexture[] tmp4 = {this.getSides((byte) 0)[0]}; - rTextures[3][(i + 1)] = tmp4; - ITexture[] tmp5 = {this.getSides((byte) 0)[0], getFront((byte) 0)[0]}; - rTextures[4][(i + 1)] = tmp5; - ITexture[] tmp6 = {this.getSides((byte) 0)[0], getFront((byte) 1)[0]}; - rTextures[5][(i + 1)] = tmp6; - ITexture[] tmp7 = {this.getSides((byte) 0)[0], getFront((byte) 2)[0]}; - rTextures[6][(i + 1)] = tmp7; - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, - final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, - final boolean aRedstone) { - - ITexture[] tmp = this.mTextures[(aSide >= 2) ? ((aSide != aFacing) ? 2 : ((byte) this.mType == 0 ? 4 : this.mType == 1 || this.mType == 2 ? 5 : this.mType == 3 ? 6 : 0)) : aSide][aColorIndex + 1]; - if (aSide != aFacing && tmp.length == 2) { - tmp = new ITexture[]{tmp[0]}; - } - return tmp; - } - - private static GT_RenderedTexture x1 = new GT_RenderedTexture(TexturesGtBlock.OVERLAY_WOODEN_SHELF_FRONT); - private static GT_RenderedTexture x2 = new GT_RenderedTexture(TexturesGtBlock.OVERLAY_WOODEN_SHELF_PAPER_FRONT); - private static GT_RenderedTexture x3 = new GT_RenderedTexture(TexturesGtBlock.OVERLAY_WOODEN_SHELF_CANS_FRONT); - - public ITexture[] getFrontNormal() { - return new ITexture[]{x1}; - } - public ITexture[] getFrontActive() { - return new ITexture[]{x2}; - } - public ITexture[] getFrontAlternative() { - return new ITexture[]{x3}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{ new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{ new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Acacia_Log)}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{ new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{ new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; - } - - public ITexture[] getFrontActive(final byte aColor) { - return this.getFrontNormal(); - } - - public ITexture[] getBackActive(final byte aColor) { - return this.getBack(aColor); - } - - public ITexture[] getBottomActive(final byte aColor) { - return this.getBottom(aColor); - } - - public ITexture[] getTopActive(final byte aColor) { - return this.getTop(aColor); - } - - public ITexture[] getSidesActive(final byte aColor) { - return this.getSides(aColor); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - public ITexture[] getFront(byte aColour) { - if (aColour == 1) { - return getFrontActive(); - } - else if (aColour == 2) { - return getFrontAlternative(); - } - return getFrontNormal(); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (KeyboardUtils.isCtrlKeyDown()) { - if (!aPlayer.getDisplayName().equalsIgnoreCase(this.getBaseMetaTileEntity().getOwnerName())) { - PlayerUtils.messagePlayer(aPlayer, "Container is not yours to lock."); - } - else { - this.mLocked = Utils.invertBoolean(this.mLocked); - if (this.mLocked) { - PlayerUtils.messagePlayer(aPlayer, "Container is now locked."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Container is now unlocked."); - } - } - } - else { - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - } - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - } - + public byte mType = 0; + public String mOldDesc = ""; + public boolean mLocked = false; + protected byte mIndex = (byte) MathUtils.randInt(1, 3); + public static GT_RenderedTexture texBottom = + new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_bottom")); + public static GT_RenderedTexture texTop = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_top")); + public static GT_RenderedTexture texSide = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_side")); + public static GT_RenderedTexture texSideCabinet = + new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_side_cabinet")); + + public GT4Entity_Shelf(final int aID, final String aName, final String aNameRegional, final String aDescription) { + super(aID, aName, aNameRegional, 0, aDescription); + mOldDesc = aDescription; + } + + public GT4Entity_Shelf(final String aName, final String aDescription, final ITexture[][][] aTextures) { + super(aName, 0, aDescription, aTextures); + mOldDesc = aDescription; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + public int getInvSize() { + return 1; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return aFacing > 1; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + if (this.getBaseMetaTileEntity().getOwnerName().equalsIgnoreCase(aPlayer.getDisplayName())) { + return true; + } + PlayerUtils.messagePlayer( + aPlayer, + "This container belongs to " + this.getBaseMetaTileEntity().getOwnerName() + "."); + return false; + } + + @Override + public boolean ownerControl() { + return false; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isInputFacing(byte aSide) { + return false; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aTile, EntityPlayer aPlayer) { + if (aTile.isClientSide()) { + return true; + } + ItemStack tStack = aPlayer.inventory.getStackInSlot(aPlayer.inventory.currentItem); + if (tStack == null) { + if (KeyboardUtils.isCtrlKeyDown()) { + if (this.mInventory[0] != null) { + PlayerUtils.messagePlayer( + aPlayer, + "Contains " + this.mInventory[0].getDisplayName() + " x" + this.mInventory[0].stackSize + + "."); + } + return false; + } else { + if ((this.mInventory[0] != null) && (this.mInventory[0].stackSize > 0)) { + if (!this.mLocked) { + PlayerUtils.messagePlayer( + aPlayer, + "Removed " + this.mInventory[0].getDisplayName() + " x" + this.mInventory[0].stackSize + + "."); + aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, this.mInventory[0]); + getBaseMetaTileEntity().setInventorySlotContents(0, null); + this.mType = 0; + return true; + } else { + PlayerUtils.messagePlayer( + aPlayer, "This container is locked. It belongs to " + aTile.getOwnerName() + "."); + return false; + } + } + return false; + } + } else if (tStack != null && this.mInventory[0] == null) { + + if (KeyboardUtils.isCtrlKeyDown() || GT_MetaGenerated_Tool_01.class.isInstance(tStack.getItem())) { + return false; + } + PlayerUtils.messagePlayer(aPlayer, "Stored " + tStack.getDisplayName() + " x" + tStack.stackSize + "."); + aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, null); + getBaseMetaTileEntity().setInventorySlotContents(0, tStack); + this.mType = (byte) MathUtils.randInt(1, 3); + return true; + } else { + if (this.mInventory[0] == null) { + this.mType = 0; + } + return super.onRightclick(aTile, aPlayer); + } + } + + @Override + public void onLeftclick(IGregTechTileEntity aTile, EntityPlayer aPlayer) { + if ((this.mInventory[0] != null) && (this.mInventory[0].stackSize > 0)) { + ItemStack tOutput = GT_Utility.copy(new Object[] {this.mInventory[0]}); + if (!aPlayer.isSneaking()) { + tOutput.stackSize = 1; + } + getBaseMetaTileEntity().decrStackSize(0, tOutput.stackSize); + EntityItem tEntity = new EntityItem( + getBaseMetaTileEntity().getWorld(), + getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1) + 0.5D, + getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1) + 0.5D, + getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1) + 0.5D, + tOutput); + tEntity.motionX = 0.0D; + tEntity.motionY = 0.0D; + tEntity.motionZ = 0.0D; + getBaseMetaTileEntity().getWorld().spawnEntityInWorld(tEntity); + if (this.mInventory[0] == null) { + this.mType = 0; + } + } + super.onLeftclick(aTile, aPlayer); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_Shelf(this.mName, this.mDescription, this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { // mLocked + aNBT.setInteger("mType", this.mType); + aNBT.setBoolean("mLocked", this.mLocked); + aNBT.setByte("mIndex", this.mIndex); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("mIndex")) { + this.mType = ((byte) aNBT.getInteger("mType")); + } + if (aNBT.hasKey("mIndex")) { + this.mLocked = (aNBT.getBoolean("mLocked")); + } + if (aNBT.hasKey("mIndex")) { + this.mIndex = aNBT.getByte("mIndex"); + } + } + + @Override + public void onValueUpdate(byte aValue) { + this.mType = aValue; + } + + @Override + public byte getUpdateData() { + return this.mType; + } + + @Override + public String[] getDescription() { + return new String[] { + mOldDesc, + "Decorative Item Storage", + "Right click to store/remove something", + "Ctrl + Rmb to check contents", + "Ctrl + Rmb with a screwdriver to lock", + }; + } + + @Override + public byte getTileEntityBaseType() { + return 0; + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + // return aSide != getBaseMetaTileEntity().getFrontFacing(); + return false; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity p0, int p1, byte p2, ItemStack p3) { + return true; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity p0, int p1, byte p2, ItemStack p3) { + return false; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[7][17][]; + for (byte i = -1; i < 16; i = (byte) (i + 1)) { + ITexture[] tmp0 = {this.getBottom((byte) 0)[0]}; + rTextures[0][(i + 1)] = tmp0; + ITexture[] tmp1 = {this.getTop((byte) 0)[0]}; + rTextures[1][(i + 1)] = tmp1; + ITexture[] tmp2 = {this.getSides((byte) 0)[0]}; + rTextures[2][(i + 1)] = tmp2; + ITexture[] tmp4 = {this.getSides((byte) 0)[0]}; + rTextures[3][(i + 1)] = tmp4; + ITexture[] tmp5 = {this.getSides((byte) 0)[0], getFront((byte) 0)[0]}; + rTextures[4][(i + 1)] = tmp5; + ITexture[] tmp6 = {this.getSides((byte) 0)[0], getFront((byte) 1)[0]}; + rTextures[5][(i + 1)] = tmp6; + ITexture[] tmp7 = {this.getSides((byte) 0)[0], getFront((byte) 2)[0]}; + rTextures[6][(i + 1)] = tmp7; + } + return rTextures; + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + + ITexture[] tmp = this.mTextures[ + (aSide >= 2) + ? ((aSide != aFacing) + ? 2 + : ((byte) this.mType == 0 + ? 4 + : this.mType == 1 || this.mType == 2 ? 5 : this.mType == 3 ? 6 : 0)) + : aSide][ + aColorIndex + 1]; + if (aSide != aFacing && tmp.length == 2) { + tmp = new ITexture[] {tmp[0]}; + } + return tmp; + } + + private static GT_RenderedTexture x1 = new GT_RenderedTexture(TexturesGtBlock.OVERLAY_WOODEN_SHELF_FRONT); + private static GT_RenderedTexture x2 = new GT_RenderedTexture(TexturesGtBlock.OVERLAY_WOODEN_SHELF_PAPER_FRONT); + private static GT_RenderedTexture x3 = new GT_RenderedTexture(TexturesGtBlock.OVERLAY_WOODEN_SHELF_CANS_FRONT); + + public ITexture[] getFrontNormal() { + return new ITexture[] {x1}; + } + + public ITexture[] getFrontActive() { + return new ITexture[] {x2}; + } + + public ITexture[] getFrontAlternative() { + return new ITexture[] {x3}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Acacia_Log)}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFrontNormal(); + } + + public ITexture[] getBackActive(final byte aColor) { + return this.getBack(aColor); + } + + public ITexture[] getBottomActive(final byte aColor) { + return this.getBottom(aColor); + } + + public ITexture[] getTopActive(final byte aColor) { + return this.getTop(aColor); + } + + public ITexture[] getSidesActive(final byte aColor) { + return this.getSides(aColor); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + public ITexture[] getFront(byte aColour) { + if (aColour == 1) { + return getFrontActive(); + } else if (aColour == 2) { + return getFrontAlternative(); + } + return getFrontNormal(); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (KeyboardUtils.isCtrlKeyDown()) { + if (!aPlayer.getDisplayName() + .equalsIgnoreCase(this.getBaseMetaTileEntity().getOwnerName())) { + PlayerUtils.messagePlayer(aPlayer, "Container is not yours to lock."); + } else { + this.mLocked = Utils.invertBoolean(this.mLocked); + if (this.mLocked) { + PlayerUtils.messagePlayer(aPlayer, "Container is now locked."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Container is now unlocked."); + } + } + } else { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Compartment.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Compartment.java index 7dcb76a22e..93361a523f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Compartment.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Compartment.java @@ -1,39 +1,38 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage.shelving; -import net.minecraft.entity.player.EntityPlayer; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; public class GT4Entity_Shelf_Compartment extends GT4Entity_Shelf { - - public GT4Entity_Shelf_Compartment(final int aID, final String aName, final String aNameRegional, final String aDescription) { - super(aID, aName, aNameRegional, aDescription); - } - - public GT4Entity_Shelf_Compartment(String mName, String mDescriptionArray, ITexture[][][] mTextures) { - super(mName, mDescriptionArray, mTextures); - } + public GT4Entity_Shelf_Compartment( + final int aID, final String aName, final String aNameRegional, final String aDescription) { + super(aID, aName, aNameRegional, aDescription); + } + + public GT4Entity_Shelf_Compartment(String mName, String mDescriptionArray, ITexture[][][] mTextures) { + super(mName, mDescriptionArray, mTextures); + } - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT4Entity_Shelf_Compartment(this.mName, this.mDescription, this.mTextures); - } + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_Shelf_Compartment(this.mName, this.mDescription, this.mTextures); + } - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (aSide == getBaseMetaTileEntity().getFrontFacing()) { - this.mType = ((byte) ((this.mType + 1) % 16)); - PlayerUtils.messagePlayer(aPlayer, "Set type to "+this.mType+"."); - } - } + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aSide == getBaseMetaTileEntity().getFrontFacing()) { + this.mType = ((byte) ((this.mType + 1) % 16)); + PlayerUtils.messagePlayer(aPlayer, "Set type to " + this.mType + "."); + } + } - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{TexturesGtBlock.OVERLAYS_COMPARTMENT_FRONT[this.mType < 16 ? this.mType : 0]}; - } + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {TexturesGtBlock.OVERLAYS_COMPARTMENT_FRONT[this.mType < 16 ? this.mType : 0]}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Desk.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Desk.java index 2c7186a3ce..c9472e157c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Desk.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Desk.java @@ -4,42 +4,42 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; - import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; public class GT4Entity_Shelf_Desk extends GT4Entity_Shelf { - public GT4Entity_Shelf_Desk(final int aID, final String aName, final String aNameRegional, final String aDescription) { - super(aID, aName, aNameRegional, aDescription); - } - - public GT4Entity_Shelf_Desk(String mName, String mDescriptionArray, ITexture[][][] mTextures) { - super(mName, mDescriptionArray, mTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT4Entity_Shelf_Desk(this.mName, this.mDescription, this.mTextures); - } - - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{TexturesGtBlock.OVERLAYS_CABINET_FRONT[this.mType < 16 ? this.mType : 0]}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; - } + public GT4Entity_Shelf_Desk( + final int aID, final String aName, final String aNameRegional, final String aDescription) { + super(aID, aName, aNameRegional, aDescription); + } + + public GT4Entity_Shelf_Desk(String mName, String mDescriptionArray, ITexture[][][] mTextures) { + super(mName, mDescriptionArray, mTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_Shelf_Desk(this.mName, this.mDescription, this.mTextures); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {TexturesGtBlock.OVERLAYS_CABINET_FRONT[this.mType < 16 ? this.mType : 0]}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.VanillaIcon_OakPlanks)}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_FileCabinet.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_FileCabinet.java index 93bb7d5bb9..9c4ae3aefa 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_FileCabinet.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_FileCabinet.java @@ -1,55 +1,54 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage.shelving; -import net.minecraft.entity.player.EntityPlayer; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; - import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; public class GT4Entity_Shelf_FileCabinet extends GT4Entity_Shelf { - public GT4Entity_Shelf_FileCabinet(final int aID, final String aName, final String aNameRegional, final String aDescription) { - super(aID, aName, aNameRegional, aDescription); - } - - public GT4Entity_Shelf_FileCabinet(String mName, String mDescriptionArray, ITexture[][][] mTextures) { - super(mName, mDescriptionArray, mTextures); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (aSide == getBaseMetaTileEntity().getFrontFacing()) { - this.mType = ((byte) ((this.mType + 1) % 16)); - PlayerUtils.messagePlayer(aPlayer, "Set type to "+this.mType+"."); - } - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT4Entity_Shelf_FileCabinet(this.mName, this.mDescription, this.mTextures); - } - - @Override - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{TexturesGtBlock.OVERLAYS_CABINET_FRONT[this.mType < 16 ? this.mType : 0]}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{texSide}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{texBottom}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{texTop}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{texSide}; - } + public GT4Entity_Shelf_FileCabinet( + final int aID, final String aName, final String aNameRegional, final String aDescription) { + super(aID, aName, aNameRegional, aDescription); + } + + public GT4Entity_Shelf_FileCabinet(String mName, String mDescriptionArray, ITexture[][][] mTextures) { + super(mName, mDescriptionArray, mTextures); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aSide == getBaseMetaTileEntity().getFrontFacing()) { + this.mType = ((byte) ((this.mType + 1) % 16)); + PlayerUtils.messagePlayer(aPlayer, "Set type to " + this.mType + "."); + } + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_Shelf_FileCabinet(this.mName, this.mDescription, this.mTextures); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {TexturesGtBlock.OVERLAYS_CABINET_FRONT[this.mType < 16 ? this.mType : 0]}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {texSide}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {texBottom}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {texTop}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {texSide}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Iron.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Iron.java index 606496501f..17110e691b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Iron.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Iron.java @@ -6,36 +6,37 @@ import gregtech.api.metatileentity.MetaTileEntity; public class GT4Entity_Shelf_Iron extends GT4Entity_Shelf { - public GT4Entity_Shelf_Iron(final int aID, final String aName, final String aNameRegional, final String aDescription) { - super(aID, aName, aNameRegional, aDescription); - } - - public GT4Entity_Shelf_Iron(String mName, String mDescriptionArray, ITexture[][][] mTextures) { - super(mName, mDescriptionArray, mTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT4Entity_Shelf_Iron(this.mName, this.mDescription, this.mTextures); - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{texSideCabinet}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{texSide}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{texBottom}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{texTop}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{texSide}; - } + public GT4Entity_Shelf_Iron( + final int aID, final String aName, final String aNameRegional, final String aDescription) { + super(aID, aName, aNameRegional, aDescription); + } + + public GT4Entity_Shelf_Iron(String mName, String mDescriptionArray, ITexture[][][] mTextures) { + super(mName, mDescriptionArray, mTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_Shelf_Iron(this.mName, this.mDescription, this.mTextures); + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {texSideCabinet}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {texSide}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {texBottom}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {texTop}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {texSide}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Large.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Large.java index cc17f49d83..03735ad381 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Large.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Large.java @@ -1,266 +1,264 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.storage.shelving; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.GT_Utility; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.sys.KeyboardUtils; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_SuperChest; import gtPlusPlus.xmod.gregtech.api.gui.GUI_SuperChest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; public class GT4Entity_Shelf_Large extends GT4Entity_Shelf { - private final int mSize; - public int mItemCount; - public ItemStack mItemStack; - - - public GT4Entity_Shelf_Large(final int aID, final String aName, final String aNameRegional, final String aDescription, final int aSize) { - super(aID, aName, aNameRegional, aDescription); - this.mSize = aSize; - this.mItemCount = 0; - this.mItemStack = null; - } - - public GT4Entity_Shelf_Large(String mName, String mDescriptionArray, final int aSize, ITexture[][][] mTextures) { - super(mName, mDescriptionArray, mTextures); - this.mSize = aSize; - this.mItemCount = 0; - this.mItemStack = null; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT4Entity_Shelf_Large(this.mName, this.mDescription, mSize, this.mTextures); - } - - /*@Override - public int getInvSize() { - return (mSize > 0 && mSize < 255 ? mSize : 255); - }*/ - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public boolean isDigitalChest() { - return true; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return true; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - if (KeyboardUtils.isCtrlKeyDown()) { - String itemName = (this.mItemStack != null ? this.mItemStack.getDisplayName() : "Nothing."); - String itemAmount = (this.mItemCount > 0 ? ""+this.mItemCount : "bad"); - String itemMessage = "This container currently holds "+(itemAmount.equalsIgnoreCase("bad") ? "nothing." : itemName+" x"+itemAmount+"."); - PlayerUtils.messagePlayer(aPlayer, itemMessage); - } - else { - aBaseMetaTileEntity.openGUI(aPlayer); - } - return true; - } - - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, - final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_SuperChest(aPlayerInventory, aBaseMetaTileEntity); - } - - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, - final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_SuperChest(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mItemCount", this.mItemCount); - if (this.mItemStack != null) { - aNBT.setTag("mItemStack", (NBTBase) this.mItemStack.writeToNBT(new NBTTagCompound())); - } - super.saveNBTData(aNBT); - - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - if (aNBT.hasKey("mItemCount")) { - this.mItemCount = aNBT.getInteger("mItemCount"); - } - if (aNBT.hasKey("mItemStack")) { - this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")); - } - super.loadNBTData(aNBT); - } - - @Override - public void onOpenGUI() { - super.onOpenGUI(); - } - - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) { - if (this.getBaseMetaTileEntity().isServerSide() && this.getBaseMetaTileEntity().isAllowedToWork()) { - try { - if (this.mInventory[0] != null) { - this.mType = (byte) this.mIndex; - } - else { - this.mType = 0; - } - - if (this.getItemCount() <= 0) { - this.mItemStack = null; - this.mItemCount = 0; - } - if (this.mItemStack == null && this.mInventory[0] != null) { - this.mItemStack = this.mInventory[0].copy(); - } - if (this.mInventory[0] != null && this.mItemCount < this.getMaxItemCount() - && GT_Utility.areStacksEqual(this.mInventory[0], this.mItemStack)) { - this.mItemCount += this.mInventory[0].stackSize; - if (this.mItemCount > this.getMaxItemCount()) { - this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount(); - this.mItemCount = this.getMaxItemCount(); - } else { - this.mInventory[0] = null; - } - } - if (this.mInventory[1] == null && this.mItemStack != null) { - this.mInventory[1] = this.mItemStack.copy(); - this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); - this.mItemCount -= this.mInventory[1].stackSize; - } else if (this.mItemCount > 0 && GT_Utility.areStacksEqual(this.mInventory[1], this.mItemStack) - && this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) { - final int tmp = Math.min(this.mItemCount, - this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize); - final ItemStack itemStack = this.mInventory[1]; - itemStack.stackSize += tmp; - this.mItemCount -= tmp; - } - if (this.mItemStack != null) { - this.mInventory[2] = this.mItemStack.copy(); - this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); - } else { - this.mInventory[2] = null; - } - } - catch (Throwable t) { - if (t instanceof ArrayIndexOutOfBoundsException) { - - } - } - } - } - - private int getItemCount() { - return this.mItemCount; - } - - public void setItemCount(final int aCount) { - this.mItemCount = aCount; - } - - public int getProgresstime() { - try { - return this.mItemCount + ((this.mInventory[0] == null) ? 0 : this.mInventory[0].stackSize) - + ((this.mInventory[1] == null) ? 0 : this.mInventory[1].stackSize); - } - catch (Throwable t) { - return 0; - } - } - - public int maxProgresstime() { - return this.getMaxItemCount(); - } - - public int getMaxItemCount() { - return this.mSize; - } - - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - return aIndex == 1; - } - - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - return aIndex == 0 && ((this.mInventory[0] == null && this.mItemStack == null) || GT_Utility.areStacksEqual(this.mInventory[0], aStack) || (this.mItemStack != null && GT_Utility.areStacksEqual(this.mItemStack, aStack))); - } - - public String[] getInfoData() { - if (this.mItemStack == null) { - return new String[]{ - this.getLocalName(), "No Items Stored", "Free Space: "+Integer.toString(this.getMaxItemCount())}; - } - return new String[]{ - this.getLocalName(), - "Storing: "+this.mItemStack.getDisplayName()+" x"+Integer.toString(this.mItemCount), - "Space Remaining: "+Integer.toString(this.getMaxItemCount()-this.getItemCount())+"/"+Integer.toString(this.getMaxItemCount())}; - } - - @Override - public String[] getDescription() { - String[] mSuper = super.getDescription(); - String[] desc = new String[mSuper.length+1]; - for (int i=0;i>mSuper.length;i++) { - desc[i] = mSuper[i]; - } - desc[desc.length-1] = "Control + Rmb block to check contents"; - return desc; - } - - @Override - public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { - Logger.INFO("1:"+aIndex); - if (aIndex == 2) { - if (ItemStack.areItemStacksEqual(aStack, mItemStack)) { - return true; - } - else { - if (mItemStack == null) { - return true; - } - return false; - } - } - return super.isItemValidForSlot(aIndex, aStack); - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - Logger.INFO("2:"+aIndex); - if (aIndex == 0) { - if (ItemStack.areItemStacksEqual(aStack, mItemStack)) { - return true; - } - else { - if (mItemStack == null) { - return true; - } - return false; - } - } - return super.canInsertItem(aIndex, aStack, aSide); - } - - + private final int mSize; + public int mItemCount; + public ItemStack mItemStack; + + public GT4Entity_Shelf_Large( + final int aID, final String aName, final String aNameRegional, final String aDescription, final int aSize) { + super(aID, aName, aNameRegional, aDescription); + this.mSize = aSize; + this.mItemCount = 0; + this.mItemStack = null; + } + + public GT4Entity_Shelf_Large(String mName, String mDescriptionArray, final int aSize, ITexture[][][] mTextures) { + super(mName, mDescriptionArray, mTextures); + this.mSize = aSize; + this.mItemCount = 0; + this.mItemStack = null; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_Shelf_Large(this.mName, this.mDescription, mSize, this.mTextures); + } + + /*@Override + public int getInvSize() { + return (mSize > 0 && mSize < 255 ? mSize : 255); + }*/ + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean isDigitalChest() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + if (KeyboardUtils.isCtrlKeyDown()) { + String itemName = (this.mItemStack != null ? this.mItemStack.getDisplayName() : "Nothing."); + String itemAmount = (this.mItemCount > 0 ? "" + this.mItemCount : "bad"); + String itemMessage = "This container currently holds " + + (itemAmount.equalsIgnoreCase("bad") ? "nothing." : itemName + " x" + itemAmount + "."); + PlayerUtils.messagePlayer(aPlayer, itemMessage); + } else { + aBaseMetaTileEntity.openGUI(aPlayer); + } + return true; + } + + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_SuperChest(aPlayerInventory, aBaseMetaTileEntity); + } + + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_SuperChest(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mItemCount", this.mItemCount); + if (this.mItemStack != null) { + aNBT.setTag("mItemStack", (NBTBase) this.mItemStack.writeToNBT(new NBTTagCompound())); + } + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("mItemCount")) { + this.mItemCount = aNBT.getInteger("mItemCount"); + } + if (aNBT.hasKey("mItemStack")) { + this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")); + } + super.loadNBTData(aNBT); + } + + @Override + public void onOpenGUI() { + super.onOpenGUI(); + } + + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) { + if (this.getBaseMetaTileEntity().isServerSide() + && this.getBaseMetaTileEntity().isAllowedToWork()) { + try { + if (this.mInventory[0] != null) { + this.mType = (byte) this.mIndex; + } else { + this.mType = 0; + } + + if (this.getItemCount() <= 0) { + this.mItemStack = null; + this.mItemCount = 0; + } + if (this.mItemStack == null && this.mInventory[0] != null) { + this.mItemStack = this.mInventory[0].copy(); + } + if (this.mInventory[0] != null + && this.mItemCount < this.getMaxItemCount() + && GT_Utility.areStacksEqual(this.mInventory[0], this.mItemStack)) { + this.mItemCount += this.mInventory[0].stackSize; + if (this.mItemCount > this.getMaxItemCount()) { + this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount(); + this.mItemCount = this.getMaxItemCount(); + } else { + this.mInventory[0] = null; + } + } + if (this.mInventory[1] == null && this.mItemStack != null) { + this.mInventory[1] = this.mItemStack.copy(); + this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + this.mItemCount -= this.mInventory[1].stackSize; + } else if (this.mItemCount > 0 + && GT_Utility.areStacksEqual(this.mInventory[1], this.mItemStack) + && this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) { + final int tmp = Math.min( + this.mItemCount, this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize); + final ItemStack itemStack = this.mInventory[1]; + itemStack.stackSize += tmp; + this.mItemCount -= tmp; + } + if (this.mItemStack != null) { + this.mInventory[2] = this.mItemStack.copy(); + this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + } else { + this.mInventory[2] = null; + } + } catch (Throwable t) { + if (t instanceof ArrayIndexOutOfBoundsException) {} + } + } + } + + private int getItemCount() { + return this.mItemCount; + } + + public void setItemCount(final int aCount) { + this.mItemCount = aCount; + } + + public int getProgresstime() { + try { + return this.mItemCount + + ((this.mInventory[0] == null) ? 0 : this.mInventory[0].stackSize) + + ((this.mInventory[1] == null) ? 0 : this.mInventory[1].stackSize); + } catch (Throwable t) { + return 0; + } + } + + public int maxProgresstime() { + return this.getMaxItemCount(); + } + + public int getMaxItemCount() { + return this.mSize; + } + + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aIndex == 1; + } + + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aIndex == 0 + && ((this.mInventory[0] == null && this.mItemStack == null) + || GT_Utility.areStacksEqual(this.mInventory[0], aStack) + || (this.mItemStack != null && GT_Utility.areStacksEqual(this.mItemStack, aStack))); + } + + public String[] getInfoData() { + if (this.mItemStack == null) { + return new String[] { + this.getLocalName(), "No Items Stored", "Free Space: " + Integer.toString(this.getMaxItemCount()) + }; + } + return new String[] { + this.getLocalName(), + "Storing: " + this.mItemStack.getDisplayName() + " x" + Integer.toString(this.mItemCount), + "Space Remaining: " + Integer.toString(this.getMaxItemCount() - this.getItemCount()) + "/" + + Integer.toString(this.getMaxItemCount()) + }; + } + + @Override + public String[] getDescription() { + String[] mSuper = super.getDescription(); + String[] desc = new String[mSuper.length + 1]; + for (int i = 0; i > mSuper.length; i++) { + desc[i] = mSuper[i]; + } + desc[desc.length - 1] = "Control + Rmb block to check contents"; + return desc; + } + + @Override + public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { + Logger.INFO("1:" + aIndex); + if (aIndex == 2) { + if (ItemStack.areItemStacksEqual(aStack, mItemStack)) { + return true; + } else { + if (mItemStack == null) { + return true; + } + return false; + } + } + return super.isItemValidForSlot(aIndex, aStack); + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + Logger.INFO("2:" + aIndex); + if (aIndex == 0) { + if (ItemStack.areItemStacksEqual(aStack, mItemStack)) { + return true; + } else { + if (mItemStack == null) { + return true; + } + return false; + } + } + return super.canInsertItem(aIndex, aStack, aSide); + } } |