diff options
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity')
50 files changed, 12871 insertions, 11465 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/BaseCustomTileEntity.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/BaseCustomTileEntity.java index 5ccbd8cb2d..a88105f7f6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/BaseCustomTileEntity.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/BaseCustomTileEntity.java @@ -1,10 +1,5 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Random; - import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; @@ -12,201 +7,202 @@ import gregtech.api.metatileentity.BaseMetaTileEntity; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; import gtPlusPlus.xmod.gregtech.api.interfaces.IBaseCustomMetaTileEntity; -import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; import gtPlusPlus.xmod.gregtech.common.StaticFields59; import ic2.api.Direction; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Random; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; public class BaseCustomTileEntity extends BaseMetaTileEntity implements IBaseCustomMetaTileEntity { - - protected NBTTagCompound mRecipeStuff2; - private static final Field ENTITY_ITEM_HEALTH_FIELD_2; - - static { - Field f = null; - try { - f = EntityItem.class.getDeclaredField("field_70291_e"); - f.setAccessible(true); - } catch (Exception var4) { - try { - f = EntityItem.class.getDeclaredField("health"); - f.setAccessible(true); - } catch (Exception var3) { - var4.printStackTrace(); - var3.printStackTrace(); - } - } - - ENTITY_ITEM_HEALTH_FIELD_2 = f; - } - - public BaseCustomTileEntity() { - super(); - Logger.MACHINE_INFO("Created new BaseCustomTileEntity"); - } - - public boolean doesExplode() { - return true; - } - - public void writeToNBT(NBTTagCompound aNBT) { - try { - super.writeToNBT(aNBT); - } catch (Throwable arg7) { - GT_Log.err.println( - "Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould\'ve been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - arg7.printStackTrace(GT_Log.err); - } - - try { - if (!aNBT.hasKey("ModVersion")) - aNBT.setString("ModVersion", CORE.VERSION); - } catch (Throwable arg6) { - GT_Log.err.println( - "Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould\'ve been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - arg6.printStackTrace(GT_Log.err); - } - } - - public void doEnergyExplosion() { - if (!doesExplode()) { - Logger.INFO("Machine tried to explode, let's stop that. xo [doEnergyExplosion]"); - return; - } - if (this.getUniversalEnergyCapacity() > 0L - && this.getUniversalEnergyStored() >= this.getUniversalEnergyCapacity() / 5L) { - this.doExplosion( - this.getOutput() * (long) (this.getUniversalEnergyStored() >= this.getUniversalEnergyCapacity() ? 4 - : (this.getUniversalEnergyStored() >= this.getUniversalEnergyCapacity() / 2L ? 2 : 1))); - GT_Mod arg9999 = GT_Mod.instance; - GT_Mod.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(this.getOwnerName()), - "electricproblems"); - } - - } - - public void doExplosion(long aAmount) { - - if (!doesExplode()) { - Logger.INFO("Machine tried to explode, let's stop that. xo [doExplosion]"); - return; - } - - if (this.canAccessData()) { - if (GregTech_API.sMachineWireFire && this.mMetaTileEntity.isElectric()) { - try { - this.mReleaseEnergy = true; - Util.emitEnergyToNetwork(GT_Values.V[5], Math.max(1L, this.getStoredEU() / GT_Values.V[5]), this); - } catch (Exception arg4) { - ; - } - } - - this.mReleaseEnergy = false; - this.mMetaTileEntity.onExplosion(); - int i; - - boolean aExplosionDropItem = false; - Object aProxyField = StaticFields59.getFieldFromGregtechProxy(false, "mExplosionItemDrop"); - if (boolean.class.isInstance(aProxyField) || Boolean.class.isInstance(aProxyField)) { - aExplosionDropItem = (boolean) aProxyField; - } - - if (aExplosionDropItem) { - for (i = 0; i < this.getSizeInventory(); ++i) { - ItemStack tItem = this.getStackInSlot(i); - if (tItem != null && tItem.stackSize > 0 && this.isValidSlot(i)) { - this.dropItems(tItem); - this.setInventorySlotContents(i, (ItemStack) null); - } - } - } - - if (this.mRecipeStuff2 != null) { - for (i = 0; i < 9; ++i) { - this.dropItems(GT_Utility.loadItem(this.mRecipeStuff2, "Ingredient." + i)); - } - } - - PollutionUtils.addPollution(this, 100000); - this.mMetaTileEntity.doExplosion(aAmount); - } - - } - - - public void dropItems(ItemStack tItem) { - if (tItem != null) { - Random tRandom = new Random(); - EntityItem tItemEntity = new EntityItem(this.worldObj, - (double) ((float) this.xCoord + tRandom.nextFloat() * 0.8F + 0.1F), - (double) ((float) this.yCoord + tRandom.nextFloat() * 0.8F + 0.1F), - (double) ((float) this.zCoord + tRandom.nextFloat() * 0.8F + 0.1F), - new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage())); - if (tItem.hasTagCompound()) { - tItemEntity.getEntityItem().setTagCompound((NBTTagCompound) tItem.getTagCompound().copy()); - } - - tItemEntity.motionX = tRandom.nextGaussian() * 0.0500000007450581D; - tItemEntity.motionY = tRandom.nextGaussian() * 0.0500000007450581D + 0.2000000029802322D; - tItemEntity.motionZ = tRandom.nextGaussian() * 0.0500000007450581D; - tItemEntity.hurtResistantTime = 999999; - tItemEntity.lifespan = 60000; - - try { - if (ENTITY_ITEM_HEALTH_FIELD_2 != null) { - ENTITY_ITEM_HEALTH_FIELD_2.setInt(tItemEntity, 99999999); - } - } catch (Exception var5) { - ; - } - - this.worldObj.spawnEntityInWorld(tItemEntity); - tItem.stackSize = 0; - } - } - - public ArrayList<ItemStack> getDrops() { - ArrayList<ItemStack> aDrops = new ArrayList<ItemStack>(); - ItemStack rStack = new ItemStack(GregTech_API.sBlockMachines, 1, this.getMetaTileID()); - // Currently not using my custom block. - // ItemStack rStack = new ItemStack(Meta_GT_Proxy.sBlockMachines, 1, - // this.getMetaTileID()); - boolean fail = true; - - ArrayList<ItemStack> aSuperDrops = super.getDrops(); - if (aSuperDrops != null && !aSuperDrops.isEmpty()) { - ItemStack aSuperStack = super.getDrops().get(0); - if (aSuperStack != null && aSuperStack.hasTagCompound()) { - NBTTagCompound aSuperNBT = aSuperStack.getTagCompound(); - if (aSuperNBT != null && !aSuperNBT.hasNoTags()) { - NBTTagCompound tNBT = (NBTTagCompound) aSuperNBT.copy(); - if (tNBT != null && !tNBT.hasNoTags()) { - if (this.hasValidMetaTileEntity()) { - this.mMetaTileEntity.setItemNBT(tNBT); - rStack.setTagCompound(tNBT); - fail = false; - aDrops.add(rStack); - } - } - } - - } - } - if (fail) { - aDrops.add(rStack); - } - return aDrops; - } - - public boolean isTeleporterCompatible(Direction aSide) { - return this.canAccessData() && this.mMetaTileEntity.isTeleporterCompatible(); - } - -}
\ No newline at end of file + + protected NBTTagCompound mRecipeStuff2; + private static final Field ENTITY_ITEM_HEALTH_FIELD_2; + + static { + Field f = null; + try { + f = EntityItem.class.getDeclaredField("field_70291_e"); + f.setAccessible(true); + } catch (Exception var4) { + try { + f = EntityItem.class.getDeclaredField("health"); + f.setAccessible(true); + } catch (Exception var3) { + var4.printStackTrace(); + var3.printStackTrace(); + } + } + + ENTITY_ITEM_HEALTH_FIELD_2 = f; + } + + public BaseCustomTileEntity() { + super(); + Logger.MACHINE_INFO("Created new BaseCustomTileEntity"); + } + + public boolean doesExplode() { + return true; + } + + public void writeToNBT(NBTTagCompound aNBT) { + try { + super.writeToNBT(aNBT); + } catch (Throwable arg7) { + GT_Log.err.println( + "Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould\'ve been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); + arg7.printStackTrace(GT_Log.err); + } + + try { + if (!aNBT.hasKey("ModVersion")) aNBT.setString("ModVersion", CORE.VERSION); + } catch (Throwable arg6) { + GT_Log.err.println( + "Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould\'ve been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); + arg6.printStackTrace(GT_Log.err); + } + } + + public void doEnergyExplosion() { + if (!doesExplode()) { + Logger.INFO("Machine tried to explode, let's stop that. xo [doEnergyExplosion]"); + return; + } + if (this.getUniversalEnergyCapacity() > 0L + && this.getUniversalEnergyStored() >= this.getUniversalEnergyCapacity() / 5L) { + this.doExplosion(this.getOutput() + * (long) + (this.getUniversalEnergyStored() >= this.getUniversalEnergyCapacity() + ? 4 + : (this.getUniversalEnergyStored() >= this.getUniversalEnergyCapacity() / 2L + ? 2 + : 1))); + GT_Mod arg9999 = GT_Mod.instance; + GT_Mod.achievements.issueAchievement( + this.getWorldObj().getPlayerEntityByName(this.getOwnerName()), "electricproblems"); + } + } + + public void doExplosion(long aAmount) { + + if (!doesExplode()) { + Logger.INFO("Machine tried to explode, let's stop that. xo [doExplosion]"); + return; + } + + if (this.canAccessData()) { + if (GregTech_API.sMachineWireFire && this.mMetaTileEntity.isElectric()) { + try { + this.mReleaseEnergy = true; + Util.emitEnergyToNetwork(GT_Values.V[5], Math.max(1L, this.getStoredEU() / GT_Values.V[5]), this); + } catch (Exception arg4) { + ; + } + } + + this.mReleaseEnergy = false; + this.mMetaTileEntity.onExplosion(); + int i; + + boolean aExplosionDropItem = false; + Object aProxyField = StaticFields59.getFieldFromGregtechProxy(false, "mExplosionItemDrop"); + if (boolean.class.isInstance(aProxyField) || Boolean.class.isInstance(aProxyField)) { + aExplosionDropItem = (boolean) aProxyField; + } + + if (aExplosionDropItem) { + for (i = 0; i < this.getSizeInventory(); ++i) { + ItemStack tItem = this.getStackInSlot(i); + if (tItem != null && tItem.stackSize > 0 && this.isValidSlot(i)) { + this.dropItems(tItem); + this.setInventorySlotContents(i, (ItemStack) null); + } + } + } + + if (this.mRecipeStuff2 != null) { + for (i = 0; i < 9; ++i) { + this.dropItems(GT_Utility.loadItem(this.mRecipeStuff2, "Ingredient." + i)); + } + } + + PollutionUtils.addPollution(this, 100000); + this.mMetaTileEntity.doExplosion(aAmount); + } + } + + public void dropItems(ItemStack tItem) { + if (tItem != null) { + Random tRandom = new Random(); + EntityItem tItemEntity = new EntityItem( + this.worldObj, + (double) ((float) this.xCoord + tRandom.nextFloat() * 0.8F + 0.1F), + (double) ((float) this.yCoord + tRandom.nextFloat() * 0.8F + 0.1F), + (double) ((float) this.zCoord + tRandom.nextFloat() * 0.8F + 0.1F), + new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage())); + if (tItem.hasTagCompound()) { + tItemEntity.getEntityItem().setTagCompound((NBTTagCompound) + tItem.getTagCompound().copy()); + } + + tItemEntity.motionX = tRandom.nextGaussian() * 0.0500000007450581D; + tItemEntity.motionY = tRandom.nextGaussian() * 0.0500000007450581D + 0.2000000029802322D; + tItemEntity.motionZ = tRandom.nextGaussian() * 0.0500000007450581D; + tItemEntity.hurtResistantTime = 999999; + tItemEntity.lifespan = 60000; + + try { + if (ENTITY_ITEM_HEALTH_FIELD_2 != null) { + ENTITY_ITEM_HEALTH_FIELD_2.setInt(tItemEntity, 99999999); + } + } catch (Exception var5) { + ; + } + + this.worldObj.spawnEntityInWorld(tItemEntity); + tItem.stackSize = 0; + } + } + + public ArrayList<ItemStack> getDrops() { + ArrayList<ItemStack> aDrops = new ArrayList<ItemStack>(); + ItemStack rStack = new ItemStack(GregTech_API.sBlockMachines, 1, this.getMetaTileID()); + // Currently not using my custom block. + // ItemStack rStack = new ItemStack(Meta_GT_Proxy.sBlockMachines, 1, + // this.getMetaTileID()); + boolean fail = true; + + ArrayList<ItemStack> aSuperDrops = super.getDrops(); + if (aSuperDrops != null && !aSuperDrops.isEmpty()) { + ItemStack aSuperStack = super.getDrops().get(0); + if (aSuperStack != null && aSuperStack.hasTagCompound()) { + NBTTagCompound aSuperNBT = aSuperStack.getTagCompound(); + if (aSuperNBT != null && !aSuperNBT.hasNoTags()) { + NBTTagCompound tNBT = (NBTTagCompound) aSuperNBT.copy(); + if (tNBT != null && !tNBT.hasNoTags()) { + if (this.hasValidMetaTileEntity()) { + this.mMetaTileEntity.setItemNBT(tNBT); + rStack.setTagCompound(tNBT); + fail = false; + aDrops.add(rStack); + } + } + } + } + } + if (fail) { + aDrops.add(rStack); + } + return aDrops; + } + + public boolean isTeleporterCompatible(Direction aSide) { + return this.canAccessData() && this.mMetaTileEntity.isTeleporterCompatible(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/BaseCustomPower_MTE.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/BaseCustomPower_MTE.java index d600d0baca..b3d8b8aa8c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/BaseCustomPower_MTE.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/BaseCustomPower_MTE.java @@ -8,277 +8,283 @@ import net.minecraftforge.common.util.ForgeDirection; public class BaseCustomPower_MTE extends BaseCustomTileEntity { - public BaseCustomPower_MTE() { - super(); - Logger.INFO("Created new BaseCustomPower_MTE"); - } - - public boolean doesExplode() { - return false; - } - - public long injectEnergyUnits(byte aSide, long aVoltage, long aAmperage) { - if (mMetaTileEntity == null) { - Logger.INFO("Bad Tile"); - } - if (this.canAccessData() && this.mMetaTileEntity.isElectric() && this.inputEnergyFrom(aSide) && aAmperage > 0L - && aVoltage > 0L && this.getStoredEU() < this.getEUCapacity() - && this.mMetaTileEntity.maxAmperesIn() >= this.getInputAmperage()) { - Logger.INFO("Injecting Energy Units"); - return super.injectEnergyUnits(aSide, aVoltage, aAmperage); - } else { - Logger.INFO("canAccessData(): "+canAccessData()); - Logger.INFO("isElectric(): "+this.mMetaTileEntity.isElectric()); - Logger.INFO("InputEnergyFromSide("+aSide+"): "+this.inputEnergyFrom(aSide)); - Logger.INFO("aAmperage: "+aAmperage); - Logger.INFO("aVoltage: "+aVoltage); - Logger.INFO("this.getStoredEU() < this.getEUCapacity(): "+(this.getStoredEU() < this.getEUCapacity())); - Logger.INFO("this.mMetaTileEntity.maxAmperesIn() >= this.mAcceptedAmperes: "+(this.mMetaTileEntity.maxAmperesIn() >= this.getInputAmperage())); - Logger.INFO("this.mMetaTileEntity.maxAmperesIn(): "+(this.mMetaTileEntity.maxAmperesIn())); - Logger.INFO("this.mAcceptedAmperes: "+(this.getInputAmperage())); - return 0L; - } - } - - public boolean drainEnergyUnits(byte aSide, long aVoltage, long aAmperage) { - Logger.INFO("Draining Energy Units 4"); - if (this.canAccessData() && this.mMetaTileEntity.isElectric() && this.outputsEnergyTo(aSide) - && this.getStoredEU() - aVoltage * aAmperage >= this.mMetaTileEntity.getMinimumStoredEU()) { - if (this.decreaseStoredEU(aVoltage * aAmperage, false)) { - this.mAverageEUOutput[this.mAverageEUOutputIndex] = (int) ((long) this.mAverageEUOutput[this.mAverageEUOutputIndex] - + aVoltage * aAmperage); - return true; - } else { - return false; - } - } else { - return false; - } - } - - @Override - public boolean decreaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooLessEnergy) { - Logger.INFO("Draining Energy Units 3"); - // TODO Auto-generated method stub - return super.decreaseStoredEnergyUnits(aEnergy, aIgnoreTooLessEnergy); - } - - @Override - public boolean increaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooMuchEnergy) { - // TODO Auto-generated method stub - return super.increaseStoredEnergyUnits(aEnergy, aIgnoreTooMuchEnergy); - } - - @Override - public boolean inputEnergyFrom(byte aSide) { - // TODO Auto-generated method stub - return super.inputEnergyFrom(aSide); - } - - @Override - public boolean outputsEnergyTo(byte aSide) { - Logger.INFO("Draining Energy Units 2"); - // TODO Auto-generated method stub - return super.outputsEnergyTo(aSide); - } - - @Override - public long getOutputAmperage() { - // TODO Auto-generated method stub - return super.getOutputAmperage(); - } - - @Override - public long getOutputVoltage() { - // TODO Auto-generated method stub - return super.getOutputVoltage(); - } - - @Override - public long getInputAmperage() { - // TODO Auto-generated method stub - return super.getInputAmperage(); - } - - @Override - public long getInputVoltage() { - // TODO Auto-generated method stub - return super.getInputVoltage(); - } - - @Override - public long getUniversalEnergyStored() { - // TODO Auto-generated method stub - return super.getUniversalEnergyStored(); - } - - @Override - public long getUniversalEnergyCapacity() { - // TODO Auto-generated method stub - return super.getUniversalEnergyCapacity(); - } - - @Override - public long getStoredEU() { - // TODO Auto-generated method stub - return super.getStoredEU(); - } - - @Override - public long getEUCapacity() { - // TODO Auto-generated method stub - return super.getEUCapacity(); - } - - @Override - public boolean setStoredEU(long aEnergy) { - // TODO Auto-generated method stub - return super.setStoredEU(aEnergy); - } - - @Override - public boolean decreaseStoredEU(long aEnergy, boolean aIgnoreTooLessEnergy) { - Logger.INFO("Draining Energy Units 1"); - // TODO Auto-generated method stub - return super.decreaseStoredEU(aEnergy, aIgnoreTooLessEnergy); - } - - @Override - public boolean decreaseStoredSteam(long aEnergy, boolean aIgnoreTooLessEnergy) { - // TODO Auto-generated method stub - return super.decreaseStoredSteam(aEnergy, aIgnoreTooLessEnergy); - } - - @Override - public void doEnergyExplosion() { - // TODO Auto-generated method stub - super.doEnergyExplosion(); - } - - @Override - public void doExplosion(long aAmount) { - // TODO Auto-generated method stub - super.doExplosion(aAmount); - } - - @Override - public byte getLightValue() { - // TODO Auto-generated method stub - return super.getLightValue(); - } - - @Override - public long getAverageElectricInput() { - // TODO Auto-generated method stub - return super.getAverageElectricInput(); - } - - @Override - public long getAverageElectricOutput() { - // TODO Auto-generated method stub - return super.getAverageElectricOutput(); - } - - @Override - public double getOutputEnergyUnitsPerTick() { - // TODO Auto-generated method stub - return super.getOutputEnergyUnitsPerTick(); - } - - @Override - public double demandedEnergyUnits() { - // TODO Auto-generated method stub - return super.demandedEnergyUnits(); - } - - @Override - public double injectEnergyUnits(ForgeDirection aDirection, double aAmount) { - // TODO Auto-generated method stub - return super.injectEnergyUnits(aDirection, aAmount); - } - - @Override - public boolean acceptsEnergyFrom(TileEntity aEmitter, ForgeDirection aDirection) { - // TODO Auto-generated method stub - return super.acceptsEnergyFrom(aEmitter, aDirection); - } - - @Override - public boolean emitsEnergyTo(TileEntity aReceiver, ForgeDirection aDirection) { - // TODO Auto-generated method stub - return super.emitsEnergyTo(aReceiver, aDirection); - } - - @Override - public double getOfferedEnergy() { - // TODO Auto-generated method stub - return super.getOfferedEnergy(); - } - - @Override - public void drawEnergy(double amount) { - // TODO Auto-generated method stub - super.drawEnergy(amount); - } - - @Override - public int injectEnergy(ForgeDirection aForgeDirection, int aAmount) { - // TODO Auto-generated method stub - return super.injectEnergy(aForgeDirection, aAmount); - } - - @Override - public int addEnergy(int aEnergy) { - // TODO Auto-generated method stub - return super.addEnergy(aEnergy); - } - - @Override - public boolean isAddedToEnergyNet() { - // TODO Auto-generated method stub - return super.isAddedToEnergyNet(); - } - - @Override - public int demandsEnergy() { - // TODO Auto-generated method stub - return super.demandsEnergy(); - } - - @Override - public int getMaxSafeInput() { - // TODO Auto-generated method stub - return super.getMaxSafeInput(); - } - - @Override - public int getMaxEnergyOutput() { - // TODO Auto-generated method stub - return super.getMaxEnergyOutput(); - } - - @Override - public int injectEnergy(Direction aDirection, int aAmount) { - // TODO Auto-generated method stub - return super.injectEnergy(aDirection, aAmount); - } - - @Override - public boolean acceptsEnergyFrom(TileEntity aReceiver, Direction aDirection) { - // TODO Auto-generated method stub - return super.acceptsEnergyFrom(aReceiver, aDirection); - } - - @Override - public boolean emitsEnergyTo(TileEntity aReceiver, Direction aDirection) { - // TODO Auto-generated method stub - return super.emitsEnergyTo(aReceiver, aDirection); - } - - @Override - public boolean isUniversalEnergyStored(long aEnergyAmount) { - // TODO Auto-generated method stub - return super.isUniversalEnergyStored(aEnergyAmount); - } - + public BaseCustomPower_MTE() { + super(); + Logger.INFO("Created new BaseCustomPower_MTE"); + } + + public boolean doesExplode() { + return false; + } + + public long injectEnergyUnits(byte aSide, long aVoltage, long aAmperage) { + if (mMetaTileEntity == null) { + Logger.INFO("Bad Tile"); + } + if (this.canAccessData() + && this.mMetaTileEntity.isElectric() + && this.inputEnergyFrom(aSide) + && aAmperage > 0L + && aVoltage > 0L + && this.getStoredEU() < this.getEUCapacity() + && this.mMetaTileEntity.maxAmperesIn() >= this.getInputAmperage()) { + Logger.INFO("Injecting Energy Units"); + return super.injectEnergyUnits(aSide, aVoltage, aAmperage); + } else { + Logger.INFO("canAccessData(): " + canAccessData()); + Logger.INFO("isElectric(): " + this.mMetaTileEntity.isElectric()); + Logger.INFO("InputEnergyFromSide(" + aSide + "): " + this.inputEnergyFrom(aSide)); + Logger.INFO("aAmperage: " + aAmperage); + Logger.INFO("aVoltage: " + aVoltage); + Logger.INFO("this.getStoredEU() < this.getEUCapacity(): " + (this.getStoredEU() < this.getEUCapacity())); + Logger.INFO("this.mMetaTileEntity.maxAmperesIn() >= this.mAcceptedAmperes: " + + (this.mMetaTileEntity.maxAmperesIn() >= this.getInputAmperage())); + Logger.INFO("this.mMetaTileEntity.maxAmperesIn(): " + (this.mMetaTileEntity.maxAmperesIn())); + Logger.INFO("this.mAcceptedAmperes: " + (this.getInputAmperage())); + return 0L; + } + } + + public boolean drainEnergyUnits(byte aSide, long aVoltage, long aAmperage) { + Logger.INFO("Draining Energy Units 4"); + if (this.canAccessData() + && this.mMetaTileEntity.isElectric() + && this.outputsEnergyTo(aSide) + && this.getStoredEU() - aVoltage * aAmperage >= this.mMetaTileEntity.getMinimumStoredEU()) { + if (this.decreaseStoredEU(aVoltage * aAmperage, false)) { + this.mAverageEUOutput[this.mAverageEUOutputIndex] = + (int) ((long) this.mAverageEUOutput[this.mAverageEUOutputIndex] + aVoltage * aAmperage); + return true; + } else { + return false; + } + } else { + return false; + } + } + + @Override + public boolean decreaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooLessEnergy) { + Logger.INFO("Draining Energy Units 3"); + // TODO Auto-generated method stub + return super.decreaseStoredEnergyUnits(aEnergy, aIgnoreTooLessEnergy); + } + + @Override + public boolean increaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooMuchEnergy) { + // TODO Auto-generated method stub + return super.increaseStoredEnergyUnits(aEnergy, aIgnoreTooMuchEnergy); + } + + @Override + public boolean inputEnergyFrom(byte aSide) { + // TODO Auto-generated method stub + return super.inputEnergyFrom(aSide); + } + + @Override + public boolean outputsEnergyTo(byte aSide) { + Logger.INFO("Draining Energy Units 2"); + // TODO Auto-generated method stub + return super.outputsEnergyTo(aSide); + } + + @Override + public long getOutputAmperage() { + // TODO Auto-generated method stub + return super.getOutputAmperage(); + } + + @Override + public long getOutputVoltage() { + // TODO Auto-generated method stub + return super.getOutputVoltage(); + } + + @Override + public long getInputAmperage() { + // TODO Auto-generated method stub + return super.getInputAmperage(); + } + + @Override + public long getInputVoltage() { + // TODO Auto-generated method stub + return super.getInputVoltage(); + } + + @Override + public long getUniversalEnergyStored() { + // TODO Auto-generated method stub + return super.getUniversalEnergyStored(); + } + + @Override + public long getUniversalEnergyCapacity() { + // TODO Auto-generated method stub + return super.getUniversalEnergyCapacity(); + } + + @Override + public long getStoredEU() { + // TODO Auto-generated method stub + return super.getStoredEU(); + } + + @Override + public long getEUCapacity() { + // TODO Auto-generated method stub + return super.getEUCapacity(); + } + + @Override + public boolean setStoredEU(long aEnergy) { + // TODO Auto-generated method stub + return super.setStoredEU(aEnergy); + } + + @Override + public boolean decreaseStoredEU(long aEnergy, boolean aIgnoreTooLessEnergy) { + Logger.INFO("Draining Energy Units 1"); + // TODO Auto-generated method stub + return super.decreaseStoredEU(aEnergy, aIgnoreTooLessEnergy); + } + + @Override + public boolean decreaseStoredSteam(long aEnergy, boolean aIgnoreTooLessEnergy) { + // TODO Auto-generated method stub + return super.decreaseStoredSteam(aEnergy, aIgnoreTooLessEnergy); + } + + @Override + public void doEnergyExplosion() { + // TODO Auto-generated method stub + super.doEnergyExplosion(); + } + + @Override + public void doExplosion(long aAmount) { + // TODO Auto-generated method stub + super.doExplosion(aAmount); + } + + @Override + public byte getLightValue() { + // TODO Auto-generated method stub + return super.getLightValue(); + } + + @Override + public long getAverageElectricInput() { + // TODO Auto-generated method stub + return super.getAverageElectricInput(); + } + + @Override + public long getAverageElectricOutput() { + // TODO Auto-generated method stub + return super.getAverageElectricOutput(); + } + + @Override + public double getOutputEnergyUnitsPerTick() { + // TODO Auto-generated method stub + return super.getOutputEnergyUnitsPerTick(); + } + + @Override + public double demandedEnergyUnits() { + // TODO Auto-generated method stub + return super.demandedEnergyUnits(); + } + + @Override + public double injectEnergyUnits(ForgeDirection aDirection, double aAmount) { + // TODO Auto-generated method stub + return super.injectEnergyUnits(aDirection, aAmount); + } + + @Override + public boolean acceptsEnergyFrom(TileEntity aEmitter, ForgeDirection aDirection) { + // TODO Auto-generated method stub + return super.acceptsEnergyFrom(aEmitter, aDirection); + } + + @Override + public boolean emitsEnergyTo(TileEntity aReceiver, ForgeDirection aDirection) { + // TODO Auto-generated method stub + return super.emitsEnergyTo(aReceiver, aDirection); + } + + @Override + public double getOfferedEnergy() { + // TODO Auto-generated method stub + return super.getOfferedEnergy(); + } + + @Override + public void drawEnergy(double amount) { + // TODO Auto-generated method stub + super.drawEnergy(amount); + } + + @Override + public int injectEnergy(ForgeDirection aForgeDirection, int aAmount) { + // TODO Auto-generated method stub + return super.injectEnergy(aForgeDirection, aAmount); + } + + @Override + public int addEnergy(int aEnergy) { + // TODO Auto-generated method stub + return super.addEnergy(aEnergy); + } + + @Override + public boolean isAddedToEnergyNet() { + // TODO Auto-generated method stub + return super.isAddedToEnergyNet(); + } + + @Override + public int demandsEnergy() { + // TODO Auto-generated method stub + return super.demandsEnergy(); + } + + @Override + public int getMaxSafeInput() { + // TODO Auto-generated method stub + return super.getMaxSafeInput(); + } + + @Override + public int getMaxEnergyOutput() { + // TODO Auto-generated method stub + return super.getMaxEnergyOutput(); + } + + @Override + public int injectEnergy(Direction aDirection, int aAmount) { + // TODO Auto-generated method stub + return super.injectEnergy(aDirection, aAmount); + } + + @Override + public boolean acceptsEnergyFrom(TileEntity aReceiver, Direction aDirection) { + // TODO Auto-generated method stub + return super.acceptsEnergyFrom(aReceiver, aDirection); + } + + @Override + public boolean emitsEnergyTo(TileEntity aReceiver, Direction aDirection) { + // TODO Auto-generated method stub + return super.emitsEnergyTo(aReceiver, aDirection); + } + + @Override + public boolean isUniversalEnergyStored(long aEnergyAmount) { + // TODO Auto-generated method stub + return super.isUniversalEnergyStored(aEnergyAmount); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicLosslessGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicLosslessGenerator.java index e1b329c07f..332d911ac4 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicLosslessGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicLosslessGenerator.java @@ -5,10 +5,10 @@ import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import java.util.Collection; import java.util.Iterator; import net.minecraft.entity.player.EntityPlayer; @@ -17,297 +17,317 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; public abstract class GTPP_MTE_BasicLosslessGenerator extends GTPP_MTE_BasicTank { - public GTPP_MTE_BasicLosslessGenerator(int aID, String aName, String aNameRegional, int aTier, String aDescription, - ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); - } - - public GTPP_MTE_BasicLosslessGenerator(int aID, String aName, String aNameRegional, int aTier, - String[] aDescription, ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); - } - - public GTPP_MTE_BasicLosslessGenerator(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - public GTPP_MTE_BasicLosslessGenerator(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - 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; - } - - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, - boolean aActive, 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 String[] getDescription() { - String[] desc = new String[this.mDescriptionArray.length + 1]; - System.arraycopy(this.mDescriptionArray, 0, desc, 0, this.mDescriptionArray.length); - desc[this.mDescriptionArray.length] = "Fuel Efficiency: " + this.getEfficiency() + "%"; - return desc; - } - - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - Logger.WARNING("Right Clicked"); - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } else { - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - } - - public ITexture[] getFront(byte aColor) { - return new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getBack(byte aColor) { - return new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getBottom(byte aColor) { - return new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getTop(byte aColor) { - return new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getSides(byte aColor) { - return new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getFrontActive(byte aColor) { - return this.getFront(aColor); - } - - public ITexture[] getBackActive(byte aColor) { - return this.getBack(aColor); - } - - public ITexture[] getBottomActive(byte aColor) { - return this.getBottom(aColor); - } - - public ITexture[] getTopActive(byte aColor) { - return this.getTop(aColor); - } - - public ITexture[] getSidesActive(byte aColor) { - return this.getSides(aColor); - } - - public boolean isFacingValid(byte aSide) { - return aSide > 1; - } - - public boolean isSimpleMachine() { - return false; - } - - public boolean isValidSlot(int aIndex) { - return aIndex < 2; - } - - public boolean isEnetOutput() { - return true; - } - - public boolean isOutputFacing(byte aSide) { - return true; - } - - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - public long maxEUOutput() { - return this.getBaseMetaTileEntity().isAllowedToWork() ? GT_Values.V[this.mTier] : 0L; - } - - public long maxEUStore() { - return Math.max(this.getEUVar(), GT_Values.V[this.mTier] * 40L + this.getMinimumStoredEU()); - } - - public boolean doesFillContainers() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - public boolean doesEmptyContainers() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - public boolean canTankBeFilled() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - public boolean canTankBeEmptied() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - public boolean displaysItemStack() { - return true; - } - - public boolean displaysStackSize() { - return false; - } - - public boolean isFluidInputAllowed(FluidStack aFluid) { - int aVal = this.getFuelValue(aFluid); - Logger.WARNING("Fuel Value: "+aVal); - return aVal > 0; - } - - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10L == 0L) { - int tFuelValue; - if (this.mFluid == null) { - if (aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() + this.getMinimumStoredEU()) { - this.mInventory[this.getStackDisplaySlot()] = null; - } else { - if (this.mInventory[this.getStackDisplaySlot()] == null) { - this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); - } - - this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " - + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); - } - } else { - tFuelValue = this.getFuelValue(this.mFluid); - int tConsumed = this.consumedFluidPerOperation(this.mFluid); - if (tFuelValue > 0 && tConsumed > 0 && this.mFluid.amount > tConsumed) { - long tFluidAmountToUse = Math.min((long) (this.mFluid.amount / tConsumed), - (this.maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / (long) tFuelValue); - if (tFluidAmountToUse > 0L && aBaseMetaTileEntity - .increaseStoredEnergyUnits(tFluidAmountToUse * (long) tFuelValue, true)) { - PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollution()); - this.mFluid.amount = (int) ((long) this.mFluid.amount - tFluidAmountToUse * (long) tConsumed); - } - } - } - - if (this.mInventory[this.getInputSlot()] != null - && aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() * 20L - + this.getMinimumStoredEU() - && GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null) { - tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); - if (tFuelValue > 0) { - ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { - aBaseMetaTileEntity.increaseStoredEnergyUnits((long) tFuelValue, true); - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollution()); - } - } - } - } - - if (aBaseMetaTileEntity.isServerSide()) { - Logger.WARNING("Ticking Servside"); - aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity - .getUniversalEnergyStored() >= this.maxEUOutput() + this.getMinimumStoredEU()); - } - - } - - public abstract int getPollution(); - - public abstract GT_Recipe_Map getRecipes(); - - public abstract int getEfficiency(); - - public int consumedFluidPerOperation(FluidStack aLiquid) { - return 1; - } - - public int getFuelValue(FluidStack aLiquid) { - if (aLiquid != null && this.getRecipes() != null) { - Collection<GT_Recipe> tRecipeList = this.getRecipes().mRecipeList; - if (tRecipeList != null) { - Logger.WARNING("Fuels: "+tRecipeList.size()); - Iterator<GT_Recipe> var4 = tRecipeList.iterator(); - - while (var4.hasNext()) { - GT_Recipe tFuel = (GT_Recipe) var4.next(); - FluidStack tLiquid; - if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null - && aLiquid.isFluidEqual(tLiquid)) { - Logger.WARNING("Fuel Ok"); - return (int) ((long) tFuel.mSpecialValue * (long) this.getEfficiency() - * (long) this.consumedFluidPerOperation(tLiquid) / 100L); - } - if ((tLiquid = tFuel.getRepresentativeFluidInput(0)) != null - && aLiquid.isFluidEqual(tLiquid)) { - Logger.WARNING("Fuel Ok"); - return (int) ((long) tFuel.mSpecialValue * (long) this.getEfficiency() - * (long) this.consumedFluidPerOperation(tLiquid) / 100L); - } - } - } - - return 0; - } else { - return 0; - } - } - - public int getFuelValue(ItemStack aStack) { - if (!GT_Utility.isStackInvalid(aStack) && this.getRecipes() != null) { - Logger.WARNING("Fuel Item OK"); - GT_Recipe tFuel = this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, - (FluidStack[]) null, new ItemStack[]{aStack}); - return tFuel != null ? (int) ((long) tFuel.mSpecialValue * 1000L * (long) this.getEfficiency() / 100L) : 0; - } else { - return 0; - } - } - - public ItemStack getEmptyContainer(ItemStack aStack) { - if (!GT_Utility.isStackInvalid(aStack) && this.getRecipes() != null) { - GT_Recipe tFuel = this.getRecipes().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; - } - } - - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) && (this.getFuelValue(aStack) > 0 - || this.getFuelValue(GT_Utility.getFluidForFilledItem(aStack, true)) > 0); - } - - public int getCapacity() { - return 16000; - } - - public int getTankPressure() { - return -100; - } -}
\ No newline at end of file + public GTPP_MTE_BasicLosslessGenerator( + int aID, String aName, String aNameRegional, int aTier, String aDescription, ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); + } + + public GTPP_MTE_BasicLosslessGenerator( + int aID, String aName, String aNameRegional, int aTier, String[] aDescription, ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); + } + + public GTPP_MTE_BasicLosslessGenerator(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + public GTPP_MTE_BasicLosslessGenerator(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + 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; + } + + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + 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 String[] getDescription() { + String[] desc = new String[this.mDescriptionArray.length + 1]; + System.arraycopy(this.mDescriptionArray, 0, desc, 0, this.mDescriptionArray.length); + desc[this.mDescriptionArray.length] = "Fuel Efficiency: " + this.getEfficiency() + "%"; + return desc; + } + + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + Logger.WARNING("Right Clicked"); + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } else { + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + } + + public ITexture[] getFront(byte aColor) { + return new ITexture[] {BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getBack(byte aColor) { + return new ITexture[] {BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getBottom(byte aColor) { + return new ITexture[] {BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getTop(byte aColor) { + return new ITexture[] {BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getSides(byte aColor) { + return new ITexture[] {BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getFrontActive(byte aColor) { + return this.getFront(aColor); + } + + public ITexture[] getBackActive(byte aColor) { + return this.getBack(aColor); + } + + public ITexture[] getBottomActive(byte aColor) { + return this.getBottom(aColor); + } + + public ITexture[] getTopActive(byte aColor) { + return this.getTop(aColor); + } + + public ITexture[] getSidesActive(byte aColor) { + return this.getSides(aColor); + } + + public boolean isFacingValid(byte aSide) { + return aSide > 1; + } + + public boolean isSimpleMachine() { + return false; + } + + public boolean isValidSlot(int aIndex) { + return aIndex < 2; + } + + public boolean isEnetOutput() { + return true; + } + + public boolean isOutputFacing(byte aSide) { + return true; + } + + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + public long maxEUOutput() { + return this.getBaseMetaTileEntity().isAllowedToWork() ? GT_Values.V[this.mTier] : 0L; + } + + public long maxEUStore() { + return Math.max(this.getEUVar(), GT_Values.V[this.mTier] * 40L + this.getMinimumStoredEU()); + } + + public boolean doesFillContainers() { + return this.getBaseMetaTileEntity().isAllowedToWork(); + } + + public boolean doesEmptyContainers() { + return this.getBaseMetaTileEntity().isAllowedToWork(); + } + + public boolean canTankBeFilled() { + return this.getBaseMetaTileEntity().isAllowedToWork(); + } + + public boolean canTankBeEmptied() { + return this.getBaseMetaTileEntity().isAllowedToWork(); + } + + public boolean displaysItemStack() { + return true; + } + + public boolean displaysStackSize() { + return false; + } + + public boolean isFluidInputAllowed(FluidStack aFluid) { + int aVal = this.getFuelValue(aFluid); + Logger.WARNING("Fuel Value: " + aVal); + return aVal > 0; + } + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10L == 0L) { + int tFuelValue; + if (this.mFluid == null) { + if (aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() + this.getMinimumStoredEU()) { + this.mInventory[this.getStackDisplaySlot()] = null; + } else { + if (this.mInventory[this.getStackDisplaySlot()] == null) { + this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); + } + + this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " + + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); + } + } else { + tFuelValue = this.getFuelValue(this.mFluid); + int tConsumed = this.consumedFluidPerOperation(this.mFluid); + if (tFuelValue > 0 && tConsumed > 0 && this.mFluid.amount > tConsumed) { + long tFluidAmountToUse = Math.min( + (long) (this.mFluid.amount / tConsumed), + (this.maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / (long) tFuelValue); + if (tFluidAmountToUse > 0L + && aBaseMetaTileEntity.increaseStoredEnergyUnits( + tFluidAmountToUse * (long) tFuelValue, true)) { + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollution()); + this.mFluid.amount = (int) ((long) this.mFluid.amount - tFluidAmountToUse * (long) tConsumed); + } + } + } + + if (this.mInventory[this.getInputSlot()] != null + && aBaseMetaTileEntity.getUniversalEnergyStored() + < this.maxEUOutput() * 20L + this.getMinimumStoredEU() + && GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null) { + tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); + if (tFuelValue > 0) { + ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); + if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits((long) tFuelValue, true); + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollution()); + } + } + } + } + + if (aBaseMetaTileEntity.isServerSide()) { + Logger.WARNING("Ticking Servside"); + aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() + && aBaseMetaTileEntity.getUniversalEnergyStored() + >= this.maxEUOutput() + this.getMinimumStoredEU()); + } + } + + public abstract int getPollution(); + + public abstract GT_Recipe_Map getRecipes(); + + public abstract int getEfficiency(); + + public int consumedFluidPerOperation(FluidStack aLiquid) { + return 1; + } + + public int getFuelValue(FluidStack aLiquid) { + if (aLiquid != null && this.getRecipes() != null) { + Collection<GT_Recipe> tRecipeList = this.getRecipes().mRecipeList; + if (tRecipeList != null) { + Logger.WARNING("Fuels: " + tRecipeList.size()); + Iterator<GT_Recipe> var4 = tRecipeList.iterator(); + + while (var4.hasNext()) { + GT_Recipe tFuel = (GT_Recipe) var4.next(); + FluidStack tLiquid; + if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null + && aLiquid.isFluidEqual(tLiquid)) { + Logger.WARNING("Fuel Ok"); + return (int) ((long) tFuel.mSpecialValue + * (long) this.getEfficiency() + * (long) this.consumedFluidPerOperation(tLiquid) + / 100L); + } + if ((tLiquid = tFuel.getRepresentativeFluidInput(0)) != null && aLiquid.isFluidEqual(tLiquid)) { + Logger.WARNING("Fuel Ok"); + return (int) ((long) tFuel.mSpecialValue + * (long) this.getEfficiency() + * (long) this.consumedFluidPerOperation(tLiquid) + / 100L); + } + } + } + + return 0; + } else { + return 0; + } + } + + public int getFuelValue(ItemStack aStack) { + if (!GT_Utility.isStackInvalid(aStack) && this.getRecipes() != null) { + Logger.WARNING("Fuel Item OK"); + GT_Recipe tFuel = this.getRecipes() + .findRecipe( + this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, (FluidStack[]) null, new ItemStack[] { + aStack + }); + return tFuel != null ? (int) ((long) tFuel.mSpecialValue * 1000L * (long) this.getEfficiency() / 100L) : 0; + } else { + return 0; + } + } + + public ItemStack getEmptyContainer(ItemStack aStack) { + if (!GT_Utility.isStackInvalid(aStack) && this.getRecipes() != null) { + GT_Recipe tFuel = this.getRecipes() + .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; + } + } + + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) + && (this.getFuelValue(aStack) > 0 + || this.getFuelValue(GT_Utility.getFluidForFilledItem(aStack, true)) > 0); + } + + public int getCapacity() { + return 16000; + } + + public int getTankPressure() { + return -100; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicMachine.java index 2eb1d36791..f6cf2391b3 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicMachine.java @@ -1,6 +1,7 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.custom.power; -import gregtech.GT_Mod; +import static gregtech.api.enums.GT_Values.V; + import gregtech.api.GregTech_API; import gregtech.api.enums.ItemList; import gregtech.api.enums.Textures; @@ -16,6 +17,7 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.random.XSTR; +import java.util.Arrays; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -26,10 +28,6 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; -import java.util.Arrays; - -import static gregtech.api.enums.GT_Values.V; - /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! * <p/> @@ -40,14 +38,20 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { /** * return values for checkRecipe() */ - protected static final int - DID_NOT_FIND_RECIPE = 0, + protected static final int DID_NOT_FIND_RECIPE = 0, FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS = 1, FOUND_AND_SUCCESSFULLY_USED_RECIPE = 2; + public static final int OTHER_SLOT_COUNT = 4; public final ItemStack[] mOutputItems; public final int mInputSlotCount, mAmperage; - public boolean mAllowInputFromOutputSide = false, mFluidTransfer = false, mItemTransfer = false, mHasBeenUpdated = false, mStuttering = false, mCharge = false, mDecharge = false; + public boolean mAllowInputFromOutputSide = false, + mFluidTransfer = false, + mItemTransfer = false, + mHasBeenUpdated = false, + mStuttering = false, + mCharge = false, + mDecharge = false; public int mMainFacing = -1, mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mOutputBlocked = 0; public FluidStack mOutputFluid; public String mGUIName = "", mNEIName = ""; @@ -56,6 +60,7 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { * Contains the Recipe which has been previously used, or null if there was no previous Recipe, which could have been buffered */ protected GT_Recipe mLastRecipe = null; + private FluidStack mFluidOut; /** @@ -75,8 +80,26 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { * 12 = SideFacingPipeActive * 13 = SideFacingPipeInactive */ - public GTPP_MTE_BasicMachine(int aID, String aName, String aNameRegional, int aTier, int aAmperage, String aDescription, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName, ITexture... aOverlays) { - super(aID, aName, aNameRegional, aTier, OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, aDescription, aOverlays); + public GTPP_MTE_BasicMachine( + int aID, + String aName, + String aNameRegional, + int aTier, + int aAmperage, + String aDescription, + int aInputSlotCount, + int aOutputSlotCount, + String aGUIName, + String aNEIName, + ITexture... aOverlays) { + super( + aID, + aName, + aNameRegional, + aTier, + OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, + aDescription, + aOverlays); mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; mAmperage = aAmperage; @@ -84,8 +107,26 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { mNEIName = aNEIName; } - public GTPP_MTE_BasicMachine(int aID, String aName, String aNameRegional, int aTier, int aAmperage, String[] aDescription, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName, ITexture... aOverlays) { - super(aID, aName, aNameRegional, aTier, OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, aDescription, aOverlays); + public GTPP_MTE_BasicMachine( + int aID, + String aName, + String aNameRegional, + int aTier, + int aAmperage, + String[] aDescription, + int aInputSlotCount, + int aOutputSlotCount, + String aGUIName, + String aNEIName, + ITexture... aOverlays) { + super( + aID, + aName, + aNameRegional, + aTier, + OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, + aDescription, + aOverlays); mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; mAmperage = aAmperage; @@ -93,7 +134,16 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { mNEIName = aNEIName; } - public GTPP_MTE_BasicMachine(String aName, int aTier, int aAmperage, String aDescription, ITexture[][][] aTextures, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName) { + public GTPP_MTE_BasicMachine( + String aName, + int aTier, + int aAmperage, + String aDescription, + ITexture[][][] aTextures, + int aInputSlotCount, + int aOutputSlotCount, + String aGUIName, + String aNEIName) { super(aName, aTier, OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, aDescription, aTextures); mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; @@ -101,8 +151,17 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { mGUIName = aGUIName; mNEIName = aNEIName; } - - public GTPP_MTE_BasicMachine(String aName, int aTier, int aAmperage, String[] aDescription, ITexture[][][] aTextures, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName) { + + public GTPP_MTE_BasicMachine( + String aName, + int aTier, + int aAmperage, + String[] aDescription, + ITexture[][][] aTextures, + int aInputSlotCount, + int aOutputSlotCount, + String aGUIName, + String aNEIName) { super(aName, aTier, OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, aDescription, aTextures); mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; @@ -112,18 +171,18 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { } protected boolean isValidMainFacing(byte aSide) { - return aSide > 1; - } - - public boolean setMainFacing(byte aSide){ - if (!isValidMainFacing(aSide)) return false; - mMainFacing = aSide; - if(getBaseMetaTileEntity().getFrontFacing() == mMainFacing){ - getBaseMetaTileEntity().setFrontFacing(GT_Utility.getOppositeSide(aSide)); - } + return aSide > 1; + } + + public boolean setMainFacing(byte aSide) { + if (!isValidMainFacing(aSide)) return false; + mMainFacing = aSide; + if (getBaseMetaTileEntity().getFrontFacing() == mMainFacing) { + getBaseMetaTileEntity().setFrontFacing(GT_Utility.getOppositeSide(aSide)); + } onFacingChange(); onMachineBlockUpdate(); - return true; + return true; } @Override @@ -132,10 +191,12 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { aTextures = Arrays.copyOf(aTextures, 14); for (int i = 0; i < aTextures.length; i++) - if (aTextures[i] != null) for (byte c = -1; c < 16; c++) { - if (rTextures[i][c + 1] == null) - rTextures[i][c + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][c + 1], aTextures[i]}; - } + if (aTextures[i] != null) + for (byte c = -1; c < 16; c++) { + if (rTextures[i][c + 1] == null) + rTextures[i][c + 1] = + new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][c + 1], aTextures[i]}; + } for (byte c = -1; c < 16; c++) { if (rTextures[0][c + 1] == null) rTextures[0][c + 1] = getSideFacingActive(c); @@ -157,8 +218,28 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { } @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return mTextures[mMainFacing < 2 ? aSide == aFacing ? aActive ? 2 : 3 : aSide == 0 ? aActive ? 6 : 7 : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1 : aSide == mMainFacing ? aActive ? 2 : 3 : (showPipeFacing() && aSide == aFacing) ? aSide == 0 ? aActive ? 8 : 9 : aSide == 1 ? aActive ? 10 : 11 : aActive ? 12 : 13 : aSide == 0 ? aActive ? 6 : 7 : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1][aColorIndex + 1]; + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + return mTextures[ + mMainFacing < 2 + ? aSide == aFacing + ? aActive ? 2 : 3 + : aSide == 0 ? aActive ? 6 : 7 : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1 + : aSide == mMainFacing + ? aActive ? 2 : 3 + : (showPipeFacing() && aSide == aFacing) + ? aSide == 0 + ? aActive ? 8 : 9 + : aSide == 1 ? aActive ? 10 : 11 : aActive ? 12 : 13 + : aSide == 0 + ? aActive ? 6 : 7 + : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1][ + aColorIndex + 1]; } @Override @@ -183,7 +264,9 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { @Override public boolean isValidSlot(int aIndex) { - return aIndex > 0 && super.isValidSlot(aIndex) && aIndex != OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length; + return aIndex > 0 + && super.isValidSlot(aIndex) + && aIndex != OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length; } @Override @@ -213,7 +296,9 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { @Override public boolean isLiquidInput(byte aSide) { - return aSide != mMainFacing && (mAllowInputFromOutputSide || aSide != getBaseMetaTileEntity().getFrontFacing()); + return aSide != mMainFacing + && (mAllowInputFromOutputSide + || aSide != getBaseMetaTileEntity().getFrontFacing()); } @Override @@ -304,7 +389,8 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { @Override public boolean isFluidInputAllowed(FluidStack aFluid) { - return getFillableStack() != null || (getRecipeList() != null && getRecipeList().containsInput(aFluid)); + return getFillableStack() != null + || (getRecipeList() != null && getRecipeList().containsInput(aFluid)); } @Override @@ -372,7 +458,14 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), mGUIName, GT_Utility.isStringValid(mNEIName) ? mNEIName : getRecipeList() != null ? getRecipeList().mUnlocalizedName : ""); + return new GT_GUIContainer_BasicMachine( + aPlayerInventory, + aBaseMetaTileEntity, + getLocalName(), + mGUIName, + GT_Utility.isStringValid(mNEIName) + ? mNEIName + : getRecipeList() != null ? getRecipeList().mUnlocalizedName : ""); } @Override @@ -434,8 +527,8 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { if (++mProgresstime >= mMaxProgresstime) { for (int i = 0; i < mOutputItems.length; i++) for (int j = 0; j < mOutputItems.length; j++) - if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot() + ((j + i) % mOutputItems.length), mOutputItems[i])) - break; + if (aBaseMetaTileEntity.addStackToSlot( + getOutputSlot() + ((j + i) % mOutputItems.length), mOutputItems[i])) break; if (mOutputFluid != null) if (getDrainableStack() == null) setDrainableStack(mOutputFluid.copy()); else if (mOutputFluid.isFluidEqual(getDrainableStack())) @@ -451,8 +544,11 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { } if (mProgresstime > 5) mStuttering = false; XSTR aXSTR = new XSTR(); - //Dumb April Fools Shit - // if(GT_Mod.gregtechproxy.mAprilFool && aXSTR.nextInt(5000)==0)GT_Utility.sendSoundToPlayers(aBaseMetaTileEntity.getWorld(), GregTech_API.sSoundList.get(5), 10.0F, -1.0F, aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getYCoord(),aBaseMetaTileEntity.getZCoord()); + // Dumb April Fools Shit + // if(GT_Mod.gregtechproxy.mAprilFool && + // aXSTR.nextInt(5000)==0)GT_Utility.sendSoundToPlayers(aBaseMetaTileEntity.getWorld(), + // GregTech_API.sSoundList.get(5), 10.0F, -1.0F, aBaseMetaTileEntity.getXCoord(), + // aBaseMetaTileEntity.getYCoord(),aBaseMetaTileEntity.getZCoord()); } else { if (!mStuttering) { stutterProcess(); @@ -466,32 +562,65 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { boolean tRemovedOutputFluid = false; - if (doesAutoOutputFluids() && getDrainableStack() != null && aBaseMetaTileEntity.getFrontFacing() != mMainFacing && (tSucceeded || aTick % 20 == 0)) { + if (doesAutoOutputFluids() + && getDrainableStack() != null + && aBaseMetaTileEntity.getFrontFacing() != mMainFacing + && (tSucceeded || aTick % 20 == 0)) { IFluidHandler tTank = aBaseMetaTileEntity.getITankContainerAtSide(aBaseMetaTileEntity.getFrontFacing()); if (tTank != null) { FluidStack tDrained = drain(1000, false); if (tDrained != null) { - int tFilledAmount = tTank.fill(ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tDrained, false); + int tFilledAmount = tTank.fill( + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tDrained, false); if (tFilledAmount > 0) - tTank.fill(ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), drain(tFilledAmount, true), true); + tTank.fill( + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), + drain(tFilledAmount, true), + true); } } if (getDrainableStack() == null) tRemovedOutputFluid = true; } - if (doesAutoOutput() && !isOutputEmpty() && aBaseMetaTileEntity.getFrontFacing() != mMainFacing && (tSucceeded || mOutputBlocked % 300 == 1 || aBaseMetaTileEntity.hasInventoryBeenModified() || aTick % 600 == 0)) { + if (doesAutoOutput() + && !isOutputEmpty() + && aBaseMetaTileEntity.getFrontFacing() != mMainFacing + && (tSucceeded + || mOutputBlocked % 300 == 1 + || aBaseMetaTileEntity.hasInventoryBeenModified() + || aTick % 600 == 0)) { TileEntity tTileEntity2 = aBaseMetaTileEntity.getTileEntityAtSide(aBaseMetaTileEntity.getFrontFacing()); - for (int i = 0, tCosts = 1; i < mOutputItems.length && tCosts > 0 && aBaseMetaTileEntity.isUniversalEnergyStored(128); i++) { - tCosts = GT_Utility.moveOneItemStack(aBaseMetaTileEntity, tTileEntity2, aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + for (int i = 0, tCosts = 1; + i < mOutputItems.length && tCosts > 0 && aBaseMetaTileEntity.isUniversalEnergyStored(128); + i++) { + tCosts = GT_Utility.moveOneItemStack( + aBaseMetaTileEntity, + tTileEntity2, + aBaseMetaTileEntity.getFrontFacing(), + aBaseMetaTileEntity.getBackFacing(), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); if (tCosts > 0) aBaseMetaTileEntity.decreaseStoredEnergyUnits(tCosts, true); } } - if (mOutputBlocked != 0) if (isOutputEmpty()) mOutputBlocked = 0; - else mOutputBlocked++; + if (mOutputBlocked != 0) + if (isOutputEmpty()) mOutputBlocked = 0; + else mOutputBlocked++; if (allowToCheckRecipe()) { - if (mMaxProgresstime <= 0 && aBaseMetaTileEntity.isAllowedToWork() && (tRemovedOutputFluid || tSucceeded || aBaseMetaTileEntity.hasInventoryBeenModified() || aTick % 600 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) && hasEnoughEnergyToCheckRecipe()) { + if (mMaxProgresstime <= 0 + && aBaseMetaTileEntity.isAllowedToWork() + && (tRemovedOutputFluid + || tSucceeded + || aBaseMetaTileEntity.hasInventoryBeenModified() + || aTick % 600 == 0 + || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) + && hasEnoughEnergyToCheckRecipe()) { if (checkRecipe() == 2) { if (mInventory[3] != null && mInventory[3].stackSize <= 0) mInventory[3] = null; for (int i = getInputSlot(), j = i + mInputSlotCount; i < j; i++) @@ -538,7 +667,8 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { if (ItemList.Display_Fluid.isStackEqual(mInventory[tDisplayStackSlot], true, true)) mInventory[tDisplayStackSlot] = null; } else { - mInventory[tDisplayStackSlot] = GT_Utility.getFluidDisplayStack(getFillableStack(), displaysStackSize()); + mInventory[tDisplayStackSlot] = + GT_Utility.getFluidDisplayStack(getFillableStack(), displaysStackSize()); } } } @@ -584,14 +714,20 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { } protected boolean canOutput(GT_Recipe aRecipe) { - return aRecipe != null && (aRecipe.mNeedsEmptyOutput ? isOutputEmpty() && getDrainableStack() == null : canOutput(aRecipe.getFluidOutput(0)) && canOutput(aRecipe.mOutputs)); + return aRecipe != null + && (aRecipe.mNeedsEmptyOutput + ? isOutputEmpty() && getDrainableStack() == null + : canOutput(aRecipe.getFluidOutput(0)) && canOutput(aRecipe.mOutputs)); } protected boolean canOutput(ItemStack... aOutputs) { if (aOutputs == null) return true; ItemStack[] tOutputSlots = getAllOutputs(); for (int i = 0; i < tOutputSlots.length && i < aOutputs.length; i++) - if (tOutputSlots[i] != null && aOutputs[i] != null && (!GT_Utility.areStacksEqual(tOutputSlots[i], aOutputs[i], false) || tOutputSlots[i].stackSize + aOutputs[i].stackSize > tOutputSlots[i].getMaxStackSize())) { + if (tOutputSlots[i] != null + && aOutputs[i] != null + && (!GT_Utility.areStacksEqual(tOutputSlots[i], aOutputs[i], false) + || tOutputSlots[i].stackSize + aOutputs[i].stackSize > tOutputSlots[i].getMaxStackSize())) { mOutputBlocked++; return false; } @@ -599,7 +735,11 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { } protected boolean canOutput(FluidStack aOutput) { - return getDrainableStack() == null || aOutput == null || (getDrainableStack().isFluidEqual(aOutput) && (getDrainableStack().amount <= 0 || getDrainableStack().amount + aOutput.amount <= getCapacity())); + return getDrainableStack() == null + || aOutput == null + || (getDrainableStack().isFluidEqual(aOutput) + && (getDrainableStack().amount <= 0 + || getDrainableStack().amount + aOutput.amount <= getCapacity())); } protected ItemStack getInputAt(int aIndex) { @@ -699,13 +839,15 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { @Override public String[] getInfoData() { - return new String[]{ - mNEIName, - "Progress:", (mProgresstime / 20) + " secs", - (mMaxProgresstime / 20) + " secs", - "Stored Energy:", - getBaseMetaTileEntity().getStoredEU() + "EU", - getBaseMetaTileEntity().getEUCapacity() + "EU"}; + return new String[] { + mNEIName, + "Progress:", + (mProgresstime / 20) + " secs", + (mMaxProgresstime / 20) + " secs", + "Stored Energy:", + getBaseMetaTileEntity().getStoredEU() + "EU", + getBaseMetaTileEntity().getEUCapacity() + "EU" + }; } @Override @@ -717,13 +859,17 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (aSide == getBaseMetaTileEntity().getFrontFacing() || aSide == mMainFacing) { mAllowInputFromOutputSide = !mAllowInputFromOutputSide; - GT_Utility.sendChatToPlayer(aPlayer, mAllowInputFromOutputSide ? "Input from Output Side allowed" : "Input from Output Side forbidden"); + GT_Utility.sendChatToPlayer( + aPlayer, + mAllowInputFromOutputSide ? "Input from Output Side allowed" : "Input from Output Side forbidden"); } } @Override public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { - return (aSide != mMainFacing || GregTech_API.getCoverBehavior(aCoverID.toStack()).isGUIClickable(aSide, GT_Utility.stackToInt(aCoverID.toStack()), 0, getBaseMetaTileEntity())); + return (aSide != mMainFacing + || GregTech_API.getCoverBehavior(aCoverID.toStack()) + .isGUIClickable(aSide, GT_Utility.stackToInt(aCoverID.toStack()), 0, getBaseMetaTileEntity())); } @Override @@ -733,8 +879,10 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { @Override public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - if (aSide == mMainFacing || aIndex < getInputSlot() || aIndex >= getInputSlot() + mInputSlotCount || (!mAllowInputFromOutputSide && aSide == aBaseMetaTileEntity.getFrontFacing())) - return false; + if (aSide == mMainFacing + || aIndex < getInputSlot() + || aIndex >= getInputSlot() + mInputSlotCount + || (!mAllowInputFromOutputSide && aSide == aBaseMetaTileEntity.getFrontFacing())) return false; for (int i = getInputSlot(), j = i + mInputSlotCount; i < j; i++) if (GT_Utility.areStacksEqual(GT_OreDictUnificator.get(aStack), mInventory[i])) return i == aIndex; return true; @@ -760,25 +908,31 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { return checkRecipe(false); } - public static boolean isValidForLowGravity(GT_Recipe tRecipe, int dimId){ - return //TODO check or get a better solution - DimensionManager.getProvider(dimId).getClass().getName().contains("Orbit") || - DimensionManager.getProvider(dimId).getClass().getName().endsWith("Space") || - DimensionManager.getProvider(dimId).getClass().getName().endsWith("Asteroids") || - DimensionManager.getProvider(dimId).getClass().getName().endsWith("SS") || - DimensionManager.getProvider(dimId).getClass().getName().contains("SpaceStation"); + public static boolean isValidForLowGravity(GT_Recipe tRecipe, int dimId) { + return // TODO check or get a better solution + DimensionManager.getProvider(dimId).getClass().getName().contains("Orbit") + || DimensionManager.getProvider(dimId).getClass().getName().endsWith("Space") + || DimensionManager.getProvider(dimId).getClass().getName().endsWith("Asteroids") + || DimensionManager.getProvider(dimId).getClass().getName().endsWith("SS") + || DimensionManager.getProvider(dimId).getClass().getName().contains("SpaceStation"); } - /** * * @param skipOC disables OverclockedNess calculation and check - if you do you must implement your own method... * @return */ - public int checkRecipe(boolean skipOC){ + public int checkRecipe(boolean skipOC) { GT_Recipe_Map tMap = getRecipeList(); if (tMap == null) return DID_NOT_FIND_RECIPE; - GT_Recipe tRecipe = tMap.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, V[mTier], new FluidStack[]{getFillableStack()}, getSpecialSlot(), getAllInputs()); + GT_Recipe tRecipe = tMap.findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + V[mTier], + new FluidStack[] {getFillableStack()}, + getSpecialSlot(), + getAllInputs()); if (tRecipe == null) return DID_NOT_FIND_RECIPE; if (tRecipe.mCanBeBuffered) mLastRecipe = tRecipe; @@ -788,7 +942,7 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { } if (tRecipe.mSpecialValue == -200 && (mCleanroom == null || mCleanroom.mEfficiency == 0)) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - if (!tRecipe.isRecipeInputEqual(true, new FluidStack[]{getFillableStack()}, getAllInputs())) + if (!tRecipe.isRecipeInputEqual(true, new FluidStack[] {getFillableStack()}, getAllInputs())) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; for (int i = 0; i < mOutputItems.length; i++) if (getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(i)) @@ -803,58 +957,76 @@ public abstract class GTPP_MTE_BasicMachine extends GTPP_MTE_BasicTank { } public ITexture[] getSideFacingActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getSideFacingInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getFrontFacingActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getFrontFacingInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getTopFacingActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getTopFacingInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getBottomFacingActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getBottomFacingInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getBottomFacingPipeActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getBottomFacingPipeInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getTopFacingPipeActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getTopFacingPipeInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getSideFacingPipeActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getSideFacingPipeInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } -}
\ No newline at end of file +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicTank.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicTank.java index 9c6840e33c..bbc2206784 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicTank.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicTank.java @@ -1,8 +1,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.custom.power; import gregtech.api.enums.ItemList; -import gregtech.api.gui.GT_Container_BasicTank; -import gregtech.api.gui.GT_GUIContainer_BasicTank; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Utility; @@ -25,19 +23,35 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { /** * @param aInvSlotCount should be 3 */ - public GTPP_MTE_BasicTank(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, String aDescription, ITexture... aTextures) { + public GTPP_MTE_BasicTank( + int aID, + String aName, + String aNameRegional, + int aTier, + int aInvSlotCount, + String aDescription, + ITexture... aTextures) { super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); } - public GTPP_MTE_BasicTank(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, String[] aDescription, ITexture... aTextures) { + public GTPP_MTE_BasicTank( + int aID, + String aName, + String aNameRegional, + int aTier, + int aInvSlotCount, + String[] aDescription, + ITexture... aTextures) { super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); } - public GTPP_MTE_BasicTank(String aName, int aTier, int aInvSlotCount, String aDescription, ITexture[][][] aTextures) { + public GTPP_MTE_BasicTank( + String aName, int aTier, int aInvSlotCount, String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aInvSlotCount, aDescription, aTextures); } - - public GTPP_MTE_BasicTank(String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) { + + public GTPP_MTE_BasicTank( + String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) { super(aName, aTier, aInvSlotCount, aDescription, aTextures); } @@ -136,7 +150,8 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { if (ItemList.Display_Fluid.isStackEqual(mInventory[getStackDisplaySlot()], true, true)) mInventory[getStackDisplaySlot()] = null; } else { - mInventory[getStackDisplaySlot()] = GT_Utility.getFluidDisplayStack(getDisplayedFluid(), displaysStackSize()); + mInventory[getStackDisplaySlot()] = + GT_Utility.getFluidDisplayStack(getDisplayedFluid(), displaysStackSize()); } } @@ -145,15 +160,22 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { if (tFluid != null && isFluidInputAllowed(tFluid)) { if (getFillableStack() == null) { if (isFluidInputAllowed(tFluid) && tFluid.amount <= getCapacity()) { - if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), GT_Utility.getContainerItem(mInventory[getInputSlot()], true), 1)) { + if (aBaseMetaTileEntity.addStackToSlot( + getOutputSlot(), + GT_Utility.getContainerItem(mInventory[getInputSlot()], true), + 1)) { setFillableStack(tFluid.copy()); this.onEmptyingContainerWhenEmpty(); aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); } } } else { - if (tFluid.isFluidEqual(getFillableStack()) && tFluid.amount + getFillableStack().amount <= getCapacity()) { - if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), GT_Utility.getContainerItem(mInventory[getInputSlot()], true), 1)) { + if (tFluid.isFluidEqual(getFillableStack()) + && tFluid.amount + getFillableStack().amount <= getCapacity()) { + if (aBaseMetaTileEntity.addStackToSlot( + getOutputSlot(), + GT_Utility.getContainerItem(mInventory[getInputSlot()], true), + 1)) { getFillableStack().amount += tFluid.amount; aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); } @@ -163,7 +185,8 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { } if (doesFillContainers()) { - ItemStack tOutput = GT_Utility.fillFluidContainer(getDrainableStack(), mInventory[getInputSlot()], false, true); + ItemStack tOutput = + GT_Utility.fillFluidContainer(getDrainableStack(), mInventory[getInputSlot()], false, true); if (tOutput != null && aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), tOutput, 1)) { FluidStack tFluid = GT_Utility.getFluidForFilledItem(tOutput, true); aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); @@ -186,8 +209,11 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { @Override public int fill(FluidStack aFluid, boolean doFill) { - if (aFluid == null || aFluid.getFluid().getID() <= 0 || aFluid.amount <= 0 || !canTankBeFilled() || !isFluidInputAllowed(aFluid)) - return 0; + if (aFluid == null + || aFluid.getFluid().getID() <= 0 + || aFluid.amount <= 0 + || !canTankBeFilled() + || !isFluidInputAllowed(aFluid)) return 0; if (getFillableStack() == null || getFillableStack().getFluid().getID() <= 0) { if (aFluid.amount <= getCapacity()) { @@ -205,8 +231,7 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { return getCapacity(); } - if (!getFillableStack().isFluidEqual(aFluid)) - return 0; + if (!getFillableStack().isFluidEqual(aFluid)) return 0; int space = getCapacity() - getFillableStack().amount; if (aFluid.amount <= space) { @@ -216,8 +241,7 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { } return aFluid.amount; } - if (doFill) - getFillableStack().amount = getCapacity(); + if (doFill) getFillableStack().amount = getCapacity(); return space; } @@ -231,8 +255,7 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { } int used = maxDrain; - if (getDrainableStack().amount < used) - used = getDrainableStack().amount; + if (getDrainableStack().amount < used) used = getDrainableStack().amount; if (doDrain) { getDrainableStack().amount -= used; @@ -259,8 +282,8 @@ public abstract class GTPP_MTE_BasicTank extends GTPP_MTE_TieredMachineBlock { public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return aIndex == getInputSlot(); } - - protected void onEmptyingContainerWhenEmpty(){ - //Do nothing + + protected void onEmptyingContainerWhenEmpty() { + // Do nothing } -}
\ No newline at end of file +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_TieredMachineBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_TieredMachineBlock.java index 8110037c46..e45588e126 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_TieredMachineBlock.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_TieredMachineBlock.java @@ -4,7 +4,6 @@ import static gregtech.api.enums.GT_Values.GT; import gregtech.api.interfaces.ITexture; import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.core.lib.CORE; public abstract class GTPP_MTE_TieredMachineBlock extends MetaTileEntityCustomPower { /** @@ -25,17 +24,31 @@ public abstract class GTPP_MTE_TieredMachineBlock extends MetaTileEntityCustomPo */ public final ITexture[][][] mTextures; - public GTPP_MTE_TieredMachineBlock(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, String aDescription, ITexture... aTextures) { + public GTPP_MTE_TieredMachineBlock( + int aID, + String aName, + String aNameRegional, + int aTier, + int aInvSlotCount, + String aDescription, + ITexture... aTextures) { super(aID, aName, aNameRegional, aInvSlotCount); mTier = (byte) Math.max(0, Math.min(aTier, 9)); - mDescriptionArray = aDescription == null ? new String[0] : new String[]{aDescription}; + mDescriptionArray = aDescription == null ? new String[0] : new String[] {aDescription}; mDescription = mDescriptionArray.length > 0 ? mDescriptionArray[0] : ""; // must always be the last call! if (GT.isClientSide()) mTextures = getTextureSet(aTextures); else mTextures = null; } - public GTPP_MTE_TieredMachineBlock(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, String[] aDescription, ITexture... aTextures) { + public GTPP_MTE_TieredMachineBlock( + int aID, + String aName, + String aNameRegional, + int aTier, + int aInvSlotCount, + String[] aDescription, + ITexture... aTextures) { super(aID, aName, aNameRegional, aInvSlotCount); mTier = (byte) Math.max(0, Math.min(aTier, 9)); mDescriptionArray = aDescription == null ? new String[0] : aDescription; @@ -46,15 +59,17 @@ public abstract class GTPP_MTE_TieredMachineBlock extends MetaTileEntityCustomPo else mTextures = null; } - public GTPP_MTE_TieredMachineBlock(String aName, int aTier, int aInvSlotCount, String aDescription, ITexture[][][] aTextures) { + public GTPP_MTE_TieredMachineBlock( + String aName, int aTier, int aInvSlotCount, String aDescription, ITexture[][][] aTextures) { super(aName, aInvSlotCount); mTier = (byte) aTier; - mDescriptionArray = aDescription == null ? new String[0] : new String[]{aDescription}; + mDescriptionArray = aDescription == null ? new String[0] : new String[] {aDescription}; mDescription = mDescriptionArray.length > 0 ? mDescriptionArray[0] : ""; mTextures = aTextures; } - public GTPP_MTE_TieredMachineBlock(String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) { + public GTPP_MTE_TieredMachineBlock( + String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) { super(aName, aInvSlotCount); mTier = (byte) aTier; mDescriptionArray = aDescription == null ? new String[0] : aDescription; @@ -79,14 +94,14 @@ public abstract class GTPP_MTE_TieredMachineBlock extends MetaTileEntityCustomPo @Override public String[] getDescription() { - AutoMap<String> aTooltip = new AutoMap<String>(); - String []s1 = null; - s1 = new String[aTooltip.size()]; - int u = 0; - for (String s : aTooltip) { - s1[u] = s; - } - return s1; + AutoMap<String> aTooltip = new AutoMap<String>(); + String[] s1 = null; + s1 = new String[aTooltip.size()]; + int u = 0; + for (String s : aTooltip) { + s1[u] = s; + } + return s1; } /** @@ -96,4 +111,4 @@ public abstract class GTPP_MTE_TieredMachineBlock extends MetaTileEntityCustomPo * @param aTextures is the optional Array you can give to the Constructor. */ public abstract ITexture[][][] getTextureSet(ITexture[] aTextures); -}
\ No newline at end of file +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/MetaTileEntityCustomPower.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/MetaTileEntityCustomPower.java index 31d24ff343..36185b638b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/MetaTileEntityCustomPower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/MetaTileEntityCustomPower.java @@ -12,83 +12,79 @@ import net.minecraft.world.World; public abstract class MetaTileEntityCustomPower extends CustomMetaTileBase { - public MetaTileEntityCustomPower(int aID, String aBasicName, String aRegionalName, int aInvSlotCount) { - super(aID, aBasicName, aRegionalName, aInvSlotCount); - this.setBaseMetaTileEntity(Meta_GT_Proxy.constructBaseMetaTileEntityCustomPower()); - this.getBaseMetaTileEntity().setMetaTileID((short) aID); - } - - public MetaTileEntityCustomPower(String aStack, int aInvSlotCount) { - super(aStack, aInvSlotCount); - } - - public long getMinimumStoredEU() { - return 0L; - } - - public boolean doesExplode() { - return this.getBaseCustomMetaTileEntity().doesExplode(); - } - - + public MetaTileEntityCustomPower(int aID, String aBasicName, String aRegionalName, int aInvSlotCount) { + super(aID, aBasicName, aRegionalName, aInvSlotCount); + this.setBaseMetaTileEntity(Meta_GT_Proxy.constructBaseMetaTileEntityCustomPower()); + this.getBaseMetaTileEntity().setMetaTileID((short) aID); + } - public void doExplosion(long aExplosionPower) { - - if (!doesExplode()) { - Logger.INFO("Machine tried to explode, let's stop that. xo [doExplosion]"); - return; - } - - float tStrength = aExplosionPower < GT_Values.V[0] - ? 1.0F - : (aExplosionPower < GT_Values.V[1] - ? 2.0F - : (aExplosionPower < GT_Values.V[2] - ? 3.0F - : (aExplosionPower < GT_Values.V[3] - ? 4.0F - : (aExplosionPower < GT_Values.V[4] - ? 5.0F - : (aExplosionPower < GT_Values.V[4] * 2L - ? 6.0F - : (aExplosionPower < GT_Values.V[5] - ? 7.0F - : (aExplosionPower < GT_Values.V[6] - ? 8.0F - : (aExplosionPower < GT_Values.V[7] - ? 9.0F - : 10.0F)))))))); - int tX = this.getBaseMetaTileEntity().getXCoord(); - short tY = this.getBaseMetaTileEntity().getYCoord(); - int tZ = this.getBaseMetaTileEntity().getZCoord(); - World tWorld = this.getBaseMetaTileEntity().getWorld(); - GT_Utility.sendSoundToPlayers(tWorld, (String) GregTech_API.sSoundList.get(Integer.valueOf(209)), 1.0F, -1.0F, - tX, tY, tZ); - tWorld.setBlock(tX, tY, tZ, Blocks.air); - if (GregTech_API.sMachineExplosions) { - tWorld.createExplosion((Entity) null, (double) tX + 0.5D, (double) tY + 0.5D, (double) tZ + 0.5D, tStrength, - true); - } + public MetaTileEntityCustomPower(String aStack, int aInvSlotCount) { + super(aStack, aInvSlotCount); + } - } + public long getMinimumStoredEU() { + return 0L; + } - @Override - public void onExplosion() { - if (!doesExplode()) { - Logger.INFO("Machine tried to explode, let's stop that. xo [onExplosion]"); - return; - } - super.onExplosion(); - } + public boolean doesExplode() { + return this.getBaseCustomMetaTileEntity().doesExplode(); + } - @Override - public boolean isElectric() { - return true; - } + public void doExplosion(long aExplosionPower) { - @Override - public long getEUVar() { - return super.getEUVar(); - } + if (!doesExplode()) { + Logger.INFO("Machine tried to explode, let's stop that. xo [doExplosion]"); + return; + } + float tStrength = aExplosionPower < GT_Values.V[0] + ? 1.0F + : (aExplosionPower < GT_Values.V[1] + ? 2.0F + : (aExplosionPower < GT_Values.V[2] + ? 3.0F + : (aExplosionPower < GT_Values.V[3] + ? 4.0F + : (aExplosionPower < GT_Values.V[4] + ? 5.0F + : (aExplosionPower < GT_Values.V[4] * 2L + ? 6.0F + : (aExplosionPower < GT_Values.V[5] + ? 7.0F + : (aExplosionPower < GT_Values.V[6] + ? 8.0F + : (aExplosionPower < GT_Values.V[7] + ? 9.0F + : 10.0F)))))))); + int tX = this.getBaseMetaTileEntity().getXCoord(); + short tY = this.getBaseMetaTileEntity().getYCoord(); + int tZ = this.getBaseMetaTileEntity().getZCoord(); + World tWorld = this.getBaseMetaTileEntity().getWorld(); + GT_Utility.sendSoundToPlayers( + tWorld, (String) GregTech_API.sSoundList.get(Integer.valueOf(209)), 1.0F, -1.0F, tX, tY, tZ); + tWorld.setBlock(tX, tY, tZ, Blocks.air); + if (GregTech_API.sMachineExplosions) { + tWorld.createExplosion( + (Entity) null, (double) tX + 0.5D, (double) tY + 0.5D, (double) tZ + 0.5D, tStrength, true); + } + } + + @Override + public void onExplosion() { + if (!doesExplode()) { + Logger.INFO("Machine tried to explode, let's stop that. xo [onExplosion]"); + return; + } + super.onExplosion(); + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public long getEUVar() { + return super.getEUVar(); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBreaker.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBreaker.java index 3821b2a95c..ac069be52d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBreaker.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBreaker.java @@ -21,265 +21,282 @@ import net.minecraft.util.EnumChatFormatting; public class GT_MetaTileEntity_BasicBreaker extends GTPP_MTE_TieredMachineBlock { - public boolean mCharge = false; - public boolean mDecharge = false; - public int mBatteryCount = 0; - public int mChargeableCount = 0; - private long count = 0L; - private long mStored = 0L; - private long mMax = 0L; - - public GT_MetaTileEntity_BasicBreaker(int aID, String aName, String aNameRegional, int aTier, String aDescription, int aSlotCount) { - super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription, new ITexture[0]); - } - - public GT_MetaTileEntity_BasicBreaker(String aName, int aTier, String aDescription, ITexture[][][] aTextures, int aSlotCount) { - super(aName, aTier, aSlotCount, aDescription, aTextures); - } - - public GT_MetaTileEntity_BasicBreaker(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, int aSlotCount) { - super(aName, aTier, aSlotCount, aDescription, aTextures); - } - - public String[] getDescription() { - final String[] desc = new String[6]; - int tTier = this.mTier; - desc[0] = "" + EnumChatFormatting.BOLD + "16 Fuse Slots"; - desc[1] = "Per each fuse, you may insert " + EnumChatFormatting.YELLOW + (GT_Values.V[tTier]) + EnumChatFormatting.GRAY + " EU/t"; - desc[2] = "However this " + EnumChatFormatting.ITALIC + EnumChatFormatting.RED + "MUST" + EnumChatFormatting.GRAY + " be in a single Amp"; - desc[3] = "This machine can accept upto a single amp of " + GT_Values.VN[Math.min(tTier + 2, 15)] + " as a result"; - desc[4] = "Breaker Loss: " + EnumChatFormatting.RED + "" + (GT_Values.V[tTier] / 16) + EnumChatFormatting.GRAY + " EU/t"; - desc[5] = CORE.GT_Tooltip; - return desc; - } - - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[2][17][]; - - for (byte i = -1; i < 16; ++i) { - rTextures[0][i + 1] = new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][i - + 1], this.mInventory.length > 4 ? BlockIcons.OVERLAYS_ENERGY_IN_MULTI[Math.min(12, mTier)] : BlockIcons.OVERLAYS_ENERGY_IN[Math.min(12, mTier)]}; - - rTextures[1][i + 1] = new ITexture[]{BlockIcons.MACHINE_CASINGS[this.mTier][i - + 1], this.mInventory.length > 4 ? BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] : BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier]}; - } - - return rTextures; - } - - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return this.mTextures[aSide == aFacing ? 1 : 0][aColorIndex + 1]; - } - - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_BasicBreaker(this.mName, this.mTier, this.mDescriptionArray, this.mTextures, this.mInventory.length); - } - - public boolean isSimpleMachine() { - return false; - } - - public boolean isElectric() { - return true; - } - - public boolean isValidSlot(int aIndex) { - return true; - } - - public boolean isFacingValid(byte aFacing) { - return true; - } - - public boolean isEnetInput() { - return true; - } - - public boolean isEnetOutput() { - return true; - } - - public boolean isInputFacing(byte aSide) { - return aSide != this.getBaseMetaTileEntity().getFrontFacing(); - } - - public boolean isOutputFacing(byte aSide) { - return aSide == this.getBaseMetaTileEntity().getFrontFacing(); - } - - public boolean isTeleporterCompatible() { - return false; - } - - public long getMinimumStoredEU() { - return GT_Values.V[this.mTier] * 16L * 16; - } - - public long maxEUStore() { - return GT_Values.V[this.mTier] * 64L * 16; - } - - public long maxEUInput() { - return GT_Values.V[this.mTier] * 16; - } - - public long maxEUOutput() { - return GT_Values.V[this.mTier]; - } - - public long maxAmperesIn() { - return 16; - } - - public long maxAmperesOut() { - return 16; - } - - public int rechargerSlotStartIndex() { - return 0; - } - - public int dechargerSlotStartIndex() { - return 0; - } - - public int rechargerSlotCount() { - return 0; - } - - public int dechargerSlotCount() { - return 0; - } - - public int getProgresstime() { - return (int) this.getBaseMetaTileEntity().getUniversalEnergyStored(); - } - - public int maxProgresstime() { - return (int) this.getBaseMetaTileEntity().getUniversalEnergyCapacity(); - } - - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - public void saveNBTData(NBTTagCompound aNBT) { - } - - public void loadNBTData(NBTTagCompound aNBT) { - } - - 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 GT_Container_4by4(aPlayerInventory, aBaseMetaTileEntity); - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_4by4(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); - } - - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (aBaseMetaTileEntity.isServerSide()) { - /*this.mCharge = aBaseMetaTileEntity.getStoredEU() / 2L > aBaseMetaTileEntity.getEUCapacity() / 3L; - this.mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3L; - this.mBatteryCount = 0; - this.mChargeableCount = 0; - ItemStack[] arg3 = this.mInventory; - int arg4 = arg3.length; - - for (int arg5 = 0; arg5 < arg4; ++arg5) { - ItemStack tStack = arg3[arg5]; - if (GT_ModHandler.isElectricItem(tStack, this.mTier)) { - if (GT_ModHandler.isChargerItem(tStack)) { - ++this.mBatteryCount; - } - - ++this.mChargeableCount; - } - }*/ - } - - } - - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return true; - } - - public int getInventoryStackLimit() { - return 1; - } - - public long[] getStoredEnergy() { - boolean scaleOverflow = false; - boolean storedOverflow = false; - long tScale = this.getBaseMetaTileEntity().getEUCapacity(); - long tStored = this.getBaseMetaTileEntity().getStoredEU(); - long tStep = 0L; - if (this.mInventory != null) { - ItemStack[] arg8 = this.mInventory; - int arg9 = arg8.length; - - for (int arg10 = 0; arg10 < arg9; ++arg10) { - ItemStack aStack = arg8[arg10]; - if (GT_ModHandler.isElectricItem(aStack)) { - if (aStack.getItem() instanceof GT_MetaBase_Item) { - Long[] stats = ((GT_MetaBase_Item) aStack.getItem()).getElectricStats(aStack); - if (stats != null) { - if (stats[0].longValue() > 4611686018427387903L) { - scaleOverflow = true; - } - - tScale += stats[0].longValue(); - tStep = ((GT_MetaBase_Item) aStack.getItem()).getRealCharge(aStack); - if (tStep > 4611686018427387903L) { - storedOverflow = true; - } - - tStored += tStep; - } - } - else if (aStack.getItem() instanceof IElectricItem) { - tStored += (long) ElectricItem.manager.getCharge(aStack); - tScale += (long) ((IElectricItem) aStack.getItem()).getMaxCharge(aStack); - } - } - } - } - - if (scaleOverflow) { - tScale = Long.MAX_VALUE; - } - - if (storedOverflow) { - tStored = Long.MAX_VALUE; - } - - return new long[]{tStored, tScale}; - } - - public String[] getInfoData() { - return new String[]{"Tile Type: " + this.getTileEntityBaseType()}; - } - - public boolean isGivingInformation() { - return true; - } - - public boolean doesExplode() { - return true; - } + public boolean mCharge = false; + public boolean mDecharge = false; + public int mBatteryCount = 0; + public int mChargeableCount = 0; + private long count = 0L; + private long mStored = 0L; + private long mMax = 0L; + + public GT_MetaTileEntity_BasicBreaker( + int aID, String aName, String aNameRegional, int aTier, String aDescription, int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription, new ITexture[0]); + } + + public GT_MetaTileEntity_BasicBreaker( + String aName, int aTier, String aDescription, ITexture[][][] aTextures, int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + public GT_MetaTileEntity_BasicBreaker( + String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + public String[] getDescription() { + final String[] desc = new String[6]; + int tTier = this.mTier; + desc[0] = "" + EnumChatFormatting.BOLD + "16 Fuse Slots"; + desc[1] = "Per each fuse, you may insert " + EnumChatFormatting.YELLOW + (GT_Values.V[tTier]) + + EnumChatFormatting.GRAY + " EU/t"; + desc[2] = "However this " + EnumChatFormatting.ITALIC + EnumChatFormatting.RED + "MUST" + + EnumChatFormatting.GRAY + " be in a single Amp"; + desc[3] = "This machine can accept upto a single amp of " + GT_Values.VN[Math.min(tTier + 2, 15)] + + " as a result"; + desc[4] = "Breaker Loss: " + EnumChatFormatting.RED + "" + (GT_Values.V[tTier] / 16) + EnumChatFormatting.GRAY + + " EU/t"; + desc[5] = CORE.GT_Tooltip; + return desc; + } + + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[2][17][]; + + for (byte i = -1; i < 16; ++i) { + rTextures[0][i + 1] = new ITexture[] { + BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], + this.mInventory.length > 4 + ? BlockIcons.OVERLAYS_ENERGY_IN_MULTI[Math.min(12, mTier)] + : BlockIcons.OVERLAYS_ENERGY_IN[Math.min(12, mTier)] + }; + + rTextures[1][i + 1] = new ITexture[] { + BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], + this.mInventory.length > 4 + ? BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] + : BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier] + }; + } + + return rTextures; + } + + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + return this.mTextures[aSide == aFacing ? 1 : 0][aColorIndex + 1]; + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_BasicBreaker( + this.mName, this.mTier, this.mDescriptionArray, this.mTextures, this.mInventory.length); + } + + public boolean isSimpleMachine() { + return false; + } + + public boolean isElectric() { + return true; + } + + public boolean isValidSlot(int aIndex) { + return true; + } + + public boolean isFacingValid(byte aFacing) { + return true; + } + + public boolean isEnetInput() { + return true; + } + + public boolean isEnetOutput() { + return true; + } + + public boolean isInputFacing(byte aSide) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + public boolean isOutputFacing(byte aSide) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + public boolean isTeleporterCompatible() { + return false; + } + + public long getMinimumStoredEU() { + return GT_Values.V[this.mTier] * 16L * 16; + } + + public long maxEUStore() { + return GT_Values.V[this.mTier] * 64L * 16; + } + + public long maxEUInput() { + return GT_Values.V[this.mTier] * 16; + } + + public long maxEUOutput() { + return GT_Values.V[this.mTier]; + } + + public long maxAmperesIn() { + return 16; + } + + public long maxAmperesOut() { + return 16; + } + + public int rechargerSlotStartIndex() { + return 0; + } + + public int dechargerSlotStartIndex() { + return 0; + } + + public int rechargerSlotCount() { + return 0; + } + + public int dechargerSlotCount() { + return 0; + } + + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyStored(); + } + + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity().getUniversalEnergyCapacity(); + } + + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + public void saveNBTData(NBTTagCompound aNBT) {} + + public void loadNBTData(NBTTagCompound aNBT) {} + + 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 GT_Container_4by4(aPlayerInventory, aBaseMetaTileEntity); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_4by4(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); + } + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + /*this.mCharge = aBaseMetaTileEntity.getStoredEU() / 2L > aBaseMetaTileEntity.getEUCapacity() / 3L; + this.mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3L; + this.mBatteryCount = 0; + this.mChargeableCount = 0; + ItemStack[] arg3 = this.mInventory; + int arg4 = arg3.length; + + for (int arg5 = 0; arg5 < arg4; ++arg5) { + ItemStack tStack = arg3[arg5]; + if (GT_ModHandler.isElectricItem(tStack, this.mTier)) { + if (GT_ModHandler.isChargerItem(tStack)) { + ++this.mBatteryCount; + } + + ++this.mChargeableCount; + } + }*/ + } + } + + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return true; + } + + public int getInventoryStackLimit() { + return 1; + } + + public long[] getStoredEnergy() { + boolean scaleOverflow = false; + boolean storedOverflow = false; + long tScale = this.getBaseMetaTileEntity().getEUCapacity(); + long tStored = this.getBaseMetaTileEntity().getStoredEU(); + long tStep = 0L; + if (this.mInventory != null) { + ItemStack[] arg8 = this.mInventory; + int arg9 = arg8.length; + + for (int arg10 = 0; arg10 < arg9; ++arg10) { + ItemStack aStack = arg8[arg10]; + if (GT_ModHandler.isElectricItem(aStack)) { + if (aStack.getItem() instanceof GT_MetaBase_Item) { + Long[] stats = ((GT_MetaBase_Item) aStack.getItem()).getElectricStats(aStack); + if (stats != null) { + if (stats[0].longValue() > 4611686018427387903L) { + scaleOverflow = true; + } + + tScale += stats[0].longValue(); + tStep = ((GT_MetaBase_Item) aStack.getItem()).getRealCharge(aStack); + if (tStep > 4611686018427387903L) { + storedOverflow = true; + } + + tStored += tStep; + } + } else if (aStack.getItem() instanceof IElectricItem) { + tStored += (long) ElectricItem.manager.getCharge(aStack); + tScale += (long) ((IElectricItem) aStack.getItem()).getMaxCharge(aStack); + } + } + } + } + + if (scaleOverflow) { + tScale = Long.MAX_VALUE; + } + + if (storedOverflow) { + tStored = Long.MAX_VALUE; + } + + return new long[] {tStored, tScale}; + } + + public String[] getInfoData() { + return new String[] {"Tile Type: " + this.getTileEntityBaseType()}; + } + + public boolean isGivingInformation() { + return true; + } + + public boolean doesExplode() { + return true; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GTPP_Recipe.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GTPP_Recipe.java index 18665538d0..cf92bdc0ba 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GTPP_Recipe.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GTPP_Recipe.java @@ -5,34 +5,120 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.util.GT_Recipe.GT_Recipe_Map; public class GT_MetaTileEntity_BasicMachine_GTPP_Recipe extends GT_MetaTileEntity_BasicMachine_GT_Recipe { - - public GT_MetaTileEntity_BasicMachine_GTPP_Recipe(int aID, String aName, String aNameRegional, int aTier, - String aDescription, GT_Recipe_Map aRecipes, int aInputSlots, int aOutputSlots, int aTankCapacity, - int aGUIParameterA, int aGUIParameterB, String aGUIName, String aSound, boolean aSharedTank, - boolean aRequiresFluidForFiltering, int aSpecialEffect, String aOverlays, Object[] aRecipe) { - super(aID, aName, aNameRegional, aTier, aDescription, aRecipes, aInputSlots, aOutputSlots, aTankCapacity, - aGUIParameterA, aGUIParameterB, aGUIName, aSound, aSharedTank, aRequiresFluidForFiltering, aSpecialEffect, - aOverlays, aRecipe); - } - public GT_MetaTileEntity_BasicMachine_GTPP_Recipe(String aName, int aTier, String aDescription, - GT_Recipe_Map aRecipes, int aInputSlots, int aOutputSlots, int aTankCapacity, int aAmperage, - int aGUIParameterA, int aGUIParameterB, ITexture[][][] aTextures, String aGUIName, String aNEIName, - String aSound, boolean aSharedTank, boolean aRequiresFluidForFiltering, int aSpecialEffect) { - super(aName, aTier, aDescription, aRecipes, aInputSlots, aOutputSlots, aTankCapacity, aAmperage, aGUIParameterA, - aGUIParameterB, aTextures, aGUIName, aNEIName, aSound, aSharedTank, aRequiresFluidForFiltering, aSpecialEffect); - } - - public GT_MetaTileEntity_BasicMachine_GTPP_Recipe(String aName, int aTier, String[] aDescription, - GT_Recipe_Map aRecipes, int aInputSlots, int aOutputSlots, int aTankCapacity, int aAmperage, - int aGUIParameterA, int aGUIParameterB, ITexture[][][] aTextures, String aGUIName, String aNEIName, - String aSound, boolean aSharedTank, boolean aRequiresFluidForFiltering, int aSpecialEffect) { - super(aName, aTier, aDescription[0], aRecipes, aInputSlots, aOutputSlots, aTankCapacity, aAmperage, aGUIParameterA, - aGUIParameterB, aTextures, aGUIName, aNEIName, aSound, aSharedTank, aRequiresFluidForFiltering, aSpecialEffect); - } + public GT_MetaTileEntity_BasicMachine_GTPP_Recipe( + int aID, + String aName, + String aNameRegional, + int aTier, + String aDescription, + GT_Recipe_Map aRecipes, + int aInputSlots, + int aOutputSlots, + int aTankCapacity, + int aGUIParameterA, + int aGUIParameterB, + String aGUIName, + String aSound, + boolean aSharedTank, + boolean aRequiresFluidForFiltering, + int aSpecialEffect, + String aOverlays, + Object[] aRecipe) { + super( + aID, + aName, + aNameRegional, + aTier, + aDescription, + aRecipes, + aInputSlots, + aOutputSlots, + aTankCapacity, + aGUIParameterA, + aGUIParameterB, + aGUIName, + aSound, + aSharedTank, + aRequiresFluidForFiltering, + aSpecialEffect, + aOverlays, + aRecipe); + } - - - + public GT_MetaTileEntity_BasicMachine_GTPP_Recipe( + String aName, + int aTier, + String aDescription, + GT_Recipe_Map aRecipes, + int aInputSlots, + int aOutputSlots, + int aTankCapacity, + int aAmperage, + int aGUIParameterA, + int aGUIParameterB, + ITexture[][][] aTextures, + String aGUIName, + String aNEIName, + String aSound, + boolean aSharedTank, + boolean aRequiresFluidForFiltering, + int aSpecialEffect) { + super( + aName, + aTier, + aDescription, + aRecipes, + aInputSlots, + aOutputSlots, + aTankCapacity, + aAmperage, + aGUIParameterA, + aGUIParameterB, + aTextures, + aGUIName, + aNEIName, + aSound, + aSharedTank, + aRequiresFluidForFiltering, + aSpecialEffect); + } + public GT_MetaTileEntity_BasicMachine_GTPP_Recipe( + String aName, + int aTier, + String[] aDescription, + GT_Recipe_Map aRecipes, + int aInputSlots, + int aOutputSlots, + int aTankCapacity, + int aAmperage, + int aGUIParameterA, + int aGUIParameterB, + ITexture[][][] aTextures, + String aGUIName, + String aNEIName, + String aSound, + boolean aSharedTank, + boolean aRequiresFluidForFiltering, + int aSpecialEffect) { + super( + aName, + aTier, + aDescription[0], + aRecipes, + aInputSlots, + aOutputSlots, + aTankCapacity, + aAmperage, + aGUIParameterA, + aGUIParameterB, + aTextures, + aGUIName, + aNEIName, + aSound, + aSharedTank, + aRequiresFluidForFiltering, + aSpecialEffect); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Dehydrator.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Dehydrator.java index aebf188fc0..02f0a3ff40 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Dehydrator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Dehydrator.java @@ -19,51 +19,105 @@ import gtPlusPlus.core.lib.CORE; @SuppressWarnings("deprecation") public class GT_MetaTileEntity_Dehydrator extends GT_MetaTileEntity_BasicMachine_GT_Recipe { - private static final CustomIcon[] sDehydratorOverlays = new CustomIcon[10]; - static { - sDehydratorOverlays[0] = new CustomIcon("basicmachines/microwave/OVERLAY_FRONT"); - sDehydratorOverlays[2] = new CustomIcon("basicmachines/plasma_arc_furnace/OVERLAY_BOTTOM"); - sDehydratorOverlays[3] = new CustomIcon("basicmachines/fluid_heater/OVERLAY_SIDE"); - sDehydratorOverlays[4] = new CustomIcon("basicmachines/chemical_bath/OVERLAY_FRONT"); - sDehydratorOverlays[5] = new CustomIcon("basicmachines/microwave/OVERLAY_FRONT_ACTIVE"); - sDehydratorOverlays[7] = new CustomIcon("basicmachines/plasma_arc_furnace/OVERLAY_BOTTOM_ACTIVE"); - sDehydratorOverlays[8] = new CustomIcon("basicmachines/fluid_heater/OVERLAY_SIDE_ACTIVE"); - sDehydratorOverlays[9] = new CustomIcon("basicmachines/chemical_bath/OVERLAY_FRONT_ACTIVE"); - //3 8 - } - + private static final CustomIcon[] sDehydratorOverlays = new CustomIcon[10]; + + static { + sDehydratorOverlays[0] = new CustomIcon("basicmachines/microwave/OVERLAY_FRONT"); + sDehydratorOverlays[2] = new CustomIcon("basicmachines/plasma_arc_furnace/OVERLAY_BOTTOM"); + sDehydratorOverlays[3] = new CustomIcon("basicmachines/fluid_heater/OVERLAY_SIDE"); + sDehydratorOverlays[4] = new CustomIcon("basicmachines/chemical_bath/OVERLAY_FRONT"); + sDehydratorOverlays[5] = new CustomIcon("basicmachines/microwave/OVERLAY_FRONT_ACTIVE"); + sDehydratorOverlays[7] = new CustomIcon("basicmachines/plasma_arc_furnace/OVERLAY_BOTTOM_ACTIVE"); + sDehydratorOverlays[8] = new CustomIcon("basicmachines/fluid_heater/OVERLAY_SIDE_ACTIVE"); + sDehydratorOverlays[9] = new CustomIcon("basicmachines/chemical_bath/OVERLAY_FRONT_ACTIVE"); + // 3 8 + } + private GT_Recipe_Map xRecipes; - private int xTankCapacity; + private int xTankCapacity; + + public GT_MetaTileEntity_Dehydrator( + int aID, String aName, String aNameRegional, int aTier, String aDescription, int aTankCapacity) { + super( + aID, + aName, + aNameRegional, + aTier, + aDescription, + GTPP_Recipe.GTPP_Recipe_Map.sChemicalDehydratorRecipes, + 2, + 9, + aTankCapacity, + 2, + 5, + "Dehydrator.png", + "UNBOXINATOR", + false, + false, + 0, + "", + null); + xRecipes = GTPP_Recipe.GTPP_Recipe_Map.sChemicalDehydratorRecipes; + xTankCapacity = aTankCapacity; + } - public GT_MetaTileEntity_Dehydrator(int aID, String aName, String aNameRegional, int aTier, String aDescription, int aTankCapacity) { - super(aID, aName, aNameRegional, aTier, aDescription, GTPP_Recipe.GTPP_Recipe_Map.sChemicalDehydratorRecipes, 2, 9, aTankCapacity, 2, 5, "Dehydrator.png", "UNBOXINATOR", false, false, 0, "", null); - xRecipes = GTPP_Recipe.GTPP_Recipe_Map.sChemicalDehydratorRecipes; - xTankCapacity = aTankCapacity; - } + public GT_MetaTileEntity_Dehydrator( + String aName, + int aTier, + String[] aDescription, + GT_Recipe.GT_Recipe_Map aRecipes, + int aTankCapacity, + int aAmperage, + ITexture[][][] aTextures, + String aGUIName, + String aNEIName) { + super( + aName, + aTier, + aDescription, + aRecipes, + 2, + 9, + aTankCapacity, + aAmperage, + 2, + 5, + aTextures, + aGUIName, + aNEIName, + "", + false, + false, + 0); + } - public GT_MetaTileEntity_Dehydrator(String aName, int aTier, String[] aDescription, GT_Recipe.GT_Recipe_Map aRecipes, int aTankCapacity, int aAmperage, ITexture[][][] aTextures, String aGUIName, String aNEIName) { - super(aName, aTier, aDescription, aRecipes, 2, 9, aTankCapacity, aAmperage, 2, 5, aTextures, aGUIName, aNEIName, "", false, false, 0); - + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Dehydrator( + this.mName, + this.mTier, + this.mDescriptionArray, + this.xRecipes, + this.xTankCapacity, + this.mAmperage, + this.mTextures, + this.mGUIName, + this.mNEIName); } @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Dehydrator(this.mName, this.mTier, this.mDescriptionArray, this.xRecipes, this.xTankCapacity, this.mAmperage, this.mTextures, this.mGUIName, this.mNEIName); + public String[] getDescription() { + String[] S = super.getDescription(); + final String[] desc = new String[S.length + 1]; + System.arraycopy(S, 0, desc, 0, S.length); + desc[S.length] = CORE.GT_Tooltip; + return desc; } - - @Override - public String[] getDescription() { - String[] S = super.getDescription(); - final String[] desc = new String[S.length + 1]; - System.arraycopy(S, 0, desc, 0, S.length); - desc[S.length] = CORE.GT_Tooltip; - return desc; - } - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[15][17][]; - for (byte i = -1; i < 16; i++) { + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[15][17][]; + for (byte i = -1; i < 16; i++) { rTextures[0][i + 1] = getSideFacingActive(i); rTextures[1][i + 1] = getSideFacingInactive(i); rTextures[2][i + 1] = getFrontFacingActive(i); @@ -71,93 +125,113 @@ public class GT_MetaTileEntity_Dehydrator extends GT_MetaTileEntity_BasicMachine rTextures[4][i + 1] = getTopFacingActive(i); rTextures[5][i + 1] = getTopFacingInactive(i); rTextures[6][i + 1] = getBottomFacingActive(i); - rTextures[7][i + 1] = getBottomFacingInactive(i); + rTextures[7][i + 1] = getBottomFacingInactive(i); rTextures[8][i + 1] = getBottomFacingPipeActive(i); rTextures[9][i + 1] = getBottomFacingPipeInactive(i); rTextures[10][i + 1] = getTopFacingPipeActive(i); rTextures[11][i + 1] = getTopFacingPipeInactive(i); rTextures[12][i + 1] = getSideFacingPipeActive(i); rTextures[13][i + 1] = getSideFacingPipeInactive(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 super.getTexture(aBaseMetaTileEntity, aSide, aFacing, aColorIndex, aActive, 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 ITexture[] getFrontFacingInactive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[0])}; - } - - @Override - public ITexture[] getBottomFacingInactive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[2])}; - } - - @Override - public ITexture[] getTopFacingInactive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[3])}; - } - - @Override - public ITexture[] getSideFacingInactive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[4])}; - } - - @Override - public ITexture[] getFrontFacingActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[5])}; - } - - @Override - public ITexture[] getBottomFacingActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[7])}; - } - - @Override - public ITexture[] getTopFacingActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[8])}; - } - - @Override - public ITexture[] getSideFacingActive(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[9])}; - } - - @Override + } + 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 super.getTexture(aBaseMetaTileEntity, aSide, aFacing, aColorIndex, aActive, 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 ITexture[] getFrontFacingInactive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[0]) + }; + } + + @Override + public ITexture[] getBottomFacingInactive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[2]) + }; + } + + @Override + public ITexture[] getTopFacingInactive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[3]) + }; + } + + @Override + public ITexture[] getSideFacingInactive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[4]) + }; + } + + @Override + public ITexture[] getFrontFacingActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[5]) + }; + } + + @Override + public ITexture[] getBottomFacingActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[7]) + }; + } + + @Override + public ITexture[] getTopFacingActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[8]) + }; + } + + @Override + public ITexture[] getSideFacingActive(final byte aColor) { + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(sDehydratorOverlays[9]) + }; + } + + @Override public ITexture[] getBottomFacingPipeActive(byte aColor) { - return new ITexture[]{MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; + return new ITexture[] {MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; } - @Override + @Override public ITexture[] getBottomFacingPipeInactive(byte aColor) { - return new ITexture[]{MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; + return new ITexture[] {MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; } - @Override + @Override public ITexture[] getTopFacingPipeActive(byte aColor) { - return new ITexture[]{MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; + return new ITexture[] {MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; } - @Override + @Override public ITexture[] getTopFacingPipeInactive(byte aColor) { - return new ITexture[]{MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; + return new ITexture[] {MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; } - @Override + @Override public ITexture[] getSideFacingPipeActive(byte aColor) { - return new ITexture[]{MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; + return new ITexture[] {MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; } - @Override + @Override public ITexture[] getSideFacingPipeInactive(byte aColor) { - return new ITexture[]{MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; - } - + return new ITexture[] {MACHINE_CASINGS[mTier][aColor + 1], TextureFactory.of(OVERLAY_PIPE_OUT)}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_DeluxeMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_DeluxeMachine.java index 79238240d2..007e6a1761 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_DeluxeMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_DeluxeMachine.java @@ -2,14 +2,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.V; -import java.util.Arrays; - -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.ItemList; import gregtech.api.enums.Textures; @@ -23,9 +15,14 @@ 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 gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.random.XSTR; +import java.util.Arrays; +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 net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -41,14 +38,20 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ /** * return values for checkRecipe() */ - protected static final int - DID_NOT_FIND_RECIPE = 0, + protected static final int DID_NOT_FIND_RECIPE = 0, FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS = 1, FOUND_AND_SUCCESSFULLY_USED_RECIPE = 2; + public static final int OTHER_SLOT_COUNT = 4; public final ItemStack[] mOutputItems; public final int mInputSlotCount, mAmperage; - public boolean mAllowInputFromOutputSide = false, mFluidTransfer = false, mItemTransfer = false, mHasBeenUpdated = false, mStuttering = false, mCharge = false, mDecharge = false; + public boolean mAllowInputFromOutputSide = false, + mFluidTransfer = false, + mItemTransfer = false, + mHasBeenUpdated = false, + mStuttering = false, + mCharge = false, + mDecharge = false; public int mMainFacing = -1, mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mOutputBlocked = 0; public FluidStack mOutputFluid; public String mGUIName = "", mNEIName = ""; @@ -56,6 +59,7 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ * Contains the Recipe which has been previously used, or null if there was no previous Recipe, which could have been buffered */ protected GT_Recipe mLastRecipe = null; + private FluidStack mFluidOut; /** @@ -75,8 +79,26 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ * 12 = SideFacingPipeActive * 13 = SideFacingPipeInactive */ - public GT_MetaTileEntity_DeluxeMachine(int aID, String aName, String aNameRegional, int aTier, int aAmperage, String aDescription, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName, ITexture... aOverlays) { - super(aID, aName, aNameRegional, aTier, OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, aDescription, aOverlays); + public GT_MetaTileEntity_DeluxeMachine( + int aID, + String aName, + String aNameRegional, + int aTier, + int aAmperage, + String aDescription, + int aInputSlotCount, + int aOutputSlotCount, + String aGUIName, + String aNEIName, + ITexture... aOverlays) { + super( + aID, + aName, + aNameRegional, + aTier, + OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, + aDescription, + aOverlays); mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; mAmperage = aAmperage; @@ -84,7 +106,16 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ mNEIName = aNEIName; } - public GT_MetaTileEntity_DeluxeMachine(String aName, int aTier, int aAmperage, String aDescription, ITexture[][][] aTextures, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName) { + public GT_MetaTileEntity_DeluxeMachine( + String aName, + int aTier, + int aAmperage, + String aDescription, + ITexture[][][] aTextures, + int aInputSlotCount, + int aOutputSlotCount, + String aGUIName, + String aNEIName) { super(aName, aTier, OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, aDescription, aTextures); mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; @@ -92,15 +123,15 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ mGUIName = aGUIName; mNEIName = aNEIName; } - - public boolean setMainFacing(byte aDirection){ - mMainFacing = aDirection; - if(getBaseMetaTileEntity().getFrontFacing() == mMainFacing){ - getBaseMetaTileEntity().setFrontFacing(GT_Utility.getOppositeSide(aDirection)); - } + + public boolean setMainFacing(byte aDirection) { + mMainFacing = aDirection; + if (getBaseMetaTileEntity().getFrontFacing() == mMainFacing) { + getBaseMetaTileEntity().setFrontFacing(GT_Utility.getOppositeSide(aDirection)); + } onFacingChange(); onMachineBlockUpdate(); - return true; + return true; } @Override @@ -109,10 +140,12 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ aTextures = Arrays.copyOf(aTextures, 14); for (int i = 0; i < aTextures.length; i++) - if (aTextures[i] != null) for (byte c = -1; c < 16; c++) { - if (rTextures[i][c + 1] == null) - rTextures[i][c + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][c + 1], aTextures[i]}; - } + if (aTextures[i] != null) + for (byte c = -1; c < 16; c++) { + if (rTextures[i][c + 1] == null) + rTextures[i][c + 1] = + new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][c + 1], aTextures[i]}; + } for (byte c = -1; c < 16; c++) { if (rTextures[0][c + 1] == null) rTextures[0][c + 1] = getSideFacingActive(c); @@ -134,8 +167,28 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ } @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return mTextures[mMainFacing < 2 ? aSide == aFacing ? aActive ? 2 : 3 : aSide == 0 ? aActive ? 6 : 7 : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1 : aSide == mMainFacing ? aActive ? 2 : 3 : (showPipeFacing() && aSide == aFacing) ? aSide == 0 ? aActive ? 8 : 9 : aSide == 1 ? aActive ? 10 : 11 : aActive ? 12 : 13 : aSide == 0 ? aActive ? 6 : 7 : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1][aColorIndex + 1]; + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + return mTextures[ + mMainFacing < 2 + ? aSide == aFacing + ? aActive ? 2 : 3 + : aSide == 0 ? aActive ? 6 : 7 : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1 + : aSide == mMainFacing + ? aActive ? 2 : 3 + : (showPipeFacing() && aSide == aFacing) + ? aSide == 0 + ? aActive ? 8 : 9 + : aSide == 1 ? aActive ? 10 : 11 : aActive ? 12 : 13 + : aSide == 0 + ? aActive ? 6 : 7 + : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1][ + aColorIndex + 1]; } @Override @@ -160,7 +213,9 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ @Override public boolean isValidSlot(int aIndex) { - return aIndex > 0 && super.isValidSlot(aIndex) && aIndex != OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length; + return aIndex > 0 + && super.isValidSlot(aIndex) + && aIndex != OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length; } @Override @@ -190,7 +245,9 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ @Override public boolean isLiquidInput(byte aSide) { - return aSide != mMainFacing && (mAllowInputFromOutputSide || aSide != getBaseMetaTileEntity().getFrontFacing()); + return aSide != mMainFacing + && (mAllowInputFromOutputSide + || aSide != getBaseMetaTileEntity().getFrontFacing()); } @Override @@ -281,7 +338,8 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ @Override public boolean isFluidInputAllowed(FluidStack aFluid) { - return getFillableStack() != null || (getRecipeList() != null && getRecipeList().containsInput(aFluid)); + return getFillableStack() != null + || (getRecipeList() != null && getRecipeList().containsInput(aFluid)); } @Override @@ -338,17 +396,17 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { if (aBaseMetaTileEntity.isClientSide()) return true; - if(!false) { - aBaseMetaTileEntity.openGUI(aPlayer); - return true; + if (!false) { + aBaseMetaTileEntity.openGUI(aPlayer); + return true; } - for(byte i=0;i < 6; i++){ - if(aBaseMetaTileEntity.getAirAtSide(i)){ - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } + for (byte i = 0; i < 6; i++) { + if (aBaseMetaTileEntity.getAirAtSide(i)) { + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } } - GT_Utility.sendChatToPlayer(aPlayer,"No free Side!"); + GT_Utility.sendChatToPlayer(aPlayer, "No free Side!"); return true; } @@ -359,7 +417,14 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), mGUIName, GT_Utility.isStringValid(mNEIName) ? mNEIName : getRecipeList() != null ? getRecipeList().mUnlocalizedName : ""); + return new GT_GUIContainer_BasicMachine( + aPlayerInventory, + aBaseMetaTileEntity, + getLocalName(), + mGUIName, + GT_Utility.isStringValid(mNEIName) + ? mNEIName + : getRecipeList() != null ? getRecipeList().mUnlocalizedName : ""); } @Override @@ -408,8 +473,8 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ super.onPostTick(aBaseMetaTileEntity, aTick); if (aBaseMetaTileEntity.isServerSide()) { - - //Utils.LOG_WARNING("Ticking Tank."); + + // Utils.LOG_WARNING("Ticking Tank."); mCharge = aBaseMetaTileEntity.getStoredEU() / 2 > aBaseMetaTileEntity.getEUCapacity() / 3; mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3; @@ -423,8 +488,8 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ if (++mProgresstime >= mMaxProgresstime) { for (int i = 0; i < mOutputItems.length; i++) for (int j = 0; j < mOutputItems.length; j++) - if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot() + ((j + i) % mOutputItems.length), mOutputItems[i])) - break; + if (aBaseMetaTileEntity.addStackToSlot( + getOutputSlot() + ((j + i) % mOutputItems.length), mOutputItems[i])) break; if (mOutputFluid != null) if (getDrainableStack() == null) setDrainableStack(mOutputFluid.copy()); else if (mOutputFluid.isFluidEqual(getDrainableStack())) @@ -440,7 +505,15 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ } if (mProgresstime > 5) mStuttering = false; XSTR aXSTR = new XSTR(); - if(false && aXSTR.nextInt(5000)==0)GT_Utility.sendSoundToPlayers(aBaseMetaTileEntity.getWorld(), GregTech_API.sSoundList.get(5), 10.0F, -1.0F, aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getYCoord(),aBaseMetaTileEntity.getZCoord()); + if (false && aXSTR.nextInt(5000) == 0) + GT_Utility.sendSoundToPlayers( + aBaseMetaTileEntity.getWorld(), + GregTech_API.sSoundList.get(5), + 10.0F, + -1.0F, + aBaseMetaTileEntity.getXCoord(), + aBaseMetaTileEntity.getYCoord(), + aBaseMetaTileEntity.getZCoord()); } else { if (!mStuttering) { stutterProcess(); @@ -455,46 +528,80 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ boolean tRemovedOutputFluid = false; Logger.WARNING("R0"); - if (doesAutoOutputFluids() && getDrainableStack() != null && aBaseMetaTileEntity.getFrontFacing() != mMainFacing && (tSucceeded || aTick % 20 == 0)) { + if (doesAutoOutputFluids() + && getDrainableStack() != null + && aBaseMetaTileEntity.getFrontFacing() != mMainFacing + && (tSucceeded || aTick % 20 == 0)) { IFluidHandler tTank = aBaseMetaTileEntity.getITankContainerAtSide(aBaseMetaTileEntity.getFrontFacing()); if (tTank != null) { FluidStack tDrained = drain(1000, false); if (tDrained != null) { - int tFilledAmount = tTank.fill(ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tDrained, false); + int tFilledAmount = tTank.fill( + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tDrained, false); if (tFilledAmount > 0) - tTank.fill(ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), drain(tFilledAmount, true), true); + tTank.fill( + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), + drain(tFilledAmount, true), + true); } } if (getDrainableStack() == null) tRemovedOutputFluid = true; } - if (doesAutoOutput() && !isOutputEmpty() && aBaseMetaTileEntity.getFrontFacing() != mMainFacing && (tSucceeded || mOutputBlocked % 300 == 1 || aBaseMetaTileEntity.hasInventoryBeenModified() || aTick % 600 == 0)) { + if (doesAutoOutput() + && !isOutputEmpty() + && aBaseMetaTileEntity.getFrontFacing() != mMainFacing + && (tSucceeded + || mOutputBlocked % 300 == 1 + || aBaseMetaTileEntity.hasInventoryBeenModified() + || aTick % 600 == 0)) { TileEntity tTileEntity2 = aBaseMetaTileEntity.getTileEntityAtSide(aBaseMetaTileEntity.getFrontFacing()); - for (int i = 0, tCosts = 1; i < mOutputItems.length && tCosts > 0 && aBaseMetaTileEntity.isUniversalEnergyStored(128); i++) { - tCosts = GT_Utility.moveOneItemStack(aBaseMetaTileEntity, tTileEntity2, aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + for (int i = 0, tCosts = 1; + i < mOutputItems.length && tCosts > 0 && aBaseMetaTileEntity.isUniversalEnergyStored(128); + i++) { + tCosts = GT_Utility.moveOneItemStack( + aBaseMetaTileEntity, + tTileEntity2, + aBaseMetaTileEntity.getFrontFacing(), + aBaseMetaTileEntity.getBackFacing(), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); if (tCosts > 0) aBaseMetaTileEntity.decreaseStoredEnergyUnits(tCosts, true); } } - if (mOutputBlocked != 0) if (isOutputEmpty()) mOutputBlocked = 0; - else mOutputBlocked++; + if (mOutputBlocked != 0) + if (isOutputEmpty()) mOutputBlocked = 0; + else mOutputBlocked++; Logger.WARNING("R1"); if (allowToCheckRecipe()) { Logger.WARNING("R2--------------------------------------------------"); - Logger.WARNING("R2: (mMaxProgresstime <= 0 && aBaseMetaTileEntity.isAllowedToWork() && (tRemovedOutputFluid || tSucceeded || aBaseMetaTileEntity.hasInventoryBeenModified() || aTick % 600 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) && hasEnoughEnergyToCheckRecipe())"); + Logger.WARNING( + "R2: (mMaxProgresstime <= 0 && aBaseMetaTileEntity.isAllowedToWork() && (tRemovedOutputFluid || tSucceeded || aBaseMetaTileEntity.hasInventoryBeenModified() || aTick % 600 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) && hasEnoughEnergyToCheckRecipe())"); Logger.WARNING("R2--------------------------------------------------"); - Logger.WARNING("R2-mMaxProgresstime: "+mMaxProgresstime); - Logger.WARNING("R2-isAllowedToWork(): "+aBaseMetaTileEntity.isAllowedToWork()); + Logger.WARNING("R2-mMaxProgresstime: " + mMaxProgresstime); + Logger.WARNING("R2-isAllowedToWork(): " + aBaseMetaTileEntity.isAllowedToWork()); Logger.WARNING("R2--------------------------------------------------"); - Logger.WARNING("R2-tRemovedOutputFluid: "+tRemovedOutputFluid); - Logger.WARNING("R2-tSucceeded: "+tSucceeded); - Logger.WARNING("R2-hasInventoryBeenModified(): "+aBaseMetaTileEntity.hasInventoryBeenModified()); - Logger.WARNING("R2-(aTick % 600 == 0): "+(aTick % 600 == 0)); - Logger.WARNING("R2-hasWorkJustBeenEnabled(): "+aBaseMetaTileEntity.hasWorkJustBeenEnabled()); + Logger.WARNING("R2-tRemovedOutputFluid: " + tRemovedOutputFluid); + Logger.WARNING("R2-tSucceeded: " + tSucceeded); + Logger.WARNING("R2-hasInventoryBeenModified(): " + aBaseMetaTileEntity.hasInventoryBeenModified()); + Logger.WARNING("R2-(aTick % 600 == 0): " + (aTick % 600 == 0)); + Logger.WARNING("R2-hasWorkJustBeenEnabled(): " + aBaseMetaTileEntity.hasWorkJustBeenEnabled()); Logger.WARNING("R2--------------------------------------------------"); - Logger.WARNING("R2-hasEnoughEnergyToCheckRecipe(): "+hasEnoughEnergyToCheckRecipe()); + Logger.WARNING("R2-hasEnoughEnergyToCheckRecipe(): " + hasEnoughEnergyToCheckRecipe()); Logger.WARNING("R2--------------------------------------------------"); - if (mMaxProgresstime <= 0 && aBaseMetaTileEntity.isAllowedToWork() && (tRemovedOutputFluid || tSucceeded || aBaseMetaTileEntity.hasInventoryBeenModified() || aTick % 600 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) && hasEnoughEnergyToCheckRecipe()) { + if (mMaxProgresstime <= 0 + && aBaseMetaTileEntity.isAllowedToWork() + && (tRemovedOutputFluid + || tSucceeded + || aBaseMetaTileEntity.hasInventoryBeenModified() + || aTick % 600 == 0 + || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) + && hasEnoughEnergyToCheckRecipe()) { Logger.WARNING("R3"); if (checkRecipe() == 2) { if (mInventory[3] != null && mInventory[3].stackSize <= 0) mInventory[3] = null; @@ -534,7 +641,7 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ } if (mMainFacing >= 2 && !mHasBeenUpdated) { mHasBeenUpdated = true; - //getBaseMetaTileEntity().setFrontFacing(getBaseMetaTileEntity().getBackFacing()); + // getBaseMetaTileEntity().setFrontFacing(getBaseMetaTileEntity().getBackFacing()); } if (displaysInputFluid()) { @@ -543,7 +650,8 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ if (ItemList.Display_Fluid.isStackEqual(mInventory[tDisplayStackSlot], true, true)) mInventory[tDisplayStackSlot] = null; } else { - mInventory[tDisplayStackSlot] = GT_Utility.getFluidDisplayStack(getFillableStack(), displaysStackSize()); + mInventory[tDisplayStackSlot] = + GT_Utility.getFluidDisplayStack(getFillableStack(), displaysStackSize()); } } } @@ -589,14 +697,20 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ } protected boolean canOutput(GT_Recipe aRecipe) { - return aRecipe != null && (aRecipe.mNeedsEmptyOutput ? isOutputEmpty() && getDrainableStack() == null : canOutput(aRecipe.getFluidOutput(0)) && canOutput(aRecipe.mOutputs)); + return aRecipe != null + && (aRecipe.mNeedsEmptyOutput + ? isOutputEmpty() && getDrainableStack() == null + : canOutput(aRecipe.getFluidOutput(0)) && canOutput(aRecipe.mOutputs)); } protected boolean canOutput(ItemStack... aOutputs) { if (aOutputs == null) return true; ItemStack[] tOutputSlots = getAllOutputs(); for (int i = 0; i < tOutputSlots.length && i < aOutputs.length; i++) - if (tOutputSlots[i] != null && aOutputs[i] != null && (!GT_Utility.areStacksEqual(tOutputSlots[i], aOutputs[i], false) || tOutputSlots[i].stackSize + aOutputs[i].stackSize > tOutputSlots[i].getMaxStackSize())) { + if (tOutputSlots[i] != null + && aOutputs[i] != null + && (!GT_Utility.areStacksEqual(tOutputSlots[i], aOutputs[i], false) + || tOutputSlots[i].stackSize + aOutputs[i].stackSize > tOutputSlots[i].getMaxStackSize())) { mOutputBlocked++; return false; } @@ -604,7 +718,11 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ } protected boolean canOutput(FluidStack aOutput) { - return getDrainableStack() == null || aOutput == null || (getDrainableStack().isFluidEqual(aOutput) && (getDrainableStack().amount <= 0 || getDrainableStack().amount + aOutput.amount <= getCapacity())); + return getDrainableStack() == null + || aOutput == null + || (getDrainableStack().isFluidEqual(aOutput) + && (getDrainableStack().amount <= 0 + || getDrainableStack().amount + aOutput.amount <= getCapacity())); } protected ItemStack getInputAt(int aIndex) { @@ -704,13 +822,15 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ @Override public String[] getInfoData() { - return new String[]{ - mNEIName, - "Progress:", (mProgresstime / 20) + " secs", - (mMaxProgresstime / 20) + " secs", - "Stored Energy:", - getBaseMetaTileEntity().getStoredEU() + "EU", - getBaseMetaTileEntity().getEUCapacity() + "EU"}; + return new String[] { + mNEIName, + "Progress:", + (mProgresstime / 20) + " secs", + (mMaxProgresstime / 20) + " secs", + "Stored Energy:", + getBaseMetaTileEntity().getStoredEU() + "EU", + getBaseMetaTileEntity().getEUCapacity() + "EU" + }; } @Override @@ -722,13 +842,19 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (aSide == getBaseMetaTileEntity().getFrontFacing() || aSide == mMainFacing) { mAllowInputFromOutputSide = !mAllowInputFromOutputSide; - GT_Utility.sendChatToPlayer(aPlayer, mAllowInputFromOutputSide ? ("Input from Output Side allowed") : ("Input from Output Side forbidden")); + GT_Utility.sendChatToPlayer( + aPlayer, + mAllowInputFromOutputSide + ? ("Input from Output Side allowed") + : ("Input from Output Side forbidden")); } } @Override public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { - return (aSide != mMainFacing || GregTech_API.getCoverBehavior(aCoverID.toStack()).isGUIClickable(aSide, GT_Utility.stackToInt(aCoverID.toStack()), 0, getBaseMetaTileEntity())); + return (aSide != mMainFacing + || GregTech_API.getCoverBehavior(aCoverID.toStack()) + .isGUIClickable(aSide, GT_Utility.stackToInt(aCoverID.toStack()), 0, getBaseMetaTileEntity())); } @Override @@ -738,8 +864,10 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ @Override public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - if (aSide == mMainFacing || aIndex < getInputSlot() || aIndex >= getInputSlot() + mInputSlotCount || (!mAllowInputFromOutputSide && aSide == aBaseMetaTileEntity.getFrontFacing())) - return false; + if (aSide == mMainFacing + || aIndex < getInputSlot() + || aIndex >= getInputSlot() + mInputSlotCount + || (!mAllowInputFromOutputSide && aSide == aBaseMetaTileEntity.getFrontFacing())) return false; for (int i = getInputSlot(), j = i + mInputSlotCount; i < j; i++) if (GT_Utility.areStacksEqual(GT_OreDictUnificator.get(aStack), mInventory[i])) return i == aIndex; return true; @@ -765,98 +893,123 @@ public abstract class GT_MetaTileEntity_DeluxeMachine extends GT_MetaTileEntity_ return checkRecipe(false); } - public static boolean isValidForLowGravity(GT_Recipe tRecipe, int dimId){ - return //TODO check or get a better solution - DimensionManager.getProvider(dimId).getClass().getName().contains("Orbit") || - DimensionManager.getProvider(dimId).getClass().getName().endsWith("Space") || - DimensionManager.getProvider(dimId).getClass().getName().endsWith("Asteroids") || - DimensionManager.getProvider(dimId).getClass().getName().endsWith("SS") || - DimensionManager.getProvider(dimId).getClass().getName().contains("SpaceStation"); + public static boolean isValidForLowGravity(GT_Recipe tRecipe, int dimId) { + return // TODO check or get a better solution + DimensionManager.getProvider(dimId).getClass().getName().contains("Orbit") + || DimensionManager.getProvider(dimId).getClass().getName().endsWith("Space") + || DimensionManager.getProvider(dimId).getClass().getName().endsWith("Asteroids") + || DimensionManager.getProvider(dimId).getClass().getName().endsWith("SS") + || DimensionManager.getProvider(dimId).getClass().getName().contains("SpaceStation"); } - /** * * @param skipOC disables OverclockedNess calculation and check - if you do you must implement your own method... * @return */ - public int checkRecipe(boolean skipOC){ + public int checkRecipe(boolean skipOC) { GT_Recipe_Map tMap = getRecipeList(); if (tMap == null) return DID_NOT_FIND_RECIPE; - GT_Recipe tRecipe = tMap.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, V[mTier], new FluidStack[]{getFillableStack()}, getSpecialSlot(), getAllInputs()); + GT_Recipe tRecipe = tMap.findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + V[mTier], + new FluidStack[] {getFillableStack()}, + getSpecialSlot(), + getAllInputs()); if (tRecipe == null) return DID_NOT_FIND_RECIPE; - if (false && tRecipe.mSpecialValue == -100 && - !isValidForLowGravity(tRecipe,getBaseMetaTileEntity().getWorld().provider.dimensionId)) + if (false + && tRecipe.mSpecialValue == -100 + && !isValidForLowGravity(tRecipe, getBaseMetaTileEntity().getWorld().provider.dimensionId)) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; if (tRecipe.mCanBeBuffered) mLastRecipe = tRecipe; if (!canOutput(tRecipe)) { mOutputBlocked++; return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; } - if (!tRecipe.isRecipeInputEqual(true, new FluidStack[]{getFillableStack()}, getAllInputs())) + if (!tRecipe.isRecipeInputEqual(true, new FluidStack[] {getFillableStack()}, getAllInputs())) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; for (int i = 0; i < mOutputItems.length; i++) if (getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(i)) - mOutputItems[i] = tRecipe.getOutput(i); + mOutputItems[i] = tRecipe.getOutput(i); mOutputFluid = tRecipe.getFluidOutput(0); calculateOverclockedNess(tRecipe); return FOUND_AND_SUCCESSFULLY_USED_RECIPE; } public ITexture[] getSideFacingActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getSideFacingInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getFrontFacingActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getFrontFacingInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getTopFacingActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getTopFacingInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getBottomFacingActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getBottomFacingInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1]}; } public ITexture[] getBottomFacingPipeActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getBottomFacingPipeInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getTopFacingPipeActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getTopFacingPipeInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getSideFacingPipeActive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getSideFacingPipeInactive(byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } -}
\ No newline at end of file +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_DeluxeTank.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_DeluxeTank.java index 1e367d4f15..4bd4e30f30 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_DeluxeTank.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_DeluxeTank.java @@ -1,18 +1,16 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.enums.ItemList; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.util.GT_Utility; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_DeluxeTank; import gtPlusPlus.xmod.gregtech.api.gui.GUI_DeluxeTank; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; /** @@ -22,324 +20,367 @@ import net.minecraftforge.fluids.FluidStack; */ public abstract class GT_MetaTileEntity_DeluxeTank extends GT_MetaTileEntity_BasicTank { - public FluidStack mFluid2; - - /** - * @param aInvSlotCount should be 3 - */ - public GT_MetaTileEntity_DeluxeTank(final int aID, final String aName, final String aNameRegional, final int aTier, final int aInvSlotCount, final String aDescription, final ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); - } - - public GT_MetaTileEntity_DeluxeTank(final String aName, final int aTier, final int aInvSlotCount, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aInvSlotCount, aDescription, aTextures); - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return aIndex != this.getStackDisplaySlot(); - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - if (this.mFluid != null) { - aNBT.setTag("mFluid", this.mFluid.writeToNBT(new NBTTagCompound())); - } - if (this.mFluid2 != null) { - aNBT.setTag("mFluid2", this.mFluid2.writeToNBT(new NBTTagCompound())); - } - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.mFluid = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mFluid")); - this.mFluid2 = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mFluid2")); - } - - @Override - public abstract boolean doesFillContainers(); - - @Override - public abstract boolean doesEmptyContainers(); - - @Override - public abstract boolean canTankBeFilled(); - - @Override - public abstract boolean canTankBeEmptied(); - - @Override - public abstract boolean displaysItemStack(); - - @Override - public abstract boolean displaysStackSize(); - - @Override - public int getInputSlot() { - return 0; - } - - @Override - public int getOutputSlot() { - return 1; - } - - @Override - public int getStackDisplaySlot() { - return 2; - } - - public int getStackDisplaySlot2() { - return 3; - } - - @Override - public boolean isFluidInputAllowed(final FluidStack aFluid) { - return true; - } - - @Override - public boolean isFluidChangingAllowed() { - return true; - } - - @Override - public FluidStack getFillableStack() { - return this.getFillableStackEx(1); - } - - public FluidStack getFillableStackEx(final int stackID) { - if (stackID <= 1){ - return this.mFluid; - } - return this.mFluid2; - } - - @Override - public FluidStack setFillableStack(final FluidStack aFluid) { - this.mFluid = aFluid; - return this.mFluid; - } - - public FluidStack setFillableStack2(final FluidStack aFluid) { - this.mFluid2 = aFluid; - return this.mFluid2; - } - - @Override - public FluidStack getDrainableStack() { - return this.getDrainableStackEx(1); - } - - public FluidStack getDrainableStackEx(final int stackID) { - if (stackID <= 1){ - return this.mFluid; - } - return this.mFluid2; - } - - @Override - public FluidStack setDrainableStack(final FluidStack aFluid) { - this.mFluid = aFluid; - return this.mFluid; - } - - @Override - public FluidStack getDisplayedFluid() { - return this.getDrainableStack(); - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_DeluxeTank(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_DeluxeTank(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); - } - - @Override - public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (this.isFluidChangingAllowed() && (this.getFillableStack() != null) && (this.getFillableStack().amount <= 0)) { - this.setFillableStack(null); - } - - if (this.displaysItemStack() && (this.getStackDisplaySlot() >= 0) && (this.getStackDisplaySlot() < this.mInventory.length)) { - if (this.getDisplayedFluid() == null) { - if (ItemList.Display_Fluid.isStackEqual(this.mInventory[this.getStackDisplaySlot()], true, true)) { - this.mInventory[this.getStackDisplaySlot()] = null; - } - } else { - this.mInventory[this.getStackDisplaySlot()] = GT_Utility.getFluidDisplayStack(this.getDisplayedFluid(), this.displaysStackSize()); - } - } - - if (this.displaysItemStack() && (this.getStackDisplaySlot2() >= 0) && (this.getStackDisplaySlot2() < this.mInventory.length)) { - if (this.getDrainableStackEx(2) == null) { - if (ItemList.Display_Fluid.isStackEqual(this.mInventory[this.getStackDisplaySlot2()], true, true)) { - this.mInventory[this.getStackDisplaySlot2()] = null; - } - } else { - this.mInventory[this.getStackDisplaySlot2()] = GT_Utility.getFluidDisplayStack(this.getDrainableStackEx(2), this.displaysStackSize()); - } - } - - if (this.doesEmptyContainers()) { - final FluidStack tFluid = GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true); - if ((tFluid != null) && this.isFluidInputAllowed(tFluid)) { - - if (tFluid.isFluidEqual(this.getDrainableStackEx(1)) || (this.getDrainableStackEx(1) == null)){ - if (this.getFillableStackEx(1) == null) { - if (this.isFluidInputAllowed(tFluid) && (tFluid.amount <= this.getCapacity())) { - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), GT_Utility.getContainerItem(this.mInventory[this.getInputSlot()], true), 1)) { - this.setFillableStack(tFluid.copy()); - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - } - } - } else { - if (tFluid.isFluidEqual(this.getFillableStack()) && ((tFluid.amount + this.getFillableStack().amount) <= this.getCapacity())) { - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), GT_Utility.getContainerItem(this.mInventory[this.getInputSlot()], true), 1)) { - this.getFillableStack().amount += tFluid.amount; - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - } - } - } - } - else if (tFluid.isFluidEqual(this.getDrainableStackEx(2)) || (this.getDrainableStackEx(2) == null)){ - if (this.getFillableStackEx(2) == null) { - if (this.isFluidInputAllowed(tFluid) && (tFluid.amount <= this.getCapacity())) { - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), GT_Utility.getContainerItem(this.mInventory[this.getInputSlot()], true), 1)) { - this.setFillableStack2(tFluid.copy()); - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - } - } - } else { - if (tFluid.isFluidEqual(this.getFillableStackEx(2)) && ((tFluid.amount + this.getFillableStackEx(2).amount) <= this.getCapacity())) { - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), GT_Utility.getContainerItem(this.mInventory[this.getInputSlot()], true), 1)) { - this.getFillableStackEx(2).amount += tFluid.amount; - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - } - } - } - } - else { - Logger.INFO("Something broke when trying to empty cells between two fluid tank areas."); - } - } - } - - if (this.doesFillContainers()) { - final ItemStack tOutput = GT_Utility.fillFluidContainer(this.getDrainableStack(), this.mInventory[this.getInputSlot()], false, true); - if ((tOutput != null) && aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tOutput, 1)) { - final FluidStack tFluid = GT_Utility.getFluidForFilledItem(tOutput, true); - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - if (tFluid != null) { - this.getDrainableStack().amount -= tFluid.amount; - } - if ((this.getDrainableStack().amount <= 0) && this.isFluidChangingAllowed()) { - this.setDrainableStack(null); - } - } - } - } - } - - @Override - public FluidStack getFluid() { - return this.getDrainableStack(); - } - - @Override - public int getFluidAmount() { - return this.getDrainableStack() != null ? this.getDrainableStack().amount : 0; - } - - @Override - public int fill(final FluidStack aFluid, final boolean doFill) { - if ((aFluid == null) || (aFluid.getFluid().getID() <= 0) || (aFluid.amount <= 0) || !this.canTankBeFilled() || !this.isFluidInputAllowed(aFluid)) { - return 0; - } - - if ((this.getFillableStack() == null) || (this.getFillableStack().getFluid().getID() <= 0)) { - if (aFluid.amount <= this.getCapacity()) { - if (doFill) { - this.setFillableStack(aFluid.copy()); - this.getBaseMetaTileEntity().markDirty(); - } - return aFluid.amount; - } - if (doFill) { - this.setFillableStack(aFluid.copy()); - this.getFillableStack().amount = this.getCapacity(); - this.getBaseMetaTileEntity().markDirty(); - } - return this.getCapacity(); - } - - if (!this.getFillableStack().isFluidEqual(aFluid)) { - return 0; - } - - final int space = this.getCapacity() - this.getFillableStack().amount; - if (aFluid.amount <= space) { - if (doFill) { - this.getFillableStack().amount += aFluid.amount; - this.getBaseMetaTileEntity().markDirty(); - } - return aFluid.amount; - } - if (doFill) { - this.getFillableStack().amount = this.getCapacity(); - } - return space; - } - - @Override - public FluidStack drain(final int maxDrain, final boolean doDrain) { - if ((this.getDrainableStack() == null) || !this.canTankBeEmptied()) { - return null; - } - if ((this.getDrainableStack().amount <= 0) && this.isFluidChangingAllowed()) { - this.setDrainableStack(null); - this.getBaseMetaTileEntity().markDirty(); - return null; - } - - int used = maxDrain; - if (this.getDrainableStack().amount < used) { - used = this.getDrainableStack().amount; - } - - if (doDrain) { - this.getDrainableStack().amount -= used; - this.getBaseMetaTileEntity().markDirty(); - } - - final FluidStack drained = this.getDrainableStack().copy(); - drained.amount = used; - - if ((this.getDrainableStack().amount <= 0) && this.isFluidChangingAllowed()) { - this.setDrainableStack(null); - this.getBaseMetaTileEntity().markDirty(); - } - - return drained; - } - - @Override - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return aIndex == this.getOutputSlot(); - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return aIndex == this.getInputSlot(); - } -}
\ No newline at end of file + public FluidStack mFluid2; + + /** + * @param aInvSlotCount should be 3 + */ + public GT_MetaTileEntity_DeluxeTank( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final int aInvSlotCount, + final String aDescription, + final ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); + } + + public GT_MetaTileEntity_DeluxeTank( + final String aName, + final int aTier, + final int aInvSlotCount, + final String aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return aIndex != this.getStackDisplaySlot(); + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + if (this.mFluid != null) { + aNBT.setTag("mFluid", this.mFluid.writeToNBT(new NBTTagCompound())); + } + if (this.mFluid2 != null) { + aNBT.setTag("mFluid2", this.mFluid2.writeToNBT(new NBTTagCompound())); + } + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mFluid = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mFluid")); + this.mFluid2 = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mFluid2")); + } + + @Override + public abstract boolean doesFillContainers(); + + @Override + public abstract boolean doesEmptyContainers(); + + @Override + public abstract boolean canTankBeFilled(); + + @Override + public abstract boolean canTankBeEmptied(); + + @Override + public abstract boolean displaysItemStack(); + + @Override + public abstract boolean displaysStackSize(); + + @Override + public int getInputSlot() { + return 0; + } + + @Override + public int getOutputSlot() { + return 1; + } + + @Override + public int getStackDisplaySlot() { + return 2; + } + + public int getStackDisplaySlot2() { + return 3; + } + + @Override + public boolean isFluidInputAllowed(final FluidStack aFluid) { + return true; + } + + @Override + public boolean isFluidChangingAllowed() { + return true; + } + + @Override + public FluidStack getFillableStack() { + return this.getFillableStackEx(1); + } + + public FluidStack getFillableStackEx(final int stackID) { + if (stackID <= 1) { + return this.mFluid; + } + return this.mFluid2; + } + + @Override + public FluidStack setFillableStack(final FluidStack aFluid) { + this.mFluid = aFluid; + return this.mFluid; + } + + public FluidStack setFillableStack2(final FluidStack aFluid) { + this.mFluid2 = aFluid; + return this.mFluid2; + } + + @Override + public FluidStack getDrainableStack() { + return this.getDrainableStackEx(1); + } + + public FluidStack getDrainableStackEx(final int stackID) { + if (stackID <= 1) { + return this.mFluid; + } + return this.mFluid2; + } + + @Override + public FluidStack setDrainableStack(final FluidStack aFluid) { + this.mFluid = aFluid; + return this.mFluid; + } + + @Override + public FluidStack getDisplayedFluid() { + return this.getDrainableStack(); + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_DeluxeTank(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_DeluxeTank(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); + } + + @Override + public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.isFluidChangingAllowed() + && (this.getFillableStack() != null) + && (this.getFillableStack().amount <= 0)) { + this.setFillableStack(null); + } + + if (this.displaysItemStack() + && (this.getStackDisplaySlot() >= 0) + && (this.getStackDisplaySlot() < this.mInventory.length)) { + if (this.getDisplayedFluid() == null) { + if (ItemList.Display_Fluid.isStackEqual(this.mInventory[this.getStackDisplaySlot()], true, true)) { + this.mInventory[this.getStackDisplaySlot()] = null; + } + } else { + this.mInventory[this.getStackDisplaySlot()] = + GT_Utility.getFluidDisplayStack(this.getDisplayedFluid(), this.displaysStackSize()); + } + } + + if (this.displaysItemStack() + && (this.getStackDisplaySlot2() >= 0) + && (this.getStackDisplaySlot2() < this.mInventory.length)) { + if (this.getDrainableStackEx(2) == null) { + if (ItemList.Display_Fluid.isStackEqual(this.mInventory[this.getStackDisplaySlot2()], true, true)) { + this.mInventory[this.getStackDisplaySlot2()] = null; + } + } else { + this.mInventory[this.getStackDisplaySlot2()] = + GT_Utility.getFluidDisplayStack(this.getDrainableStackEx(2), this.displaysStackSize()); + } + } + + if (this.doesEmptyContainers()) { + final FluidStack tFluid = GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true); + if ((tFluid != null) && this.isFluidInputAllowed(tFluid)) { + + if (tFluid.isFluidEqual(this.getDrainableStackEx(1)) || (this.getDrainableStackEx(1) == null)) { + if (this.getFillableStackEx(1) == null) { + if (this.isFluidInputAllowed(tFluid) && (tFluid.amount <= this.getCapacity())) { + if (aBaseMetaTileEntity.addStackToSlot( + this.getOutputSlot(), + GT_Utility.getContainerItem(this.mInventory[this.getInputSlot()], true), + 1)) { + this.setFillableStack(tFluid.copy()); + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + } + } + } else { + if (tFluid.isFluidEqual(this.getFillableStack()) + && ((tFluid.amount + this.getFillableStack().amount) <= this.getCapacity())) { + if (aBaseMetaTileEntity.addStackToSlot( + this.getOutputSlot(), + GT_Utility.getContainerItem(this.mInventory[this.getInputSlot()], true), + 1)) { + this.getFillableStack().amount += tFluid.amount; + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + } + } + } + } else if (tFluid.isFluidEqual(this.getDrainableStackEx(2)) + || (this.getDrainableStackEx(2) == null)) { + if (this.getFillableStackEx(2) == null) { + if (this.isFluidInputAllowed(tFluid) && (tFluid.amount <= this.getCapacity())) { + if (aBaseMetaTileEntity.addStackToSlot( + this.getOutputSlot(), + GT_Utility.getContainerItem(this.mInventory[this.getInputSlot()], true), + 1)) { + this.setFillableStack2(tFluid.copy()); + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + } + } + } else { + if (tFluid.isFluidEqual(this.getFillableStackEx(2)) + && ((tFluid.amount + this.getFillableStackEx(2).amount) <= this.getCapacity())) { + if (aBaseMetaTileEntity.addStackToSlot( + this.getOutputSlot(), + GT_Utility.getContainerItem(this.mInventory[this.getInputSlot()], true), + 1)) { + this.getFillableStackEx(2).amount += tFluid.amount; + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + } + } + } + } else { + Logger.INFO("Something broke when trying to empty cells between two fluid tank areas."); + } + } + } + + if (this.doesFillContainers()) { + final ItemStack tOutput = GT_Utility.fillFluidContainer( + this.getDrainableStack(), this.mInventory[this.getInputSlot()], false, true); + if ((tOutput != null) && aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tOutput, 1)) { + final FluidStack tFluid = GT_Utility.getFluidForFilledItem(tOutput, true); + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + if (tFluid != null) { + this.getDrainableStack().amount -= tFluid.amount; + } + if ((this.getDrainableStack().amount <= 0) && this.isFluidChangingAllowed()) { + this.setDrainableStack(null); + } + } + } + } + } + + @Override + public FluidStack getFluid() { + return this.getDrainableStack(); + } + + @Override + public int getFluidAmount() { + return this.getDrainableStack() != null ? this.getDrainableStack().amount : 0; + } + + @Override + public int fill(final FluidStack aFluid, final boolean doFill) { + if ((aFluid == null) + || (aFluid.getFluid().getID() <= 0) + || (aFluid.amount <= 0) + || !this.canTankBeFilled() + || !this.isFluidInputAllowed(aFluid)) { + return 0; + } + + if ((this.getFillableStack() == null) + || (this.getFillableStack().getFluid().getID() <= 0)) { + if (aFluid.amount <= this.getCapacity()) { + if (doFill) { + this.setFillableStack(aFluid.copy()); + this.getBaseMetaTileEntity().markDirty(); + } + return aFluid.amount; + } + if (doFill) { + this.setFillableStack(aFluid.copy()); + this.getFillableStack().amount = this.getCapacity(); + this.getBaseMetaTileEntity().markDirty(); + } + return this.getCapacity(); + } + + if (!this.getFillableStack().isFluidEqual(aFluid)) { + return 0; + } + + final int space = this.getCapacity() - this.getFillableStack().amount; + if (aFluid.amount <= space) { + if (doFill) { + this.getFillableStack().amount += aFluid.amount; + this.getBaseMetaTileEntity().markDirty(); + } + return aFluid.amount; + } + if (doFill) { + this.getFillableStack().amount = this.getCapacity(); + } + return space; + } + + @Override + public FluidStack drain(final int maxDrain, final boolean doDrain) { + if ((this.getDrainableStack() == null) || !this.canTankBeEmptied()) { + return null; + } + if ((this.getDrainableStack().amount <= 0) && this.isFluidChangingAllowed()) { + this.setDrainableStack(null); + this.getBaseMetaTileEntity().markDirty(); + return null; + } + + int used = maxDrain; + if (this.getDrainableStack().amount < used) { + used = this.getDrainableStack().amount; + } + + if (doDrain) { + this.getDrainableStack().amount -= used; + this.getBaseMetaTileEntity().markDirty(); + } + + final FluidStack drained = this.getDrainableStack().copy(); + drained.amount = used; + + if ((this.getDrainableStack().amount <= 0) && this.isFluidChangingAllowed()) { + this.setDrainableStack(null); + this.getBaseMetaTileEntity().markDirty(); + } + + return drained; + } + + @Override + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aIndex == this.getOutputSlot(); + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aIndex == this.getInputSlot(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java index 02b7a03f3b..6a49e9b84d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java @@ -11,100 +11,112 @@ import net.minecraftforge.fluids.Fluid; public class GT_MetaTileEntity_Hatch_AirIntake extends GT_MetaTileEntity_Hatch_FluidGenerator { - public GT_MetaTileEntity_Hatch_AirIntake(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier); - } - - public GT_MetaTileEntity_Hatch_AirIntake(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_AirIntake(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public String[] getCustomTooltip() { - String[] aTooltip = new String[3]; - aTooltip[0] = "DO NOT OBSTRUCT THE INPUT!"; - aTooltip[1] = "Draws in Air from the surrounding environment"; - aTooltip[2] = "Creates "+getAmountOfFluidToGenerate()+"L of Air every "+getMaxTickTime()+" ticks"; - return aTooltip; - } - - @Override - public Fluid getFluidToGenerate() { - return FluidUtils.getAir(1).getFluid(); - } - - @Override - public int getAmountOfFluidToGenerate() { - return 1000; - } - - @Override - public int getMaxTickTime() { - return 4; - } - - @Override - public int getCapacity() { - return 128000; - } - - @Override - public boolean doesHatchMeetConditionsToGenerate() { - return this.getBaseMetaTileEntity().getAirAtSide(this.getBaseMetaTileEntity().getFrontFacing()); - } - - @Override - public void generateParticles(World aWorld, String name) { - if (this.getBaseMetaTileEntity().isServerSide()) { - return; - } - final float ran1 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); - float ran2 = 0.0f; - float ran3 = 0.0f; - ran2 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); - ran3 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); - - final IGregTechTileEntity aMuffler = this.getBaseMetaTileEntity(); - final ForgeDirection aDir = ForgeDirection.getOrientation((int) aMuffler.getFrontFacing()); - final float xPos = aDir.offsetX * 0.76f + aMuffler.getXCoord() + 0.25f; - float yPos = aDir.offsetY * 0.76f + aMuffler.getYCoord() + 0.65f; - final float zPos = aDir.offsetZ * 0.76f + aMuffler.getZCoord() + 0.25f; - float ySpd = aDir.offsetY * 0.1f + 0.2f + 0.1f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); - float xSpd; - float zSpd; - if (aDir.offsetY == -1) { - //Logger.INFO("Y = -1"); - final float temp = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 2.0f * CORE.PI; - xSpd = (float) Math.sin(temp) * 0.1f; - zSpd = (float) Math.cos(temp) * 0.1f; - ySpd = -ySpd; - yPos = yPos - 0.8f; - } - else { - xSpd = aDir.offsetX * (0.1f + 0.2f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat()); - zSpd = aDir.offsetZ * (0.1f + 0.2f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat()); - - xSpd = -xSpd; - zSpd = -zSpd; - } - - aWorld.spawnParticle(name, (double) (xPos + ran1 * 0.5f), - (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), - (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), (double) xSpd, - (double) -ySpd, (double) zSpd); - aWorld.spawnParticle(name, (double) (xPos + ran2 * 0.5f), - (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), - (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), (double) xSpd, - (double) -ySpd, (double) zSpd); - aWorld.spawnParticle(name, (double) (xPos + ran3 * 0.5f), - (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), - (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), (double) xSpd, - (double) -ySpd, (double) zSpd); - } - + public GT_MetaTileEntity_Hatch_AirIntake( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_AirIntake( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_AirIntake(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public String[] getCustomTooltip() { + String[] aTooltip = new String[3]; + aTooltip[0] = "DO NOT OBSTRUCT THE INPUT!"; + aTooltip[1] = "Draws in Air from the surrounding environment"; + aTooltip[2] = "Creates " + getAmountOfFluidToGenerate() + "L of Air every " + getMaxTickTime() + " ticks"; + return aTooltip; + } + + @Override + public Fluid getFluidToGenerate() { + return FluidUtils.getAir(1).getFluid(); + } + + @Override + public int getAmountOfFluidToGenerate() { + return 1000; + } + + @Override + public int getMaxTickTime() { + return 4; + } + + @Override + public int getCapacity() { + return 128000; + } + + @Override + public boolean doesHatchMeetConditionsToGenerate() { + return this.getBaseMetaTileEntity() + .getAirAtSide(this.getBaseMetaTileEntity().getFrontFacing()); + } + + @Override + public void generateParticles(World aWorld, String name) { + if (this.getBaseMetaTileEntity().isServerSide()) { + return; + } + final float ran1 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); + float ran2 = 0.0f; + float ran3 = 0.0f; + ran2 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); + ran3 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); + + final IGregTechTileEntity aMuffler = this.getBaseMetaTileEntity(); + final ForgeDirection aDir = ForgeDirection.getOrientation((int) aMuffler.getFrontFacing()); + final float xPos = aDir.offsetX * 0.76f + aMuffler.getXCoord() + 0.25f; + float yPos = aDir.offsetY * 0.76f + aMuffler.getYCoord() + 0.65f; + final float zPos = aDir.offsetZ * 0.76f + aMuffler.getZCoord() + 0.25f; + float ySpd = aDir.offsetY * 0.1f + 0.2f + 0.1f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); + float xSpd; + float zSpd; + if (aDir.offsetY == -1) { + // Logger.INFO("Y = -1"); + final float temp = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 2.0f * CORE.PI; + xSpd = (float) Math.sin(temp) * 0.1f; + zSpd = (float) Math.cos(temp) * 0.1f; + ySpd = -ySpd; + yPos = yPos - 0.8f; + } else { + xSpd = aDir.offsetX * (0.1f + 0.2f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat()); + zSpd = aDir.offsetZ * (0.1f + 0.2f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat()); + + xSpd = -xSpd; + zSpd = -zSpd; + } + + aWorld.spawnParticle( + name, + (double) (xPos + ran1 * 0.5f), + (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) xSpd, + (double) -ySpd, + (double) zSpd); + aWorld.spawnParticle( + name, + (double) (xPos + ran2 * 0.5f), + (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) xSpd, + (double) -ySpd, + (double) zSpd); + aWorld.spawnParticle( + name, + (double) (xPos + ran3 * 0.5f), + (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) xSpd, + (double) -ySpd, + (double) zSpd); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java index 45611d9e05..ca640b7a1d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java @@ -6,27 +6,27 @@ import gregtech.api.metatileentity.MetaTileEntity; public class GT_MetaTileEntity_Hatch_AirIntake_Extreme extends GT_MetaTileEntity_Hatch_AirIntake { - public GT_MetaTileEntity_Hatch_AirIntake_Extreme(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier); - } - - public GT_MetaTileEntity_Hatch_AirIntake_Extreme(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_AirIntake_Extreme(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public int getAmountOfFluidToGenerate() { - return 8000; - } - - @Override - public int getCapacity() { - return 256000; - } - + public GT_MetaTileEntity_Hatch_AirIntake_Extreme( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_AirIntake_Extreme( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_AirIntake_Extreme(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public int getAmountOfFluidToGenerate() { + return 8000; + } + + @Override + public int getCapacity() { + return 256000; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ControlCore.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ControlCore.java index 5347b2e4f7..b2ea5a62ec 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ControlCore.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ControlCore.java @@ -19,38 +19,43 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; public class GT_MetaTileEntity_Hatch_ControlCore extends GT_MetaTileEntity_Hatch { - + public GT_Recipe_Map mRecipeMap = null; - + public BlockPos mControllerLocation; public GT_MetaTileEntity_Hatch_ControlCore(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier), "Core determines maximum tier machine will operate at"); + super( + aID, + aName, + aNameRegional, + aTier, + getSlots(aTier), + "Core determines maximum tier machine will operate at"); } public GT_MetaTileEntity_Hatch_ControlCore(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); } - - public GT_MetaTileEntity_Hatch_ControlCore(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + + public GT_MetaTileEntity_Hatch_ControlCore( + String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription[0], aTextures); } - - @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 ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Control_Core)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Control_Core)}; } @Override public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Control_Core)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Control_Core)}; } @Override @@ -75,7 +80,8 @@ public class GT_MetaTileEntity_Hatch_ControlCore extends GT_MetaTileEntity_Hatch @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_ControlCore(mName, mTier, StaticFields59.getDescriptionArray(this), mTextures); + return new GT_MetaTileEntity_Hatch_ControlCore( + mName, mTier, StaticFields59.getDescriptionArray(this), mTextures); } @Override @@ -87,12 +93,12 @@ public class GT_MetaTileEntity_Hatch_ControlCore extends GT_MetaTileEntity_Hatch @Override public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); + return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); } @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, "Control Core Module"); + return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, "Control Core Module"); } @Override @@ -111,8 +117,17 @@ public class GT_MetaTileEntity_Hatch_ControlCore extends GT_MetaTileEntity_Hatch protected void fillStacksIntoFirstSlots() { for (int i = 0; i < mInventory.length; i++) for (int j = i + 1; j < mInventory.length; j++) - if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { - GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); } } @@ -123,26 +138,25 @@ public class GT_MetaTileEntity_Hatch_ControlCore extends GT_MetaTileEntity_Hatch @Override public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aSide == getBaseMetaTileEntity().getFrontFacing() && (aStack != null && aStack.getItem() instanceof ItemControlCore); - } - - public boolean setOwner(TileEntity aTileEntity) { - if (mControllerLocation != null) { - return false; - } - else { - mControllerLocation = new BlockPos(aTileEntity); - return true; - } - } - - public boolean setOwner(IGregTechTileEntity aTileEntity) { - if (mControllerLocation != null) { - return false; - } - else { - mControllerLocation = new BlockPos(aTileEntity); - return true; - } - } + return aSide == getBaseMetaTileEntity().getFrontFacing() + && (aStack != null && aStack.getItem() instanceof ItemControlCore); + } + + public boolean setOwner(TileEntity aTileEntity) { + if (mControllerLocation != null) { + return false; + } else { + mControllerLocation = new BlockPos(aTileEntity); + return true; + } + } + + public boolean setOwner(IGregTechTileEntity aTileEntity) { + if (mControllerLocation != null) { + return false; + } else { + mControllerLocation = new BlockPos(aTileEntity); + return true; + } + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java index 39f477b173..8405e2b09c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java @@ -1,84 +1,85 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; +import gregtech.api.enums.GT_Values; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.enums.GT_Values; -import gregtech.api.interfaces.ITexture; - public class GT_MetaTileEntity_Hatch_DynamoBuffer extends GT_MetaTileEntity_Hatch_Dynamo { - public GT_MetaTileEntity_Hatch_DynamoBuffer(final int aID, final String aName, final String aNameRegional, - final int aTier) { - super(aID, aName, aNameRegional, aTier); - } + public GT_MetaTileEntity_Hatch_DynamoBuffer( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_DynamoBuffer( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } - public GT_MetaTileEntity_Hatch_DynamoBuffer(final String aName, final int aTier, final String aDescription, - final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } + /*public GT_MetaTileEntity_Hatch_DynamoBuffer(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + }*/ - /*public GT_MetaTileEntity_Hatch_DynamoBuffer(final String aName, final int aTier, final String[] aDescription, - final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - }*/ + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, TexturesGtBlock.OVERLAYS_ENERGY_OUT_MULTI_BUFFER[this.mTier]}; + } - public ITexture[] getTexturesActive(final ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, TexturesGtBlock.OVERLAYS_ENERGY_OUT_MULTI_BUFFER[this.mTier]}; - } + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, TexturesGtBlock.OVERLAYS_ENERGY_OUT_MULTI_BUFFER[this.mTier]}; + } - public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, TexturesGtBlock.OVERLAYS_ENERGY_OUT_MULTI_BUFFER[this.mTier]}; - } + @Override + public long getMinimumStoredEU() { + return 0L; + } - @Override - public long getMinimumStoredEU() { - return 0L; - } + @Override + public long maxEUStore() { + return 512L + GT_Values.V[this.mTier + 1] * 2048L; + } - @Override - public long maxEUStore() { - return 512L + GT_Values.V[this.mTier + 1] * 2048L; - } + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return (MetaTileEntity) + new GT_MetaTileEntity_Hatch_DynamoBuffer(this.mName, this.mTier, this.mDescription, this.mTextures); + } - @Override - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return (MetaTileEntity) new GT_MetaTileEntity_Hatch_DynamoBuffer(this.mName, this.mTier, this.mDescription, this.mTextures); - } + @Override + public String[] getDescription() { + String[] g; + if (CORE.GTNH || (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && Utils.getGregtechVersionAsInt() >= 50932)) { + g = new String[] { + "Dynamo with internal storage and additional Amp capacity", + "Does not accept more than " + (this.maxEUOutput() * this.maxAmperesIn()) + "EU/t as input", + CORE.GT_Tooltip + }; - @Override - public String[] getDescription() { - String[] g; - if (CORE.GTNH || (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && Utils.getGregtechVersionAsInt() >= 50932)) { - g = new String[]{ - "Dynamo with internal storage and additional Amp capacity", - "Does not accept more than "+(this.maxEUOutput() * this.maxAmperesIn())+"EU/t as input", - CORE.GT_Tooltip}; - - } - else { - g = new String[]{ - "Dynamo with internal storage and additional Amp capacity", - "Stores "+maxEUStore()+"EU", - "Amperage In: 4", - "Amperage Out: 4", - "Does not accept more than "+(this.maxEUOutput() * this.maxAmperesIn())+"EU/t as input", - "Large Turbines only supply 1A to this, other Multiblocks can inject more amps", - CORE.GT_Tooltip}; - } - return g; - } + } else { + g = new String[] { + "Dynamo with internal storage and additional Amp capacity", + "Stores " + maxEUStore() + "EU", + "Amperage In: 4", + "Amperage Out: 4", + "Does not accept more than " + (this.maxEUOutput() * this.maxAmperesIn()) + "EU/t as input", + "Large Turbines only supply 1A to this, other Multiblocks can inject more amps", + CORE.GT_Tooltip + }; + } + return g; + } - @Override - public long maxAmperesIn() { - return 4; - } + @Override + public long maxAmperesIn() { + return 4; + } - @Override - public long maxAmperesOut() { - return 4; - } -}
\ No newline at end of file + @Override + public long maxAmperesOut() { + return 4; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.java index 67a6fc7aeb..500f1945bc 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import java.util.ArrayList; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -15,166 +13,172 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_DataHatch; import gtPlusPlus.xmod.gregtech.api.gui.GUI_DataHatch; 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; import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_Hatch_ElementalDataOrbHolder extends GT_MetaTileEntity_Hatch { - public GT_Recipe_Map mRecipeMap = null; - - public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 17, new String[]{ - "Holds Data Orbs for the Elemental Duplicator", - "Can insert/extract the circuit slot", - "Use Circuit to select a slot (1-16)", - CORE.GT_Tooltip - }); - } - - public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 17, aDescription, aTextures); - } - - public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 17, aDescription, aTextures); - } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Data_Orb)}; - } - - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Data_Orb)}; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isValidSlot(int aIndex) { - return true; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(mName, mTier, mDescriptionArray, mTextures); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_DataHatch(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_DataHatch(aPlayerInventory, aBaseMetaTileEntity, "Data Orb Repository"); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { - fillStacksIntoFirstSlots(); - } - } - - public void updateSlots() { - for (int i = 0; i < mInventory.length-1; i++) - if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; - fillStacksIntoFirstSlots(); - } - - protected void fillStacksIntoFirstSlots() { - for (int i = 0; i < mInventory.length-1; i++) { - if (mInventory[i] != null && mInventory[i].stackSize <= 0) { - mInventory[i] = null; - } - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - - } - - public String trans(String aKey, String aEnglish) { - return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aKey, aEnglish, false); - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - Logger.INFO("Checking if we can pull "+aStack.getDisplayName()+" from slot "+aIndex); - if (aIndex == mInventory.length-1 && ItemUtils.isControlCircuit(aStack) && aSide == getBaseMetaTileEntity().getFrontFacing()) { - return true; - } - return false; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - Logger.INFO("Checking if we can put "+aStack.getDisplayName()+" into slot "+aIndex); - if (aIndex == mInventory.length-1 && ItemUtils.isControlCircuit(aStack) && aSide == getBaseMetaTileEntity().getFrontFacing()) { - return true; - } - return false; - } - - public ArrayList<ItemStack> getInventory(){ - ArrayList<ItemStack> aContents = new ArrayList<ItemStack>(); - for (int i = getBaseMetaTileEntity().getSizeInventory() - 2; i >= 0; i--) { + public GT_Recipe_Map mRecipeMap = null; + + public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 17, new String[] { + "Holds Data Orbs for the Elemental Duplicator", + "Can insert/extract the circuit slot", + "Use Circuit to select a slot (1-16)", + CORE.GT_Tooltip + }); + } + + public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 17, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder( + String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 17, aDescription, aTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Data_Orb)}; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Data_Orb)}; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_DataHatch(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_DataHatch(aPlayerInventory, aBaseMetaTileEntity, "Data Orb Repository"); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length - 1; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < mInventory.length - 1; i++) { + if (mInventory[i] != null && mInventory[i].stackSize <= 0) { + mInventory[i] = null; + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {} + + public String trans(String aKey, String aEnglish) { + return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aKey, aEnglish, false); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + Logger.INFO("Checking if we can pull " + aStack.getDisplayName() + " from slot " + aIndex); + if (aIndex == mInventory.length - 1 + && ItemUtils.isControlCircuit(aStack) + && aSide == getBaseMetaTileEntity().getFrontFacing()) { + return true; + } + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + Logger.INFO("Checking if we can put " + aStack.getDisplayName() + " into slot " + aIndex); + if (aIndex == mInventory.length - 1 + && ItemUtils.isControlCircuit(aStack) + && aSide == getBaseMetaTileEntity().getFrontFacing()) { + return true; + } + return false; + } + + public ArrayList<ItemStack> getInventory() { + ArrayList<ItemStack> aContents = new ArrayList<ItemStack>(); + for (int i = getBaseMetaTileEntity().getSizeInventory() - 2; i >= 0; i--) { if (getBaseMetaTileEntity().getStackInSlot(i) != null) - aContents.add(getBaseMetaTileEntity().getStackInSlot(i)); - } - return aContents; - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - if (aIndex == mInventory.length-1 && ItemUtils.isControlCircuit(aStack) && aSide == getBaseMetaTileEntity().getFrontFacing()) { - Logger.INFO("Putting "+aStack.getDisplayName()+" into slot "+aIndex); - return true; - } - return false; - } - - @Override - public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { - if (aIndex == mInventory.length-1 && ItemUtils.isControlCircuit(aStack)) { - Logger.INFO("Pulling "+aStack.getDisplayName()+" from slot "+aIndex); - return true; - } - return false; - } - + aContents.add(getBaseMetaTileEntity().getStackInSlot(i)); + } + return aContents; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + if (aIndex == mInventory.length - 1 + && ItemUtils.isControlCircuit(aStack) + && aSide == getBaseMetaTileEntity().getFrontFacing()) { + Logger.INFO("Putting " + aStack.getDisplayName() + " into slot " + aIndex); + return true; + } + return false; + } + + @Override + public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { + if (aIndex == mInventory.length - 1 && ItemUtils.isControlCircuit(aStack)) { + Logger.INFO("Pulling " + aStack.getDisplayName() + " from slot " + aIndex); + return true; + } + return false; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy_RTG.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy_RTG.java index 8646e7e0a7..d70a84949f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy_RTG.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy_RTG.java @@ -2,10 +2,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.V; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; - import gregtech.api.gui.GT_Container_3by3; import gregtech.api.gui.GT_GUIContainer_3by3; import gregtech.api.interfaces.ITexture; @@ -17,6 +13,9 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.InventoryUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.HashMap; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.Item; @@ -25,269 +24,277 @@ import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_Hatch_Energy_RTG extends GT_MetaTileEntity_Hatch_Energy { - public GT_MetaTileEntity_Hatch_Energy_RTG(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount) { - super(aID, aName, aNameRegional, aTier); - setInventoryContent(aInvSlotCount); - } - - public GT_MetaTileEntity_Hatch_Energy_RTG(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - public GT_MetaTileEntity_Hatch_Energy_RTG(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, int aInvSlotCount) { - super(aName, aTier, aDescription, aTextures); - setInventoryContent(aInvSlotCount); - } - - @Override - public String[] getDescription() { - String[] S = super.getDescription(); - final String[] desc = new String[S.length + 1]; - System.arraycopy(S, 0, desc, 0, S.length); - desc[S.length] = CORE.GT_Tooltip; - return desc; - } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, TexturesGtBlock.getTextureFromIcon(TexturesGtBlock.Overlay_Hatch_RTG_On, new short[] {220, 220, 220, 0})}; - } - - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, TexturesGtBlock.getTextureFromIcon(TexturesGtBlock.Overlay_Hatch_RTG_Off, new short[] {220, 220, 220, 0})}; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isEnetInput() { - return false; - } - - @Override - public boolean isInputFacing(byte aSide) { - return aSide == getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public boolean isValidSlot(int aIndex) { - return true; - } - - @Override - public long getMinimumStoredEU() { - return 0; - } - - @Override - public long maxEUInput() { - return V[mTier]; - } - - @Override - public long maxEUStore() { - return Long.MAX_VALUE / (Short.MAX_VALUE * Byte.MAX_VALUE) ; - } - - @Override - public long maxAmperesIn() { - return 0; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_Energy_RTG(mName, mTier, mDescriptionArray, mTextures, 9); - } - - @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 true; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_3by3(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_3by3(aPlayerInventory, aBaseMetaTileEntity, "RTG Power Unit"); - } - - private static class Dat { - - protected final String mUniqueDataTag; - private final ItemStack mStack; - private final NBTTagCompound mNBT; - - public Dat(ItemStack aStack) { - mStack = aStack; - mNBT = (aStack.getTagCompound() != null ? aStack.getTagCompound() : new NBTTagCompound()); - mUniqueDataTag = ""+Item.getIdFromItem(aStack.getItem())+""+aStack.getItemDamage()+""+1+""+mNBT.getId(); - } - - public int getKey() { - return Item.getIdFromItem(mStack.getItem())+mStack.getItemDamage(); - } - - } - - private static final HashMap<String, ItemStack> mFuelInstanceMap = new HashMap<String, ItemStack>(); - private static final HashMap<String, Long> mFuelValueMap = new HashMap<String, Long>(); - private static final HashMap<String, Integer> mFuelTypeMap = new HashMap<String, Integer>(); - private static final HashMap<Integer, String> mFuelTypeMapReverse = new HashMap<Integer, String>(); - - public static boolean registerPelletForHatch(ItemStack aStack, long aFuelValue) { - if (!ItemUtils.checkForInvalidItems(aStack)) { - return false; - } - ItemStack aTemp = aStack.copy(); - aTemp.stackSize = 1; - Dat aDat = new Dat(aTemp); - String aKey = aDat.mUniqueDataTag; - mFuelInstanceMap.put(aKey, aTemp); - mFuelValueMap.put(aKey, aFuelValue); - mFuelTypeMap.put(aKey, aDat.getKey()); - mFuelTypeMapReverse.put(aDat.getKey(), aKey); - Logger.INFO("RTG Hatch: Registered Fuel Pellet: "+ItemUtils.getItemName(aTemp)+", Fuel Value: "+aFuelValue+", Key: "+aKey+", Key2: "+aDat.getKey()); - return true; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { - InventoryUtils.sortInventoryItems(this); - } - if (aTimer % 100 == 0 && aBaseMetaTileEntity.isServerSide()) { - if (hasPellet(this)) { - Logger.INFO("Has Pellet"); - tryConsumePellet(this); - } - } - } - - private static void tryConsumePellet(GT_MetaTileEntity_Hatch_Energy_RTG aTile) { - ItemStack aPellet = getPelletToConsume(aTile); - if (aPellet != null) { - Logger.INFO("Found Pellet"); - long aFuel = getFuelValueOfPellet(aPellet); - if (aFuel > 0) { - Logger.INFO("Has Fuel Value: "+aFuel); - if (hasSpaceForEnergy(aTile, aFuel)) { - Logger.INFO("Can buffer"); - aPellet.stackSize = 0; - Logger.INFO("Stack set to 0"); - aPellet = null; - Logger.INFO("null stack"); - addEnergyToInternalStorage(aTile, aFuel); - Logger.INFO("Consumed"); - } - } - } - aTile.updateSlots(); - Logger.INFO("updating slots"); - } - - private static void addEnergyToInternalStorage(GT_MetaTileEntity_Hatch_Energy_RTG aTile, long aFuel) { - aTile.getBaseMetaTileEntity().increaseStoredEnergyUnits(aFuel, true); - } - - public static boolean hasSpaceForEnergy(GT_MetaTileEntity_Hatch_Energy_RTG aTile, long aAmount) { - long aMax = aTile.maxEUStore(); - long aCurrent = aTile.getEUVar(); - if ((aMax - aCurrent) >= aAmount) { - return true; - } - return false; - } - - public void updateSlots() { - for (int i = 0; i < mInventory.length; i++) { - if (mInventory[i] != null && mInventory[i].stackSize <= 0) { - mInventory[i] = null; - } - } - InventoryUtils.sortInventoryItems(this); - } - - public static boolean hasPellet(GT_MetaTileEntity_Hatch_Energy_RTG aTile) { - for (ItemStack o : aTile.mInventory) { - if (o != null ) { - for (ItemStack i : mFuelInstanceMap.values()) { - if (ItemUtils.areItemsEqual(o, i)) { - return true; - } - } - } - } - return false; - } - - public static String getPelletType(ItemStack o) { - if (o == null) { - return "error"; - } - Dat aDat = new Dat(o); - return mFuelTypeMapReverse.get(aDat.getKey()); - } - - public static long getFuelValueOfPellet(ItemStack aPellet) { - String aType = getPelletType(aPellet); - if (mFuelValueMap.containsKey(aType)) { - return mFuelValueMap.get(aType); - } - return 0; - } - - public static ItemStack getPelletToConsume(GT_MetaTileEntity_Hatch_Energy_RTG aTile) { - for (ItemStack o : aTile.mInventory) { - if (o != null ) { - for (ItemStack i : mFuelInstanceMap.values()) { - if (ItemUtils.areItemsEqual(o, i)) { - return o; - } - } - } - } - return null; - } - - private void setInventoryContent(int aInvSlotCount) { - try { - Field fieldInventory = MetaTileEntity.class.getDeclaredField("mInventory"); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(fieldInventory, fieldInventory.getModifiers() & ~Modifier.PRIVATE & ~Modifier.FINAL); - fieldInventory.set(this, new ItemStack[aInvSlotCount]); - } catch (Exception e) { - e.printStackTrace(); - } - } - -}
\ No newline at end of file + public GT_MetaTileEntity_Hatch_Energy_RTG( + int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount) { + super(aID, aName, aNameRegional, aTier); + setInventoryContent(aInvSlotCount); + } + + public GT_MetaTileEntity_Hatch_Energy_RTG(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_Energy_RTG( + String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, int aInvSlotCount) { + super(aName, aTier, aDescription, aTextures); + setInventoryContent(aInvSlotCount); + } + + @Override + public String[] getDescription() { + String[] S = super.getDescription(); + final String[] desc = new String[S.length + 1]; + System.arraycopy(S, 0, desc, 0, S.length); + desc[S.length] = CORE.GT_Tooltip; + return desc; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { + aBaseTexture, + TexturesGtBlock.getTextureFromIcon(TexturesGtBlock.Overlay_Hatch_RTG_On, new short[] {220, 220, 220, 0}) + }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { + aBaseTexture, + TexturesGtBlock.getTextureFromIcon(TexturesGtBlock.Overlay_Hatch_RTG_Off, new short[] {220, 220, 220, 0}) + }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isInputFacing(byte aSide) { + return aSide == getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public long maxEUStore() { + return Long.MAX_VALUE / (Short.MAX_VALUE * Byte.MAX_VALUE); + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Energy_RTG(mName, mTier, mDescriptionArray, mTextures, 9); + } + + @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 true; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_3by3(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_3by3(aPlayerInventory, aBaseMetaTileEntity, "RTG Power Unit"); + } + + private static class Dat { + + protected final String mUniqueDataTag; + private final ItemStack mStack; + private final NBTTagCompound mNBT; + + public Dat(ItemStack aStack) { + mStack = aStack; + mNBT = (aStack.getTagCompound() != null ? aStack.getTagCompound() : new NBTTagCompound()); + mUniqueDataTag = "" + Item.getIdFromItem(aStack.getItem()) + "" + aStack.getItemDamage() + "" + 1 + "" + + mNBT.getId(); + } + + public int getKey() { + return Item.getIdFromItem(mStack.getItem()) + mStack.getItemDamage(); + } + } + + private static final HashMap<String, ItemStack> mFuelInstanceMap = new HashMap<String, ItemStack>(); + private static final HashMap<String, Long> mFuelValueMap = new HashMap<String, Long>(); + private static final HashMap<String, Integer> mFuelTypeMap = new HashMap<String, Integer>(); + private static final HashMap<Integer, String> mFuelTypeMapReverse = new HashMap<Integer, String>(); + + public static boolean registerPelletForHatch(ItemStack aStack, long aFuelValue) { + if (!ItemUtils.checkForInvalidItems(aStack)) { + return false; + } + ItemStack aTemp = aStack.copy(); + aTemp.stackSize = 1; + Dat aDat = new Dat(aTemp); + String aKey = aDat.mUniqueDataTag; + mFuelInstanceMap.put(aKey, aTemp); + mFuelValueMap.put(aKey, aFuelValue); + mFuelTypeMap.put(aKey, aDat.getKey()); + mFuelTypeMapReverse.put(aDat.getKey(), aKey); + Logger.INFO("RTG Hatch: Registered Fuel Pellet: " + ItemUtils.getItemName(aTemp) + ", Fuel Value: " + aFuelValue + + ", Key: " + aKey + ", Key2: " + aDat.getKey()); + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + InventoryUtils.sortInventoryItems(this); + } + if (aTimer % 100 == 0 && aBaseMetaTileEntity.isServerSide()) { + if (hasPellet(this)) { + Logger.INFO("Has Pellet"); + tryConsumePellet(this); + } + } + } + + private static void tryConsumePellet(GT_MetaTileEntity_Hatch_Energy_RTG aTile) { + ItemStack aPellet = getPelletToConsume(aTile); + if (aPellet != null) { + Logger.INFO("Found Pellet"); + long aFuel = getFuelValueOfPellet(aPellet); + if (aFuel > 0) { + Logger.INFO("Has Fuel Value: " + aFuel); + if (hasSpaceForEnergy(aTile, aFuel)) { + Logger.INFO("Can buffer"); + aPellet.stackSize = 0; + Logger.INFO("Stack set to 0"); + aPellet = null; + Logger.INFO("null stack"); + addEnergyToInternalStorage(aTile, aFuel); + Logger.INFO("Consumed"); + } + } + } + aTile.updateSlots(); + Logger.INFO("updating slots"); + } + + private static void addEnergyToInternalStorage(GT_MetaTileEntity_Hatch_Energy_RTG aTile, long aFuel) { + aTile.getBaseMetaTileEntity().increaseStoredEnergyUnits(aFuel, true); + } + + public static boolean hasSpaceForEnergy(GT_MetaTileEntity_Hatch_Energy_RTG aTile, long aAmount) { + long aMax = aTile.maxEUStore(); + long aCurrent = aTile.getEUVar(); + if ((aMax - aCurrent) >= aAmount) { + return true; + } + return false; + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) { + if (mInventory[i] != null && mInventory[i].stackSize <= 0) { + mInventory[i] = null; + } + } + InventoryUtils.sortInventoryItems(this); + } + + public static boolean hasPellet(GT_MetaTileEntity_Hatch_Energy_RTG aTile) { + for (ItemStack o : aTile.mInventory) { + if (o != null) { + for (ItemStack i : mFuelInstanceMap.values()) { + if (ItemUtils.areItemsEqual(o, i)) { + return true; + } + } + } + } + return false; + } + + public static String getPelletType(ItemStack o) { + if (o == null) { + return "error"; + } + Dat aDat = new Dat(o); + return mFuelTypeMapReverse.get(aDat.getKey()); + } + + public static long getFuelValueOfPellet(ItemStack aPellet) { + String aType = getPelletType(aPellet); + if (mFuelValueMap.containsKey(aType)) { + return mFuelValueMap.get(aType); + } + return 0; + } + + public static ItemStack getPelletToConsume(GT_MetaTileEntity_Hatch_Energy_RTG aTile) { + for (ItemStack o : aTile.mInventory) { + if (o != null) { + for (ItemStack i : mFuelInstanceMap.values()) { + if (ItemUtils.areItemsEqual(o, i)) { + return o; + } + } + } + } + return null; + } + + private void setInventoryContent(int aInvSlotCount) { + try { + Field fieldInventory = MetaTileEntity.class.getDeclaredField("mInventory"); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(fieldInventory, fieldInventory.getModifiers() & ~Modifier.PRIVATE & ~Modifier.FINAL); + fieldInventory.set(this, new ItemStack[aInvSlotCount]); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_FluidGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_FluidGenerator.java index c7e07b7534..b11b3bc78e 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_FluidGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_FluidGenerator.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import java.lang.reflect.Field; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; @@ -14,6 +12,7 @@ import gtPlusPlus.api.objects.random.XSTR; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import java.lang.reflect.Field; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -23,133 +22,130 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; public abstract class GT_MetaTileEntity_Hatch_FluidGenerator extends GT_MetaTileEntity_Hatch_Input { - - protected static XSTR floatGen = new XSTR(); + + protected static XSTR floatGen = new XSTR(); public int mProgresstime = 0, mMaxProgresstime = 0; - public GT_MetaTileEntity_Hatch_FluidGenerator(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier); - } - - public GT_MetaTileEntity_Hatch_FluidGenerator(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - private static String[] S; - private static Field F; - - public abstract String[] getCustomTooltip(); - - public abstract Fluid getFluidToGenerate(); - - public abstract int getAmountOfFluidToGenerate(); - - public abstract int getMaxTickTime(); - - public synchronized String[] getDescription() { - try { - if (F == null || S == null) { - Field t = ReflectionUtils.getField(this.getClass(), "mDescriptionArray"); - if (t != null) { - F = t; - } - else { - F = ReflectionUtils.getField(this.getClass(), "mDescription"); - } - if (S == null && F != null) { - Object o = F.get(this); - if (o instanceof String[]) { - S = (String[]) o; - } - else if (o instanceof String) { - S = new String[] {(String) o}; - } - } - - } - } - catch (Throwable t) { - Logger.INFO("1"); - t.printStackTrace(); - } - try { - if (S != null) { - String[] aCustomTips = getCustomTooltip(); - final String[] desc = new String[S.length + aCustomTips.length + 1]; - System.arraycopy(S, 0, desc, 0, S.length); - for (int i=0;i<aCustomTips.length;i++) { - desc[S.length + i] = aCustomTips[i]; - } - desc[S.length + aCustomTips.length] = CORE.GT_Tooltip; - return desc; - } - } - catch (Throwable t) { - Logger.INFO("2"); - t.printStackTrace(); - } - - return new String[] {"Broken Tooltip - Report on Github"}; - - } - - public ITexture[] getTexturesActive(final ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, - new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.OVERLAY_MUFFLER)}; - } - - public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, - new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.OVERLAY_MUFFLER)}; - } - - public boolean isSimpleMachine() { - return true; - } - - public boolean isFacingValid(final byte aFacing) { - return true; - } - - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - public boolean isValidSlot(final int aIndex) { - return false; - } - - public abstract MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity); - - public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - return false; - } - - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - return false; - } - - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (!aBaseMetaTileEntity.isAllowedToWork()) { - aBaseMetaTileEntity.setActive(false); - mProgresstime = 0; - mMaxProgresstime = 0; - } - else { - aBaseMetaTileEntity.setActive(true); - mMaxProgresstime = getMaxTickTime(); - if (++mProgresstime >= mMaxProgresstime) { - if (this.canTankBeFilled()) { - addFluidToHatch(aTick); - } - mProgresstime = 0; - } - } - } - + public GT_MetaTileEntity_Hatch_FluidGenerator( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_FluidGenerator( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + private static String[] S; + private static Field F; + + public abstract String[] getCustomTooltip(); + + public abstract Fluid getFluidToGenerate(); + + public abstract int getAmountOfFluidToGenerate(); + + public abstract int getMaxTickTime(); + + public synchronized String[] getDescription() { + try { + if (F == null || S == null) { + Field t = ReflectionUtils.getField(this.getClass(), "mDescriptionArray"); + if (t != null) { + F = t; + } else { + F = ReflectionUtils.getField(this.getClass(), "mDescription"); + } + if (S == null && F != null) { + Object o = F.get(this); + if (o instanceof String[]) { + S = (String[]) o; + } else if (o instanceof String) { + S = new String[] {(String) o}; + } + } + } + } catch (Throwable t) { + Logger.INFO("1"); + t.printStackTrace(); + } + try { + if (S != null) { + String[] aCustomTips = getCustomTooltip(); + final String[] desc = new String[S.length + aCustomTips.length + 1]; + System.arraycopy(S, 0, desc, 0, S.length); + for (int i = 0; i < aCustomTips.length; i++) { + desc[S.length + i] = aCustomTips[i]; + } + desc[S.length + aCustomTips.length] = CORE.GT_Tooltip; + return desc; + } + } catch (Throwable t) { + Logger.INFO("2"); + t.printStackTrace(); + } + + return new String[] {"Broken Tooltip - Report on Github"}; + } + + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] { + aBaseTexture, new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.OVERLAY_MUFFLER) + }; + } + + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] { + aBaseTexture, new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.OVERLAY_MUFFLER) + }; + } + + public boolean isSimpleMachine() { + return true; + } + + public boolean isFacingValid(final byte aFacing) { + return true; + } + + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + public boolean isValidSlot(final int aIndex) { + return false; + } + + public abstract MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity); + + public boolean allowPullStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (!aBaseMetaTileEntity.isAllowedToWork()) { + aBaseMetaTileEntity.setActive(false); + mProgresstime = 0; + mMaxProgresstime = 0; + } else { + aBaseMetaTileEntity.setActive(true); + mMaxProgresstime = getMaxTickTime(); + if (++mProgresstime >= mMaxProgresstime) { + if (this.canTankBeFilled()) { + addFluidToHatch(aTick); + } + mProgresstime = 0; + } + } + } + @Override public int getProgresstime() { return mProgresstime; @@ -166,62 +162,68 @@ public abstract class GT_MetaTileEntity_Hatch_FluidGenerator extends GT_MetaTile return mMaxProgresstime - mProgresstime; } - public abstract void generateParticles(final World aWorld, final String name); - - public int getTankPressure() { - return 100; - } - - public abstract int getCapacity(); - - @Override - public boolean canTankBeEmptied() { - return true; - } - - public abstract boolean doesHatchMeetConditionsToGenerate(); - - public boolean addFluidToHatch(long aTick) { - if (!doesHatchMeetConditionsToGenerate()) { - return false; - } - int aFillAmount = this.fill(FluidUtils.getFluidStack(getFluidToGenerate(), getAmountOfFluidToGenerate()), true); - if (aFillAmount > 0) { - if (this.getBaseMetaTileEntity().isClientSide()) { - generateParticles(this.getBaseMetaTileEntity().getWorld(), "cloud"); - } - } - return aFillAmount > 0; - } - - @Override - public boolean canTankBeFilled() { - if (this.getCapacity()-this.getFluidAmount() > 0) { - //Logger.INFO("Total Space: "+this.getCapacity()); - //Logger.INFO("Current amount: "+this.getFluidAmount()); - //Logger.INFO("To add: "+this.getAmountOfFluidToGenerate()); - //Logger.INFO("Space Free: "+(this.getCapacity()-this.getFluidAmount())); - } - if (this.mFluid == null || (this.mFluid != null && (this.getCapacity() - this.getFluidAmount() >= this.getAmountOfFluidToGenerate()))) { - return true; - } - return false; - } - - @Override - public boolean doesEmptyContainers() { - return false; - } - - @Override - public boolean doesFillContainers() { - return true; - } - - @Override - public int fill(FluidStack aFluid, boolean doFill) { - if (aFluid == null || aFluid.getFluid().getID() <= 0 || aFluid.amount <= 0 || aFluid.getFluid() != getFluidToGenerate() || !canTankBeFilled()) { - return 0; + public abstract void generateParticles(final World aWorld, final String name); + + public int getTankPressure() { + return 100; + } + + public abstract int getCapacity(); + + @Override + public boolean canTankBeEmptied() { + return true; + } + + public abstract boolean doesHatchMeetConditionsToGenerate(); + + public boolean addFluidToHatch(long aTick) { + if (!doesHatchMeetConditionsToGenerate()) { + return false; + } + int aFillAmount = this.fill(FluidUtils.getFluidStack(getFluidToGenerate(), getAmountOfFluidToGenerate()), true); + if (aFillAmount > 0) { + if (this.getBaseMetaTileEntity().isClientSide()) { + generateParticles(this.getBaseMetaTileEntity().getWorld(), "cloud"); + } + } + return aFillAmount > 0; + } + + @Override + public boolean canTankBeFilled() { + if (this.getCapacity() - this.getFluidAmount() > 0) { + // Logger.INFO("Total Space: "+this.getCapacity()); + // Logger.INFO("Current amount: "+this.getFluidAmount()); + // Logger.INFO("To add: "+this.getAmountOfFluidToGenerate()); + // Logger.INFO("Space Free: "+(this.getCapacity()-this.getFluidAmount())); + } + if (this.mFluid == null + || (this.mFluid != null + && (this.getCapacity() - this.getFluidAmount() >= this.getAmountOfFluidToGenerate()))) { + return true; + } + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public int fill(FluidStack aFluid, boolean doFill) { + if (aFluid == null + || aFluid.getFluid().getID() <= 0 + || aFluid.amount <= 0 + || aFluid.getFluid() != getFluidToGenerate() + || !canTankBeFilled()) { + return 0; } if (getFillableStack() == null || getFillableStack().getFluid().getID() <= 0) { @@ -240,8 +242,7 @@ public abstract class GT_MetaTileEntity_Hatch_FluidGenerator extends GT_MetaTile return getCapacity(); } - if (!getFillableStack().isFluidEqual(aFluid)) - return 0; + if (!getFillableStack().isFluidEqual(aFluid)) return 0; int space = getCapacity() - getFillableStack().amount; if (aFluid.amount <= space) { @@ -251,37 +252,36 @@ public abstract class GT_MetaTileEntity_Hatch_FluidGenerator extends GT_MetaTile } return aFluid.amount; } - if (doFill) - getFillableStack().amount = getCapacity(); + if (doFill) getFillableStack().amount = getCapacity(); return space; } - @Override - public boolean canFill(ForgeDirection aSide, Fluid aFluid) { - return false; - } - - @Override - public int fill(ForgeDirection arg0, FluidStack arg1, boolean arg2) { - return 0; - } - - @Override - public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { - return 0; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + return false; + } + + @Override + public int fill(ForgeDirection arg0, FluidStack arg1, boolean arg2) { + return 0; + } + + @Override + public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + return 0; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { aNBT.setInteger("mProgresstime", mProgresstime); aNBT.setInteger("mMaxProgresstime", mMaxProgresstime); - super.saveNBTData(aNBT); - } + super.saveNBTData(aNBT); + } - @Override - public void loadNBTData(NBTTagCompound aNBT) { + @Override + public void loadNBTData(NBTTagCompound aNBT) { mProgresstime = aNBT.getInteger("mProgresstime"); mMaxProgresstime = aNBT.getInteger("mMaxProgresstime"); - super.loadNBTData(aNBT); - } + super.loadNBTData(aNBT); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java index 57f8b722c3..d56a95d60f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java @@ -2,10 +2,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.V; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - import gregtech.api.enums.GT_Values; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -15,57 +11,48 @@ import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; - import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.hatches.charge.*; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; -public class GT_MetaTileEntity_Hatch_InputBattery -extends -GT_MetaTileEntity_Hatch { - public final GT_Recipe_Map mRecipeMap = null; +public class GT_MetaTileEntity_Hatch_InputBattery extends GT_MetaTileEntity_Hatch { + public final GT_Recipe_Map mRecipeMap = null; - public GT_MetaTileEntity_Hatch_InputBattery(int aID, String aName, - String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier), "Chargeable Item Bus for Multiblocks"); - } + public GT_MetaTileEntity_Hatch_InputBattery(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier), "Chargeable Item Bus for Multiblocks"); + } - public GT_MetaTileEntity_Hatch_InputBattery(String aName, int aTier, - String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, - aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 4 : 16, - aDescription, aTextures); - } + public GT_MetaTileEntity_Hatch_InputBattery( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 4 : 16, aDescription, aTextures); + } - @Override - public String[] getDescription() { - int mSlots = 0; - if (this.mTier == 2) { - mSlots = 4; - } - else if (this.mTier == 4) { - mSlots = 16; - } - else { - mSlots = 16; - } - return new String[]{ - this.mDescription, - "Capacity: " + mSlots + " slots", - CORE.GT_Tooltip}; - } + @Override + public String[] getDescription() { + int mSlots = 0; + if (this.mTier == 2) { + mSlots = 4; + } else if (this.mTier == 4) { + mSlots = 16; + } else { + mSlots = 16; + } + return new String[] {this.mDescription, "Capacity: " + mSlots + " slots", CORE.GT_Tooltip}; + } - @Override + @Override public boolean isEnetInput() { return true; } - @Override + @Override public boolean isInputFacing(byte aSide) { return aSide == getBaseMetaTileEntity().getFrontFacing(); } - @Override public long getMinimumStoredEU() { return 0; @@ -85,174 +72,171 @@ GT_MetaTileEntity_Hatch { public long maxAmperesIn() { return 4; } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, - new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Charger)}; - } - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, - new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Charger)}; - } + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Charger)}; + } - @Override - public boolean isSimpleMachine() { - return true; - } + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Charger)}; + } - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } + @Override + public boolean isSimpleMachine() { + return true; + } - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } - @Override - public boolean isValidSlot(int aIndex) { - return true; - } + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_InputBattery(mName, mTier, - mDescription, mTextures); - } + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_InputBattery(mName, mTier, mDescription, mTextures); + } - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, - EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) - return true; - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, - IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 2 : - return new CONTAINER_Electric_2by2(aPlayerInventory, - aBaseMetaTileEntity); - case 4 : - return new CONTAINER_Electric_4by4(aPlayerInventory, - aBaseMetaTileEntity); - default : - return new CONTAINER_Electric_4by4(aPlayerInventory, - aBaseMetaTileEntity); - } - } + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + switch (mTier) { + case 2: + return new CONTAINER_Electric_2by2(aPlayerInventory, aBaseMetaTileEntity); + case 4: + return new CONTAINER_Electric_4by4(aPlayerInventory, aBaseMetaTileEntity); + default: + return new CONTAINER_Electric_4by4(aPlayerInventory, aBaseMetaTileEntity); + } + } - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, - IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 2 : - return new GUI_Electric_2by2(aPlayerInventory, - aBaseMetaTileEntity, "Charging Bus"); - case 4 : - return new GUI_Electric_4by4(aPlayerInventory, - aBaseMetaTileEntity, "Charging Bus"); - default : - return new GUI_Electric_4by4(aPlayerInventory, - aBaseMetaTileEntity, "Charging Bus"); - } - } + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + switch (mTier) { + case 2: + return new GUI_Electric_2by2(aPlayerInventory, aBaseMetaTileEntity, "Charging Bus"); + case 4: + return new GUI_Electric_4by4(aPlayerInventory, aBaseMetaTileEntity, "Charging Bus"); + default: + return new GUI_Electric_4by4(aPlayerInventory, aBaseMetaTileEntity, "Charging Bus"); + } + } - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (aBaseMetaTileEntity.isServerSide() - && aBaseMetaTileEntity.hasInventoryBeenModified()) { - fillStacksIntoFirstSlots(); - } - if (aBaseMetaTileEntity.isServerSide()){ - if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity) { - MetaTileEntity mMetaTileEntity = (MetaTileEntity) aBaseMetaTileEntity.getMetaTileEntity(); - if (mMetaTileEntity.rechargerSlotCount() > 0 && aBaseMetaTileEntity.getStoredEU() > 0) { - for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { - if (aBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { - for (int u=0;u<10;u++){ - aBaseMetaTileEntity.decreaseStoredEnergyUnits(GT_ModHandler.chargeElectricItem(mMetaTileEntity.mInventory[i], (int) Math.min(V[this.mTier] * 15, aBaseMetaTileEntity.getStoredEU()), (int) Math.min(Integer.MAX_VALUE, GT_Values.V[u]), false, false), true); - if (mMetaTileEntity.mInventory[i].stackSize <= 0){ - mMetaTileEntity.mInventory[i] = null; - } - } - } - } - } - else { - //Utils.LOG_INFO("reCharger Slot Count = "+mMetaTileEntity.rechargerSlotCount()); - //Utils.LOG_INFO("getStoredEU = "+aBaseMetaTileEntity.getStoredEU()); - //Utils.LOG_INFO("getEUVar = "+mMetaTileEntity.getEUVar()); - } - } - } - super.onPostTick(aBaseMetaTileEntity, aTimer); - } + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + if (aBaseMetaTileEntity.isServerSide()) { + if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity) { + MetaTileEntity mMetaTileEntity = (MetaTileEntity) aBaseMetaTileEntity.getMetaTileEntity(); + if (mMetaTileEntity.rechargerSlotCount() > 0 && aBaseMetaTileEntity.getStoredEU() > 0) { + for (int i = mMetaTileEntity.rechargerSlotStartIndex(), + k = mMetaTileEntity.rechargerSlotCount() + i; + i < k; + i++) { + if (aBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { + for (int u = 0; u < 10; u++) { + aBaseMetaTileEntity.decreaseStoredEnergyUnits( + GT_ModHandler.chargeElectricItem( + mMetaTileEntity.mInventory[i], + (int) Math.min(V[this.mTier] * 15, aBaseMetaTileEntity.getStoredEU()), + (int) Math.min(Integer.MAX_VALUE, GT_Values.V[u]), + false, + false), + true); + if (mMetaTileEntity.mInventory[i].stackSize <= 0) { + mMetaTileEntity.mInventory[i] = null; + } + } + } + } + } else { + // Utils.LOG_INFO("reCharger Slot Count = "+mMetaTileEntity.rechargerSlotCount()); + // Utils.LOG_INFO("getStoredEU = "+aBaseMetaTileEntity.getStoredEU()); + // Utils.LOG_INFO("getEUVar = "+mMetaTileEntity.getEUVar()); + } + } + } + super.onPostTick(aBaseMetaTileEntity, aTimer); + } - public void updateSlots() { - for (int i = 0; i < mInventory.length; i++) - if (mInventory[i] != null && mInventory[i].stackSize <= 0) - mInventory[i] = null; - fillStacksIntoFirstSlots(); - } + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } - protected void fillStacksIntoFirstSlots() { - for (int i = 0; i < mInventory.length; i++) - for (int j = i + 1; j < mInventory.length; j++) - if (mInventory[j] != null - && (mInventory[i] == null || GT_Utility.areStacksEqual( - mInventory[i], mInventory[j]))) { - GT_Utility.moveStackFromSlotAToSlotB( - getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, - i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - } + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) + if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, - int aIndex, byte aSide, ItemStack aStack) { - return aSide == getBaseMetaTileEntity().getFrontFacing() - && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); - } + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aSide == getBaseMetaTileEntity().getFrontFacing() + && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); + } - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, - int aIndex, byte aSide, ItemStack aStack) { - return aSide == getBaseMetaTileEntity().getFrontFacing() - && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); - } + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aSide == getBaseMetaTileEntity().getFrontFacing() + && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); + } - @Override - public int rechargerSlotStartIndex() { - return 0; - } + @Override + public int rechargerSlotStartIndex() { + return 0; + } - @Override - public int rechargerSlotCount() { - switch (mTier) { - case 2 : - return 4; - case 4 : - return 16; - default : - return 16; - } - } + @Override + public int rechargerSlotCount() { + switch (mTier) { + case 2: + return 4; + case 4: + return 16; + default: + return 16; + } + } - @Override - public int dechargerSlotStartIndex() { - return 0; - } + @Override + public int dechargerSlotStartIndex() { + return 0; + } - @Override - public int dechargerSlotCount() { - return 0; - } + @Override + public int dechargerSlotCount() { + return 0; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java index ba4e394114..94b927c80d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java @@ -24,306 +24,314 @@ import net.minecraftforge.common.util.ForgeDirection; public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch_Muffler { - protected int SLOT_FILTER = 0; - - @Override - public void onConfigLoad(GT_Config aConfig) { - super.onConfigLoad(aConfig); - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK || CORE.GTNH) { - try { - Integer a1 = (int) StaticFields59.getFieldFromGregtechProxy("mPollutionSmogLimit"); - if (a1 != null && a1 > 0) { - mPollutionSmogLimit = a1; - } - } - catch (Throwable t) { - mPollutionSmogLimit = 500000; - } - } - } - - private int mPollutionSmogLimit = 500000; - - public GT_MetaTileEntity_Hatch_Muffler_Adv(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier); - ReflectionUtils.setField(this, "mInventory", new ItemStack[1]); - } - - public GT_MetaTileEntity_Hatch_Muffler_Adv(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - ReflectionUtils.setField(this, "mInventory", new ItemStack[1]); - } - - public GT_MetaTileEntity_Hatch_Muffler_Adv(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription[0], aTextures); - ReflectionUtils.setField(this, "mInventory", new ItemStack[1]); - } - - public String[] getDescription() { - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - String[] mDescArray = StaticFields59.getDescriptionArray(this); - String[] desc = new String[mDescArray.length + 7]; - System.arraycopy(mDescArray, 0, desc, 0, mDescArray.length); - desc[mDescArray.length] = "DO NOT OBSTRUCT THE OUTPUT!"; - desc[mDescArray.length + 1] = "Requires 3 Air on the exhaust face"; - desc[mDescArray.length + 2] = "Requires Air Filters"; - desc[mDescArray.length + 3] = "Mufflers require T2 Filters from IV-"+GT_Values.VN[9]; - desc[mDescArray.length + 4] = "Reduces Pollution to " + this.calculatePollutionReductionForTooltip(100) + "%"; - desc[mDescArray.length + 5] = "Recovers " + (105 - this.calculatePollutionReductionForTooltip(100)) + "% of CO2/CO/SO2"; - desc[mDescArray.length + 6] = CORE.GT_Tooltip; - return desc; - } - else { - return new String[] {}; - } - } - - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Muffler_Adv)}; - } - - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Muffler_Adv)}; - } - - public boolean isValidSlot(int aIndex) { - return aIndex == SLOT_FILTER; - } - - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_Muffler_Adv(this.mName, this.mTier, StaticFields59.getDescriptionArray(this), this.mTextures); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, - EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) - return true; - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - - - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_Hatch_Muffler_Advanced(aPlayerInventory, aBaseMetaTileEntity); - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_Hatch_Muffler_Advanced(aPlayerInventory, aBaseMetaTileEntity, "Advanced Muffler", "machine_Charger.png"); - } - - private boolean airCheck() { - if ( - this.getBaseMetaTileEntity().getAirAtSide(this.getBaseMetaTileEntity().getFrontFacing()) && - this.getBaseMetaTileEntity().getAirAtSideAndDistance(this.getBaseMetaTileEntity().getFrontFacing(), 1) && - this.getBaseMetaTileEntity().getAirAtSideAndDistance(this.getBaseMetaTileEntity().getFrontFacing(), 2) - ) { - return true; - } - return false; - } - - public boolean polluteEnvironment() { - if (airCheck() && damageAirFilter()) { - int aEmission = this.calculatePollutionReduction(10000); - PollutionUtils.addPollution(this.getBaseMetaTileEntity(), aEmission); - //Logger.INFO("Outputting "+aEmission+"gbl"); - return true; - } else { - //Logger.INFO("Failed to output pollution"); - return false; - } - } - - - public int calculatePollutionReductionForTooltip(int aPollution) { - return (int) (aPollution * Math.pow(0.64D, (double) (this.mTier - 1))); - } - - public int calculatePollutionReduction(int aPollution) { - double aVal1 = aPollution * Math.pow(0.64D, (double) (this.mTier - 1)); - int aVal2 = (int) aVal1; - if (!hasValidFilter()) { - aVal2 = (int) ((double) aPollution * Math.pow(0.7D, (double) (this.mTier - 1)));; - } - return aVal2; - } - - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - if (aIndex == this.SLOT_FILTER) { - if (isAirFilter(aStack)) { - return true; - } - } - return false; - } - - private ItemStack getInventoryStack() { - if (this.mInventory != null && this.mInventory.length > 0) { - if (this.mInventory.length-1 >= this.SLOT_FILTER) { - return this.mInventory[this.SLOT_FILTER]; - } - } - return null; - } - - private void breakAirFilter() { - if (this.mInventory != null && this.mInventory.length > 0) { - if (this.mInventory.length-1 >= this.SLOT_FILTER) { - Logger.INFO("Breaking Filter"); - this.mInventory[this.SLOT_FILTER] = null; - } - } - } - - public boolean hasValidFilter() { - return isAirFilter(getInventoryStack()); - } - - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - - //Logger.INFO("A1"); - - super.onPostTick(aBaseMetaTileEntity, aTick); - - //Logger.INFO("A2"); - - String aParticleName; - if ((aTick % 2) == 0){ - aParticleName = "cloud"; - } - else { - aParticleName = "smoke"; - } - - //Logger.INFO("A3"); - - if (aBaseMetaTileEntity.isClientSide()) { - //Logger.INFO("B1"); - if (this.getBaseMetaTileEntity().isActive()) { - //Logger.INFO("C1"); - this.pollutionParticles(this.getBaseMetaTileEntity().getWorld(), aParticleName); - } - //return; - } - else { - //Logger.INFO("B2"); - if (this.getInventoryStack() == null) { - //Logger.INFO("D1"); - //Logger.INFO("Empty - "+this.mInventory.length); - } - else { - //Logger.INFO("D2"); - } - } - //Logger.INFO("A4"); - - - - } - - public boolean isAirFilter(ItemStack filter){ - if (filter == null) { - return false; - } - if (filter.getItem() instanceof ItemAirFilter){ - - if (this.mTier < 5) { - return true; - } - else { - if (filter.getItemDamage() == 1) { - return true; - } - } - } - return false; - } - - public boolean damageAirFilter(){ - ItemStack filter = getInventoryStack(); - if (filter == null) { - return false; - } - - if (isAirFilter(filter)){ - long currentUse = ItemAirFilter.getFilterDamage(filter); - Logger.INFO("Filter Damage: "+currentUse); - //Remove broken Filter - if ((filter.getItemDamage() == 0 && currentUse >= 50-1) || (filter.getItemDamage() == 1 && currentUse >= 2500-1)){ - breakAirFilter(); - return true; - } - else { - //Do Damage - ItemAirFilter.setFilterDamage(filter, currentUse+1); - Logger.INFO("Filter Damage now: "+currentUse); - return true; - } - } - return false; - } - - public void pollutionParticles(World aWorld, String name) { - float ran1 = CORE.RANDOM.nextFloat(); - float ran2 = 0.0F; - float ran3 = 0.0F; - boolean chk1 = ran1 * 100.0F < (float) this.calculatePollutionReduction(100); - boolean chk2; - boolean chk3; - int aPollutionAmount = PollutionUtils.getPollution(getBaseMetaTileEntity()); - if (aPollutionAmount >= mPollutionSmogLimit) { - ran2 = CORE.RANDOM.nextFloat(); - ran3 = CORE.RANDOM.nextFloat(); - chk2 = ran2 * 100.0F < (float) this.calculatePollutionReduction(100); - chk3 = ran3 * 100.0F < (float) this.calculatePollutionReduction(100); - if (!chk1 && !chk2 && !chk3) { - return; - } - } else { - if (!chk1) { - return; - } - - chk3 = false; - chk2 = false; - } - - IGregTechTileEntity aMuffler = this.getBaseMetaTileEntity(); - ForgeDirection aDir = ForgeDirection.getOrientation(aMuffler.getFrontFacing()); - float xPos = (float) aDir.offsetX * 0.76F + (float) aMuffler.getXCoord() + 0.25F; - float yPos = (float) aDir.offsetY * 0.76F + (float) aMuffler.getYCoord() + 0.25F; - float zPos = (float) aDir.offsetZ * 0.76F + (float) aMuffler.getZCoord() + 0.25F; - float ySpd = (float) aDir.offsetY * 0.1F + 0.2F + 0.1F * CORE.RANDOM.nextFloat(); - float xSpd; - float zSpd; - if (aDir.offsetY == -1) { - float temp = CORE.RANDOM.nextFloat() * 2.0F * CORE.PI; - xSpd = (float) Math.sin((double) temp) * 0.1F; - zSpd = (float) Math.cos((double) temp) * 0.1F; - } else { - xSpd = (float) aDir.offsetX * (0.1F + 0.2F * CORE.RANDOM.nextFloat()); - zSpd = (float) aDir.offsetZ * (0.1F + 0.2F * CORE.RANDOM.nextFloat()); - } - - if (chk1) { - aWorld.spawnParticle(name, (double) (xPos + ran1 * 0.5F), (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), - (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), (double) xSpd, (double) ySpd, (double) zSpd); - } - - if (chk2) { - aWorld.spawnParticle(name, (double) (xPos + ran2 * 0.5F), (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), - (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), (double) xSpd, (double) ySpd, (double) zSpd); - } - - if (chk3) { - aWorld.spawnParticle(name, (double) (xPos + ran3 * 0.5F), (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), - (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), (double) xSpd, (double) ySpd, (double) zSpd); - } - - } - - - -}
\ No newline at end of file + protected int SLOT_FILTER = 0; + + @Override + public void onConfigLoad(GT_Config aConfig) { + super.onConfigLoad(aConfig); + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK || CORE.GTNH) { + try { + Integer a1 = (int) StaticFields59.getFieldFromGregtechProxy("mPollutionSmogLimit"); + if (a1 != null && a1 > 0) { + mPollutionSmogLimit = a1; + } + } catch (Throwable t) { + mPollutionSmogLimit = 500000; + } + } + } + + private int mPollutionSmogLimit = 500000; + + public GT_MetaTileEntity_Hatch_Muffler_Adv(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + ReflectionUtils.setField(this, "mInventory", new ItemStack[1]); + } + + public GT_MetaTileEntity_Hatch_Muffler_Adv(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + ReflectionUtils.setField(this, "mInventory", new ItemStack[1]); + } + + public GT_MetaTileEntity_Hatch_Muffler_Adv( + String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription[0], aTextures); + ReflectionUtils.setField(this, "mInventory", new ItemStack[1]); + } + + public String[] getDescription() { + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + String[] mDescArray = StaticFields59.getDescriptionArray(this); + String[] desc = new String[mDescArray.length + 7]; + System.arraycopy(mDescArray, 0, desc, 0, mDescArray.length); + desc[mDescArray.length] = "DO NOT OBSTRUCT THE OUTPUT!"; + desc[mDescArray.length + 1] = "Requires 3 Air on the exhaust face"; + desc[mDescArray.length + 2] = "Requires Air Filters"; + desc[mDescArray.length + 3] = "Mufflers require T2 Filters from IV-" + GT_Values.VN[9]; + desc[mDescArray.length + 4] = + "Reduces Pollution to " + this.calculatePollutionReductionForTooltip(100) + "%"; + desc[mDescArray.length + 5] = + "Recovers " + (105 - this.calculatePollutionReductionForTooltip(100)) + "% of CO2/CO/SO2"; + desc[mDescArray.length + 6] = CORE.GT_Tooltip; + return desc; + } else { + return new String[] {}; + } + } + + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Muffler_Adv)}; + } + + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Muffler_Adv)}; + } + + public boolean isValidSlot(int aIndex) { + return aIndex == SLOT_FILTER; + } + + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Muffler_Adv( + this.mName, this.mTier, StaticFields59.getDescriptionArray(this), this.mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_Hatch_Muffler_Advanced(aPlayerInventory, aBaseMetaTileEntity); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_Hatch_Muffler_Advanced( + aPlayerInventory, aBaseMetaTileEntity, "Advanced Muffler", "machine_Charger.png"); + } + + private boolean airCheck() { + if (this.getBaseMetaTileEntity() + .getAirAtSide(this.getBaseMetaTileEntity().getFrontFacing()) + && this.getBaseMetaTileEntity() + .getAirAtSideAndDistance(this.getBaseMetaTileEntity().getFrontFacing(), 1) + && this.getBaseMetaTileEntity() + .getAirAtSideAndDistance(this.getBaseMetaTileEntity().getFrontFacing(), 2)) { + return true; + } + return false; + } + + public boolean polluteEnvironment() { + if (airCheck() && damageAirFilter()) { + int aEmission = this.calculatePollutionReduction(10000); + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), aEmission); + // Logger.INFO("Outputting "+aEmission+"gbl"); + return true; + } else { + // Logger.INFO("Failed to output pollution"); + return false; + } + } + + public int calculatePollutionReductionForTooltip(int aPollution) { + return (int) (aPollution * Math.pow(0.64D, (double) (this.mTier - 1))); + } + + public int calculatePollutionReduction(int aPollution) { + double aVal1 = aPollution * Math.pow(0.64D, (double) (this.mTier - 1)); + int aVal2 = (int) aVal1; + if (!hasValidFilter()) { + aVal2 = (int) ((double) aPollution * Math.pow(0.7D, (double) (this.mTier - 1))); + ; + } + return aVal2; + } + + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + if (aIndex == this.SLOT_FILTER) { + if (isAirFilter(aStack)) { + return true; + } + } + return false; + } + + private ItemStack getInventoryStack() { + if (this.mInventory != null && this.mInventory.length > 0) { + if (this.mInventory.length - 1 >= this.SLOT_FILTER) { + return this.mInventory[this.SLOT_FILTER]; + } + } + return null; + } + + private void breakAirFilter() { + if (this.mInventory != null && this.mInventory.length > 0) { + if (this.mInventory.length - 1 >= this.SLOT_FILTER) { + Logger.INFO("Breaking Filter"); + this.mInventory[this.SLOT_FILTER] = null; + } + } + } + + public boolean hasValidFilter() { + return isAirFilter(getInventoryStack()); + } + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + + // Logger.INFO("A1"); + + super.onPostTick(aBaseMetaTileEntity, aTick); + + // Logger.INFO("A2"); + + String aParticleName; + if ((aTick % 2) == 0) { + aParticleName = "cloud"; + } else { + aParticleName = "smoke"; + } + + // Logger.INFO("A3"); + + if (aBaseMetaTileEntity.isClientSide()) { + // Logger.INFO("B1"); + if (this.getBaseMetaTileEntity().isActive()) { + // Logger.INFO("C1"); + this.pollutionParticles(this.getBaseMetaTileEntity().getWorld(), aParticleName); + } + // return; + } else { + // Logger.INFO("B2"); + if (this.getInventoryStack() == null) { + // Logger.INFO("D1"); + // Logger.INFO("Empty - "+this.mInventory.length); + } else { + // Logger.INFO("D2"); + } + } + // Logger.INFO("A4"); + + } + + public boolean isAirFilter(ItemStack filter) { + if (filter == null) { + return false; + } + if (filter.getItem() instanceof ItemAirFilter) { + + if (this.mTier < 5) { + return true; + } else { + if (filter.getItemDamage() == 1) { + return true; + } + } + } + return false; + } + + public boolean damageAirFilter() { + ItemStack filter = getInventoryStack(); + if (filter == null) { + return false; + } + + if (isAirFilter(filter)) { + long currentUse = ItemAirFilter.getFilterDamage(filter); + Logger.INFO("Filter Damage: " + currentUse); + // Remove broken Filter + if ((filter.getItemDamage() == 0 && currentUse >= 50 - 1) + || (filter.getItemDamage() == 1 && currentUse >= 2500 - 1)) { + breakAirFilter(); + return true; + } else { + // Do Damage + ItemAirFilter.setFilterDamage(filter, currentUse + 1); + Logger.INFO("Filter Damage now: " + currentUse); + return true; + } + } + return false; + } + + public void pollutionParticles(World aWorld, String name) { + float ran1 = CORE.RANDOM.nextFloat(); + float ran2 = 0.0F; + float ran3 = 0.0F; + boolean chk1 = ran1 * 100.0F < (float) this.calculatePollutionReduction(100); + boolean chk2; + boolean chk3; + int aPollutionAmount = PollutionUtils.getPollution(getBaseMetaTileEntity()); + if (aPollutionAmount >= mPollutionSmogLimit) { + ran2 = CORE.RANDOM.nextFloat(); + ran3 = CORE.RANDOM.nextFloat(); + chk2 = ran2 * 100.0F < (float) this.calculatePollutionReduction(100); + chk3 = ran3 * 100.0F < (float) this.calculatePollutionReduction(100); + if (!chk1 && !chk2 && !chk3) { + return; + } + } else { + if (!chk1) { + return; + } + + chk3 = false; + chk2 = false; + } + + IGregTechTileEntity aMuffler = this.getBaseMetaTileEntity(); + ForgeDirection aDir = ForgeDirection.getOrientation(aMuffler.getFrontFacing()); + float xPos = (float) aDir.offsetX * 0.76F + (float) aMuffler.getXCoord() + 0.25F; + float yPos = (float) aDir.offsetY * 0.76F + (float) aMuffler.getYCoord() + 0.25F; + float zPos = (float) aDir.offsetZ * 0.76F + (float) aMuffler.getZCoord() + 0.25F; + float ySpd = (float) aDir.offsetY * 0.1F + 0.2F + 0.1F * CORE.RANDOM.nextFloat(); + float xSpd; + float zSpd; + if (aDir.offsetY == -1) { + float temp = CORE.RANDOM.nextFloat() * 2.0F * CORE.PI; + xSpd = (float) Math.sin((double) temp) * 0.1F; + zSpd = (float) Math.cos((double) temp) * 0.1F; + } else { + xSpd = (float) aDir.offsetX * (0.1F + 0.2F * CORE.RANDOM.nextFloat()); + zSpd = (float) aDir.offsetZ * (0.1F + 0.2F * CORE.RANDOM.nextFloat()); + } + + if (chk1) { + aWorld.spawnParticle( + name, + (double) (xPos + ran1 * 0.5F), + (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) xSpd, + (double) ySpd, + (double) zSpd); + } + + if (chk2) { + aWorld.spawnParticle( + name, + (double) (xPos + ran2 * 0.5F), + (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) xSpd, + (double) ySpd, + (double) zSpd); + } + + if (chk3) { + aWorld.spawnParticle( + name, + (double) (xPos + ran3 * 0.5F), + (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) xSpd, + (double) ySpd, + (double) zSpd); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java index d0f1d8e03f..350b7a788a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import java.lang.reflect.Field; - import gregtech.api.enums.Materials; import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons; @@ -15,194 +13,209 @@ import gregtech.api.util.GT_Utility; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.common.StaticFields59; +import java.lang.reflect.Field; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.FluidStack; public class GT_MetaTileEntity_Hatch_Naquadah extends GT_MetaTileEntity_Hatch_Input { - public final FluidStack[] mFluidsToUse = new FluidStack[3]; - public final int mFluidCapacity; - - public GT_MetaTileEntity_Hatch_Naquadah(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional, 6); - mFluidCapacity = 32000; - initHatch(); - } - - public GT_MetaTileEntity_Hatch_Naquadah(final String aName, final String aDescription, - final ITexture[][][] aTextures) { - super(aName, 6, aDescription, aTextures); - mFluidCapacity = 32000; - initHatch(); - } - - public GT_MetaTileEntity_Hatch_Naquadah(final String aName, final String[] aDescription, - final ITexture[][][] aTextures) { - super(aName, 6, aDescription[0], aTextures); - mFluidCapacity = 32000; - initHatch(); - } - - private void initHatch() { - if (mFluidsToUse[0] == null) { - mFluidsToUse[0] = Materials.Naquadah.getMolten(1); - } - if (mFluidsToUse[1] == null) { - mFluidsToUse[1] = Materials.NaquadahEnriched.getMolten(1); - } - if (mFluidsToUse[2] == null) { - mFluidsToUse[2] = Materials.Naquadria.getMolten(1); - } - } - - public ITexture[] getTexturesActive(final ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE_ACTIVE) }; - } - - public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE) }; - } - - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - if (aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 0) { - for (FluidStack f : mFluidsToUse) { - if (f != null) { - if (GT_Utility.getFluidForFilledItem(aStack, true).getFluid() == f.getFluid()) { - return true; - } - } - } - } - return false; - } - - public boolean isFluidInputAllowed(final FluidStack aFluid) { - for (FluidStack f : mFluidsToUse) { - if (f != null) { - if (aFluid.getFluid() == f.getFluid()) { - return true; - } - } - } - return false; - } - - public int getCapacity() { - return this.mFluidCapacity; - } - - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return (MetaTileEntity) new GT_MetaTileEntity_Hatch_Naquadah(this.mName, this.mDescription, this.mTextures); - } - - @Override - public String[] getDescription() { - if (aDescCache[0] == null || aDescCache[0].contains(".name") || aDescCache[0].contains("fluid.")) { - aDescCache[0] = formatFluidString(this.mFluidsToUse[0]); - } - if (aDescCache[1] == null || aDescCache[1].contains(".name") || aDescCache[1].contains("fluid.")) { - aDescCache[1] = formatFluidString(this.mFluidsToUse[1]); - } - if (aDescCache[2] == null || aDescCache[2].contains(".name") || aDescCache[2].contains("fluid.")) { - aDescCache[2] = formatFluidString(this.mFluidsToUse[2]); - } - String aNaq = aDescCache[0]; - String aEnrNaq = aDescCache[1]; - String aNaquad = aDescCache[2]; - String[] s2 = new String[]{ - "Fluid Input for Multiblocks", - "Capacity: " + getCapacity()+"L", - "Accepted Fluid: " + aNaq, - "Accepted Fluid: " + aEnrNaq, - "Accepted Fluid: " + aNaquad, - CORE.GT_Tooltip - }; - return s2; - } - - private static String[] aDescCache = new String[3]; - private String formatFluidString(FluidStack f) { - FluidStack mLockedStack = f; - Integer mLockedTemp = 0;; - String mTempMod = ""+EnumChatFormatting.RESET; - mLockedTemp = mLockedStack.getFluid().getTemperature(); - if (mLockedTemp != null) { - if (mLockedTemp <= -3000) { - mTempMod = ""+EnumChatFormatting.DARK_PURPLE; - } - else if (mLockedTemp >= -2999 && mLockedTemp <= -500) { - mTempMod = ""+EnumChatFormatting.DARK_BLUE; - } - else if (mLockedTemp >= -499 && mLockedTemp <= -50) { - mTempMod = ""+EnumChatFormatting.BLUE; - } - else if (mLockedTemp >= 30 && mLockedTemp <= 300) { - mTempMod = ""+EnumChatFormatting.AQUA; - } - else if (mLockedTemp >= 301 && mLockedTemp <= 800) { - mTempMod = ""+EnumChatFormatting.YELLOW; - } - else if (mLockedTemp >= 801 && mLockedTemp <= 1500) { - mTempMod = ""+EnumChatFormatting.GOLD; - } - else if (mLockedTemp >= 1501) { - mTempMod = ""+EnumChatFormatting.RED; - } - } - return mTempMod + mLockedStack.getLocalizedName(); - } - - @Override - public boolean doesFillContainers() { - return false; - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - // TODO Auto-generated method stub - return super.getTextureSet(aTextures); - } - - private Field F1, F2; - - - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - byte a1 = 0, a2 = 0; - try { - if (F1 == null) { - F1 = ReflectionUtils.getField(getClass(), "actualTexture"); - } - if (F2 == null) { - F2 = ReflectionUtils.getField(getClass(), "mTexturePage"); - } - - if (F1 != null) { - a1 = F1.getByte(this); - } - if (F2 != null) { - a2 = F2.getByte(this); - } - } - catch (IllegalArgumentException | IllegalAccessException n) {} - - int textureIndex = a1 | a2 << 7; - byte texturePointer = (byte) (a1 & 127); - - - - if (aSide == 1 || aSide == 0) { - ITexture g = textureIndex > 0 ? StaticFields59.getCasingTexturePages(a2, texturePointer) : BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]; - - return new ITexture[] {g, new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_TOP_ACTIVE) }; - } - - return aSide != aFacing ? - (textureIndex > 0 ? new ITexture[] { StaticFields59.getCasingTexturePages(a2, texturePointer) } : new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1] }) - : (textureIndex > 0 ? (aActive ? this.getTexturesActive(StaticFields59.getCasingTexturePages(a2, texturePointer)) : this.getTexturesInactive(StaticFields59.getCasingTexturePages(a2, texturePointer))) - : (aActive ? this.getTexturesActive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]) : this.getTexturesInactive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]))); - } - + public final FluidStack[] mFluidsToUse = new FluidStack[3]; + public final int mFluidCapacity; + + public GT_MetaTileEntity_Hatch_Naquadah(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional, 6); + mFluidCapacity = 32000; + initHatch(); + } + + public GT_MetaTileEntity_Hatch_Naquadah( + final String aName, final String aDescription, final ITexture[][][] aTextures) { + super(aName, 6, aDescription, aTextures); + mFluidCapacity = 32000; + initHatch(); + } + + public GT_MetaTileEntity_Hatch_Naquadah( + final String aName, final String[] aDescription, final ITexture[][][] aTextures) { + super(aName, 6, aDescription[0], aTextures); + mFluidCapacity = 32000; + initHatch(); + } + + private void initHatch() { + if (mFluidsToUse[0] == null) { + mFluidsToUse[0] = Materials.Naquadah.getMolten(1); + } + if (mFluidsToUse[1] == null) { + mFluidsToUse[1] = Materials.NaquadahEnriched.getMolten(1); + } + if (mFluidsToUse[2] == null) { + mFluidsToUse[2] = Materials.Naquadria.getMolten(1); + } + } + + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] { + aBaseTexture, + new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE_ACTIVE) + }; + } + + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] { + aBaseTexture, new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE) + }; + } + + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + if (aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 0) { + for (FluidStack f : mFluidsToUse) { + if (f != null) { + if (GT_Utility.getFluidForFilledItem(aStack, true).getFluid() == f.getFluid()) { + return true; + } + } + } + } + return false; + } + + public boolean isFluidInputAllowed(final FluidStack aFluid) { + for (FluidStack f : mFluidsToUse) { + if (f != null) { + if (aFluid.getFluid() == f.getFluid()) { + return true; + } + } + } + return false; + } + + public int getCapacity() { + return this.mFluidCapacity; + } + + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return (MetaTileEntity) new GT_MetaTileEntity_Hatch_Naquadah(this.mName, this.mDescription, this.mTextures); + } + + @Override + public String[] getDescription() { + if (aDescCache[0] == null || aDescCache[0].contains(".name") || aDescCache[0].contains("fluid.")) { + aDescCache[0] = formatFluidString(this.mFluidsToUse[0]); + } + if (aDescCache[1] == null || aDescCache[1].contains(".name") || aDescCache[1].contains("fluid.")) { + aDescCache[1] = formatFluidString(this.mFluidsToUse[1]); + } + if (aDescCache[2] == null || aDescCache[2].contains(".name") || aDescCache[2].contains("fluid.")) { + aDescCache[2] = formatFluidString(this.mFluidsToUse[2]); + } + String aNaq = aDescCache[0]; + String aEnrNaq = aDescCache[1]; + String aNaquad = aDescCache[2]; + String[] s2 = new String[] { + "Fluid Input for Multiblocks", + "Capacity: " + getCapacity() + "L", + "Accepted Fluid: " + aNaq, + "Accepted Fluid: " + aEnrNaq, + "Accepted Fluid: " + aNaquad, + CORE.GT_Tooltip + }; + return s2; + } + + private static String[] aDescCache = new String[3]; + + private String formatFluidString(FluidStack f) { + FluidStack mLockedStack = f; + Integer mLockedTemp = 0; + ; + String mTempMod = "" + EnumChatFormatting.RESET; + mLockedTemp = mLockedStack.getFluid().getTemperature(); + if (mLockedTemp != null) { + if (mLockedTemp <= -3000) { + mTempMod = "" + EnumChatFormatting.DARK_PURPLE; + } else if (mLockedTemp >= -2999 && mLockedTemp <= -500) { + mTempMod = "" + EnumChatFormatting.DARK_BLUE; + } else if (mLockedTemp >= -499 && mLockedTemp <= -50) { + mTempMod = "" + EnumChatFormatting.BLUE; + } else if (mLockedTemp >= 30 && mLockedTemp <= 300) { + mTempMod = "" + EnumChatFormatting.AQUA; + } else if (mLockedTemp >= 301 && mLockedTemp <= 800) { + mTempMod = "" + EnumChatFormatting.YELLOW; + } else if (mLockedTemp >= 801 && mLockedTemp <= 1500) { + mTempMod = "" + EnumChatFormatting.GOLD; + } else if (mLockedTemp >= 1501) { + mTempMod = "" + EnumChatFormatting.RED; + } + } + return mTempMod + mLockedStack.getLocalizedName(); + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + // TODO Auto-generated method stub + return super.getTextureSet(aTextures); + } + + private Field F1, F2; + + @Override + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + byte a1 = 0, a2 = 0; + try { + if (F1 == null) { + F1 = ReflectionUtils.getField(getClass(), "actualTexture"); + } + if (F2 == null) { + F2 = ReflectionUtils.getField(getClass(), "mTexturePage"); + } + + if (F1 != null) { + a1 = F1.getByte(this); + } + if (F2 != null) { + a2 = F2.getByte(this); + } + } catch (IllegalArgumentException | IllegalAccessException n) { + } + + int textureIndex = a1 | a2 << 7; + byte texturePointer = (byte) (a1 & 127); + + if (aSide == 1 || aSide == 0) { + ITexture g = textureIndex > 0 + ? StaticFields59.getCasingTexturePages(a2, texturePointer) + : BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]; + + return new ITexture[] { + g, new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_TOP_ACTIVE) + }; + } + + return aSide != aFacing + ? (textureIndex > 0 + ? new ITexture[] {StaticFields59.getCasingTexturePages(a2, texturePointer)} + : new ITexture[] {BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]}) + : (textureIndex > 0 + ? (aActive + ? this.getTexturesActive(StaticFields59.getCasingTexturePages(a2, texturePointer)) + : this.getTexturesInactive(StaticFields59.getCasingTexturePages(a2, texturePointer))) + : (aActive + ? this.getTexturesActive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]) + : this.getTexturesInactive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]))); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java index ba97cc38eb..d6b0a570ac 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java @@ -2,10 +2,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.V; -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; @@ -13,224 +9,215 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; - import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.gui.hatches.charge.*; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; -public class GT_MetaTileEntity_Hatch_OutputBattery -extends -GT_MetaTileEntity_Hatch { - public GT_MetaTileEntity_Hatch_OutputBattery(int aID, String aName, - String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier), - "Dischargeable Item Bus for Multiblocks"); - } - - public GT_MetaTileEntity_Hatch_OutputBattery(String aName, int aTier, - String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, - aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, - aDescription, aTextures); - } - - - @Override - public String[] getDescription() { - int mSlots = 0; - if (this.mTier == 2) { - mSlots = 4; - } - else if (this.mTier == 4) { - mSlots = 16; - } - else { - mSlots = 16; - } - return new String[]{ - this.mDescription, - "Capacity: " + mSlots + " slots", - CORE.GT_Tooltip}; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isOutputFacing(byte aSide) { - return aSide == getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public long getMinimumStoredEU() { - return 0; - } - - @Override - public long maxEUOutput() { - return V[mTier]; - } - - @Override - public long maxEUStore() { - return 512 + V[mTier + 1] * 8; - } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, - new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Discharger)}; - } - - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, - new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Discharger)}; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isValidSlot(int aIndex) { - return true; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_OutputBattery(mName, mTier, - mDescription, mTextures); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, - EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) - return true; - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, - IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 2 : - return new CONTAINER_Electric_2by2(aPlayerInventory, - aBaseMetaTileEntity); - case 4 : - return new CONTAINER_Electric_4by4(aPlayerInventory, - aBaseMetaTileEntity); - default : - return new CONTAINER_Electric_4by4(aPlayerInventory, - aBaseMetaTileEntity); - } - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, - IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 2 : - return new GUI_Electric_2by2(aPlayerInventory, - aBaseMetaTileEntity, "Discharging Bus"); - case 4 : - return new GUI_Electric_4by4(aPlayerInventory, - aBaseMetaTileEntity, "Discharging Bus"); - default : - return new GUI_Electric_4by4(aPlayerInventory, - aBaseMetaTileEntity, "Discharging Bus"); - } - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, - int aIndex, byte aSide, ItemStack aStack) { - return aSide == aBaseMetaTileEntity.getFrontFacing(); - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, - int aIndex, byte aSide, ItemStack aStack) { - return aSide == aBaseMetaTileEntity.getFrontFacing(); - } - - public void updateSlots() { - for (int i = 0; i < mInventory.length; i++) - if (mInventory[i] != null && mInventory[i].stackSize <= 0) - mInventory[i] = null; - fillStacksIntoFirstSlots(); - } - - protected void fillStacksIntoFirstSlots() { - for (int i = 0; i < mInventory.length; i++) - for (int j = i + 1; j < mInventory.length; j++) - if (mInventory[j] != null - && (mInventory[i] == null || GT_Utility.areStacksEqual( - mInventory[i], mInventory[j]))) { - GT_Utility.moveStackFromSlotAToSlotB( - getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, - i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - } - - @Override - public int rechargerSlotStartIndex() { - return 0; - } - - @Override - public int rechargerSlotCount() { - return 0; - } - - @Override - public int dechargerSlotStartIndex() { - return 0; - } - - @Override - public int dechargerSlotCount() { - return mTier == 2 ? 4 : 16; - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (aBaseMetaTileEntity.isServerSide() - && aBaseMetaTileEntity.hasInventoryBeenModified()) { - fillStacksIntoFirstSlots(); - } - - if (aBaseMetaTileEntity.isServerSide()){ - if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity) { - MetaTileEntity mMetaTileEntity = (MetaTileEntity) aBaseMetaTileEntity.getMetaTileEntity(); - if (mMetaTileEntity.dechargerSlotCount() > 0 && mMetaTileEntity.getEUVar() < aBaseMetaTileEntity.getEUCapacity()) { - for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) { - if (mMetaTileEntity.mInventory[i] != null && mMetaTileEntity.getEUVar() < aBaseMetaTileEntity.getEUCapacity()) { - aBaseMetaTileEntity.increaseStoredEnergyUnits(GT_ModHandler.dischargeElectricItem(mMetaTileEntity.mInventory[i], (int) Math.min(V[mTier] * 15, aBaseMetaTileEntity.getEUCapacity() - aBaseMetaTileEntity.getStoredEU()), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), true, false, false), true); - if (mMetaTileEntity.mInventory[i].stackSize <= 0) - mMetaTileEntity.mInventory[i] = null; - } - } - } - } - } - super.onPostTick(aBaseMetaTileEntity, aTimer); - } - - +public class GT_MetaTileEntity_Hatch_OutputBattery extends GT_MetaTileEntity_Hatch { + public GT_MetaTileEntity_Hatch_OutputBattery(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier), "Dischargeable Item Bus for Multiblocks"); + } + + public GT_MetaTileEntity_Hatch_OutputBattery( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + int mSlots = 0; + if (this.mTier == 2) { + mSlots = 4; + } else if (this.mTier == 4) { + mSlots = 16; + } else { + mSlots = 16; + } + return new String[] {this.mDescription, "Capacity: " + mSlots + " slots", CORE.GT_Tooltip}; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isOutputFacing(byte aSide) { + return aSide == getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUOutput() { + return V[mTier]; + } + + @Override + public long maxEUStore() { + return 512 + V[mTier + 1] * 8; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Discharger)}; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Discharger)}; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_OutputBattery(mName, mTier, mDescription, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + switch (mTier) { + case 2: + return new CONTAINER_Electric_2by2(aPlayerInventory, aBaseMetaTileEntity); + case 4: + return new CONTAINER_Electric_4by4(aPlayerInventory, aBaseMetaTileEntity); + default: + return new CONTAINER_Electric_4by4(aPlayerInventory, aBaseMetaTileEntity); + } + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + switch (mTier) { + case 2: + return new GUI_Electric_2by2(aPlayerInventory, aBaseMetaTileEntity, "Discharging Bus"); + case 4: + return new GUI_Electric_4by4(aPlayerInventory, aBaseMetaTileEntity, "Discharging Bus"); + default: + return new GUI_Electric_4by4(aPlayerInventory, aBaseMetaTileEntity, "Discharging Bus"); + } + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aSide == aBaseMetaTileEntity.getFrontFacing(); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aSide == aBaseMetaTileEntity.getFrontFacing(); + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) + if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return mTier == 2 ? 4 : 16; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + + if (aBaseMetaTileEntity.isServerSide()) { + if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity) { + MetaTileEntity mMetaTileEntity = (MetaTileEntity) aBaseMetaTileEntity.getMetaTileEntity(); + if (mMetaTileEntity.dechargerSlotCount() > 0 + && mMetaTileEntity.getEUVar() < aBaseMetaTileEntity.getEUCapacity()) { + for (int i = mMetaTileEntity.dechargerSlotStartIndex(), + k = mMetaTileEntity.dechargerSlotCount() + i; + i < k; + i++) { + if (mMetaTileEntity.mInventory[i] != null + && mMetaTileEntity.getEUVar() < aBaseMetaTileEntity.getEUCapacity()) { + aBaseMetaTileEntity.increaseStoredEnergyUnits( + GT_ModHandler.dischargeElectricItem( + mMetaTileEntity.mInventory[i], + (int) Math.min( + V[mTier] * 15, + aBaseMetaTileEntity.getEUCapacity() + - aBaseMetaTileEntity.getStoredEU()), + (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), + true, + false, + false), + true); + if (mMetaTileEntity.mInventory[i].stackSize <= 0) mMetaTileEntity.mInventory[i] = null; + } + } + } + } + } + super.onPostTick(aBaseMetaTileEntity, aTimer); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Plasma.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Plasma.java index 1251c42ae3..7f09abf177 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Plasma.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Plasma.java @@ -1,9 +1,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import java.lang.reflect.Field; - import com.google.common.collect.BiMap; - import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -14,6 +11,7 @@ import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.common.StaticFields59; +import java.lang.reflect.Field; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.Fluid; @@ -22,198 +20,201 @@ import net.minecraftforge.fluids.FluidStack; public class GT_MetaTileEntity_Hatch_Plasma extends GT_MetaTileEntity_Hatch_Output { - public final AutoMap<Fluid> mFluidsToUse = new AutoMap<Fluid>(); - public final int mFluidCapacity; - private int mTotalPlasmaSupported = -1; - - public GT_MetaTileEntity_Hatch_Plasma(final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional, 6); - mFluidCapacity = 256000; - initHatch(); - } - - public GT_MetaTileEntity_Hatch_Plasma(final String aName, final String aDescription, - final ITexture[][][] aTextures) { - super(aName, 6, aDescription, aTextures); - mFluidCapacity = 256000; - initHatch(); - } - - public GT_MetaTileEntity_Hatch_Plasma(final String aName, final String[] aDescription, - final ITexture[][][] aTextures) { - super(aName, 6, aDescription[0], aTextures); - mFluidCapacity = 256000; - initHatch(); - } - - private void initHatch() { - - //Get all Plasmas, but the easiest way to do this is to just ask the Fluid Registry what exists and filter through them lazily. - Field fluidNameCache; - - fluidNameCache = ReflectionUtils.getField(FluidRegistry.class, "fluidNames"); - - AutoMap<String> mValidPlasmaNameCache = new AutoMap<String>(); - if (fluidNameCache != null) { - try { - Object fluidNames = fluidNameCache.get(null); - if (fluidNames != null) { - try { - @SuppressWarnings("unchecked") - BiMap<Integer, String> fluidNamesMap = (BiMap<Integer, String>) fluidNames; - if (fluidNamesMap != null) { - for (String g : fluidNamesMap.values()) { - if (g.toLowerCase().contains("plasma")) { - mValidPlasmaNameCache.put(g); - } - } - } - } catch (ClassCastException e) { - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - } - } - - AutoMap<Fluid> mPlasmaCache = new AutoMap<Fluid>(); - if (!mValidPlasmaNameCache.isEmpty()) { - for (String y : mValidPlasmaNameCache) { - Fluid t = FluidRegistry.getFluid(y); - if (t != null) { - if (t.getTemperature() > 1000) { - mPlasmaCache.put(t); - } - } - } - } - - if (!mPlasmaCache.isEmpty()) { - for (Fluid w : mPlasmaCache) { - mFluidsToUse.put(w); - } - } - - - - - - } - - public ITexture[] getTexturesActive(final ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture }; - } - - public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture }; - } - - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - if (aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 0) { - for (Fluid f : mFluidsToUse) { - if (f != null) { - if (GT_Utility.getFluidForFilledItem(aStack, true).getFluid() == f) { - return true; - } - } - } - } - return false; - } - - public boolean isFluidInputAllowed(final FluidStack aFluid) { - for (Fluid f : mFluidsToUse) { - if (f != null) { - if (aFluid.getFluid() == f) { - return true; - } - } - } - return false; - } - - public int getCapacity() { - return this.mFluidCapacity; - } - - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return (MetaTileEntity) new GT_MetaTileEntity_Hatch_Plasma(this.mName, this.mDescription, this.mTextures); - } - - @Override - public String[] getDescription() { - - if (mTotalPlasmaSupported < 0) { - if (mFluidsToUse.isEmpty()) { - mTotalPlasmaSupported = 0; - } - else { - mTotalPlasmaSupported = mFluidsToUse.size(); - } - } - - String aX = EnumChatFormatting.GRAY+""; - String a1 = EnumChatFormatting.GOLD+"Refined containment"+aX; - String a2 = EnumChatFormatting.GOLD+"Capacity: "+EnumChatFormatting.DARK_AQUA+getCapacity()+"L"+aX; - String a3 = EnumChatFormatting.GOLD+"Supports "+EnumChatFormatting.DARK_RED+mTotalPlasmaSupported+EnumChatFormatting.GOLD+" types of plasma"+aX; - - - - String[] s2 = new String[]{ - a1, a2, a3, CORE.GT_Tooltip - }; - return s2; - } - - @Override - public boolean doesFillContainers() { - return true; - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - // TODO Auto-generated method stub - return super.getTextureSet(aTextures); - } - - private Field F1, F2; - - - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - byte a1 = 0, a2 = 0; - try { - if (F1 == null) { - F1 = ReflectionUtils.getField(getClass(), "actualTexture"); - } - if (F2 == null) { - F2 = ReflectionUtils.getField(getClass(), "mTexturePage"); - } - - if (F1 != null) { - a1 = F1.getByte(this); - } - if (F2 != null) { - a2 = F2.getByte(this); - } - } - catch (IllegalArgumentException | IllegalAccessException n) {} - - int textureIndex = a1 | a2 << 7; - byte texturePointer = (byte) (a1 & 127); - - - - if (aSide == 1 || aSide == 0) { - ITexture g = textureIndex > 0 ? StaticFields59.getCasingTexturePages(a2, texturePointer) : BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]; - - return new ITexture[] {g}; - } - - return aSide != aFacing ? - (textureIndex > 0 ? new ITexture[] { StaticFields59.getCasingTexturePages(a2, texturePointer) } : new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1] }) - : (textureIndex > 0 ? (aActive ? this.getTexturesActive(StaticFields59.getCasingTexturePages(a2, texturePointer)) : this.getTexturesInactive(StaticFields59.getCasingTexturePages(a2, texturePointer))) - : (aActive ? this.getTexturesActive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]) : this.getTexturesInactive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]))); - } - + public final AutoMap<Fluid> mFluidsToUse = new AutoMap<Fluid>(); + public final int mFluidCapacity; + private int mTotalPlasmaSupported = -1; + + public GT_MetaTileEntity_Hatch_Plasma(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional, 6); + mFluidCapacity = 256000; + initHatch(); + } + + public GT_MetaTileEntity_Hatch_Plasma( + final String aName, final String aDescription, final ITexture[][][] aTextures) { + super(aName, 6, aDescription, aTextures); + mFluidCapacity = 256000; + initHatch(); + } + + public GT_MetaTileEntity_Hatch_Plasma( + final String aName, final String[] aDescription, final ITexture[][][] aTextures) { + super(aName, 6, aDescription[0], aTextures); + mFluidCapacity = 256000; + initHatch(); + } + + private void initHatch() { + + // Get all Plasmas, but the easiest way to do this is to just ask the Fluid Registry what exists and filter + // through them lazily. + Field fluidNameCache; + + fluidNameCache = ReflectionUtils.getField(FluidRegistry.class, "fluidNames"); + + AutoMap<String> mValidPlasmaNameCache = new AutoMap<String>(); + if (fluidNameCache != null) { + try { + Object fluidNames = fluidNameCache.get(null); + if (fluidNames != null) { + try { + @SuppressWarnings("unchecked") + BiMap<Integer, String> fluidNamesMap = (BiMap<Integer, String>) fluidNames; + if (fluidNamesMap != null) { + for (String g : fluidNamesMap.values()) { + if (g.toLowerCase().contains("plasma")) { + mValidPlasmaNameCache.put(g); + } + } + } + } catch (ClassCastException e) { + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + } + } + + AutoMap<Fluid> mPlasmaCache = new AutoMap<Fluid>(); + if (!mValidPlasmaNameCache.isEmpty()) { + for (String y : mValidPlasmaNameCache) { + Fluid t = FluidRegistry.getFluid(y); + if (t != null) { + if (t.getTemperature() > 1000) { + mPlasmaCache.put(t); + } + } + } + } + + if (!mPlasmaCache.isEmpty()) { + for (Fluid w : mPlasmaCache) { + mFluidsToUse.put(w); + } + } + } + + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture}; + } + + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture}; + } + + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + if (aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 0) { + for (Fluid f : mFluidsToUse) { + if (f != null) { + if (GT_Utility.getFluidForFilledItem(aStack, true).getFluid() == f) { + return true; + } + } + } + } + return false; + } + + public boolean isFluidInputAllowed(final FluidStack aFluid) { + for (Fluid f : mFluidsToUse) { + if (f != null) { + if (aFluid.getFluid() == f) { + return true; + } + } + } + return false; + } + + public int getCapacity() { + return this.mFluidCapacity; + } + + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return (MetaTileEntity) new GT_MetaTileEntity_Hatch_Plasma(this.mName, this.mDescription, this.mTextures); + } + + @Override + public String[] getDescription() { + + if (mTotalPlasmaSupported < 0) { + if (mFluidsToUse.isEmpty()) { + mTotalPlasmaSupported = 0; + } else { + mTotalPlasmaSupported = mFluidsToUse.size(); + } + } + + String aX = EnumChatFormatting.GRAY + ""; + String a1 = EnumChatFormatting.GOLD + "Refined containment" + aX; + String a2 = EnumChatFormatting.GOLD + "Capacity: " + EnumChatFormatting.DARK_AQUA + getCapacity() + "L" + aX; + String a3 = EnumChatFormatting.GOLD + "Supports " + EnumChatFormatting.DARK_RED + mTotalPlasmaSupported + + EnumChatFormatting.GOLD + " types of plasma" + aX; + + String[] s2 = new String[] {a1, a2, a3, CORE.GT_Tooltip}; + return s2; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + // TODO Auto-generated method stub + return super.getTextureSet(aTextures); + } + + private Field F1, F2; + + @Override + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + byte a1 = 0, a2 = 0; + try { + if (F1 == null) { + F1 = ReflectionUtils.getField(getClass(), "actualTexture"); + } + if (F2 == null) { + F2 = ReflectionUtils.getField(getClass(), "mTexturePage"); + } + + if (F1 != null) { + a1 = F1.getByte(this); + } + if (F2 != null) { + a2 = F2.getByte(this); + } + } catch (IllegalArgumentException | IllegalAccessException n) { + } + + int textureIndex = a1 | a2 << 7; + byte texturePointer = (byte) (a1 & 127); + + if (aSide == 1 || aSide == 0) { + ITexture g = textureIndex > 0 + ? StaticFields59.getCasingTexturePages(a2, texturePointer) + : BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]; + + return new ITexture[] {g}; + } + + return aSide != aFacing + ? (textureIndex > 0 + ? new ITexture[] {StaticFields59.getCasingTexturePages(a2, texturePointer)} + : new ITexture[] {BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]}) + : (textureIndex > 0 + ? (aActive + ? this.getTexturesActive(StaticFields59.getCasingTexturePages(a2, texturePointer)) + : this.getTexturesInactive(StaticFields59.getCasingTexturePages(a2, texturePointer))) + : (aActive + ? this.getTexturesActive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]) + : this.getTexturesInactive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]))); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java index 75c5dbb9ee..0a2ccdb8e5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java @@ -18,106 +18,109 @@ import net.minecraftforge.fluids.IFluidHandler; public class GT_MetaTileEntity_Hatch_Reservoir extends GT_MetaTileEntity_Hatch_FluidGenerator { - private static Block sBlock_EIO; - private static Block sBlock_RIO; - - public GT_MetaTileEntity_Hatch_Reservoir(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier); - } - - public GT_MetaTileEntity_Hatch_Reservoir(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_Reservoir(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public String[] getCustomTooltip() { - String[] aTooltip = new String[3]; - aTooltip[0] = "Requires a Block of water facing the intake"; - aTooltip[1] = "Infinite water supply hatch"; - aTooltip[2] = "Creates 8000L of Water every 4 ticks"; - return aTooltip; - } - - @Override - public Fluid getFluidToGenerate() { - return FluidRegistry.WATER; - } - - @Override - public int getAmountOfFluidToGenerate() { - return 8000; - } - - @Override - public int getMaxTickTime() { - return 4; - } - - @Override - public int getCapacity() { - return 256000; - } - - private static void setCrossModData() { - if (LoadedMods.EnderIO && sBlock_EIO == null) { - sBlock_EIO = GameRegistry.findBlock("EnderIO", "blockReservoir"); - } - if (LoadedMods.RemoteIO && sBlock_RIO == null) { - sBlock_RIO = GameRegistry.findBlock("RIO", "machine"); - } - } - - public static boolean isTileValid(TileEntity aTile) { - if (aTile != null) { - if (aTile instanceof IFluidHandler) { - IFluidHandler aFluidHandler = (IFluidHandler) aTile; - return aFluidHandler.canDrain(ForgeDirection.UNKNOWN, FluidRegistry.WATER); - } - } - return false; - } - - @Override - public boolean doesHatchMeetConditionsToGenerate() { - Block aWater = this.getBaseMetaTileEntity().getBlockAtSide(this.getBaseMetaTileEntity().getFrontFacing()); - if (aWater != null && aWater != Blocks.air) { - if (!this.canTankBeFilled()) { - return false; - } - setCrossModData(); - if (LoadedMods.EnderIO) { - if (aWater == sBlock_EIO) { - return isTileValid(this.getBaseMetaTileEntity().getTileEntityAtSide(this.getBaseMetaTileEntity().getFrontFacing())); - } - } - if (LoadedMods.RemoteIO) { - if (aWater == sBlock_RIO && this.getBaseMetaTileEntity().getMetaIDAtSide(this.getBaseMetaTileEntity().getFrontFacing()) == 0) { - return isTileValid(this.getBaseMetaTileEntity().getTileEntityAtSide(this.getBaseMetaTileEntity().getFrontFacing())); - } - } - return aWater == Blocks.water || aWater == Blocks.flowing_water; - } - return false; - } - - @Override - public void generateParticles(World aWorld, String name) { - - } - - public ITexture[] getTexturesActive(final ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, - new GT_RenderedTexture(TexturesGtBlock.Overlay_Water)}; - } - - public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, - new GT_RenderedTexture(TexturesGtBlock.Overlay_Water)}; - } + private static Block sBlock_EIO; + private static Block sBlock_RIO; + public GT_MetaTileEntity_Hatch_Reservoir( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_Reservoir( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Reservoir(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public String[] getCustomTooltip() { + String[] aTooltip = new String[3]; + aTooltip[0] = "Requires a Block of water facing the intake"; + aTooltip[1] = "Infinite water supply hatch"; + aTooltip[2] = "Creates 8000L of Water every 4 ticks"; + return aTooltip; + } + + @Override + public Fluid getFluidToGenerate() { + return FluidRegistry.WATER; + } + + @Override + public int getAmountOfFluidToGenerate() { + return 8000; + } + + @Override + public int getMaxTickTime() { + return 4; + } + + @Override + public int getCapacity() { + return 256000; + } + + private static void setCrossModData() { + if (LoadedMods.EnderIO && sBlock_EIO == null) { + sBlock_EIO = GameRegistry.findBlock("EnderIO", "blockReservoir"); + } + if (LoadedMods.RemoteIO && sBlock_RIO == null) { + sBlock_RIO = GameRegistry.findBlock("RIO", "machine"); + } + } + + public static boolean isTileValid(TileEntity aTile) { + if (aTile != null) { + if (aTile instanceof IFluidHandler) { + IFluidHandler aFluidHandler = (IFluidHandler) aTile; + return aFluidHandler.canDrain(ForgeDirection.UNKNOWN, FluidRegistry.WATER); + } + } + return false; + } + + @Override + public boolean doesHatchMeetConditionsToGenerate() { + Block aWater = this.getBaseMetaTileEntity() + .getBlockAtSide(this.getBaseMetaTileEntity().getFrontFacing()); + if (aWater != null && aWater != Blocks.air) { + if (!this.canTankBeFilled()) { + return false; + } + setCrossModData(); + if (LoadedMods.EnderIO) { + if (aWater == sBlock_EIO) { + return isTileValid(this.getBaseMetaTileEntity() + .getTileEntityAtSide(this.getBaseMetaTileEntity().getFrontFacing())); + } + } + if (LoadedMods.RemoteIO) { + if (aWater == sBlock_RIO + && this.getBaseMetaTileEntity() + .getMetaIDAtSide( + this.getBaseMetaTileEntity().getFrontFacing()) + == 0) { + return isTileValid(this.getBaseMetaTileEntity() + .getTileEntityAtSide(this.getBaseMetaTileEntity().getFrontFacing())); + } + } + return aWater == Blocks.water || aWater == Blocks.flowing_water; + } + return false; + } + + @Override + public void generateParticles(World aWorld, String name) {} + + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Water)}; + } + + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Water)}; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusInput.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusInput.java index f1dd131a67..2f3574ed5d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusInput.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusInput.java @@ -10,225 +10,302 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; -import gtPlusPlus.core.lib.CORE; import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; 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_Hatch_Steam_BusInput extends GT_MetaTileEntity_Hatch { - public GT_Recipe_Map mRecipeMap = null; - public boolean disableSort; - - public GT_MetaTileEntity_Hatch_Steam_BusInput(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[]{ - "Item Input for Steam Multiblocks", - "Shift + right click with screwdriver to toggle automatic item shuffling", - "Capacity: 4 stacks", - "Does not work with non-steam multiblocks", - CORE.GT_Tooltip}); - } - - public GT_MetaTileEntity_Hatch_Steam_BusInput(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 4, aDescription, aTextures); - } - - public GT_MetaTileEntity_Hatch_Steam_BusInput(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 4, aDescription, aTextures); - } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_IN)}; - } - - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_IN)}; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isValidSlot(int aIndex) { - return true; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_Steam_BusInput(mName, mTier, mDescriptionArray, mTextures); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, "Steam Input Bus"); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { - fillStacksIntoFirstSlots(); - } - } - - public void updateSlots() { - for (int i = 0; i < mInventory.length; i++) - if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; - fillStacksIntoFirstSlots(); - } - - protected void fillStacksIntoFirstSlots() { - if (disableSort) { - for (int i = 0; i < mInventory.length; i++) - if (mInventory[i] != null && mInventory[i].stackSize <= 0) - mInventory[i] = null; - } else { - for (int i = 0; i < mInventory.length; i++) - for (int j = i + 1; j < mInventory.length; j++) - if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) - GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("disableSort", disableSort); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - disableSort = aNBT.getBoolean("disableSort"); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (aPlayer.isSneaking()) { - disableSort = !disableSort; - GT_Utility.sendChatToPlayer(aPlayer, trans("200", "Automatic Item Shuffling: " + (disableSort ? "Disabled" : "Enabled"))); - } - } - - public String trans(String aKey, String aEnglish) { - return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aKey, aEnglish, 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 aSide == getBaseMetaTileEntity().getFrontFacing() && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); - } - - - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[14][17][]; - for (byte c = -1; c < 16; c++) { - if (rTextures[0][c + 1] == null) rTextures[0][c + 1] = getSideFacingActive(c); - if (rTextures[1][c + 1] == null) rTextures[1][c + 1] = getSideFacingInactive(c); - if (rTextures[2][c + 1] == null) rTextures[2][c + 1] = getFrontFacingActive(c); - if (rTextures[3][c + 1] == null) rTextures[3][c + 1] = getFrontFacingInactive(c); - if (rTextures[4][c + 1] == null) rTextures[4][c + 1] = getTopFacingActive(c); - if (rTextures[5][c + 1] == null) rTextures[5][c + 1] = getTopFacingInactive(c); - if (rTextures[6][c + 1] == null) rTextures[6][c + 1] = getBottomFacingActive(c); - if (rTextures[7][c + 1] == null) rTextures[7][c + 1] = getBottomFacingInactive(c); - if (rTextures[8][c + 1] == null) rTextures[8][c + 1] = getBottomFacingPipeActive(c); - if (rTextures[9][c + 1] == null) rTextures[9][c + 1] = getBottomFacingPipeInactive(c); - if (rTextures[10][c + 1] == null) rTextures[10][c + 1] = getTopFacingPipeActive(c); - if (rTextures[11][c + 1] == null) rTextures[11][c + 1] = getTopFacingPipeInactive(c); - if (rTextures[12][c + 1] == null) rTextures[12][c + 1] = getSideFacingPipeActive(c); - if (rTextures[13][c + 1] == null) rTextures[13][c + 1] = getSideFacingPipeInactive(c); - } - return rTextures; - } - - public ITexture[] getSideFacingActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE)}; - } - - public ITexture[] getSideFacingInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE)}; - } - - public ITexture[] getFrontFacingActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE)}; - } - - public ITexture[] getFrontFacingInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE)}; - } - - public ITexture[] getTopFacingActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP)}; - } - - public ITexture[] getTopFacingInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP)}; - } - - public ITexture[] getBottomFacingActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM)}; - } - - public ITexture[] getBottomFacingInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM)}; - } - - public ITexture[] getBottomFacingPipeActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - - public ITexture[] getBottomFacingPipeInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - - public ITexture[] getTopFacingPipeActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - - public ITexture[] getTopFacingPipeInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - - public ITexture[] getSideFacingPipeActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - - public ITexture[] getSideFacingPipeInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - - + public GT_Recipe_Map mRecipeMap = null; + public boolean disableSort; + + public GT_MetaTileEntity_Hatch_Steam_BusInput(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[] { + "Item Input for Steam Multiblocks", + "Shift + right click with screwdriver to toggle automatic item shuffling", + "Capacity: 4 stacks", + "Does not work with non-steam multiblocks", + CORE.GT_Tooltip + }); + } + + public GT_MetaTileEntity_Hatch_Steam_BusInput( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_Steam_BusInput( + String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_IN)}; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_IN)}; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Steam_BusInput(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, "Steam Input Bus"); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + if (disableSort) { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + } else { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) + if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("disableSort", disableSort); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + disableSort = aNBT.getBoolean("disableSort"); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + disableSort = !disableSort; + GT_Utility.sendChatToPlayer( + aPlayer, trans("200", "Automatic Item Shuffling: " + (disableSort ? "Disabled" : "Enabled"))); + } + } + + public String trans(String aKey, String aEnglish) { + return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aKey, aEnglish, 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 aSide == getBaseMetaTileEntity().getFrontFacing() + && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[14][17][]; + for (byte c = -1; c < 16; c++) { + if (rTextures[0][c + 1] == null) rTextures[0][c + 1] = getSideFacingActive(c); + if (rTextures[1][c + 1] == null) rTextures[1][c + 1] = getSideFacingInactive(c); + if (rTextures[2][c + 1] == null) rTextures[2][c + 1] = getFrontFacingActive(c); + if (rTextures[3][c + 1] == null) rTextures[3][c + 1] = getFrontFacingInactive(c); + if (rTextures[4][c + 1] == null) rTextures[4][c + 1] = getTopFacingActive(c); + if (rTextures[5][c + 1] == null) rTextures[5][c + 1] = getTopFacingInactive(c); + if (rTextures[6][c + 1] == null) rTextures[6][c + 1] = getBottomFacingActive(c); + if (rTextures[7][c + 1] == null) rTextures[7][c + 1] = getBottomFacingInactive(c); + if (rTextures[8][c + 1] == null) rTextures[8][c + 1] = getBottomFacingPipeActive(c); + if (rTextures[9][c + 1] == null) rTextures[9][c + 1] = getBottomFacingPipeInactive(c); + if (rTextures[10][c + 1] == null) rTextures[10][c + 1] = getTopFacingPipeActive(c); + if (rTextures[11][c + 1] == null) rTextures[11][c + 1] = getTopFacingPipeInactive(c); + if (rTextures[12][c + 1] == null) rTextures[12][c + 1] = getSideFacingPipeActive(c); + if (rTextures[13][c + 1] == null) rTextures[13][c + 1] = getSideFacingPipeInactive(c); + } + return rTextures; + } + + public ITexture[] getSideFacingActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE) + }; + } + + public ITexture[] getSideFacingInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE) + }; + } + + public ITexture[] getFrontFacingActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE) + }; + } + + public ITexture[] getFrontFacingInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE) + }; + } + + public ITexture[] getTopFacingActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP) + }; + } + + public ITexture[] getTopFacingInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP) + }; + } + + public ITexture[] getBottomFacingActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM + : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM) + }; + } + + public ITexture[] getBottomFacingInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM + : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM) + }; + } + + public ITexture[] getBottomFacingPipeActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM + : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; + } + + public ITexture[] getBottomFacingPipeInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM + : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; + } + + public ITexture[] getTopFacingPipeActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; + } + + public ITexture[] getTopFacingPipeInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; + } + + public ITexture[] getSideFacingPipeActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; + } + + public ITexture[] getSideFacingPipeInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusOutput.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusOutput.java index 2fb3fea084..fa5cf4bd5b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusOutput.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusOutput.java @@ -15,28 +15,32 @@ import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_Hatch_Steam_BusOutput extends GT_MetaTileEntity_Hatch { public GT_MetaTileEntity_Hatch_Steam_BusOutput(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 4, new String[]{"Item Output for Steam Multiblocks", - "Capacity: 4 stacks", - "Does not work with non-steam multiblocks", - CORE.GT_Tooltip}); + super(aID, aName, aNameRegional, aTier, 4, new String[] { + "Item Output for Steam Multiblocks", + "Capacity: 4 stacks", + "Does not work with non-steam multiblocks", + CORE.GT_Tooltip + }); } - public GT_MetaTileEntity_Hatch_Steam_BusOutput(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + public GT_MetaTileEntity_Hatch_Steam_BusOutput( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { super(aName, aTier, 4, aDescription, aTextures); } - public GT_MetaTileEntity_Hatch_Steam_BusOutput(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + public GT_MetaTileEntity_Hatch_Steam_BusOutput( + String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { super(aName, aTier, 4, aDescription, aTextures); } @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; } @Override public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; } @Override @@ -73,12 +77,12 @@ public class GT_MetaTileEntity_Hatch_Steam_BusOutput extends GT_MetaTileEntity_H @Override public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); + return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); } @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, "Steam Output Bus"); + return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, "Steam Output Bus"); } @Override @@ -90,8 +94,6 @@ public class GT_MetaTileEntity_Hatch_Steam_BusOutput extends GT_MetaTileEntity_H public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return false; } - - @Override public ITexture[][][] getTextureSet(ITexture[] aTextures) { @@ -114,62 +116,128 @@ public class GT_MetaTileEntity_Hatch_Steam_BusOutput extends GT_MetaTileEntity_H } return rTextures; } - - public ITexture[] getSideFacingActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE) + }; } public ITexture[] getSideFacingInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE) + }; } public ITexture[] getFrontFacingActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE) + }; } public ITexture[] getFrontFacingInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE) + }; } public ITexture[] getTopFacingActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP) + }; } public ITexture[] getTopFacingInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP) + }; } public ITexture[] getBottomFacingActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM + : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM) + }; } public ITexture[] getBottomFacingInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM + : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM) + }; } public ITexture[] getBottomFacingPipeActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM + : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getBottomFacingPipeInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM + : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getTopFacingPipeActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getTopFacingPipeInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getSideFacingPipeActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } public ITexture[] getSideFacingPipeInactive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 + ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE + : Textures.BlockIcons.MACHINE_BRONZE_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) + }; } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Turbine.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Turbine.java index 69f7f98606..5973d21fc5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Turbine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Turbine.java @@ -30,376 +30,389 @@ import net.minecraft.nbt.NBTTagCompound; @SuppressWarnings("deprecation") public class GT_MetaTileEntity_Hatch_Turbine extends GT_MetaTileEntity_Hatch { - public boolean mHasController = false; - public boolean mUsingAnimation = true; - private String mControllerLocation; - public int mEUt = 0; - - public GT_MetaTileEntity_Hatch_Turbine(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 16, "Turbine Rotor holder for XL Turbines"); - } - - public GT_MetaTileEntity_Hatch_Turbine(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 1, aDescription, aTextures); - } - - public GT_MetaTileEntity_Hatch_Turbine(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 1, aDescription[0], aTextures); - } - - @Override - public String[] getDescription() { - return new String[]{ - this.mDescription, - "Right Click with a soldering iron to reset controller link", - "Right Click with a wrench to remove turbine", - "Right Click with a screwdriver for technical information", - "Sneak + Right Click with a wrench to rotate", - "Sneak + Right Click with a screwdriver to disable animations", - CORE.GT_Tooltip}; - } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, getFrontFacingTurbineTexture()}; - } - - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, getFrontFacingTurbineTexture()}; - } - - public int getEU() { - return this.mEUt; - } - - public void setEU(int aEU) { - this.mEUt = aEU; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isValidSlot(int aIndex) { - return false; - } - - public boolean hasTurbine() { - ItemStack aStack = this.mInventory[0]; - boolean aIsValid = GregtechMetaTileEntity_LargerTurbineBase.isValidTurbine(aStack); - return aIsValid; - } - - public ItemStack getTurbine() { - if (hasTurbine()) { - return this.mInventory[0]; - } - return null; - } - - public boolean canWork() { - return hasTurbine(); - } - - public boolean insertTurbine(ItemStack aTurbine) { - if (GregtechMetaTileEntity_LargerTurbineBase.isValidTurbine(aTurbine)) { - this.mInventory[0] = aTurbine; - return true; - } - return false; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_Turbine(mName, mTier, StaticFields59.getDescriptionArray(this), mTextures); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - else { - aBaseMetaTileEntity.openGUI(aPlayer); - } - return true; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity, "Turbine Rotor Hatch"); - } - - @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 int getInventoryStackLimit() { - return 1; - } - - public void damageTurbine(int aEUt, int damageFactorLow, float damageFactorHigh) { - if (hasTurbine() && MathUtils.randInt(0, 1) == 0) { - ItemStack aTurbine = getTurbine(); - ((GT_MetaGenerated_Tool) aTurbine.getItem()).doDamage(aTurbine, (long)getDamageToComponent(aTurbine) * (long) Math.min(aEUt / damageFactorLow, Math.pow(aEUt, damageFactorHigh))); - } - } - - private final int getDamageToComponent(ItemStack aStack) { - return 1; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("mHasController", mHasController); - aNBT.setBoolean("mUsingAnimation", mUsingAnimation); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - mHasController = aNBT.getBoolean("mHasController"); - mUsingAnimation = aNBT.getBoolean("mUsingAnimation"); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (this.mHasController) { - if (aTick % 20 == 0) { - if (isControllerActive()) { - this.getBaseMetaTileEntity().setActive(true); - } - else { - this.getBaseMetaTileEntity().setActive(false); - } - } - } - else if (!this.mHasController && this.mControllerLocation != null) { - //Weird Invalid State - if (setController(BlockPos.generateBlockPos(mControllerLocation))) { - //Valid - } - } - else { - //No Controller - } - if (this.mInventory[0] != null && this.mInventory[0].stackSize <= 0) - this.mInventory[0] = null; - } - - public boolean isControllerActive() { - GregtechMetaTileEntity_LargerTurbineBase x = getController(); - if (x != null) { - //Logger.INFO("Checking Status of Controller. Running? "+(x.mEUt > 0)); - return x.mEUt > 0; - } - //Logger.INFO("Status of Controller failed, controller is null."); - return false; - } - - public GregtechMetaTileEntity_LargerTurbineBase getController() { - if (this.mHasController && this.mControllerLocation != null && this.mControllerLocation.length() > 0) { - BlockPos p = BlockPos.generateBlockPos(mControllerLocation); - if (p != null) { - //Logger.INFO(p.getLocationString()); - IGregTechTileEntity tTileEntity = getBaseMetaTileEntity().getIGregTechTileEntity(p.xPos, p.yPos, - p.zPos); - if (tTileEntity != null && tTileEntity.getMetaTileEntity() instanceof GregtechMetaTileEntity_LargerTurbineBase) { - return (GregtechMetaTileEntity_LargerTurbineBase) tTileEntity.getMetaTileEntity(); - } - else { - if (tTileEntity == null) { - Logger.INFO("Controller MTE is null, somehow?"); - } - else { - Logger.INFO("Controller is a different MTE to expected"); - } - } - } - } - //Logger.INFO("Failed to Get Controller."); - return null; - } - - public boolean canSetNewController() { - if ((mControllerLocation != null && mControllerLocation.length() > 0) || this.mHasController) { - return false; - } - return true; - } - - public boolean setController(BlockPos aPos) { - clearController(); - if (canSetNewController()) { - mControllerLocation = aPos.getUniqueIdentifier(); - mHasController = true; - Logger.INFO("Successfully injected controller into this Turbine Assembly Hatch."); - } - return mHasController; - } - - public void clearController() { - this.mControllerLocation = null; - this.mHasController = false; - } - - public boolean usingAnimations() { - return mUsingAnimation; - } - - private ITexture getFrontFacingTurbineTexture() { - if (!mHasController) { - return this.getBaseMetaTileEntity().isActive() ? new GT_RenderedTexture(LargeTurbineTextureHandler.OVERLAY_LP_TURBINE_ACTIVE[4] ) : new GT_RenderedTexture(LargeTurbineTextureHandler.OVERLAY_LP_TURBINE[4] ); - } - else { - if (usingAnimations()) { - if (isControllerActive()) { - return getController().frontFaceActive; - } - } - return getController().frontFace; - } - } - - @Override - public long getMinimumStoredEU() { - return 0; - } - - @Override - public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { - return false; - } - - @Override - public int[] getAccessibleSlotsFromSide(int aSide) { - return new int[] {}; - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - return false; - } - - public void setActive(boolean b) { - this.getBaseMetaTileEntity().setActive(b); - } - - @Override - public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { - return false; - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (!aPlayer.isSneaking()) { - PlayerUtils.messagePlayer(aPlayer, "Using Animations? "+usingAnimations()); - PlayerUtils.messagePlayer(aPlayer, "Has Controller? "+this.mHasController); - if (mHasController) { - PlayerUtils.messagePlayer(aPlayer, "Controller Location: "+BlockPos.generateBlockPos(mControllerLocation).getLocationString()); - PlayerUtils.messagePlayer(aPlayer, "Controller Active? "+this.isControllerActive()); - } - PlayerUtils.messagePlayer(aPlayer, "Active? "+this.getBaseMetaTileEntity().isActive()); - PlayerUtils.messagePlayer(aPlayer, "Has Turbine inserted? "+this.hasTurbine()); - if (this.hasTurbine()) { - Materials aMat = GT_MetaGenerated_Tool.getPrimaryMaterial(getTurbine()); - String aSize = GregtechMetaTileEntity_LargerTurbineBase.getTurbineSizeString(GregtechMetaTileEntity_LargerTurbineBase.getTurbineSize(getTurbine())); - PlayerUtils.messagePlayer(aPlayer, "Using: "+aMat.mLocalizedName+" "+aSize); - } - } - else { - this.mUsingAnimation = Utils.invertBoolean(mUsingAnimation); - if (this.mUsingAnimation) { - PlayerUtils.messagePlayer(aPlayer, "Using Animated Turbine Texture."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Using Static Turbine Texture."); - } - } - } - - @Override - public boolean onWrenchRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (this.getBaseMetaTileEntity().isServerSide() && !aPlayer.isSneaking()) { - ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); - if (tCurrentItem != null) { - if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { - return onToolClick(tCurrentItem, aPlayer, aWrenchingSide); - } - } - } - return super.onWrenchRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); - } - - @Override - public boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (this.getBaseMetaTileEntity().isServerSide()) { - ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); - if (tCurrentItem != null) { - if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { - return onToolClick(tCurrentItem, aPlayer, aWrenchingSide); - } - } - } - return false; - } - - public boolean onToolClick(ItemStack tCurrentItem, EntityPlayer aPlayer, byte aSide) { - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWrenchList)) { - boolean aHasTurbine = this.hasTurbine(); - if (aPlayer.inventory.getFirstEmptyStack() >= 0 && aHasTurbine) { - if (PlayerUtils.isCreative(aPlayer) || GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { - aPlayer.inventory.addItemStackToInventory((this.getTurbine())); - this.mInventory[0] = null; - GT_Utility.sendChatToPlayer(aPlayer, "Removed turbine with wrench."); - return true; - } - } - else { - GT_Utility.sendChatToPlayer(aPlayer, aHasTurbine ? "Cannot remove turbine, no free inventory space." : "No turbine to remove."); - } - } - else if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sSolderingToolList)) { - if (mControllerLocation != null && mControllerLocation.length() > 0) { - if (setController(BlockPos.generateBlockPos(mControllerLocation))) { - if (PlayerUtils.isCreative(aPlayer) || GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { - String tChat = "Trying to Reset linked Controller"; - IGregTechTileEntity g = this.getBaseMetaTileEntity(); - GT_Utility.sendChatToPlayer(aPlayer, tChat); - GT_Utility.sendSoundToPlayers(g.getWorld(), GregTech_API.sSoundList.get(101), 1.0F, -1, g.getXCoord(), g.getYCoord(), g.getZCoord()); - return true; - } - } - } - } - return false; - } - + public boolean mHasController = false; + public boolean mUsingAnimation = true; + private String mControllerLocation; + public int mEUt = 0; + + public GT_MetaTileEntity_Hatch_Turbine(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 16, "Turbine Rotor holder for XL Turbines"); + } + + public GT_MetaTileEntity_Hatch_Turbine(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 1, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_Turbine(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 1, aDescription[0], aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, + "Right Click with a soldering iron to reset controller link", + "Right Click with a wrench to remove turbine", + "Right Click with a screwdriver for technical information", + "Sneak + Right Click with a wrench to rotate", + "Sneak + Right Click with a screwdriver to disable animations", + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, getFrontFacingTurbineTexture()}; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, getFrontFacingTurbineTexture()}; + } + + public int getEU() { + return this.mEUt; + } + + public void setEU(int aEU) { + this.mEUt = aEU; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return aFacing > 1; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return false; + } + + public boolean hasTurbine() { + ItemStack aStack = this.mInventory[0]; + boolean aIsValid = GregtechMetaTileEntity_LargerTurbineBase.isValidTurbine(aStack); + return aIsValid; + } + + public ItemStack getTurbine() { + if (hasTurbine()) { + return this.mInventory[0]; + } + return null; + } + + public boolean canWork() { + return hasTurbine(); + } + + public boolean insertTurbine(ItemStack aTurbine) { + if (GregtechMetaTileEntity_LargerTurbineBase.isValidTurbine(aTurbine)) { + this.mInventory[0] = aTurbine; + return true; + } + return false; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Turbine(mName, mTier, StaticFields59.getDescriptionArray(this), mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } else { + aBaseMetaTileEntity.openGUI(aPlayer); + } + return true; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity, "Turbine Rotor Hatch"); + } + + @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 int getInventoryStackLimit() { + return 1; + } + + public void damageTurbine(int aEUt, int damageFactorLow, float damageFactorHigh) { + if (hasTurbine() && MathUtils.randInt(0, 1) == 0) { + ItemStack aTurbine = getTurbine(); + ((GT_MetaGenerated_Tool) aTurbine.getItem()) + .doDamage( + aTurbine, + (long) getDamageToComponent(aTurbine) + * (long) Math.min(aEUt / damageFactorLow, Math.pow(aEUt, damageFactorHigh))); + } + } + + private final int getDamageToComponent(ItemStack aStack) { + return 1; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mHasController", mHasController); + aNBT.setBoolean("mUsingAnimation", mUsingAnimation); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mHasController = aNBT.getBoolean("mHasController"); + mUsingAnimation = aNBT.getBoolean("mUsingAnimation"); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.mHasController) { + if (aTick % 20 == 0) { + if (isControllerActive()) { + this.getBaseMetaTileEntity().setActive(true); + } else { + this.getBaseMetaTileEntity().setActive(false); + } + } + } else if (!this.mHasController && this.mControllerLocation != null) { + // Weird Invalid State + if (setController(BlockPos.generateBlockPos(mControllerLocation))) { + // Valid + } + } else { + // No Controller + } + if (this.mInventory[0] != null && this.mInventory[0].stackSize <= 0) this.mInventory[0] = null; + } + + public boolean isControllerActive() { + GregtechMetaTileEntity_LargerTurbineBase x = getController(); + if (x != null) { + // Logger.INFO("Checking Status of Controller. Running? "+(x.mEUt > 0)); + return x.mEUt > 0; + } + // Logger.INFO("Status of Controller failed, controller is null."); + return false; + } + + public GregtechMetaTileEntity_LargerTurbineBase getController() { + if (this.mHasController && this.mControllerLocation != null && this.mControllerLocation.length() > 0) { + BlockPos p = BlockPos.generateBlockPos(mControllerLocation); + if (p != null) { + // Logger.INFO(p.getLocationString()); + IGregTechTileEntity tTileEntity = + getBaseMetaTileEntity().getIGregTechTileEntity(p.xPos, p.yPos, p.zPos); + if (tTileEntity != null + && tTileEntity.getMetaTileEntity() instanceof GregtechMetaTileEntity_LargerTurbineBase) { + return (GregtechMetaTileEntity_LargerTurbineBase) tTileEntity.getMetaTileEntity(); + } else { + if (tTileEntity == null) { + Logger.INFO("Controller MTE is null, somehow?"); + } else { + Logger.INFO("Controller is a different MTE to expected"); + } + } + } + } + // Logger.INFO("Failed to Get Controller."); + return null; + } + + public boolean canSetNewController() { + if ((mControllerLocation != null && mControllerLocation.length() > 0) || this.mHasController) { + return false; + } + return true; + } + + public boolean setController(BlockPos aPos) { + clearController(); + if (canSetNewController()) { + mControllerLocation = aPos.getUniqueIdentifier(); + mHasController = true; + Logger.INFO("Successfully injected controller into this Turbine Assembly Hatch."); + } + return mHasController; + } + + public void clearController() { + this.mControllerLocation = null; + this.mHasController = false; + } + + public boolean usingAnimations() { + return mUsingAnimation; + } + + private ITexture getFrontFacingTurbineTexture() { + if (!mHasController) { + return this.getBaseMetaTileEntity().isActive() + ? new GT_RenderedTexture(LargeTurbineTextureHandler.OVERLAY_LP_TURBINE_ACTIVE[4]) + : new GT_RenderedTexture(LargeTurbineTextureHandler.OVERLAY_LP_TURBINE[4]); + } else { + if (usingAnimations()) { + if (isControllerActive()) { + return getController().frontFaceActive; + } + } + return getController().frontFace; + } + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(int aSide) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + return false; + } + + public void setActive(boolean b) { + this.getBaseMetaTileEntity().setActive(b); + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return false; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (!aPlayer.isSneaking()) { + PlayerUtils.messagePlayer(aPlayer, "Using Animations? " + usingAnimations()); + PlayerUtils.messagePlayer(aPlayer, "Has Controller? " + this.mHasController); + if (mHasController) { + PlayerUtils.messagePlayer( + aPlayer, + "Controller Location: " + + BlockPos.generateBlockPos(mControllerLocation).getLocationString()); + PlayerUtils.messagePlayer(aPlayer, "Controller Active? " + this.isControllerActive()); + } + PlayerUtils.messagePlayer( + aPlayer, "Active? " + this.getBaseMetaTileEntity().isActive()); + PlayerUtils.messagePlayer(aPlayer, "Has Turbine inserted? " + this.hasTurbine()); + if (this.hasTurbine()) { + Materials aMat = GT_MetaGenerated_Tool.getPrimaryMaterial(getTurbine()); + String aSize = GregtechMetaTileEntity_LargerTurbineBase.getTurbineSizeString( + GregtechMetaTileEntity_LargerTurbineBase.getTurbineSize(getTurbine())); + PlayerUtils.messagePlayer(aPlayer, "Using: " + aMat.mLocalizedName + " " + aSize); + } + } else { + this.mUsingAnimation = Utils.invertBoolean(mUsingAnimation); + if (this.mUsingAnimation) { + PlayerUtils.messagePlayer(aPlayer, "Using Animated Turbine Texture."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Using Static Turbine Texture."); + } + } + } + + @Override + public boolean onWrenchRightClick( + byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (this.getBaseMetaTileEntity().isServerSide() && !aPlayer.isSneaking()) { + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem != null) { + if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { + return onToolClick(tCurrentItem, aPlayer, aWrenchingSide); + } + } + } + return super.onWrenchRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); + } + + @Override + public boolean onSolderingToolRightClick( + byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (this.getBaseMetaTileEntity().isServerSide()) { + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem != null) { + if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { + return onToolClick(tCurrentItem, aPlayer, aWrenchingSide); + } + } + } + return false; + } + + public boolean onToolClick(ItemStack tCurrentItem, EntityPlayer aPlayer, byte aSide) { + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWrenchList)) { + boolean aHasTurbine = this.hasTurbine(); + if (aPlayer.inventory.getFirstEmptyStack() >= 0 && aHasTurbine) { + if (PlayerUtils.isCreative(aPlayer) + || GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { + aPlayer.inventory.addItemStackToInventory((this.getTurbine())); + this.mInventory[0] = null; + GT_Utility.sendChatToPlayer(aPlayer, "Removed turbine with wrench."); + return true; + } + } else { + GT_Utility.sendChatToPlayer( + aPlayer, + aHasTurbine ? "Cannot remove turbine, no free inventory space." : "No turbine to remove."); + } + } else if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sSolderingToolList)) { + if (mControllerLocation != null && mControllerLocation.length() > 0) { + if (setController(BlockPos.generateBlockPos(mControllerLocation))) { + if (PlayerUtils.isCreative(aPlayer) + || GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { + String tChat = "Trying to Reset linked Controller"; + IGregTechTileEntity g = this.getBaseMetaTileEntity(); + GT_Utility.sendChatToPlayer(aPlayer, tChat); + GT_Utility.sendSoundToPlayers( + g.getWorld(), + GregTech_API.sSoundList.get(101), + 1.0F, + -1, + g.getXCoord(), + g.getYCoord(), + g.getZCoord()); + return true; + } + } + } + } + return false; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java index 0b84f676f4..85b921b1ed 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java @@ -23,198 +23,194 @@ import net.minecraft.world.chunk.Chunk; public class GT_MetaTileEntity_Hatch_TurbineProvider extends GT_MetaTileEntity_Hatch_InputBus { - public GT_MetaTileEntity_Hatch_TurbineProvider(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier); - } - - public GT_MetaTileEntity_Hatch_TurbineProvider(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - public GT_MetaTileEntity_Hatch_TurbineProvider(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription[0], aTextures); - } - - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_TurbineProvider(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity); - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity, "Turbine Housing"); - } - - @Override - public String[] getDescription() { - return new String[]{ - "An automation port for Large Turbines", - "Will attempt once per 1200 ticks to fill the turbine slot of it's parent turbine", - "You may adjust this with a screwdriver", - "Hold shift to adjust in finer amounts", - "Hold control to adjust direction", - "Left Click with Screwdriver to reset", - "This module assumes the entire turbine is in the same Chunk", - CORE.GT_Tooltip}; - } - - - private GT_MetaTileEntity_LargeTurbine mParent = null; - - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - super.onPostTick(aBaseMetaTileEntity, aTimer); - if (aTimer % mRefreshTime == 0 && this.getBaseMetaTileEntity().isServerSide()) { - tryRefillTurbine(); - } - } - - private final void tryFindParentTurbine() { - Logger.INFO("This turbine housing has no parent, searching world."); - IGregTechTileEntity T = this.getBaseMetaTileEntity(); - World W = T.getWorld(); - Chunk C = W.getChunkFromBlockCoords(T.getXCoord(), T.getZCoord()); - for (Object o : C.chunkTileEntityMap.values()) { - if (o instanceof IGregTechTileEntity) { - IGregTechTileEntity G = (IGregTechTileEntity) o; - final IMetaTileEntity aMetaTileEntity = G.getMetaTileEntity(); - if (aMetaTileEntity == null) { - continue; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_LargeTurbine) { - GT_MetaTileEntity_LargeTurbine aTurb = (GT_MetaTileEntity_LargeTurbine) aMetaTileEntity; - for (GT_MetaTileEntity_Hatch_InputBus ee : aTurb.mInputBusses) { - if (ee.equals(this)) { - mParent = aTurb; - Logger.INFO("Found a Parent to attach to this housing."); - return; - } - } - } - } - } - } - - private final void tryRefillTurbine() { - if (mParent == null) { - tryFindParentTurbine(); - } - if (mParent != null && mParent.mInventory[1] == null) { - for (ItemStack aStack : this.mInventory) { - if (isItemStackTurbine(aStack)) { - setGUIItemStack(aStack); - } - } - } - } - - protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) { - boolean result = false; - if (mParent.mInventory[1] == null) { - mParent.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null; - mParent.depleteInput(aNewGuiSlotContents); - mParent.updateSlots(); - this.updateSlots(); - result = true; - } - return result; - } - - public boolean isItemStackTurbine(ItemStack aStack) { - if (aStack.getItem() instanceof GT_MetaGenerated_Tool) { - if (aStack.getItemDamage() >= 170 && aStack.getItemDamage() <= 176) { - return true; - } - } - return false; - } - - public boolean isItemStackScrewdriver(ItemStack aStack) { - if (aStack.getItem() instanceof GT_MetaGenerated_Tool) { - if (aStack.getItemDamage() == 22 || aStack.getItemDamage() == 150) { - 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 isItemStackTurbine(aStack); - } - - private int mRefreshTime = 1200; - private boolean mDescending = true; - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("mRefreshTime", mRefreshTime); - aNBT.setBoolean("mDescending", mDescending); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - mRefreshTime = aNBT.getInteger("mRefreshTime"); - mDescending = aNBT.getBoolean("mDescending"); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (aPlayer != null) { - if (KeyboardUtils.isCtrlKeyDown()) { - mDescending = Utils.invertBoolean(mDescending); - PlayerUtils.messagePlayer(aPlayer, "Direction: "+(mDescending ? "DOWN" : "UP")); - } - else { - int aAmount = 0; - if (KeyboardUtils.isShiftKeyDown()) { - aAmount = 10; - } - else { - aAmount = 100; - } - if (mDescending) { - mRefreshTime -= aAmount; - if (mRefreshTime < 0) { - mRefreshTime = 1200; - } - } - else { - mRefreshTime += aAmount; - if (mRefreshTime > 1200) { - mRefreshTime = 0; - } - } - PlayerUtils.messagePlayer(aPlayer, "Set check time to be every "+mRefreshTime+" ticks."); - } - } - } - - @Override - public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - boolean aDidScrewdriver = false; - if (aPlayer != null) { - if (aPlayer.getHeldItem() != null) { - if (isItemStackScrewdriver(aPlayer.getHeldItem())) { - aDidScrewdriver = true; - mRefreshTime = 1200; - PlayerUtils.messagePlayer(aPlayer, "Reset check time to "+mRefreshTime+" ticks."); - } - } - } - if (!aDidScrewdriver) { - super.onLeftclick(aBaseMetaTileEntity, aPlayer); - } - } - + public GT_MetaTileEntity_Hatch_TurbineProvider(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + } + public GT_MetaTileEntity_Hatch_TurbineProvider( + String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_TurbineProvider( + String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription[0], aTextures); + } + + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_TurbineProvider(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity, "Turbine Housing"); + } + + @Override + public String[] getDescription() { + return new String[] { + "An automation port for Large Turbines", + "Will attempt once per 1200 ticks to fill the turbine slot of it's parent turbine", + "You may adjust this with a screwdriver", + "Hold shift to adjust in finer amounts", + "Hold control to adjust direction", + "Left Click with Screwdriver to reset", + "This module assumes the entire turbine is in the same Chunk", + CORE.GT_Tooltip + }; + } + + private GT_MetaTileEntity_LargeTurbine mParent = null; + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + super.onPostTick(aBaseMetaTileEntity, aTimer); + if (aTimer % mRefreshTime == 0 && this.getBaseMetaTileEntity().isServerSide()) { + tryRefillTurbine(); + } + } + + private final void tryFindParentTurbine() { + Logger.INFO("This turbine housing has no parent, searching world."); + IGregTechTileEntity T = this.getBaseMetaTileEntity(); + World W = T.getWorld(); + Chunk C = W.getChunkFromBlockCoords(T.getXCoord(), T.getZCoord()); + for (Object o : C.chunkTileEntityMap.values()) { + if (o instanceof IGregTechTileEntity) { + IGregTechTileEntity G = (IGregTechTileEntity) o; + final IMetaTileEntity aMetaTileEntity = G.getMetaTileEntity(); + if (aMetaTileEntity == null) { + continue; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_LargeTurbine) { + GT_MetaTileEntity_LargeTurbine aTurb = (GT_MetaTileEntity_LargeTurbine) aMetaTileEntity; + for (GT_MetaTileEntity_Hatch_InputBus ee : aTurb.mInputBusses) { + if (ee.equals(this)) { + mParent = aTurb; + Logger.INFO("Found a Parent to attach to this housing."); + return; + } + } + } + } + } + } + + private final void tryRefillTurbine() { + if (mParent == null) { + tryFindParentTurbine(); + } + if (mParent != null && mParent.mInventory[1] == null) { + for (ItemStack aStack : this.mInventory) { + if (isItemStackTurbine(aStack)) { + setGUIItemStack(aStack); + } + } + } + } + + protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) { + boolean result = false; + if (mParent.mInventory[1] == null) { + mParent.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null; + mParent.depleteInput(aNewGuiSlotContents); + mParent.updateSlots(); + this.updateSlots(); + result = true; + } + return result; + } + + public boolean isItemStackTurbine(ItemStack aStack) { + if (aStack.getItem() instanceof GT_MetaGenerated_Tool) { + if (aStack.getItemDamage() >= 170 && aStack.getItemDamage() <= 176) { + return true; + } + } + return false; + } + + public boolean isItemStackScrewdriver(ItemStack aStack) { + if (aStack.getItem() instanceof GT_MetaGenerated_Tool) { + if (aStack.getItemDamage() == 22 || aStack.getItemDamage() == 150) { + 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 isItemStackTurbine(aStack); + } + + private int mRefreshTime = 1200; + private boolean mDescending = true; + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mRefreshTime", mRefreshTime); + aNBT.setBoolean("mDescending", mDescending); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mRefreshTime = aNBT.getInteger("mRefreshTime"); + mDescending = aNBT.getBoolean("mDescending"); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer != null) { + if (KeyboardUtils.isCtrlKeyDown()) { + mDescending = Utils.invertBoolean(mDescending); + PlayerUtils.messagePlayer(aPlayer, "Direction: " + (mDescending ? "DOWN" : "UP")); + } else { + int aAmount = 0; + if (KeyboardUtils.isShiftKeyDown()) { + aAmount = 10; + } else { + aAmount = 100; + } + if (mDescending) { + mRefreshTime -= aAmount; + if (mRefreshTime < 0) { + mRefreshTime = 1200; + } + } else { + mRefreshTime += aAmount; + if (mRefreshTime > 1200) { + mRefreshTime = 0; + } + } + PlayerUtils.messagePlayer(aPlayer, "Set check time to be every " + mRefreshTime + " ticks."); + } + } + } + + @Override + public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + boolean aDidScrewdriver = false; + if (aPlayer != null) { + if (aPlayer.getHeldItem() != null) { + if (isItemStackScrewdriver(aPlayer.getHeldItem())) { + aDidScrewdriver = true; + mRefreshTime = 1200; + PlayerUtils.messagePlayer(aPlayer, "Reset check time to " + mRefreshTime + " ticks."); + } + } + } + if (!aDidScrewdriver) { + super.onLeftclick(aBaseMetaTileEntity, aPlayer); + } + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java index d0682b85e8..f144076131 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java @@ -15,134 +15,130 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_SuperBus_Input extends GT_MetaTileEntity_Hatch_InputBus { - public GT_MetaTileEntity_SuperBus_Input(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier)); - } - - public GT_MetaTileEntity_SuperBus_Input(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, getSlots(aTier), aDescription, aTextures); - } - - /** - * Returns a factor of 16 based on tier. - * - * @param aTier The tier of this bus. - * @return (1 + aTier) * 16 - */ - public static int getSlots(int aTier) { - return (1 + aTier) * 16; - } - - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE_IN)}; - } - - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE_IN)}; - } - - 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_SuperBus_Input(this.mName, this.mTier, ArrayExt.of(this.mDescription), this.mTextures); - } - - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aSide == this.getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public String[] getDescription() { - String[] aDesc = new String[] { - "Item Input for Multiblocks", - "This bus has no GUI, but can have items extracted", - ""+getSlots(this.mTier)+" Slots", - CORE.GT_Tooltip - }; - return aDesc; - } - - @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); - } - - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } else { - //Logger.INFO("Trying to display Super Input Bus contents."); - displayBusContents(aPlayer); - return true; - } - } - - public void displayBusContents(EntityPlayer aPlayer) { - String STRIP = "Item Array: "; - String aNameString = ItemUtils.getArrayStackNames(getRealInventory()); - aNameString = aNameString.replace(STRIP, ""); - - String[] aNames; - if (aNameString.length() < 1) { - aNames = null; - } - else { - aNames = aNameString.split(","); - } - - if (aNames == null || aNames.length <= 0) { - PlayerUtils.messagePlayer(aPlayer, "This Super Bus (I) is Empty. Total Slots: "+getSlots(this.mTier)); - return; - } - - PlayerUtils.messagePlayer(aPlayer, "This Super Bus (I) contains: ["+getRealInventory().length+"]"); - - if (aNames.length <= 12) { - for (String s : aNames) { - if (s.startsWith(" ")) { - s = s.substring(1); - } - //Logger.INFO("Trying to display Super Input Bus contents. "+s); - PlayerUtils.messagePlayer(aPlayer, s); - } - } - else { - - String superString = ""; - - for (String s : aNames) { - if (s.startsWith(" ")) { - s = s.substring(1); - } - superString += (s+", "); - } - PlayerUtils.messagePlayer(aPlayer, superString); - } - - - } - -}
\ No newline at end of file + public GT_MetaTileEntity_SuperBus_Input(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier)); + } + + public GT_MetaTileEntity_SuperBus_Input(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, getSlots(aTier), aDescription, aTextures); + } + + /** + * Returns a factor of 16 based on tier. + * + * @param aTier The tier of this bus. + * @return (1 + aTier) * 16 + */ + public static int getSlots(int aTier) { + return (1 + aTier) * 16; + } + + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE_IN)}; + } + + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE_IN)}; + } + + 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_SuperBus_Input( + this.mName, this.mTier, ArrayExt.of(this.mDescription), this.mTextures); + } + + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aSide == this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public String[] getDescription() { + String[] aDesc = new String[] { + "Item Input for Multiblocks", + "This bus has no GUI, but can have items extracted", + "" + getSlots(this.mTier) + " Slots", + CORE.GT_Tooltip + }; + return aDesc; + } + + @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); + } + + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } else { + // Logger.INFO("Trying to display Super Input Bus contents."); + displayBusContents(aPlayer); + return true; + } + } + + public void displayBusContents(EntityPlayer aPlayer) { + String STRIP = "Item Array: "; + String aNameString = ItemUtils.getArrayStackNames(getRealInventory()); + aNameString = aNameString.replace(STRIP, ""); + + String[] aNames; + if (aNameString.length() < 1) { + aNames = null; + } else { + aNames = aNameString.split(","); + } + + if (aNames == null || aNames.length <= 0) { + PlayerUtils.messagePlayer(aPlayer, "This Super Bus (I) is Empty. Total Slots: " + getSlots(this.mTier)); + return; + } + + PlayerUtils.messagePlayer(aPlayer, "This Super Bus (I) contains: [" + getRealInventory().length + "]"); + + if (aNames.length <= 12) { + for (String s : aNames) { + if (s.startsWith(" ")) { + s = s.substring(1); + } + // Logger.INFO("Trying to display Super Input Bus contents. "+s); + PlayerUtils.messagePlayer(aPlayer, s); + } + } else { + + String superString = ""; + + for (String s : aNames) { + if (s.startsWith(" ")) { + s = s.substring(1); + } + superString += (s + ", "); + } + PlayerUtils.messagePlayer(aPlayer, superString); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java index 37aa57298a..7fecabd5d7 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java @@ -17,164 +17,170 @@ import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_SuperBus_Output extends GT_MetaTileEntity_Hatch_OutputBus { - public GT_MetaTileEntity_SuperBus_Output(int id, String name, String nameRegional, int tier) { - super(id, name, nameRegional, tier, getSlots(tier)); - } - - public GT_MetaTileEntity_SuperBus_Output(String name, int tier, String[] description, ITexture[][][] textures) { - super(name, tier, getSlots(tier), description, textures); - } - - /** - * Returns a factor of 16 based on tier. - * - * @param aTier The tier of this bus. - * @return (1 + aTier) * 16 - */ - public static int getSlots(int aTier) { - return (1 + aTier) * 16; - } - - public boolean isValidSlot(int aIndex) { - return true; - } - - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_SuperBus_Output(this.mName, this.mTier, ArrayExt.of(this.mDescription), this.mTextures); - } - - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return null; - } - - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { - this.fillStacksIntoFirstSlots(); - } + public GT_MetaTileEntity_SuperBus_Output(int id, String name, String nameRegional, int tier) { + super(id, name, nameRegional, tier, getSlots(tier)); + } + + public GT_MetaTileEntity_SuperBus_Output(String name, int tier, String[] description, ITexture[][][] textures) { + super(name, tier, getSlots(tier), description, textures); + } + + /** + * Returns a factor of 16 based on tier. + * + * @param aTier The tier of this bus. + * @return (1 + aTier) * 16 + */ + public static int getSlots(int aTier) { + return (1 + aTier) * 16; + } + + public boolean isValidSlot(int aIndex) { + return true; + } + + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_SuperBus_Output( + this.mName, this.mTier, ArrayExt.of(this.mDescription), this.mTextures); + } + + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + this.fillStacksIntoFirstSlots(); + } super.onPostTick(aBaseMetaTileEntity, aTimer); - } - - public void updateSlots() { - for (int i = 0; i < this.mInventory.length; ++i) { - if (this.mInventory[i] != null && this.mInventory[i].stackSize <= 0) { - this.mInventory[i] = null; - } - } - this.fillStacksIntoFirstSlots(); - } - - protected void fillStacksIntoFirstSlots() { - for (int i = 0; i < this.mInventory.length; ++i) { - for (int j = i + 1; j < this.mInventory.length; ++j) { - if (this.mInventory[j] != null && (this.mInventory[i] == null - || GT_Utility.areStacksEqual(this.mInventory[i], this.mInventory[j]))) { - GT_Utility.moveStackFromSlotAToSlotB((IInventory) this.getBaseMetaTileEntity(), (IInventory) this.getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - } - } - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - } - - @Override - public String[] getDescription() { - String[] aDesc = new String[] { - "Item Output for Multiblocks", - "This bus has no GUI", - ""+getSlots(this.mTier)+" Slots", - CORE.GT_Tooltip - }; - return aDesc; - } - - @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); - } - - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } else { - displayBusContents(aPlayer); - return true; - } - } - - public void displayBusContents(EntityPlayer aPlayer) { - String STRIP = "Item Array: "; - String aNameString = ItemUtils.getArrayStackNames(getRealInventory()); - aNameString = aNameString.replace(STRIP, ""); - - String[] aNames; - if (aNameString.length() < 1) { - aNames = null; - } - else { - aNames = aNameString.split(","); - } - - if (aNames == null || aNames.length <= 0) { - PlayerUtils.messagePlayer(aPlayer, "This Super Bus (O) is Empty. Total Slots: "+getSlots(this.mTier)); - return; - } - - PlayerUtils.messagePlayer(aPlayer, "This Super Bus (O) contains:"); - for (String s : aNames) { - if (s.startsWith(" ")) { - s = s.substring(1); - } - //Logger.INFO("Trying to display Super Output Bus contents. "+s); - PlayerUtils.messagePlayer(aPlayer, s); - } - } - - @Override - public int getMaxItemCount() { - // TODO Auto-generated method stub - return super.getMaxItemCount(); - } - - @Override - public int getSizeInventory() { - // TODO Auto-generated method stub - return super.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int aIndex) { - // TODO Auto-generated method stub - return super.getStackInSlot(aIndex); - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - // TODO Auto-generated method stub - return super.canInsertItem(aIndex, aStack, aSide); - } - - @Override - public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { - // TODO Auto-generated method stub - return super.canExtractItem(aIndex, aStack, aSide); - } - - @Override - public ItemStack[] getRealInventory() { - // TODO Auto-generated method stub - return super.getRealInventory(); - } -}
\ No newline at end of file + } + + public void updateSlots() { + for (int i = 0; i < this.mInventory.length; ++i) { + if (this.mInventory[i] != null && this.mInventory[i].stackSize <= 0) { + this.mInventory[i] = null; + } + } + this.fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < this.mInventory.length; ++i) { + for (int j = i + 1; j < this.mInventory.length; ++j) { + if (this.mInventory[j] != null + && (this.mInventory[i] == null + || GT_Utility.areStacksEqual(this.mInventory[i], this.mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + (IInventory) this.getBaseMetaTileEntity(), + (IInventory) this.getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public String[] getDescription() { + String[] aDesc = new String[] { + "Item Output for Multiblocks", "This bus has no GUI", "" + getSlots(this.mTier) + " Slots", CORE.GT_Tooltip + }; + return aDesc; + } + + @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); + } + + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } else { + displayBusContents(aPlayer); + return true; + } + } + + public void displayBusContents(EntityPlayer aPlayer) { + String STRIP = "Item Array: "; + String aNameString = ItemUtils.getArrayStackNames(getRealInventory()); + aNameString = aNameString.replace(STRIP, ""); + + String[] aNames; + if (aNameString.length() < 1) { + aNames = null; + } else { + aNames = aNameString.split(","); + } + + if (aNames == null || aNames.length <= 0) { + PlayerUtils.messagePlayer(aPlayer, "This Super Bus (O) is Empty. Total Slots: " + getSlots(this.mTier)); + return; + } + + PlayerUtils.messagePlayer(aPlayer, "This Super Bus (O) contains:"); + for (String s : aNames) { + if (s.startsWith(" ")) { + s = s.substring(1); + } + // Logger.INFO("Trying to display Super Output Bus contents. "+s); + PlayerUtils.messagePlayer(aPlayer, s); + } + } + + @Override + public int getMaxItemCount() { + // TODO Auto-generated method stub + return super.getMaxItemCount(); + } + + @Override + public int getSizeInventory() { + // TODO Auto-generated method stub + return super.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(int aIndex) { + // TODO Auto-generated method stub + return super.getStackInSlot(aIndex); + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + // TODO Auto-generated method stub + return super.canInsertItem(aIndex, aStack, aSide); + } + + @Override + public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { + // TODO Auto-generated method stub + return super.canExtractItem(aIndex, aStack, aSide); + } + + @Override + public ItemStack[] getRealInventory() { + // TODO Auto-generated method stub + return super.getRealInventory(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java index f6e778f989..8f7fd8d4d3 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java @@ -13,107 +13,167 @@ import gtPlusPlus.xmod.gregtech.common.StaticFields59; import net.minecraft.util.EnumChatFormatting; public class GregtechMetaPipeEntityFluid extends GT_MetaPipeEntity_Fluid { - - - public static final boolean mGt6Pipe; - - static { - mGt6Pipe = StaticFields59.mGT6StylePipes; - } - - public final GT_Materials mMaterial; - private boolean mCheckConnections; - - - public GregtechMetaPipeEntityFluid(int aID, String aName, String aNameRegional, float aThickNess, GT_Materials aMaterial, - int aCapacity, int aHeatResistance, boolean aGasProof) { - this(aID, aName, aNameRegional, aThickNess, aMaterial, aCapacity, aHeatResistance, aGasProof, 1); - } - - public GregtechMetaPipeEntityFluid(final String aName, final float aThickNess, final GT_Materials aMaterial, final int aCapacity, final int aHeatResistance, final boolean aGasProof) { - this(aName, aThickNess, aMaterial, aCapacity, aHeatResistance, aGasProof, 1); - } - public GregtechMetaPipeEntityFluid(int aID, String aName, String aNameRegional, float aThickNess, GT_Materials aMaterial, - int aCapacity, int aHeatResistance, boolean aGasProof, int aFluidTypes) { - super(aID, aName, aNameRegional, aThickNess, null, aCapacity, aHeatResistance, aGasProof); - this.mLastReceivedFrom = 0; - this.oLastReceivedFrom = 0; - this.mCheckConnections = !mGt6Pipe; - this.mMaterial = aMaterial; - } - + public static final boolean mGt6Pipe; + static { + mGt6Pipe = StaticFields59.mGT6StylePipes; + } - public GregtechMetaPipeEntityFluid(String aName, float aThickNess, GT_Materials aMaterial, int aCapacity, - int aHeatResistance, boolean aGasProof, int aFluidTypes) { - super(aName, aThickNess, null, aCapacity, aHeatResistance, aGasProof); - this.mLastReceivedFrom = 0; - this.oLastReceivedFrom = 0; - this.mCheckConnections = !mGt6Pipe; - this.mMaterial = aMaterial; - } + public final GT_Materials mMaterial; + private boolean mCheckConnections; + public GregtechMetaPipeEntityFluid( + int aID, + String aName, + String aNameRegional, + float aThickNess, + GT_Materials aMaterial, + int aCapacity, + int aHeatResistance, + boolean aGasProof) { + this(aID, aName, aNameRegional, aThickNess, aMaterial, aCapacity, aHeatResistance, aGasProof, 1); + } - @Override - public byte getTileEntityBaseType() { - return this.mMaterial == null ? 4 : (byte) ((this.mMaterial.contains(SubTag.WOOD) ? 12 : 4) + Math.max(0, Math.min(3, this.mMaterial.mToolQuality))); - } + public GregtechMetaPipeEntityFluid( + final String aName, + final float aThickNess, + final GT_Materials aMaterial, + final int aCapacity, + final int aHeatResistance, + final boolean aGasProof) { + this(aName, aThickNess, aMaterial, aCapacity, aHeatResistance, aGasProof, 1); + } - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaPipeEntityFluid(this.mName, this.mThickNess, this.mMaterial, this.mCapacity, this.mHeatResistance, this.mGasProof); - } + public GregtechMetaPipeEntityFluid( + int aID, + String aName, + String aNameRegional, + float aThickNess, + GT_Materials aMaterial, + int aCapacity, + int aHeatResistance, + boolean aGasProof, + int aFluidTypes) { + super(aID, aName, aNameRegional, aThickNess, null, aCapacity, aHeatResistance, aGasProof); + this.mLastReceivedFrom = 0; + this.oLastReceivedFrom = 0; + this.mCheckConnections = !mGt6Pipe; + this.mMaterial = aMaterial; + } - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aConnections, byte aColorIndex, boolean aConnected, boolean aRedstone) { - float tThickNess = getThickNess(); - if (mDisableInput == 0) - return new ITexture[]{aConnected ? getBaseTexture(tThickNess, mPipeAmount, mMaterial, aColorIndex) : TextureFactory.of(mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], Dyes.getModulation(aColorIndex, mMaterial.mRGBa))}; - byte tMask = 0; - byte[][] sRestrictionArray = { - {2, 3, 5, 4}, - {2, 3, 4, 5}, - {1, 0, 4, 5}, - {1, 0, 4, 5}, - {1, 0, 2, 3}, - {1, 0, 2, 3} - }; - if (aSide >= 0 && aSide < 6) { - for (byte i = 0; i < 4; i++) if (isInputDisabledAtSide(sRestrictionArray[aSide][i])) tMask |= 1 << i; - //Full block size renderer flips side 5 and 2 textures, flip restrictor textures to compensate - if (aSide == 5 || aSide == 2) - if (tMask > 3 && tMask < 12) - tMask = (byte) (tMask ^ 12); - } - return new ITexture[]{aConnected ? getBaseTexture(tThickNess, mPipeAmount, mMaterial, aColorIndex) : TextureFactory.of(mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], Dyes.getModulation(aColorIndex, mMaterial.mRGBa)), getRestrictorTexture(tMask)}; - } + public GregtechMetaPipeEntityFluid( + String aName, + float aThickNess, + GT_Materials aMaterial, + int aCapacity, + int aHeatResistance, + boolean aGasProof, + int aFluidTypes) { + super(aName, aThickNess, null, aCapacity, aHeatResistance, aGasProof); + this.mLastReceivedFrom = 0; + this.oLastReceivedFrom = 0; + this.mCheckConnections = !mGt6Pipe; + this.mMaterial = aMaterial; + } - protected static ITexture getBaseTexture(float aThickNess, int aPipeAmount, GT_Materials aMaterial, byte aColorIndex) { - if (aPipeAmount >= 9) - return TextureFactory.of(aMaterial.mIconSet.mTextures[OrePrefixes.pipeNonuple.mTextureIndex], Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - if (aPipeAmount >= 4) - return TextureFactory.of(aMaterial.mIconSet.mTextures[OrePrefixes.pipeQuadruple.mTextureIndex], Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - if (aThickNess < 0.124F) - return TextureFactory.of(aMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - if (aThickNess < 0.374F) - return TextureFactory.of(aMaterial.mIconSet.mTextures[OrePrefixes.pipeTiny.mTextureIndex], Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - if (aThickNess < 0.499F) - return TextureFactory.of(aMaterial.mIconSet.mTextures[OrePrefixes.pipeSmall.mTextureIndex], Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - if (aThickNess < 0.749F) - return TextureFactory.of(aMaterial.mIconSet.mTextures[OrePrefixes.pipeMedium.mTextureIndex], Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - if (aThickNess < 0.874F) - return TextureFactory.of(aMaterial.mIconSet.mTextures[OrePrefixes.pipeLarge.mTextureIndex], Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - return TextureFactory.of(aMaterial.mIconSet.mTextures[OrePrefixes.pipeHuge.mTextureIndex], Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - } + @Override + public byte getTileEntityBaseType() { + return this.mMaterial == null + ? 4 + : (byte) ((this.mMaterial.contains(SubTag.WOOD) ? 12 : 4) + + Math.max(0, Math.min(3, this.mMaterial.mToolQuality))); + } - @Override - public String[] getDescription() { - return new String[]{ - EnumChatFormatting.BLUE + "Fluid Capacity: %%%" + (mCapacity * 20) + "%%% L/sec" + EnumChatFormatting.GRAY, - EnumChatFormatting.RED + "Heat Limit: %%%" + mHeatResistance + "%%% K" + EnumChatFormatting.GRAY, - EnumChatFormatting.DARK_GREEN + "Gas Proof: " + (this.mGasProof) + EnumChatFormatting.GRAY, - //CORE.GT_Tooltip - }; - } -}
\ No newline at end of file + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPipeEntityFluid( + this.mName, this.mThickNess, this.mMaterial, this.mCapacity, this.mHeatResistance, this.mGasProof); + } + + @Override + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aConnections, + byte aColorIndex, + boolean aConnected, + boolean aRedstone) { + float tThickNess = getThickNess(); + if (mDisableInput == 0) + return new ITexture[] { + aConnected + ? getBaseTexture(tThickNess, mPipeAmount, mMaterial, aColorIndex) + : TextureFactory.of( + mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], + Dyes.getModulation(aColorIndex, mMaterial.mRGBa)) + }; + byte tMask = 0; + byte[][] sRestrictionArray = { + {2, 3, 5, 4}, + {2, 3, 4, 5}, + {1, 0, 4, 5}, + {1, 0, 4, 5}, + {1, 0, 2, 3}, + {1, 0, 2, 3} + }; + if (aSide >= 0 && aSide < 6) { + for (byte i = 0; i < 4; i++) if (isInputDisabledAtSide(sRestrictionArray[aSide][i])) tMask |= 1 << i; + // Full block size renderer flips side 5 and 2 textures, flip restrictor textures to compensate + if (aSide == 5 || aSide == 2) if (tMask > 3 && tMask < 12) tMask = (byte) (tMask ^ 12); + } + return new ITexture[] { + aConnected + ? getBaseTexture(tThickNess, mPipeAmount, mMaterial, aColorIndex) + : TextureFactory.of( + mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], + Dyes.getModulation(aColorIndex, mMaterial.mRGBa)), + getRestrictorTexture(tMask) + }; + } + + protected static ITexture getBaseTexture( + float aThickNess, int aPipeAmount, GT_Materials aMaterial, byte aColorIndex) { + if (aPipeAmount >= 9) + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeNonuple.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aPipeAmount >= 4) + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeQuadruple.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.124F) + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.374F) + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeTiny.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.499F) + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeSmall.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.749F) + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeMedium.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.874F) + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeLarge.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeHuge.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + } + + @Override + public String[] getDescription() { + return new String[] { + EnumChatFormatting.BLUE + "Fluid Capacity: %%%" + (mCapacity * 20) + "%%% L/sec" + EnumChatFormatting.GRAY, + EnumChatFormatting.RED + "Heat Limit: %%%" + mHeatResistance + "%%% K" + EnumChatFormatting.GRAY, + EnumChatFormatting.DARK_GREEN + "Gas Proof: " + (this.mGasProof) + EnumChatFormatting.GRAY, + // CORE.GT_Tooltip + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java index c2ffcbce46..eff2413102 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java @@ -1,10 +1,7 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import static gregtech.api.enums.GT_Values.VN; import static gtPlusPlus.core.lib.CORE.GTNH; -import net.minecraft.util.EnumChatFormatting; - import gregtech.api.enums.*; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -14,142 +11,285 @@ import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Cable; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; -import gtPlusPlus.core.lib.CORE; - public class GregtechMetaPipeEntity_Cable extends GT_MetaPipeEntity_Cable implements IMetaTileEntityCable { - private static Textures.BlockIcons INSULATION_MEDIUM_PLUS; - static{ - if(GTNH) { - try { - INSULATION_MEDIUM_PLUS = (Textures.BlockIcons) GT_Utility.getField(Textures.BlockIcons.class, "INSULATION_MEDIUM_PLUS").get(null); - } catch (IllegalAccessException | NullPointerException e) { - throw new Error(e); - } - } - } - - private short[] vRGB = null; - - public GregtechMetaPipeEntity_Cable(final int aID, final String aName, final String aNameRegional, final float aThickNess, final Materials aMaterial, final long aCableLossPerMeter, final long aAmperage, final long aVoltage, final boolean aInsulated, final boolean aCanShock, final short[] aRGB) { - super(aID, aName, aNameRegional, aThickNess, aMaterial, aCableLossPerMeter, aAmperage, aVoltage, aInsulated, aCanShock); - this.vRGB = aRGB==null || aRGB.length!=4?Materials.Iron.mRGBa:aRGB; - } - - public GregtechMetaPipeEntity_Cable(final String aName, final float aThickNess, final Materials aMaterial, final long aCableLossPerMeter, final long aAmperage, final long aVoltage, final boolean aInsulated, final boolean aCanShock, final short[] aRGB) { - super(aName, aThickNess, aMaterial, aCableLossPerMeter, aAmperage, aVoltage, aInsulated, aCanShock); - this.vRGB = aRGB==null || aRGB.length!=4?Materials.Iron.mRGBa:aRGB; - } - - public GregtechMetaPipeEntity_Cable(final int aID, final String aName, final String aNameRegional, final float aThickNess, final long aCableLossPerMeter, final long aAmperage, final long aVoltage, final boolean aInsulated, final boolean aCanShock, final short[] aRGB) { - this(aID, aName, aNameRegional, aThickNess, null, aCableLossPerMeter, aAmperage, aVoltage, aInsulated, aCanShock,aRGB); - } - - public GregtechMetaPipeEntity_Cable(final String aName, final float aThickNess, final long aCableLossPerMeter, final long aAmperage, final long aVoltage, final boolean aInsulated, final boolean aCanShock, final short[] aRGB) { - this(aName, aThickNess, null, aCableLossPerMeter, aAmperage, aVoltage, aInsulated, aCanShock,aRGB); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaPipeEntity_Cable(this.mName, this.mThickNess, this.mMaterial, this.mCableLossPerMeter, this.mAmperage, this.mVoltage, this.mInsulated, this.mCanShock, this.vRGB); - } - - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aConnections, byte aColorIndex, boolean aConnected, boolean aRedstone) { - return GTNH? - getTextureGTNH(aBaseMetaTileEntity,aSide,aConnections,aColorIndex,aConnected,aRedstone): - getTexturePure(aBaseMetaTileEntity,aSide,aConnections,aColorIndex,aConnected,aRedstone); - } - - private ITexture[] getTextureGTNH(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aConnections, - byte aColorIndex, boolean aConnected, boolean aRedstone) { - - Materials wireMaterial=mMaterial; - if (wireMaterial == null){ - wireMaterial = Materials.Iron; - } - - if (!mInsulated) - return new ITexture[]{new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], Dyes.getModulation(aColorIndex, vRGB) )}; - if (aConnected) { - float tThickNess = getThickNess(); - if (tThickNess < 0.124F) - return new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.INSULATION_FULL, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - if (tThickNess < 0.374F)//0.375 x1 - return new ITexture[]{new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_TINY, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - if (tThickNess < 0.499F)//0.500 x2 - return new ITexture[]{new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_SMALL, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - if (tThickNess < 0.624F)//0.625 x4 - return new ITexture[]{new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_MEDIUM, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - if (tThickNess < 0.749F)//0.750 x8 - return new ITexture[]{new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), new GT_RenderedTexture(INSULATION_MEDIUM_PLUS, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - if (tThickNess < 0.874F)//0.825 x12 - return new ITexture[]{new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_LARGE, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - return new ITexture[]{new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_HUGE, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - } - return new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.INSULATION_FULL, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - } - - private ITexture[] getTexturePure(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aConnections, - byte aColorIndex, boolean aConnected, boolean aRedstone) { - - //if (this.vRGB == null || this.vRGB.length < 3 || this.vRGB.length > 4){ - // this.vRGB = new short[]{200, 0, 200, 0}; - //} - //if (this.vRGB.length != 4){ - // short[] tempRGB = this.vRGB; - // this.vRGB = new short[]{tempRGB[0], tempRGB[1], tempRGB[2], 0}; - //} - // - //Materials wireMaterial = this.mMaterial; - // - //if (wireMaterial == null){ - // wireMaterial = Materials.Iron; - //} - - //With the code in constructors it should work - Materials wireMaterial=mMaterial; - if (wireMaterial == null){ - wireMaterial = Materials.Iron; - } - - if (!(this.mInsulated)) - return new ITexture[] { new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], - Dyes.getModulation(aColorIndex, this.vRGB)) }; - if (aConnected) { - float tThickNess = getThickNess(); - if (tThickNess < 0.124F) - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.INSULATION_FULL, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - if (tThickNess < 0.374F) - return new ITexture[] { - new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_TINY, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - if (tThickNess < 0.499F) - return new ITexture[] { - new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_SMALL, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - if (tThickNess < 0.624F) - return new ITexture[] { - new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_MEDIUM, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - if (tThickNess < 0.749F) - return new ITexture[] { - new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_LARGE, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - if (tThickNess < 0.874F) - return new ITexture[] { - new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_HUGE, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - return new ITexture[] { new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_FULL, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - } - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.INSULATION_FULL, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - } -}
\ No newline at end of file + private static Textures.BlockIcons INSULATION_MEDIUM_PLUS; + + static { + if (GTNH) { + try { + INSULATION_MEDIUM_PLUS = + (Textures.BlockIcons) GT_Utility.getField(Textures.BlockIcons.class, "INSULATION_MEDIUM_PLUS") + .get(null); + } catch (IllegalAccessException | NullPointerException e) { + throw new Error(e); + } + } + } + + private short[] vRGB = null; + + public GregtechMetaPipeEntity_Cable( + final int aID, + final String aName, + final String aNameRegional, + final float aThickNess, + final Materials aMaterial, + final long aCableLossPerMeter, + final long aAmperage, + final long aVoltage, + final boolean aInsulated, + final boolean aCanShock, + final short[] aRGB) { + super( + aID, + aName, + aNameRegional, + aThickNess, + aMaterial, + aCableLossPerMeter, + aAmperage, + aVoltage, + aInsulated, + aCanShock); + this.vRGB = aRGB == null || aRGB.length != 4 ? Materials.Iron.mRGBa : aRGB; + } + + public GregtechMetaPipeEntity_Cable( + final String aName, + final float aThickNess, + final Materials aMaterial, + final long aCableLossPerMeter, + final long aAmperage, + final long aVoltage, + final boolean aInsulated, + final boolean aCanShock, + final short[] aRGB) { + super(aName, aThickNess, aMaterial, aCableLossPerMeter, aAmperage, aVoltage, aInsulated, aCanShock); + this.vRGB = aRGB == null || aRGB.length != 4 ? Materials.Iron.mRGBa : aRGB; + } + + public GregtechMetaPipeEntity_Cable( + final int aID, + final String aName, + final String aNameRegional, + final float aThickNess, + final long aCableLossPerMeter, + final long aAmperage, + final long aVoltage, + final boolean aInsulated, + final boolean aCanShock, + final short[] aRGB) { + this( + aID, + aName, + aNameRegional, + aThickNess, + null, + aCableLossPerMeter, + aAmperage, + aVoltage, + aInsulated, + aCanShock, + aRGB); + } + + public GregtechMetaPipeEntity_Cable( + final String aName, + final float aThickNess, + final long aCableLossPerMeter, + final long aAmperage, + final long aVoltage, + final boolean aInsulated, + final boolean aCanShock, + final short[] aRGB) { + this(aName, aThickNess, null, aCableLossPerMeter, aAmperage, aVoltage, aInsulated, aCanShock, aRGB); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPipeEntity_Cable( + this.mName, + this.mThickNess, + this.mMaterial, + this.mCableLossPerMeter, + this.mAmperage, + this.mVoltage, + this.mInsulated, + this.mCanShock, + this.vRGB); + } + + @Override + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aConnections, + byte aColorIndex, + boolean aConnected, + boolean aRedstone) { + return GTNH + ? getTextureGTNH(aBaseMetaTileEntity, aSide, aConnections, aColorIndex, aConnected, aRedstone) + : getTexturePure(aBaseMetaTileEntity, aSide, aConnections, aColorIndex, aConnected, aRedstone); + } + + private ITexture[] getTextureGTNH( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aConnections, + byte aColorIndex, + boolean aConnected, + boolean aRedstone) { + + Materials wireMaterial = mMaterial; + if (wireMaterial == null) { + wireMaterial = Materials.Iron; + } + + if (!mInsulated) + return new ITexture[] { + new GT_RenderedTexture( + wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], Dyes.getModulation(aColorIndex, vRGB)) + }; + if (aConnected) { + float tThickNess = getThickNess(); + if (tThickNess < 0.124F) + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_FULL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.374F) // 0.375 x1 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_TINY, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.499F) // 0.500 x2 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_SMALL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.624F) // 0.625 x4 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_MEDIUM, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.749F) // 0.750 x8 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + INSULATION_MEDIUM_PLUS, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.874F) // 0.825 x12 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_LARGE, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_HUGE, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_FULL, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + + private ITexture[] getTexturePure( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aConnections, + byte aColorIndex, + boolean aConnected, + boolean aRedstone) { + + // if (this.vRGB == null || this.vRGB.length < 3 || this.vRGB.length > 4){ + // this.vRGB = new short[]{200, 0, 200, 0}; + // } + // if (this.vRGB.length != 4){ + // short[] tempRGB = this.vRGB; + // this.vRGB = new short[]{tempRGB[0], tempRGB[1], tempRGB[2], 0}; + // } + // + // Materials wireMaterial = this.mMaterial; + // + // if (wireMaterial == null){ + // wireMaterial = Materials.Iron; + // } + + // With the code in constructors it should work + Materials wireMaterial = mMaterial; + if (wireMaterial == null) { + wireMaterial = Materials.Iron; + } + + if (!(this.mInsulated)) + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], Dyes.getModulation(aColorIndex, this.vRGB)) + }; + if (aConnected) { + float tThickNess = getThickNess(); + if (tThickNess < 0.124F) + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_FULL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.374F) + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_TINY, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.499F) + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_SMALL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.624F) + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_MEDIUM, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.749F) + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_LARGE, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + if (tThickNess < 0.874F) + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_HUGE, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[69], this.vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_FULL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_FULL, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaTreeFarmerStructural.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaTreeFarmerStructural.java index d05a254bf7..14399e525d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaTreeFarmerStructural.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaTreeFarmerStructural.java @@ -1,56 +1,63 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import net.minecraft.nbt.NBTTagCompound; - 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.metatileentity.implementations.base.machines.GregtechMetaTreeFarmerBase; +import net.minecraft.nbt.NBTTagCompound; -public class GregtechMetaTreeFarmerStructural -extends GregtechMetaTreeFarmerBase { - - @Override - public String[] getDescription() { - return new String[] {this.mDescription}; - } - - public GregtechMetaTreeFarmerStructural(final int aID, final String aName, final String aNameRegional, final int aTier) { - super(aID, aName, aNameRegional, aTier, 0, "Structural Blocks for the Tree Farmer."); - } - - public GregtechMetaTreeFarmerStructural(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 GregtechMetaTreeFarmerStructural(final String aName, final int aTier, final int aInvSlotCount, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aInvSlotCount, aDescription, aTextures); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTreeFarmerStructural(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 false; - } - - @Override - public void saveNBTData(final NBTTagCompound paramNBTTagCompound) { - } - - @Override - public void loadNBTData(final NBTTagCompound paramNBTTagCompound) { - } +public class GregtechMetaTreeFarmerStructural extends GregtechMetaTreeFarmerBase { + + @Override + public String[] getDescription() { + return new String[] {this.mDescription}; + } + + public GregtechMetaTreeFarmerStructural( + final int aID, final String aName, final String aNameRegional, final int aTier) { + super(aID, aName, aNameRegional, aTier, 0, "Structural Blocks for the Tree Farmer."); + } + + public GregtechMetaTreeFarmerStructural( + 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 GregtechMetaTreeFarmerStructural( + final String aName, + final int aTier, + final int aInvSlotCount, + final String aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTreeFarmerStructural( + 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 false; + } + + @Override + public void saveNBTData(final NBTTagCompound paramNBTTagCompound) {} + + @Override + public void loadNBTData(final NBTTagCompound paramNBTTagCompound) {} } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/CustomMetaTileBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/CustomMetaTileBase.java index fdc8a7777b..cd4d0c0edd 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/CustomMetaTileBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/CustomMetaTileBase.java @@ -1,67 +1,70 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; -import java.util.Locale; - import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.GT_LanguageManager; import gtPlusPlus.xmod.gregtech.api.interfaces.IBaseCustomMetaTileEntity; import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; +import java.util.Locale; import net.minecraft.item.ItemStack; public abstract class CustomMetaTileBase extends MetaTileEntity { + private IBaseCustomMetaTileEntity mBaseCustomMetaTileEntity2; - private IBaseCustomMetaTileEntity mBaseCustomMetaTileEntity2; - /** * accessibility to this Field is no longer given, see below */ private IGregTechTileEntity mBaseCustomMetaTileEntity; - - public CustomMetaTileBase(int aID, String aBasicName, String aRegionalName, int aInvSlotCount) { - super(aID, aBasicName, aRegionalName, aInvSlotCount); - GT_LanguageManager.addStringLocalization("gtpp.blockmachines." + aBasicName.replaceAll(" ", "_").toLowerCase(Locale.ENGLISH) + ".name", aRegionalName); - this.setBaseMetaTileEntity(Meta_GT_Proxy.constructBaseMetaTileEntity()); - this.getBaseMetaTileEntity().setMetaTileID((short) aID); - mBaseCustomMetaTileEntity2 = (IBaseCustomMetaTileEntity) getBaseMetaTileEntity(); - } - + + public CustomMetaTileBase(int aID, String aBasicName, String aRegionalName, int aInvSlotCount) { + super(aID, aBasicName, aRegionalName, aInvSlotCount); + GT_LanguageManager.addStringLocalization( + "gtpp.blockmachines." + aBasicName.replaceAll(" ", "_").toLowerCase(Locale.ENGLISH) + ".name", + aRegionalName); + this.setBaseMetaTileEntity(Meta_GT_Proxy.constructBaseMetaTileEntity()); + this.getBaseMetaTileEntity().setMetaTileID((short) aID); + mBaseCustomMetaTileEntity2 = (IBaseCustomMetaTileEntity) getBaseMetaTileEntity(); + } + @Override public IGregTechTileEntity getBaseMetaTileEntity() { return mBaseCustomMetaTileEntity; } - + public IBaseCustomMetaTileEntity getBaseCustomMetaTileEntity() { return mBaseCustomMetaTileEntity2; } @Override public void setBaseMetaTileEntity(IGregTechTileEntity aBaseMetaTileEntity) { - super.setBaseMetaTileEntity(aBaseMetaTileEntity); + super.setBaseMetaTileEntity(aBaseMetaTileEntity); if (mBaseCustomMetaTileEntity != null && aBaseMetaTileEntity == null) { - mBaseCustomMetaTileEntity.getMetaTileEntity().inValidate(); - mBaseCustomMetaTileEntity.setMetaTileEntity(null); + mBaseCustomMetaTileEntity.getMetaTileEntity().inValidate(); + mBaseCustomMetaTileEntity.setMetaTileEntity(null); } mBaseCustomMetaTileEntity = aBaseMetaTileEntity; if (mBaseCustomMetaTileEntity != null) { - mBaseCustomMetaTileEntity.setMetaTileEntity(this); + mBaseCustomMetaTileEntity.setMetaTileEntity(this); } } - public CustomMetaTileBase(String aName, int aInvSlotCount) { - super(aName, aInvSlotCount); - } + public CustomMetaTileBase(String aName, int aInvSlotCount) { + super(aName, aInvSlotCount); + } + + public ItemStack getStackForm(long aAmount) { + return new ItemStack( + Meta_GT_Proxy.sBlockMachines, + (int) aAmount, + this.getBaseMetaTileEntity().getMetaTileID()); + } - public ItemStack getStackForm(long aAmount) { - return new ItemStack(Meta_GT_Proxy.sBlockMachines, (int) aAmount, this.getBaseMetaTileEntity().getMetaTileID()); - } + public String getLocalName() { + return GT_LanguageManager.getTranslation("gtpp.blockmachines." + this.mName + ".name"); + } - public String getLocalName() { - return GT_LanguageManager.getTranslation("gtpp.blockmachines." + this.mName + ".name"); - } - - /** + /** * This determines the BaseMetaTileEntity belonging to this MetaTileEntity by using the Meta ID of the Block itself. * <p/> * 0 = BaseMetaTileEntity, Wrench lvl 0 to dismantlee @@ -76,17 +79,16 @@ public abstract class CustomMetaTileBase extends MetaTileEntity { * 9 = BaseMetaPipeEntity, Cutter lvl 1 to dismantle * 10 = BaseMetaPipeEntity, Cutter lvl 2 to dismantle * 11 = BaseMetaPipeEntity, Cutter lvl 3 to dismantle - * + * * == Reserved for Alk now - * + * * 12 = BaseMetaPipeEntity, Wrench lvl 0 to dismantle * 13 = BaseMetaPipeEntity, Wrench lvl 1 to dismantle * 14 = BaseMetaPipeEntity, Wrench lvl 2 to dismantle * 15 = BaseMetaPipeEntity, Wrench lvl 3 to dismantle */ - @Override + @Override public byte getTileEntityBaseType() { - return 12; - } - -}
\ No newline at end of file + return 12; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java index ba9e618539..f00901c45b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java @@ -1,5 +1,8 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; +import static gregtech.api.enums.Textures.BlockIcons.FLUID_IN_SIGN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_IN; + import gregtech.GT_Mod; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -15,185 +18,182 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; - -import static gregtech.api.enums.Textures.BlockIcons.FLUID_IN_SIGN; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_IN; - public class GT_MetaTileEntity_Hatch_CustomFluidBase extends GT_MetaTileEntity_Hatch { - public final Fluid mLockedFluid; - public final int mFluidCapacity; - protected FluidStack mLockedStack = null; - protected String mTempMod = null; - - public GT_MetaTileEntity_Hatch_CustomFluidBase(Fluid aFluid, int aAmount, final int aID, final String aName, final String aNameRegional) { - super(aID, aName, aNameRegional, 6, 3, new String[]{ - "Fluid Input for Multiblocks", - "Capacity: " + GT_Utility.formatNumbers(aAmount) + "L"}); - this.mLockedFluid = aFluid; - this.mFluidCapacity = aAmount; - } - - public GT_MetaTileEntity_Hatch_CustomFluidBase(Fluid aFluid, int aAmount, final String aName, final String aDescription, - final ITexture[][][] aTextures) { - super(aName, 6, 3, aDescription, aTextures); - this.mLockedFluid = aFluid; - this.mFluidCapacity = aAmount; - } - - public GT_MetaTileEntity_Hatch_CustomFluidBase(Fluid aFluid, int aAmount, final String aName, final String[] aDescription, final ITexture[][][] aTextures) { - super(aName, 6, 3, aDescription[0], aTextures); - this.mLockedFluid = aFluid; - this.mFluidCapacity = aAmount; - } - - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, - final ItemStack aStack) { - if (aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 0) { + public final Fluid mLockedFluid; + public final int mFluidCapacity; + protected FluidStack mLockedStack = null; + protected String mTempMod = null; + + public GT_MetaTileEntity_Hatch_CustomFluidBase( + Fluid aFluid, int aAmount, final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional, 6, 3, new String[] { + "Fluid Input for Multiblocks", "Capacity: " + GT_Utility.formatNumbers(aAmount) + "L" + }); + this.mLockedFluid = aFluid; + this.mFluidCapacity = aAmount; + } + + public GT_MetaTileEntity_Hatch_CustomFluidBase( + Fluid aFluid, int aAmount, final String aName, final String aDescription, final ITexture[][][] aTextures) { + super(aName, 6, 3, aDescription, aTextures); + this.mLockedFluid = aFluid; + this.mFluidCapacity = aAmount; + } + + public GT_MetaTileEntity_Hatch_CustomFluidBase( + Fluid aFluid, + int aAmount, + final String aName, + final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, 6, 3, aDescription[0], aTextures); + this.mLockedFluid = aFluid; + this.mFluidCapacity = aAmount; + } + + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + if (aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 0) { FluidStack fs = GT_Utility.getFluidForFilledItem(aStack, true); - return fs != null && fs.getFluid() == this.mLockedFluid; + return fs != null && fs.getFluid() == this.mLockedFluid; } return false; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 1; - } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch ? - new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(FLUID_IN_SIGN)} : - new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN)}; - } - - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch ? - new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(FLUID_IN_SIGN)} : - new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN)}; - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public boolean doesFillContainers() { - //return true; - return false; - } - - @Override - public boolean doesEmptyContainers() { - return true; - } - - @Override - public boolean canTankBeFilled() { - return true; - } - - @Override - public boolean canTankBeEmptied() { - return true; - } - - @Override - public boolean displaysItemStack() { - return true; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - public void updateSlots() { - if (mInventory[getInputSlot()] != null && mInventory[getInputSlot()].stackSize <= 0) - mInventory[getInputSlot()] = null; - } - - @Override - public int getTankPressure() { - return -100; - } - - public int getCapacity() { - return this.mFluidCapacity; - } - - @Override - public String[] getDescription() { - if (mLockedStack == null) { - mLockedStack = FluidUtils.getFluidStack(mLockedFluid, 1); - } - int aFluidTemp = 0; - boolean isSteam = false; - if (mLockedFluid != null) { - aFluidTemp = mLockedFluid.getTemperature(); - mTempMod = mLockedFluid.getName(); - } - if (mTempMod.equalsIgnoreCase("steam")) { - isSteam = true; - } - - - EnumChatFormatting aColour = EnumChatFormatting.BLUE; - if (aFluidTemp <= -3000) { - aColour = EnumChatFormatting.DARK_PURPLE; - } - else if (aFluidTemp >= -2999 && aFluidTemp <= -500) { - aColour = EnumChatFormatting.DARK_BLUE; - } - else if (aFluidTemp >= -499 && aFluidTemp <= -50) { - aColour = EnumChatFormatting.BLUE; - } - else if (aFluidTemp >= 30 && aFluidTemp <= 300) { - aColour = EnumChatFormatting.AQUA; - } - else if (aFluidTemp >= 301 && aFluidTemp <= 800) { - aColour = EnumChatFormatting.YELLOW; - } - else if (aFluidTemp >= 801 && aFluidTemp <= 1500) { - aColour = EnumChatFormatting.GOLD; - } - else if (aFluidTemp >= 1501) { - aColour = EnumChatFormatting.RED; - } - String aFluidName = "Accepted Fluid: " + aColour + (mLockedStack != null ? mLockedStack.getLocalizedName() : "Empty") + EnumChatFormatting.RESET; - return new String[]{ - "Fluid Input for "+(isSteam ? "Steam " : "")+"Multiblocks", - "Capacity: " + getCapacity()+"L", - aFluidName, - CORE.GT_Tooltip - }; - } - - public boolean isFluidInputAllowed(final FluidStack aFluid) { - return aFluid.getFluid() == this.mLockedFluid; - } - - public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_CustomFluidBase(this.mLockedFluid, this.mFluidCapacity, this.mName, this.mDescription, this.mTextures); - } -}
\ No newline at end of file + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 1; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] {aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(FLUID_IN_SIGN)} + : new ITexture[] {aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN)}; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] {aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(FLUID_IN_SIGN)} + : new ITexture[] {aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN)}; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public boolean doesFillContainers() { + // return true; + return false; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return true; + } + + @Override + public boolean displaysItemStack() { + return true; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + public void updateSlots() { + if (mInventory[getInputSlot()] != null && mInventory[getInputSlot()].stackSize <= 0) + mInventory[getInputSlot()] = null; + } + + @Override + public int getTankPressure() { + return -100; + } + + public int getCapacity() { + return this.mFluidCapacity; + } + + @Override + public String[] getDescription() { + if (mLockedStack == null) { + mLockedStack = FluidUtils.getFluidStack(mLockedFluid, 1); + } + int aFluidTemp = 0; + boolean isSteam = false; + if (mLockedFluid != null) { + aFluidTemp = mLockedFluid.getTemperature(); + mTempMod = mLockedFluid.getName(); + } + if (mTempMod.equalsIgnoreCase("steam")) { + isSteam = true; + } + + EnumChatFormatting aColour = EnumChatFormatting.BLUE; + if (aFluidTemp <= -3000) { + aColour = EnumChatFormatting.DARK_PURPLE; + } else if (aFluidTemp >= -2999 && aFluidTemp <= -500) { + aColour = EnumChatFormatting.DARK_BLUE; + } else if (aFluidTemp >= -499 && aFluidTemp <= -50) { + aColour = EnumChatFormatting.BLUE; + } else if (aFluidTemp >= 30 && aFluidTemp <= 300) { + aColour = EnumChatFormatting.AQUA; + } else if (aFluidTemp >= 301 && aFluidTemp <= 800) { + aColour = EnumChatFormatting.YELLOW; + } else if (aFluidTemp >= 801 && aFluidTemp <= 1500) { + aColour = EnumChatFormatting.GOLD; + } else if (aFluidTemp >= 1501) { + aColour = EnumChatFormatting.RED; + } + String aFluidName = "Accepted Fluid: " + aColour + + (mLockedStack != null ? mLockedStack.getLocalizedName() : "Empty") + EnumChatFormatting.RESET; + return new String[] { + "Fluid Input for " + (isSteam ? "Steam " : "") + "Multiblocks", + "Capacity: " + getCapacity() + "L", + aFluidName, + CORE.GT_Tooltip + }; + } + + public boolean isFluidInputAllowed(final FluidStack aFluid) { + return aFluid.getFluid() == this.mLockedFluid; + } + + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_CustomFluidBase( + this.mLockedFluid, this.mFluidCapacity, this.mName, this.mDescription, this.mTextures); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java index 4dd5bf25d6..efc2d008bb 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java @@ -2,21 +2,7 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; import static gregtech.api.enums.GT_Values.VN; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; - import cofh.api.energy.IEnergyReceiver; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; - import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.Dyes; @@ -33,436 +19,534 @@ import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Proxy; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; import ic2.api.energy.tile.IEnergySink; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; public class GregtechMetaPipeEntityBase_Cable extends MetaPipeEntity implements IMetaTileEntityCable { - public final float mThickNess; - public final GT_Materials mMaterial; - public final long mCableLossPerMeter, mAmperage, mVoltage; - public final boolean mInsulated, mCanShock; - public long mTransferredAmperage = 0, mTransferredAmperageLast20 = 0, mTransferredVoltageLast20 = 0; - public long mRestRF; - public short mOverheat; - public final int mWireHeatingTicks; - - public GregtechMetaPipeEntityBase_Cable(final int aID, final String aName, final String aNameRegional, - final float aThickNess, final GT_Materials aMaterial, final long aCableLossPerMeter, final long aAmperage, - final long aVoltage, final boolean aInsulated, final boolean aCanShock) { - super(aID, aName, aNameRegional, 0); - this.mThickNess = aThickNess; - this.mMaterial = aMaterial; - this.mAmperage = aAmperage; - this.mVoltage = aVoltage; - this.mInsulated = aInsulated; - this.mCanShock = aCanShock; - this.mCableLossPerMeter = aCableLossPerMeter; - this.mWireHeatingTicks = this.getGT5Var(); - } - - public GregtechMetaPipeEntityBase_Cable(final String aName, final float aThickNess, final GT_Materials aMaterial, - final long aCableLossPerMeter, final long aAmperage, final long aVoltage, final boolean aInsulated, - final boolean aCanShock) { - super(aName, 0); - this.mThickNess = aThickNess; - this.mMaterial = aMaterial; - this.mAmperage = aAmperage; - this.mVoltage = aVoltage; - this.mInsulated = aInsulated; - this.mCanShock = aCanShock; - this.mCableLossPerMeter = aCableLossPerMeter; - this.mWireHeatingTicks = this.getGT5Var(); - } - - private int getGT5Var() { - final Class<? extends GT_Proxy> clazz = GT_Mod.gregtechproxy.getClass(); - final String lookingForValue = "mWireHeatingTicks"; - int temp = 4; - Field field; - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - try { - field = clazz.getClass().getField(lookingForValue); - final Class<?> clazzType = field.getType(); - if (clazzType.toString().equals("int")) { - temp = (field.getInt(clazz)); - } else { - temp = 4; - } - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - // Utils.LOG_INFO("FATAL ERROR - REFLECTION FAILED FOR GT CABLES - // - PLEASE REPORT THIS."); - Logger.WARNING("FATAL ERROR - REFLECTION FAILED FOR GT CABLES - PLEASE REPORT THIS."); - Logger.ERROR("FATAL ERROR - REFLECTION FAILED FOR GT CABLES - PLEASE REPORT THIS."); - temp = 4; - } - } - return temp; - } - - @Override - public byte getTileEntityBaseType() { - return (byte) (this.mInsulated ? 9 : 8); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaPipeEntityBase_Cable(this.mName, this.mThickNess, this.mMaterial, - this.mCableLossPerMeter, this.mAmperage, this.mVoltage, this.mInsulated, this.mCanShock); - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, - final byte aConnections, final byte aColorIndex, final boolean aConnected, final boolean aRedstone) { - if (!this.mInsulated) { - return new ITexture[] { new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], - this.mMaterial.mRGBa) }; - } - if (aConnected) { - final float tThickNess = this.getThickNess(); - if (tThickNess < 0.37F) { - return new ITexture[] { - new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], - this.mMaterial.mRGBa), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_TINY, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - } - if (tThickNess < 0.49F) { - return new ITexture[] { - new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], - this.mMaterial.mRGBa), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_SMALL, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - } - if (tThickNess < 0.74F) { - return new ITexture[] { - new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], - this.mMaterial.mRGBa), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_MEDIUM, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - } - if (tThickNess < 0.99F) { - return new ITexture[] { - new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], - this.mMaterial.mRGBa), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_LARGE, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - } - return new ITexture[] { - new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], - this.mMaterial.mRGBa), - new GT_RenderedTexture(Textures.BlockIcons.INSULATION_HUGE, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - } - return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.INSULATION_FULL, - Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; - } - - @Override - public void onEntityCollidedWithBlock(final World aWorld, final int aX, final int aY, final int aZ, - final Entity aEntity) { - if (this.mCanShock && ((((BaseMetaPipeEntity) this.getBaseMetaTileEntity()).mConnections & -128) == 0) - && (aEntity instanceof EntityLivingBase)) { - GT_Utility.applyElectricityDamage((EntityLivingBase) aEntity, this.mTransferredVoltageLast20, - this.mTransferredAmperageLast20); - } - } - - @Override - public AxisAlignedBB getCollisionBoundingBoxFromPool(final World aWorld, final int aX, final int aY, final int aZ) { - if (!this.mCanShock) { - return super.getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ); - } - return AxisAlignedBB.getBoundingBox(aX + 0.125D, aY + 0.125D, aZ + 0.125D, aX + 0.875D, aY + 0.875D, - aZ + 0.875D); - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(final byte aFacing) { - return false; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return true; - } - - @Override - public final boolean renderInside(final byte aSide) { - return false; - } - - @Override - public int getProgresstime() { - return (int) this.mTransferredAmperage * 64; - } - - @Override - public int maxProgresstime() { - return (int) this.mAmperage * 64; - } - - @Override - public long injectEnergyUnits(final byte aSide, final long aVoltage, final long aAmperage) { - if (!this.getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).letsEnergyIn(aSide, - this.getBaseMetaTileEntity().getCoverIDAtSide(aSide), - this.getBaseMetaTileEntity().getCoverDataAtSide(aSide), this.getBaseMetaTileEntity())) { - return 0; - } - return this.transferElectricity(aSide, aVoltage, aAmperage, - new ArrayList<>(Arrays.asList((TileEntity) this.getBaseMetaTileEntity()))); - } - - - /** - * Adds support for the newer function added by https://github.com/Blood-Asp/GT5-Unofficial/commit/73ee102b63efd92c0f164a7ed7a79ebcd2619617#diff-3051838621d8ae87aa5ccd1345e1f07d - */ - public long transferElectricity(byte arg0, long arg1, long arg2, HashSet<TileEntity> arg3) { - ArrayList<TileEntity> aTiles = new ArrayList<TileEntity>(); - for (TileEntity y : arg3) { - aTiles.add(y); - } - return transferElectricity(arg0, arg1, arg2, aTiles); - } - - @Override - public long transferElectricity(final byte aSide, long aVoltage, final long aAmperage, - final ArrayList<TileEntity> aAlreadyPassedTileEntityList) { - long rUsedAmperes = 0; - aVoltage -= this.mCableLossPerMeter; - if (aVoltage > 0) { - for (byte i = 0; (i < 6) && (aAmperage > rUsedAmperes); i++) { - if ((i != aSide) && ((this.mConnections & (1 << i)) != 0) - && this.getBaseMetaTileEntity().getCoverBehaviorAtSide(i).letsEnergyOut(i, - this.getBaseMetaTileEntity().getCoverIDAtSide(i), - this.getBaseMetaTileEntity().getCoverDataAtSide(i), this.getBaseMetaTileEntity())) { - final TileEntity tTileEntity = this.getBaseMetaTileEntity().getTileEntityAtSide(i); - if (!aAlreadyPassedTileEntityList.contains(tTileEntity)) { - aAlreadyPassedTileEntityList.add(tTileEntity); - if (tTileEntity instanceof IEnergyConnected) { - if (this.getBaseMetaTileEntity().getColorization() >= 0) { - final byte tColor = ((IEnergyConnected) tTileEntity).getColorization(); - if ((tColor >= 0) && (tColor != this.getBaseMetaTileEntity().getColorization())) { - continue; - } - } - if ((tTileEntity instanceof IGregTechTileEntity) - && (((IGregTechTileEntity) tTileEntity) - .getMetaTileEntity() instanceof IMetaTileEntityCable) - && ((IGregTechTileEntity) tTileEntity) - .getCoverBehaviorAtSide(GT_Utility.getOppositeSide(i)) - .letsEnergyIn(GT_Utility.getOppositeSide(i), - ((IGregTechTileEntity) tTileEntity) - .getCoverIDAtSide(GT_Utility.getOppositeSide(i)), - ((IGregTechTileEntity) tTileEntity) - .getCoverDataAtSide(GT_Utility.getOppositeSide(i)), - ((IGregTechTileEntity) tTileEntity))) { - if (((IGregTechTileEntity) tTileEntity).getTimer() > 50) { - rUsedAmperes += ((IMetaTileEntityCable) ((IGregTechTileEntity) tTileEntity) - .getMetaTileEntity()).transferElectricity(GT_Utility.getOppositeSide(i), - aVoltage, aAmperage - rUsedAmperes, aAlreadyPassedTileEntityList); - } - } else { - rUsedAmperes += ((IEnergyConnected) tTileEntity).injectEnergyUnits( - GT_Utility.getOppositeSide(i), aVoltage, aAmperage - rUsedAmperes); - } - // } else if (tTileEntity instanceof IEnergySink) { - // ForgeDirection tDirection = - // ForgeDirection.getOrientation(i).getOpposite(); - // if - // (((IEnergySink)tTileEntity).acceptsEnergyFrom((TileEntity)getBaseMetaTileEntity(), - // tDirection)) { - // if - // (((IEnergySink)tTileEntity).demandedEnergyUnits() - // > 0 && - // ((IEnergySink)tTileEntity).injectEnergyUnits(tDirection, - // aVoltage) < aVoltage) rUsedAmperes++; - // } - } else if (tTileEntity instanceof IEnergySink) { - final ForgeDirection tDirection = ForgeDirection.getOrientation(i).getOpposite(); - if (((IEnergySink) tTileEntity).acceptsEnergyFrom((TileEntity) this.getBaseMetaTileEntity(), - tDirection)) { - if ((((IEnergySink) tTileEntity).getDemandedEnergy() > 0) - && (((IEnergySink) tTileEntity).injectEnergy(tDirection, aVoltage, - aVoltage) < aVoltage)) { - rUsedAmperes++; - } - } - } else if (GregTech_API.mOutputRF && (tTileEntity instanceof IEnergyReceiver)) { - final ForgeDirection tDirection = ForgeDirection.getOrientation(i).getOpposite(); - final int rfOut = (int) ((aVoltage * GregTech_API.mEUtoRF) / 100); - if (((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, true) == rfOut) { - ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, false); - rUsedAmperes++; - } else if (((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, true) > 0) { - if (this.mRestRF == 0) { - final int RFtrans = ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, - false); - rUsedAmperes++; - this.mRestRF = rfOut - RFtrans; - } else { - final int RFtrans = ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, - (int) this.mRestRF, false); - this.mRestRF = this.mRestRF - RFtrans; - } - } - if (GregTech_API.mRFExplosions && (((IEnergyReceiver) tTileEntity) - .getMaxEnergyStored(tDirection) < (rfOut * 600))) { - if (rfOut > ((32 * GregTech_API.mEUtoRF) / 100)) { - this.doExplosion(rfOut); - } - } - } - } - } - } - } - - this.mTransferredAmperage += rUsedAmperes; - this.mTransferredVoltageLast20 = Math.max(this.mTransferredVoltageLast20, aVoltage); - this.mTransferredAmperageLast20 = Math.max(this.mTransferredAmperageLast20, this.mTransferredAmperage); - - if ((aVoltage > this.mVoltage) || (this.mTransferredAmperage > this.mAmperage)) { - // GT 5.09 - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - if (this.mOverheat > (this.mWireHeatingTicks * 100)) { - this.getBaseMetaTileEntity().setToFire(); - } else { - this.mOverheat += 100; - } - return aAmperage; - } - // GT 5.08 - else { - this.getBaseMetaTileEntity().setToFire(); - return aAmperage; - } - } - - return rUsedAmperes; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - this.mTransferredAmperage = 0; - if (this.mOverheat > 0) { - this.mOverheat--; - } - - if ((aTick % 20) == 0) { - this.mTransferredVoltageLast20 = 0; - this.mTransferredAmperageLast20 = 0; - this.mConnections = 0; - for (byte i = 0, j = 0; i < 6; i++) { - j = GT_Utility.getOppositeSide(i); - if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).alwaysLookConnected(i, - aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), - aBaseMetaTileEntity) - || aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsEnergyIn(i, - aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), - aBaseMetaTileEntity) - || aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsEnergyOut(i, - aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), - aBaseMetaTileEntity)) { - final TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(i); - if (tTileEntity instanceof IColoredTileEntity) { - if (aBaseMetaTileEntity.getColorization() >= 0) { - final byte tColor = ((IColoredTileEntity) tTileEntity).getColorization(); - if ((tColor >= 0) && (tColor != aBaseMetaTileEntity.getColorization())) { - continue; - } - } - } - if ((tTileEntity instanceof IEnergyConnected) - && (((IEnergyConnected) tTileEntity).inputEnergyFrom(j) - || ((IEnergyConnected) tTileEntity).outputsEnergyTo(j))) { - this.mConnections |= (1 << i); - continue; - } - if ((tTileEntity instanceof IGregTechTileEntity) && (((IGregTechTileEntity) tTileEntity) - .getMetaTileEntity() instanceof IMetaTileEntityCable)) { - if (((IGregTechTileEntity) tTileEntity).getCoverBehaviorAtSide(j).alwaysLookConnected(j, - ((IGregTechTileEntity) tTileEntity).getCoverIDAtSide(j), - ((IGregTechTileEntity) tTileEntity).getCoverDataAtSide(j), - ((IGregTechTileEntity) tTileEntity)) - || ((IGregTechTileEntity) tTileEntity).getCoverBehaviorAtSide(j).letsEnergyIn(j, - ((IGregTechTileEntity) tTileEntity).getCoverIDAtSide(j), - ((IGregTechTileEntity) tTileEntity).getCoverDataAtSide(j), - ((IGregTechTileEntity) tTileEntity)) - || ((IGregTechTileEntity) tTileEntity).getCoverBehaviorAtSide(j).letsEnergyOut(j, - ((IGregTechTileEntity) tTileEntity).getCoverIDAtSide(j), - ((IGregTechTileEntity) tTileEntity).getCoverDataAtSide(j), - ((IGregTechTileEntity) tTileEntity))) { - this.mConnections |= (1 << i); - continue; - } - } - if ((tTileEntity instanceof IEnergySink) && ((IEnergySink) tTileEntity).acceptsEnergyFrom( - (TileEntity) aBaseMetaTileEntity, ForgeDirection.getOrientation(j))) { - this.mConnections |= (1 << i); - continue; - } - if (GregTech_API.mOutputRF && (tTileEntity instanceof IEnergyReceiver) - && ((IEnergyReceiver) tTileEntity).canConnectEnergy(ForgeDirection.getOrientation(j))) { - this.mConnections |= (1 << i); - continue; - } - /* - * if (tTileEntity instanceof IEnergyEmitter && - * ((IEnergyEmitter)tTileEntity).emitsEnergyTo(( - * TileEntity)aBaseMetaTileEntity, - * ForgeDirection.getOrientation(j))) { mConnections |= - * (1<<i); continue; } - */ - } - } - } - } - } - - @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[] getDescription() { - return new String[] { - "Max Voltage: " + EnumChatFormatting.GREEN + this.mVoltage + " (" - + VN[GT_Utility.getTier(this.mVoltage)] + ")" + EnumChatFormatting.GRAY, - "Max Amperage: " + EnumChatFormatting.YELLOW + this.mAmperage + EnumChatFormatting.GRAY, - "Loss/Meter/Ampere: " + EnumChatFormatting.RED + this.mCableLossPerMeter + EnumChatFormatting.GRAY - + " EU-Volt" }; - } - - @Override - public float getThickNess() { - return this.mThickNess; - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - // - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - // - } -}
\ No newline at end of file + public final float mThickNess; + public final GT_Materials mMaterial; + public final long mCableLossPerMeter, mAmperage, mVoltage; + public final boolean mInsulated, mCanShock; + public long mTransferredAmperage = 0, mTransferredAmperageLast20 = 0, mTransferredVoltageLast20 = 0; + public long mRestRF; + public short mOverheat; + public final int mWireHeatingTicks; + + public GregtechMetaPipeEntityBase_Cable( + final int aID, + final String aName, + final String aNameRegional, + final float aThickNess, + final GT_Materials aMaterial, + final long aCableLossPerMeter, + final long aAmperage, + final long aVoltage, + final boolean aInsulated, + final boolean aCanShock) { + super(aID, aName, aNameRegional, 0); + this.mThickNess = aThickNess; + this.mMaterial = aMaterial; + this.mAmperage = aAmperage; + this.mVoltage = aVoltage; + this.mInsulated = aInsulated; + this.mCanShock = aCanShock; + this.mCableLossPerMeter = aCableLossPerMeter; + this.mWireHeatingTicks = this.getGT5Var(); + } + + public GregtechMetaPipeEntityBase_Cable( + final String aName, + final float aThickNess, + final GT_Materials aMaterial, + final long aCableLossPerMeter, + final long aAmperage, + final long aVoltage, + final boolean aInsulated, + final boolean aCanShock) { + super(aName, 0); + this.mThickNess = aThickNess; + this.mMaterial = aMaterial; + this.mAmperage = aAmperage; + this.mVoltage = aVoltage; + this.mInsulated = aInsulated; + this.mCanShock = aCanShock; + this.mCableLossPerMeter = aCableLossPerMeter; + this.mWireHeatingTicks = this.getGT5Var(); + } + + private int getGT5Var() { + final Class<? extends GT_Proxy> clazz = GT_Mod.gregtechproxy.getClass(); + final String lookingForValue = "mWireHeatingTicks"; + int temp = 4; + Field field; + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + try { + field = clazz.getClass().getField(lookingForValue); + final Class<?> clazzType = field.getType(); + if (clazzType.toString().equals("int")) { + temp = (field.getInt(clazz)); + } else { + temp = 4; + } + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + // Utils.LOG_INFO("FATAL ERROR - REFLECTION FAILED FOR GT CABLES + // - PLEASE REPORT THIS."); + Logger.WARNING("FATAL ERROR - REFLECTION FAILED FOR GT CABLES - PLEASE REPORT THIS."); + Logger.ERROR("FATAL ERROR - REFLECTION FAILED FOR GT CABLES - PLEASE REPORT THIS."); + temp = 4; + } + } + return temp; + } + + @Override + public byte getTileEntityBaseType() { + return (byte) (this.mInsulated ? 9 : 8); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPipeEntityBase_Cable( + this.mName, + this.mThickNess, + this.mMaterial, + this.mCableLossPerMeter, + this.mAmperage, + this.mVoltage, + this.mInsulated, + this.mCanShock); + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aConnections, + final byte aColorIndex, + final boolean aConnected, + final boolean aRedstone) { + if (!this.mInsulated) { + return new ITexture[] { + new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa) + }; + } + if (aConnected) { + final float tThickNess = this.getThickNess(); + if (tThickNess < 0.37F) { + return new ITexture[] { + new GT_RenderedTexture( + this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_TINY, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + if (tThickNess < 0.49F) { + return new ITexture[] { + new GT_RenderedTexture( + this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_SMALL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + if (tThickNess < 0.74F) { + return new ITexture[] { + new GT_RenderedTexture( + this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_MEDIUM, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + if (tThickNess < 0.99F) { + return new ITexture[] { + new GT_RenderedTexture( + this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_LARGE, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + return new ITexture[] { + new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_HUGE, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_FULL, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) + }; + } + + @Override + public void onEntityCollidedWithBlock( + final World aWorld, final int aX, final int aY, final int aZ, final Entity aEntity) { + if (this.mCanShock + && ((((BaseMetaPipeEntity) this.getBaseMetaTileEntity()).mConnections & -128) == 0) + && (aEntity instanceof EntityLivingBase)) { + GT_Utility.applyElectricityDamage( + (EntityLivingBase) aEntity, this.mTransferredVoltageLast20, this.mTransferredAmperageLast20); + } + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(final World aWorld, final int aX, final int aY, final int aZ) { + if (!this.mCanShock) { + return super.getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ); + } + return AxisAlignedBB.getBoundingBox( + aX + 0.125D, aY + 0.125D, aZ + 0.125D, aX + 0.875D, aY + 0.875D, aZ + 0.875D); + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public final boolean renderInside(final byte aSide) { + return false; + } + + @Override + public int getProgresstime() { + return (int) this.mTransferredAmperage * 64; + } + + @Override + public int maxProgresstime() { + return (int) this.mAmperage * 64; + } + + @Override + public long injectEnergyUnits(final byte aSide, final long aVoltage, final long aAmperage) { + if (!this.getBaseMetaTileEntity() + .getCoverBehaviorAtSide(aSide) + .letsEnergyIn( + aSide, + this.getBaseMetaTileEntity().getCoverIDAtSide(aSide), + this.getBaseMetaTileEntity().getCoverDataAtSide(aSide), + this.getBaseMetaTileEntity())) { + return 0; + } + return this.transferElectricity( + aSide, aVoltage, aAmperage, new ArrayList<>(Arrays.asList((TileEntity) this.getBaseMetaTileEntity()))); + } + + /** + * Adds support for the newer function added by https://github.com/Blood-Asp/GT5-Unofficial/commit/73ee102b63efd92c0f164a7ed7a79ebcd2619617#diff-3051838621d8ae87aa5ccd1345e1f07d + */ + public long transferElectricity(byte arg0, long arg1, long arg2, HashSet<TileEntity> arg3) { + ArrayList<TileEntity> aTiles = new ArrayList<TileEntity>(); + for (TileEntity y : arg3) { + aTiles.add(y); + } + return transferElectricity(arg0, arg1, arg2, aTiles); + } + + @Override + public long transferElectricity( + final byte aSide, + long aVoltage, + final long aAmperage, + final ArrayList<TileEntity> aAlreadyPassedTileEntityList) { + long rUsedAmperes = 0; + aVoltage -= this.mCableLossPerMeter; + if (aVoltage > 0) { + for (byte i = 0; (i < 6) && (aAmperage > rUsedAmperes); i++) { + if ((i != aSide) + && ((this.mConnections & (1 << i)) != 0) + && this.getBaseMetaTileEntity() + .getCoverBehaviorAtSide(i) + .letsEnergyOut( + i, + this.getBaseMetaTileEntity().getCoverIDAtSide(i), + this.getBaseMetaTileEntity().getCoverDataAtSide(i), + this.getBaseMetaTileEntity())) { + final TileEntity tTileEntity = this.getBaseMetaTileEntity().getTileEntityAtSide(i); + if (!aAlreadyPassedTileEntityList.contains(tTileEntity)) { + aAlreadyPassedTileEntityList.add(tTileEntity); + if (tTileEntity instanceof IEnergyConnected) { + if (this.getBaseMetaTileEntity().getColorization() >= 0) { + final byte tColor = ((IEnergyConnected) tTileEntity).getColorization(); + if ((tColor >= 0) + && (tColor + != this.getBaseMetaTileEntity().getColorization())) { + continue; + } + } + if ((tTileEntity instanceof IGregTechTileEntity) + && (((IGregTechTileEntity) tTileEntity).getMetaTileEntity() + instanceof IMetaTileEntityCable) + && ((IGregTechTileEntity) tTileEntity) + .getCoverBehaviorAtSide(GT_Utility.getOppositeSide(i)) + .letsEnergyIn( + GT_Utility.getOppositeSide(i), + ((IGregTechTileEntity) tTileEntity) + .getCoverIDAtSide(GT_Utility.getOppositeSide(i)), + ((IGregTechTileEntity) tTileEntity) + .getCoverDataAtSide(GT_Utility.getOppositeSide(i)), + ((IGregTechTileEntity) tTileEntity))) { + if (((IGregTechTileEntity) tTileEntity).getTimer() > 50) { + rUsedAmperes += ((IMetaTileEntityCable) + ((IGregTechTileEntity) tTileEntity).getMetaTileEntity()) + .transferElectricity( + GT_Utility.getOppositeSide(i), + aVoltage, + aAmperage - rUsedAmperes, + aAlreadyPassedTileEntityList); + } + } else { + rUsedAmperes += ((IEnergyConnected) tTileEntity) + .injectEnergyUnits( + GT_Utility.getOppositeSide(i), aVoltage, aAmperage - rUsedAmperes); + } + // } else if (tTileEntity instanceof IEnergySink) { + // ForgeDirection tDirection = + // ForgeDirection.getOrientation(i).getOpposite(); + // if + // (((IEnergySink)tTileEntity).acceptsEnergyFrom((TileEntity)getBaseMetaTileEntity(), + // tDirection)) { + // if + // (((IEnergySink)tTileEntity).demandedEnergyUnits() + // > 0 && + // ((IEnergySink)tTileEntity).injectEnergyUnits(tDirection, + // aVoltage) < aVoltage) rUsedAmperes++; + // } + } else if (tTileEntity instanceof IEnergySink) { + final ForgeDirection tDirection = + ForgeDirection.getOrientation(i).getOpposite(); + if (((IEnergySink) tTileEntity) + .acceptsEnergyFrom((TileEntity) this.getBaseMetaTileEntity(), tDirection)) { + if ((((IEnergySink) tTileEntity).getDemandedEnergy() > 0) + && (((IEnergySink) tTileEntity).injectEnergy(tDirection, aVoltage, aVoltage) + < aVoltage)) { + rUsedAmperes++; + } + } + } else if (GregTech_API.mOutputRF && (tTileEntity instanceof IEnergyReceiver)) { + final ForgeDirection tDirection = + ForgeDirection.getOrientation(i).getOpposite(); + final int rfOut = (int) ((aVoltage * GregTech_API.mEUtoRF) / 100); + if (((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, true) == rfOut) { + ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, false); + rUsedAmperes++; + } else if (((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, true) > 0) { + if (this.mRestRF == 0) { + final int RFtrans = + ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, false); + rUsedAmperes++; + this.mRestRF = rfOut - RFtrans; + } else { + final int RFtrans = ((IEnergyReceiver) tTileEntity) + .receiveEnergy(tDirection, (int) this.mRestRF, false); + this.mRestRF = this.mRestRF - RFtrans; + } + } + if (GregTech_API.mRFExplosions + && (((IEnergyReceiver) tTileEntity).getMaxEnergyStored(tDirection) + < (rfOut * 600))) { + if (rfOut > ((32 * GregTech_API.mEUtoRF) / 100)) { + this.doExplosion(rfOut); + } + } + } + } + } + } + } + + this.mTransferredAmperage += rUsedAmperes; + this.mTransferredVoltageLast20 = Math.max(this.mTransferredVoltageLast20, aVoltage); + this.mTransferredAmperageLast20 = Math.max(this.mTransferredAmperageLast20, this.mTransferredAmperage); + + if ((aVoltage > this.mVoltage) || (this.mTransferredAmperage > this.mAmperage)) { + // GT 5.09 + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + if (this.mOverheat > (this.mWireHeatingTicks * 100)) { + this.getBaseMetaTileEntity().setToFire(); + } else { + this.mOverheat += 100; + } + return aAmperage; + } + // GT 5.08 + else { + this.getBaseMetaTileEntity().setToFire(); + return aAmperage; + } + } + + return rUsedAmperes; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + this.mTransferredAmperage = 0; + if (this.mOverheat > 0) { + this.mOverheat--; + } + + if ((aTick % 20) == 0) { + this.mTransferredVoltageLast20 = 0; + this.mTransferredAmperageLast20 = 0; + this.mConnections = 0; + for (byte i = 0, j = 0; i < 6; i++) { + j = GT_Utility.getOppositeSide(i); + if (aBaseMetaTileEntity + .getCoverBehaviorAtSide(i) + .alwaysLookConnected( + i, + aBaseMetaTileEntity.getCoverIDAtSide(i), + aBaseMetaTileEntity.getCoverDataAtSide(i), + aBaseMetaTileEntity) + || aBaseMetaTileEntity + .getCoverBehaviorAtSide(i) + .letsEnergyIn( + i, + aBaseMetaTileEntity.getCoverIDAtSide(i), + aBaseMetaTileEntity.getCoverDataAtSide(i), + aBaseMetaTileEntity) + || aBaseMetaTileEntity + .getCoverBehaviorAtSide(i) + .letsEnergyOut( + i, + aBaseMetaTileEntity.getCoverIDAtSide(i), + aBaseMetaTileEntity.getCoverDataAtSide(i), + aBaseMetaTileEntity)) { + final TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(i); + if (tTileEntity instanceof IColoredTileEntity) { + if (aBaseMetaTileEntity.getColorization() >= 0) { + final byte tColor = ((IColoredTileEntity) tTileEntity).getColorization(); + if ((tColor >= 0) && (tColor != aBaseMetaTileEntity.getColorization())) { + continue; + } + } + } + if ((tTileEntity instanceof IEnergyConnected) + && (((IEnergyConnected) tTileEntity).inputEnergyFrom(j) + || ((IEnergyConnected) tTileEntity).outputsEnergyTo(j))) { + this.mConnections |= (1 << i); + continue; + } + if ((tTileEntity instanceof IGregTechTileEntity) + && (((IGregTechTileEntity) tTileEntity).getMetaTileEntity() + instanceof IMetaTileEntityCable)) { + if (((IGregTechTileEntity) tTileEntity) + .getCoverBehaviorAtSide(j) + .alwaysLookConnected( + j, + ((IGregTechTileEntity) tTileEntity).getCoverIDAtSide(j), + ((IGregTechTileEntity) tTileEntity).getCoverDataAtSide(j), + ((IGregTechTileEntity) tTileEntity)) + || ((IGregTechTileEntity) tTileEntity) + .getCoverBehaviorAtSide(j) + .letsEnergyIn( + j, + ((IGregTechTileEntity) tTileEntity).getCoverIDAtSide(j), + ((IGregTechTileEntity) tTileEntity).getCoverDataAtSide(j), + ((IGregTechTileEntity) tTileEntity)) + || ((IGregTechTileEntity) tTileEntity) + .getCoverBehaviorAtSide(j) + .letsEnergyOut( + j, + ((IGregTechTileEntity) tTileEntity).getCoverIDAtSide(j), + ((IGregTechTileEntity) tTileEntity).getCoverDataAtSide(j), + ((IGregTechTileEntity) tTileEntity))) { + this.mConnections |= (1 << i); + continue; + } + } + if ((tTileEntity instanceof IEnergySink) + && ((IEnergySink) tTileEntity) + .acceptsEnergyFrom( + (TileEntity) aBaseMetaTileEntity, ForgeDirection.getOrientation(j))) { + this.mConnections |= (1 << i); + continue; + } + if (GregTech_API.mOutputRF + && (tTileEntity instanceof IEnergyReceiver) + && ((IEnergyReceiver) tTileEntity).canConnectEnergy(ForgeDirection.getOrientation(j))) { + this.mConnections |= (1 << i); + continue; + } + /* + * if (tTileEntity instanceof IEnergyEmitter && + * ((IEnergyEmitter)tTileEntity).emitsEnergyTo(( + * TileEntity)aBaseMetaTileEntity, + * ForgeDirection.getOrientation(j))) { mConnections |= + * (1<<i); continue; } + */ + } + } + } + } + } + + @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[] getDescription() { + return new String[] { + "Max Voltage: " + EnumChatFormatting.GREEN + this.mVoltage + " (" + VN[GT_Utility.getTier(this.mVoltage)] + + ")" + EnumChatFormatting.GRAY, + "Max Amperage: " + EnumChatFormatting.YELLOW + this.mAmperage + EnumChatFormatting.GRAY, + "Loss/Meter/Ampere: " + EnumChatFormatting.RED + this.mCableLossPerMeter + EnumChatFormatting.GRAY + + " EU-Volt" + }; + } + + @Override + public float getThickNess() { + return this.mThickNess; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + // + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + // + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTileEntity.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTileEntity.java index c9201471a4..41f434f7e6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTileEntity.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTileEntity.java @@ -5,73 +5,80 @@ import static gregtech.api.enums.GT_Values.GT; import gregtech.api.interfaces.ITexture; import gregtech.api.metatileentity.MetaTileEntity; -import gtPlusPlus.core.lib.CORE; - public abstract class GregtechMetaTileEntity extends MetaTileEntity { - /** - * Value between [0 - 9] to describe the Tier of this Machine. - */ - protected byte mTier; - - /** - * A simple Description. - */ - protected final String mDescription; + /** + * Value between [0 - 9] to describe the Tier of this Machine. + */ + protected byte mTier; - /** - * Contains all Textures used by this Block. - */ - public final ITexture[][][] mTextures; + /** + * A simple Description. + */ + protected final String mDescription; - public GregtechMetaTileEntity(final int aID, final String aName, final String aNameRegional, final int aTier, - final int aInvSlotCount, final String aDescription, final ITexture... aTextures) { - super(aID, aName, aNameRegional, aInvSlotCount); - this.mTier = (byte) Math.max(0, Math.min(aTier, 9)); - this.mDescription = aDescription; + /** + * Contains all Textures used by this Block. + */ + public final ITexture[][][] mTextures; - // must always be the last call! - if (GT.isClientSide()) { - this.mTextures = this.getTextureSet(aTextures); - } else { - this.mTextures = null; - } - } + public GregtechMetaTileEntity( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final int aInvSlotCount, + final String aDescription, + final ITexture... aTextures) { + super(aID, aName, aNameRegional, aInvSlotCount); + this.mTier = (byte) Math.max(0, Math.min(aTier, 9)); + this.mDescription = aDescription; - public GregtechMetaTileEntity(final String aName, final int aTier, final int aInvSlotCount, - final String aDescription, final ITexture[][][] aTextures) { - super(aName, aInvSlotCount); - this.mTier = (byte) aTier; - this.mDescription = aDescription; - this.mTextures = aTextures; + // must always be the last call! + if (GT.isClientSide()) { + this.mTextures = this.getTextureSet(aTextures); + } else { + this.mTextures = null; + } + } - } + public GregtechMetaTileEntity( + final String aName, + final int aTier, + final int aInvSlotCount, + final String aDescription, + final ITexture[][][] aTextures) { + super(aName, aInvSlotCount); + this.mTier = (byte) aTier; + this.mDescription = aDescription; + this.mTextures = aTextures; + } - @Override - public byte getTileEntityBaseType() { - return (byte) (Math.min(3, this.mTier <= 0 ? 0 : 1 + ((this.mTier - 1) / 4))); - } + @Override + public byte getTileEntityBaseType() { + return (byte) (Math.min(3, this.mTier <= 0 ? 0 : 1 + ((this.mTier - 1) / 4))); + } - @Override - public long getInputTier() { - return this.mTier; - } + @Override + public long getInputTier() { + return this.mTier; + } - @Override - public long getOutputTier() { - return this.mTier; - } + @Override + public long getOutputTier() { + return this.mTier; + } - @Override - public String[] getDescription() { - return new String[] { this.mDescription }; - } + @Override + public String[] getDescription() { + return new String[] {this.mDescription}; + } - /** - * Used Client Side to get a Texture Set for this Block. Called after - * setting the Tier and the Description so that those two are accessible. - * - * @param aTextures - * is the optional Array you can give to the Constructor. - */ - public abstract ITexture[][][] getTextureSet(ITexture[] aTextures); -}
\ No newline at end of file + /** + * Used Client Side to get a Texture Set for this Block. Called after + * setting the Tier and the Description so that those two are accessible. + * + * @param aTextures + * is the optional Array you can give to the Constructor. + */ + public abstract ITexture[][][] getTextureSet(ITexture[] aTextures); +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTransformerHiAmp.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTransformerHiAmp.java index d0021f8358..e900aac944 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTransformerHiAmp.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTransformerHiAmp.java @@ -1,116 +1,131 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; - 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_Transformer; - import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.PlayerUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; public class GregtechMetaTransformerHiAmp extends GT_MetaTileEntity_Transformer { - private boolean mHalfMode = false; - - public GregtechMetaTransformerHiAmp(int aID, String aName, String aNameRegional, int aTier, String aDescription) { - super(aID, aName, aNameRegional, aTier, aDescription); - } - - public GregtechMetaTransformerHiAmp(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public long maxEUStore() { - return ((512L + gregtech.api.enums.GT_Values.V[(this.mTier + 1)] * 2L) * 8); - } - - @Override - public long maxAmperesOut() { - if (this.mHalfMode) { - return ((getBaseMetaTileEntity().isAllowedToWork()) ? 8L : 2L); - } - return ((getBaseMetaTileEntity().isAllowedToWork()) ? 16L : 4L); - } - - @Override - public long maxAmperesIn() { - if (this.mHalfMode) { - return ((getBaseMetaTileEntity().isAllowedToWork()) ? 2L : 8L); - } - return ((getBaseMetaTileEntity().isAllowedToWork()) ? 4L : 16L); - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[12][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; - rTextures[1][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; - rTextures[2][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; - rTextures[3][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] }; - rTextures[4][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] }; - rTextures[5][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] }; - rTextures[6][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] }; - rTextures[7][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] }; - rTextures[8][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] }; - rTextures[9][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] }; - rTextures[10][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] }; - rTextures[11][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], - Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] }; - } - return rTextures; - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTransformerHiAmp(this.mName, this.mTier, this.mDescription, this.mTextures); - } - - @Override - public String[] getDescription() { - return new String[] { this.mDescription, - "Accepts 4A and outputs 16A", - "Toggle 2A/8A half-mode with Screwdriver", - CORE.GT_Tooltip}; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("mHalfMode", this.mHalfMode); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - this.mHalfMode = aNBT.getBoolean("mHalfMode"); - super.loadNBTData(aNBT); - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - this.mHalfMode = Utils.invertBoolean(mHalfMode); - if (this.mHalfMode) { - PlayerUtils.messagePlayer(aPlayer, "Transformer is now running at 2A:8A in/out Ratio."); - } else { - - PlayerUtils.messagePlayer(aPlayer, "Transformer is now running at 4A:16A in/out Ratio."); - } - } -}
\ No newline at end of file + private boolean mHalfMode = false; + + public GregtechMetaTransformerHiAmp(int aID, String aName, String aNameRegional, int aTier, String aDescription) { + super(aID, aName, aNameRegional, aTier, aDescription); + } + + public GregtechMetaTransformerHiAmp(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public long maxEUStore() { + return ((512L + gregtech.api.enums.GT_Values.V[(this.mTier + 1)] * 2L) * 8); + } + + @Override + public long maxAmperesOut() { + if (this.mHalfMode) { + return ((getBaseMetaTileEntity().isAllowedToWork()) ? 8L : 2L); + } + return ((getBaseMetaTileEntity().isAllowedToWork()) ? 16L : 4L); + } + + @Override + public long maxAmperesIn() { + if (this.mHalfMode) { + return ((getBaseMetaTileEntity().isAllowedToWork()) ? 2L : 8L); + } + return ((getBaseMetaTileEntity().isAllowedToWork()) ? 4L : 16L); + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[12][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] + }; + rTextures[1][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] + }; + rTextures[2][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] + }; + rTextures[3][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] + }; + rTextures[4][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] + }; + rTextures[5][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] + }; + rTextures[6][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] + }; + rTextures[7][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] + }; + rTextures[8][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] + }; + rTextures[9][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] + }; + rTextures[10][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] + }; + rTextures[11][i + 1] = new ITexture[] { + Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] + }; + } + return rTextures; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTransformerHiAmp(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public String[] getDescription() { + return new String[] { + this.mDescription, "Accepts 4A and outputs 16A", "Toggle 2A/8A half-mode with Screwdriver", CORE.GT_Tooltip + }; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mHalfMode", this.mHalfMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mHalfMode = aNBT.getBoolean("mHalfMode"); + super.loadNBTData(aNBT); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + this.mHalfMode = Utils.invertBoolean(mHalfMode); + if (this.mHalfMode) { + PlayerUtils.messagePlayer(aPlayer, "Transformer is now running at 2A:8A in/out Ratio."); + } else { + + PlayerUtils.messagePlayer(aPlayer, "Transformer is now running at 4A:16A in/out Ratio."); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index f6d4d3946c..4bd18819c6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -1,5 +1,7 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.structure.IItemSource; import com.gtnewhorizon.structurelib.structure.IStructureElement; @@ -44,6 +46,15 @@ import gtPlusPlus.preloader.CORE_Preloader; import gtPlusPlus.preloader.asm.AsmConfig; import gtPlusPlus.xmod.gregtech.api.gui.*; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; +import java.util.function.BiPredicate; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -61,1562 +72,1590 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; import org.apache.commons.lang3.ArrayUtils; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.function.BiConsumer; -import java.util.function.BiPredicate; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.stream.Collectors; +// Glee8e - 11/12/21 - 2:15pm +// Yeah, now I see what's wrong. Someone inherited from GregtechMeta_MultiBlockBase instead of +// GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialDehydrator> as it should have been +// so any method in GregtechMetaTileEntity_IndustrialDehydrator would see generic field declared in +// GregtechMeta_MultiBlockBase without generic parameter + +public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_EnhancedMultiBlockBase<T>> + extends GT_MetaTileEntity_EnhancedMultiBlockBase<T> { + + public static final boolean DEBUG_DISABLE_CORES_TEMPORARILY = true; + + static { + Method a08 = findRecipe08 = ReflectionUtils.getMethod( + GT_Recipe_Map.class, + "findRecipe", + IHasWorldObjectAndCoords.class, + GT_Recipe.class, + boolean.class, + long.class, + FluidStack[].class, + ItemStack.class, + ItemStack[].class); + Method a09 = findRecipe09 = ReflectionUtils.getMethod( + GT_Recipe_Map.class, + "findRecipe", + IHasWorldObjectAndCoords.class, + GT_Recipe.class, + boolean.class, + boolean.class, + long.class, + FluidStack[].class, + ItemStack.class, + ItemStack[].class); + Logger.MACHINE_INFO("Found .08 findRecipe method? " + (a08 != null)); + Logger.MACHINE_INFO("Found .09 findRecipe method? " + (a09 != null)); + + try { + calculatePollutionReduction = + GT_MetaTileEntity_Hatch_Muffler.class.getDeclaredMethod("calculatePollutionReduction", int.class); + } catch (NoSuchMethodException | SecurityException e) { + } + } + // Find Recipe Methods + private static final Method findRecipe08; + private static final Method findRecipe09; + + public GT_Recipe mLastRecipe; + private boolean mInternalCircuit = false; + protected long mTotalRunTime = 0; + protected boolean mVoidExcess = false; + + public ArrayList<GT_MetaTileEntity_Hatch_ControlCore> mControlCoreBus = + new ArrayList<GT_MetaTileEntity_Hatch_ControlCore>(); + /** + * Don't use this for recipe input check, otherwise you'll get duplicated fluids + */ + public ArrayList<GT_MetaTileEntity_Hatch_AirIntake> mAirIntakes = + new ArrayList<GT_MetaTileEntity_Hatch_AirIntake>(); + + public ArrayList<GT_MetaTileEntity_Hatch_InputBattery> mChargeHatches = + new ArrayList<GT_MetaTileEntity_Hatch_InputBattery>(); + public ArrayList<GT_MetaTileEntity_Hatch_OutputBattery> mDischargeHatches = + new ArrayList<GT_MetaTileEntity_Hatch_OutputBattery>(); + public ArrayList<GT_MetaTileEntity_Hatch> mAllEnergyHatches = new ArrayList<GT_MetaTileEntity_Hatch>(); + public ArrayList<GT_MetaTileEntity_Hatch> mAllDynamoHatches = new ArrayList<GT_MetaTileEntity_Hatch>(); + + // Custom Behaviour Map + private static final HashMap<String, SpecialMultiBehaviour> mCustomBehviours = + new HashMap<String, SpecialMultiBehaviour>(); + + public GregtechMeta_MultiBlockBase(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + public GregtechMeta_MultiBlockBase(final String aName) { + super(aName); + } -// Glee8e - 11/12/21 - 2:15pm -// Yeah, now I see what's wrong. Someone inherited from GregtechMeta_MultiBlockBase instead of GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialDehydrator> as it should have been -// so any method in GregtechMetaTileEntity_IndustrialDehydrator would see generic field declared in GregtechMeta_MultiBlockBase without generic parameter - -public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_EnhancedMultiBlockBase<T>> extends GT_MetaTileEntity_EnhancedMultiBlockBase<T> { - - public static final boolean DEBUG_DISABLE_CORES_TEMPORARILY = true; - - static { - - Method a08 = findRecipe08 = ReflectionUtils.getMethod(GT_Recipe_Map.class, "findRecipe", IHasWorldObjectAndCoords.class, GT_Recipe.class, boolean.class, long.class, FluidStack[].class, ItemStack.class, ItemStack[].class); - Method a09 = findRecipe09 = ReflectionUtils.getMethod(GT_Recipe_Map.class, "findRecipe", IHasWorldObjectAndCoords.class, GT_Recipe.class, boolean.class, boolean.class, long.class, FluidStack[].class, ItemStack.class, ItemStack[].class); - Logger.MACHINE_INFO("Found .08 findRecipe method? "+(a08 != null)); - Logger.MACHINE_INFO("Found .09 findRecipe method? "+(a09 != null)); - - try { - calculatePollutionReduction = GT_MetaTileEntity_Hatch_Muffler.class.getDeclaredMethod("calculatePollutionReduction", int.class); - } - catch (NoSuchMethodException | SecurityException e) {} - - } - - //Find Recipe Methods - private static final Method findRecipe08; - private static final Method findRecipe09; - - public GT_Recipe mLastRecipe; - private boolean mInternalCircuit = false; - protected long mTotalRunTime = 0; - protected boolean mVoidExcess = false; - - public ArrayList<GT_MetaTileEntity_Hatch_ControlCore> mControlCoreBus = new ArrayList<GT_MetaTileEntity_Hatch_ControlCore>(); - /** - * Don't use this for recipe input check, otherwise you'll get duplicated fluids - */ - public ArrayList<GT_MetaTileEntity_Hatch_AirIntake> mAirIntakes = new ArrayList<GT_MetaTileEntity_Hatch_AirIntake>(); - public ArrayList<GT_MetaTileEntity_Hatch_InputBattery> mChargeHatches = new ArrayList<GT_MetaTileEntity_Hatch_InputBattery>(); - public ArrayList<GT_MetaTileEntity_Hatch_OutputBattery> mDischargeHatches = new ArrayList<GT_MetaTileEntity_Hatch_OutputBattery>(); - public ArrayList<GT_MetaTileEntity_Hatch> mAllEnergyHatches = new ArrayList<GT_MetaTileEntity_Hatch>(); - public ArrayList<GT_MetaTileEntity_Hatch> mAllDynamoHatches = new ArrayList<GT_MetaTileEntity_Hatch>(); - - // Custom Behaviour Map - private static final HashMap<String, SpecialMultiBehaviour> mCustomBehviours = new HashMap<String, SpecialMultiBehaviour>(); - - - public GregtechMeta_MultiBlockBase(final int aID, final String aName, - final String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMeta_MultiBlockBase(final String aName) { - super(aName); - } - - public static boolean isValidMetaTileEntity( - final MetaTileEntity aMetaTileEntity) { - return (aMetaTileEntity.getBaseMetaTileEntity() != null) - && (aMetaTileEntity.getBaseMetaTileEntity() - .getMetaTileEntity() == aMetaTileEntity) - && !aMetaTileEntity.getBaseMetaTileEntity().isDead(); - } - - public abstract boolean hasSlotInGUI(); - - public long getTotalRuntimeInTicks() { - return this.mTotalRunTime; - } - - @Override - public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - if (hasSlotInGUI()) { - return new GT_Container_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); - } - else { - String aCustomGUI = getCustomGUIResourceName(); - if (aCustomGUI == null) { - return new CONTAINER_MultiMachine_NoPlayerInventory(aPlayerInventory, aBaseMetaTileEntity); - } - else { - return new CONTAINER_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); - } - } - } - - public abstract String getCustomGUIResourceName(); - - public boolean requiresVanillaGtGUI() { - return false; - } - - @Override - public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { - String aCustomGUI = getCustomGUIResourceName(); - aCustomGUI = aCustomGUI != null ? aCustomGUI : hasSlotInGUI() ? "MultiblockDisplay" : "MultiblockDisplay_Generic"; - aCustomGUI = aCustomGUI + ".png"; - if (hasSlotInGUI()) { - if (!requiresVanillaGtGUI()) { - return new GUI_Multi_Basic_Slotted(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); - } - else { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); - } - } - else { - if (getCustomGUIResourceName() == null && !hasSlotInGUI()) { - return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); - } - else { - return new GUI_MultiMachine_Default(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); - } - } - } - - public abstract String getMachineType(); - - public String getMachineTooltip() { - return "Machine Type: " + EnumChatFormatting.YELLOW + getMachineType() + EnumChatFormatting.RESET; - } - - public String[] getExtraInfoData() { - return new String[0]; - }; - - @Override - public final String[] getInfoData() { - ArrayList<String> mInfo = new ArrayList<String>(); - try { - if (!this.getMetaName().equals("")) { - mInfo.add(this.getMetaName()); - } - - String[] extra = getExtraInfoData(); - - if (extra == null) { - extra = new String[0]; - } - if (extra.length > 0) { - for (String s : extra) { - mInfo.add(s); - } - } - - long seconds = (this.mTotalRunTime/20); - int weeks = (int) (TimeUnit.SECONDS.toDays(seconds) / 7); - int days = (int) (TimeUnit.SECONDS.toDays(seconds) - 7 * weeks); - long hours = TimeUnit.SECONDS.toHours(seconds) - TimeUnit.DAYS.toHours(days) - TimeUnit.DAYS.toHours(7*weeks); - long minutes = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds) * 60); - long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) *60); - - mInfo.add(getMachineTooltip()); - - //Lets borrow the GTNH handling - - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.progress")+": "+ - EnumChatFormatting.GREEN + Integer.toString(mProgresstime/20) + EnumChatFormatting.RESET +" s / "+ - EnumChatFormatting.YELLOW + Integer.toString(mMaxProgresstime/20) + EnumChatFormatting.RESET +" s"); - - - if (!this.mAllEnergyHatches.isEmpty()) { - long storedEnergy = getStoredEnergyInAllEnergyHatches(); - long maxEnergy = getMaxEnergyStorageOfAllEnergyHatches(); - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.energy")+":"); - mInfo.add(StatCollector.translateToLocal(""+EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET +" EU / "+ - EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET +" EU")); - - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.mei")+":"); - mInfo.add(StatCollector.translateToLocal(""+EnumChatFormatting.YELLOW+Long.toString(getMaxInputVoltage())+EnumChatFormatting.RESET+ " EU/t(*2A) "+StatCollector.translateToLocal("GTPP.machines.tier")+": "+ - EnumChatFormatting.YELLOW+GT_Values.VN[GT_Utility.getTier(getMaxInputVoltage())]+ EnumChatFormatting.RESET)); - ; - } - if (!this.mAllDynamoHatches.isEmpty()) { - long storedEnergy = getStoredEnergyInAllDynamoHatches(); - long maxEnergy = getMaxEnergyStorageOfAllDynamoHatches(); - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.energy")+" In Dynamos:"); - mInfo.add(StatCollector.translateToLocal(""+EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET +" EU / "+ - EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET +" EU")); - } - - if (-mEUt > 0) { - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.usage")+":"); - mInfo.add(StatCollector.translateToLocal(""+EnumChatFormatting.RED + Integer.toString(-mEUt) + EnumChatFormatting.RESET + " EU/t")); - } - else { - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.generation")+":"); - mInfo.add(StatCollector.translateToLocal(""+EnumChatFormatting.GREEN + Integer.toString(mEUt) + EnumChatFormatting.RESET + " EU/t")); - } - - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.problems")+": "+ - EnumChatFormatting.RED+ (getIdealStatus() - getRepairStatus())+EnumChatFormatting.RESET+ - " "+StatCollector.translateToLocal("GTPP.multiblock.efficiency")+": "+ - EnumChatFormatting.YELLOW+Float.toString(mEfficiency / 100.0F)+EnumChatFormatting.RESET + " %"); - - if (this.getPollutionPerSecond(null) > 0) { - int mPollutionReduction = getPollutionReductionForAllMufflers(); - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.pollution")+": "+ EnumChatFormatting.RED + this.getPollutionPerSecond(null)+ EnumChatFormatting.RESET+"/sec"); - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.pollutionreduced")+": "+ EnumChatFormatting.GREEN + mPollutionReduction+ EnumChatFormatting.RESET+" %"); - } - - if (this.mControlCoreBus.size() > 0) { - int tTier = this.getControlCoreTier(); - mInfo.add(StatCollector.translateToLocal("GTPP.CC.machinetier")+": "+ - EnumChatFormatting.GREEN+tTier+EnumChatFormatting.RESET); - } - - mInfo.add(StatCollector.translateToLocal("GTPP.CC.discount")+": "+ - EnumChatFormatting.GREEN+(getEuDiscountForParallelism())+EnumChatFormatting.RESET + "%"); - - mInfo.add(StatCollector.translateToLocal("GTPP.CC.parallel")+": "+EnumChatFormatting.GREEN+(getMaxParallelRecipes())+EnumChatFormatting.RESET); - - - mInfo.add("Total Time Since Built: " + EnumChatFormatting.DARK_GREEN + Integer.toString(weeks)+EnumChatFormatting.RESET+" Weeks, " + EnumChatFormatting.DARK_GREEN+ Integer.toString(days) +EnumChatFormatting.RESET+ " Days, "); - mInfo.add(EnumChatFormatting.DARK_GREEN + Long.toString(hours) +EnumChatFormatting.RESET + " Hours, " + EnumChatFormatting.DARK_GREEN+ Long.toString(minutes) +EnumChatFormatting.RESET+ " Minutes, " + EnumChatFormatting.DARK_GREEN+ Long.toString(second) +EnumChatFormatting.RESET+ " Seconds."); - mInfo.add("Total Time in ticks: " + EnumChatFormatting.DARK_GREEN + Long.toString(this.mTotalRunTime)); - - - String[] mInfo2 = mInfo.toArray(new String[mInfo.size()]); - return mInfo2; - } - catch (Throwable t) { - t.printStackTrace(); - } - return new String[] {}; - - - } - - public int getPollutionReductionForAllMufflers() { - int mPollutionReduction=0; - for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - mPollutionReduction=Math.max(calculatePollutionReductionForHatch(tHatch, 100),mPollutionReduction); - } - } - return mPollutionReduction; - } - - public long getStoredEnergyInAllEnergyHatches() { - long storedEnergy=0; - for(GT_MetaTileEntity_Hatch tHatch : mAllEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU(); - } - } - return storedEnergy; - } - - public long getMaxEnergyStorageOfAllEnergyHatches() { - long maxEnergy=0; - for(GT_MetaTileEntity_Hatch tHatch : mAllEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity(); - } - } - return maxEnergy; - } - - public long getStoredEnergyInAllDynamoHatches() { - long storedEnergy=0; - for(GT_MetaTileEntity_Hatch tHatch : mAllDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU(); - } - } - return storedEnergy; - } - - public long getMaxEnergyStorageOfAllDynamoHatches() { - long maxEnergy=0; - for(GT_MetaTileEntity_Hatch tHatch : mAllDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity(); - } - } - return maxEnergy; - } - - @Override - public boolean isGivingInformation() { - return true; - } - - private String[] aCachedToolTip; - - /*private final String aRequiresMuffler = "1x Muffler Hatch"; - private final String aRequiresCoreModule = "1x Core Module"; - private final String aRequiresMaint = "1x Maintanence Hatch";*/ - - public final static String TAG_HIDE_HATCHES = "TAG_HIDE_HATCHES"; - public final static String TAG_HIDE_MAINT = "TAG_HIDE_MAINT"; - public final static String TAG_HIDE_POLLUTION = "TAG_HIDE_POLLUTION"; - public final static String TAG_HIDE_MACHINE_TYPE = "TAG_HIDE_MACHINE_TYPE"; - - public int getAmountOfOutputs() { - return 1; - } - - public abstract int getMaxParallelRecipes(); - public abstract int getEuDiscountForParallelism(); - - @Override - public boolean isCorrectMachinePart(final ItemStack paramItemStack) { - return true; - } - - @Override - public int getDamageToComponent(final ItemStack paramItemStack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack p0) { - return false; - } - - @Override - public void startSoundLoop(final byte aIndex, final double aX, final double aY, final double aZ) { - super.startSoundLoop(aIndex, aX, aY, aZ); - if (aIndex == 1) { - GT_Utility.doSoundAtClient(getSound(), 10, 1.0F, aX, aY, aZ); - } - } - - public void startProcess() { - if(GT_Utility.isStringValid(getSound())) this.sendLoopStart((byte) 1); - } - - public String getSound() { return ""; } - - - public int canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) { - return canBufferOutputs(aRecipe, aParallelRecipes, true); - } - - public int canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes, boolean aAllow16SlotWithoutCheck) { - // Null recipe or a recipe with lots of outputs? - // E.G. Gendustry custom comb with a billion centrifuge outputs? - // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true. - if (aRecipe == null || aRecipe.mOutputs.length > 16) { - if (aRecipe == null) { - return 0; - } - else if (aRecipe.mOutputs.length > 16) { - if (aAllow16SlotWithoutCheck) { - return aParallelRecipes; - } - else { - // Do nothing, we want to check this recipe properly. - } - } - } - return canBufferOutputs(aRecipe.mOutputs, aRecipe.mFluidOutputs, aParallelRecipes); - } - - public int canBufferOutputs(ItemStack[] aItemOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) { - if (mVoidExcess) return aParallelRecipes; - log("Determining if we have space to buffer outputs. Parallel: "+aParallelRecipes); - - // Do we even need to check for item outputs? - boolean aDoesOutputItems = aItemOutputs.length > 0; - // Do we even need to check for fluid outputs? - boolean aDoesOutputFluids = aFluidOutputs.length > 0; - - - - /* ======================================== - * Item Management - * ======================================== - */ - - if (aDoesOutputItems) { - log("We have items to output."); - - // How many slots are free across all the output buses? - int aInputBusSlotsFree = 0; - - /* - * Create Variables for Item Output - */ - - AutoMap<FlexiblePair<ItemStack, Integer>> aItemMap = new AutoMap<FlexiblePair<ItemStack, Integer>>(); - AutoMap<ItemStack> aOutputs = new AutoMap<ItemStack>(aItemOutputs); - - for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) { - if (!isValidMetaTileEntity(tBus)) { - continue; - } - final IInventory tBusInv = tBus.getBaseMetaTileEntity(); - for (int i = 0; i < tBusInv.getSizeInventory(); i++) { - if (tBus.getStackInSlot(i) == null) { - aInputBusSlotsFree++; - } - else { - ItemStack aT = tBus.getStackInSlot(i); - int aSize = aT.stackSize; - aT = aT.copy(); - aT.stackSize = 0; - aItemMap.put(new FlexiblePair<ItemStack, Integer>(aT, aSize)); - } - } - } - - // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the recipe outputs. - ConcurrentSet<FlexiblePair<ItemStack, Integer>> aInputMap = new ConcurrentHashSet<FlexiblePair<ItemStack, Integer>>(); - - // Iterate over the outputs, calculating require stack spacing they will require. - for (int i=0;i<aOutputs.size();i++) { - ItemStack aY = aOutputs.get(i); - if (aY == null) { - continue; - } - else { - int aStackSize = aY.stackSize * aParallelRecipes; - - int aSlotsNeedsForThisStack = (int) Math.ceil((float) aStackSize / aY.getMaxStackSize()); - // Should round up and add as many stacks as required nicely. - for (int o=0;o<aSlotsNeedsForThisStack;o++) { - if (aStackSize < 1) break; - int aStackToRemove = Math.min(aStackSize, aY.getMaxStackSize()); - aStackSize -= aStackToRemove; - aY = aY.copy(); - aY.stackSize = 0; - aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackToRemove)); - } - } - } - - // We have items to add to the output buses. See if any are not full stacks and see if we can make them full. - if (aInputMap.size() > 0) { - // Iterate over the current stored items in the Output busses, if any match and are not full, we can try account for merging. - busItems: for (FlexiblePair<ItemStack, Integer> y : aItemMap) { - // Iterate over the 'inputs', we can safely remove these as we go. - outputItems: for (FlexiblePair<ItemStack, Integer> u : aInputMap) { - // Create local vars for readability. - ItemStack aOutputBusStack = y.getKey(); - ItemStack aOutputStack = u.getKey(); - // Stacks match, including NBT. - if (GT_Utility.areStacksEqual(aOutputBusStack, aOutputStack, false)) { - // Stack Matches, but it's full, continue. - if (aOutputBusStack.stackSize >= 64) { - // This stack is full, no point checking it. - continue busItems; - } - else { - // We can merge these two stacks without any hassle. - if ((aOutputBusStack.stackSize + aOutputStack.stackSize) <= 64) { - // Update the stack size in the bus storage map. - y.setValue(aOutputBusStack.stackSize + aOutputStack.stackSize); - // Remove the 'input' stack from the recipe outputs, so we don't try count it again. - aInputMap.remove(u); - continue outputItems; - } - // Stack merging is too much, so we fill this stack, leave the remainder. - else { - int aRemainder = (aOutputBusStack.stackSize + aOutputStack.stackSize) - 64; - // Update the stack size in the bus storage map. - y.setValue(64); - // Create a new object to iterate over later, with the remainder data; - FlexiblePair<ItemStack, Integer> t = new FlexiblePair<ItemStack, Integer>(u.getKey(), aRemainder); - // Remove the 'input' stack from the recipe outputs, so we don't try count it again. - aInputMap.remove(u); - // Add the remainder stack. - aInputMap.add(t); - continue outputItems; - } - } - } - else { - continue outputItems; - } - } - } - } - - // We have stacks that did not merge, do we have space for them? - if (aInputMap.size() > 0) { - if (aInputMap.size() > aInputBusSlotsFree) { - aParallelRecipes = (int) Math.floor((double) aInputBusSlotsFree/aInputMap.size() * aParallelRecipes); - // We do not have enough free slots in total to accommodate the remaining managed stacks. - log(" Free: "+aInputBusSlotsFree+", Required: "+aInputMap.size()); - if(aParallelRecipes == 0) { - log("Failed to find enough space for all item outputs."); - return 0; - } - - } - } - - /* - * End Item Management - */ - - } - - - - - - /* ======================================== - * Fluid Management - * ======================================== - */ - - - - if (aDoesOutputFluids) { - log("We have Fluids to output."); - // How many slots are free across all the output buses? - int aFluidHatches = 0; - int aEmptyFluidHatches = 0; - int aFullFluidHatches = 0; - // Create Map for Fluid Output - ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>> aOutputHatches = new ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>>(); - for (final GT_MetaTileEntity_Hatch_Output tBus : this.mOutputHatches) { - if (!isValidMetaTileEntity(tBus)) { - continue; - } - aFluidHatches++; - // Map the Hatch with the space left for easy checking later. - if (tBus.getFluid() == null) { - aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(tBus, null, tBus.getCapacity())); - } - else { - int aSpaceLeft = tBus.getCapacity() - tBus.getFluidAmount(); - aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(tBus, tBus.getFluid(), aSpaceLeft)); - } - } - // Create a map of all the fluids we would like to output, we can iterate over this and see how many we can merge into existing hatch stacks. - ArrayList<FluidStack> aOutputFluids = new ArrayList<FluidStack>(); - // Ugly ass boxing - aOutputFluids.addAll(new AutoMap<FluidStack>(aFluidOutputs)); - // Iterate the Hatches, updating their 'stored' data. - //for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aHatchData : aOutputHatches) { - for (int i = 0;i<aOutputHatches.size();i++) { - // The Hatch Itself - GT_MetaTileEntity_Hatch_Output aHatch = aOutputHatches.get(i).getValue_1(); - // Fluid in the Hatch - FluidStack aHatchStack = aOutputHatches.get(i).getValue_2(); - // Fluid that the hatch is locked to - String aHatchLockedFluid = aOutputHatches.get(i).getValue_1().getLockedFluidName(); - // Space left in Hatch - int aSpaceLeftInHatch = aHatch.getCapacity() - aHatch.getFluidAmount(); - // Hatch is full, - if (aSpaceLeftInHatch <= 0) { - aFullFluidHatches++; - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - continue; - } - // Hatch has space - else { - // Check if any fluids match - //aFluidMatch: for (FluidStack aOutputStack : aOutputFluids) { - for(int j = 0;j<aOutputFluids.size();j++) { - //log(" aHatchStack "+aHatchStack.getLocalizedName()+" aOutput stack "+aOutputStack.getLocalizedName()); - if (GT_Utility.areFluidsEqual(aHatchStack, aOutputFluids.get(j)) && (aHatchLockedFluid == null || aHatchLockedFluid.equals(aOutputFluids.get(j).getFluid().getName()))) { - int aFluidToPutIntoHatch = aOutputFluids.get(j).amount * aParallelRecipes; - // Not Enough space to insert all of the fluid. - // We fill this hatch and add a smaller Fluidstack back to the iterator. - if (aSpaceLeftInHatch < aFluidToPutIntoHatch) { - // Copy existing Hatch Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - aNewHatchStack.amount = 0; - // Copy existing Hatch Stack again - FluidStack aNewOutputStack = aHatchStack.copy(); - aNewOutputStack.amount = 0; - // How much fluid do we have left after we fill the hatch? - int aFluidLeftAfterInsert = aFluidToPutIntoHatch - aSpaceLeftInHatch; - // Set new stacks to appropriate values - aNewHatchStack.amount = aHatch.getCapacity(); - aNewOutputStack.amount = aFluidLeftAfterInsert; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Add remaining Fluid to Output list - aOutputFluids.add(aNewOutputStack); - // Re-add hatch to hatch list, with new data. - //Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); - //aOutputHatches.add(aNewHatchData); - break; - } - // We can fill this hatch perfectly (rare case), may as well add it directly to the full list. - else if (aSpaceLeftInHatch == aFluidToPutIntoHatch) { - // Copy Old Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - // Add in amount from output stack - aNewHatchStack.amount += aFluidToPutIntoHatch; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Re-add hatch to hatch list, with new data. - Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); - aOutputHatches.add(aNewHatchData); - break; - } - // We have more space than we need to merge, so we remove the stack from the output list and update the hatch list. - else { - // Copy Old Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - // Add in amount from output stack - aNewHatchStack.amount += aFluidToPutIntoHatch; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Re-add hatch to hatch list, with new data. - Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); - aOutputHatches.add(aNewHatchData); - // Check next fluid - continue; - } - - } - else if (aHatchLockedFluid == null || aHatchLockedFluid.equals(aOutputFluids.get(j).getFluid().getName())) { - aEmptyFluidHatches++; - } - else { - continue; - } - } - } - } - - for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aFreeHatchCheck : aOutputHatches) { - // Free Hatch - if ((aFreeHatchCheck.getValue_2() == null || aFreeHatchCheck.getValue_3() == 0 || aFreeHatchCheck.getValue_1().getFluid() == null) && !aFreeHatchCheck.getValue_1().isFluidLocked()) { - aEmptyFluidHatches++; - } - } - - // We have Fluid Stacks we did not merge. Do we have space? - log("fluids to output "+aOutputFluids.size()+" empty hatches "+aEmptyFluidHatches); - if (aOutputFluids.size() > 0) { - // Not enough space to add fluids. - if (aOutputFluids.size() > aEmptyFluidHatches) { - aParallelRecipes = (int) Math.floor((double) aEmptyFluidHatches/aOutputFluids.size() * aParallelRecipes); - log("Failed to find enough space for all fluid outputs. Free: "+aEmptyFluidHatches+", Required: "+aOutputFluids.size()); - return 0; - - } - } - - /* - * End Fluid Management - */ - } - - return aParallelRecipes; - } - - /** - * A Static {@link Method} object which holds the current status of logging. - */ - public static Method aLogger = null; - - public void log(String s) { - if (!AsmConfig.disableAllLogging) { - if (CORE_Preloader.DEBUG_MODE) { - Logger.INFO(s); - } else { - Logger.MACHINE_INFO(s); - } - } - } - - public boolean checkRecipeGeneric() { - return checkRecipeGeneric(1, 100, 0); - } - - public boolean checkRecipeGeneric(int aMaxParallelRecipes, long aEUPercent, int aSpeedBonusPercent) { - return checkRecipeGeneric(aMaxParallelRecipes, aEUPercent, aSpeedBonusPercent, 10000); - } - - 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); - } - - public boolean checkRecipeGeneric(GT_Recipe aRecipe, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll) { - if (aRecipe == null) { - return false; - } - 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, aRecipe); - } - - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll) { - return checkRecipeGeneric(aItemInputs, aFluidInputs, aMaxParallelRecipes, aEUPercent, aSpeedBonusPercent, aOutputChanceRoll, null); - } - - - /* - * public boolean checkRecipeGeneric( ItemStack[] aItemInputs, FluidStack[] - * aFluidInputs, int aMaxParallelRecipes, int aEUPercent, int - * aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { // Based on - * the Processing Array. A bit overkill, but very flexible. - * - * - * if (this.doesMachineBoostOutput()) { log("Boosting."); return - * checkRecipeBoostedOutputs(aItemInputs, aFluidInputs, aMaxParallelRecipes, - * aEUPercent, aSpeedBonusPercent, aOutputChanceRoll, aRecipe); } - * - * - * //Control Core to control the Multiblocks behaviour. int aControlCoreTier = - * getControlCoreTier(); - * - * //If no core, return false; if (aControlCoreTier > 0) { - * log("Control core found."); } - * - * - * // 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)); log("Running checkRecipeGeneric(0)"); - * - * //Check to see if Voltage Tier > Control Core Tier if (tTier > - * aControlCoreTier) { - * log("Control core found is lower tier than power tier. OK"); tTier = (byte) - * aControlCoreTier; } - * - * tTier = (byte) MathUtils.getValueWithinRange(tTier, 0, 9); - * - * GT_Recipe tRecipe = aRecipe != null ? aRecipe : 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; } - * - * if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) { - * 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); log("EU1: "+tRecipeEUt); // Count - * recipes to do in parallel, consuming input items and fluids and considering - * input voltage limits for (; parallelRecipes < aMaxParallelRecipes && - * tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) { if - * (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - * log("Broke at "+parallelRecipes+"."); break; } - * log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); tTotalEUt - * += tRecipeEUt; log("EU2: "+tTotalEUt); } - * - * if (parallelRecipes == 0) { log("BAD RETURN - 3"); return false; } - * - * log("EU3: "+tTotalEUt); - * - * // -- 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 * 10000); - * - * int aTempEu = (int) Math.floor(tTotalEUt); log("EU4: "+aTempEu); - * this.mEUt = (int) aTempEu; - * - * - * 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(); - * - * log("GOOD RETURN - 1"); return true; } - */ - - public long getMaxInputEnergy() { - long rEnergy = 0; - if (mEnergyHatches.size() == 1) // so it only takes 1 amp is only 1 hatch is present so it works like most gt multies - return mEnergyHatches.get(0).getBaseMetaTileEntity().getInputVoltage(); + public static boolean isValidMetaTileEntity(final MetaTileEntity aMetaTileEntity) { + return (aMetaTileEntity.getBaseMetaTileEntity() != null) + && (aMetaTileEntity.getBaseMetaTileEntity().getMetaTileEntity() == aMetaTileEntity) + && !aMetaTileEntity.getBaseMetaTileEntity().isDead(); + } + + public abstract boolean hasSlotInGUI(); + + public long getTotalRuntimeInTicks() { + return this.mTotalRunTime; + } + + @Override + public Object getServerGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + if (hasSlotInGUI()) { + return new GT_Container_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); + } else { + String aCustomGUI = getCustomGUIResourceName(); + if (aCustomGUI == null) { + return new CONTAINER_MultiMachine_NoPlayerInventory(aPlayerInventory, aBaseMetaTileEntity); + } else { + return new CONTAINER_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); + } + } + } + + public abstract String getCustomGUIResourceName(); + + public boolean requiresVanillaGtGUI() { + return false; + } + + @Override + public Object getClientGUI( + final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + String aCustomGUI = getCustomGUIResourceName(); + aCustomGUI = + aCustomGUI != null ? aCustomGUI : hasSlotInGUI() ? "MultiblockDisplay" : "MultiblockDisplay_Generic"; + aCustomGUI = aCustomGUI + ".png"; + if (hasSlotInGUI()) { + if (!requiresVanillaGtGUI()) { + return new GUI_Multi_Basic_Slotted( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); + } else { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); + } + } else { + if (getCustomGUIResourceName() == null && !hasSlotInGUI()) { + return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); + } else { + return new GUI_MultiMachine_Default( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); + } + } + } + + public abstract String getMachineType(); + + public String getMachineTooltip() { + return "Machine Type: " + EnumChatFormatting.YELLOW + getMachineType() + EnumChatFormatting.RESET; + } + + public String[] getExtraInfoData() { + return new String[0]; + } + ; + + @Override + public final String[] getInfoData() { + ArrayList<String> mInfo = new ArrayList<String>(); + try { + if (!this.getMetaName().equals("")) { + mInfo.add(this.getMetaName()); + } + + String[] extra = getExtraInfoData(); + + if (extra == null) { + extra = new String[0]; + } + if (extra.length > 0) { + for (String s : extra) { + mInfo.add(s); + } + } + + long seconds = (this.mTotalRunTime / 20); + int weeks = (int) (TimeUnit.SECONDS.toDays(seconds) / 7); + int days = (int) (TimeUnit.SECONDS.toDays(seconds) - 7 * weeks); + long hours = + TimeUnit.SECONDS.toHours(seconds) - TimeUnit.DAYS.toHours(days) - TimeUnit.DAYS.toHours(7 * weeks); + long minutes = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds) * 60); + long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) * 60); + + mInfo.add(getMachineTooltip()); + + // Lets borrow the GTNH handling + + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.progress") + ": " + EnumChatFormatting.GREEN + + Integer.toString(mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + + EnumChatFormatting.YELLOW + + Integer.toString(mMaxProgresstime / 20) + EnumChatFormatting.RESET + " s"); + + if (!this.mAllEnergyHatches.isEmpty()) { + long storedEnergy = getStoredEnergyInAllEnergyHatches(); + long maxEnergy = getMaxEnergyStorageOfAllEnergyHatches(); + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.energy") + ":"); + mInfo.add(StatCollector.translateToLocal("" + EnumChatFormatting.GREEN + Long.toString(storedEnergy) + + EnumChatFormatting.RESET + " EU / " + EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + + EnumChatFormatting.RESET + " EU")); + + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.mei") + ":"); + mInfo.add(StatCollector.translateToLocal("" + EnumChatFormatting.YELLOW + + Long.toString(getMaxInputVoltage()) + EnumChatFormatting.RESET + " EU/t(*2A) " + + StatCollector.translateToLocal("GTPP.machines.tier") + ": " + EnumChatFormatting.YELLOW + + GT_Values.VN[GT_Utility.getTier(getMaxInputVoltage())] + EnumChatFormatting.RESET)); + ; + } + if (!this.mAllDynamoHatches.isEmpty()) { + long storedEnergy = getStoredEnergyInAllDynamoHatches(); + long maxEnergy = getMaxEnergyStorageOfAllDynamoHatches(); + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.energy") + " In Dynamos:"); + mInfo.add(StatCollector.translateToLocal("" + EnumChatFormatting.GREEN + Long.toString(storedEnergy) + + EnumChatFormatting.RESET + " EU / " + EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + + EnumChatFormatting.RESET + " EU")); + } + + if (-mEUt > 0) { + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.usage") + ":"); + mInfo.add(StatCollector.translateToLocal( + "" + EnumChatFormatting.RED + Integer.toString(-mEUt) + EnumChatFormatting.RESET + " EU/t")); + } else { + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.generation") + ":"); + mInfo.add(StatCollector.translateToLocal( + "" + EnumChatFormatting.GREEN + Integer.toString(mEUt) + EnumChatFormatting.RESET + " EU/t")); + } + + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.problems") + ": " + EnumChatFormatting.RED + + (getIdealStatus() - getRepairStatus()) + EnumChatFormatting.RESET + " " + + StatCollector.translateToLocal("GTPP.multiblock.efficiency") + ": " + EnumChatFormatting.YELLOW + + Float.toString(mEfficiency / 100.0F) + EnumChatFormatting.RESET + " %"); + + if (this.getPollutionPerSecond(null) > 0) { + int mPollutionReduction = getPollutionReductionForAllMufflers(); + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.pollution") + ": " + EnumChatFormatting.RED + + this.getPollutionPerSecond(null) + EnumChatFormatting.RESET + "/sec"); + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.pollutionreduced") + ": " + + EnumChatFormatting.GREEN + mPollutionReduction + EnumChatFormatting.RESET + " %"); + } + + if (this.mControlCoreBus.size() > 0) { + int tTier = this.getControlCoreTier(); + mInfo.add(StatCollector.translateToLocal("GTPP.CC.machinetier") + ": " + EnumChatFormatting.GREEN + + tTier + EnumChatFormatting.RESET); + } + + mInfo.add(StatCollector.translateToLocal("GTPP.CC.discount") + ": " + EnumChatFormatting.GREEN + + (getEuDiscountForParallelism()) + EnumChatFormatting.RESET + "%"); + + mInfo.add(StatCollector.translateToLocal("GTPP.CC.parallel") + ": " + EnumChatFormatting.GREEN + + (getMaxParallelRecipes()) + EnumChatFormatting.RESET); + + mInfo.add("Total Time Since Built: " + EnumChatFormatting.DARK_GREEN + Integer.toString(weeks) + + EnumChatFormatting.RESET + " Weeks, " + EnumChatFormatting.DARK_GREEN + Integer.toString(days) + + EnumChatFormatting.RESET + " Days, "); + mInfo.add(EnumChatFormatting.DARK_GREEN + Long.toString(hours) + EnumChatFormatting.RESET + " Hours, " + + EnumChatFormatting.DARK_GREEN + Long.toString(minutes) + EnumChatFormatting.RESET + " Minutes, " + + EnumChatFormatting.DARK_GREEN + Long.toString(second) + EnumChatFormatting.RESET + " Seconds."); + mInfo.add("Total Time in ticks: " + EnumChatFormatting.DARK_GREEN + Long.toString(this.mTotalRunTime)); + + String[] mInfo2 = mInfo.toArray(new String[mInfo.size()]); + return mInfo2; + } catch (Throwable t) { + t.printStackTrace(); + } + return new String[] {}; + } + + public int getPollutionReductionForAllMufflers() { + int mPollutionReduction = 0; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { + if (isValidMetaTileEntity(tHatch)) { + mPollutionReduction = Math.max(calculatePollutionReductionForHatch(tHatch, 100), mPollutionReduction); + } + } + return mPollutionReduction; + } + + public long getStoredEnergyInAllEnergyHatches() { + long storedEnergy = 0; + for (GT_MetaTileEntity_Hatch tHatch : mAllEnergyHatches) { + if (isValidMetaTileEntity(tHatch)) { + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); + } + } + return storedEnergy; + } + + public long getMaxEnergyStorageOfAllEnergyHatches() { + long maxEnergy = 0; + for (GT_MetaTileEntity_Hatch tHatch : mAllEnergyHatches) { + if (isValidMetaTileEntity(tHatch)) { + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); + } + } + return maxEnergy; + } + + public long getStoredEnergyInAllDynamoHatches() { + long storedEnergy = 0; + for (GT_MetaTileEntity_Hatch tHatch : mAllDynamoHatches) { + if (isValidMetaTileEntity(tHatch)) { + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); + } + } + return storedEnergy; + } + + public long getMaxEnergyStorageOfAllDynamoHatches() { + long maxEnergy = 0; + for (GT_MetaTileEntity_Hatch tHatch : mAllDynamoHatches) { + if (isValidMetaTileEntity(tHatch)) { + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); + } + } + return maxEnergy; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + private String[] aCachedToolTip; + + /*private final String aRequiresMuffler = "1x Muffler Hatch"; + private final String aRequiresCoreModule = "1x Core Module"; + private final String aRequiresMaint = "1x Maintanence Hatch";*/ + + public static final String TAG_HIDE_HATCHES = "TAG_HIDE_HATCHES"; + public static final String TAG_HIDE_MAINT = "TAG_HIDE_MAINT"; + public static final String TAG_HIDE_POLLUTION = "TAG_HIDE_POLLUTION"; + public static final String TAG_HIDE_MACHINE_TYPE = "TAG_HIDE_MACHINE_TYPE"; + + public int getAmountOfOutputs() { + return 1; + } + + public abstract int getMaxParallelRecipes(); + + public abstract int getEuDiscountForParallelism(); + + @Override + public boolean isCorrectMachinePart(final ItemStack paramItemStack) { + return true; + } + + @Override + public int getDamageToComponent(final ItemStack paramItemStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack p0) { + return false; + } + + @Override + public void startSoundLoop(final byte aIndex, final double aX, final double aY, final double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 1) { + GT_Utility.doSoundAtClient(getSound(), 10, 1.0F, aX, aY, aZ); + } + } + + public void startProcess() { + if (GT_Utility.isStringValid(getSound())) this.sendLoopStart((byte) 1); + } + + public String getSound() { + return ""; + } + + public int canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) { + return canBufferOutputs(aRecipe, aParallelRecipes, true); + } + + public int canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes, boolean aAllow16SlotWithoutCheck) { + // Null recipe or a recipe with lots of outputs? + // E.G. Gendustry custom comb with a billion centrifuge outputs? + // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true. + if (aRecipe == null || aRecipe.mOutputs.length > 16) { + if (aRecipe == null) { + return 0; + } else if (aRecipe.mOutputs.length > 16) { + if (aAllow16SlotWithoutCheck) { + return aParallelRecipes; + } else { + // Do nothing, we want to check this recipe properly. + } + } + } + return canBufferOutputs(aRecipe.mOutputs, aRecipe.mFluidOutputs, aParallelRecipes); + } + + public int canBufferOutputs(ItemStack[] aItemOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) { + if (mVoidExcess) return aParallelRecipes; + log("Determining if we have space to buffer outputs. Parallel: " + aParallelRecipes); + + // Do we even need to check for item outputs? + boolean aDoesOutputItems = aItemOutputs.length > 0; + // Do we even need to check for fluid outputs? + boolean aDoesOutputFluids = aFluidOutputs.length > 0; + + /* ======================================== + * Item Management + * ======================================== + */ + + if (aDoesOutputItems) { + log("We have items to output."); + + // How many slots are free across all the output buses? + int aInputBusSlotsFree = 0; + + /* + * Create Variables for Item Output + */ + + AutoMap<FlexiblePair<ItemStack, Integer>> aItemMap = new AutoMap<FlexiblePair<ItemStack, Integer>>(); + AutoMap<ItemStack> aOutputs = new AutoMap<ItemStack>(aItemOutputs); + + for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) { + if (!isValidMetaTileEntity(tBus)) { + continue; + } + final IInventory tBusInv = tBus.getBaseMetaTileEntity(); + for (int i = 0; i < tBusInv.getSizeInventory(); i++) { + if (tBus.getStackInSlot(i) == null) { + aInputBusSlotsFree++; + } else { + ItemStack aT = tBus.getStackInSlot(i); + int aSize = aT.stackSize; + aT = aT.copy(); + aT.stackSize = 0; + aItemMap.put(new FlexiblePair<ItemStack, Integer>(aT, aSize)); + } + } + } + + // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the + // recipe outputs. + ConcurrentSet<FlexiblePair<ItemStack, Integer>> aInputMap = + new ConcurrentHashSet<FlexiblePair<ItemStack, Integer>>(); + + // Iterate over the outputs, calculating require stack spacing they will require. + for (int i = 0; i < aOutputs.size(); i++) { + ItemStack aY = aOutputs.get(i); + if (aY == null) { + continue; + } else { + int aStackSize = aY.stackSize * aParallelRecipes; + + int aSlotsNeedsForThisStack = (int) Math.ceil((float) aStackSize / aY.getMaxStackSize()); + // Should round up and add as many stacks as required nicely. + for (int o = 0; o < aSlotsNeedsForThisStack; o++) { + if (aStackSize < 1) break; + int aStackToRemove = Math.min(aStackSize, aY.getMaxStackSize()); + aStackSize -= aStackToRemove; + aY = aY.copy(); + aY.stackSize = 0; + aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackToRemove)); + } + } + } + + // We have items to add to the output buses. See if any are not full stacks and see if we can make them + // full. + if (aInputMap.size() > 0) { + // Iterate over the current stored items in the Output busses, if any match and are not full, we can try + // account for merging. + busItems: + for (FlexiblePair<ItemStack, Integer> y : aItemMap) { + // Iterate over the 'inputs', we can safely remove these as we go. + outputItems: + for (FlexiblePair<ItemStack, Integer> u : aInputMap) { + // Create local vars for readability. + ItemStack aOutputBusStack = y.getKey(); + ItemStack aOutputStack = u.getKey(); + // Stacks match, including NBT. + if (GT_Utility.areStacksEqual(aOutputBusStack, aOutputStack, false)) { + // Stack Matches, but it's full, continue. + if (aOutputBusStack.stackSize >= 64) { + // This stack is full, no point checking it. + continue busItems; + } else { + // We can merge these two stacks without any hassle. + if ((aOutputBusStack.stackSize + aOutputStack.stackSize) <= 64) { + // Update the stack size in the bus storage map. + y.setValue(aOutputBusStack.stackSize + aOutputStack.stackSize); + // Remove the 'input' stack from the recipe outputs, so we don't try count it again. + aInputMap.remove(u); + continue outputItems; + } + // Stack merging is too much, so we fill this stack, leave the remainder. + else { + int aRemainder = (aOutputBusStack.stackSize + aOutputStack.stackSize) - 64; + // Update the stack size in the bus storage map. + y.setValue(64); + // Create a new object to iterate over later, with the remainder data; + FlexiblePair<ItemStack, Integer> t = + new FlexiblePair<ItemStack, Integer>(u.getKey(), aRemainder); + // Remove the 'input' stack from the recipe outputs, so we don't try count it again. + aInputMap.remove(u); + // Add the remainder stack. + aInputMap.add(t); + continue outputItems; + } + } + } else { + continue outputItems; + } + } + } + } + + // We have stacks that did not merge, do we have space for them? + if (aInputMap.size() > 0) { + if (aInputMap.size() > aInputBusSlotsFree) { + aParallelRecipes = + (int) Math.floor((double) aInputBusSlotsFree / aInputMap.size() * aParallelRecipes); + // We do not have enough free slots in total to accommodate the remaining managed stacks. + log(" Free: " + aInputBusSlotsFree + ", Required: " + aInputMap.size()); + if (aParallelRecipes == 0) { + log("Failed to find enough space for all item outputs."); + return 0; + } + } + } + + /* + * End Item Management + */ + + } + + /* ======================================== + * Fluid Management + * ======================================== + */ + + if (aDoesOutputFluids) { + log("We have Fluids to output."); + // How many slots are free across all the output buses? + int aFluidHatches = 0; + int aEmptyFluidHatches = 0; + int aFullFluidHatches = 0; + // Create Map for Fluid Output + ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>> aOutputHatches = + new ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>>(); + for (final GT_MetaTileEntity_Hatch_Output tBus : this.mOutputHatches) { + if (!isValidMetaTileEntity(tBus)) { + continue; + } + aFluidHatches++; + // Map the Hatch with the space left for easy checking later. + if (tBus.getFluid() == null) { + aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( + tBus, null, tBus.getCapacity())); + } else { + int aSpaceLeft = tBus.getCapacity() - tBus.getFluidAmount(); + aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( + tBus, tBus.getFluid(), aSpaceLeft)); + } + } + // Create a map of all the fluids we would like to output, we can iterate over this and see how many we can + // merge into existing hatch stacks. + ArrayList<FluidStack> aOutputFluids = new ArrayList<FluidStack>(); + // Ugly ass boxing + aOutputFluids.addAll(new AutoMap<FluidStack>(aFluidOutputs)); + // Iterate the Hatches, updating their 'stored' data. + // for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aHatchData : aOutputHatches) { + for (int i = 0; i < aOutputHatches.size(); i++) { + // The Hatch Itself + GT_MetaTileEntity_Hatch_Output aHatch = aOutputHatches.get(i).getValue_1(); + // Fluid in the Hatch + FluidStack aHatchStack = aOutputHatches.get(i).getValue_2(); + // Fluid that the hatch is locked to + String aHatchLockedFluid = aOutputHatches.get(i).getValue_1().getLockedFluidName(); + // Space left in Hatch + int aSpaceLeftInHatch = aHatch.getCapacity() - aHatch.getFluidAmount(); + // Hatch is full, + if (aSpaceLeftInHatch <= 0) { + aFullFluidHatches++; + aOutputHatches.remove(aOutputHatches.get(i)); + i--; + continue; + } + // Hatch has space + else { + // Check if any fluids match + // aFluidMatch: for (FluidStack aOutputStack : aOutputFluids) { + for (int j = 0; j < aOutputFluids.size(); j++) { + // log(" aHatchStack "+aHatchStack.getLocalizedName()+" aOutput stack + // "+aOutputStack.getLocalizedName()); + if (GT_Utility.areFluidsEqual(aHatchStack, aOutputFluids.get(j)) + && (aHatchLockedFluid == null + || aHatchLockedFluid.equals( + aOutputFluids.get(j).getFluid().getName()))) { + int aFluidToPutIntoHatch = aOutputFluids.get(j).amount * aParallelRecipes; + // Not Enough space to insert all of the fluid. + // We fill this hatch and add a smaller Fluidstack back to the iterator. + if (aSpaceLeftInHatch < aFluidToPutIntoHatch) { + // Copy existing Hatch Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + aNewHatchStack.amount = 0; + // Copy existing Hatch Stack again + FluidStack aNewOutputStack = aHatchStack.copy(); + aNewOutputStack.amount = 0; + // How much fluid do we have left after we fill the hatch? + int aFluidLeftAfterInsert = aFluidToPutIntoHatch - aSpaceLeftInHatch; + // Set new stacks to appropriate values + aNewHatchStack.amount = aHatch.getCapacity(); + aNewOutputStack.amount = aFluidLeftAfterInsert; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputFluids.get(j)); + j--; + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aOutputHatches.get(i)); + i--; + // Add remaining Fluid to Output list + aOutputFluids.add(aNewOutputStack); + // Re-add hatch to hatch list, with new data. + // Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new + // Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, + // aNewHatchStack.amount); + // aOutputHatches.add(aNewHatchData); + break; + } + // We can fill this hatch perfectly (rare case), may as well add it directly to the full + // list. + else if (aSpaceLeftInHatch == aFluidToPutIntoHatch) { + // Copy Old Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + // Add in amount from output stack + aNewHatchStack.amount += aFluidToPutIntoHatch; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputFluids.get(j)); + j--; + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aOutputHatches.get(i)); + i--; + // Re-add hatch to hatch list, with new data. + Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = + new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( + aHatch, aNewHatchStack, aNewHatchStack.amount); + aOutputHatches.add(aNewHatchData); + break; + } + // We have more space than we need to merge, so we remove the stack from the output list and + // update the hatch list. + else { + // Copy Old Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + // Add in amount from output stack + aNewHatchStack.amount += aFluidToPutIntoHatch; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputFluids.get(j)); + j--; + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aOutputHatches.get(i)); + i--; + // Re-add hatch to hatch list, with new data. + Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = + new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( + aHatch, aNewHatchStack, aNewHatchStack.amount); + aOutputHatches.add(aNewHatchData); + // Check next fluid + continue; + } + + } else if (aHatchLockedFluid == null + || aHatchLockedFluid.equals( + aOutputFluids.get(j).getFluid().getName())) { + aEmptyFluidHatches++; + } else { + continue; + } + } + } + } + + for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aFreeHatchCheck : aOutputHatches) { + // Free Hatch + if ((aFreeHatchCheck.getValue_2() == null + || aFreeHatchCheck.getValue_3() == 0 + || aFreeHatchCheck.getValue_1().getFluid() == null) + && !aFreeHatchCheck.getValue_1().isFluidLocked()) { + aEmptyFluidHatches++; + } + } + + // We have Fluid Stacks we did not merge. Do we have space? + log("fluids to output " + aOutputFluids.size() + " empty hatches " + aEmptyFluidHatches); + if (aOutputFluids.size() > 0) { + // Not enough space to add fluids. + if (aOutputFluids.size() > aEmptyFluidHatches) { + aParallelRecipes = + (int) Math.floor((double) aEmptyFluidHatches / aOutputFluids.size() * aParallelRecipes); + log("Failed to find enough space for all fluid outputs. Free: " + aEmptyFluidHatches + + ", Required: " + aOutputFluids.size()); + return 0; + } + } + + /* + * End Fluid Management + */ + } + + return aParallelRecipes; + } + + /** + * A Static {@link Method} object which holds the current status of logging. + */ + public static Method aLogger = null; + + public void log(String s) { + if (!AsmConfig.disableAllLogging) { + if (CORE_Preloader.DEBUG_MODE) { + Logger.INFO(s); + } else { + Logger.MACHINE_INFO(s); + } + } + } + + public boolean checkRecipeGeneric() { + return checkRecipeGeneric(1, 100, 0); + } + + public boolean checkRecipeGeneric(int aMaxParallelRecipes, long aEUPercent, int aSpeedBonusPercent) { + return checkRecipeGeneric(aMaxParallelRecipes, aEUPercent, aSpeedBonusPercent, 10000); + } + + 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); + } + + public boolean checkRecipeGeneric( + GT_Recipe aRecipe, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + if (aRecipe == null) { + return false; + } + 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, + aRecipe); + } + + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll) { + return checkRecipeGeneric( + aItemInputs, + aFluidInputs, + aMaxParallelRecipes, + aEUPercent, + aSpeedBonusPercent, + aOutputChanceRoll, + null); + } + + /* + * public boolean checkRecipeGeneric( ItemStack[] aItemInputs, FluidStack[] + * aFluidInputs, int aMaxParallelRecipes, int aEUPercent, int + * aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { // Based on + * the Processing Array. A bit overkill, but very flexible. + * + * + * if (this.doesMachineBoostOutput()) { log("Boosting."); return + * checkRecipeBoostedOutputs(aItemInputs, aFluidInputs, aMaxParallelRecipes, + * aEUPercent, aSpeedBonusPercent, aOutputChanceRoll, aRecipe); } + * + * + * //Control Core to control the Multiblocks behaviour. int aControlCoreTier = + * getControlCoreTier(); + * + * //If no core, return false; if (aControlCoreTier > 0) { + * log("Control core found."); } + * + * + * // 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)); log("Running checkRecipeGeneric(0)"); + * + * //Check to see if Voltage Tier > Control Core Tier if (tTier > + * aControlCoreTier) { + * log("Control core found is lower tier than power tier. OK"); tTier = (byte) + * aControlCoreTier; } + * + * tTier = (byte) MathUtils.getValueWithinRange(tTier, 0, 9); + * + * GT_Recipe tRecipe = aRecipe != null ? aRecipe : 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; } + * + * if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) { + * 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); log("EU1: "+tRecipeEUt); // Count + * recipes to do in parallel, consuming input items and fluids and considering + * input voltage limits for (; parallelRecipes < aMaxParallelRecipes && + * tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) { if + * (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + * log("Broke at "+parallelRecipes+"."); break; } + * log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); tTotalEUt + * += tRecipeEUt; log("EU2: "+tTotalEUt); } + * + * if (parallelRecipes == 0) { log("BAD RETURN - 3"); return false; } + * + * log("EU3: "+tTotalEUt); + * + * // -- 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 * 10000); + * + * int aTempEu = (int) Math.floor(tTotalEUt); log("EU4: "+aTempEu); + * this.mEUt = (int) aTempEu; + * + * + * 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(); + * + * log("GOOD RETURN - 1"); return true; } + */ + + public long getMaxInputEnergy() { + long rEnergy = 0; + if (mEnergyHatches.size() + == 1) // so it only takes 1 amp is only 1 hatch is present so it works like most gt multies + return mEnergyHatches.get(0).getBaseMetaTileEntity().getInputVoltage(); for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) - if (isValidMetaTileEntity(tHatch)) rEnergy += tHatch.getBaseMetaTileEntity().getInputVoltage() * tHatch.getBaseMetaTileEntity().getInputAmperage(); + if (isValidMetaTileEntity(tHatch)) + rEnergy += tHatch.getBaseMetaTileEntity().getInputVoltage() + * tHatch.getBaseMetaTileEntity().getInputAmperage(); return rEnergy; - } - - public boolean hasPerfectOverclock() { - return false; - } - - 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, 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; - } - - - /* - * Check for Special Behaviours - */ - - // First populate the map if we need to. - if (mCustomBehviours.isEmpty()) { - mCustomBehviours.putAll(Multiblock_API.getSpecialBehaviourItemMap()); - } - - // We have a special slot object in the recipe - if (tRecipe.mSpecialItems != null) { - // The special slot is an item - if (tRecipe.mSpecialItems instanceof ItemStack) { - // Make an Itemstack instance of this. - ItemStack aSpecialStack = (ItemStack) tRecipe.mSpecialItems; - // Check if this item is in an input bus. - boolean aDidFindMatch = false; - for (ItemStack aInputItemsToCheck : aItemInputs) { - // If we find a matching stack, continue. - if (GT_Utility.areStacksEqual(aSpecialStack, aInputItemsToCheck, false)) { - // Iterate all special behaviour items, to see if we need to utilise one. - aDidFindMatch = true; - break; - } - } - // Try prevent needless iteration loops if we don't have the required inputs at all. - if (aDidFindMatch) { - // Iterate all special behaviour items, to see if we need to utilise one. - for (SpecialMultiBehaviour aBehaviours : mCustomBehviours.values()) { - // Found a match, let's adjust this recipe now. - if (aBehaviours.isTriggerItem(aSpecialStack)) { - // Adjust this recipe to suit special item - aMaxParallelRecipes = aBehaviours.getMaxParallelRecipes(); - aEUPercent = aBehaviours.getEUPercent(); - aSpeedBonusPercent = aBehaviours.getSpeedBonusPercent(); - aOutputChanceRoll = aBehaviours.getOutputChanceRoll(); - break; - } - } - } - } - } - - 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; - if (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; - } - - - - - - /* - * Here we handle recipe boosting, which grants additional output %'s to recipes that do not have 100%. - */ - - private boolean mHasBoostedCurrentRecipe = false; - private GT_Recipe mBoostedRecipe = null; - private ItemStack[] mInputVerificationForBoosting = null; - - /** - * Does this machine boost it's output? - * @return - if true, gives additional % to output chances. - */ - protected boolean doesMachineBoostOutput() { - return false; - } - - - - private int boostOutput(int aAmount) { - if (aAmount <= 0) { - return 10000; - } - if (aAmount <= 250) { - aAmount += MathUtils.randInt(Math.max(aAmount/2, 1), aAmount*2); - } - else if (aAmount <= 500) { - aAmount += MathUtils.randInt(Math.max(aAmount/2, 1), aAmount*2); - } - else if (aAmount <= 750) { - aAmount += MathUtils.randInt(Math.max(aAmount/2, 1), aAmount*2); - } - else if (aAmount <= 1000) { - aAmount = (aAmount*2); - } - else if (aAmount <= 1500) { - aAmount = (aAmount*2); - } - else if (aAmount <= 2000) { - aAmount = (int) (aAmount*1.5); - } - else if (aAmount <= 3000) { - aAmount = (int) (aAmount*1.5); - } - else if (aAmount <= 4000) { - aAmount = (int) (aAmount*1.2); - } - else if (aAmount <= 5000) { - aAmount = (int) (aAmount*1.2); - } - else if (aAmount <= 7000) { - aAmount = (int) (aAmount*1.2); - } - else if (aAmount <= 9000) { - aAmount = (int) (aAmount*1.1); - } - return Math.min(10000, aAmount); - } - - public GT_Recipe generateAdditionalOutputForRecipe(GT_Recipe aRecipe) { - AutoMap<Integer> aNewChances = new AutoMap<Integer>(); - for (int chance : aRecipe.mChances) { - aNewChances.put(boostOutput(chance)); - } - GT_Recipe aClone = aRecipe.copy(); - int[] aTemp = new int[aNewChances.size()]; - int slot = 0; - for (int g : aNewChances) { - aTemp[slot] = g; - slot++; - } - aClone.mChances = aTemp; - return aClone; - } - - - /** - * Processes recipes but provides a bonus to the output % of items if they are < 100%. - * - * @param aItemInputs - * @param aFluidInputs - * @param aMaxParallelRecipes - * @param aEUPercent - * @param aSpeedBonusPercent - * @param aOutputChanceRoll - * @param aRecipe - * @return - */ - public boolean checkRecipeBoostedOutputs( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, long aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - log("Running checkRecipeGeneric(0)"); - - GT_Recipe tRecipe = aRecipe != null ? aRecipe : findRecipe( - getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - - log("Running checkRecipeGeneric(1)"); - - //First we check whether or not we have an input cached for boosting. - //If not, we set it to the current recipe. - //If we do, we compare it against the current recipe, if thy are the same, we try return a boosted recipe, if not, we boost a new recipe. - boolean isRecipeInputTheSame = false; - - //No cached recipe inputs, assume first run. - if (mInputVerificationForBoosting == null) { - mInputVerificationForBoosting = tRecipe.mInputs; - isRecipeInputTheSame = true; - } - //If the inputs match, we are good. - else { - if (tRecipe.mInputs == mInputVerificationForBoosting) { - isRecipeInputTheSame = true; - } - else { - isRecipeInputTheSame = false; - } - } - - //Inputs are the same, let's see if there's a boosted version. - if (isRecipeInputTheSame) { - //Yes, let's just set that as the recipe - if (mHasBoostedCurrentRecipe && mBoostedRecipe != null) { - tRecipe = mBoostedRecipe; - } - //We have yet to generate a new boosted recipe - else { - GT_Recipe aBoostedRecipe = this.generateAdditionalOutputForRecipe(tRecipe); - if (aBoostedRecipe != null) { - mBoostedRecipe = aBoostedRecipe; - mHasBoostedCurrentRecipe = true; - tRecipe = mBoostedRecipe; - } - //Bad boost - else { - mBoostedRecipe = null; - mHasBoostedCurrentRecipe = false; - } - } - } - //We have changed inputs, so we should generate a new boosted recipe - else { - GT_Recipe aBoostedRecipe = this.generateAdditionalOutputForRecipe(tRecipe); - if (aBoostedRecipe != null) { - mBoostedRecipe = aBoostedRecipe; - mHasBoostedCurrentRecipe = true; - tRecipe = mBoostedRecipe; - } - //Bad boost - else { - mBoostedRecipe = null; - mHasBoostedCurrentRecipe = false; - } - } - - //Bad modify, let's just use the original recipe. - if (!mHasBoostedCurrentRecipe || mBoostedRecipe == null) { - tRecipe = aRecipe != null ? aRecipe : findRecipe( - getBaseMetaTileEntity(), mLastRecipe, false, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - } - - // 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 /= 2; - } - } + } - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } + public boolean hasPerfectOverclock() { + return false; + } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + 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, + 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; + } - // 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; - } - } + /* + * Check for Special Behaviours + */ - // 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; - } - } + // First populate the map if we need to. + if (mCustomBehviours.isEmpty()) { + mCustomBehviours.putAll(Multiblock_API.getSpecialBehaviourItemMap()); + } - // 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; - } - } - } + // We have a special slot object in the recipe + if (tRecipe.mSpecialItems != null) { + // The special slot is an item + if (tRecipe.mSpecialItems instanceof ItemStack) { + // Make an Itemstack instance of this. + ItemStack aSpecialStack = (ItemStack) tRecipe.mSpecialItems; + // Check if this item is in an input bus. + boolean aDidFindMatch = false; + for (ItemStack aInputItemsToCheck : aItemInputs) { + // If we find a matching stack, continue. + if (GT_Utility.areStacksEqual(aSpecialStack, aInputItemsToCheck, false)) { + // Iterate all special behaviour items, to see if we need to utilise one. + aDidFindMatch = true; + break; + } + } + // Try prevent needless iteration loops if we don't have the required inputs at all. + if (aDidFindMatch) { + // Iterate all special behaviour items, to see if we need to utilise one. + for (SpecialMultiBehaviour aBehaviours : mCustomBehviours.values()) { + // Found a match, let's adjust this recipe now. + if (aBehaviours.isTriggerItem(aSpecialStack)) { + // Adjust this recipe to suit special item + aMaxParallelRecipes = aBehaviours.getMaxParallelRecipes(); + aEUPercent = aBehaviours.getEUPercent(); + aSpeedBonusPercent = aBehaviours.getSpeedBonusPercent(); + aOutputChanceRoll = aBehaviours.getOutputChanceRoll(); + break; + } + } + } + } + } - tOutputItems = removeNulls(tOutputItems); + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } - // 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); - } - } + // 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 (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); - } + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } - // 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()]); + // -- 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 (hasPerfectOverclock()) { + this.mMaxProgresstime /= 4; + } else { + this.mMaxProgresstime /= 2; + } + } + } - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - log("GOOD RETURN - 1"); - return true; - } + // 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; + } + /* + * Here we handle recipe boosting, which grants additional output %'s to recipes that do not have 100%. + */ + private boolean mHasBoostedCurrentRecipe = false; + private GT_Recipe mBoostedRecipe = null; + private ItemStack[] mInputVerificationForBoosting = null; + /** + * Does this machine boost it's output? + * @return - if true, gives additional % to output chances. + */ + protected boolean doesMachineBoostOutput() { + return false; + } + private int boostOutput(int aAmount) { + if (aAmount <= 0) { + return 10000; + } + if (aAmount <= 250) { + aAmount += MathUtils.randInt(Math.max(aAmount / 2, 1), aAmount * 2); + } else if (aAmount <= 500) { + aAmount += MathUtils.randInt(Math.max(aAmount / 2, 1), aAmount * 2); + } else if (aAmount <= 750) { + aAmount += MathUtils.randInt(Math.max(aAmount / 2, 1), aAmount * 2); + } else if (aAmount <= 1000) { + aAmount = (aAmount * 2); + } else if (aAmount <= 1500) { + aAmount = (aAmount * 2); + } else if (aAmount <= 2000) { + aAmount = (int) (aAmount * 1.5); + } else if (aAmount <= 3000) { + aAmount = (int) (aAmount * 1.5); + } else if (aAmount <= 4000) { + aAmount = (int) (aAmount * 1.2); + } else if (aAmount <= 5000) { + aAmount = (int) (aAmount * 1.2); + } else if (aAmount <= 7000) { + aAmount = (int) (aAmount * 1.2); + } else if (aAmount <= 9000) { + aAmount = (int) (aAmount * 1.1); + } + return Math.min(10000, aAmount); + } + public GT_Recipe generateAdditionalOutputForRecipe(GT_Recipe aRecipe) { + AutoMap<Integer> aNewChances = new AutoMap<Integer>(); + for (int chance : aRecipe.mChances) { + aNewChances.put(boostOutput(chance)); + } + GT_Recipe aClone = aRecipe.copy(); + int[] aTemp = new int[aNewChances.size()]; + int slot = 0; + for (int g : aNewChances) { + aTemp[slot] = g; + slot++; + } + aClone.mChances = aTemp; + return aClone; + } + /** + * Processes recipes but provides a bonus to the output % of items if they are < 100%. + * + * @param aItemInputs + * @param aFluidInputs + * @param aMaxParallelRecipes + * @param aEUPercent + * @param aSpeedBonusPercent + * @param aOutputChanceRoll + * @param aRecipe + * @return + */ + public boolean checkRecipeBoostedOutputs( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = aRecipe != null + ? aRecipe + : findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + + log("Running checkRecipeGeneric(1)"); + + // First we check whether or not we have an input cached for boosting. + // If not, we set it to the current recipe. + // If we do, we compare it against the current recipe, if thy are the same, we try return a boosted recipe, if + // not, we boost a new recipe. + boolean isRecipeInputTheSame = false; + + // No cached recipe inputs, assume first run. + if (mInputVerificationForBoosting == null) { + mInputVerificationForBoosting = tRecipe.mInputs; + isRecipeInputTheSame = true; + } + // If the inputs match, we are good. + else { + if (tRecipe.mInputs == mInputVerificationForBoosting) { + isRecipeInputTheSame = true; + } else { + isRecipeInputTheSame = false; + } + } + // Inputs are the same, let's see if there's a boosted version. + if (isRecipeInputTheSame) { + // Yes, let's just set that as the recipe + if (mHasBoostedCurrentRecipe && mBoostedRecipe != null) { + tRecipe = mBoostedRecipe; + } + // We have yet to generate a new boosted recipe + else { + GT_Recipe aBoostedRecipe = this.generateAdditionalOutputForRecipe(tRecipe); + if (aBoostedRecipe != null) { + mBoostedRecipe = aBoostedRecipe; + mHasBoostedCurrentRecipe = true; + tRecipe = mBoostedRecipe; + } + // Bad boost + else { + mBoostedRecipe = null; + mHasBoostedCurrentRecipe = false; + } + } + } + // We have changed inputs, so we should generate a new boosted recipe + else { + GT_Recipe aBoostedRecipe = this.generateAdditionalOutputForRecipe(tRecipe); + if (aBoostedRecipe != null) { + mBoostedRecipe = aBoostedRecipe; + mHasBoostedCurrentRecipe = true; + tRecipe = mBoostedRecipe; + } + // Bad boost + else { + mBoostedRecipe = null; + mHasBoostedCurrentRecipe = false; + } + } + + // Bad modify, let's just use the original recipe. + if (!mHasBoostedCurrentRecipe || mBoostedRecipe == null) { + tRecipe = aRecipe != null + ? aRecipe + : findRecipe( + getBaseMetaTileEntity(), + mLastRecipe, + false, + false, + gregtech.api.enums.GT_Values.V[tTier], + aFluidInputs, + aItemInputs); + } + + // 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 /= 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 isMachineRunning() { + boolean aRunning = this.getBaseMetaTileEntity().isActive(); + // log("Queried Multiblock is currently running: "+aRunning); + return aRunning; + } + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + // Time Counter + if (aBaseMetaTileEntity.isServerSide()) { + this.mTotalRunTime++; + } - public boolean isMachineRunning() { - boolean aRunning = this.getBaseMetaTileEntity().isActive(); - //log("Queried Multiblock is currently running: "+aRunning); - return aRunning; - } + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mChargeHatches.clear(); + this.mDischargeHatches.clear(); + this.mControlCoreBus.clear(); + this.mAirIntakes.clear(); + this.mTecTechEnergyHatches.clear(); + this.mTecTechDynamoHatches.clear(); + this.mAllEnergyHatches.clear(); + this.mAllDynamoHatches.clear(); + } + } - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, - final long aTick) { - - //Time Counter - if (aBaseMetaTileEntity.isServerSide()){ - this.mTotalRunTime++; - } + super.onPostTick(aBaseMetaTileEntity, aTick); + } - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mUpdate == 1 || this.mStartUpCheck == 1) { - this.mChargeHatches.clear(); - this.mDischargeHatches.clear(); - this.mControlCoreBus.clear(); - this.mAirIntakes.clear(); - this.mTecTechEnergyHatches.clear(); - this.mTecTechDynamoHatches.clear(); - this.mAllEnergyHatches.clear(); - this.mAllDynamoHatches.clear(); - } - } + @Override + public void explodeMultiblock() { + MetaTileEntity tTileEntity; + for (final Iterator<GT_MetaTileEntity_Hatch_InputBattery> localIterator = this.mChargeHatches.iterator(); + localIterator.hasNext(); + tTileEntity.getBaseMetaTileEntity().doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + tTileEntity = null; + for (final Iterator<GT_MetaTileEntity_Hatch_OutputBattery> localIterator = this.mDischargeHatches.iterator(); + localIterator.hasNext(); + tTileEntity.getBaseMetaTileEntity().doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + tTileEntity = null; + for (final Iterator<GT_MetaTileEntity_Hatch> localIterator = this.mTecTechDynamoHatches.iterator(); + localIterator.hasNext(); + tTileEntity.getBaseMetaTileEntity().doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + tTileEntity = null; + for (final Iterator<GT_MetaTileEntity_Hatch> localIterator = this.mTecTechEnergyHatches.iterator(); + localIterator.hasNext(); + tTileEntity.getBaseMetaTileEntity().doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + super.explodeMultiblock(); + } - super.onPostTick(aBaseMetaTileEntity, aTick); - } + protected int getGUICircuit(ItemStack[] t) { + Item g = CI.getNumberedCircuit(0).getItem(); + ItemStack guiSlot = this.mInventory[1]; + int mMode = -1; + if (guiSlot != null && guiSlot.getItem() == g) { + this.mInternalCircuit = true; + return guiSlot.getItemDamage(); + } else { + this.mInternalCircuit = false; + } - @Override - public void explodeMultiblock() { - MetaTileEntity tTileEntity; - for (final Iterator<GT_MetaTileEntity_Hatch_InputBattery> localIterator = this.mChargeHatches - .iterator(); localIterator.hasNext(); tTileEntity - .getBaseMetaTileEntity() - .doExplosion(gregtech.api.enums.GT_Values.V[8])) { - tTileEntity = localIterator.next(); - } - tTileEntity = null; - for (final Iterator<GT_MetaTileEntity_Hatch_OutputBattery> localIterator = this.mDischargeHatches - .iterator(); localIterator.hasNext(); tTileEntity - .getBaseMetaTileEntity() - .doExplosion(gregtech.api.enums.GT_Values.V[8])) { - tTileEntity = localIterator.next(); - } - tTileEntity = null; - for (final Iterator<GT_MetaTileEntity_Hatch> localIterator = this.mTecTechDynamoHatches - .iterator(); localIterator.hasNext(); tTileEntity - .getBaseMetaTileEntity() - .doExplosion(gregtech.api.enums.GT_Values.V[8])) { - tTileEntity = localIterator.next(); - } - tTileEntity = null; - for (final Iterator<GT_MetaTileEntity_Hatch> localIterator = this.mTecTechEnergyHatches - .iterator(); localIterator.hasNext(); tTileEntity - .getBaseMetaTileEntity() - .doExplosion(gregtech.api.enums.GT_Values.V[8])) { - tTileEntity = localIterator.next(); - } + if (!this.mInternalCircuit) { + for (ItemStack j : t) { + if (j.getItem() == g) { + mMode = j.getItemDamage(); + break; + } + } + } + return mMode; + } + protected ItemStack getGUIItemStack() { + ItemStack guiSlot = this.mInventory[1]; + return guiSlot; + } + + protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) { + boolean result = false; + if (this.mInventory[1] == null) { + this.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null; + this.depleteInput(aNewGuiSlotContents); + this.updateSlots(); + result = true; + } + return result; + } + protected boolean clearGUIItemSlot() { + return setGUIItemStack(null); + } - super.explodeMultiblock(); - } + public ItemStack findItemInInventory(Item aSearchStack) { + return findItemInInventory(aSearchStack, 0); + } - protected int getGUICircuit(ItemStack[] t) { - Item g = CI.getNumberedCircuit(0).getItem(); - ItemStack guiSlot = this.mInventory[1]; - int mMode = -1; - if (guiSlot != null && guiSlot.getItem() == g) { - this.mInternalCircuit = true; - return guiSlot.getItemDamage(); - } - else { - this.mInternalCircuit = false; - } + public ItemStack findItemInInventory(Item aSearchStack, int aMeta) { + return findItemInInventory(ItemUtils.simpleMetaStack(aSearchStack, aMeta, 1)); + } - if (!this.mInternalCircuit) { - for (ItemStack j : t) { - if (j.getItem() == g) { - mMode = j.getItemDamage(); - break; - } - } - } - return mMode; - } - - protected ItemStack getGUIItemStack() { - ItemStack guiSlot = this.mInventory[1]; - return guiSlot; - } - - protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) { - boolean result = false; - if (this.mInventory[1] == null) { - this.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null; - this.depleteInput(aNewGuiSlotContents); - this.updateSlots(); - result = true; - } - return result; - } - - protected boolean clearGUIItemSlot() { - return setGUIItemStack(null); - } - - - public ItemStack findItemInInventory(Item aSearchStack) { - return findItemInInventory(aSearchStack, 0); - } - - public ItemStack findItemInInventory(Item aSearchStack, int aMeta) { - return findItemInInventory(ItemUtils.simpleMetaStack(aSearchStack, aMeta, 1)); - } - - public ItemStack findItemInInventory(ItemStack aSearchStack) { - if (aSearchStack != null && this.mInputBusses.size() > 0) { - for (GT_MetaTileEntity_Hatch_InputBus bus : this.mInputBusses) { - if (bus != null) { - for (ItemStack uStack : bus.mInventory) { - if (uStack != null) { - if (aSearchStack.getClass().isInstance(uStack.getItem())) { - return uStack; - } - } - } - } - } - } - return null; - } - - /** - * Deplete fluid input from a set of restricted hatches. This assumes these hatches can store nothing else but your - * expected fluid - */ - protected boolean depleteInputFromRestrictedHatches(Collection<GT_MetaTileEntity_Hatch_CustomFluidBase> aHatches, int aAmount) { + public ItemStack findItemInInventory(ItemStack aSearchStack) { + if (aSearchStack != null && this.mInputBusses.size() > 0) { + for (GT_MetaTileEntity_Hatch_InputBus bus : this.mInputBusses) { + if (bus != null) { + for (ItemStack uStack : bus.mInventory) { + if (uStack != null) { + if (aSearchStack.getClass().isInstance(uStack.getItem())) { + return uStack; + } + } + } + } + } + } + return null; + } + + /** + * Deplete fluid input from a set of restricted hatches. This assumes these hatches can store nothing else but your + * expected fluid + */ + protected boolean depleteInputFromRestrictedHatches( + Collection<GT_MetaTileEntity_Hatch_CustomFluidBase> aHatches, int aAmount) { for (final GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : aHatches) { if (isValidMetaTileEntity(tHatch)) { FluidStack tLiquid = tHatch.getFluid(); @@ -1634,1181 +1673,1254 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_En } @Override - public void updateSlots() { - for (final GT_MetaTileEntity_Hatch_InputBattery tHatch : this.mChargeHatches) { - if (isValidMetaTileEntity(tHatch)) { - tHatch.updateSlots(); - } - } - for (final GT_MetaTileEntity_Hatch_OutputBattery tHatch : this.mDischargeHatches) { - if (isValidMetaTileEntity(tHatch)) { - tHatch.updateSlots(); - } - } - super.updateSlots(); - } - - public boolean isToolCreative(ItemStack mStack){ - Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(mStack); - Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(mStack); - if (t1 == Materials._NULL && t2 == Materials._NULL){ - return true; - } - return false; - } - - /** - * Causes a Random Maint. Issue. - * @return {@link boolean} - Returns whether or not an issue was caused, should always be true. - */ - public boolean causeMaintenanceIssue() { - boolean b = false; - switch (this.getBaseMetaTileEntity().getRandomNumber(6)) { - case 0 : { - this.mWrench = false; - b = true; - break; - } - case 1 : { - this.mScrewdriver = false; - b = true; - break; - } - case 2 : { - this.mSoftHammer = false; - b = true; - break; - } - case 3 : { - this.mHardHammer = false; - b = true; - break; - } - case 4 : { - this.mSolderingTool = false; - b = true; - break; - } - case 5 : { - this.mCrowbar = false; - b = true; - break; - } - } - return b; - } - - public void fixAllMaintenanceIssue() { - this.mCrowbar = true; - this.mWrench = true; - this.mHardHammer = true; - this.mSoftHammer = true; - this.mSolderingTool = true; - this.mScrewdriver = true; - } - - public boolean checkHatch() { - return mMaintenanceHatches.size() <= 1 && (this.getPollutionPerSecond(null) > 0 ? !mMufflerHatches.isEmpty() : true); - } - - public <E> boolean addToMachineListInternal(ArrayList<E> aList, final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - return addToMachineListInternal(aList, getMetaTileEntity(aTileEntity), aBaseCasingIndex); - } - - public <E> boolean addToMachineListInternal(ArrayList<E> aList, final IMetaTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } - - //Check type - /* - * Class <?> aHatchType = ReflectionUtils.getTypeOfGenericObject(aList); if - * (!aHatchType.isInstance(aTileEntity)) { return false; } - */ - - // Try setRecipeMap - - try { - if (aTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { - resetRecipeMapForHatch((GT_MetaTileEntity_Hatch) aTileEntity, getRecipeMap()); - } - if (aTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { - resetRecipeMapForHatch((GT_MetaTileEntity_Hatch) aTileEntity, getRecipeMap()); - } - } - catch (Throwable t) { - t.printStackTrace(); - } - - if (aList.isEmpty()) { - if (aTileEntity instanceof GT_MetaTileEntity_Hatch) { - if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { - log("Adding " + aTileEntity.getInventoryName() + " at " + new BlockPos(aTileEntity.getBaseMetaTileEntity()).getLocationString()); - } - updateTexture(aTileEntity, aBaseCasingIndex); - return aList.add((E) aTileEntity); - } - } - else { - IGregTechTileEntity aCur = aTileEntity.getBaseMetaTileEntity(); - if (aList.contains(aTileEntity)) { - log("Found Duplicate "+aTileEntity.getInventoryName()+" @ " + new BlockPos(aCur).getLocationString()); - return false; - } - BlockPos aCurPos = new BlockPos(aCur); - boolean aExists = false; - for (E m : aList) { - IGregTechTileEntity b = ((IMetaTileEntity) m).getBaseMetaTileEntity(); - if (b != null) { - BlockPos aPos = new BlockPos(b); - if (aPos != null) { - if (aCurPos.equals(aPos)) { - if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { - log("Found Duplicate "+b.getInventoryName()+" at " + aPos.getLocationString()); - } - return false; - } - } - } - } - if (aTileEntity instanceof GT_MetaTileEntity_Hatch) { - if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { - log("Adding " + aCur.getInventoryName() + " at " + aCurPos.getLocationString()); - } - updateTexture(aTileEntity, aBaseCasingIndex); - return aList.add((E) aTileEntity); - } - } - return false; - } - - public int getControlCoreTier() { - - //Always return best tier if config is off. - /*boolean aCoresConfig = gtPlusPlus.core.lib.CORE.ConfigSwitches.requireControlCores; - if (!aCoresConfig) { - return 10; - }*/ - - if (mControlCoreBus.isEmpty()) { - log("No Control Core Modules Found."); - return 0; - } - GT_MetaTileEntity_Hatch_ControlCore i = getControlCoreBus(); - if (i != null) { - ItemStack x = i.mInventory[0]; - if (x != null) { - return x.getItemDamage(); - } - } - log("Control Core Module was null."); - return 0; - } - - public GT_MetaTileEntity_Hatch_ControlCore getControlCoreBus() { - if (this.mControlCoreBus == null || this.mControlCoreBus.isEmpty()) { - return null; - } - GT_MetaTileEntity_Hatch_ControlCore x = this.mControlCoreBus.get(0); - if (x != null) { - log("getControlCore(ok)"); - return x; - } - log("getControlCore(bad)"); - return null; - } - - //mControlCoreBus - public boolean addControlCoreToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (!mControlCoreBus.isEmpty()) { - log("Tried to add a secondary control core module."); - return false; - } - GT_MetaTileEntity_Hatch_ControlCore Module = (GT_MetaTileEntity_Hatch_ControlCore) getMetaTileEntity(aTileEntity); - if (Module != null) { - if (Module.setOwner(aTileEntity)) { - log("Adding control core module."); - return addToMachineListInternal(mControlCoreBus, Module, aBaseCasingIndex); - } - } - return false; - } - - private IMetaTileEntity getMetaTileEntity(final IGregTechTileEntity aTileEntity) { - if (aTileEntity == null) { - return null; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - return aMetaTileEntity; - } - - - @Override - public boolean addToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - return addToMachineList(getMetaTileEntity(aTileEntity), aBaseCasingIndex); - } - - public boolean addToMachineList(final IMetaTileEntity aMetaTileEntity, final int aBaseCasingIndex) { - if (aMetaTileEntity == null) { - return false; - } - - //Use this to determine the correct value, then update the hatch texture after. - boolean aDidAdd = false; - - //Handle Custom Hatches - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_ControlCore) { - log("Found GT_MetaTileEntity_Hatch_ControlCore"); - if (!mControlCoreBus.isEmpty()) { - log("Tried to add a secondary control core module."); - return false; - } - aDidAdd = addToMachineListInternal(this.mControlCoreBus, aMetaTileEntity, aBaseCasingIndex); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBattery) { - log("Found GT_MetaTileEntity_Hatch_InputBattery"); - aDidAdd = addToMachineListInternal(mChargeHatches, aMetaTileEntity, aBaseCasingIndex); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBattery) { - log("Found GT_MetaTileEntity_Hatch_OutputBattery"); - aDidAdd = addToMachineListInternal(mDischargeHatches, aMetaTileEntity, aBaseCasingIndex); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) { - aDidAdd = addToMachineListInternal(mAirIntakes, aMetaTileEntity, aBaseCasingIndex) && addToMachineListInternal(mInputHatches, aMetaTileEntity, aBaseCasingIndex); - } - - //Handle TT Multi-A Energy Hatches - else if (LoadedMods.TecTech && isThisHatchMultiEnergy(aMetaTileEntity)) { - log("Found isThisHatchMultiEnergy"); - aDidAdd = addToMachineListInternal(mTecTechEnergyHatches, aMetaTileEntity, aBaseCasingIndex); - updateMasterEnergyHatchList(aMetaTileEntity); - } - - //Handle TT Multi-A Dynamos - else if (LoadedMods.TecTech && isThisHatchMultiDynamo(aMetaTileEntity)) { - log("Found isThisHatchMultiDynamo"); - aDidAdd = addToMachineListInternal(mTecTechDynamoHatches, aMetaTileEntity, aBaseCasingIndex); - updateMasterDynamoHatchList(aMetaTileEntity); - } - - //Handle Fluid Hatches using seperate logic - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) - aDidAdd = addToMachineListInternal(mInputHatches, aMetaTileEntity, aBaseCasingIndex); - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) - aDidAdd = addToMachineListInternal(mOutputHatches, aMetaTileEntity, aBaseCasingIndex); - - //Process Remaining hatches using Vanilla GT Logic - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) - aDidAdd = addToMachineListInternal(mInputBusses, aMetaTileEntity, aBaseCasingIndex); - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) - aDidAdd = addToMachineListInternal(mOutputBusses, aMetaTileEntity, aBaseCasingIndex); - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { - aDidAdd = addToMachineListInternal(mEnergyHatches, aMetaTileEntity, aBaseCasingIndex); - updateMasterEnergyHatchList(aMetaTileEntity); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { - aDidAdd = addToMachineListInternal(mDynamoHatches, aMetaTileEntity, aBaseCasingIndex); - updateMasterDynamoHatchList(aMetaTileEntity); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) - aDidAdd = addToMachineListInternal(mMaintenanceHatches, aMetaTileEntity, aBaseCasingIndex); - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) - aDidAdd = addToMachineListInternal(mMufflerHatches, aMetaTileEntity, aBaseCasingIndex); - - //return super.addToMachineList(aTileEntity, aBaseCasingIndex); - return aDidAdd; - } - - - - @Override - public boolean addMaintenanceToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { - return addToMachineList(aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - @Override - public boolean addMufflerToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { - return addToMachineList(aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - @Override - public boolean addInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { - return addToMachineList(aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - @Override - public boolean addOutputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { - return addToMachineList(aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - public boolean addAirIntakeToMachineList(final IGregTechTileEntity aMetaTileEntity, final int aBaseCasingIndex) { - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) { - return addToMachineList(aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - public boolean addFluidInputToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - return addFluidInputToMachineList(getMetaTileEntity(aTileEntity), aBaseCasingIndex); - } - - public boolean addFluidInputToMachineList(final IMetaTileEntity aMetaTileEntity, final int aBaseCasingIndex) { - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { - return addToMachineList(aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - public boolean clearRecipeMapForAllInputHatches() { - return resetRecipeMapForAllInputHatches(null); - } - - public boolean resetRecipeMapForAllInputHatches() { - return resetRecipeMapForAllInputHatches(this.getRecipeMap()); - } - - public boolean resetRecipeMapForAllInputHatches(GT_Recipe_Map aMap) { - int cleared = 0; - for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { - if (resetRecipeMapForHatch(g, aMap)) { - cleared++; - } - } - for (GT_MetaTileEntity_Hatch_InputBus g : this.mInputBusses) { - if (resetRecipeMapForHatch(g, aMap)) { - cleared++; - } - } - return cleared > 0; - } - public boolean resetRecipeMapForHatch(IGregTechTileEntity aTileEntity, GT_Recipe_Map aMap) { - try { - final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { - return resetRecipeMapForHatch((GT_MetaTileEntity_Hatch)aMetaTileEntity, aMap); - } - else { - return false; - } - } - catch (Throwable t) { - t.printStackTrace(); - return false; - } - } - - public boolean resetRecipeMapForHatch(GT_MetaTileEntity_Hatch aTileEntity, GT_Recipe_Map aMap) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity; - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input){ - ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = null; - ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap; - if (aMap != null && aMap.mNEIName != null) { - log("Remapped Input Hatch to "+aMap.mNEIName+"."); - } - else { - log("Cleared Input Hatch."); - } - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { - ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = null; - ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = aMap; - if (aMap != null && aMap.mNEIName != null) { - log("Remapped Input Bus to "+aMap.mNEIName+"."); - } - else { - log("Cleared Input Bus."); - } - } - else { - ((GT_MetaTileEntity_Hatch_Steam_BusInput) aMetaTileEntity).mRecipeMap = null; - ((GT_MetaTileEntity_Hatch_Steam_BusInput) aMetaTileEntity).mRecipeMap = aMap; - if (aMap != null && aMap.mNEIName != null) { - log("Remapped Input Bus to "+aMap.mNEIName+"."); - } - else { - log("Cleared Input Bus."); - } - } - return true; - } - else { - return false; - } - } - - @Override - public final void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - clearRecipeMapForAllInputHatches(); - onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ); - resetRecipeMapForAllInputHatches(); - } - - public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - - } - - - - - - /** - * Enable Texture Casing Support if found in GT 5.09 - */ - - public boolean updateTexture(final IGregTechTileEntity aTileEntity, int aCasingID){ - return updateTexture(getMetaTileEntity(aTileEntity), aCasingID); - } - - /** - * Enable Texture Casing Support if found in GT 5.09 - */ - - @SuppressWarnings("deprecation") - public boolean updateTexture(final IMetaTileEntity aTileEntity, int aCasingID){ - try { //gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch.updateTexture(int) - - final IMetaTileEntity aMetaTileEntity = aTileEntity; - if (aMetaTileEntity == null) { - return false; - } - Method mProper = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); - if (mProper != null){ - if (GT_MetaTileEntity_Hatch.class.isInstance(aMetaTileEntity)){ - mProper.setAccessible(true); - mProper.invoke(aMetaTileEntity, aCasingID); - //log("Good Method Call for updateTexture."); - return true; - } - } - else { - log("Bad Method Call for updateTexture."); - if (GT_MetaTileEntity_Hatch.class.isInstance(aMetaTileEntity)){ - if (aCasingID <= Byte.MAX_VALUE) { - ((GT_MetaTileEntity_Hatch) aTileEntity).mMachineBlock = (byte) aCasingID; - log("Good Method Call for updateTexture. Used fallback method of setting mMachineBlock as casing id was <= 128."); - return true; - } - else { - log("updateTexture returning false. 1.2"); - } - } - else { - log("updateTexture returning false. 1.3"); - } - } - log("updateTexture returning false. 1"); - return false; - } - catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - log("updateTexture returning false."); - log("updateTexture returning false. 2"); - e.printStackTrace(); - return false; - } - - } - - - - - - - - - - /** - * TecTech Support - */ - - - /** - * This is the array Used to Store the Tectech Multi-Amp Dynamo hatches. - */ - - public ArrayList<GT_MetaTileEntity_Hatch> mTecTechDynamoHatches = new ArrayList<GT_MetaTileEntity_Hatch>(); - - /** - * This is the array Used to Store the Tectech Multi-Amp Energy hatches. - */ - - public ArrayList<GT_MetaTileEntity_Hatch> mTecTechEnergyHatches = new ArrayList<GT_MetaTileEntity_Hatch>(); - - /** - * TecTech Multi-Amp Dynamo Support - * @param aTileEntity - The Dynamo Hatch - * @param aBaseCasingIndex - Casing Texture - * @return - */ - - public boolean addMultiAmpDynamoToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex){ - final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity == null) { - return false; - } - if (isThisHatchMultiDynamo(aTileEntity)) { - return addToMachineListInternal(mTecTechDynamoHatches, aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - public boolean isThisHatchMultiDynamo(IGregTechTileEntity aTileEntity){ - return isThisHatchMultiDynamo(getMetaTileEntity(aTileEntity)); - } - - public boolean isThisHatchMultiDynamo(IMetaTileEntity aMetaTileEntity){ - Class<?> mDynamoClass; - mDynamoClass = ReflectionUtils.getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti"); - if (mDynamoClass != null){ - if (mDynamoClass.isInstance(aMetaTileEntity)){ - return true; - } - } - return false; - } - - @Override - public boolean addDynamoToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo || isThisHatchMultiDynamo(aMetaTileEntity)) { - return addToMachineList(aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - private boolean updateMasterDynamoHatchList(IMetaTileEntity aMetaTileEntity) { - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { - GT_MetaTileEntity_Hatch aHatch = (GT_MetaTileEntity_Hatch) aMetaTileEntity; - return mAllDynamoHatches.add(aHatch); - } - return false; - } - - - /** - * TecTech Multi-Amp Energy Hatch Support - * @param aTileEntity - The Energy Hatch - * @param aBaseCasingIndex - Casing Texture - * @return - */ - - public boolean addMultiAmpEnergyToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex){ - final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity == null) { - return false; - } - if (isThisHatchMultiEnergy(aMetaTileEntity)) { - return addToMachineListInternal(mTecTechEnergyHatches, aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - public boolean isThisHatchMultiEnergy(IGregTechTileEntity aTileEntity){ - return isThisHatchMultiEnergy(getMetaTileEntity(aTileEntity)); - } - - public boolean isThisHatchMultiEnergy(IMetaTileEntity aMetaTileEntity){ - Class<?> mDynamoClass; - mDynamoClass = ReflectionUtils.getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti"); - if (mDynamoClass != null){ - if (mDynamoClass.isInstance(aMetaTileEntity)){ - return true; - } - } - return false; - } - - @Override - public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy || isThisHatchMultiEnergy(aMetaTileEntity)) { - return addToMachineList(aMetaTileEntity, aBaseCasingIndex); - } - return false; - } - - private boolean updateMasterEnergyHatchList(IMetaTileEntity aMetaTileEntity) { - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { - GT_MetaTileEntity_Hatch aHatch = (GT_MetaTileEntity_Hatch) aMetaTileEntity; - return mAllEnergyHatches.add(aHatch); - } - return false; - } - - - /** - * Pollution Management - */ - - private static Method calculatePollutionReduction = null; - public int calculatePollutionReductionForHatch(GT_MetaTileEntity_Hatch_Muffler i , int g) { - if (calculatePollutionReduction != null) { - try { - return (int) calculatePollutionReduction.invoke(i, g); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - - } - } - return 0; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setLong("mTotalRunTime", this.mTotalRunTime); - aNBT.setBoolean("mVoidExcess", this.mVoidExcess); - super.saveNBTData(aNBT); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); - this.mVoidExcess = aNBT.getBoolean("mVoidExcess"); - super.loadNBTData(aNBT); - } - - - - - - - - - - - - - - /** - * Custom Find Recipe with Debugging - */ - - - public GT_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final boolean aNotUnificated, - final boolean aDontCheckStackSizes, final long aVoltage, final FluidStack[] aFluids, - final ItemStack... aInputs) { - return this.findRecipe(aTileEntity, null, aNotUnificated, aDontCheckStackSizes, aVoltage, aFluids, - (ItemStack) null, aInputs); - } - - public GT_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final boolean aNotUnificated, - final long aVoltage, final FluidStack[] aFluids, final ItemStack... aInputs) { - return this.findRecipe(aTileEntity, null, aNotUnificated, aVoltage, aFluids, (ItemStack) null, aInputs); - } - - public GT_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final GT_Recipe aRecipe, - final boolean aNotUnificated, final boolean aDontCheckStackSizes, final long aVoltage, - final FluidStack[] aFluids, final ItemStack... aInputs) { - return this.findRecipe(aTileEntity, aRecipe, aNotUnificated, aDontCheckStackSizes, aVoltage, aFluids, - (ItemStack) null, aInputs); - } - - public GT_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final GT_Recipe aRecipe, - final boolean aNotUnificated, final long aVoltage, final FluidStack[] aFluids, - final ItemStack... aInputs) { - return this.findRecipe(aTileEntity, aRecipe, aNotUnificated, aVoltage, aFluids, (ItemStack) null, aInputs); - } - - public GT_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final GT_Recipe aRecipe, - final boolean aNotUnificated, final long aVoltage, final FluidStack[] aFluids, - final ItemStack aSpecialSlot, final ItemStack... aInputs) { - return this.findRecipe(aTileEntity, aRecipe, aNotUnificated, true, aVoltage, aFluids, aSpecialSlot, - aInputs); - } - - public GT_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final GT_Recipe aRecipe, - final boolean aNotUnificated, final boolean aDontCheckStackSizes, final long aVoltage, - final FluidStack[] aFluids, final ItemStack aSpecialSlot, ItemStack... aInputs) { - if (this.getRecipeMap().mRecipeList.isEmpty()) { - log("No Recipes in Map to search through."); - return null; - } - GT_Recipe mRecipeResult = null; - try { - if (GregTech_API.sPostloadFinished) { - if (this.getRecipeMap().mMinimalInputFluids > 0) { - if (aFluids == null) { - log("aFluids == null && minFluids > 0"); - return null; - } - int tAmount = 0; - for (final FluidStack aFluid : aFluids) { - if (aFluid != null) { - ++tAmount; - } - } - if (tAmount < this.getRecipeMap().mMinimalInputFluids) { - log("Not enough fluids?"); - return null; - } - } - if (this.getRecipeMap().mMinimalInputItems > 0) { - if (aInputs == null) { - log("No inputs and minItems > 0"); - return null; - } - int tAmount = 0; - for (final ItemStack aInput : aInputs) { - if (aInput != null) { - ++tAmount; - } - } - if (tAmount < this.getRecipeMap().mMinimalInputItems) { - log("Not enough items?"); - return null; - } - } - } - else { - log("Game Not Loaded properly for recipe lookup."); - } - if (aNotUnificated) { - aInputs = GT_OreDictUnificator.getStackArray(true, (Object[]) aInputs); - } - if (aRecipe != null && !aRecipe.mFakeRecipe && aRecipe.mCanBeBuffered - && aRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { - mRecipeResult = (aRecipe.mEnabled/* && aVoltage * this.getRecipeMap().mAmperage >= aRecipe.mEUt*/) ? aRecipe : null; - log("x) Found Recipe? "+(mRecipeResult != null ? "true" : "false")); - if (mRecipeResult != null) { - return mRecipeResult; - } - } - if (mRecipeResult == null && this.getRecipeMap().mUsualInputCount >= 0 && aInputs != null && aInputs.length > 0) { - for (final ItemStack tStack : aInputs) { - if (tStack != null) { - Collection<GT_Recipe> tRecipes = this.getRecipeMap().mRecipeItemMap.get(new GT_ItemStack(tStack)); - if (tRecipes != null) { - for (final GT_Recipe tRecipe : tRecipes) { - if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { - mRecipeResult = (tRecipe.mEnabled/* && aVoltage * this.getRecipeMap().mAmperage >= tRecipe.mEUt*/) - ? tRecipe - : null; - log("1) Found Recipe? "+(mRecipeResult != null ? "true" : "false")); - //return mRecipeResult; - } - } - } - - //TODO - Investigate if this requires to be in it's own block - tRecipes = this.getRecipeMap().mRecipeItemMap - .get(new GT_ItemStack(GT_Utility.copyMetaData(32767L, new Object[]{tStack}))); - if (tRecipes != null) { - for (final GT_Recipe tRecipe : tRecipes) { - if (!tRecipe.mFakeRecipe - && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { - mRecipeResult = (tRecipe.mEnabled /*&& aVoltage * this.getRecipeMap().mAmperage >= tRecipe.mEUt*/) - ? tRecipe - : null; - log("2) Found Recipe? "+(mRecipeResult != null ? "true" : "false")); - //return mRecipeResult; - } - } - } - } - } - } - if (mRecipeResult == null && this.getRecipeMap().mMinimalInputItems == 0 && aFluids != null && aFluids.length > 0) { - for (final FluidStack aFluid2 : aFluids) { - if (aFluid2 != null) { - final Collection<GT_Recipe> tRecipes = this.getRecipeMap().mRecipeFluidMap.get(aFluid2.getFluid()); - if (tRecipes != null) { - for (final GT_Recipe tRecipe : tRecipes) { - if (!tRecipe.mFakeRecipe - && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { - mRecipeResult = (tRecipe.mEnabled/* && aVoltage * this.getRecipeMap().mAmperage >= tRecipe.mEUt*/) - ? tRecipe - : null; - log("3) Found Recipe? "+(mRecipeResult != null ? "true" : "false")); - //return mRecipeResult; - } - } - } - } - } - } - } - catch (Throwable t) { - log("Invalid recipe lookup."); - } - - - if (mRecipeResult == null) { - log("Invalid recipe, Fallback lookup. "+this.getRecipeMap().mRecipeList.size()+" | "+this.getRecipeMap().mNEIName); - if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - try { - return (GT_Recipe) findRecipe08.invoke(getRecipeMap(), aTileEntity, aRecipe, aNotUnificated, aVoltage, aFluids, aSpecialSlot, aInputs); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - return null; - } - } - else { - try { - return (GT_Recipe) findRecipe09.invoke(getRecipeMap(), aTileEntity, aRecipe, aNotUnificated, aDontCheckStackSizes, aVoltage, aFluids, aSpecialSlot, aInputs); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - return null; - } - } - } - else { - return mRecipeResult; - } - - - - - } - - - - - /** - * Custom Tool Handling - */ - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, - float aY, float aZ) { - // Do Things - if (this.getBaseMetaTileEntity().isServerSide()) { - //Logger.INFO("Right Clicked Controller."); - ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); - if (tCurrentItem != null) { - //Logger.INFO("Holding Item."); - if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { - //Logger.INFO("Is GT_MetaGenerated_Tool."); - int[] aOreID = OreDictionary.getOreIDs(tCurrentItem); - for (int id : aOreID) { - // Plunger - if (OreDictionary.getOreName(id).equals("craftingToolPlunger")) { - //Logger.INFO("Is Plunger."); - return onPlungerRightClick(aPlayer, aSide, aX, aY, aZ); - } - } - } - } - } - //Do Super - boolean aSuper = super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); - return aSuper; - } - - public boolean onPlungerRightClick(EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { - int aHatchIndex = 0; - PlayerUtils.messagePlayer(aPlayer, "Trying to clear "+mOutputHatches.size()+" output hatches."); - for (GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { - if (hatch.mFluid != null) { - PlayerUtils.messagePlayer(aPlayer, "Clearing "+hatch.mFluid.amount+"L of "+hatch.mFluid.getLocalizedName()+" from hatch "+aHatchIndex+"."); - hatch.mFluid = null; - } - aHatchIndex++; - } - return aHatchIndex > 0; - } - - @Override - public boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - boolean tSuper = super.onSolderingToolRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); - if (aPlayer.isSneaking()) - return tSuper; - mVoidExcess = !mVoidExcess; - aPlayer.addChatMessage(new ChatComponentTranslation(mVoidExcess ? "interaction.voidexcess.enabled" : "interaction.voidexcess.disabled")); - return true; - } - - public boolean isValidBlockForStructure(IGregTechTileEntity aBaseMetaTileEntity, int aCasingID, boolean canBeHatch, - Block aFoundBlock, int aFoundMeta, Block aExpectedBlock, int aExpectedMeta) { - boolean isHatch = false; - if (aBaseMetaTileEntity != null) { - - // Unsure why this check exists? - /*if (aCasingID < 64) { - aCasingID = TAE.GTPP_INDEX(aCasingID); - }*/ - - isHatch = this.addToMachineList(aBaseMetaTileEntity, aCasingID); - if (isHatch) { - return true; - } - else { - int aMetaTileID = aBaseMetaTileEntity.getMetaTileID(); - //Found a controller - if (aMetaTileID >= 750 && aMetaTileID < 1000 && aFoundBlock == GregTech_API.sBlockMachines) { - return true; - } - //Vanilla Hatches/Busses - else if (aMetaTileID >= 10 && aMetaTileID <= 99 && aFoundBlock == GregTech_API.sBlockMachines) { - return true; - } - //Adv Mufflers - else if (aMetaTileID >= 30001 && aMetaTileID <= 30009 && aFoundBlock == GregTech_API.sBlockMachines) { - return true; - } - //Control Core, Super IO - else if (aMetaTileID >= 30020 && aMetaTileID <= 30040 && aFoundBlock == GregTech_API.sBlockMachines) { - return true; - } - //Auto maint - else if (aMetaTileID == 111 && aFoundBlock == GregTech_API.sBlockMachines) { - return true; - } - //Data Ports - else if ((aMetaTileID == 131 || aMetaTileID == 132) && aFoundBlock == GregTech_API.sBlockMachines) { - return true; - } - else { - log("Found meta Tile: "+aMetaTileID); - } - } - } - if (!isHatch) { - if (aFoundBlock == aExpectedBlock && aFoundMeta == aExpectedMeta) { - return true; - } - else if (aFoundBlock != aExpectedBlock) { - if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { - log("A1 - Found: "+aFoundBlock.getLocalizedName()+":"+aFoundMeta+", Expected: "+aExpectedBlock.getLocalizedName()+":"+aExpectedMeta); - //log("Loc: "+(new BlockPos(aBaseMetaTileEntity).getLocationString())); - } - return false; - } - else if (aFoundMeta != aExpectedMeta) { - log("A2"); - return false; - } - - } - log("A3"); - return false; - } - - @Override - public void onServerStart() { - super.onServerStart(); - tryTickWaitTimerDown(); - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - tryTickWaitTimerDown(); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - tryTickWaitTimerDown(); - } - - @Override - public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { - super.onCreated(aStack, aWorld, aPlayer); - tryTickWaitTimerDown(); - } - - private final void tryTickWaitTimerDown() { - /*if (mStartUpCheck > 10) { - mStartUpCheck = 10; - }*/ - } - - //Only support to use meta to tier - - /** - * accept meta [0, maxMeta) - * @param maxMeta exclusive - */ - public static <T> IStructureElement<T> addTieredBlock(Block aBlock, BiConsumer<T, Integer> aSetTheFuckingMeta, Function<T, Integer> aGetTheFuckingMeta, int maxMeta) { - return addTieredBlock(aBlock, (t, i) -> { - aSetTheFuckingMeta.accept(t, i); - return true; - }, aGetTheFuckingMeta, 0, maxMeta - ); - } - - /** - * - * @param minMeta inclusive - * @param maxMeta exclusive - */ - public static <T> IStructureElement<T> addTieredBlock(Block aBlock, BiConsumer<T, Integer> aSetTheFuckingMeta, Function<T, Integer> aGetTheFuckingMeta, int minMeta, int maxMeta) { - return addTieredBlock(aBlock, (t, i) -> { - aSetTheFuckingMeta.accept(t, i); - return true; - }, aGetTheFuckingMeta, minMeta, maxMeta - ); - } - - /** - * - * @param minMeta inclusive - * @param maxMeta exclusive - */ - public static <T> IStructureElement<T> addTieredBlock(Block aBlock, BiPredicate<T, Integer> aSetTheFuckingMeta, Function<T, Integer> aGetTheFuckingMeta, int minMeta, int maxMeta) { - - return new IStructureElement<T>() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block tBlock = world.getBlock(x, y, z); - if (aBlock == tBlock) { - Integer currentMeta = aGetTheFuckingMeta.apply(t); - int newMeta = tBlock.getDamageValue(world, x, y, z) + 1; - if (newMeta > maxMeta || newMeta < minMeta + 1) return false; - if (currentMeta == 0) { - return aSetTheFuckingMeta.test(t, newMeta); - } else { - return currentMeta == newMeta; - } - } - return false; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, aBlock, getMeta(trigger)); - return true; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return world.setBlock(x, y, z, aBlock, getMeta(trigger), 3); - } - - private int getMeta(ItemStack trigger) { - int meta = trigger.stackSize; - if (meta <= 0) meta = minMeta; - if (meta + minMeta >= maxMeta) meta = maxMeta - 1 - minMeta; - return meta + minMeta; - } - - @Override - public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, IItemSource s, EntityPlayerMP actor, Consumer<IChatComponent> chatter) { - if (world.getBlock(x, y, z) == aBlock) { - if (world.getBlockMetadata(x, y, z) == getMeta(trigger)) { - return PlaceResult.SKIP; - } - return PlaceResult.REJECT; - } - return StructureUtility.survivalPlaceBlock(aBlock, getMeta(trigger), world, x, y, z, s, actor, chatter); - } - }; - } - - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - if (aSide == aFacing) { - if (aActive) - return new ITexture[]{getCasingTexture(), - TextureFactory.builder().addIcon(getActiveOverlay()).extFacing().build()}; - return new ITexture[]{getCasingTexture(), - TextureFactory.builder().addIcon(getInactiveOverlay()).extFacing().build()}; - } - return new ITexture[]{getCasingTexture()}; - } - - protected IIconContainer getActiveOverlay() { - return null; - } - - protected IIconContainer getInactiveOverlay() { - return null; - } - - protected ITexture getCasingTexture() { - return Textures.BlockIcons.getCasingTextureForId(getCasingTextureId()); - } - - protected int getCasingTextureId() { - return 0; - } - - public enum GTPPHatchElement implements IHatchElement<GregtechMeta_MultiBlockBase<?>> { - AirIntake(GregtechMeta_MultiBlockBase::addAirIntakeToMachineList, GT_MetaTileEntity_Hatch_AirIntake.class) { - @Override - public long count(GregtechMeta_MultiBlockBase<?> t) { - return t.mAirIntakes.size(); - } - }, - ControlCore(GregtechMeta_MultiBlockBase::addControlCoreToMachineList, GT_MetaTileEntity_Hatch_ControlCore.class) { - @Override - public long count(GregtechMeta_MultiBlockBase<?> t) { - return t.mControlCoreBus.size(); - } - }, - TTDynamo(GregtechMeta_MultiBlockBase::addMultiAmpDynamoToMachineList, "com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti") { - @Override - public long count(GregtechMeta_MultiBlockBase<?> t) { - return t.mTecTechDynamoHatches.size(); - } - }, - TTEnergy(GregtechMeta_MultiBlockBase::addMultiAmpEnergyToMachineList, "com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti") { - @Override - public long count(GregtechMeta_MultiBlockBase<?> t) { - return t.mTecTechEnergyHatches.size(); - } - }, - ; - - @SuppressWarnings("unchecked") - private static <T> Class<T> retype(Class<?> clazz) { - return (Class<T>) clazz; - } - - private final List<? extends Class<? extends IMetaTileEntity>> mMteClasses; - private final IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> mAdder; - - @SafeVarargs - GTPPHatchElement(IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> aAdder, Class<? extends IMetaTileEntity>... aMteClasses) { - this.mMteClasses = Arrays.asList(aMteClasses); - this.mAdder = aAdder; - } - - GTPPHatchElement(IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> aAdder, String... aClassNames) { - this.mMteClasses = Arrays.stream(aClassNames) - .map(ReflectionUtils::getClass) - .filter(Objects::nonNull) - .<Class<? extends IMetaTileEntity>>map(GTPPHatchElement::retype) - .collect(Collectors.toList()); - this.mAdder = aAdder; - } - - @Override - public List<? extends Class<? extends IMetaTileEntity>> mteClasses() { - return mMteClasses; - } - - @Override - public IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> adder() { - return mAdder; - } - } + public void updateSlots() { + for (final GT_MetaTileEntity_Hatch_InputBattery tHatch : this.mChargeHatches) { + if (isValidMetaTileEntity(tHatch)) { + tHatch.updateSlots(); + } + } + for (final GT_MetaTileEntity_Hatch_OutputBattery tHatch : this.mDischargeHatches) { + if (isValidMetaTileEntity(tHatch)) { + tHatch.updateSlots(); + } + } + super.updateSlots(); + } + + public boolean isToolCreative(ItemStack mStack) { + Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(mStack); + Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(mStack); + if (t1 == Materials._NULL && t2 == Materials._NULL) { + return true; + } + return false; + } + + /** + * Causes a Random Maint. Issue. + * @return {@link boolean} - Returns whether or not an issue was caused, should always be true. + */ + public boolean causeMaintenanceIssue() { + boolean b = false; + switch (this.getBaseMetaTileEntity().getRandomNumber(6)) { + case 0: { + this.mWrench = false; + b = true; + break; + } + case 1: { + this.mScrewdriver = false; + b = true; + break; + } + case 2: { + this.mSoftHammer = false; + b = true; + break; + } + case 3: { + this.mHardHammer = false; + b = true; + break; + } + case 4: { + this.mSolderingTool = false; + b = true; + break; + } + case 5: { + this.mCrowbar = false; + b = true; + break; + } + } + return b; + } + + public void fixAllMaintenanceIssue() { + this.mCrowbar = true; + this.mWrench = true; + this.mHardHammer = true; + this.mSoftHammer = true; + this.mSolderingTool = true; + this.mScrewdriver = true; + } + + public boolean checkHatch() { + return mMaintenanceHatches.size() <= 1 + && (this.getPollutionPerSecond(null) > 0 ? !mMufflerHatches.isEmpty() : true); + } + + public <E> boolean addToMachineListInternal( + ArrayList<E> aList, final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + return addToMachineListInternal(aList, getMetaTileEntity(aTileEntity), aBaseCasingIndex); + } + + public <E> boolean addToMachineListInternal( + ArrayList<E> aList, final IMetaTileEntity aTileEntity, final int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } + + // Check type + /* + * Class <?> aHatchType = ReflectionUtils.getTypeOfGenericObject(aList); if + * (!aHatchType.isInstance(aTileEntity)) { return false; } + */ + + // Try setRecipeMap + + try { + if (aTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + resetRecipeMapForHatch((GT_MetaTileEntity_Hatch) aTileEntity, getRecipeMap()); + } + if (aTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + resetRecipeMapForHatch((GT_MetaTileEntity_Hatch) aTileEntity, getRecipeMap()); + } + } catch (Throwable t) { + t.printStackTrace(); + } + + if (aList.isEmpty()) { + if (aTileEntity instanceof GT_MetaTileEntity_Hatch) { + if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { + log("Adding " + aTileEntity.getInventoryName() + " at " + + new BlockPos(aTileEntity.getBaseMetaTileEntity()).getLocationString()); + } + updateTexture(aTileEntity, aBaseCasingIndex); + return aList.add((E) aTileEntity); + } + } else { + IGregTechTileEntity aCur = aTileEntity.getBaseMetaTileEntity(); + if (aList.contains(aTileEntity)) { + log("Found Duplicate " + aTileEntity.getInventoryName() + " @ " + + new BlockPos(aCur).getLocationString()); + return false; + } + BlockPos aCurPos = new BlockPos(aCur); + boolean aExists = false; + for (E m : aList) { + IGregTechTileEntity b = ((IMetaTileEntity) m).getBaseMetaTileEntity(); + if (b != null) { + BlockPos aPos = new BlockPos(b); + if (aPos != null) { + if (aCurPos.equals(aPos)) { + if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { + log("Found Duplicate " + b.getInventoryName() + " at " + aPos.getLocationString()); + } + return false; + } + } + } + } + if (aTileEntity instanceof GT_MetaTileEntity_Hatch) { + if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { + log("Adding " + aCur.getInventoryName() + " at " + aCurPos.getLocationString()); + } + updateTexture(aTileEntity, aBaseCasingIndex); + return aList.add((E) aTileEntity); + } + } + return false; + } + + public int getControlCoreTier() { + + // Always return best tier if config is off. + /*boolean aCoresConfig = gtPlusPlus.core.lib.CORE.ConfigSwitches.requireControlCores; + if (!aCoresConfig) { + return 10; + }*/ + + if (mControlCoreBus.isEmpty()) { + log("No Control Core Modules Found."); + return 0; + } + GT_MetaTileEntity_Hatch_ControlCore i = getControlCoreBus(); + if (i != null) { + ItemStack x = i.mInventory[0]; + if (x != null) { + return x.getItemDamage(); + } + } + log("Control Core Module was null."); + return 0; + } + + public GT_MetaTileEntity_Hatch_ControlCore getControlCoreBus() { + if (this.mControlCoreBus == null || this.mControlCoreBus.isEmpty()) { + return null; + } + GT_MetaTileEntity_Hatch_ControlCore x = this.mControlCoreBus.get(0); + if (x != null) { + log("getControlCore(ok)"); + return x; + } + log("getControlCore(bad)"); + return null; + } + + // mControlCoreBus + public boolean addControlCoreToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + if (!mControlCoreBus.isEmpty()) { + log("Tried to add a secondary control core module."); + return false; + } + GT_MetaTileEntity_Hatch_ControlCore Module = + (GT_MetaTileEntity_Hatch_ControlCore) getMetaTileEntity(aTileEntity); + if (Module != null) { + if (Module.setOwner(aTileEntity)) { + log("Adding control core module."); + return addToMachineListInternal(mControlCoreBus, Module, aBaseCasingIndex); + } + } + return false; + } + + private IMetaTileEntity getMetaTileEntity(final IGregTechTileEntity aTileEntity) { + if (aTileEntity == null) { + return null; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + return aMetaTileEntity; + } + + @Override + public boolean addToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + return addToMachineList(getMetaTileEntity(aTileEntity), aBaseCasingIndex); + } + + public boolean addToMachineList(final IMetaTileEntity aMetaTileEntity, final int aBaseCasingIndex) { + if (aMetaTileEntity == null) { + return false; + } + + // Use this to determine the correct value, then update the hatch texture after. + boolean aDidAdd = false; + + // Handle Custom Hatches + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_ControlCore) { + log("Found GT_MetaTileEntity_Hatch_ControlCore"); + if (!mControlCoreBus.isEmpty()) { + log("Tried to add a secondary control core module."); + return false; + } + aDidAdd = addToMachineListInternal(this.mControlCoreBus, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBattery) { + log("Found GT_MetaTileEntity_Hatch_InputBattery"); + aDidAdd = addToMachineListInternal(mChargeHatches, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBattery) { + log("Found GT_MetaTileEntity_Hatch_OutputBattery"); + aDidAdd = addToMachineListInternal(mDischargeHatches, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) { + aDidAdd = addToMachineListInternal(mAirIntakes, aMetaTileEntity, aBaseCasingIndex) + && addToMachineListInternal(mInputHatches, aMetaTileEntity, aBaseCasingIndex); + } + + // Handle TT Multi-A Energy Hatches + else if (LoadedMods.TecTech && isThisHatchMultiEnergy(aMetaTileEntity)) { + log("Found isThisHatchMultiEnergy"); + aDidAdd = addToMachineListInternal(mTecTechEnergyHatches, aMetaTileEntity, aBaseCasingIndex); + updateMasterEnergyHatchList(aMetaTileEntity); + } + + // Handle TT Multi-A Dynamos + else if (LoadedMods.TecTech && isThisHatchMultiDynamo(aMetaTileEntity)) { + log("Found isThisHatchMultiDynamo"); + aDidAdd = addToMachineListInternal(mTecTechDynamoHatches, aMetaTileEntity, aBaseCasingIndex); + updateMasterDynamoHatchList(aMetaTileEntity); + } + + // Handle Fluid Hatches using seperate logic + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) + aDidAdd = addToMachineListInternal(mInputHatches, aMetaTileEntity, aBaseCasingIndex); + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) + aDidAdd = addToMachineListInternal(mOutputHatches, aMetaTileEntity, aBaseCasingIndex); + + // Process Remaining hatches using Vanilla GT Logic + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) + aDidAdd = addToMachineListInternal(mInputBusses, aMetaTileEntity, aBaseCasingIndex); + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) + aDidAdd = addToMachineListInternal(mOutputBusses, aMetaTileEntity, aBaseCasingIndex); + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + aDidAdd = addToMachineListInternal(mEnergyHatches, aMetaTileEntity, aBaseCasingIndex); + updateMasterEnergyHatchList(aMetaTileEntity); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { + aDidAdd = addToMachineListInternal(mDynamoHatches, aMetaTileEntity, aBaseCasingIndex); + updateMasterDynamoHatchList(aMetaTileEntity); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) + aDidAdd = addToMachineListInternal(mMaintenanceHatches, aMetaTileEntity, aBaseCasingIndex); + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) + aDidAdd = addToMachineListInternal(mMufflerHatches, aMetaTileEntity, aBaseCasingIndex); + + // return super.addToMachineList(aTileEntity, aBaseCasingIndex); + return aDidAdd; + } + + @Override + public boolean addMaintenanceToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + @Override + public boolean addMufflerToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + @Override + public boolean addInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + @Override + public boolean addOutputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean addAirIntakeToMachineList(final IGregTechTileEntity aMetaTileEntity, final int aBaseCasingIndex) { + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean addFluidInputToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + return addFluidInputToMachineList(getMetaTileEntity(aTileEntity), aBaseCasingIndex); + } + + public boolean addFluidInputToMachineList(final IMetaTileEntity aMetaTileEntity, final int aBaseCasingIndex) { + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean clearRecipeMapForAllInputHatches() { + return resetRecipeMapForAllInputHatches(null); + } + + public boolean resetRecipeMapForAllInputHatches() { + return resetRecipeMapForAllInputHatches(this.getRecipeMap()); + } + + public boolean resetRecipeMapForAllInputHatches(GT_Recipe_Map aMap) { + int cleared = 0; + for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { + if (resetRecipeMapForHatch(g, aMap)) { + cleared++; + } + } + for (GT_MetaTileEntity_Hatch_InputBus g : this.mInputBusses) { + if (resetRecipeMapForHatch(g, aMap)) { + cleared++; + } + } + return cleared > 0; + } + + public boolean resetRecipeMapForHatch(IGregTechTileEntity aTileEntity, GT_Recipe_Map aMap) { + try { + final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { + return resetRecipeMapForHatch((GT_MetaTileEntity_Hatch) aMetaTileEntity, aMap); + } else { + return false; + } + } catch (Throwable t) { + t.printStackTrace(); + return false; + } + } + + public boolean resetRecipeMapForHatch(GT_MetaTileEntity_Hatch aTileEntity, GT_Recipe_Map aMap) { + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = null; + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap; + if (aMap != null && aMap.mNEIName != null) { + log("Remapped Input Hatch to " + aMap.mNEIName + "."); + } else { + log("Cleared Input Hatch."); + } + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = null; + ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = aMap; + if (aMap != null && aMap.mNEIName != null) { + log("Remapped Input Bus to " + aMap.mNEIName + "."); + } else { + log("Cleared Input Bus."); + } + } else { + ((GT_MetaTileEntity_Hatch_Steam_BusInput) aMetaTileEntity).mRecipeMap = null; + ((GT_MetaTileEntity_Hatch_Steam_BusInput) aMetaTileEntity).mRecipeMap = aMap; + if (aMap != null && aMap.mNEIName != null) { + log("Remapped Input Bus to " + aMap.mNEIName + "."); + } else { + log("Cleared Input Bus."); + } + } + return true; + } else { + return false; + } + } + + @Override + public final void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + clearRecipeMapForAllInputHatches(); + onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ); + resetRecipeMapForAllInputHatches(); + } + + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {} + + /** + * Enable Texture Casing Support if found in GT 5.09 + */ + public boolean updateTexture(final IGregTechTileEntity aTileEntity, int aCasingID) { + return updateTexture(getMetaTileEntity(aTileEntity), aCasingID); + } + + /** + * Enable Texture Casing Support if found in GT 5.09 + */ + @SuppressWarnings("deprecation") + public boolean updateTexture(final IMetaTileEntity aTileEntity, int aCasingID) { + try { // gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch.updateTexture(int) + + final IMetaTileEntity aMetaTileEntity = aTileEntity; + if (aMetaTileEntity == null) { + return false; + } + Method mProper = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); + if (mProper != null) { + if (GT_MetaTileEntity_Hatch.class.isInstance(aMetaTileEntity)) { + mProper.setAccessible(true); + mProper.invoke(aMetaTileEntity, aCasingID); + // log("Good Method Call for updateTexture."); + return true; + } + } else { + log("Bad Method Call for updateTexture."); + if (GT_MetaTileEntity_Hatch.class.isInstance(aMetaTileEntity)) { + if (aCasingID <= Byte.MAX_VALUE) { + ((GT_MetaTileEntity_Hatch) aTileEntity).mMachineBlock = (byte) aCasingID; + log( + "Good Method Call for updateTexture. Used fallback method of setting mMachineBlock as casing id was <= 128."); + return true; + } else { + log("updateTexture returning false. 1.2"); + } + } else { + log("updateTexture returning false. 1.3"); + } + } + log("updateTexture returning false. 1"); + return false; + } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + log("updateTexture returning false."); + log("updateTexture returning false. 2"); + e.printStackTrace(); + return false; + } + } + + /** + * TecTech Support + */ + + /** + * This is the array Used to Store the Tectech Multi-Amp Dynamo hatches. + */ + public ArrayList<GT_MetaTileEntity_Hatch> mTecTechDynamoHatches = new ArrayList<GT_MetaTileEntity_Hatch>(); + + /** + * This is the array Used to Store the Tectech Multi-Amp Energy hatches. + */ + public ArrayList<GT_MetaTileEntity_Hatch> mTecTechEnergyHatches = new ArrayList<GT_MetaTileEntity_Hatch>(); + + /** + * TecTech Multi-Amp Dynamo Support + * @param aTileEntity - The Dynamo Hatch + * @param aBaseCasingIndex - Casing Texture + * @return + */ + public boolean addMultiAmpDynamoToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity == null) { + return false; + } + if (isThisHatchMultiDynamo(aTileEntity)) { + return addToMachineListInternal(mTecTechDynamoHatches, aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean isThisHatchMultiDynamo(IGregTechTileEntity aTileEntity) { + return isThisHatchMultiDynamo(getMetaTileEntity(aTileEntity)); + } + + public boolean isThisHatchMultiDynamo(IMetaTileEntity aMetaTileEntity) { + Class<?> mDynamoClass; + mDynamoClass = ReflectionUtils.getClass( + "com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti"); + if (mDynamoClass != null) { + if (mDynamoClass.isInstance(aMetaTileEntity)) { + return true; + } + } + return false; + } + + @Override + public boolean addDynamoToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo || isThisHatchMultiDynamo(aMetaTileEntity)) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + private boolean updateMasterDynamoHatchList(IMetaTileEntity aMetaTileEntity) { + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { + GT_MetaTileEntity_Hatch aHatch = (GT_MetaTileEntity_Hatch) aMetaTileEntity; + return mAllDynamoHatches.add(aHatch); + } + return false; + } + + /** + * TecTech Multi-Amp Energy Hatch Support + * @param aTileEntity - The Energy Hatch + * @param aBaseCasingIndex - Casing Texture + * @return + */ + public boolean addMultiAmpEnergyToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity == null) { + return false; + } + if (isThisHatchMultiEnergy(aMetaTileEntity)) { + return addToMachineListInternal(mTecTechEnergyHatches, aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean isThisHatchMultiEnergy(IGregTechTileEntity aTileEntity) { + return isThisHatchMultiEnergy(getMetaTileEntity(aTileEntity)); + } + + public boolean isThisHatchMultiEnergy(IMetaTileEntity aMetaTileEntity) { + Class<?> mDynamoClass; + mDynamoClass = ReflectionUtils.getClass( + "com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti"); + if (mDynamoClass != null) { + if (mDynamoClass.isInstance(aMetaTileEntity)) { + return true; + } + } + return false; + } + + @Override + public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy || isThisHatchMultiEnergy(aMetaTileEntity)) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + private boolean updateMasterEnergyHatchList(IMetaTileEntity aMetaTileEntity) { + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { + GT_MetaTileEntity_Hatch aHatch = (GT_MetaTileEntity_Hatch) aMetaTileEntity; + return mAllEnergyHatches.add(aHatch); + } + return false; + } + + /** + * Pollution Management + */ + private static Method calculatePollutionReduction = null; + + public int calculatePollutionReductionForHatch(GT_MetaTileEntity_Hatch_Muffler i, int g) { + if (calculatePollutionReduction != null) { + try { + return (int) calculatePollutionReduction.invoke(i, g); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + + } + } + return 0; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setLong("mTotalRunTime", this.mTotalRunTime); + aNBT.setBoolean("mVoidExcess", this.mVoidExcess); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); + this.mVoidExcess = aNBT.getBoolean("mVoidExcess"); + super.loadNBTData(aNBT); + } + + /** + * Custom Find Recipe with Debugging + */ + public GT_Recipe findRecipe( + final IHasWorldObjectAndCoords aTileEntity, + final boolean aNotUnificated, + final boolean aDontCheckStackSizes, + final long aVoltage, + final FluidStack[] aFluids, + final ItemStack... aInputs) { + return this.findRecipe( + aTileEntity, null, aNotUnificated, aDontCheckStackSizes, aVoltage, aFluids, (ItemStack) null, aInputs); + } + + public GT_Recipe findRecipe( + final IHasWorldObjectAndCoords aTileEntity, + final boolean aNotUnificated, + final long aVoltage, + final FluidStack[] aFluids, + final ItemStack... aInputs) { + return this.findRecipe(aTileEntity, null, aNotUnificated, aVoltage, aFluids, (ItemStack) null, aInputs); + } + + public GT_Recipe findRecipe( + final IHasWorldObjectAndCoords aTileEntity, + final GT_Recipe aRecipe, + final boolean aNotUnificated, + final boolean aDontCheckStackSizes, + final long aVoltage, + final FluidStack[] aFluids, + final ItemStack... aInputs) { + return this.findRecipe( + aTileEntity, + aRecipe, + aNotUnificated, + aDontCheckStackSizes, + aVoltage, + aFluids, + (ItemStack) null, + aInputs); + } + + public GT_Recipe findRecipe( + final IHasWorldObjectAndCoords aTileEntity, + final GT_Recipe aRecipe, + final boolean aNotUnificated, + final long aVoltage, + final FluidStack[] aFluids, + final ItemStack... aInputs) { + return this.findRecipe(aTileEntity, aRecipe, aNotUnificated, aVoltage, aFluids, (ItemStack) null, aInputs); + } + + public GT_Recipe findRecipe( + final IHasWorldObjectAndCoords aTileEntity, + final GT_Recipe aRecipe, + final boolean aNotUnificated, + final long aVoltage, + final FluidStack[] aFluids, + final ItemStack aSpecialSlot, + final ItemStack... aInputs) { + return this.findRecipe(aTileEntity, aRecipe, aNotUnificated, true, aVoltage, aFluids, aSpecialSlot, aInputs); + } + + public GT_Recipe findRecipe( + final IHasWorldObjectAndCoords aTileEntity, + final GT_Recipe aRecipe, + final boolean aNotUnificated, + final boolean aDontCheckStackSizes, + final long aVoltage, + final FluidStack[] aFluids, + final ItemStack aSpecialSlot, + ItemStack... aInputs) { + if (this.getRecipeMap().mRecipeList.isEmpty()) { + log("No Recipes in Map to search through."); + return null; + } + GT_Recipe mRecipeResult = null; + try { + if (GregTech_API.sPostloadFinished) { + if (this.getRecipeMap().mMinimalInputFluids > 0) { + if (aFluids == null) { + log("aFluids == null && minFluids > 0"); + return null; + } + int tAmount = 0; + for (final FluidStack aFluid : aFluids) { + if (aFluid != null) { + ++tAmount; + } + } + if (tAmount < this.getRecipeMap().mMinimalInputFluids) { + log("Not enough fluids?"); + return null; + } + } + if (this.getRecipeMap().mMinimalInputItems > 0) { + if (aInputs == null) { + log("No inputs and minItems > 0"); + return null; + } + int tAmount = 0; + for (final ItemStack aInput : aInputs) { + if (aInput != null) { + ++tAmount; + } + } + if (tAmount < this.getRecipeMap().mMinimalInputItems) { + log("Not enough items?"); + return null; + } + } + } else { + log("Game Not Loaded properly for recipe lookup."); + } + if (aNotUnificated) { + aInputs = GT_OreDictUnificator.getStackArray(true, (Object[]) aInputs); + } + if (aRecipe != null + && !aRecipe.mFakeRecipe + && aRecipe.mCanBeBuffered + && aRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { + mRecipeResult = (aRecipe.mEnabled /* && aVoltage * this.getRecipeMap().mAmperage >= aRecipe.mEUt*/) + ? aRecipe + : null; + log("x) Found Recipe? " + (mRecipeResult != null ? "true" : "false")); + if (mRecipeResult != null) { + return mRecipeResult; + } + } + if (mRecipeResult == null + && this.getRecipeMap().mUsualInputCount >= 0 + && aInputs != null + && aInputs.length > 0) { + for (final ItemStack tStack : aInputs) { + if (tStack != null) { + Collection<GT_Recipe> tRecipes = + this.getRecipeMap().mRecipeItemMap.get(new GT_ItemStack(tStack)); + if (tRecipes != null) { + for (final GT_Recipe tRecipe : tRecipes) { + if (!tRecipe.mFakeRecipe + && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { + mRecipeResult = + (tRecipe.mEnabled /* && aVoltage * this.getRecipeMap().mAmperage >= tRecipe.mEUt*/) + ? tRecipe + : null; + log("1) Found Recipe? " + (mRecipeResult != null ? "true" : "false")); + // return mRecipeResult; + } + } + } + + // TODO - Investigate if this requires to be in it's own block + tRecipes = this.getRecipeMap() + .mRecipeItemMap + .get(new GT_ItemStack(GT_Utility.copyMetaData(32767L, new Object[] {tStack}))); + if (tRecipes != null) { + for (final GT_Recipe tRecipe : tRecipes) { + if (!tRecipe.mFakeRecipe + && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { + mRecipeResult = + (tRecipe.mEnabled /*&& aVoltage * this.getRecipeMap().mAmperage >= tRecipe.mEUt*/) + ? tRecipe + : null; + log("2) Found Recipe? " + (mRecipeResult != null ? "true" : "false")); + // return mRecipeResult; + } + } + } + } + } + } + if (mRecipeResult == null + && this.getRecipeMap().mMinimalInputItems == 0 + && aFluids != null + && aFluids.length > 0) { + for (final FluidStack aFluid2 : aFluids) { + if (aFluid2 != null) { + final Collection<GT_Recipe> tRecipes = + this.getRecipeMap().mRecipeFluidMap.get(aFluid2.getFluid()); + if (tRecipes != null) { + for (final GT_Recipe tRecipe : tRecipes) { + if (!tRecipe.mFakeRecipe + && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) { + mRecipeResult = + (tRecipe.mEnabled /* && aVoltage * this.getRecipeMap().mAmperage >= tRecipe.mEUt*/) + ? tRecipe + : null; + log("3) Found Recipe? " + (mRecipeResult != null ? "true" : "false")); + // return mRecipeResult; + } + } + } + } + } + } + } catch (Throwable t) { + log("Invalid recipe lookup."); + } + + if (mRecipeResult == null) { + log("Invalid recipe, Fallback lookup. " + + this.getRecipeMap().mRecipeList.size() + " | " + this.getRecipeMap().mNEIName); + if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + try { + return (GT_Recipe) findRecipe08.invoke( + getRecipeMap(), + aTileEntity, + aRecipe, + aNotUnificated, + aVoltage, + aFluids, + aSpecialSlot, + aInputs); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + return null; + } + } else { + try { + return (GT_Recipe) findRecipe09.invoke( + getRecipeMap(), + aTileEntity, + aRecipe, + aNotUnificated, + aDontCheckStackSizes, + aVoltage, + aFluids, + aSpecialSlot, + aInputs); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + return null; + } + } + } else { + return mRecipeResult; + } + } + + /** + * Custom Tool Handling + */ + @Override + public boolean onRightclick( + IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + // Do Things + if (this.getBaseMetaTileEntity().isServerSide()) { + // Logger.INFO("Right Clicked Controller."); + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem != null) { + // Logger.INFO("Holding Item."); + if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { + // Logger.INFO("Is GT_MetaGenerated_Tool."); + int[] aOreID = OreDictionary.getOreIDs(tCurrentItem); + for (int id : aOreID) { + // Plunger + if (OreDictionary.getOreName(id).equals("craftingToolPlunger")) { + // Logger.INFO("Is Plunger."); + return onPlungerRightClick(aPlayer, aSide, aX, aY, aZ); + } + } + } + } + } + // Do Super + boolean aSuper = super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + return aSuper; + } + + public boolean onPlungerRightClick(EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + int aHatchIndex = 0; + PlayerUtils.messagePlayer(aPlayer, "Trying to clear " + mOutputHatches.size() + " output hatches."); + for (GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { + if (hatch.mFluid != null) { + PlayerUtils.messagePlayer( + aPlayer, + "Clearing " + hatch.mFluid.amount + "L of " + hatch.mFluid.getLocalizedName() + " from hatch " + + aHatchIndex + "."); + hatch.mFluid = null; + } + aHatchIndex++; + } + return aHatchIndex > 0; + } + + @Override + public boolean onSolderingToolRightClick( + byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + boolean tSuper = super.onSolderingToolRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); + if (aPlayer.isSneaking()) return tSuper; + mVoidExcess = !mVoidExcess; + aPlayer.addChatMessage(new ChatComponentTranslation( + mVoidExcess ? "interaction.voidexcess.enabled" : "interaction.voidexcess.disabled")); + return true; + } + + public boolean isValidBlockForStructure( + IGregTechTileEntity aBaseMetaTileEntity, + int aCasingID, + boolean canBeHatch, + Block aFoundBlock, + int aFoundMeta, + Block aExpectedBlock, + int aExpectedMeta) { + boolean isHatch = false; + if (aBaseMetaTileEntity != null) { + + // Unsure why this check exists? + /*if (aCasingID < 64) { + aCasingID = TAE.GTPP_INDEX(aCasingID); + }*/ + + isHatch = this.addToMachineList(aBaseMetaTileEntity, aCasingID); + if (isHatch) { + return true; + } else { + int aMetaTileID = aBaseMetaTileEntity.getMetaTileID(); + // Found a controller + if (aMetaTileID >= 750 && aMetaTileID < 1000 && aFoundBlock == GregTech_API.sBlockMachines) { + return true; + } + // Vanilla Hatches/Busses + else if (aMetaTileID >= 10 && aMetaTileID <= 99 && aFoundBlock == GregTech_API.sBlockMachines) { + return true; + } + // Adv Mufflers + else if (aMetaTileID >= 30001 && aMetaTileID <= 30009 && aFoundBlock == GregTech_API.sBlockMachines) { + return true; + } + // Control Core, Super IO + else if (aMetaTileID >= 30020 && aMetaTileID <= 30040 && aFoundBlock == GregTech_API.sBlockMachines) { + return true; + } + // Auto maint + else if (aMetaTileID == 111 && aFoundBlock == GregTech_API.sBlockMachines) { + return true; + } + // Data Ports + else if ((aMetaTileID == 131 || aMetaTileID == 132) && aFoundBlock == GregTech_API.sBlockMachines) { + return true; + } else { + log("Found meta Tile: " + aMetaTileID); + } + } + } + if (!isHatch) { + if (aFoundBlock == aExpectedBlock && aFoundMeta == aExpectedMeta) { + return true; + } else if (aFoundBlock != aExpectedBlock) { + if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { + log("A1 - Found: " + aFoundBlock.getLocalizedName() + ":" + aFoundMeta + ", Expected: " + + aExpectedBlock.getLocalizedName() + ":" + aExpectedMeta); + // log("Loc: "+(new BlockPos(aBaseMetaTileEntity).getLocationString())); + } + return false; + } else if (aFoundMeta != aExpectedMeta) { + log("A2"); + return false; + } + } + log("A3"); + return false; + } + + @Override + public void onServerStart() { + super.onServerStart(); + tryTickWaitTimerDown(); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + tryTickWaitTimerDown(); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + tryTickWaitTimerDown(); + } + + @Override + public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + super.onCreated(aStack, aWorld, aPlayer); + tryTickWaitTimerDown(); + } + + private final void tryTickWaitTimerDown() { + /*if (mStartUpCheck > 10) { + mStartUpCheck = 10; + }*/ + } + + // Only support to use meta to tier + + /** + * accept meta [0, maxMeta) + * @param maxMeta exclusive + */ + public static <T> IStructureElement<T> addTieredBlock( + Block aBlock, + BiConsumer<T, Integer> aSetTheFuckingMeta, + Function<T, Integer> aGetTheFuckingMeta, + int maxMeta) { + return addTieredBlock( + aBlock, + (t, i) -> { + aSetTheFuckingMeta.accept(t, i); + return true; + }, + aGetTheFuckingMeta, + 0, + maxMeta); + } + + /** + * + * @param minMeta inclusive + * @param maxMeta exclusive + */ + public static <T> IStructureElement<T> addTieredBlock( + Block aBlock, + BiConsumer<T, Integer> aSetTheFuckingMeta, + Function<T, Integer> aGetTheFuckingMeta, + int minMeta, + int maxMeta) { + return addTieredBlock( + aBlock, + (t, i) -> { + aSetTheFuckingMeta.accept(t, i); + return true; + }, + aGetTheFuckingMeta, + minMeta, + maxMeta); + } + + /** + * + * @param minMeta inclusive + * @param maxMeta exclusive + */ + public static <T> IStructureElement<T> addTieredBlock( + Block aBlock, + BiPredicate<T, Integer> aSetTheFuckingMeta, + Function<T, Integer> aGetTheFuckingMeta, + int minMeta, + int maxMeta) { + + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block tBlock = world.getBlock(x, y, z); + if (aBlock == tBlock) { + Integer currentMeta = aGetTheFuckingMeta.apply(t); + int newMeta = tBlock.getDamageValue(world, x, y, z) + 1; + if (newMeta > maxMeta || newMeta < minMeta + 1) return false; + if (currentMeta == 0) { + return aSetTheFuckingMeta.test(t, newMeta); + } else { + return currentMeta == newMeta; + } + } + return false; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, aBlock, getMeta(trigger)); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock(x, y, z, aBlock, getMeta(trigger), 3); + } + + private int getMeta(ItemStack trigger) { + int meta = trigger.stackSize; + if (meta <= 0) meta = minMeta; + if (meta + minMeta >= maxMeta) meta = maxMeta - 1 - minMeta; + return meta + minMeta; + } + + @Override + public PlaceResult survivalPlaceBlock( + T t, + World world, + int x, + int y, + int z, + ItemStack trigger, + IItemSource s, + EntityPlayerMP actor, + Consumer<IChatComponent> chatter) { + if (world.getBlock(x, y, z) == aBlock) { + if (world.getBlockMetadata(x, y, z) == getMeta(trigger)) { + return PlaceResult.SKIP; + } + return PlaceResult.REJECT; + } + return StructureUtility.survivalPlaceBlock(aBlock, getMeta(trigger), world, x, y, z, s, actor, chatter); + } + }; + } + + @Override + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + if (aSide == aFacing) { + if (aActive) + return new ITexture[] { + getCasingTexture(), + TextureFactory.builder() + .addIcon(getActiveOverlay()) + .extFacing() + .build() + }; + return new ITexture[] { + getCasingTexture(), + TextureFactory.builder() + .addIcon(getInactiveOverlay()) + .extFacing() + .build() + }; + } + return new ITexture[] {getCasingTexture()}; + } + + protected IIconContainer getActiveOverlay() { + return null; + } + + protected IIconContainer getInactiveOverlay() { + return null; + } + + protected ITexture getCasingTexture() { + return Textures.BlockIcons.getCasingTextureForId(getCasingTextureId()); + } + + protected int getCasingTextureId() { + return 0; + } + + public enum GTPPHatchElement implements IHatchElement<GregtechMeta_MultiBlockBase<?>> { + AirIntake(GregtechMeta_MultiBlockBase::addAirIntakeToMachineList, GT_MetaTileEntity_Hatch_AirIntake.class) { + @Override + public long count(GregtechMeta_MultiBlockBase<?> t) { + return t.mAirIntakes.size(); + } + }, + ControlCore( + GregtechMeta_MultiBlockBase::addControlCoreToMachineList, GT_MetaTileEntity_Hatch_ControlCore.class) { + @Override + public long count(GregtechMeta_MultiBlockBase<?> t) { + return t.mControlCoreBus.size(); + } + }, + TTDynamo( + GregtechMeta_MultiBlockBase::addMultiAmpDynamoToMachineList, + "com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti") { + @Override + public long count(GregtechMeta_MultiBlockBase<?> t) { + return t.mTecTechDynamoHatches.size(); + } + }, + TTEnergy( + GregtechMeta_MultiBlockBase::addMultiAmpEnergyToMachineList, + "com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti") { + @Override + public long count(GregtechMeta_MultiBlockBase<?> t) { + return t.mTecTechEnergyHatches.size(); + } + }, + ; + + @SuppressWarnings("unchecked") + private static <T> Class<T> retype(Class<?> clazz) { + return (Class<T>) clazz; + } + + private final List<? extends Class<? extends IMetaTileEntity>> mMteClasses; + private final IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> mAdder; + + @SafeVarargs + GTPPHatchElement( + IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> aAdder, + Class<? extends IMetaTileEntity>... aMteClasses) { + this.mMteClasses = Arrays.asList(aMteClasses); + this.mAdder = aAdder; + } + + GTPPHatchElement(IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> aAdder, String... aClassNames) { + this.mMteClasses = Arrays.stream(aClassNames) + .map(ReflectionUtils::getClass) + .filter(Objects::nonNull) + .<Class<? extends IMetaTileEntity>>map(GTPPHatchElement::retype) + .collect(Collectors.toList()); + this.mAdder = aAdder; + } + + @Override + public List<? extends Class<? extends IMetaTileEntity>> mteClasses() { + return mMteClasses; + } + + @Override + public IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> adder() { + return mAdder; + } + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java index 5503280409..119d681212 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java @@ -1,7 +1,7 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; -import java.util.ArrayList; -import java.util.List; +import static gregtech.api.enums.GT_Values.V; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -16,265 +16,268 @@ import gtPlusPlus.api.objects.data.*; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusInput; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusOutput; +import java.util.ArrayList; +import java.util.List; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; +public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMultiBase<T>> + extends GregtechMeta_MultiBlockBase<T> { -import static gregtech.api.enums.GT_Values.V; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + public ArrayList<GT_MetaTileEntity_Hatch_Steam_BusInput> mSteamInputs = + new ArrayList<GT_MetaTileEntity_Hatch_Steam_BusInput>(); + public ArrayList<GT_MetaTileEntity_Hatch_Steam_BusOutput> mSteamOutputs = + new ArrayList<GT_MetaTileEntity_Hatch_Steam_BusOutput>(); + public ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mSteamInputFluids = + new ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase>(); + + protected static final String TT_steaminputbus = StatCollector.translateToLocal("GTPP.MBTT.SteamInputBus"); + protected static final String TT_steamoutputbus = StatCollector.translateToLocal("GTPP.MBTT.SteamOutputBus"); + protected static final String TT_steamhatch = StatCollector.translateToLocal("GTPP.MBTT.SteamHatch"); + + public GregtechMeta_SteamMultiBase(String aName) { + super(aName); + } + + public GregtechMeta_SteamMultiBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @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(getCasingTextureIndex()), + aActive ? getFrontOverlayActive() : getFrontOverlay() + }; + } + return new ITexture[] {Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex())}; + } + + protected abstract GT_RenderedTexture getFrontOverlay(); + + protected abstract GT_RenderedTexture getFrontOverlayActive(); + + private int getCasingTextureIndex() { + return 10; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean checkRecipe(ItemStack arg0) { + + log("Running checkRecipeGeneric(0)"); + ArrayList<ItemStack> tItems = getStoredInputs(); + ArrayList<FluidStack> tFluids = getStoredFluids(); + GT_Recipe_Map tMap = this.getRecipeMap(); + if (tMap == null) { + return false; + } + ItemStack[] aItemInputs = tItems.toArray(new ItemStack[0]); + FluidStack[] aFluidInputs = tFluids.toArray(new FluidStack[0]); + GT_Recipe tRecipe = tMap.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, V[1], null, null, aItemInputs); + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + int aEUPercent = 100; + int aSpeedBonusPercent = 0; + int aOutputChanceRoll = 10000; + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + int aMaxParallelRecipes = + canBufferOutputs(tRecipe.mOutputs, tRecipe.mFluidOutputs, this.getMaxParallelRecipes()); + 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("tRecipeEUt: " + tRecipeEUt); + + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (32 - 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 * 1.5f); + + this.mEUt = (int) Math.ceil(tTotalEUt * 1.33f); + + // this.mEUt = (3 * tRecipe.mEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = getOutputFluids(tRecipe, parallelRecipes); + + // Collect output item types + ItemStack[] tOutputItems = getOutputItems(tRecipe); + + // 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[0]); + + // 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 ArrayList<FluidStack> getAllSteamStacks() { + ArrayList<FluidStack> aFluids = new ArrayList<FluidStack>(); + FluidStack aSteam = FluidUtils.getSteam(1); + for (FluidStack aFluid : this.getStoredFluids()) { + if (aFluid.isFluidEqual(aSteam)) { + aFluids.add(aFluid); + } + } + return aFluids; + } + + public int getTotalSteamStored() { + int aSteam = 0; + for (FluidStack aFluid : getAllSteamStacks()) { + aSteam += aFluid.amount; + } + return aSteam; + } + + public boolean tryConsumeSteam(int aAmount) { + if (getTotalSteamStored() <= 0) { + return false; + } else { + return this.depleteInput(FluidUtils.getSteam(aAmount)); + } + } + + @Override + public int getMaxEfficiency(ItemStack arg0) { + return 0; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mSteamInputs.clear(); + this.mSteamOutputs.clear(); + this.mSteamInputFluids.clear(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } -public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMultiBase<T>> extends GregtechMeta_MultiBlockBase<T> { - - public ArrayList<GT_MetaTileEntity_Hatch_Steam_BusInput> mSteamInputs = new ArrayList<GT_MetaTileEntity_Hatch_Steam_BusInput>(); - public ArrayList<GT_MetaTileEntity_Hatch_Steam_BusOutput> mSteamOutputs = new ArrayList<GT_MetaTileEntity_Hatch_Steam_BusOutput>(); - public ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mSteamInputFluids = new ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase>(); - - protected static final String TT_steaminputbus = StatCollector.translateToLocal("GTPP.MBTT.SteamInputBus"); - protected static final String TT_steamoutputbus = StatCollector.translateToLocal("GTPP.MBTT.SteamOutputBus"); - protected static final String TT_steamhatch = StatCollector.translateToLocal("GTPP.MBTT.SteamHatch"); - - public GregtechMeta_SteamMultiBase(String aName) { - super(aName); - } - - public GregtechMeta_SteamMultiBase(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - @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(getCasingTextureIndex()), aActive ? getFrontOverlayActive() : getFrontOverlay()}; - } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex())}; - } - - protected abstract GT_RenderedTexture getFrontOverlay(); - - protected abstract GT_RenderedTexture getFrontOverlayActive(); - - private int getCasingTextureIndex() { - return 10; - } - - @Override - public boolean hasSlotInGUI() { - return true; - } - - @Override - public String getCustomGUIResourceName() { - return null; - } - - @Override - public int getEuDiscountForParallelism() { - return 0; - } - - @Override - public boolean checkRecipe(ItemStack arg0) { - - - log("Running checkRecipeGeneric(0)"); - ArrayList<ItemStack> tItems = getStoredInputs(); - ArrayList<FluidStack> tFluids = getStoredFluids(); - GT_Recipe_Map tMap = this.getRecipeMap(); - if (tMap == null) { - return false; - } - ItemStack[] aItemInputs = tItems.toArray(new ItemStack[0]); - FluidStack[] aFluidInputs = tFluids.toArray(new FluidStack[0]); - GT_Recipe tRecipe = tMap.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, V[1], null, null, aItemInputs); - if (tRecipe == null) { - log("BAD RETURN - 1"); - return false; - } - - int aEUPercent = 100; - int aSpeedBonusPercent = 0; - int aOutputChanceRoll = 10000; - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - - - log("Running checkRecipeGeneric(1)"); - // Remember last recipe - an optimization for findRecipe() - this.mLastRecipe = tRecipe; - - - int aMaxParallelRecipes = canBufferOutputs(tRecipe.mOutputs, tRecipe.mFluidOutputs, this.getMaxParallelRecipes()); - 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("tRecipeEUt: "+tRecipeEUt); - - - - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (32 - 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 * 1.5f); - - this.mEUt = (int)Math.ceil(tTotalEUt*1.33f); - - //this.mEUt = (3 * tRecipe.mEUt); - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = getOutputFluids(tRecipe, parallelRecipes); - - // Collect output item types - ItemStack[] tOutputItems = getOutputItems(tRecipe); - - // 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[0]); - - // 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 ArrayList<FluidStack> getAllSteamStacks(){ - ArrayList<FluidStack> aFluids = new ArrayList<FluidStack>(); - FluidStack aSteam = FluidUtils.getSteam(1); - for (FluidStack aFluid : this.getStoredFluids()) { - if (aFluid.isFluidEqual(aSteam)) { - aFluids.add(aFluid); - } - } - return aFluids; - } - - public int getTotalSteamStored() { - int aSteam = 0; - for (FluidStack aFluid : getAllSteamStacks()) { - aSteam += aFluid.amount; - } - return aSteam; - } - - public boolean tryConsumeSteam(int aAmount) { - if (getTotalSteamStored() <= 0) { - return false; - } - else { - return this.depleteInput(FluidUtils.getSteam(aAmount)); - } - } - - @Override - public int getMaxEfficiency(ItemStack arg0) { - return 0; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (this.mUpdate == 1 || this.mStartUpCheck == 1) { - this.mSteamInputs.clear(); - this.mSteamOutputs.clear(); - this.mSteamInputFluids.clear(); - } - } - super.onPostTick(aBaseMetaTileEntity, aTick); - } - /** * Called every tick the Machine runs */ public boolean onRunningTick(ItemStack aStack) { - fixAllMaintenanceIssue(); + fixAllMaintenanceIssue(); if (mEUt < 0) { - long aSteamVal = (((long) -mEUt * 10000) / Math.max(1000, mEfficiency)); - //Logger.INFO("Trying to drain "+aSteamVal+" steam per tick."); + long aSteamVal = (((long) -mEUt * 10000) / Math.max(1000, mEfficiency)); + // Logger.INFO("Trying to drain "+aSteamVal+" steam per tick."); if (!tryConsumeSteam((int) aSteamVal)) { stopMachine(); return false; @@ -282,403 +285,408 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu } return true; } - - @Override - public boolean addToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { - if (aTileEntity == null) { - log("Invalid IGregTechTileEntity"); - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - log("Invalid IMetaTileEntity"); - return false; - } - - //Use this to determine the correct value, then update the hatch texture after. - boolean aDidAdd = false; - - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase) { - log("Adding Steam Input Hatch"); - aDidAdd = addToMachineListInternal(mSteamInputFluids, aMetaTileEntity, aBaseCasingIndex); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { - log("Trying to set recipe map. Type: "+(getRecipeMap() != null ? getRecipeMap().mNEIName : "Null")); - this.resetRecipeMapForHatch(aTileEntity, getRecipeMap()); - log("Adding Steam Input Bus"); + + @Override + public boolean addToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + if (aTileEntity == null) { + log("Invalid IGregTechTileEntity"); + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + log("Invalid IMetaTileEntity"); + return false; + } + + // Use this to determine the correct value, then update the hatch texture after. + boolean aDidAdd = false; + + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase) { + log("Adding Steam Input Hatch"); + aDidAdd = addToMachineListInternal(mSteamInputFluids, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { + log("Trying to set recipe map. Type: " + (getRecipeMap() != null ? getRecipeMap().mNEIName : "Null")); + this.resetRecipeMapForHatch(aTileEntity, getRecipeMap()); + log("Adding Steam Input Bus"); aDidAdd = addToMachineListInternal(mSteamInputs, aMetaTileEntity, aBaseCasingIndex); - } - else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusOutput) { - log("Adding Steam Output Bus"); - aDidAdd = addToMachineListInternal(mSteamOutputs, aMetaTileEntity, aBaseCasingIndex); - } - - return aDidAdd; - } - - - - - @Override - public void stopMachine() { - super.stopMachine(); - } - - public FluidStack[] getOutputFluids(GT_Recipe aRecipe, int parallelRecipes) { - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[aRecipe.mFluidOutputs.length]; - for (int h = 0; h < aRecipe.mFluidOutputs.length; h++) { - if (aRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = aRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - return tOutputFluids; - } - - public ItemStack[] getOutputItems(GT_Recipe aRecipe) { - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[aRecipe.mOutputs.length]; - for (int h = 0; h < aRecipe.mOutputs.length; h++) { - if (aRecipe.getOutput(h) != null) { - tOutputItems[h] = aRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - return tOutputItems; - } - - public int getOutputCount(ItemStack[] aOutputs) { - return aOutputs.length; - } - public int getOutputFluidCount(FluidStack[] aOutputs) { - return aOutputs.length; - } - - public int canBufferOutputs(final ItemStack[] aOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) { - - log("Determining if we have space to buffer outputs. Parallel: "+aParallelRecipes); - - // Null recipe or a recipe with lots of outputs? - // E.G. Gendustry custom comb with a billion centrifuge outputs? - // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true. - if (aOutputs == null && aFluidOutputs == null) { - return 0; - } - - // Do we even need to check for item outputs? - boolean aDoesOutputItems = aOutputs != null ? aOutputs.length > 0 : false; - // Do we even need to check for fluid outputs? - boolean aDoesOutputFluids = aFluidOutputs != null ? aFluidOutputs.length > 0 : false; - - if (!aDoesOutputItems && !aDoesOutputFluids) { - return 0; - } - - /* ======================================== - * Item Management - * ======================================== - */ - - if (aDoesOutputItems) { - log("We have items to output."); - - // How many slots are free across all the output buses? - int aInputBusSlotsFree = 0; - - /* - * Create Variables for Item Output - */ - - AutoMap<FlexiblePair<ItemStack, Integer>> aItemMap = new AutoMap<FlexiblePair<ItemStack, Integer>>(); - AutoMap<ItemStack> aItemOutputs = new AutoMap<ItemStack>(aOutputs); - - for (final GT_MetaTileEntity_Hatch_Steam_BusOutput tBus : this.mSteamOutputs) { - if (!isValidMetaTileEntity(tBus)) { - continue; - } - final IInventory tBusInv = tBus.getBaseMetaTileEntity(); - for (int i = 0; i < tBusInv.getSizeInventory(); i++) { - if (tBus.getStackInSlot(i) == null) { - aInputBusSlotsFree++; - } - else { - ItemStack aT = tBus.getStackInSlot(i); - int aSize = aT.stackSize; - aT = aT.copy(); - aT.stackSize = 0; - aItemMap.put(new FlexiblePair<ItemStack, Integer>(aT, aSize)); - } - } - } - - // Count the slots we need, later we can check if any are able to merge with existing stacks - int aRecipeSlotsRequired = 0; - - // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the recipe outputs. - ConcurrentSet<FlexiblePair<ItemStack, Integer>> aInputMap = new ConcurrentHashSet<FlexiblePair<ItemStack, Integer>>(); - - // Iterate over the outputs, calculating require stack spacing they will require. - for (int i=0;i<getOutputCount(aOutputs);i++) { - ItemStack aY = aItemOutputs.get(i); - if (aY == null) { - continue; - } - else { - int aStackSize = aY.stackSize * aParallelRecipes; - if (aStackSize > 64) { - int aSlotsNeedsForThisStack = (int) Math.ceil((double) ((float) aStackSize / 64f)); - // Should round up and add as many stacks as required nicely. - aRecipeSlotsRequired += aSlotsNeedsForThisStack; - for (int o=0;o<aRecipeSlotsRequired;o++) { - int aStackToRemove = (aStackSize -= 64) > 64 ? 64 : aStackSize; - aY = aY.copy(); - aY.stackSize = 0; - aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackToRemove)); - } - } - else { - // Only requires one slot - aRecipeSlotsRequired++; - aY = aY.copy(); - aY.stackSize = 0; - aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackSize)); - } - } - } - - // We have items to add to the output buses. See if any are not full stacks and see if we can make them full. - if (aInputMap.size() > 0) { - // Iterate over the current stored items in the Output busses, if any match and are not full, we can try account for merging. - busItems: for (FlexiblePair<ItemStack, Integer> y : aItemMap) { - // Iterate over the 'inputs', we can safely remove these as we go. - outputItems: for (FlexiblePair<ItemStack, Integer> u : aInputMap) { - // Create local vars for readability. - ItemStack aOutputBusStack = y.getKey(); - ItemStack aOutputStack = u.getKey(); - // Stacks match, including NBT. - if (GT_Utility.areStacksEqual(aOutputBusStack, aOutputStack, false)) { - // Stack Matches, but it's full, continue. - if (aOutputBusStack.stackSize >= 64) { - // This stack is full, no point checking it. - continue busItems; - } - else { - // We can merge these two stacks without any hassle. - if ((aOutputBusStack.stackSize + aOutputStack.stackSize) <= 64) { - // Update the stack size in the bus storage map. - y.setValue(aOutputBusStack.stackSize + aOutputStack.stackSize); - // Remove the 'input' stack from the recipe outputs, so we don't try count it again. - aInputMap.remove(u); - continue outputItems; - } - // Stack merging is too much, so we fill this stack, leave the remainder. - else { - int aRemainder = (aOutputBusStack.stackSize + aOutputStack.stackSize) - 64; - // Update the stack size in the bus storage map. - y.setValue(64); - // Create a new object to iterate over later, with the remainder data; - FlexiblePair<ItemStack, Integer> t = new FlexiblePair<ItemStack, Integer>(u.getKey(), aRemainder); - // Remove the 'input' stack from the recipe outputs, so we don't try count it again. - aInputMap.remove(u); - // Add the remainder stack. - aInputMap.add(t); - continue outputItems; - } - } - } - else { - continue outputItems; - } - } - } - } - - // We have stacks that did not merge, do we have space for them? - if (aInputMap.size() > 0) { - if (aInputMap.size() > aInputBusSlotsFree) { - aParallelRecipes = (int) Math.floor((double) aInputBusSlotsFree/aInputMap.size() * aParallelRecipes); - // We do not have enough free slots in total to accommodate the remaining managed stacks. - log(" Free: "+aInputBusSlotsFree+", Required: "+aInputMap.size()); - if(aParallelRecipes == 0) { - log("Failed to find enough space for all item outputs."); - return 0; - } - - } - } - - /* - * End Item Management - */ - - } - - - - - - /* ======================================== - * Fluid Management - * ======================================== - */ - - - - if (aDoesOutputFluids) { - log("We have Fluids to output."); - // How many slots are free across all the output buses? - int aFluidHatches = 0; - int aEmptyFluidHatches = 0; - int aFullFluidHatches = 0; - // Create Map for Fluid Output - ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>> aOutputHatches = new ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>>(); - for (final GT_MetaTileEntity_Hatch_Output tBus : this.mOutputHatches) { - if (!isValidMetaTileEntity(tBus)) { - continue; - } - aFluidHatches++; - // Map the Hatch with the space left for easy checking later. - if (tBus.getFluid() == null) { - aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(tBus, null, tBus.getCapacity())); - } - else { - int aSpaceLeft = tBus.getCapacity() - tBus.getFluidAmount(); - aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(tBus, tBus.getFluid(), aSpaceLeft)); - } - } - // Create a map of all the fluids we would like to output, we can iterate over this and see how many we can merge into existing hatch stacks. - ArrayList<FluidStack> aOutputFluids = new ArrayList<FluidStack>(); - // Ugly ass boxing - aOutputFluids.addAll(new AutoMap<FluidStack>(aFluidOutputs)); - // Iterate the Hatches, updating their 'stored' data. - //for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aHatchData : aOutputHatches) { - for (int i = 0;i<aOutputHatches.size();i++) { - // The Hatch Itself - GT_MetaTileEntity_Hatch_Output aHatch = aOutputHatches.get(i).getValue_1(); - // Fluid in the Hatch - FluidStack aHatchStack = aOutputHatches.get(i).getValue_2(); - // Space left in Hatch - int aSpaceLeftInHatch = aHatch.getCapacity() - aHatch.getFluidAmount(); - // Hatch is full, - if (aSpaceLeftInHatch <= 0) { - aFullFluidHatches++; - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - continue; - } - // Hatch has space - else { - // Check if any fluids match - //aFluidMatch: for (FluidStack aOutputStack : aOutputFluids) { - for(int j = 0;j<getOutputFluidCount(aFluidOutputs);j++) { - //log(" aHatchStack "+aHatchStack.getLocalizedName()+" aOutput stack "+aOutputStack.getLocalizedName()); - if (GT_Utility.areFluidsEqual(aHatchStack, aOutputFluids.get(j))) { - int aFluidToPutIntoHatch = aOutputFluids.get(j).amount * aParallelRecipes; - // Not Enough space to insert all of the fluid. - // We fill this hatch and add a smaller Fluidstack back to the iterator. - if (aSpaceLeftInHatch < aFluidToPutIntoHatch) { - // Copy existing Hatch Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - aNewHatchStack.amount = 0; - // Copy existing Hatch Stack again - FluidStack aNewOutputStack = aHatchStack.copy(); - aNewOutputStack.amount = 0; - // How much fluid do we have left after we fill the hatch? - int aFluidLeftAfterInsert = aFluidToPutIntoHatch - aSpaceLeftInHatch; - // Set new stacks to appropriate values - aNewHatchStack.amount = aHatch.getCapacity(); - aNewOutputStack.amount = aFluidLeftAfterInsert; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Add remaining Fluid to Output list - aOutputFluids.add(aNewOutputStack); - // Re-add hatch to hatch list, with new data. - //Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); - //aOutputHatches.add(aNewHatchData); - break; - } - // We can fill this hatch perfectly (rare case), may as well add it directly to the full list. - else if (aSpaceLeftInHatch == aFluidToPutIntoHatch) { - // Copy Old Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - // Add in amount from output stack - aNewHatchStack.amount += aFluidToPutIntoHatch; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Re-add hatch to hatch list, with new data. - Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); - aOutputHatches.add(aNewHatchData); - break; - } - // We have more space than we need to merge, so we remove the stack from the output list and update the hatch list. - else { - // Copy Old Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - // Add in amount from output stack - aNewHatchStack.amount += aFluidToPutIntoHatch; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Re-add hatch to hatch list, with new data. - Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); - aOutputHatches.add(aNewHatchData); - // Check next fluid - continue; - } - - } - else { - continue; - } - } - } - } - - for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aFreeHatchCheck : aOutputHatches) { - // Free Hatch - if (aFreeHatchCheck.getValue_2() == null || aFreeHatchCheck.getValue_3() == 0 || aFreeHatchCheck.getValue_1().getFluid() == null) { - aEmptyFluidHatches++; - } - } - - // We have Fluid Stacks we did not merge. Do we have space? - log("fluids to output "+aOutputFluids.size()+" empty hatches "+aEmptyFluidHatches); - if (aOutputFluids.size() > 0) { - // Not enough space to add fluids. - if (aOutputFluids.size() > aEmptyFluidHatches) { - aParallelRecipes = (int) Math.floor((double) aEmptyFluidHatches/aOutputFluids.size() * aParallelRecipes); - log("Failed to find enough space for all fluid outputs. Free: "+aEmptyFluidHatches+", Required: "+aOutputFluids.size()); - return 0; - - } - } - - /* - * End Fluid Management - */ - } - - return aParallelRecipes; - } - - - /* - * Handle I/O with custom hatches - */ - - @Override + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusOutput) { + log("Adding Steam Output Bus"); + aDidAdd = addToMachineListInternal(mSteamOutputs, aMetaTileEntity, aBaseCasingIndex); + } + + return aDidAdd; + } + + @Override + public void stopMachine() { + super.stopMachine(); + } + + public FluidStack[] getOutputFluids(GT_Recipe aRecipe, int parallelRecipes) { + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[aRecipe.mFluidOutputs.length]; + for (int h = 0; h < aRecipe.mFluidOutputs.length; h++) { + if (aRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = aRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + return tOutputFluids; + } + + public ItemStack[] getOutputItems(GT_Recipe aRecipe) { + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[aRecipe.mOutputs.length]; + for (int h = 0; h < aRecipe.mOutputs.length; h++) { + if (aRecipe.getOutput(h) != null) { + tOutputItems[h] = aRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + return tOutputItems; + } + + public int getOutputCount(ItemStack[] aOutputs) { + return aOutputs.length; + } + + public int getOutputFluidCount(FluidStack[] aOutputs) { + return aOutputs.length; + } + + public int canBufferOutputs(final ItemStack[] aOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) { + + log("Determining if we have space to buffer outputs. Parallel: " + aParallelRecipes); + + // Null recipe or a recipe with lots of outputs? + // E.G. Gendustry custom comb with a billion centrifuge outputs? + // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true. + if (aOutputs == null && aFluidOutputs == null) { + return 0; + } + + // Do we even need to check for item outputs? + boolean aDoesOutputItems = aOutputs != null ? aOutputs.length > 0 : false; + // Do we even need to check for fluid outputs? + boolean aDoesOutputFluids = aFluidOutputs != null ? aFluidOutputs.length > 0 : false; + + if (!aDoesOutputItems && !aDoesOutputFluids) { + return 0; + } + + /* ======================================== + * Item Management + * ======================================== + */ + + if (aDoesOutputItems) { + log("We have items to output."); + + // How many slots are free across all the output buses? + int aInputBusSlotsFree = 0; + + /* + * Create Variables for Item Output + */ + + AutoMap<FlexiblePair<ItemStack, Integer>> aItemMap = new AutoMap<FlexiblePair<ItemStack, Integer>>(); + AutoMap<ItemStack> aItemOutputs = new AutoMap<ItemStack>(aOutputs); + + for (final GT_MetaTileEntity_Hatch_Steam_BusOutput tBus : this.mSteamOutputs) { + if (!isValidMetaTileEntity(tBus)) { + continue; + } + final IInventory tBusInv = tBus.getBaseMetaTileEntity(); + for (int i = 0; i < tBusInv.getSizeInventory(); i++) { + if (tBus.getStackInSlot(i) == null) { + aInputBusSlotsFree++; + } else { + ItemStack aT = tBus.getStackInSlot(i); + int aSize = aT.stackSize; + aT = aT.copy(); + aT.stackSize = 0; + aItemMap.put(new FlexiblePair<ItemStack, Integer>(aT, aSize)); + } + } + } + + // Count the slots we need, later we can check if any are able to merge with existing stacks + int aRecipeSlotsRequired = 0; + + // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the + // recipe outputs. + ConcurrentSet<FlexiblePair<ItemStack, Integer>> aInputMap = + new ConcurrentHashSet<FlexiblePair<ItemStack, Integer>>(); + + // Iterate over the outputs, calculating require stack spacing they will require. + for (int i = 0; i < getOutputCount(aOutputs); i++) { + ItemStack aY = aItemOutputs.get(i); + if (aY == null) { + continue; + } else { + int aStackSize = aY.stackSize * aParallelRecipes; + if (aStackSize > 64) { + int aSlotsNeedsForThisStack = (int) Math.ceil((double) ((float) aStackSize / 64f)); + // Should round up and add as many stacks as required nicely. + aRecipeSlotsRequired += aSlotsNeedsForThisStack; + for (int o = 0; o < aRecipeSlotsRequired; o++) { + int aStackToRemove = (aStackSize -= 64) > 64 ? 64 : aStackSize; + aY = aY.copy(); + aY.stackSize = 0; + aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackToRemove)); + } + } else { + // Only requires one slot + aRecipeSlotsRequired++; + aY = aY.copy(); + aY.stackSize = 0; + aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackSize)); + } + } + } + + // We have items to add to the output buses. See if any are not full stacks and see if we can make them + // full. + if (aInputMap.size() > 0) { + // Iterate over the current stored items in the Output busses, if any match and are not full, we can try + // account for merging. + busItems: + for (FlexiblePair<ItemStack, Integer> y : aItemMap) { + // Iterate over the 'inputs', we can safely remove these as we go. + outputItems: + for (FlexiblePair<ItemStack, Integer> u : aInputMap) { + // Create local vars for readability. + ItemStack aOutputBusStack = y.getKey(); + ItemStack aOutputStack = u.getKey(); + // Stacks match, including NBT. + if (GT_Utility.areStacksEqual(aOutputBusStack, aOutputStack, false)) { + // Stack Matches, but it's full, continue. + if (aOutputBusStack.stackSize >= 64) { + // This stack is full, no point checking it. + continue busItems; + } else { + // We can merge these two stacks without any hassle. + if ((aOutputBusStack.stackSize + aOutputStack.stackSize) <= 64) { + // Update the stack size in the bus storage map. + y.setValue(aOutputBusStack.stackSize + aOutputStack.stackSize); + // Remove the 'input' stack from the recipe outputs, so we don't try count it again. + aInputMap.remove(u); + continue outputItems; + } + // Stack merging is too much, so we fill this stack, leave the remainder. + else { + int aRemainder = (aOutputBusStack.stackSize + aOutputStack.stackSize) - 64; + // Update the stack size in the bus storage map. + y.setValue(64); + // Create a new object to iterate over later, with the remainder data; + FlexiblePair<ItemStack, Integer> t = + new FlexiblePair<ItemStack, Integer>(u.getKey(), aRemainder); + // Remove the 'input' stack from the recipe outputs, so we don't try count it again. + aInputMap.remove(u); + // Add the remainder stack. + aInputMap.add(t); + continue outputItems; + } + } + } else { + continue outputItems; + } + } + } + } + + // We have stacks that did not merge, do we have space for them? + if (aInputMap.size() > 0) { + if (aInputMap.size() > aInputBusSlotsFree) { + aParallelRecipes = + (int) Math.floor((double) aInputBusSlotsFree / aInputMap.size() * aParallelRecipes); + // We do not have enough free slots in total to accommodate the remaining managed stacks. + log(" Free: " + aInputBusSlotsFree + ", Required: " + aInputMap.size()); + if (aParallelRecipes == 0) { + log("Failed to find enough space for all item outputs."); + return 0; + } + } + } + + /* + * End Item Management + */ + + } + + /* ======================================== + * Fluid Management + * ======================================== + */ + + if (aDoesOutputFluids) { + log("We have Fluids to output."); + // How many slots are free across all the output buses? + int aFluidHatches = 0; + int aEmptyFluidHatches = 0; + int aFullFluidHatches = 0; + // Create Map for Fluid Output + ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>> aOutputHatches = + new ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>>(); + for (final GT_MetaTileEntity_Hatch_Output tBus : this.mOutputHatches) { + if (!isValidMetaTileEntity(tBus)) { + continue; + } + aFluidHatches++; + // Map the Hatch with the space left for easy checking later. + if (tBus.getFluid() == null) { + aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( + tBus, null, tBus.getCapacity())); + } else { + int aSpaceLeft = tBus.getCapacity() - tBus.getFluidAmount(); + aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( + tBus, tBus.getFluid(), aSpaceLeft)); + } + } + // Create a map of all the fluids we would like to output, we can iterate over this and see how many we can + // merge into existing hatch stacks. + ArrayList<FluidStack> aOutputFluids = new ArrayList<FluidStack>(); + // Ugly ass boxing + aOutputFluids.addAll(new AutoMap<FluidStack>(aFluidOutputs)); + // Iterate the Hatches, updating their 'stored' data. + // for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aHatchData : aOutputHatches) { + for (int i = 0; i < aOutputHatches.size(); i++) { + // The Hatch Itself + GT_MetaTileEntity_Hatch_Output aHatch = aOutputHatches.get(i).getValue_1(); + // Fluid in the Hatch + FluidStack aHatchStack = aOutputHatches.get(i).getValue_2(); + // Space left in Hatch + int aSpaceLeftInHatch = aHatch.getCapacity() - aHatch.getFluidAmount(); + // Hatch is full, + if (aSpaceLeftInHatch <= 0) { + aFullFluidHatches++; + aOutputHatches.remove(aOutputHatches.get(i)); + i--; + continue; + } + // Hatch has space + else { + // Check if any fluids match + // aFluidMatch: for (FluidStack aOutputStack : aOutputFluids) { + for (int j = 0; j < getOutputFluidCount(aFluidOutputs); j++) { + // log(" aHatchStack "+aHatchStack.getLocalizedName()+" aOutput stack + // "+aOutputStack.getLocalizedName()); + if (GT_Utility.areFluidsEqual(aHatchStack, aOutputFluids.get(j))) { + int aFluidToPutIntoHatch = aOutputFluids.get(j).amount * aParallelRecipes; + // Not Enough space to insert all of the fluid. + // We fill this hatch and add a smaller Fluidstack back to the iterator. + if (aSpaceLeftInHatch < aFluidToPutIntoHatch) { + // Copy existing Hatch Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + aNewHatchStack.amount = 0; + // Copy existing Hatch Stack again + FluidStack aNewOutputStack = aHatchStack.copy(); + aNewOutputStack.amount = 0; + // How much fluid do we have left after we fill the hatch? + int aFluidLeftAfterInsert = aFluidToPutIntoHatch - aSpaceLeftInHatch; + // Set new stacks to appropriate values + aNewHatchStack.amount = aHatch.getCapacity(); + aNewOutputStack.amount = aFluidLeftAfterInsert; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputFluids.get(j)); + j--; + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aOutputHatches.get(i)); + i--; + // Add remaining Fluid to Output list + aOutputFluids.add(aNewOutputStack); + // Re-add hatch to hatch list, with new data. + // Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new + // Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, + // aNewHatchStack.amount); + // aOutputHatches.add(aNewHatchData); + break; + } + // We can fill this hatch perfectly (rare case), may as well add it directly to the full + // list. + else if (aSpaceLeftInHatch == aFluidToPutIntoHatch) { + // Copy Old Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + // Add in amount from output stack + aNewHatchStack.amount += aFluidToPutIntoHatch; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputFluids.get(j)); + j--; + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aOutputHatches.get(i)); + i--; + // Re-add hatch to hatch list, with new data. + Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = + new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( + aHatch, aNewHatchStack, aNewHatchStack.amount); + aOutputHatches.add(aNewHatchData); + break; + } + // We have more space than we need to merge, so we remove the stack from the output list and + // update the hatch list. + else { + // Copy Old Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + // Add in amount from output stack + aNewHatchStack.amount += aFluidToPutIntoHatch; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputFluids.get(j)); + j--; + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aOutputHatches.get(i)); + i--; + // Re-add hatch to hatch list, with new data. + Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = + new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( + aHatch, aNewHatchStack, aNewHatchStack.amount); + aOutputHatches.add(aNewHatchData); + // Check next fluid + continue; + } + + } else { + continue; + } + } + } + } + + for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aFreeHatchCheck : aOutputHatches) { + // Free Hatch + if (aFreeHatchCheck.getValue_2() == null + || aFreeHatchCheck.getValue_3() == 0 + || aFreeHatchCheck.getValue_1().getFluid() == null) { + aEmptyFluidHatches++; + } + } + + // We have Fluid Stacks we did not merge. Do we have space? + log("fluids to output " + aOutputFluids.size() + " empty hatches " + aEmptyFluidHatches); + if (aOutputFluids.size() > 0) { + // Not enough space to add fluids. + if (aOutputFluids.size() > aEmptyFluidHatches) { + aParallelRecipes = + (int) Math.floor((double) aEmptyFluidHatches / aOutputFluids.size() * aParallelRecipes); + log("Failed to find enough space for all fluid outputs. Free: " + aEmptyFluidHatches + + ", Required: " + aOutputFluids.size()); + return 0; + } + } + + /* + * End Fluid Management + */ + } + + return aParallelRecipes; + } + + /* + * Handle I/O with custom hatches + */ + + @Override public boolean depleteInput(FluidStack aLiquid) { if (aLiquid == null) return false; for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) { @@ -696,14 +704,15 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu return false; } - @Override + @Override public boolean depleteInput(ItemStack aStack) { if (GT_Utility.isStackInvalid(aStack)) return false; FluidStack aLiquid = GT_Utility.getFluidForFilledItem(aStack, true); if (aLiquid != null) return depleteInput(aLiquid); for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) { if (isValidMetaTileEntity(tHatch)) { - if (GT_Utility.areStacksEqual(aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(0))) { + if (GT_Utility.areStacksEqual( + aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(0))) { if (tHatch.getBaseMetaTileEntity().getStackInSlot(0).stackSize >= aStack.stackSize) { tHatch.getBaseMetaTileEntity().decrStackSize(0, aStack.stackSize); return true; @@ -715,7 +724,8 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu tHatch.mRecipeMap = getRecipeMap(); if (isValidMetaTileEntity(tHatch)) { for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (GT_Utility.areStacksEqual(aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(i))) { + if (GT_Utility.areStacksEqual( + aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(i))) { if (tHatch.getBaseMetaTileEntity().getStackInSlot(0).stackSize >= aStack.stackSize) { tHatch.getBaseMetaTileEntity().decrStackSize(0, aStack.stackSize); return true; @@ -727,7 +737,7 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu return false; } - @Override + @Override public ArrayList<FluidStack> getStoredFluids() { ArrayList<FluidStack> rList = new ArrayList<FluidStack>(); for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) { @@ -738,7 +748,7 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu return rList; } - @Override + @Override public ArrayList<ItemStack> getStoredInputs() { ArrayList<ItemStack> rList = new ArrayList<ItemStack>(); for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : mSteamInputs) { @@ -746,7 +756,7 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu if (isValidMetaTileEntity(tHatch)) { for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { if (tHatch.getBaseMetaTileEntity().getStackInSlot(i) != null) { - rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); + rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); } } } @@ -754,7 +764,7 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu return rList; } - @Override + @Override public boolean addOutput(ItemStack aStack) { if (GT_Utility.isStackInvalid(aStack)) return false; aStack = GT_Utility.copy(aStack); @@ -778,7 +788,7 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu return outputSuccess; } - @Override + @Override public ArrayList<ItemStack> getStoredOutputs() { ArrayList<ItemStack> rList = new ArrayList<ItemStack>(); for (GT_MetaTileEntity_Hatch_Steam_BusOutput tHatch : mSteamOutputs) { @@ -791,13 +801,11 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu return rList; } - @Override + @Override public void updateSlots() { for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : mSteamInputs) if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); } - - } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechDoubleFuelGeneratorBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechDoubleFuelGeneratorBase.java index 287d2105ac..473b2ad538 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechDoubleFuelGeneratorBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechDoubleFuelGeneratorBase.java @@ -2,427 +2,478 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generat import static gregtech.api.enums.GT_Values.V; -import java.util.Collection; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; - import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_DeluxeTank; +import java.util.Collection; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; public abstract class GregtechDoubleFuelGeneratorBase extends GT_MetaTileEntity_DeluxeTank { - private boolean useFuel = false; - - public GregtechDoubleFuelGeneratorBase(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, 4, aDescription, aTextures); - } - - public GregtechDoubleFuelGeneratorBase(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, 4, aDescription, aTextures); - } - - @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 String[] getDescription() { - return new String[]{this.mDescription, "Fuel Efficiency: " + this.getEfficiency() + "%"}; - } - - - /* @Override + private boolean useFuel = false; + + public GregtechDoubleFuelGeneratorBase( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, 4, aDescription, aTextures); + } + + public GregtechDoubleFuelGeneratorBase( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + @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 String[] getDescription() { + return new String[] {this.mDescription, "Fuel Efficiency: " + this.getEfficiency() + "%"}; + } + + /* @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { if (aBaseMetaTileEntity.isClientSide()) return true; aBaseMetaTileEntity.openGUI(aPlayer); return true; }*/ - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()){ - Logger.WARNING("Entity is Client side, simply returning true"); - return true; - } - Logger.WARNING("Entity is not Client side, opening entity Container and by extension, it's GUI, then returning true"); - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getFrontActive(final byte aColor) { - return this.getFront(aColor); - } - - 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 boolean isFacingValid(final byte aSide) { - return aSide > 1; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return aIndex < 2; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return true; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public long maxEUOutput() { - return this.getBaseMetaTileEntity().isAllowedToWork() ? V[this.mTier] : 0; - } - - @Override - public long maxEUStore() { - return Math.max(this.getEUVar(), (V[this.mTier] * 115) + this.getMinimumStoredEU()); - } - - @Override - public boolean doesFillContainers() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - @Override - public boolean doesEmptyContainers() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - @Override - public boolean canTankBeFilled() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - @Override - public boolean canTankBeEmptied() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - @Override - public boolean displaysItemStack() { - return true; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - @Override - public boolean isFluidInputAllowed(final FluidStack aFluid) { - return this.getFuelValue(aFluid) > 0; - } - - @Override - public long getMinimumStoredEU() { - return 512; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && ((aTick % 10) == 0)) { - if (this.mFluid == null) { - if (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUOutput() + this.getMinimumStoredEU())) { - this.mInventory[this.getStackDisplaySlot()] = null; - } else { - if (this.mInventory[this.getStackDisplaySlot()] == null) { - this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); - } - this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); - } - } else { - if ((this.mFluid != null) && (this.mFluid2 != null)){ - final int tFuelValue = this.getFuelValue(this.mFluid), tConsumed = this.consumedFluidPerOperation(this.mFluid); - final int tFuelValue2 = this.getFuelValue(this.mFluid2), tConsumed2 = this.consumedFluidPerOperation(this.mFluid2); - if (((tFuelValue > 0) && (tConsumed > 0) && (this.mFluid.amount > tConsumed))/* && (tFuelValue2 > 0 && tConsumed2 > 0 && mFluid2.amount > tConsumed2)*/) { - - Logger.WARNING("tFuelValue: "+tFuelValue); - Logger.WARNING("tConsumed: "+tConsumed); - Logger.WARNING("mFluid.name: "+this.mFluid.getFluid().getName()); - Logger.WARNING("mFluid.amount: "+this.mFluid.amount); - Logger.WARNING("mFluid.amount > tConsumed: "+(this.mFluid.amount > tConsumed)); - - Logger.WARNING("========================================================="); - - Logger.WARNING("tFuelValue2: "+tFuelValue2); - Logger.WARNING("tConsumed2: "+tConsumed2); - Logger.WARNING("mFluid2.name: "+this.mFluid2.getFluid().getName()); - Logger.WARNING("mFluid2.amount: "+this.mFluid2.amount); - Logger.WARNING("mFluid2.amount > tConsumed2: "+(this.mFluid2.amount > tConsumed2)); - long tFluidAmountToUse = Math.min(this.mFluid.amount / tConsumed, (((this.maxEUOutput() * 30) + this.getMinimumStoredEU()) - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue); - long tFluidAmountToUse2 = Math.min(this.mFluid2.amount / tConsumed2, (((this.maxEUOutput() * 30) + this.getMinimumStoredEU()) - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue2); - - if (tFluidAmountToUse <= 0){ - /*if ((mFluid.amount / tConsumed) == getCapacity()){ - tFluidAmountToUse = 1; - }*/ - - if (aBaseMetaTileEntity.getUniversalEnergyStored() <= (aBaseMetaTileEntity.getEUCapacity()-aBaseMetaTileEntity.getUniversalEnergyStored())){ - tFluidAmountToUse = 1; - Logger.WARNING("========================================================="); - Logger.WARNING("tFluidAmountToUse - Updated: "+tFluidAmountToUse); - Logger.WARNING("========================================================="); - } - } - - if (tFluidAmountToUse2 <= 0){ - /*if ((mFluid2.amount / tConsumed) == getCapacity()){ - tFluidAmountToUse2 = 1; - }*/ - if (aBaseMetaTileEntity.getUniversalEnergyStored() <= (aBaseMetaTileEntity.getEUCapacity()-aBaseMetaTileEntity.getUniversalEnergyStored())){ - tFluidAmountToUse2 = 1; - Logger.WARNING("========================================================="); - Logger.WARNING("tFluidAmountToUse2 - Updated: "+tFluidAmountToUse2); - Logger.WARNING("========================================================="); - } - } - - Logger.WARNING("========================================================="); - Logger.WARNING("tFluidAmountToUse: "+tFluidAmountToUse); - Logger.WARNING("========================================================="); - - /*Utils.LOG_WARNING("mFluid.amount / tConsumed: "+("fluidAmount:"+mFluid.amount)+(" tConsumed:"+tConsumed)+" | "+(mFluid.amount / tConsumed)); - Utils.LOG_WARNING("maxEUOutput() * 20 + getMinimumStoredEU(): "+(maxEUOutput() * 30 + getMinimumStoredEU())); - Utils.LOG_WARNING("maxEUOutput(): "+maxEUOutput()); - Utils.LOG_WARNING("maxEUOutput() * 20: "+(maxEUOutput() * 30)); - Utils.LOG_WARNING("getMinimumStoredEU(): "+(getMinimumStoredEU())); - Utils.LOG_WARNING("aBaseMetaTileEntity.getUniversalEnergyStored(): "+(aBaseMetaTileEntity.getUniversalEnergyStored())); - Utils.LOG_WARNING("(maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()): "+((maxEUOutput() * 30 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()))); - Utils.LOG_WARNING("tFuelValue: "+(tFuelValue)); - Utils.LOG_WARNING("(maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue): "+((maxEUOutput() * 30 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue)); - */ - - Logger.WARNING("========================================================="); - Logger.WARNING("tFluidAmountToUse2: "+tFluidAmountToUse2); - Logger.WARNING("========================================================="); - - /*Utils.LOG_WARNING("mFluid2.amount / tConsumed2: "+("fluidAmount2:"+mFluid2.amount)+(" tConsumed2:"+tConsumed2)+" | "+(mFluid2.amount / tConsumed2)); - Utils.LOG_WARNING("maxEUOutput() * 20 + getMinimumStoredEU(): "+(maxEUOutput() * 30 + getMinimumStoredEU())); - Utils.LOG_WARNING("maxEUOutput(): "+maxEUOutput()); - Utils.LOG_WARNING("maxEUOutput() * 20: "+(maxEUOutput() * 30)); - Utils.LOG_WARNING("getMinimumStoredEU(): "+(getMinimumStoredEU())); - Utils.LOG_WARNING("aBaseMetaTileEntity.getUniversalEnergyStored(): "+(aBaseMetaTileEntity.getUniversalEnergyStored())); - Utils.LOG_WARNING("(maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()): "+((maxEUOutput() * 30 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()))); - Utils.LOG_WARNING("tFuelValue2: "+(tFuelValue2)); - Utils.LOG_WARNING("(maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue2): "+((maxEUOutput() * 30 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue2)); - */ - if (((tFluidAmountToUse > 0) && aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true)) && ((tFluidAmountToUse2 > 0) && aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse2 * tFuelValue2, true))){ - - Logger.WARNING("tFuelValue: "+tFuelValue); - Logger.WARNING("tConsumed: "+tConsumed); - Logger.WARNING("mFluid.name: "+this.mFluid.getFluid().getName()); - Logger.WARNING("mFluid.amount: "+this.mFluid.amount); - Logger.WARNING("mFluid.amount > tConsumed: "+(this.mFluid.amount > tConsumed)); - - Logger.WARNING("========================================================="); - - Logger.WARNING("tFuelValue2: "+tFuelValue2); - Logger.WARNING("tConsumed2: "+tConsumed2); - Logger.WARNING("mFluid2.name: "+this.mFluid2.getFluid().getName()); - Logger.WARNING("mFluid2.amount: "+this.mFluid2.amount); - Logger.WARNING("mFluid2.amount > tConsumed2: "+(this.mFluid2.amount > tConsumed2)); - - if (this.useFuel){ - this.mFluid.amount -= tFluidAmountToUse * tConsumed; - this.mFluid2.amount -= tFluidAmountToUse2 * tConsumed2; - this.useFuel = false; - } - else { - this.useFuel = true; - } - - } - else { - Logger.WARNING("========================================================="); - Logger.WARNING("Either tFluidAmountToUse1 <= 0, power cannot be increased of tFluidAmountToUse2 <= 0"); - Logger.WARNING("tFluidAmountToUse1: "+tFluidAmountToUse); - Logger.WARNING("tFluidAmountToUse2: "+tFluidAmountToUse2); - } - } - else { - /*Utils.LOG_WARNING("(tFuelValue > 0 && tConsumed > 0 && mFluid.amount > tConsumed) && (tFuelValue2 > 0 && tConsumed2 > 0 && mFluid2.amount > tConsumed2)"); - Utils.LOG_WARNING("tFuelValue: "+tFuelValue); - Utils.LOG_WARNING("tConsumed: "+tConsumed); - Utils.LOG_WARNING("mFluid.amount: "+mFluid.amount); - Utils.LOG_WARNING("mFluid.amount > tConsumed: "+(mFluid.amount > tConsumed)); - - Utils.LOG_WARNING("========================================================="); - - Utils.LOG_WARNING("tFuelValue2: "+tFuelValue2); - Utils.LOG_WARNING("tConsumed2: "+tConsumed2); - Utils.LOG_WARNING("mFluid2.amount: "+mFluid2.amount); - Utils.LOG_WARNING("mFluid2.amount > tConsumed2: "+(mFluid2.amount > tConsumed2)); */ - } - } - else { - Logger.WARNING("One mFluid is null"); - if (this.mFluid != null) { - Logger.WARNING("mFluid1 is not null"); - } - if (this.mFluid2 != null) { - Logger.WARNING("mFluid2 is not null"); - } - } - } - if ((this.mInventory[this.getInputSlot()] != null) && (aBaseMetaTileEntity.getUniversalEnergyStored() < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())) && (GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null)) { - final int tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); - if (tFuelValue > 0) { - final ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { - aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - } - } - } - } - - if (aBaseMetaTileEntity.isServerSide()) { - aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && (aBaseMetaTileEntity.getUniversalEnergyStored() >= (this.maxEUOutput() + this.getMinimumStoredEU()))); - } - } - - public abstract GT_Recipe_Map getRecipes(); - - public abstract int getEfficiency(); - - public int consumedFluidPerOperation(final FluidStack aLiquid) { - return 1; - } - - public int getFuelValue(final FluidStack aLiquid) { - if ((aLiquid == null) || (this.getRecipes() == null)) { - return 0; - } - FluidStack tLiquid; - final Collection<GT_Recipe> tRecipeList = this.getRecipes().mRecipeList; - if (tRecipeList != null) { - for (final GT_Recipe tFuel : tRecipeList) { - if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null) { - if (aLiquid.isFluidEqual(tLiquid)) { - return (int) (((long) tFuel.mSpecialValue * this.getEfficiency() * this.consumedFluidPerOperation(tLiquid)) / 100); - } - } - } - } - return 0; - } - - public int getFuelValue(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { - return 0; - } - final GT_Recipe tFuel = this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); - if (tFuel != null) { - return (int) ((tFuel.mSpecialValue * 1000L * this.getEfficiency()) / 100); - } - return 0; - } - - public ItemStack getEmptyContainer(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { - return null; - } - final GT_Recipe tFuel = this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); - if (tFuel != null) { - return GT_Utility.copy(tFuel.getOutput(0)); - } - return GT_Utility.getContainerItem(aStack, true); - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) && ((this.getFuelValue(aStack) > 0) || (this.getFuelValue(GT_Utility.getFluidForFilledItem(aStack, true)) > 0)); - } - - @Override - public int getCapacity() { - return 32000; - } - - @Override - public int getTankPressure() { - return -100; - } + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + Logger.WARNING("Entity is Client side, simply returning true"); + return true; + } + Logger.WARNING( + "Entity is not Client side, opening entity Container and by extension, it's GUI, then returning true"); + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + 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 boolean isFacingValid(final byte aSide) { + return aSide > 1; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return aIndex < 2; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return true; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public long maxEUOutput() { + return this.getBaseMetaTileEntity().isAllowedToWork() ? V[this.mTier] : 0; + } + + @Override + public long maxEUStore() { + return Math.max(this.getEUVar(), (V[this.mTier] * 115) + this.getMinimumStoredEU()); + } + + @Override + public boolean doesFillContainers() { + return this.getBaseMetaTileEntity().isAllowedToWork(); + } + + @Override + public boolean doesEmptyContainers() { + return this.getBaseMetaTileEntity().isAllowedToWork(); + } + + @Override + public boolean canTankBeFilled() { + return this.getBaseMetaTileEntity().isAllowedToWork(); + } + + @Override + public boolean canTankBeEmptied() { + return this.getBaseMetaTileEntity().isAllowedToWork(); + } + + @Override + public boolean displaysItemStack() { + return true; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public boolean isFluidInputAllowed(final FluidStack aFluid) { + return this.getFuelValue(aFluid) > 0; + } + + @Override + public long getMinimumStoredEU() { + return 512; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && ((aTick % 10) == 0)) { + if (this.mFluid == null) { + if (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUOutput() + this.getMinimumStoredEU())) { + this.mInventory[this.getStackDisplaySlot()] = null; + } else { + if (this.mInventory[this.getStackDisplaySlot()] == null) { + this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); + } + this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " + + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); + } + } else { + if ((this.mFluid != null) && (this.mFluid2 != null)) { + final int tFuelValue = this.getFuelValue(this.mFluid), + tConsumed = this.consumedFluidPerOperation(this.mFluid); + final int tFuelValue2 = this.getFuelValue(this.mFluid2), + tConsumed2 = this.consumedFluidPerOperation(this.mFluid2); + if (((tFuelValue > 0) + && (tConsumed > 0) + && (this.mFluid.amount + > tConsumed)) /* && (tFuelValue2 > 0 && tConsumed2 > 0 && mFluid2.amount > tConsumed2)*/) { + + Logger.WARNING("tFuelValue: " + tFuelValue); + Logger.WARNING("tConsumed: " + tConsumed); + Logger.WARNING("mFluid.name: " + this.mFluid.getFluid().getName()); + Logger.WARNING("mFluid.amount: " + this.mFluid.amount); + Logger.WARNING("mFluid.amount > tConsumed: " + (this.mFluid.amount > tConsumed)); + + Logger.WARNING("========================================================="); + + Logger.WARNING("tFuelValue2: " + tFuelValue2); + Logger.WARNING("tConsumed2: " + tConsumed2); + Logger.WARNING( + "mFluid2.name: " + this.mFluid2.getFluid().getName()); + Logger.WARNING("mFluid2.amount: " + this.mFluid2.amount); + Logger.WARNING("mFluid2.amount > tConsumed2: " + (this.mFluid2.amount > tConsumed2)); + long tFluidAmountToUse = Math.min( + this.mFluid.amount / tConsumed, + (((this.maxEUOutput() * 30) + this.getMinimumStoredEU()) + - aBaseMetaTileEntity.getUniversalEnergyStored()) + / tFuelValue); + long tFluidAmountToUse2 = Math.min( + this.mFluid2.amount / tConsumed2, + (((this.maxEUOutput() * 30) + this.getMinimumStoredEU()) + - aBaseMetaTileEntity.getUniversalEnergyStored()) + / tFuelValue2); + + if (tFluidAmountToUse <= 0) { + /*if ((mFluid.amount / tConsumed) == getCapacity()){ + tFluidAmountToUse = 1; + }*/ + + if (aBaseMetaTileEntity.getUniversalEnergyStored() + <= (aBaseMetaTileEntity.getEUCapacity() + - aBaseMetaTileEntity.getUniversalEnergyStored())) { + tFluidAmountToUse = 1; + Logger.WARNING("========================================================="); + Logger.WARNING("tFluidAmountToUse - Updated: " + tFluidAmountToUse); + Logger.WARNING("========================================================="); + } + } + + if (tFluidAmountToUse2 <= 0) { + /*if ((mFluid2.amount / tConsumed) == getCapacity()){ + tFluidAmountToUse2 = 1; + }*/ + if (aBaseMetaTileEntity.getUniversalEnergyStored() + <= (aBaseMetaTileEntity.getEUCapacity() + - aBaseMetaTileEntity.getUniversalEnergyStored())) { + tFluidAmountToUse2 = 1; + Logger.WARNING("========================================================="); + Logger.WARNING("tFluidAmountToUse2 - Updated: " + tFluidAmountToUse2); + Logger.WARNING("========================================================="); + } + } + + Logger.WARNING("========================================================="); + Logger.WARNING("tFluidAmountToUse: " + tFluidAmountToUse); + Logger.WARNING("========================================================="); + + /*Utils.LOG_WARNING("mFluid.amount / tConsumed: "+("fluidAmount:"+mFluid.amount)+(" tConsumed:"+tConsumed)+" | "+(mFluid.amount / tConsumed)); + Utils.LOG_WARNING("maxEUOutput() * 20 + getMinimumStoredEU(): "+(maxEUOutput() * 30 + getMinimumStoredEU())); + Utils.LOG_WARNING("maxEUOutput(): "+maxEUOutput()); + Utils.LOG_WARNING("maxEUOutput() * 20: "+(maxEUOutput() * 30)); + Utils.LOG_WARNING("getMinimumStoredEU(): "+(getMinimumStoredEU())); + Utils.LOG_WARNING("aBaseMetaTileEntity.getUniversalEnergyStored(): "+(aBaseMetaTileEntity.getUniversalEnergyStored())); + Utils.LOG_WARNING("(maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()): "+((maxEUOutput() * 30 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()))); + Utils.LOG_WARNING("tFuelValue: "+(tFuelValue)); + Utils.LOG_WARNING("(maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue): "+((maxEUOutput() * 30 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue)); + */ + + Logger.WARNING("========================================================="); + Logger.WARNING("tFluidAmountToUse2: " + tFluidAmountToUse2); + Logger.WARNING("========================================================="); + + /*Utils.LOG_WARNING("mFluid2.amount / tConsumed2: "+("fluidAmount2:"+mFluid2.amount)+(" tConsumed2:"+tConsumed2)+" | "+(mFluid2.amount / tConsumed2)); + Utils.LOG_WARNING("maxEUOutput() * 20 + getMinimumStoredEU(): "+(maxEUOutput() * 30 + getMinimumStoredEU())); + Utils.LOG_WARNING("maxEUOutput(): "+maxEUOutput()); + Utils.LOG_WARNING("maxEUOutput() * 20: "+(maxEUOutput() * 30)); + Utils.LOG_WARNING("getMinimumStoredEU(): "+(getMinimumStoredEU())); + Utils.LOG_WARNING("aBaseMetaTileEntity.getUniversalEnergyStored(): "+(aBaseMetaTileEntity.getUniversalEnergyStored())); + Utils.LOG_WARNING("(maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()): "+((maxEUOutput() * 30 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()))); + Utils.LOG_WARNING("tFuelValue2: "+(tFuelValue2)); + Utils.LOG_WARNING("(maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue2): "+((maxEUOutput() * 30 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue2)); + */ + if (((tFluidAmountToUse > 0) + && aBaseMetaTileEntity.increaseStoredEnergyUnits( + tFluidAmountToUse * tFuelValue, true)) + && ((tFluidAmountToUse2 > 0) + && aBaseMetaTileEntity.increaseStoredEnergyUnits( + tFluidAmountToUse2 * tFuelValue2, true))) { + + Logger.WARNING("tFuelValue: " + tFuelValue); + Logger.WARNING("tConsumed: " + tConsumed); + Logger.WARNING( + "mFluid.name: " + this.mFluid.getFluid().getName()); + Logger.WARNING("mFluid.amount: " + this.mFluid.amount); + Logger.WARNING("mFluid.amount > tConsumed: " + (this.mFluid.amount > tConsumed)); + + Logger.WARNING("========================================================="); + + Logger.WARNING("tFuelValue2: " + tFuelValue2); + Logger.WARNING("tConsumed2: " + tConsumed2); + Logger.WARNING( + "mFluid2.name: " + this.mFluid2.getFluid().getName()); + Logger.WARNING("mFluid2.amount: " + this.mFluid2.amount); + Logger.WARNING("mFluid2.amount > tConsumed2: " + (this.mFluid2.amount > tConsumed2)); + + if (this.useFuel) { + this.mFluid.amount -= tFluidAmountToUse * tConsumed; + this.mFluid2.amount -= tFluidAmountToUse2 * tConsumed2; + this.useFuel = false; + } else { + this.useFuel = true; + } + + } else { + Logger.WARNING("========================================================="); + Logger.WARNING( + "Either tFluidAmountToUse1 <= 0, power cannot be increased of tFluidAmountToUse2 <= 0"); + Logger.WARNING("tFluidAmountToUse1: " + tFluidAmountToUse); + Logger.WARNING("tFluidAmountToUse2: " + tFluidAmountToUse2); + } + } else { + /*Utils.LOG_WARNING("(tFuelValue > 0 && tConsumed > 0 && mFluid.amount > tConsumed) && (tFuelValue2 > 0 && tConsumed2 > 0 && mFluid2.amount > tConsumed2)"); + Utils.LOG_WARNING("tFuelValue: "+tFuelValue); + Utils.LOG_WARNING("tConsumed: "+tConsumed); + Utils.LOG_WARNING("mFluid.amount: "+mFluid.amount); + Utils.LOG_WARNING("mFluid.amount > tConsumed: "+(mFluid.amount > tConsumed)); + + Utils.LOG_WARNING("========================================================="); + + Utils.LOG_WARNING("tFuelValue2: "+tFuelValue2); + Utils.LOG_WARNING("tConsumed2: "+tConsumed2); + Utils.LOG_WARNING("mFluid2.amount: "+mFluid2.amount); + Utils.LOG_WARNING("mFluid2.amount > tConsumed2: "+(mFluid2.amount > tConsumed2)); */ + } + } else { + Logger.WARNING("One mFluid is null"); + if (this.mFluid != null) { + Logger.WARNING("mFluid1 is not null"); + } + if (this.mFluid2 != null) { + Logger.WARNING("mFluid2 is not null"); + } + } + } + if ((this.mInventory[this.getInputSlot()] != null) + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())) + && (GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null)) { + final int tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); + if (tFuelValue > 0) { + final ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); + if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + } + } + } + } + + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() + && (aBaseMetaTileEntity.getUniversalEnergyStored() + >= (this.maxEUOutput() + this.getMinimumStoredEU()))); + } + } + + public abstract GT_Recipe_Map getRecipes(); + + public abstract int getEfficiency(); + + public int consumedFluidPerOperation(final FluidStack aLiquid) { + return 1; + } + + public int getFuelValue(final FluidStack aLiquid) { + if ((aLiquid == null) || (this.getRecipes() == null)) { + return 0; + } + FluidStack tLiquid; + final Collection<GT_Recipe> tRecipeList = this.getRecipes().mRecipeList; + if (tRecipeList != null) { + for (final GT_Recipe tFuel : tRecipeList) { + if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null) { + if (aLiquid.isFluidEqual(tLiquid)) { + return (int) (((long) tFuel.mSpecialValue + * this.getEfficiency() + * this.consumedFluidPerOperation(tLiquid)) + / 100); + } + } + } + } + return 0; + } + + public int getFuelValue(final ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { + return 0; + } + final GT_Recipe tFuel = + this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); + if (tFuel != null) { + return (int) ((tFuel.mSpecialValue * 1000L * this.getEfficiency()) / 100); + } + return 0; + } + + public ItemStack getEmptyContainer(final ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { + return null; + } + final GT_Recipe tFuel = + this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); + if (tFuel != null) { + return GT_Utility.copy(tFuel.getOutput(0)); + } + return GT_Utility.getContainerItem(aStack, true); + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) + && ((this.getFuelValue(aStack) > 0) + || (this.getFuelValue(GT_Utility.getFluidForFilledItem(aStack, true)) > 0)); + } + + @Override + public int getCapacity() { + return 32000; + } + + @Override + public int getTankPressure() { + return -100; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaBoilerBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaBoilerBase.java index 99ad81a4a9..7333f5fb3d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaBoilerBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaBoilerBase.java @@ -1,10 +1,5 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; @@ -15,368 +10,360 @@ import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; - import gtPlusPlus.core.util.math.MathUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -public abstract class GregtechMetaBoilerBase extends GT_MetaTileEntity_BasicTank -{ - public int mTemperature = 20; - public int mProcessingEnergy = 0; - public int mLossTimer = 0; - public FluidStack mSteam = null; - public boolean mHadNoWater = false; - public long RI = MathUtils.randLong(5L, 30L); - - public GregtechMetaBoilerBase(final int aID, final String aName, final String aNameRegional, final String aDescription, final ITexture... aTextures) - { - super(aID, aName, aNameRegional, 0, 4, aDescription, aTextures); - } - - public GregtechMetaBoilerBase(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) - { - super(aName, aTier, 4, aDescription, aTextures); - } - - @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)(aActive ? 4 : 3)) : aSide][aColorIndex + 1]; - //mTextures[(aSide==aFacing?(aActive?4:3):aSide==GT_Utility.getOppositeSide(aFacing)?2:aSide==0?0:aSide==1?1:2)][aColorIndex+1]; - if((aSide!=aFacing)&&(tmp.length==2)){ - tmp = new ITexture[]{tmp[0]}; - } - return tmp; - } - - @Override - public boolean isElectric() - { - return false; - } - - @Override - public boolean isPneumatic() - { - return false; - } - - @Override - public boolean isSteampowered() - { - return false; - } - - @Override - public boolean isSimpleMachine() - { - return false; - } - - @Override - public boolean isFacingValid(final byte aFacing) - { - return aFacing > 1; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) - { - return true; - } - - @Override - public boolean isValidSlot(final int aIndex) - { - return true; - } - - @Override - public int getProgresstime() - { - return this.mTemperature; - } - - @Override - public int maxProgresstime() - { - return 500; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) - { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - if (aPlayer != null) { - if (GT_Utility.areStacksEqual(aPlayer.getCurrentEquippedItem(), new ItemStack(Items.water_bucket, 1))) - { - this.fill(Materials.Water.getFluid(1000 * aPlayer.getCurrentEquippedItem().stackSize), true); - aPlayer.getCurrentEquippedItem().func_150996_a(Items.bucket); - } - else - { - aBaseMetaTileEntity.openGUI(aPlayer); - } - } - return true; - } - - @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 boolean displaysItemStack() - { - return false; - } - - @Override - public boolean displaysStackSize() - { - return false; - } - - @Override - public boolean isFluidInputAllowed(final FluidStack aFluid) - { - return GT_ModHandler.isWater(aFluid); - } - - @Override - public FluidStack getDrainableStack() - { - return this.mSteam; - } - - @Override - public FluidStack setDrainableStack(final FluidStack aFluid) - { - this.mSteam = aFluid; - return this.mSteam; - } - - @Override - public boolean isDrainableStackSeparate() { - return true; - } - - @Override - public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aCover) - { - return GregTech_API.getCoverBehavior(aCover.toStack()).isSimpleCover(); - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) - { - super.saveNBTData(aNBT); - aNBT.setInteger("mLossTimer", this.mLossTimer); - aNBT.setInteger("mTemperature", this.mTemperature); - aNBT.setInteger("mProcessingEnergy", this.mProcessingEnergy); - if (this.mSteam != null) { - try - { - aNBT.setTag("mSteam", this.mSteam.writeToNBT(new NBTTagCompound())); - } - catch (final Throwable e) {} - } - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) - { - super.loadNBTData(aNBT); - this.mLossTimer = aNBT.getInteger("mLossTimer"); - this.mTemperature = aNBT.getInteger("mTemperature"); - this.mProcessingEnergy = aNBT.getInteger("mProcessingEnergy"); - this.mSteam = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mSteam")); - } - - @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 > 40) - { - 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 > 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; - if (this.mSteam == null) { - this.mSteam = GT_ModHandler.getSteam(150L); - } else if (GT_ModHandler.isSteam(this.mSteam)) { - this.mSteam.amount += 150; - } else { - this.mSteam = GT_ModHandler.getSteam(150L); - } - } - } - 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()) && - (this.mInventory[2] != null)) { - if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.gem.get(Materials.Coal))) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.dust.get(Materials.Coal))) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.dustImpure.get(Materials.Coal))) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.crushed.get(Materials.Coal)))) - { - this.mProcessingEnergy += 160; - aBaseMetaTileEntity.decrStackSize(2, 1); - if (aBaseMetaTileEntity.getRandomNumber(3) == 0) { - aBaseMetaTileEntity.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); - } - } - else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.gem.get(Materials.Charcoal))) - { - this.mProcessingEnergy += 160; - aBaseMetaTileEntity.decrStackSize(2, 1); - if (aBaseMetaTileEntity.getRandomNumber(3) == 0) { - aBaseMetaTileEntity.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); - } - } - else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], "fuelCoke")) - { - this.mProcessingEnergy += 640; - aBaseMetaTileEntity.decrStackSize(2, 1); - if (aBaseMetaTileEntity.getRandomNumber(2) == 0) { - aBaseMetaTileEntity.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); - } - } - else if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.gem.get(Materials.Lignite))) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.dust.get(Materials.Lignite))) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.dustImpure.get(Materials.Lignite))) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.crushed.get(Materials.Lignite)))) - { - this.mProcessingEnergy += 40; - aBaseMetaTileEntity.decrStackSize(2, 1); - if (aBaseMetaTileEntity.getRandomNumber(8) == 0) { - aBaseMetaTileEntity.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); - } - } - } - if ((this.mTemperature < 1000) && (this.mProcessingEnergy > 0) && ((aTick % 12L) == 0L)) - { - this.mProcessingEnergy -= 2; - this.mTemperature += 1; - } - aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0); - } - } - - @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(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) - { - return (aIndex == 1) || (aIndex == 3); - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) - { - return aIndex == 2; - } - - @Override - public void doSound(final byte aIndex, final double aX, final double aY, final double aZ) - { - if (aIndex == 1) - { - GT_Utility.doSoundAtClient(GregTech_API.sSoundList.get(Integer.valueOf(4)), 2, 1.0F, aX, aY, aZ); - for (int l = 0; l < 8; l++) { - this.getBaseMetaTileEntity().getWorld().spawnParticle("largesmoke", (aX - 0.5D) + Math.random(), aY, (aZ - 0.5D) + Math.random(), 0.0D, 0.0D, 0.0D); - } - } - } - - @Override - public int getCapacity() - { - return 16000; - } - - // This type of machine can have different water and steam capacities. - public int getSteamCapacity() - { - return 32000; - } - - @Override - public int getTankPressure() - { - return 100; - } +public abstract class GregtechMetaBoilerBase extends GT_MetaTileEntity_BasicTank { + public int mTemperature = 20; + public int mProcessingEnergy = 0; + public int mLossTimer = 0; + public FluidStack mSteam = null; + public boolean mHadNoWater = false; + public long RI = MathUtils.randLong(5L, 30L); + + public GregtechMetaBoilerBase( + final int aID, + final String aName, + final String aNameRegional, + final String aDescription, + final ITexture... aTextures) { + super(aID, aName, aNameRegional, 0, 4, aDescription, aTextures); + } + + public GregtechMetaBoilerBase( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + @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) (aActive ? 4 : 3)) : aSide][aColorIndex + 1]; + // mTextures[(aSide==aFacing?(aActive?4:3):aSide==GT_Utility.getOppositeSide(aFacing)?2:aSide==0?0:aSide==1?1:2)][aColorIndex+1]; + if ((aSide != aFacing) && (tmp.length == 2)) { + tmp = new ITexture[] {tmp[0]}; + } + return tmp; + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public boolean isPneumatic() { + return false; + } + + @Override + public boolean isSteampowered() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing > 1; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public int getProgresstime() { + return this.mTemperature; + } + + @Override + public int maxProgresstime() { + return 500; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + if (aPlayer != null) { + if (GT_Utility.areStacksEqual(aPlayer.getCurrentEquippedItem(), new ItemStack(Items.water_bucket, 1))) { + this.fill(Materials.Water.getFluid(1000 * aPlayer.getCurrentEquippedItem().stackSize), true); + aPlayer.getCurrentEquippedItem().func_150996_a(Items.bucket); + } else { + aBaseMetaTileEntity.openGUI(aPlayer); + } + } + return true; + } + + @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 boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public boolean isFluidInputAllowed(final FluidStack aFluid) { + return GT_ModHandler.isWater(aFluid); + } + + @Override + public FluidStack getDrainableStack() { + return this.mSteam; + } + + @Override + public FluidStack setDrainableStack(final FluidStack aFluid) { + this.mSteam = aFluid; + return this.mSteam; + } + + @Override + public boolean isDrainableStackSeparate() { + return true; + } + + @Override + public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aCover) { + return GregTech_API.getCoverBehavior(aCover.toStack()).isSimpleCover(); + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mLossTimer", this.mLossTimer); + aNBT.setInteger("mTemperature", this.mTemperature); + aNBT.setInteger("mProcessingEnergy", this.mProcessingEnergy); + if (this.mSteam != null) { + try { + aNBT.setTag("mSteam", this.mSteam.writeToNBT(new NBTTagCompound())); + } catch (final Throwable e) { + } + } + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mLossTimer = aNBT.getInteger("mLossTimer"); + this.mTemperature = aNBT.getInteger("mTemperature"); + this.mProcessingEnergy = aNBT.getInteger("mProcessingEnergy"); + this.mSteam = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mSteam")); + } + + @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 > 40) { + 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 > 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; + if (this.mSteam == null) { + this.mSteam = GT_ModHandler.getSteam(150L); + } else if (GT_ModHandler.isSteam(this.mSteam)) { + this.mSteam.amount += 150; + } else { + this.mSteam = GT_ModHandler.getSteam(150L); + } + } + } 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()) + && (this.mInventory[2] != null)) { + if ((GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.gem.get(Materials.Coal))) + || (GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.dust.get(Materials.Coal))) + || (GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.dustImpure.get(Materials.Coal))) + || (GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.crushed.get(Materials.Coal)))) { + this.mProcessingEnergy += 160; + aBaseMetaTileEntity.decrStackSize(2, 1); + if (aBaseMetaTileEntity.getRandomNumber(3) == 0) { + aBaseMetaTileEntity.addStackToSlot( + 3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); + } + } else if (GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.gem.get(Materials.Charcoal))) { + this.mProcessingEnergy += 160; + aBaseMetaTileEntity.decrStackSize(2, 1); + if (aBaseMetaTileEntity.getRandomNumber(3) == 0) { + aBaseMetaTileEntity.addStackToSlot( + 3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); + } + } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], "fuelCoke")) { + this.mProcessingEnergy += 640; + aBaseMetaTileEntity.decrStackSize(2, 1); + if (aBaseMetaTileEntity.getRandomNumber(2) == 0) { + aBaseMetaTileEntity.addStackToSlot( + 3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); + } + } else if ((GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.gem.get(Materials.Lignite))) + || (GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.dust.get(Materials.Lignite))) + || (GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.dustImpure.get(Materials.Lignite))) + || (GT_OreDictUnificator.isItemStackInstanceOf( + this.mInventory[2], OrePrefixes.crushed.get(Materials.Lignite)))) { + this.mProcessingEnergy += 40; + aBaseMetaTileEntity.decrStackSize(2, 1); + if (aBaseMetaTileEntity.getRandomNumber(8) == 0) { + aBaseMetaTileEntity.addStackToSlot( + 3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); + } + } + } + if ((this.mTemperature < 1000) && (this.mProcessingEnergy > 0) && ((aTick % 12L) == 0L)) { + this.mProcessingEnergy -= 2; + this.mTemperature += 1; + } + aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0); + } + } + + @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( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return (aIndex == 1) || (aIndex == 3); + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aIndex == 2; + } + + @Override + public void doSound(final byte aIndex, final double aX, final double aY, final double aZ) { + if (aIndex == 1) { + GT_Utility.doSoundAtClient(GregTech_API.sSoundList.get(Integer.valueOf(4)), 2, 1.0F, aX, aY, aZ); + for (int l = 0; l < 8; l++) { + this.getBaseMetaTileEntity() + .getWorld() + .spawnParticle( + "largesmoke", + (aX - 0.5D) + Math.random(), + aY, + (aZ - 0.5D) + Math.random(), + 0.0D, + 0.0D, + 0.0D); + } + } + } + + @Override + public int getCapacity() { + return 16000; + } + + // This type of machine can have different water and steam capacities. + public int getSteamCapacity() { + return 32000; + } + + @Override + public int getTankPressure() { + return 100; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaSolarGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaSolarGenerator.java index e692530963..258f6320ae 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaSolarGenerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaSolarGenerator.java @@ -2,214 +2,251 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generat import static gregtech.api.enums.GT_Values.V; -import net.minecraft.entity.player.EntityPlayer; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.util.GT_Utility; +import net.minecraft.entity.player.EntityPlayer; public abstract class GregtechMetaSolarGenerator extends GT_MetaTileEntity_BasicTank { - public int mEfficiency; - public int mProcessingEnergy = 0; - public int mSolarCharge = 20; - public int mLossTimer = 0; - public static int sEnergyPerTick = 16; - - public GregtechMetaSolarGenerator(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); - } - - public GregtechMetaSolarGenerator(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - @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 String[] getDescription() { - return new String[]{this.mDescription, "Efficiency: " + this.getEfficiency() + "%"}; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getFrontActive(final byte aColor) { - return this.getFront(aColor); - } - - 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 boolean isFacingValid(final byte aSide) { - return aSide > 1; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return aIndex < 2; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return true; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public long maxEUOutput() { - return this.getBaseMetaTileEntity().isAllowedToWork() ? V[this.mTier] : 0; - } - - @Override - public long maxEUStore() { - return Math.max(this.getEUVar(), (V[this.mTier] * 40) + this.getMinimumStoredEU()); - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && (aTick > 20L) - && (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUOutput() + aBaseMetaTileEntity.getEUCapacity()))) { - - if (this.mSolarCharge <= 20) { - this.mSolarCharge = 20; - this.mLossTimer = 0; - } - if (++this.mLossTimer > 45) { - this.mSolarCharge -= 1; - this.mLossTimer = 0; - } - - if ((aTick % 25L) == 0L) { - if (this.mSolarCharge > 100) { - if ((this.mProcessingEnergy > 0) && (aBaseMetaTileEntity.isAllowedToWork()) && ((aTick % 256L) == 0L) && (!aBaseMetaTileEntity.getWorld().isThundering() && (aBaseMetaTileEntity.getUniversalEnergyStored() < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())))) { - this.getBaseMetaTileEntity().increaseStoredEnergyUnits((sEnergyPerTick * this.getEfficiency()) / 10, false); - } - } - } - - if ((this.mSolarCharge < 500) && (this.mProcessingEnergy > 0) && ((aTick % 12L) == 0L)) { - this.mProcessingEnergy -= 1; - this.mSolarCharge += 1; - } - - 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 (aBaseMetaTileEntity.isServerSide()){ - aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && (aBaseMetaTileEntity.getUniversalEnergyStored() >= (this.maxEUOutput() + this.getMinimumStoredEU()))); - } - } - } - - public abstract int getEfficiency(); - - @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; - } + public int mEfficiency; + public int mProcessingEnergy = 0; + public int mSolarCharge = 20; + public int mLossTimer = 0; + public static int sEnergyPerTick = 16; + + public GregtechMetaSolarGenerator( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); + } + + public GregtechMetaSolarGenerator( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @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 String[] getDescription() { + return new String[] {this.mDescription, "Efficiency: " + this.getEfficiency() + "%"}; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + 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 boolean isFacingValid(final byte aSide) { + return aSide > 1; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return aIndex < 2; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return true; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public long maxEUOutput() { + return this.getBaseMetaTileEntity().isAllowedToWork() ? V[this.mTier] : 0; + } + + @Override + public long maxEUStore() { + return Math.max(this.getEUVar(), (V[this.mTier] * 40) + this.getMinimumStoredEU()); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide() + && aBaseMetaTileEntity.isAllowedToWork() + && (aTick > 20L) + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < (this.maxEUOutput() + aBaseMetaTileEntity.getEUCapacity()))) { + + if (this.mSolarCharge <= 20) { + this.mSolarCharge = 20; + this.mLossTimer = 0; + } + if (++this.mLossTimer > 45) { + this.mSolarCharge -= 1; + this.mLossTimer = 0; + } + + if ((aTick % 25L) == 0L) { + if (this.mSolarCharge > 100) { + if ((this.mProcessingEnergy > 0) + && (aBaseMetaTileEntity.isAllowedToWork()) + && ((aTick % 256L) == 0L) + && (!aBaseMetaTileEntity.getWorld().isThundering() + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())))) { + this.getBaseMetaTileEntity() + .increaseStoredEnergyUnits((sEnergyPerTick * this.getEfficiency()) / 10, false); + } + } + } + + if ((this.mSolarCharge < 500) && (this.mProcessingEnergy > 0) && ((aTick % 12L) == 0L)) { + this.mProcessingEnergy -= 1; + this.mSolarCharge += 1; + } + + 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 (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() + && (aBaseMetaTileEntity.getUniversalEnergyStored() + >= (this.maxEUOutput() + this.getMinimumStoredEU()))); + } + } + } + + public abstract int getEfficiency(); + + @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; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechRocketFuelGeneratorBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechRocketFuelGeneratorBase.java index f9105dceb1..fe7ffee685 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechRocketFuelGeneratorBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechRocketFuelGeneratorBase.java @@ -2,8 +2,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generat import static gregtech.api.enums.GT_Values.V; -import java.util.Collection; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -14,6 +12,7 @@ import gregtech.api.util.GT_Utility; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -21,352 +20,384 @@ import net.minecraftforge.fluids.FluidStack; public abstract class GregtechRocketFuelGeneratorBase extends GT_MetaTileEntity_BasicTank { - private boolean useFuel = false; - protected int pollMin, pollMax; - - public GregtechRocketFuelGeneratorBase(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); - int pollMin = (int)(CORE.ConfigSwitches.baseMinPollutionPerSecondRocketFuelGenerator * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); - int pollMax = (int)(CORE.ConfigSwitches.baseMaxPollutionPerSecondRocketFuelGenerator * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); - } - - public GregtechRocketFuelGeneratorBase(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - int pollMin = (int)(CORE.ConfigSwitches.baseMinPollutionPerSecondRocketFuelGenerator * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); - int pollMax = (int)(CORE.ConfigSwitches.baseMaxPollutionPerSecondRocketFuelGenerator * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); - } - - @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 String[] getDescription() { - String aPollution = "Causes between "+pollMin+" and "+pollMax+ " Pollution per second"; - return new String[]{ - this.mDescription, - "Fuel Efficiency: " + this.getEfficiency() + "%", - aPollution, - CORE.GT_Tooltip}; - } - - - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; - } - - public ITexture[] getFrontActive(final byte aColor) { - return this.getFront(aColor); - } - - 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 boolean isFacingValid(final byte aSide) { - return aSide > 1; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return aIndex < 2; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return this.getBaseMetaTileEntity().getFrontFacing() == aSide; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public long maxEUOutput() { - return V[this.mTier]; - } - - @Override - public long maxEUStore() { - return Math.max(this.getEUVar(), (V[this.mTier] * 500) + this.getMinimumStoredEU()); - } - - @Override - public boolean doesFillContainers() { - return false; - } - - @Override - public boolean doesEmptyContainers() { - return true; - } - - @Override - public boolean canTankBeFilled() { - return true; - } - - @Override - public boolean canTankBeEmptied() { - return false; - } - - @Override - public boolean displaysItemStack() { - return true; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - @Override - public boolean isFluidInputAllowed(final FluidStack aFluid) { - return this.getFuelValue(aFluid) > 0; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - - - //super.onPostTick(aBaseMetaTileEntity, aTick); - - /*if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10L == 0L) { - int tFuelValue; - if (this.mFluid == null) { - if (aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() + this.getMinimumStoredEU()) { - this.mInventory[this.getStackDisplaySlot()] = null; - } else { - if (this.mInventory[this.getStackDisplaySlot()] == null) { - this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); - } - - this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " - + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); - } - } else { - tFuelValue = this.getFuelValue(this.mFluid); - int tConsumed = this.consumedFluidPerOperation(this.mFluid); - if (tFuelValue > 0 && tConsumed > 0 && this.mFluid.amount > tConsumed) { - long tFluidAmountToUse = Math.min((long) (this.mFluid.amount / tConsumed), - (this.maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / (long) tFuelValue); - if (tFluidAmountToUse > 0L && aBaseMetaTileEntity - .increaseStoredEnergyUnits(tFluidAmountToUse * (long) tFuelValue, true)) { - PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollution()); - this.mFluid.amount = (int) ((long) this.mFluid.amount - tFluidAmountToUse * (long) tConsumed); - } - } - } - - if (this.mInventory[this.getInputSlot()] != null - && aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() * 20L - + this.getMinimumStoredEU() - && GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null) { - tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); - if (tFuelValue > 0) { - ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { - aBaseMetaTileEntity.increaseStoredEnergyUnits((long) tFuelValue, true); - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollution()); - } - } - } - } - - if (aBaseMetaTileEntity.isServerSide()) { - aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity - .getUniversalEnergyStored() >= this.maxEUOutput() + this.getMinimumStoredEU()); - }*/ - - - - - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && ((aTick % 10) == 0)) { - if (this.mFluid == null) { - if (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUOutput() + this.getMinimumStoredEU())) { - this.mInventory[this.getStackDisplaySlot()] = null; - } else { - if (this.mInventory[this.getStackDisplaySlot()] == null) { - this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); - } - this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); - } - } else { - final int tFuelValue = this.getFuelValue(this.mFluid), tConsumed = this.consumedFluidPerOperation(this.mFluid); - if ((tFuelValue > 0) && (tConsumed > 0) && (this.mFluid.amount >= tConsumed)) { - final long tFluidAmountToUse = Math.min(this.mFluid.amount / tConsumed, (((this.maxEUOutput() * 20) + this.getMinimumStoredEU()) - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue); - if ((tFluidAmountToUse > 0) && aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true)){ - int aSafeFloor = (int) Math.max(((tFluidAmountToUse * tConsumed)/3), 1); - this.mFluid.amount -= (int) aSafeFloor; - PollutionUtils.addPollution(getBaseMetaTileEntity(), 10 * getPollution()); - } - } - } - if ((this.mInventory[this.getInputSlot()] != null) && (aBaseMetaTileEntity.getUniversalEnergyStored() < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())) && (GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null)) { - final int tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); - if (tFuelValue > 0) { - final ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { - aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - PollutionUtils.addPollution(getBaseMetaTileEntity(), 10 * getPollution()); - } - } - } - } - - if (aBaseMetaTileEntity.isServerSide()) { - aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && (aBaseMetaTileEntity.getUniversalEnergyStored() >= (this.maxEUOutput() + this.getMinimumStoredEU()))); - } - } - - public int getPollution() { - return MathUtils.randInt(pollMin, pollMax); - } - - public abstract GT_Recipe_Map getRecipes(); - - public abstract int getEfficiency(); - - public int consumedFluidPerOperation(final FluidStack aLiquid) { - return 1; - } - - public int getFuelValue(final FluidStack aLiquid) { - if ((aLiquid == null) || (this.getRecipes() == null)) { - return 0; - } - FluidStack tLiquid; - final Collection<GT_Recipe> tRecipeList = this.getRecipes().mRecipeList; - if (tRecipeList != null) { - //Logger.INFO("Step A"); - for (final GT_Recipe tFuel : tRecipeList) { - //Logger.INFO("Step B"); - if ((tLiquid = tFuel.mFluidInputs[0]) != null) { - //Logger.INFO("Step C"); - if (aLiquid.isFluidEqual(tLiquid)) { - //Logger.INFO("Found some fuel?"); - int aperOp = this.consumedFluidPerOperation(tLiquid); - int aConsume = (int) (((long) tFuel.mSpecialValue * this.getEfficiency() * aperOp) / 100); - //Logger.INFO("Fuel Value: "+tFuel.mSpecialValue); - //Logger.INFO("Efficiency: "+getEfficiency()); - //Logger.INFO("Consumed per op: "+aperOp); - //Logger.INFO("Consuming "+aConsume); - return aConsume; - } - } - } - } - //Logger.INFO("No Fuel Value | Valid? "+(aLiquid != null)); - return 0; - } - - public int getFuelValue(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { - return 0; - } - final GT_Recipe tFuel = this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); - if (tFuel != null) { - return (int) ((tFuel.mSpecialValue * 1000L * this.getEfficiency()) / 100); - } - return 0; - } - - public ItemStack getEmptyContainer(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { - return null; - } - final GT_Recipe tFuel = this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); - if (tFuel != null) { - return GT_Utility.copy(tFuel.getOutput(0)); - } - return GT_Utility.getContainerItem(aStack, true); - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) && ((this.getFuelValue(aStack) > 0) || (this.getFuelValue(GT_Utility.getFluidForFilledItem(aStack, true)) > 0)); - } - - @Override - public int getCapacity() { - return 32000; - } - - @Override - public int getTankPressure() { - return -100; - } + private boolean useFuel = false; + protected int pollMin, pollMax; + + public GregtechRocketFuelGeneratorBase( + final int aID, + final String aName, + final String aNameRegional, + final int aTier, + final String aDescription, + final ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); + int pollMin = (int) (CORE.ConfigSwitches.baseMinPollutionPerSecondRocketFuelGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); + int pollMax = (int) (CORE.ConfigSwitches.baseMaxPollutionPerSecondRocketFuelGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); + } + + public GregtechRocketFuelGeneratorBase( + final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + int pollMin = (int) (CORE.ConfigSwitches.baseMinPollutionPerSecondRocketFuelGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); + int pollMax = (int) (CORE.ConfigSwitches.baseMaxPollutionPerSecondRocketFuelGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); + } + + @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 String[] getDescription() { + String aPollution = "Causes between " + pollMin + " and " + pollMax + " Pollution per second"; + return new String[] { + this.mDescription, "Fuel Efficiency: " + this.getEfficiency() + "%", aPollution, CORE.GT_Tooltip + }; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1]}; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + 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 boolean isFacingValid(final byte aSide) { + return aSide > 1; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return aIndex < 2; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return this.getBaseMetaTileEntity().getFrontFacing() == aSide; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public long maxEUOutput() { + return V[this.mTier]; + } + + @Override + public long maxEUStore() { + return Math.max(this.getEUVar(), (V[this.mTier] * 500) + this.getMinimumStoredEU()); + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return true; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public boolean isFluidInputAllowed(final FluidStack aFluid) { + return this.getFuelValue(aFluid) > 0; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + + // super.onPostTick(aBaseMetaTileEntity, aTick); + + /*if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10L == 0L) { + int tFuelValue; + if (this.mFluid == null) { + if (aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() + this.getMinimumStoredEU()) { + this.mInventory[this.getStackDisplaySlot()] = null; + } else { + if (this.mInventory[this.getStackDisplaySlot()] == null) { + this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); + } + + this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " + + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); + } + } else { + tFuelValue = this.getFuelValue(this.mFluid); + int tConsumed = this.consumedFluidPerOperation(this.mFluid); + if (tFuelValue > 0 && tConsumed > 0 && this.mFluid.amount > tConsumed) { + long tFluidAmountToUse = Math.min((long) (this.mFluid.amount / tConsumed), + (this.maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / (long) tFuelValue); + if (tFluidAmountToUse > 0L && aBaseMetaTileEntity + .increaseStoredEnergyUnits(tFluidAmountToUse * (long) tFuelValue, true)) { + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollution()); + this.mFluid.amount = (int) ((long) this.mFluid.amount - tFluidAmountToUse * (long) tConsumed); + } + } + } + + if (this.mInventory[this.getInputSlot()] != null + && aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() * 20L + + this.getMinimumStoredEU() + && GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null) { + tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); + if (tFuelValue > 0) { + ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); + if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits((long) tFuelValue, true); + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollution()); + } + } + } + } + + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity + .getUniversalEnergyStored() >= this.maxEUOutput() + this.getMinimumStoredEU()); + }*/ + + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && ((aTick % 10) == 0)) { + if (this.mFluid == null) { + if (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUOutput() + this.getMinimumStoredEU())) { + this.mInventory[this.getStackDisplaySlot()] = null; + } else { + if (this.mInventory[this.getStackDisplaySlot()] == null) { + this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); + } + this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " + + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); + } + } else { + final int tFuelValue = this.getFuelValue(this.mFluid), + tConsumed = this.consumedFluidPerOperation(this.mFluid); + if ((tFuelValue > 0) && (tConsumed > 0) && (this.mFluid.amount >= tConsumed)) { + final long tFluidAmountToUse = Math.min( + this.mFluid.amount / tConsumed, + (((this.maxEUOutput() * 20) + this.getMinimumStoredEU()) + - aBaseMetaTileEntity.getUniversalEnergyStored()) + / tFuelValue); + if ((tFluidAmountToUse > 0) + && aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true)) { + int aSafeFloor = (int) Math.max(((tFluidAmountToUse * tConsumed) / 3), 1); + this.mFluid.amount -= (int) aSafeFloor; + PollutionUtils.addPollution(getBaseMetaTileEntity(), 10 * getPollution()); + } + } + } + if ((this.mInventory[this.getInputSlot()] != null) + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())) + && (GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null)) { + final int tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); + if (tFuelValue > 0) { + final ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); + if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + PollutionUtils.addPollution(getBaseMetaTileEntity(), 10 * getPollution()); + } + } + } + } + + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() + && (aBaseMetaTileEntity.getUniversalEnergyStored() + >= (this.maxEUOutput() + this.getMinimumStoredEU()))); + } + } + + public int getPollution() { + return MathUtils.randInt(pollMin, pollMax); + } + + public abstract GT_Recipe_Map getRecipes(); + + public abstract int getEfficiency(); + + public int consumedFluidPerOperation(final FluidStack aLiquid) { + return 1; + } + + public int getFuelValue(final FluidStack aLiquid) { + if ((aLiquid == null) || (this.getRecipes() == null)) { + return 0; + } + FluidStack tLiquid; + final Collection<GT_Recipe> tRecipeList = this.getRecipes().mRecipeList; + if (tRecipeList != null) { + // Logger.INFO("Step A"); + for (final GT_Recipe tFuel : tRecipeList) { + // Logger.INFO("Step B"); + if ((tLiquid = tFuel.mFluidInputs[0]) != null) { + // Logger.INFO("Step C"); + if (aLiquid.isFluidEqual(tLiquid)) { + // Logger.INFO("Found some fuel?"); + int aperOp = this.consumedFluidPerOperation(tLiquid); + int aConsume = (int) (((long) tFuel.mSpecialValue * this.getEfficiency() * aperOp) / 100); + // Logger.INFO("Fuel Value: "+tFuel.mSpecialValue); + // Logger.INFO("Efficiency: "+getEfficiency()); + // Logger.INFO("Consumed per op: "+aperOp); + // Logger.INFO("Consuming "+aConsume); + return aConsume; + } + } + } + } + // Logger.INFO("No Fuel Value | Valid? "+(aLiquid != null)); + return 0; + } + + public int getFuelValue(final ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { + return 0; + } + final GT_Recipe tFuel = + this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); + if (tFuel != null) { + return (int) ((tFuel.mSpecialValue * 1000L * this.getEfficiency()) / 100); + } + return 0; + } + + public ItemStack getEmptyContainer(final ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { + return null; + } + final GT_Recipe tFuel = + this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); + if (tFuel != null) { + return GT_Utility.copy(tFuel.getOutput(0)); + } + return GT_Utility.getContainerItem(aStack, true); + } + + @Override + public boolean allowPutStack( + final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) + && ((this.getFuelValue(aStack) > 0) + || (this.getFuelValue(GT_Utility.getFluidForFilledItem(aStack, true)) > 0)); + } + + @Override + public int getCapacity() { + return 32000; + } + + @Override + public int getTankPressure() { + return -100; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaSafeBlockBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaSafeBlockBase.java index 34b3e86c70..a76ed88a17 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaSafeBlockBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaSafeBlockBase.java @@ -2,290 +2,310 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.machine import static gregtech.api.enums.GT_Values.V; -import java.util.UUID; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.player.PlayerCache; +import java.util.UUID; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public abstract class GregtechMetaSafeBlockBase extends GT_MetaTileEntity_TieredMachineBlock { - public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false, bUnbreakable = false; - public int mSuccess = 0, mTargetStackSize = 0; - public UUID ownerUUID; - //UnbreakableBlockManager Xasda = new UnbreakableBlockManager(); - private boolean value_last = false, value_current = false; - - public GregtechMetaSafeBlockBase(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 GregtechMetaSafeBlockBase(final String aName, final int aTier, final int aInvSlotCount, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aInvSlotCount, aDescription, aTextures); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[6][17][]; - final ITexture tIcon = this.getOverlayIcon(), tOut = new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_QCHEST), tUp = new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT); - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tUp, tIcon}; //Back - rTextures[1][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tIcon}; // Right, Strangely The top side as well when facing East? - rTextures[2][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tIcon}; // Top And Bottom, When Facing South (What the hell?) - rTextures[3][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tIcon}; // Left, Top if facing West and Bottom if facing east? - rTextures[4][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tIcon}; // Top and Bottom when Facing North.. - rTextures[5][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tOut}; // Front - } - 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[5][aColorIndex + 1]; - } - if (GT_Utility.getOppositeSide(aSide) == aFacing) { - return this.mTextures[0][aColorIndex + 1]; - } - switch (aFacing) { - case 0: - return this.mTextures[4][aColorIndex + 1]; - case 1: - return this.mTextures[2][aColorIndex + 1]; - case 2: - switch (aSide) { - case 0: - return this.mTextures[2][aColorIndex + 1]; - case 1: - return this.mTextures[2][aColorIndex + 1]; - case 4: - return this.mTextures[1][aColorIndex + 1]; - case 5: - return this.mTextures[3][aColorIndex + 1]; - } - case 3: - switch (aSide) { - case 0: - return this.mTextures[4][aColorIndex + 1]; - case 1: - return this.mTextures[4][aColorIndex + 1]; - case 4: - return this.mTextures[3][aColorIndex + 1]; - case 5: - return this.mTextures[1][aColorIndex + 1]; - } - case 4: - switch (aSide) { - case 0: - return this.mTextures[3][aColorIndex + 1]; - case 1: - return this.mTextures[1][aColorIndex + 1]; - case 2: - return this.mTextures[3][aColorIndex + 1]; - case 3: - return this.mTextures[1][aColorIndex + 1]; - } - case 5: - switch (aSide) { - case 0: - return this.mTextures[1][aColorIndex + 1]; - case 1: - return this.mTextures[3][aColorIndex + 1]; - case 2: - return this.mTextures[1][aColorIndex + 1]; - case 3: - return this.mTextures[3][aColorIndex + 1]; - } - } - return this.mTextures[5][aColorIndex + 1]; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return aIndex < (this.mInventory.length - 1); - } - - @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 !this.isOutputFacing(aSide); - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return this.getBaseMetaTileEntity().getBackFacing() == aSide; - } - - @Override - public boolean isTeleporterCompatible() { - return false; - } - - @Override - public long getMinimumStoredEU() { - return 512; - } - - @Override - public long maxEUStore() { - return 512 + (V[this.mTier] * 50); - } - - @Override - public long maxEUInput() { - return V[this.mTier]; - } - - @Override - public long maxEUOutput() { - return this.bOutput ? V[this.mTier] : 0; - } - - @Override - public long maxAmperesIn() { - return 1; - } - - @Override - public long maxAmperesOut() { - return 1; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - public abstract ITexture getOverlayIcon(); - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - - if (aBaseMetaTileEntity.isClientSide()) { - //Utils.LOG_WARNING("Clicky Clicky."); - return true; - - } - if (aPlayer != null) { - final UUID tempUUID = aPlayer.getUniqueID(); - /*if (!aPlayer.worldObj.isRemote){ - //PlayerCache.appendParamChanges(aPlayer.getDisplayName(), aPlayer.getUniqueID().toString()); - }*/ - //Utils.LOG_INFO("test"); - if (this.ownerUUID == null){ - Logger.INFO("No owner yet for this block."); - } - else { - //Utils.LOG_INFO("test"); - Logger.INFO("Current Owner: "+PlayerCache.lookupPlayerByUUID(this.ownerUUID)+" - UUID: "+this.ownerUUID); - } - Logger.WARNING("Is ownerUUID Null"); - if (this.ownerUUID == null){ - Logger.WARNING("OwnerUUID is Null, let's set it."); - Logger.WARNING("Accessing Players UUID is: "+tempUUID); - this.ownerUUID = tempUUID; - //Utils.messagePlayer(aPlayer, "Owner of this safe, now set. Try accessing it again."); - Logger.WARNING("Block Owner is now set to: "+this.ownerUUID); - } - Logger.WARNING("No, it is not."); - Logger.WARNING("Checking ownerUUID."); - if (this.ownerUUID != null){ - Logger.WARNING("ownerUUID != Null, if accessor == owner."); - Logger.WARNING("Accessing is: "+PlayerCache.lookupPlayerByUUID(tempUUID)); - if (this.ownerUUID.equals(tempUUID)){ - Logger.WARNING("Owner's UUID: "+this.ownerUUID); - aBaseMetaTileEntity.openGUI(aPlayer); - //Utils.LOG_WARNING("GUI should now be open for you sir."); - } - else { - PlayerUtils.messagePlayer(aPlayer, "Access Denied, This does not belong to you."); - PlayerUtils.messagePlayer(aPlayer, "it is owned by: "+PlayerCache.lookupPlayerByUUID(this.ownerUUID)); - Logger.WARNING("Expecting Player : "+PlayerCache.lookupPlayerByUUID(this.ownerUUID)); - Logger.ERROR("Access Denied."); - return true; - } - - } - - /*else { - Utils.LOG_ERROR("This is NOT good. Tell Draknyte1 your safe broke."); - }*/ - /*Utils.LOG_WARNING("Clicky Clicky."); - Utils.messagePlayer(aPlayer, "Owner of this safe, now set."); - aBaseMetaTileEntity.openGUI(aPlayer); */ - - } - return true; - } - - @Override - public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setBoolean("bUnbreakable", this.bUnbreakable); - aNBT.setBoolean("bOutput", this.bOutput); - aNBT.setBoolean("bRedstoneIfFull", this.bRedstoneIfFull); - aNBT.setInteger("mTargetStackSize", this.mTargetStackSize); - if (this.ownerUUID != null) { - aNBT.setString("ownerUUID", this.ownerUUID.toString()); - } - } - - @Override - public void loadNBTData(final NBTTagCompound aNBT) { - this.bUnbreakable = aNBT.getBoolean("bUnbreakable"); - this.bOutput = aNBT.getBoolean("bOutput"); - this.bRedstoneIfFull = aNBT.getBoolean("bRedstoneIfFull"); - this.mTargetStackSize = aNBT.getInteger("mTargetStackSize"); - if (aNBT.hasKey("ownerUUID")) { - this.ownerUUID = UUID.fromString(aNBT.getString("ownerUUID")); - } - } - - @Override - public void setItemNBT(final NBTTagCompound aNBT) { - super.setItemNBT(aNBT); - if (this.mTargetStackSize > 0) { - aNBT.setInteger("mTargetStackSize", this.mTargetStackSize); - } - } - - - @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 aSide != aBaseMetaTileEntity.getBackFacing(); - } -}
\ No newline at end of file + public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false, bUnbreakable = false; + public int mSuccess = 0, mTargetStackSize = 0; + public UUID ownerUUID; + // UnbreakableBlockManager Xasda = new UnbreakableBlockManager(); + private boolean value_last = false, value_current = false; + + public GregtechMetaSafeBlockBase( + 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 GregtechMetaSafeBlockBase( + final String aName, + final int aTier, + final int aInvSlotCount, + final String aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[6][17][]; + final ITexture tIcon = this.getOverlayIcon(), + tOut = new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_QCHEST), + tUp = new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT); + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = + new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tUp, tIcon}; // Back + rTextures[1][i + 1] = new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tIcon + }; // Right, Strangely The top side as well when facing East? + rTextures[2][i + 1] = new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tIcon + }; // Top And Bottom, When Facing South (What the hell?) + rTextures[3][i + 1] = new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tIcon + }; // Left, Top if facing West and Bottom if facing east? + rTextures[4][i + 1] = new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tIcon + }; // Top and Bottom when Facing North.. + rTextures[5][i + 1] = + new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[this.mTier][i + 1], tOut}; // Front + } + 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[5][aColorIndex + 1]; + } + if (GT_Utility.getOppositeSide(aSide) == aFacing) { + return this.mTextures[0][aColorIndex + 1]; + } + switch (aFacing) { + case 0: + return this.mTextures[4][aColorIndex + 1]; + case 1: + return this.mTextures[2][aColorIndex + 1]; + case 2: + switch (aSide) { + case 0: + return this.mTextures[2][aColorIndex + 1]; + case 1: + return this.mTextures[2][aColorIndex + 1]; + case 4: + return this.mTextures[1][aColorIndex + 1]; + case 5: + return this.mTextures[3][aColorIndex + 1]; + } + case 3: + switch (aSide) { + case 0: + return this.mTextures[4][aColorIndex + 1]; + case 1: + return this.mTextures[4][aColorIndex + 1]; + case 4: + return this.mTextures[3][aColorIndex + 1]; + case 5: + return this.mTextures[1][aColorIndex + 1]; + } + case 4: + switch (aSide) { + case 0: + return this.mTextures[3][aColorIndex + 1]; + case 1: + return this.mTextures[1][aColorIndex + 1]; + case 2: + return this.mTextures[3][aColorIndex + 1]; + case 3: + return this.mTextures[1][aColorIndex + 1]; + } + case 5: + switch (aSide) { + case 0: + return this.mTextures[1][aColorIndex + 1]; + case 1: + return this.mTextures[3][aColorIndex + 1]; + case 2: + return this.mTextures[1][aColorIndex + 1]; + case 3: + return this.mTextures[3][aColorIndex + 1]; + } + } + return this.mTextures[5][aColorIndex + 1]; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return aIndex < (this.mInventory.length - 1); + } + + @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 !this.isOutputFacing(aSide); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return this.getBaseMetaTileEntity().getBackFacing() == aSide; + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 512; + } + + @Override + public long maxEUStore() { + return 512 + (V[this.mTier] * 50); + } + + @Override + public long maxEUInput() { + return V[this.mTier]; + } + + @Override + public long maxEUOutput() { + return this.bOutput ? V[this.mTier] : 0; + } + + @Override + public long maxAmperesIn() { + return 1; + } + + @Override + public long maxAmperesOut() { + return 1; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + public abstract ITexture getOverlayIcon(); + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + + if (aBaseMetaTileEntity.isClientSide()) { + // Utils.LOG_WARNING("Clicky Clicky."); + return true; + } + if (aPlayer != null) { + final UUID tempUUID = aPlayer.getUniqueID(); + /*if (!aPlayer.worldObj.isRemote){ + //PlayerCache.appendParamChanges(aPlayer.getDisplayName(), aPlayer.getUniqueID().toString()); + }*/ + // Utils.LOG_INFO("test"); + if (this.ownerUUID == null) { + Logger.INFO("No owner yet for this block."); + } else { + // Utils.LOG_INFO("test"); + Logger.INFO("Current Owner: " + PlayerCache.lookupPlayerByUUID(this.ownerUUID) + " - UUID: " + + this.ownerUUID); + } + Logger.WARNING("Is ownerUUID Null"); + if (this.ownerUUID == null) { + Logger.WARNING("OwnerUUID is Null, let's set it."); + Logger.WARNING("Accessing Players UUID is: " + tempUUID); + this.ownerUUID = tempUUID; + // Utils.messagePlayer(aPlayer, "Owner of this safe, now set. Try accessing it again."); + Logger.WARNING("Block Owner is now set to: " + this.ownerUUID); + } + Logger.WARNING("No, it is not."); + Logger.WARNING("Checking ownerUUID."); + if (this.ownerUUID != null) { + Logger.WARNING("ownerUUID != Null, if accessor == owner."); + Logger.WARNING("Accessing is: " + PlayerCache.lookupPlayerByUUID(tempUUID)); + if (this.ownerUUID.equals(tempUUID)) { + Logger.WARNING("Owner's UUID: " + this.ownerUUID); + aBaseMetaTileEntity.openGUI(aPlayer); + // Utils.LOG_WARNING("GUI should now be open for you sir."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Access Denied, This does not belong to you."); + PlayerUtils.messagePlayer( + aPlayer, "it is owned by: " + PlayerCache.lookupPlayerByUUID(this.ownerUUID)); + Logger.WARNING("Expecting Player : " + PlayerCache.lookupPlayerByUUID(this.ownerUUID)); + Logger.ERROR("Access Denied."); + return true; + } + } + + /*else { + Utils.LOG_ERROR("This is NOT good. Tell Draknyte1 your safe broke."); + }*/ + /*Utils.LOG_WARNING("Clicky Clicky."); + Utils.messagePlayer(aPlayer, "Owner of this safe, now set."); + aBaseMetaTileEntity.openGUI(aPlayer); */ + + } + return true; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setBoolean("bUnbreakable", this.bUnbreakable); + aNBT.setBoolean("bOutput", this.bOutput); + aNBT.setBoolean("bRedstoneIfFull", this.bRedstoneIfFull); + aNBT.setInteger("mTargetStackSize", this.mTargetStackSize); + if (this.ownerUUID != null) { + aNBT.setString("ownerUUID", this.ownerUUID.toString()); + } + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.bUnbreakable = aNBT.getBoolean("bUnbreakable"); + this.bOutput = aNBT.getBoolean("bOutput"); + this.bRedstoneIfFull = aNBT.getBoolean("bRedstoneIfFull"); + this.mTargetStackSize = aNBT.getInteger("mTargetStackSize"); + if (aNBT.hasKey("ownerUUID")) { + this.ownerUUID = UUID.fromString(aNBT.getString("ownerUUID")); + } + } + + @Override + public void setItemNBT(final NBTTagCompound aNBT) { + super.setItemNBT(aNBT); + if (this.mTargetStackSize > 0) { + aNBT.setInteger("mTargetStackSize", this.mTargetStackSize); + } + } + + @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 aSide != aBaseMetaTileEntity.getBackFacing(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaTreeFarmerBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaTreeFarmerBase.java index df838f012a..39d61acebc 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaTreeFarmerBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaTreeFarmerBase.java @@ -1,176 +1,199 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.machines; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; - import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; public abstract class GregtechMetaTreeFarmerBase extends GT_MetaTileEntity_TieredMachineBlock { - public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false, bUnbreakable = false; - public int mSuccess = 0, mTargetStackSize = 0; - - public GregtechMetaTreeFarmerBase(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 GregtechMetaTreeFarmerBase(final String aName, final int aTier, final int aInvSlotCount, final String aDescription, final ITexture[][][] aTextures) { - super(aName, aTier, aInvSlotCount, aDescription, aTextures); - } - - @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 boolean isSimpleMachine() { - 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 !this.isOutputFacing(aSide); - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return this.getBaseMetaTileEntity().getBackFacing() == aSide; - } - - @Override - public boolean isTeleporterCompatible() { - return false; - } - - @Override - public long getMinimumStoredEU() { - return 0; - } - - @Override - public long maxEUStore() { - 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 isAccessAllowed(final EntityPlayer aPlayer) { - return false; - } - - public abstract ITexture getOverlayIcon(); - - - @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 ITexture[] getFront(final byte aColor) { - return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager)}; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager)}; - } - - 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.Casing_Machine_Podzol)}; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager)}; - } - - public ITexture[] getFrontActive(final byte aColor) { - return this.getFront(aColor); - } - - 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); - } -}
\ No newline at end of file + public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false, bUnbreakable = false; + public int mSuccess = 0, mTargetStackSize = 0; + + public GregtechMetaTreeFarmerBase( + 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 GregtechMetaTreeFarmerBase( + final String aName, + final int aTier, + final int aInvSlotCount, + final String aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @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 boolean isSimpleMachine() { + 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 !this.isOutputFacing(aSide); + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return this.getBaseMetaTileEntity().getBackFacing() == aSide; + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + 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 isAccessAllowed(final EntityPlayer aPlayer) { + return false; + } + + public abstract ITexture getOverlayIcon(); + + @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 ITexture[] getFront(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager)}; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager)}; + } + + 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.Casing_Machine_Podzol)}; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager)}; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + 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); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java index 5e0918059d..46666114c1 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java @@ -9,7 +9,7 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_Hatch_Catalysts extends GT_MetaTileEntity_Hatch_NbtConsumable { - + public GT_MetaTileEntity_Hatch_Catalysts(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional, 0, 16, "Dedicated Catalyst Storage", false); } @@ -17,55 +17,53 @@ public class GT_MetaTileEntity_Hatch_Catalysts extends GT_MetaTileEntity_Hatch_N public GT_MetaTileEntity_Hatch_Catalysts(String aName, String aDescription, ITexture[][][] aTextures) { super(aName, 0, 16, aDescription, false, aTextures); } - + public GT_MetaTileEntity_Hatch_Catalysts(String aName, String[] aDescription, ITexture[][][] aTextures) { super(aName, 0, 16, aDescription[0], false, aTextures); } @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Catalyst)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Catalyst)}; } @Override public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Catalyst)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Catalyst)}; + } + + @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 boolean isFacingValid(byte aFacing) { return true; } - @Override - public Class<? extends GT_MetaTileEntity_Hatch_NbtConsumable> getHatchEntityClass() { - return GT_MetaTileEntity_Hatch_Catalysts.class; - } + @Override + public Class<? extends GT_MetaTileEntity_Hatch_NbtConsumable> getHatchEntityClass() { + return GT_MetaTileEntity_Hatch_Catalysts.class; + } - @Override - public String getNameGUI() { - return "Catalyst Container"; - } + @Override + public String getNameGUI() { + return "Catalyst Container"; + } - @Override - public AutoMap<ItemStack> getItemsValidForUsageSlots() { - return new AutoMap<ItemStack>(); - } + @Override + public AutoMap<ItemStack> getItemsValidForUsageSlots() { + return new AutoMap<ItemStack>(); + } - @Override - public boolean isItemValidForUsageSlot(ItemStack aStack) { - return ItemUtils.isCatalyst(aStack); - } + @Override + public boolean isItemValidForUsageSlot(ItemStack aStack) { + return ItemUtils.isCatalyst(aStack); + } - @Override - public int getInputSlotCount() { - return 16; - } + @Override + public int getInputSlotCount() { + return 16; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_MillingBalls.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_MillingBalls.java index 0f10272ad7..265088a9e0 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_MillingBalls.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_MillingBalls.java @@ -9,7 +9,7 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_Hatch_MillingBalls extends GT_MetaTileEntity_Hatch_NbtConsumable { - + public GT_MetaTileEntity_Hatch_MillingBalls(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional, 6, 4, "Dedicated Milling Ball Storage", false); } @@ -17,55 +17,53 @@ public class GT_MetaTileEntity_Hatch_MillingBalls extends GT_MetaTileEntity_Hatc public GT_MetaTileEntity_Hatch_MillingBalls(String aName, String aDescription, ITexture[][][] aTextures) { super(aName, 6, 4, aDescription, false, aTextures); } - + public GT_MetaTileEntity_Hatch_MillingBalls(String aName, String[] aDescription, ITexture[][][] aTextures) { super(aName, 6, 4, aDescription[0], false, aTextures); } @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Milling_Balls)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Milling_Balls)}; } @Override public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Milling_Balls)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Milling_Balls)}; + } + + @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 boolean isFacingValid(byte aFacing) { return true; } - @Override - public Class<? extends GT_MetaTileEntity_Hatch_NbtConsumable> getHatchEntityClass() { - return GT_MetaTileEntity_Hatch_MillingBalls.class; - } + @Override + public Class<? extends GT_MetaTileEntity_Hatch_NbtConsumable> getHatchEntityClass() { + return GT_MetaTileEntity_Hatch_MillingBalls.class; + } - @Override - public String getNameGUI() { - return "Ball Housing"; - } + @Override + public String getNameGUI() { + return "Ball Housing"; + } - @Override - public AutoMap<ItemStack> getItemsValidForUsageSlots() { - return new AutoMap<ItemStack>(); - } + @Override + public AutoMap<ItemStack> getItemsValidForUsageSlots() { + return new AutoMap<ItemStack>(); + } - @Override - public boolean isItemValidForUsageSlot(ItemStack aStack) { - return ItemUtils.isMillingBall(aStack); - } + @Override + public boolean isItemValidForUsageSlot(ItemStack aStack) { + return ItemUtils.isMillingBall(aStack); + } - @Override - public int getInputSlotCount() { - return 4; - } + @Override + public int getInputSlotCount() { + return 4; + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_NbtConsumable.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_NbtConsumable.java index 552042a4c5..5d232836b4 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_NbtConsumable.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_NbtConsumable.java @@ -1,7 +1,5 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers; -import java.lang.reflect.Constructor; - import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -15,269 +13,308 @@ import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.gui.hatches.CONTAINER_HatchNbtConsumable; import gtPlusPlus.xmod.gregtech.api.gui.hatches.GUI_HatchNbtConsumable; import gtPlusPlus.xmod.gregtech.common.StaticFields59; +import java.lang.reflect.Constructor; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public abstract class GT_MetaTileEntity_Hatch_NbtConsumable extends GT_MetaTileEntity_Hatch { - public GT_Recipe_Map mRecipeMap = null; - private final int mInputslotCount; - private final int mTotalSlotCount; - private final boolean mAllowDuplicateUsageTypes; - - public GT_MetaTileEntity_Hatch_NbtConsumable(int aID, String aName, String aNameRegional, int aTier, int aInputSlots, String aDescription, boolean aAllowDuplicateTypes) { - super(aID, aName, aNameRegional, aTier, aInputSlots*2, aDescription); - mInputslotCount = getInputSlotCount(); - mTotalSlotCount = getInputSlotCount()*2; - mAllowDuplicateUsageTypes = aAllowDuplicateTypes; - } - - public GT_MetaTileEntity_Hatch_NbtConsumable(String aName, int aTier, int aInputSlots, String aDescription, boolean aAllowDuplicateTypes, ITexture[][][] aTextures) { - super(aName, aTier, aInputSlots*2, aDescription, aTextures); - mInputslotCount = getInputSlotCount(); - mTotalSlotCount = getInputSlotCount()*2; - mAllowDuplicateUsageTypes = aAllowDuplicateTypes; - } - - public GT_MetaTileEntity_Hatch_NbtConsumable(String aName, int aTier, int aInputSlots, String[] aDescription, boolean aAllowDuplicateTypes, ITexture[][][] aTextures) { - super(aName, aTier, aInputSlots*2, aDescription, aTextures); - mInputslotCount = getInputSlotCount(); - mTotalSlotCount = getInputSlotCount()*2; - mAllowDuplicateUsageTypes = aAllowDuplicateTypes; - } - - @Override - public abstract ITexture[] getTexturesActive(ITexture aBaseTexture); - - @Override - public abstract ITexture[] getTexturesInactive(ITexture aBaseTexture); - - public abstract int getInputSlotCount(); - - @Override - public final boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public final boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public final boolean isValidSlot(int aIndex) { - return true; - } - - @Override - public final MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - Constructor<?> aConstructor = ReflectionUtils.getConstructor(getHatchEntityClass(), new Class[] {String.class, String[].class, ITexture[][][].class}); - GT_MetaTileEntity_Hatch_NbtConsumable aInstance = ReflectionUtils.createNewInstanceFromConstructor(aConstructor, new Object[] {mName, StaticFields59.getDescriptionArray(this), mTextures}); - if (aInstance instanceof GT_MetaTileEntity_Hatch_NbtConsumable) { - GT_MetaTileEntity_Hatch_NbtConsumable aMetaTile = (GT_MetaTileEntity_Hatch_NbtConsumable) aInstance; - return aMetaTile; - } - return null; - } - - public abstract Class<? extends GT_MetaTileEntity_Hatch_NbtConsumable> getHatchEntityClass(); - - @Override - public final boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); - return true; - } - - @Override - public final Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_HatchNbtConsumable(aPlayerInventory, aBaseMetaTileEntity, mInputslotCount); - } - - @Override - public final Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - CONTAINER_HatchNbtConsumable aContainer = new CONTAINER_HatchNbtConsumable(aPlayerInventory, aBaseMetaTileEntity, mInputslotCount); - return new GUI_HatchNbtConsumable(aContainer, getNameGUI()); - } - - public abstract String getNameGUI(); - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - validateUsageSlots(); - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { - fillStacksIntoFirstSlots(); - tryFillUsageSlots(); - } - } - - public final void updateSlots() { - for (int i = 0; i < mInventory.length; i++) { - if (mInventory[i] != null && mInventory[i].stackSize <= 0) { - mInventory[i] = null; - } - // Only moves items in the first four slots - if (i <= getSlotID_LastInput()) { - fillStacksIntoFirstSlots(); - } - } - } - - protected void validateUsageSlots() { - for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { - if (mInventory[i] != null && mInventory[i].stackSize < 1) { - mInventory[i] = null; - this.markDirty(); - } - } - } - - // Only moves items in the first four slots - protected final void fillStacksIntoFirstSlots() { - for (int i = 0; i <= getSlotID_LastInput() ; i++) { - for (int j = i + 1; j <= getSlotID_LastInput(); j++) { - if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { - GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } - } - } - } - - public final void tryFillUsageSlots() { - int aSlotSpace = (mInputslotCount - getContentUsageSlots().size()); - if (aSlotSpace > 0) { - Logger.INFO("We have empty usage slots. "+aSlotSpace); - for (int i=getSlotID_FirstInput();i<=getSlotID_LastInput();i++) { - ItemStack aStackToTryMove = mInventory[i]; - if (aStackToTryMove != null && isItemValidForUsageSlot(aStackToTryMove)) { - Logger.INFO("Trying to move stack from input slot "+i); - if (moveItemFromStockToUsageSlots(aStackToTryMove)) { - Logger.INFO("Updating Slots."); - updateSlots(); - } - } - } - } - } - - private int getSlotID_FirstInput() { - return 0; - } - private int getSlotID_LastInput() { - return mInputslotCount-1; - } - private int getSlotID_FirstUsage() { - return mInputslotCount; - } - private int getSlotID_LastUsage() { - return mTotalSlotCount-1; - } - - - public final AutoMap<ItemStack> getContentUsageSlots() { - AutoMap<ItemStack> aItems = new AutoMap<ItemStack>(); - for (int i=mInputslotCount;i<mTotalSlotCount;i++) { - if (mInventory[i] != null) { - aItems.add(mInventory[i]); - } - } - return aItems; - } - - - public final boolean moveItemFromStockToUsageSlots(ItemStack aStack) { - return moveItemFromStockToUsageSlots(aStack, mAllowDuplicateUsageTypes); - } - - public final boolean moveItemFromStockToUsageSlots(ItemStack aStack, boolean aAllowMultiOfSameTypeInUsageSlots) { - if (aStack != null) { - if (aStack.stackSize > 0) { - - if (!isItemValidForUsageSlot(aStack)) { - Logger.INFO("Stack not valid: "+ItemUtils.getItemName(aStack)); - return false; - } - - // Copy the input stack into a new object - ItemStack aStackToMove = aStack.copy(); - // Set stack size of stack to move to 1. - aStackToMove.stackSize = 1; - // Did we set a stack in the usage slots? - boolean aDidSet = false; - // Did we find another of this item already in the usage slots? - boolean aFoundMatching = false; - // Continue processing with our new stack - // First check for duplicates - for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { - if (mInventory[i] != null) { - if (GT_Utility.areStacksEqual(aStackToMove, mInventory[i], true)) { - Logger.INFO("Found matching stack in slot "+i+"."); - aFoundMatching = true; - break; - } - } - } - // Then Move stack to Usage slots - for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { - if (mInventory[i] == null) { - if ((aFoundMatching && aAllowMultiOfSameTypeInUsageSlots) || !aFoundMatching) { - mInventory[i] = aStackToMove; - aDidSet = true; - Logger.INFO("Moving new stack to usage slots."); - break; - } - } - } - if (aDidSet) { - Logger.INFO("Depleting input stack size by 1."); - // Depleted one from the original input stack - aStack.stackSize--; - } - return aDidSet; - } - } - return false; - } - - @Override - public final boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public final boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aSide == getBaseMetaTileEntity().getFrontFacing() && isItemValidForUsageSlot(aStack) && aIndex < mInputslotCount; - } - - /** - * Items that get compared when checking for Usage Slot validity. - * Can return an empty map if isItemValidForUsageSlot() is overridden. - * @return - */ - public abstract AutoMap<ItemStack> getItemsValidForUsageSlots(); - - /** - * Checks if the given item is valid for Usage Slots. - * Can be overridden for easier handling if you already have methods to check this. - * @param aStack - * @return - */ - public boolean isItemValidForUsageSlot(ItemStack aStack) { - if (aStack != null) { - for (ItemStack aValid : getItemsValidForUsageSlots()) { - if (GT_Utility.areStacksEqual(aStack, aValid, true)) { - return true; - } - } - } - return false; - } + public GT_Recipe_Map mRecipeMap = null; + private final int mInputslotCount; + private final int mTotalSlotCount; + private final boolean mAllowDuplicateUsageTypes; + + public GT_MetaTileEntity_Hatch_NbtConsumable( + int aID, + String aName, + String aNameRegional, + int aTier, + int aInputSlots, + String aDescription, + boolean aAllowDuplicateTypes) { + super(aID, aName, aNameRegional, aTier, aInputSlots * 2, aDescription); + mInputslotCount = getInputSlotCount(); + mTotalSlotCount = getInputSlotCount() * 2; + mAllowDuplicateUsageTypes = aAllowDuplicateTypes; + } + + public GT_MetaTileEntity_Hatch_NbtConsumable( + String aName, + int aTier, + int aInputSlots, + String aDescription, + boolean aAllowDuplicateTypes, + ITexture[][][] aTextures) { + super(aName, aTier, aInputSlots * 2, aDescription, aTextures); + mInputslotCount = getInputSlotCount(); + mTotalSlotCount = getInputSlotCount() * 2; + mAllowDuplicateUsageTypes = aAllowDuplicateTypes; + } + + public GT_MetaTileEntity_Hatch_NbtConsumable( + String aName, + int aTier, + int aInputSlots, + String[] aDescription, + boolean aAllowDuplicateTypes, + ITexture[][][] aTextures) { + super(aName, aTier, aInputSlots * 2, aDescription, aTextures); + mInputslotCount = getInputSlotCount(); + mTotalSlotCount = getInputSlotCount() * 2; + mAllowDuplicateUsageTypes = aAllowDuplicateTypes; + } + + @Override + public abstract ITexture[] getTexturesActive(ITexture aBaseTexture); + + @Override + public abstract ITexture[] getTexturesInactive(ITexture aBaseTexture); + + public abstract int getInputSlotCount(); + + @Override + public final boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public final boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public final boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public final MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + Constructor<?> aConstructor = ReflectionUtils.getConstructor( + getHatchEntityClass(), new Class[] {String.class, String[].class, ITexture[][][].class}); + GT_MetaTileEntity_Hatch_NbtConsumable aInstance = ReflectionUtils.createNewInstanceFromConstructor( + aConstructor, new Object[] {mName, StaticFields59.getDescriptionArray(this), mTextures}); + if (aInstance instanceof GT_MetaTileEntity_Hatch_NbtConsumable) { + GT_MetaTileEntity_Hatch_NbtConsumable aMetaTile = (GT_MetaTileEntity_Hatch_NbtConsumable) aInstance; + return aMetaTile; + } + return null; + } + + public abstract Class<? extends GT_MetaTileEntity_Hatch_NbtConsumable> getHatchEntityClass(); + + @Override + public final boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public final Object getServerGUI( + int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_HatchNbtConsumable(aPlayerInventory, aBaseMetaTileEntity, mInputslotCount); + } + + @Override + public final Object getClientGUI( + int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + CONTAINER_HatchNbtConsumable aContainer = + new CONTAINER_HatchNbtConsumable(aPlayerInventory, aBaseMetaTileEntity, mInputslotCount); + return new GUI_HatchNbtConsumable(aContainer, getNameGUI()); + } + + public abstract String getNameGUI(); + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + validateUsageSlots(); + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + tryFillUsageSlots(); + } + } + + public final void updateSlots() { + for (int i = 0; i < mInventory.length; i++) { + if (mInventory[i] != null && mInventory[i].stackSize <= 0) { + mInventory[i] = null; + } + // Only moves items in the first four slots + if (i <= getSlotID_LastInput()) { + fillStacksIntoFirstSlots(); + } + } + } + + protected void validateUsageSlots() { + for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { + if (mInventory[i] != null && mInventory[i].stackSize < 1) { + mInventory[i] = null; + this.markDirty(); + } + } + } + + // Only moves items in the first four slots + protected final void fillStacksIntoFirstSlots() { + for (int i = 0; i <= getSlotID_LastInput(); i++) { + for (int j = i + 1; j <= getSlotID_LastInput(); j++) { + if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + } + } + + public final void tryFillUsageSlots() { + int aSlotSpace = (mInputslotCount - getContentUsageSlots().size()); + if (aSlotSpace > 0) { + Logger.INFO("We have empty usage slots. " + aSlotSpace); + for (int i = getSlotID_FirstInput(); i <= getSlotID_LastInput(); i++) { + ItemStack aStackToTryMove = mInventory[i]; + if (aStackToTryMove != null && isItemValidForUsageSlot(aStackToTryMove)) { + Logger.INFO("Trying to move stack from input slot " + i); + if (moveItemFromStockToUsageSlots(aStackToTryMove)) { + Logger.INFO("Updating Slots."); + updateSlots(); + } + } + } + } + } + + private int getSlotID_FirstInput() { + return 0; + } + + private int getSlotID_LastInput() { + return mInputslotCount - 1; + } + + private int getSlotID_FirstUsage() { + return mInputslotCount; + } + + private int getSlotID_LastUsage() { + return mTotalSlotCount - 1; + } + + public final AutoMap<ItemStack> getContentUsageSlots() { + AutoMap<ItemStack> aItems = new AutoMap<ItemStack>(); + for (int i = mInputslotCount; i < mTotalSlotCount; i++) { + if (mInventory[i] != null) { + aItems.add(mInventory[i]); + } + } + return aItems; + } + + public final boolean moveItemFromStockToUsageSlots(ItemStack aStack) { + return moveItemFromStockToUsageSlots(aStack, mAllowDuplicateUsageTypes); + } + + public final boolean moveItemFromStockToUsageSlots(ItemStack aStack, boolean aAllowMultiOfSameTypeInUsageSlots) { + if (aStack != null) { + if (aStack.stackSize > 0) { + + if (!isItemValidForUsageSlot(aStack)) { + Logger.INFO("Stack not valid: " + ItemUtils.getItemName(aStack)); + return false; + } + + // Copy the input stack into a new object + ItemStack aStackToMove = aStack.copy(); + // Set stack size of stack to move to 1. + aStackToMove.stackSize = 1; + // Did we set a stack in the usage slots? + boolean aDidSet = false; + // Did we find another of this item already in the usage slots? + boolean aFoundMatching = false; + // Continue processing with our new stack + // First check for duplicates + for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { + if (mInventory[i] != null) { + if (GT_Utility.areStacksEqual(aStackToMove, mInventory[i], true)) { + Logger.INFO("Found matching stack in slot " + i + "."); + aFoundMatching = true; + break; + } + } + } + // Then Move stack to Usage slots + for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { + if (mInventory[i] == null) { + if ((aFoundMatching && aAllowMultiOfSameTypeInUsageSlots) || !aFoundMatching) { + mInventory[i] = aStackToMove; + aDidSet = true; + Logger.INFO("Moving new stack to usage slots."); + break; + } + } + } + if (aDidSet) { + Logger.INFO("Depleting input stack size by 1."); + // Depleted one from the original input stack + aStack.stackSize--; + } + return aDidSet; + } + } + return false; + } + + @Override + public final boolean allowPullStack( + IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public final boolean allowPutStack( + IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return aSide == getBaseMetaTileEntity().getFrontFacing() + && isItemValidForUsageSlot(aStack) + && aIndex < mInputslotCount; + } + + /** + * Items that get compared when checking for Usage Slot validity. + * Can return an empty map if isItemValidForUsageSlot() is overridden. + * @return + */ + public abstract AutoMap<ItemStack> getItemsValidForUsageSlots(); + + /** + * Checks if the given item is valid for Usage Slots. + * Can be overridden for easier handling if you already have methods to check this. + * @param aStack + * @return + */ + public boolean isItemValidForUsageSlot(ItemStack aStack) { + if (aStack != null) { + for (ItemStack aValid : getItemsValidForUsageSlots()) { + if (GT_Utility.areStacksEqual(aStack, aValid, true)) { + return true; + } + } + } + return false; + } } |