diff options
author | Johann Bernhardt <johann.bernhardt@tum.de> | 2021-12-12 19:38:06 +0100 |
---|---|---|
committer | Johann Bernhardt <johann.bernhardt@tum.de> | 2021-12-12 19:38:06 +0100 |
commit | 311ab89f93558233a40079f7cb16605b141b5346 (patch) | |
tree | c5f44ef47f441a57c5f57aa801f639c7879ed760 /src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines | |
parent | 896143b96132f5ac54aa8d8f7386f27487e5e530 (diff) | |
download | GT5-Unofficial-311ab89f93558233a40079f7cb16605b141b5346.tar.gz GT5-Unofficial-311ab89f93558233a40079f7cb16605b141b5346.tar.bz2 GT5-Unofficial-311ab89f93558233a40079f7cb16605b141b5346.zip |
Move sources and resources
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines')
72 files changed, 28502 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_WorldAccelerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_WorldAccelerator.java new file mode 100644 index 0000000000..129446c40d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_WorldAccelerator.java @@ -0,0 +1,328 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import static gregtech.api.enums.GT_Values.V; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import gregtech.api.enums.Textures; +import gregtech.api.enums.Textures.BlockIcons.CustomIcon; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_RenderedTexture; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import net.minecraftforge.common.util.ForgeDirection; + +public class GT_MetaTileEntity_WorldAccelerator extends GT_MetaTileEntity_TieredMachineBlock { + + public static String[] BlacklistedTileEntiyClassNames; + + private byte mMode = 0; // 0: RandomTicks around 1: TileEntities with range + // 1 + private static CustomIcon _mGTIco_Norm_Idle; + private static CustomIcon _mGTIco_Norm_Active; + private static CustomIcon _mGTIco_TE_Idle; + private static CustomIcon _mGTIco_TE_Active; + private static int[] mAccelerateStatic = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512, 512, 512, 512, 512, 512 }; + + @Override + public void registerIcons(IIconRegister aBlockIconRegister) { + super.registerIcons(aBlockIconRegister); + _mGTIco_Norm_Idle = new CustomIcon("iconsets/OVERLAY_ACCELERATOR"); + _mGTIco_Norm_Active = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_ACTIVE"); + _mGTIco_TE_Idle = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_TE"); + _mGTIco_TE_Active = new CustomIcon("iconsets/OVERLAY_ACCELERATOR_TE_ACTIVE"); + } + + @SideOnly(Side.CLIENT) + @Override + public void onValueUpdate(byte aValue) { + mMode = aValue; + } + + @Override + public byte getUpdateData() { + return mMode; + } + + public GT_MetaTileEntity_WorldAccelerator(int pID, String pName, String pNameRegional, int pTier) { + super(pID, pName, pNameRegional, pTier, 0, ""); + } + + @Override + public String[] getDescription() { + return new String[] { + String.format("Accelerating things (Radius: %d EU/t: %d Speed Bonus: x%d)", mTier, + getEnergyDemand(mTier, false), mAccelerateStatic[mTier]), + "Use a screwdriver to change mode", "To accelerate TileEntities, this machine has to be adjacent to it", + "This machine accepts up to 8 Amps", "Accelerating TileEntities doubles Energy-Demand"}; + + } + + public GT_MetaTileEntity_WorldAccelerator(String pName, int pTier, int pInvSlotCount, String pDescription, + ITexture[][][] pTextures) { + super(pName, pTier, pInvSlotCount, pDescription, pTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity pTileEntity) { + return new GT_MetaTileEntity_WorldAccelerator(mName, mTier, mInventory.length, mDescription, mTextures); + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] pTextures) { + return new ITexture[0][0][0]; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity pBaseMetaTileEntity, byte pSide, byte pFacing, byte pColorIndex, + boolean pActive, boolean pRedstone) { + if (mMode == 0) + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][pColorIndex + 1], + (pSide < 2) ? null + : pActive ? new GT_RenderedTexture(_mGTIco_Norm_Active) + : new GT_RenderedTexture(_mGTIco_Norm_Idle) }; + else + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][pColorIndex + 1], (pSide < 2) ? null + : pActive ? new GT_RenderedTexture(_mGTIco_TE_Active) : new GT_RenderedTexture(_mGTIco_TE_Idle) }; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity pBaseMetaTileEntity, int pIndex, byte pSide, ItemStack pStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity pBaseMetaTileEntity, int pIndex, byte pSide, ItemStack pStack) { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound pNBT) { + pNBT.setByte("mAccelMode", mMode); + } + + public static long getEnergyDemand(int pTier, boolean pIsAcceleratingTEs) { + return V[pTier] * (pIsAcceleratingTEs ? 6 : 3); + } + + @Override + public void loadNBTData(NBTTagCompound pNBT) { + mMode = pNBT.getByte("mAccelMode"); + } + + @Override + public boolean isAccessAllowed(EntityPlayer pPlayer) { + return true; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isInputFacing(byte aSide) { + return true; + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 512; + } + + @Override + public long maxEUStore() { + return 512 + V[mTier] * 50; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public long maxAmperesIn() { + return 8; + } + + private static String[] mModeStr = { "Blocks", "TileEntities" }; + + @Override + public void onScrewdriverRightClick(byte pSide, EntityPlayer pPlayer, float pX, float pY, float pZ) { + mMode = (byte) (mMode == 0x00 ? 0x01 : 0x00); + markDirty(); + PlayerUtils.messagePlayer(pPlayer, String.format("Switched mode to: %s", mModeStr[mMode])); + } + + @Override + public void onPostTick(IGregTechTileEntity pBaseMetaTileEntity, long pTick) { + try { + if (!pBaseMetaTileEntity.isServerSide()) + return; + + long tEnergyDemand = getEnergyDemand(mTier, (mMode == 1)); + + // Do we have enough energy to run? Or are we not allowed to run? + if (pBaseMetaTileEntity.getStoredEU() < tEnergyDemand || !pBaseMetaTileEntity.isAllowedToWork()) { + // Check if machine was active before + if (pBaseMetaTileEntity.isActive()) + pBaseMetaTileEntity.setActive(false); // Then disable it now + } else { + // Continue to drain power + if (pBaseMetaTileEntity.decreaseStoredEnergyUnits(tEnergyDemand, false)) { + World tWorld = pBaseMetaTileEntity.getWorld(); + // Limit the random ticks to once per second + if (mMode == 0) { + if (pTick % 20 == 0) + doAccelerateNormalBlocks(pBaseMetaTileEntity, tWorld); + } else + doAccelerateTileEntities(pBaseMetaTileEntity, tWorld); + + } else { + // Energy drain failed. Disable machine + if (pBaseMetaTileEntity.isActive()) + pBaseMetaTileEntity.setActive(false); + } + } + } catch (Exception e) { + Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.onPostTick.crash"); + Logger.ERROR(e.getMessage()); + } + } + + private void doAccelerateTileEntities(IGregTechTileEntity pBaseMetaTileEntity, World pWorld) { + try { + if (!pBaseMetaTileEntity.isActive()) + getBaseMetaTileEntity().setActive(true); + + for (ForgeDirection tDir : ForgeDirection.VALID_DIRECTIONS) { + TileEntity tTile = pBaseMetaTileEntity.getTileEntityAtSide((byte) tDir.ordinal()); + if (isTEBlackListed(tTile)) + continue; + + long tMaxTime = System.nanoTime() + 1000000; + for (int j = 0; j < mAccelerateStatic[mTier]; j++) { + tTile.updateEntity(); + if (System.nanoTime() > tMaxTime) + break; + } + } + } catch (Exception e) { + Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.doAccelerateTileEntities.crash"); + Logger.ERROR(e.getMessage()); + } + } + + private static List<String> _mBlacklistedTileEntities = new ArrayList<String>(); + + // Inspired by ChromatiCraft's TileAccelerator + private boolean isTEBlackListed(TileEntity pTile) { + if (pTile == null) + return true; // Obvious + if (!pTile.canUpdate()) + return true; // Skip if TE can't update at all + if (pTile.isInvalid()) + return true; // Obvious + + String tSimpleClassName = pTile.getClass().getSimpleName().toLowerCase(); + String tCanonicalName = pTile.getClass().getCanonicalName().toLowerCase(); + if (tSimpleClassName.contains("conduit") || tSimpleClassName.contains("wire") + || tSimpleClassName.contains("cable")) + return true; + if (tCanonicalName.contains("appeng") || tCanonicalName.contains("gregtech")) + // Don't accelerate ANY Gregtech machines! + return true; + for (String tS : BlacklistedTileEntiyClassNames) { + if (tCanonicalName.equalsIgnoreCase(tS)) + return true; + } + + return false; + } + + /** + * Accelerate normal blocks. Eats some power and adds randomTicks to every + * block within its working area (Tier-Number = radius) This does only + * affect blocks that implement the "RandomTick" method; Which is mostly + * used for grass growth and plants. + * + * @param pBaseMetaTileEntity + */ + private void doAccelerateNormalBlocks(IGregTechTileEntity pBaseMetaTileEntity, World pWorld) { + if (!pBaseMetaTileEntity.isActive()) + getBaseMetaTileEntity().setActive(true); + + Random rnd = new Random(); + int tX = pBaseMetaTileEntity.getXCoord(); + int tY = pBaseMetaTileEntity.getYCoord(); + int tZ = pBaseMetaTileEntity.getZCoord(); + + int tX1 = tX - mTier; + int tX2 = tX + mTier; + int tY1 = Math.max(tY - mTier, 0); // Limit to bedrock + int tY2 = Math.min(tY + mTier, 255); // Limit to build height + int tZ1 = tZ - mTier; + int tZ2 = tZ + mTier; + + for (int xi = tX1; xi <= tX2; xi++) + for (int yi = tY1; yi <= tY2; yi++) + for (int zi = tZ1; zi <= tZ2; zi++) + tryTickBlock(pWorld, xi, yi, zi, rnd); + + } + + /** + * Send a tick to the target block + * + * @param pWorld + * @param pX + * @param pY + * @param pZ + * @param pRnd + */ + private void tryTickBlock(World pWorld, int pX, int pY, int pZ, Random pRnd) { + try { + for (int j = 0; j < mTier; j++) { + Block tBlock = pWorld.getBlock(pX, pY, pZ); + if (tBlock.getTickRandomly()) + tBlock.updateTick(pWorld, pX, pY, pZ, pRnd); + } + } catch (Exception e) { + Logger.ERROR("GT_MetaTileEntity_WorldAccelerator.tryTickBlock.crash"); + Logger.ERROR(e.getMessage()); + } + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java new file mode 100644 index 0000000000..eb01823151 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java @@ -0,0 +1,789 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import static gregtech.api.enums.GT_Values.V; +import static gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils.mPollution; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.item.general.ItemAirFilter; +import gtPlusPlus.core.item.general.ItemBasicScrubberTurbine; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.gui.basic.CONTAINER_PollutionCleaner; +import gtPlusPlus.xmod.gregtech.api.gui.basic.GUI_PollutionCleaner; +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; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_BasicMachine { + + public int mPollutionReduction = 0; + protected int mBaseEff = 2500; + protected int mOptimalAirFlow = 0; + protected boolean mHasPollution = false; + protected int SLOT_ROTOR = 4; + protected int SLOT_FILTER = 5; + protected static boolean mPollutionEnabled = true; + + protected boolean mSaveRotor = false; + + public GregtechMetaAtmosphericReconditioner(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 2, "Making sure you don't live in Gwalior - Uses 2A", 2, 0, "Recycler.png", "", + new ITexture[]{ + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB) + }); + mPollutionEnabled = PollutionUtils.mPollution(); + } + + public GregtechMetaAtmosphericReconditioner(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 2, aDescription, aTextures, 2, 0, aGUIName, aNEIName); + mPollutionEnabled = PollutionUtils.mPollution(); + } + + /*public GregtechMetaAtmosphericReconditioner(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 2, aDescription, aTextures, 2, 0, aGUIName, aNEIName); + }*/ + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaAtmosphericReconditioner(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public String[] getDescription() { + + boolean highTier = this.mTier >= 7; + + String[] A = new String[]{ + this.mDescription, + highTier ? "Will attempt to remove 1/4 pollution from 8 surrounding chunks" : "", + highTier ? "If these chunks are not loaded, they will be ignored" : "", + "Requires a turbine rotor and an Air Filter [T1/T2] to run.", + "The turbine rotor must be manually inserted/replaced", + "Can be configured with a soldering iron to change modes", + "Low Efficiency: Removes half pollution, Turbine takes 50% dmg", + "High Efficiency: Removes full pollution, Turbine takes 100% dmg", + "Turbine Rotor will not break in LE mode", + "Insert an equal tier Conveyor Module to enable automation" + }; + if (!mPollutionEnabled) { + String[] B = new String[] { + "===============================================", + "Pollution is disabled, scrubbers will now have a bonus use", + "They are now able to remove ALL lingering pollution as GT ignores it", + "and it will linger forever!", + "===============================================", + }; + A = ArrayUtils.addAll(A, B); + } + return A; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); + aNBT.setBoolean("mSaveRotor", mSaveRotor); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mOptimalAirFlow = aNBT.getInteger("mOptimalAirFlow"); + this.mSaveRotor = aNBT.getBoolean("mSaveRotor"); + } + + @Override + public long maxAmperesIn() { + return 2; + } + + @Override + public long getMinimumStoredEU() { + return V[mTier] * 2; + } + + @Override + public long maxEUStore() { + return V[mTier] * 256; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + + //Get Current Pollution Amount. + int mCurrentPollution = getCurrentChunkPollution(); + boolean isIdle = true; + + //Get Inventory Item + ItemStack stackRotor = this.mInventory[SLOT_ROTOR]; + ItemStack stackFilter = this.mInventory[SLOT_FILTER]; + + //Power Drain + long drainEU = maxEUInput() * maxAmperesIn(); + if (aBaseMetaTileEntity.isActive() && aBaseMetaTileEntity.getStoredEU() >= drainEU){ + if(aBaseMetaTileEntity.decreaseStoredEnergyUnits(drainEU, false)){ + isIdle = false; + } + else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } + else if (!aBaseMetaTileEntity.isActive() && aBaseMetaTileEntity.getStoredEU() >= drainEU/4){ + if(aBaseMetaTileEntity.decreaseStoredEnergyUnits((drainEU/4), false)){ + isIdle = false; + } + else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } + else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + + //Only try once/sec. + if (!isIdle && aTick % 20L == 0L){ + + //Check if machine can work. + if ((aBaseMetaTileEntity.isAllowedToWork())){ + + //Enable machine animation/graphic + if (hasRotor(stackRotor) && hasAirFilter(stackFilter) && this.mHasPollution){ + if (!this.getBaseMetaTileEntity().isActive()) { + aBaseMetaTileEntity.setActive(true); + } + } + else if (!this.mHasPollution || mCurrentPollution <= 0 || stackRotor == null || stackFilter == null || !hasRotor(stackRotor) || !hasAirFilter(stackFilter)){ + if (!this.getBaseMetaTileEntity().isActive()) { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } + + //If Active. + if (aBaseMetaTileEntity.isActive()){ + + //Do nothing if there is no pollution. + if(this.mHasPollution && mCurrentPollution > 0){ + + //Only check every 30s. + if (!isIdle && aTick % (20L * 30) == 0L){ + mPollutionEnabled = PollutionUtils.mPollution(); + //Clear out pollution if it's disabled, because I am a nice gal. + if (!mPollution()) { + PollutionUtils.nullifyPollution(this.getBaseMetaTileEntity()); + } + } + + + + + //Use a Turbine + if(hasRotor(stackRotor) && hasAirFilter(stackFilter)){ + Logger.WARNING("Found Turbine."); + mBaseEff = (int) ((50.0F + (10.0F * ((GT_MetaGenerated_Tool) stackRotor.getItem()).getToolCombatDamage(stackRotor))) * 100); + mOptimalAirFlow = (int) Math.max(Float.MIN_NORMAL, ((GT_MetaGenerated_Tool) stackRotor.getItem()).getToolStats(stackRotor).getSpeedMultiplier() + * GT_MetaGenerated_Tool.getPrimaryMaterial(stackRotor).mToolSpeed * 50); + + //Make sure we have a valid Turbine and Eff/Airflow + if (this.mBaseEff > 0 && this.mOptimalAirFlow > 0){ + //Utils.LOG_WARNING("Pollution Cleaner [5]"); + + //Log Debug information. + Logger.WARNING("mBaseEff[1]:"+mBaseEff); + Logger.WARNING("mOptimalAirFlow[1]:"+mOptimalAirFlow); + + //Calculate The Voltage we are running + long tVoltage = drainEU; + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + //Check Sides for Air, + //More air means more pollution processing. + int mAirSides = getFreeSpaces(); + + int reduction = 0; + + //If no sides are free, how will you process the atmosphere? + if (mAirSides > 0){ + reduction += (((Math.max((tTier-2), 1)*2)*50)*mAirSides); //Was originally *100 + Logger.WARNING("mPollutionReduction[1]:"+reduction); + + //I stole this code + reduction = (MathUtils.safeInt((long)reduction*this.mBaseEff)/100000)*mAirSides*Math.max((tTier-2), 1); + Logger.WARNING("reduction[2]:"+reduction); + reduction = MathUtils.safeInt(((long)reduction/100)*this.mOptimalAirFlow); + Logger.WARNING("reduction[3]:"+reduction); + + mPollutionReduction = reduction; + + //Set a temp to remove variable to aleviate duplicate code. + int toRemove = 0; + + Logger.WARNING("mCurrentPollution[4]:"+mCurrentPollution); + if (reduction <= mCurrentPollution){ + //Clean some Air. + toRemove = reduction; + } + else { + //Makes sure we don't get negative pollution. + toRemove = mCurrentPollution; + } + + //We are good to clean + if (toRemove > 0){ + if (damageTurbineRotor() && damageAirFilter()){ + Logger.INFO("Removing "+toRemove+" pollution"); + removePollution(mSaveRotor ? (toRemove/2) : toRemove); + Logger.WARNING("mNewPollution[4]:"+getCurrentChunkPollution()); + } + else { + Logger.WARNING("Could not damage turbine rotor or Air Filter."); + aBaseMetaTileEntity.setActive(false); + } + } //End of pollution removal block. + } //End of valid air sides block. + } //End of valid toolstats block. + } //End of correct inventory item block. + else { + //Utils.LOG_WARNING("Wrong Tool metaitem Found."); + } + } + } + else if (!aBaseMetaTileEntity.isActive()) { + return; + } + } //End of can work block. + else { //Disable Machine. + //aBaseMetaTileEntity.setActive(false); + } + } //End of 1/sec action block. + else { + + if (hasRotor(stackRotor) && hasAirFilter(stackFilter) && this.mHasPollution && !isIdle && aBaseMetaTileEntity.isAllowedToWork()){ + aBaseMetaTileEntity.setActive(true); + } + else if (isIdle || !this.mHasPollution || mCurrentPollution <= 0 || stackRotor == null || stackFilter == null || !hasRotor(stackRotor) || !hasAirFilter(stackFilter)){ + aBaseMetaTileEntity.setActive(false); + } + + } + if (this.getBaseMetaTileEntity().isActive()) { + if (MathUtils.randInt(0, 5) <= 2) { + this.sendSound((byte) -120); + } + } + + } //End of is serverside block. + } + + + public int getCurrentChunkPollution(){ + int mCurrentChunkPollution = 0; + if (this.mTier < 7) { + mCurrentChunkPollution = PollutionUtils.getPollution(getBaseMetaTileEntity()); + } + else { + AutoMap<Chunk> aSurrounding = new AutoMap<Chunk>(); + World aWorld = this.getBaseMetaTileEntity().getWorld(); + int xPos = this.getBaseMetaTileEntity().getXCoord(); + int zPos = this.getBaseMetaTileEntity().getZCoord(); + Chunk a1 = aWorld.getChunkFromBlockCoords(xPos-32, zPos-32); + Chunk a2 = aWorld.getChunkFromBlockCoords(xPos-32, zPos); + Chunk a3 = aWorld.getChunkFromBlockCoords(xPos-32, zPos+32); + Chunk b1 = aWorld.getChunkFromBlockCoords(xPos, zPos-32); + Chunk b2 = aWorld.getChunkFromBlockCoords(xPos, zPos); + Chunk b3 = aWorld.getChunkFromBlockCoords(xPos, zPos+32); + Chunk c1 = aWorld.getChunkFromBlockCoords(xPos+32, zPos-32); + Chunk c2 = aWorld.getChunkFromBlockCoords(xPos+32, zPos); + Chunk c3 = aWorld.getChunkFromBlockCoords(xPos+32, zPos+32); + aSurrounding.put(a1); + aSurrounding.put(a2); + aSurrounding.put(a3); + aSurrounding.put(b1); + aSurrounding.put(b2); + aSurrounding.put(b3); + aSurrounding.put(c1); + aSurrounding.put(c2); + aSurrounding.put(c3); + for (Chunk r : aSurrounding) { + mCurrentChunkPollution += getPollutionInChunk(r); + } + } + if (mCurrentChunkPollution > 0){ + mHasPollution = true; + } + else { + mHasPollution = false; + } + return mCurrentChunkPollution; + } + + public int getPollutionInChunk(Chunk aChunk){ + int mCurrentChunkPollution = PollutionUtils.getPollution(aChunk); + if (mCurrentChunkPollution > 0){ + mHasPollution = true; + } + else { + mHasPollution = false; + } + return mCurrentChunkPollution; + } + + public boolean hasRotor(ItemStack rotorStack){ + if(rotorStack != null){ + if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { + return true; + } + if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool && rotorStack.getItemDamage() >= 170 && rotorStack.getItemDamage() <= 179){ + return true; + } + } + return false; + } + + public boolean damageTurbineRotor(){ + try{ + + boolean creativeRotor = false; + ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; + if (rotorStack == null) { + return false; + } + else { + if(rotorStack.getItem() instanceof GT_MetaGenerated_Tool_01) { + Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(rotorStack); + Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(rotorStack); + if (t1 == Materials._NULL && t2 == Materials._NULL){ + creativeRotor = true; + } + } + } + + if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { + long currentUse = ItemBasicScrubberTurbine.getFilterDamage(rotorStack); + //Remove broken Filter + if (rotorStack.getItemDamage() == 0 && currentUse >= 2500-10){ + this.mInventory[this.SLOT_FILTER] = null; + return false; + } + else if (rotorStack.getItemDamage() == 1 && currentUse >= 5000-10){ + this.mInventory[this.SLOT_FILTER] = null; + return false; + } + else { + //Do Damage + ItemAirFilter.setFilterDamage(rotorStack, currentUse+10); + Logger.WARNING("Rotor Damage: "+currentUse); + return true; + } + } + + if(mInventory[SLOT_ROTOR].getItem() instanceof GT_MetaGenerated_Tool_01 && + ((GT_MetaGenerated_Tool) mInventory[SLOT_ROTOR].getItem()).getToolStats(mInventory[SLOT_ROTOR]).getSpeedMultiplier()>0 && + GT_MetaGenerated_Tool.getPrimaryMaterial(mInventory[SLOT_ROTOR]).mToolSpeed>0 ) { + + long damageValue = (long) Math.floor(Math.abs(MathUtils.randFloat(1, 2) - MathUtils.randFloat(1, 3)) * (1 + 3 - 1) + 1); + double fDam = Math.floor(Math.abs(MathUtils.randFloat(1f, 2f) - MathUtils.randFloat(1f, 2f)) * (1f + 2f - 1f) + 1f); + damageValue -= fDam; + + //Logger.WARNING("Trying to do "+damageValue+" damage to the rotor. ["+fDam+"]"); + /*Materials M1 = GT_MetaGenerated_Tool.getPrimaryMaterial(this.mInventory[this.SLOT_ROTOR]); + Materials M2 = GT_MetaGenerated_Tool.getSecondaryMaterial(this.mInventory[this.SLOT_ROTOR]); + + Logger.WARNING("Trying to do "+damageValue+" damage to the rotor. [2]");*/ + + //Damage Rotor + //int rotorDurability = this.mInventory[this.SLOT_ROTOR].getItemDamage(); + long rotorDamage = creativeRotor ? 0 : GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + long rotorDurabilityMax = creativeRotor ? Integer.MAX_VALUE : GT_MetaGenerated_Tool.getToolMaxDamage(this.mInventory[this.SLOT_ROTOR]); + long rotorDurability = (rotorDurabilityMax - rotorDamage); + Logger.WARNING("Rotor Damage: "+rotorDamage + " | Max Durability: "+rotorDurabilityMax+" | "+" Remaining Durability: "+rotorDurability); + if (rotorDurability >= damageValue){ + + + if (!mSaveRotor){ + Logger.WARNING("Damaging Rotor."); + + if (!creativeRotor) + GT_ModHandler.damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue, 0, null); + + long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + if (tempDur < rotorDurabilityMax){ + return true; + } + else { + rotorDurability = 0; + } + } + else { + Logger.WARNING("Damaging Rotor."); + if (rotorDurability > 1000){ + if (!creativeRotor) + GT_ModHandler.damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue/2, 0, null); + long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + if (tempDur < rotorDurabilityMax){ + return true; + } + else { + rotorDurability = 0; + } + } + } + + + } + + if (rotorDurability <= 0 && !mSaveRotor && !creativeRotor) { + Logger.WARNING("Destroying Rotor."); + this.mInventory[this.SLOT_ROTOR] = null; + return false; + } + else if (rotorDurability <= 0 && mSaveRotor) { + Logger.WARNING("Saving Rotor."); + return false; + } + + + }else { + Logger.WARNING("Bad Rotor."); + return false; + } + } + catch (Throwable t){} + return false; + } + + public int getFreeSpaces(){ + int mAir = 0; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int x = aBaseMetaTileEntity.getXCoord(); + int y = aBaseMetaTileEntity.getYCoord(); + int z = aBaseMetaTileEntity.getZCoord(); + if(aBaseMetaTileEntity.getAirOffset(x+1, y, z)){ + mAir++; + } + if(aBaseMetaTileEntity.getAirOffset(x-1, y, z)){ + mAir++; + } + if(aBaseMetaTileEntity.getAirOffset(x, y, z+1)){ + mAir++; + } + if(aBaseMetaTileEntity.getAirOffset(x, y, z-1)){ + mAir++; + } + if(aBaseMetaTileEntity.getAirOffset(x, y+1, z)){ + mAir++; + } + if(aBaseMetaTileEntity.getAirOffset(x, y-1, z)){ + mAir++; + } + return mAir; + } + + public boolean removePollution(int toRemove){ + + if (this == null || this.getBaseMetaTileEntity() == null || this.getBaseMetaTileEntity().getWorld() == null) { + return false; + } + + if (this.mTier < 7) { + int startPollution = getCurrentChunkPollution(); + PollutionUtils.removePollution(this.getBaseMetaTileEntity(), toRemove); + int after = getCurrentChunkPollution(); + return (after<startPollution); + } + else { + int chunksWithRemoval = 0; + int totalRemoved = 0; + AutoMap<Chunk> aSurrounding = new AutoMap<Chunk>(); + Chunk aThisChunk = this.getBaseMetaTileEntity().getWorld().getChunkFromBlockCoords(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getZCoord()); + int mainChunkX = aThisChunk.xPosition; + int mainChunkZ = aThisChunk.zPosition; + + World aWorld = this.getBaseMetaTileEntity().getWorld(); + int xPos = this.getBaseMetaTileEntity().getXCoord(); + int zPos = this.getBaseMetaTileEntity().getZCoord(); + + Chunk a1 = aWorld.getChunkFromBlockCoords(xPos-32, zPos-32); + Chunk a2 = aWorld.getChunkFromBlockCoords(xPos-32, zPos); + Chunk a3 = aWorld.getChunkFromBlockCoords(xPos-32, zPos+32); + Chunk b1 = aWorld.getChunkFromBlockCoords(xPos, zPos-32); + Chunk b2 = aWorld.getChunkFromBlockCoords(xPos, zPos); + Chunk b3 = aWorld.getChunkFromBlockCoords(xPos, zPos+32); + Chunk c1 = aWorld.getChunkFromBlockCoords(xPos+32, zPos-32); + Chunk c2 = aWorld.getChunkFromBlockCoords(xPos+32, zPos); + Chunk c3 = aWorld.getChunkFromBlockCoords(xPos+32, zPos+32); + + aSurrounding.put(a1); + aSurrounding.put(a2); + aSurrounding.put(a3); + aSurrounding.put(b1); + aSurrounding.put(b2); + aSurrounding.put(b3); + aSurrounding.put(c1); + aSurrounding.put(c2); + aSurrounding.put(c3); + + for (Chunk r : aSurrounding) { + if (!r.isChunkLoaded) { + continue; + } + + int startPollution = getPollutionInChunk(r); + if (startPollution == 0) { + continue; + } + + Logger.WARNING("Trying to remove pollution from chunk "+r.xPosition+", "+r.zPosition+" | "+startPollution); + int after = 0; + boolean isMainChunk = r.isAtLocation(mainChunkX, mainChunkZ); + + int removal = Math.max(0, !isMainChunk ? (toRemove/4) : toRemove); + if (removePollution(r, removal)) { + chunksWithRemoval++; + after = getPollutionInChunk(r); + } + else { + after = 0; + } + if (startPollution - after > 0) { + totalRemoved += (startPollution - after); + } + Logger.WARNING("Removed "+(startPollution - after)+" pollution from chunk "+r.xPosition+", "+r.zPosition+" | "+after); + } + return totalRemoved > 0 && chunksWithRemoval > 0; + } + } + + public boolean removePollution(Chunk aChunk, int toRemove){ + int before = getCurrentChunkPollution(); + PollutionUtils.removePollution(aChunk, toRemove); + int after = getCurrentChunkPollution(); + return (after<before); + } + + + public boolean hasAirFilter(ItemStack filter){ + if (filter == null) { + return false; + } + if (filter.getItem() instanceof ItemAirFilter){ + return true; + } + return false; + } + + public boolean damageAirFilter(){ + ItemStack filter = this.mInventory[this.SLOT_FILTER]; + if (filter == null) { + return false; + } + + boolean creativeRotor = false; + ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; + if (rotorStack != null) { + if(rotorStack.getItem() instanceof GT_MetaGenerated_Tool_01) { + Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(rotorStack); + Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(rotorStack); + if (t1 == Materials._NULL && t2 == Materials._NULL){ + creativeRotor = true; + } + } + } + + if (creativeRotor) { + return true; + } + + + if (filter.getItem() instanceof ItemAirFilter){ + + long currentUse = ItemAirFilter.getFilterDamage(filter); + + //Remove broken Filter + if (filter.getItemDamage() == 0 && currentUse >= 50-1){ + this.mInventory[this.SLOT_FILTER] = null; + return false; + } + else if (filter.getItemDamage() == 1 && currentUse >= 2500-1){ + this.mInventory[this.SLOT_FILTER] = null; + return false; + } + else { + //Do Damage + ItemAirFilter.setFilterDamage(filter, currentUse+1); + Logger.WARNING("Filter Damage: "+currentUse); + return true; + } + } + return false; + } + + + @Override + public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_PollutionCleaner(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_PollutionCleaner(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), this.mGUIName); + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + if (aIndex == 5) { + if (aStack.getItem() instanceof ItemAirFilter) { + Logger.INFO("Inserting Air Filter into "+aIndex); + return true; + } + } + if (aIndex == 4) { + if (this.mInventory[6] != null) { + Logger.INFO("Found conveyor, can automate turbines. Inserting into "+aIndex); + if (aStack.getItem() instanceof ItemBasicScrubberTurbine) { + return true; + } + if (aStack.getItem() instanceof GT_MetaGenerated_Tool && aStack.getItemDamage() >= 170 && aStack.getItemDamage() <= 179){ + return true; + } + } + } + //return super.canInsertItem(aIndex, aStack, aSide); + return false; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + public boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, + float aZ) { + this.mSaveRotor = Utils.invertBoolean(mSaveRotor); + if (mSaveRotor){ + PlayerUtils.messagePlayer(aPlayer, "Running in low efficiency mode, rotors will not break."); + } + else { + PlayerUtils.messagePlayer(aPlayer, "Running in high efficiency mode, rotors will break."); + } + return true; + } + + @Override + public void doSound(byte aIndex, double aX, double aY, double aZ) { + if (aIndex == -120) { + GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(103)), MathUtils.randInt(5, 50), 0.05F, aX, aY, aZ); + } else if (aIndex == -121 || aIndex == -122) { + //GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(108)), 0, 0.5F, aX, aY, aZ); + } /*else if (aIndex == -122) { + GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(6)), 100, 1.0F, aX, aY, aZ); + }*/ else { + super.doSound((byte) 0, aX, aY, aZ); + } + } + + @Override + public boolean canHaveInsufficientEnergy() { + // TODO Auto-generated method stub + return super.canHaveInsufficientEnergy(); + } + + @Override + public String[] getInfoData() { + AutoMap<String> aTooltipSuper = new AutoMap<String>(); + for (String s : super.getInfoData()) { + aTooltipSuper.put(s); + } + int mAirSides = getFreeSpaces(); + int reduction = 0; + + try { + long tVoltage = maxEUInput(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + reduction += (((Math.max((tTier-2), 1)*2)*50)*mAirSides); + reduction = (MathUtils.safeInt((long)reduction*this.mBaseEff)/100000)*mAirSides*Math.max((tTier-2), 1); + reduction = MathUtils.safeInt(((long)reduction/100)*this.mOptimalAirFlow); + + aTooltipSuper.put("Maximum pollution removed per second: "+reduction); + } + catch (Throwable t) { + aTooltipSuper.put("Maximum pollution removed per second: "+mPollutionReduction); + } + aTooltipSuper.put("Air Sides: "+mAirSides); + + String[] mBuiltOutput = new String[aTooltipSuper.size()]; + int aIndex = 0; + for (String i : aTooltipSuper) { + mBuiltOutput[aIndex++] = i; + } + + + + return mBuiltOutput; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { + if (aSide <= 1) { + return false; + } + return super.allowCoverOnSide(aSide, aCoverID); + } + + @Override + public ITexture[] getTopFacingInactive(byte aColor) { + return super.getTopFacingInactive(aColor); + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); + aNBT.setBoolean("mSaveRotor", mSaveRotor); + super.setItemNBT(aNBT); + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaCondensor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaCondensor.java new file mode 100644 index 0000000000..0f7edd062d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaCondensor.java @@ -0,0 +1,174 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import net.minecraft.entity.player.InventoryPlayer; + +import gregtech.api.enums.Dyes; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; + +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_SteamCondenser; +import gtPlusPlus.xmod.gregtech.api.gui.GUI_SteamCondenser; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators.GregtechMetaBoilerBase; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidHandler; + +public class GregtechMetaCondensor extends GregtechMetaBoilerBase{ + + public GregtechMetaCondensor(final int aID, final String aName, final String aNameRegional) + { + super(aID, aName, aNameRegional, "A Steam condenser - [IC2->Steam]", new ITexture[0]); + } + + public GregtechMetaCondensor(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures) + { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[]{this.mDescription, "IC2 Steam + Water = Normal Steam.", "Requires no power to run, although it's not very fast.", CORE.GT_Tooltip}; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) + { + final ITexture[][][] rTextures = new ITexture[5][17][]; + for (byte i = -1; i < 16; i++){ + rTextures[0][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa))}; + rTextures[1][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) }; + rTextures[2][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE) }; + rTextures[3][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER) }; + rTextures[4][(i + 1)] = new ITexture [] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_VENT, Dyes.getModulation(i, Dyes.MACHINE_METAL.mRGBa)), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE) }; + } + return rTextures; + } + + @Override + public int maxProgresstime() + { + return 1000; + } + + @Override + public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) + { + return new CONTAINER_SteamCondenser(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) + { + return new GUI_SteamCondenser(aPlayerInventory, aBaseMetaTileEntity, "SteelBoiler.png"); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) + { + return new GregtechMetaCondensor(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) + { + this.RI = MathUtils.randLong(5L, 30L); + if ((aBaseMetaTileEntity.isServerSide()) && (aTick > 20L)) + { + if (this.mTemperature <= 5) + { + this.mTemperature = 5; + this.mLossTimer = 0; + } + if (++this.mLossTimer > 10) + { + this.mTemperature -= 1; + this.mLossTimer = 0; + } + for (byte i = 1; (this.mSteam != null) && (i < 6); i = (byte)(i + 1)) { + if (i != aBaseMetaTileEntity.getFrontFacing()) + { + final IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide(i); + if (tTileEntity != null) + { + final FluidStack tDrained = aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), Math.max(1, this.mSteam.amount / 2), false); + if (tDrained != null) + { + final int tFilledAmount = tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), tDrained, false); + if (tFilledAmount > 0) { + tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), tFilledAmount, true), true); + } + } + } + } + } + if ((aTick % 10L) == 0L) { + if (this.mTemperature > 5) + { + if ((this.mFluid == null) || (!GT_ModHandler.isWater(this.mFluid)) || (this.mFluid.amount <= 0)) + { + this.mHadNoWater = true; + } + else + { + if (this.mHadNoWater) + { + aBaseMetaTileEntity.doExplosion(2048L); + return; + } + this.mFluid.amount -= 1; + if (this.mSteam == null) { + this.mSteam = GT_ModHandler.getSteam(30L); + } else if (GT_ModHandler.isSteam(this.mSteam)) { + this.mSteam.amount += 30; + } else { + this.mSteam = GT_ModHandler.getSteam(30L); + } + } + } + else { + this.mHadNoWater = false; + } + } + if ((this.mSteam != null) && + (this.mSteam.amount > getSteamCapacity())) + { + this.sendSound((byte)1); + this.mSteam.amount = getSteamCapacity() * 3 / 4; + } + /*if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()) && + (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.bucket.get(IC2.getItemFromBlock(p_150898_0_))))) + { + this.mProcessingEnergy += 1000; + aBaseMetaTileEntity.decrStackSize(2, 1); + aBaseMetaTileEntity.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.bucket, Materials.Empty, 1L)); + }*/ + if ((this.mTemperature < 1000) && (this.mProcessingEnergy > 0) && ((aTick % this.RI) == 0L)) + { + this.mProcessingEnergy -= 40; + this.mTemperature += 2; + } + aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0); + } + } + + @Override + public final int fill(final FluidStack aFluid, final boolean doFill) + { + if ((Utils.isIC2Steam(aFluid)) && (this.mProcessingEnergy < 50)) + { + final int tFilledAmount = Math.min(50, aFluid.amount); + if (doFill) { + this.mProcessingEnergy += tFilledAmount; + } + return tFilledAmount; + } + return super.fill(aFluid, doFill); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaGarbageCollector.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaGarbageCollector.java new file mode 100644 index 0000000000..88658c399d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaGarbageCollector.java @@ -0,0 +1,323 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +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 gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +public class GregtechMetaGarbageCollector extends GregtechMetaTileEntity { + + long mLastCleanup = 0; + long mLocalTickVar = 0; + int mFrequency = 5; + + public GregtechMetaGarbageCollector(final String aName, final String aNameRegional, final String aDescription) { + super(991, aName, aNameRegional, 5, 0, aDescription); + } + + public GregtechMetaGarbageCollector(final String aName, final String aDescription, final ITexture[][][] aTextures) { + super(aName, 5, 0, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, + "Can request the JVM to perform garbage collection", + "Configurable to run once every 5 minute interval (5-180)", + "This Machine has no recipe", + "Admin Tool, Limit one per world if possible", + CORE.GT_Tooltip}; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; + } + + + public ITexture[] getFront(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; + } + + + public ITexture[] getBack(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; + } + + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; + } + + + public ITexture[] getTop(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; + } + + + public ITexture[] getSides(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redox_3)}; + } + + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; + } + + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; + } + + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; + } + + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; + } + + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redox_3)}; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (mFrequency < 180){ + mFrequency += 5; + } + else { + mFrequency = 5; + } + PlayerUtils.messagePlayer(aPlayer, "Running every "+mFrequency+" minutes."); + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaGarbageCollector(this.mName, this.mDescription, this.mTextures); + } + + @Override public boolean isSimpleMachine() {return true;} + @Override public boolean isElectric() {return false;} + @Override public boolean isValidSlot(final int aIndex) {return false;} + @Override public boolean isFacingValid(final byte aFacing) {return true;} + @Override public boolean isEnetInput() {return false;} + @Override public boolean isEnetOutput() {return false;} + @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isTeleporterCompatible() {return false;} + @Override public long getMinimumStoredEU() {return 0;} + @Override public long maxEUStore() {return 0;} + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + @Override public int rechargerSlotStartIndex() {return 0;} + @Override public int dechargerSlotStartIndex() {return 0;} + @Override public int rechargerSlotCount() {return 0;} + @Override public int dechargerSlotCount() {return 0;} + @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} + @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} + @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) + { + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + private void showPollution(final World worldIn, final EntityPlayer playerIn){ + PlayerUtils.messagePlayer(playerIn, "Running every "+mFrequency+" minutes. Owner: "+this.getBaseMetaTileEntity().getOwnerName()); + long aDiff = mLocalTickVar - this.mLastCleanup; + PlayerUtils.messagePlayer(playerIn, "Last run: "+Utils.getSecondsFromMillis(aDiff)+" seconds ago."); + + + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + + @Override + public String[] getInfoData() { + return new String[] { + this.getLocalName() + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { + } + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return true; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.getBaseMetaTileEntity().isServerSide()) { + mLocalTickVar = System.currentTimeMillis(); + long aDiff = mLocalTickVar - this.mLastCleanup; + if (Utils.getSecondsFromMillis(aDiff) >= (this.mFrequency * 60)) { + CORE.gc(); + this.mLastCleanup = mLocalTickVar; + } + } + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java new file mode 100644 index 0000000000..5f55e080ad --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java @@ -0,0 +1,386 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +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 gregtech.api.util.GT_Utility; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaPollutionCreator extends GregtechMetaTileEntity { + + int mCurrentPollution; + int mAveragePollution; + int mAveragePollutionArray[] = new int[10]; + private int mArrayPos = 0; + private int mTickTimer = 0; + private int mSecondTimer = 0; + + public GregtechMetaPollutionCreator(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaPollutionCreator(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "A useful debug machine to create pollution.", CORE.GT_Tooltip}; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; + } + + + public ITexture[] getFront(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; + } + + + public ITexture[] getBack(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getTop(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getSides(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; + } + + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier+3][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (pollutionMultiplier > 99){ + pollutionMultiplier = 1; + } + else { + pollutionMultiplier++; + } + PlayerUtils.messagePlayer(aPlayer, "Pollution Mutliplier is now "+pollutionMultiplier+"."); + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPollutionCreator(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override public boolean isSimpleMachine() {return false;} + @Override public boolean isElectric() {return true;} + @Override public boolean isValidSlot(final int aIndex) {return true;} + @Override public boolean isFacingValid(final byte aFacing) {return true;} + @Override public boolean isEnetInput() {return true;} + @Override public boolean isEnetOutput() {return false;} + @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isTeleporterCompatible() {return false;} + @Override public long getMinimumStoredEU() {return 0;} + @Override public long maxEUStore() {return 0;} + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + @Override public int rechargerSlotStartIndex() {return 0;} + @Override public int dechargerSlotStartIndex() {return 0;} + @Override public int rechargerSlotCount() {return 0;} + @Override public int dechargerSlotCount() {return 0;} + @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} + @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} + @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) + { + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + public int pollutionMultiplier = 1; + + private void showPollution(final World worldIn, final EntityPlayer playerIn){ + if(!PollutionUtils.mPollution()){ + PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); + } + else { + addPollution(); + PlayerUtils.messagePlayer(playerIn, "This chunk now contains "+getCurrentChunkPollution()+" pollution."); + //PlayerUtils.messagePlayer(playerIn, "Average over last ten minutes: "+getAveragePollutionOverLastTen()+" pollution."); + } + } + + private boolean addPollution(){ + PollutionUtils.addPollution(getBaseMetaTileEntity(), 100000*pollutionMultiplier); + return true; + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + public int getCurrentChunkPollution(){ + return getCurrentChunkPollution(this.getBaseMetaTileEntity()); + } + + public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity){ + return PollutionUtils.getPollution(aBaseMetaTileEntity); + } + + + @Override + public String[] getInfoData() { + return new String[] { + this.getLocalName(), + "Current Pollution: "+this.mCurrentPollution, + "Average/10 minutes:"+getAveragePollutionOverLastTen()}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { + } + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + //int mCurrentPollution; + //int mAveragePollution; + //int mAveragePollutionArray[] = new int[10]; + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + aNBT.setInteger("mAveragePollution", this.mAveragePollution); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + if (this.getBaseMetaTileEntity().isServerSide()) { + if (this.mCurrentPollution == 0) { + this.mCurrentPollution = getCurrentChunkPollution(); + } + if (this.mArrayPos < 0 || this.mArrayPos > 9) { + this.mArrayPos = 0; + } + this.mTickTimer = 0; + } + } + + + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.getBaseMetaTileEntity().isServerSide()) { + //TickTimer - 20 times a second + this.mTickTimer++; + if (mTickTimer % 20 == 0){ + this.mCurrentPollution = getCurrentChunkPollution(); + } + } + } + + public int getAveragePollutionOverLastTen(){ + int counter = 0; + int total = 0; + + for (int i=0;i<this.mAveragePollutionArray.length;i++){ + if (this.mAveragePollutionArray[i] != 0){ + total += this.mAveragePollutionArray[i]; + counter++; + } + } + int returnValue = 0; + if (total > 0 && counter > 0){ + returnValue = (total/counter); + this.mAveragePollution = returnValue; + } + else { + returnValue = getCurrentChunkPollution(); + } + //Logger.INFO("| DEBUG: "+returnValue +" | ArrayPos:"+this.mArrayPos+" | Counter:"+counter+" | Total:"+total+" |"); + return returnValue; + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java new file mode 100644 index 0000000000..10319f2269 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java @@ -0,0 +1,439 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +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 gregtech.api.util.GT_Utility; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { + + int mCurrentPollution; + int mAveragePollution; + int mAveragePollutionArray[] = new int[10]; + private int mArrayPos = 0; + private int mTickTimer = 0; + private int mSecondTimer = 0; + private long mRedstoneLevel = 0; + + public GregtechMetaPollutionDetector(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaPollutionDetector(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "Right click to check pollution levels.", + "Configure with screwdriver to set redstone output amount.", + "Does not use power.", + CORE.GT_Tooltip}; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, + final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return aSide == aFacing + ? new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) } + : new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(Textures.BlockIcons.VOID) }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + /*@Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; + }*/ + + + public ITexture[] getFront(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; + } + + + public ITexture[] getBack(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getTop(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getSides(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; + } + + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPollutionDetector(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override public boolean isSimpleMachine() {return false;} + @Override public boolean isElectric() {return true;} + @Override public boolean isValidSlot(final int aIndex) {return true;} + @Override public boolean isFacingValid(final byte aFacing) {return true;} + @Override public boolean isEnetInput() {return true;} + @Override public boolean isEnetOutput() {return false;} + @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isTeleporterCompatible() {return false;} + @Override public long getMinimumStoredEU() {return 0;} + @Override public long maxEUStore() {return 0;} + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + @Override public int rechargerSlotStartIndex() {return 0;} + @Override public int dechargerSlotStartIndex() {return 0;} + @Override public int rechargerSlotCount() {return 0;} + @Override public int dechargerSlotCount() {return 0;} + @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} + @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} + @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) + { + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + private void showPollution(final World worldIn, final EntityPlayer playerIn){ + if(!PollutionUtils.mPollution()){ + PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); + } + else { + PlayerUtils.messagePlayer(playerIn, "This chunk contains "+getCurrentChunkPollution()+" pollution."); + PlayerUtils.messagePlayer(playerIn, "Emit Redstone at pollution level: "+this.mRedstoneLevel); + } + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + public int getCurrentChunkPollution(){ + return getCurrentChunkPollution(this.getBaseMetaTileEntity()); + } + + public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity){ + return PollutionUtils.getPollution(aBaseMetaTileEntity); + } + + + @Override + public String[] getInfoData() { + return new String[] { + this.getLocalName(), + "Current Pollution: "+this.mCurrentPollution, + "Average/10 Sec: "+this.mAveragePollution, + "Emit Redstone at pollution level: "+this.mRedstoneLevel}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { + } + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + //int mCurrentPollution; + //int mAveragePollution; + //int mAveragePollutionArray[] = new int[10]; + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + aNBT.setInteger("mAveragePollution", this.mAveragePollution); + aNBT.setLong("mRedstoneLevel", this.mRedstoneLevel); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + this.mRedstoneLevel = aNBT.getLong("mRedstoneLevel"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + //Only Calc server-side + if (!this.getBaseMetaTileEntity().isServerSide()) { + return; + } + //Emit Redstone + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel){ + for (int i=0;i<6;i++){ + this.getBaseMetaTileEntity().setStrongOutputRedstoneSignal((byte) i, (byte) 16); + } + this.markDirty(); + } + else { + for (int i=0;i<6;i++){ + this.getBaseMetaTileEntity().setStrongOutputRedstoneSignal((byte) i, (byte) 0); + } + this.markDirty(); + } + + //Do Math for stats + if (this.mTickTimer % 20 == 0) { + mCurrentPollution = this.getCurrentChunkPollution(); + if (mArrayPos > mAveragePollutionArray.length-1) { + mArrayPos = 0; + } + mAveragePollutionArray[mArrayPos] = mCurrentPollution; + mAveragePollution = getAveragePollutionOverLastTen(); + mArrayPos++; + } + this.mTickTimer++; + + } + + public int getAveragePollutionOverLastTen(){ + return MathUtils.getIntAverage(mAveragePollutionArray); + + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, + float aX, float aY, float aZ) { + + if (aSide == this.getBaseMetaTileEntity().getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0: + this.mRedstoneLevel -= 5000; + break; + case 1: + this.mRedstoneLevel += 5000; + break; + case 2: + this.mRedstoneLevel -= 50000; + break; + case 3: + this.mRedstoneLevel += 50000; + } + this.markDirty(); + GT_Utility.sendChatToPlayer(aPlayer, "Emit Redstone at Pollution Level: " + this.mRedstoneLevel); + } + + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + public boolean allowGeneralRedstoneOutput() { + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel){ + this.markDirty(); + return true; + } + return false; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, + EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + + @Override + public void onMachineBlockUpdate() { + super.onMachineBlockUpdate(); + } + + @Override + public boolean hasSidedRedstoneOutputBehavior() { + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel){ + this.markDirty(); + return true; + } + return false; + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java new file mode 100644 index 0000000000..140f1d9cd5 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java @@ -0,0 +1,394 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import static gregtech.api.enums.GT_Values.V; + +import java.util.HashSet; +import java.util.Set; + +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_BasicMachine; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.interfaces.IChunkLoader; +import gtPlusPlus.core.chunkloading.GTPP_ChunkManager; +import gtPlusPlus.core.chunkloading.StaticChunkFunctions; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_BasicMachine implements IChunkLoader { + + public GregtechMetaTileEntityChunkLoader(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 2, "Loads " + getMaxChunksToLoadForTier(aTier) + " chunks when powered", 0, 0, "Recycler.png", "", new ITexture[]{}); + } + + public GregtechMetaTileEntityChunkLoader(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 2, aDescription, aTextures, 0, 0, aGUIName, aNEIName); + } + + public static int getMaxChunksToLoadForTier(int aTier) { + if (aTier < 4) { + return 3 * 3; + } + if (aTier < 6) { + return 7 * 7; + } + if (aTier < 8) { + return 15 * 15; + } + else { + return 0; + } + } + + @Override + public String[] getDescription() { + return new String[] { + "Loads " + getMaxChunksToLoadForTier(this.mTier) + " chunks when powered", + "Consumes 2A", + "Behaves Identically to a Railcraft World Anchor", + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; + } + + + public ITexture[] getFront(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; + } + + + public ITexture[] getBack(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; + } + + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; + } + + + public ITexture[] getTop(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; + } + + + public ITexture[] getSides(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier])}; + } + + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; + } + + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; + } + + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; + } + + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; + } + + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_MaragingSteel), new GT_RenderedTexture(TexturesGtBlock.TIERED_MACHINE_HULLS[mTier+1])}; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityChunkLoader(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()){ + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + private void showPollution(final World worldIn, final EntityPlayer playerIn){ + //PlayerUtils.messagePlayer(playerIn, "Running every "+mFrequency+" minutes. Owner: "+this.getBaseMetaTileEntity().getOwnerName()); + //PlayerUtils.messagePlayer(playerIn, "Last run: "+Utils.getSecondsFromMillis(aDiff)+" seconds ago."); + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + + @Override + public String[] getInfoData() { + return super.getInfoData(); + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return true; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + // Have we set the Chunk this Tile resides in yet? + if (mCurrentChunk == null) { + int xTile = getBaseMetaTileEntity().getXCoord(); + int zTile = getBaseMetaTileEntity().getZCoord(); + createInitialWorkingChunk(aBaseMetaTileEntity, xTile, zTile); + } + + // Try unload all chunks if fail to meet global chunkloading conditions. + if (StaticChunkFunctions.onPostTick(aBaseMetaTileEntity, aTick)) { + // Can this tile actively chunkload? + if (getChunkLoadingActive()) { + // Consume some power + this.setEUVar(this.getEUVar() - (maxEUInput() * maxAmperesIn())); + + // Do we need to re-request tickets? + if (getDoesWorkChunkNeedReload()) { + // Request ticket for current chunk. + GTPP_ChunkManager.requestChunkLoad((TileEntity)getBaseMetaTileEntity(), mCurrentChunk); + // Request a ticket for each chunk we have mapped out in a spiral pattern. + if (!mLoadedChunks.isEmpty()) { + for (ChunkCoordIntPair Y : mLoadedChunks) { + GTPP_ChunkManager.requestChunkLoad((TileEntity)getBaseMetaTileEntity(), Y); + } + } + setDoesWorkChunkNeedReload(false); + } + + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + StaticChunkFunctions.saveNBTDataForTileEntity(this.getBaseMetaTileEntity(), aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + StaticChunkFunctions.loadNBTDataForTileEntity(this.getBaseMetaTileEntity(), aNBT); + } + + @Override + public long maxAmperesIn() { + return 2; + } + + @Override + public long getMinimumStoredEU() { + return V[mTier] * 2; + } + + @Override + public long maxEUStore() { + return V[mTier] * 256; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + + /* + * Chunkloading Vars + */ + + private long mTicksRemainingForChunkloading = -1; + private ChunkCoordIntPair mCurrentChunk; + private Set<ChunkCoordIntPair> mLoadedChunks = new HashSet<ChunkCoordIntPair>(); + private boolean mRefreshChunkTickets = false; + + @Override + public long getTicksRemaining() { + return -1; + } + + @Override + public void setTicksRemaining(long aTicks) { + mTicksRemainingForChunkloading = aTicks; + } + + @Override + public ChunkCoordIntPair getResidingChunk() { + return mCurrentChunk; + } + + @Override + public void setResidingChunk(ChunkCoordIntPair aCurrentChunk) { + mCurrentChunk = aCurrentChunk; + } + + @Override + public boolean getChunkLoadingActive() { + return this.getEUVar() >= maxEUInput() * maxAmperesIn(); + } + + @Override + public void setChunkLoadingActive(boolean aActive) { + + } + + @Override + public boolean getDoesWorkChunkNeedReload() { + return mRefreshChunkTickets; + } + + @Override + public void setDoesWorkChunkNeedReload(boolean aActive) { + mRefreshChunkTickets = aActive; + } + + @Override + public boolean addChunkToLoadedList(ChunkCoordIntPair aActiveChunk) { + return mLoadedChunks.add(aActiveChunk); + } + + @Override + public boolean removeChunkFromLoadedList(ChunkCoordIntPair aActiveChunk) { + return mLoadedChunks.remove(aActiveChunk); + } + + @Override + public Set<ChunkCoordIntPair> getManagedChunks() { + return mLoadedChunks; + } + + @Override + public void onRemoval() { + StaticChunkFunctions.onRemoval(getBaseMetaTileEntity()); + super.onRemoval(); + } + + public static Set<ChunkCoordIntPair> spiralChunks(final IGregTechTileEntity aBaseMetaTileEntity, int X, int Z) { + World w = aBaseMetaTileEntity.getWorld(); + HashSet<ChunkCoordIntPair> aSet = new HashSet<ChunkCoordIntPair>(); + if (w == null) { + return aSet; + } + Chunk thisChunk = w.getChunkFromBlockCoords(aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getZCoord()); + ChunkCoordIntPair aChunkCo = new ChunkCoordIntPair(thisChunk.xPosition, thisChunk.zPosition); + int x,z,dx,dz; + x = z = dx =0; + dz = -1; + int t = Math.max(X,Z); + int maxI = t*t; + for(int i =0; i < maxI; i++){ + if ((-X/2 <= x) && (x <= X/2) && (-Z/2 <= z) && (z <= Z/2)){ + Chunk C = w.getChunkFromChunkCoords(aChunkCo.chunkXPos + x, aChunkCo.chunkZPos + z); + if (C != null) { + aSet.add(new ChunkCoordIntPair(C.xPosition, C.zPosition)); + } + } + if( (x == z) || ((x < 0) && (x == -z)) || ((x > 0) && (x == 1-z))){ + t = dx; + dx = -dz; + dz = t; + } + x += dx; + z += dz; + } + return aSet; + } + + @Override + public int getChunkloaderTier() { + return mTier; + } + + public void createInitialWorkingChunk(IGregTechTileEntity aBaseMetaTileEntity, int aTileX, int aTileZ) { + final int centerX = aTileX >> 4; + final int centerZ = aTileZ >> 4; + addChunkToLoadedList(new ChunkCoordIntPair(centerX, centerZ)); + GTPP_ChunkManager.requestChunkLoad((TileEntity)aBaseMetaTileEntity.getMetaTileEntity(), getResidingChunk()); + // If this surrounding chunk map for this tile is empty, we spiral out and map chunks to keep loaded. + if (getManagedChunks().isEmpty()) { + int aChunks = GregtechMetaTileEntityChunkLoader.getMaxChunksToLoadForTier(getChunkloaderTier()); + mLoadedChunks.addAll(spiralChunks(aBaseMetaTileEntity, getChunkloaderTier(), getChunkloaderTier())); + } + if (!mLoadedChunks.isEmpty()) { + for (ChunkCoordIntPair Y : mLoadedChunks) { + GTPP_ChunkManager.requestChunkLoad((TileEntity)aBaseMetaTileEntity.getMetaTileEntity(), Y); + } + } + setDoesWorkChunkNeedReload(false); + } + + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java new file mode 100644 index 0000000000..8456f40797 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java @@ -0,0 +1,204 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; + +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntityThaumcraftResearcher extends GregtechMetaTileEntity { + + public GregtechMetaTileEntityThaumcraftResearcher(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaTileEntityThaumcraftResearcher(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, "Generates Thaumcraft research notes, because it's magic."}; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; + } + + + public ITexture[] getFront(final byte aColor) { + return new ITexture[]{getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Metal_Grate_A)}; + } + + + public ITexture[] getBack(final byte aColor) { + return new ITexture[]{getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Metal_Grate_B)}; + } + + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[]{getSides(aColor)[0]}; + } + + + public ITexture[] getTop(final byte aColor) { + return new ITexture[]{getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue)}; + } + + + public ITexture[] getSides(final byte aColor) { + return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; + } + + + public ITexture[] getFrontActive(final byte aColor) { + return getFront(aColor); + } + + + public ITexture[] getBackActive(final byte aColor) { + return getBack(aColor); + } + + + public ITexture[] getBottomActive(final byte aColor) { + return getBottom(aColor); + } + + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[]{getSides(aColor)[0], new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange)}; + } + + + public ITexture[] getSidesActive(final byte aColor) { + return getSides(aColor); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityThaumcraftResearcher(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override public boolean isSimpleMachine() {return false;} + @Override public boolean isElectric() {return true;} + @Override public boolean isValidSlot(final int aIndex) {return true;} + @Override public boolean isFacingValid(final byte aFacing) {return true;} + @Override public boolean isEnetInput() {return true;} + @Override public boolean isEnetOutput() {return false;} + @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getBackFacing();} + @Override public boolean isTeleporterCompatible() {return false;} + @Override public long getMinimumStoredEU() {return 0;} + @Override public long maxEUStore() {return 512000;} + @Override public int rechargerSlotStartIndex() {return 0;} + @Override public int dechargerSlotStartIndex() {return 0;} + @Override public int rechargerSlotCount() {return 0;} + @Override public int dechargerSlotCount() {return 0;} + @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} + + @Override + public int getCapacity() { + return 128000; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) + { + return true; + } + return true; + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aSide==this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return true; + } + + @Override + public String[] getInfoData() { + return new String[] { + this.getLocalName(), + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int getSizeInventory() { + return 2; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + //aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + //aNBT.setInteger("mAveragePollution", this.mAveragePollution); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + //this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + //this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_BasicWasher.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_BasicWasher.java new file mode 100644 index 0000000000..99b3faa7d4 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_BasicWasher.java @@ -0,0 +1,71 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.core.lib.CORE; +import gregtech.api.util.GTPP_Recipe; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_BasicWasher extends GT_MetaTileEntity_BasicMachine { + + public GregtechMetaTileEntity_BasicWasher(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, + "It's like an automatic Cauldron for washing dusts.", 1, 1, "PotionBrewer.png", "", + new ITexture[]{ + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_POTIONBREWER), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER) + } + ); + } + + public GregtechMetaTileEntity_BasicWasher(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + /*public GregtechMetaTileEntity_BasicWasher(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + }*/ + + @Override + public String[] getDescription() { + return new String[]{this.mDescription, "Grants no byproducts, but it is fast.", CORE.GT_Tooltip}; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_BasicWasher(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sSimpleWasherRecipes; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (getRecipeList().containsInput(aStack)); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return (aFluid.getFluid().getName().equals("water")) || (super.isFluidInputAllowed(aFluid)); + } + + @Override + public int getCapacity() { + return 8000 * Math.max(1, this.mTier); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ChemicalReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ChemicalReactor.java new file mode 100644 index 0000000000..c872e5c912 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ChemicalReactor.java @@ -0,0 +1,666 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import static gregtech.api.enums.GT_Values.E; + +import java.util.HashSet; +import java.util.List; + +import cpw.mods.fml.common.registry.LanguageRegistry; +import gregtech.GT_Mod; +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.api.objects.random.XSTR; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.slots.SlotChemicalPlantInput; +import gtPlusPlus.xmod.gregtech.api.gui.fluidreactor.Container_FluidReactor; +import gtPlusPlus.xmod.gregtech.api.gui.fluidreactor.GUI_FluidReactor; +import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +public class GregtechMetaTileEntity_ChemicalReactor extends GT_MetaTileEntity_BasicMachine { + + public boolean mFluidTransfer_1 = false; + public boolean mFluidTransfer_2 = false; + + public FluidStack[] mInputFluids = new FluidStack[4]; + public FluidStack[] mOutputFluids = new FluidStack[2]; + + public GregtechMetaTileEntity_ChemicalReactor(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, + "For mixing fluids", 4, 4, "ChemicalReactor.png", "", + new ITexture[]{ + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Side_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Side), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Front_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Front), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_FluidReactor_Top) + } + ); + } + + public GregtechMetaTileEntity_ChemicalReactor(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + /*public GregtechMetaTileEntity_BasicWasher(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + }*/ + + @Override + public String[] getDescription() { + return new String[]{this.mDescription, "Because why not?", CORE.GT_Tooltip}; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + try { + GregtechMetaTileEntity_ChemicalReactor y = new GregtechMetaTileEntity_ChemicalReactor(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + return y; + } + catch(Throwable t) { + t.printStackTrace(); + } + return null; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + try { + Container_FluidReactor y = new Container_FluidReactor(aPlayerInventory, aBaseMetaTileEntity); + return y; + } + catch(Throwable t) { + t.printStackTrace(); + } + return null; + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_FluidReactor(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), + this.mGUIName, + GT_Utility.isStringValid(this.mNEIName) + ? this.mNEIName + : (this.getRecipeList() != null ? this.getRecipeList().mUnlocalizedName : "")); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return null; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (getRecipeList().containsInput(aStack)); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return (super.isFluidInputAllowed(aFluid)); + } + + @Override + public int getCapacity() { + return 32000 * Math.max(1, this.mTier) / 4; + } + + @Override + public int getInputSlot() { + return 3; + } + + @Override + public boolean isLiquidInput(byte aSide) { + return aSide > 1; + } + + @Override + public boolean isLiquidOutput(byte aSide) { + return aSide < 2; + } + + @Override + public int getOutputSlot() { + return super.getOutputSlot(); + } + + @Override + public int getStackDisplaySlot() { + return super.getStackDisplaySlot(); + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return super.canTankBeFilled(); + } + + @Override + public boolean canTankBeEmptied() { + return super.canTankBeEmptied(); + } + + @Override + public FluidStack getDisplayedFluid() { + return super.getDisplayedFluid(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mFluidTransfer_1", mFluidTransfer_1); + aNBT.setBoolean("mFluidTransfer_2", mFluidTransfer_2); + for (int i=0;i<4;i++) { + if (this.mInputFluids[i] != null) { + aNBT.setTag("mInputFluid"+i, this.mInputFluids[i].writeToNBT(new NBTTagCompound())); + } + } + for (int i=0;i<2;i++) { + if (this.mOutputFluids[i] != null) { + aNBT.setTag("mOutputFluid"+i, this.mOutputFluids[i].writeToNBT(new NBTTagCompound())); + } + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mFluidTransfer_1 = aNBT.getBoolean("mFluidTransfer_1"); + mFluidTransfer_2 = aNBT.getBoolean("mFluidTransfer_2"); + for (int i=0;i<4;i++) { + if (this.mInputFluids[i] == null) { + this.mInputFluids[i] = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mInputFluid"+i)); + } + } + for (int i=0;i<2;i++) { + if (this.mOutputFluids[i] == null) { + this.mOutputFluids[i] = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mOutputFluid"+i)); + } + } + } + + /* + * Custom Fluid Handling - TODO + */ + + public FluidStack getFillableStack() { + return this.mFluid; + } + + public FluidStack setFillableStack(FluidStack aFluid) { + this.mFluid = aFluid; + return this.mFluid; + } + + public FluidStack getDrainableStack() { + return this.mFluid; + } + + public FluidStack setDrainableStack(FluidStack aFluid) { + this.mFluid = aFluid; + return this.mFluid; + } + + + + + + + + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // Re-implement basic machine logic from the ground up.= + + if (aBaseMetaTileEntity.isServerSide()) { + this.mCharge = aBaseMetaTileEntity.getStoredEU() / 2L > aBaseMetaTileEntity.getEUCapacity() / 3L; + this.mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3L; + this.doDisplayThings(); + boolean tSucceeded = false; + int i; + if (this.mMaxProgresstime > 0 && (this.mProgresstime >= 0 || aBaseMetaTileEntity.isAllowedToWork())) { + aBaseMetaTileEntity.setActive(true); + if (this.mProgresstime >= 0 && !this.drainEnergyForProcess((long) this.mEUt)) { + if (!this.mStuttering) { + this.stutterProcess(); + if (this.canHaveInsufficientEnergy()) { + this.mProgresstime = -100; + } + + this.mStuttering = true; + } + } else { + if (++this.mProgresstime >= this.mMaxProgresstime) { + for (i = 0; i < this.mOutputItems.length; ++i) { + for (i = 0; i < this.mOutputItems.length && !aBaseMetaTileEntity.addStackToSlot( + this.getOutputSlot() + (i + i) % this.mOutputItems.length, + this.mOutputItems[i]); ++i) { + ; + } + } + + if (this.mOutputFluid != null) { + if (this.getDrainableStack() == null) { + this.setDrainableStack(this.mOutputFluid.copy()); + } else if (this.mOutputFluid.isFluidEqual(this.getDrainableStack())) { + FluidStack var10000 = this.getDrainableStack(); + var10000.amount += this.mOutputFluid.amount; + } + } + + for (i = 0; i < this.mOutputItems.length; ++i) { + this.mOutputItems[i] = null; + } + + this.mOutputFluid = null; + this.mEUt = 0; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + this.mStuttering = false; + tSucceeded = true; + this.endProcess(); + } + + if (this.mProgresstime > 5) { + this.mStuttering = false; + } + } + } else { + aBaseMetaTileEntity.setActive(false); + } + + boolean tRemovedOutputFluid = false; + if (this.doesAutoOutputFluids() && this.getDrainableStack() != null + && aBaseMetaTileEntity.getFrontFacing() != this.mMainFacing && (tSucceeded || aTick % 20L == 0L)) { + IFluidHandler tTank = aBaseMetaTileEntity.getITankContainerAtSide(aBaseMetaTileEntity.getFrontFacing()); + if (tTank != null) { + FluidStack tDrained = this.drain(1000, false); + if (tDrained != null) { + int tFilledAmount = tTank.fill( + ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tDrained, false); + if (tFilledAmount > 0) { + tTank.fill(ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), + this.drain(tFilledAmount, true), true); + } + } + } + + if (this.getDrainableStack() == null) { + tRemovedOutputFluid = true; + } + } + + int j; + if (this.doesAutoOutput() && !this.isOutputEmpty() + && aBaseMetaTileEntity.getFrontFacing() != this.mMainFacing + && (tSucceeded || this.mOutputBlocked % 300 == 1 || aBaseMetaTileEntity.hasInventoryBeenModified() + || aTick % 600L == 0L)) { + TileEntity tTileEntity2 = aBaseMetaTileEntity.getTileEntityAtSide(aBaseMetaTileEntity.getFrontFacing()); + j = 0; + + for (byte tCosts = 1; j < this.mOutputItems.length && tCosts > 0 + && aBaseMetaTileEntity.isUniversalEnergyStored(128L); ++j) { + tCosts = GT_Utility.moveOneItemStack(aBaseMetaTileEntity, tTileEntity2, + aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), (List) null, + false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + if (tCosts > 0) { + aBaseMetaTileEntity.decreaseStoredEnergyUnits((long) tCosts, true); + } + } + } + + if (this.mOutputBlocked != 0) { + if (this.isOutputEmpty()) { + this.mOutputBlocked = 0; + } else { + ++this.mOutputBlocked; + } + } + + if (this.allowToCheckRecipe()) { + if (this.mMaxProgresstime <= 0 && aBaseMetaTileEntity.isAllowedToWork() + && (tRemovedOutputFluid || tSucceeded || aBaseMetaTileEntity.hasInventoryBeenModified() + || aTick % 600L == 0L || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) + && this.hasEnoughEnergyToCheckRecipe()) { + if (this.checkRecipe() == 2) { + if (this.mInventory[3] != null && this.mInventory[3].stackSize <= 0) { + this.mInventory[3] = null; + } + + i = this.getInputSlot(); + + for (j = i + this.mInputSlotCount; i < j; ++i) { + if (this.mInventory[i] != null && this.mInventory[i].stackSize <= 0) { + this.mInventory[i] = null; + } + } + + for (i = 0; i < this.mOutputItems.length; ++i) { + this.mOutputItems[i] = GT_Utility.copy(new Object[]{this.mOutputItems[i]}); + if (this.mOutputItems[i] != null && this.mOutputItems[i].stackSize > 64) { + this.mOutputItems[i].stackSize = 64; + } + + this.mOutputItems[i] = GT_OreDictUnificator.get(true, this.mOutputItems[i]); + } + + if (this.mFluid != null && this.mFluid.amount <= 0) { + this.mFluid = null; + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + if (GT_Utility.isDebugItem(this.mInventory[this.dechargerSlotStartIndex()])) { + this.mEUt = this.mMaxProgresstime = 1; + } + + this.startProcess(); + } else { + this.mMaxProgresstime = 0; + + for (i = 0; i < this.mOutputItems.length; ++i) { + this.mOutputItems[i] = null; + } + + this.mOutputFluid = null; + } + } + } else if (!this.mStuttering) { + this.stutterProcess(); + this.mStuttering = true; + } + } + + + + } + + @Override + protected void doDisplayThings() { + // TODO Auto-generated method stub + super.doDisplayThings(); + } + + @Override + protected ItemStack getSpecialSlot() { + // TODO Auto-generated method stub + return super.getSpecialSlot(); + } + + @Override + protected ItemStack getOutputAt(int aIndex) { + // TODO Auto-generated method stub + return super.getOutputAt(aIndex); + } + + @Override + protected ItemStack[] getAllOutputs() { + // TODO Auto-generated method stub + return super.getAllOutputs(); + } + + @Override + protected ItemStack getInputAt(int aIndex) { + // TODO Auto-generated method stub + return super.getInputAt(aIndex); + } + + @Override + protected ItemStack[] getAllInputs() { + // TODO Auto-generated method stub + return super.getAllInputs(); + } + + @Override + protected boolean displaysInputFluid() { + return true; + } + + @Override + protected boolean displaysOutputFluid() { + return true; + } + + @Override + public boolean doesAutoOutput() { + return super.doesAutoOutput(); + } + + @Override + public boolean doesAutoOutputFluids() { + return this.mFluidTransfer_1 && this.mFluidTransfer_2; + } + + @Override + public void startProcess() { + super.startProcess(); + } + + @Override + public void endProcess() { + super.endProcess(); + } + + @Override + public String[] getInfoData() { + return super.getInfoData(); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return super.allowPullStack(aBaseMetaTileEntity, aIndex, aSide, aStack); + } + + @Override + public int checkRecipe() { + return super.checkRecipe(); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + + /* if (aBaseMetaTileEntity != null) { + if (!aBaseMetaTileEntity.getWorld().isRemote) { + itemslots : for (int i=3;i<7;i++) { + ItemStack aStack = aBaseMetaTileEntity.getStackInSlot(i); + if (aStack != null) { + if (FluidContainerRegistry.isContainer(aStack)) { + if (this.isItemValidForSlot(i, aStack)) { + // Add Fluid + FluidStack aContainerFluid = FluidContainerRegistry.getFluidForFilledItem(aStack); + if (aContainerFluid != null) { + fluidslots : for (FluidStack u : mInputFluids) { + if (u != null && u.isFluidEqual(aContainerFluid)) { + if (u.amount <= (this.getCapacity() - aContainerFluid.amount)) { + + // Matching, not full, let's fill, then continue + u.amount += aContainerFluid.amount; + + // Update stack size + if (aStack.stackSize > 1) { + aStack.stackSize--; + } + else { + aStack = null; + } + + // Add Output container + // TODO + + continue itemslots; + } + else { + // Too full + break fluidslots; + } + } + else { + if (u == null ) { + + // Empty, let's fill, then continue + u = aContainerFluid.copy(); + + // Update stack size + if (aStack.stackSize > 1) { + aStack.stackSize--; + } + else { + aStack = null; + } + + // Add Output container + // TODO + + continue itemslots; + + } + else { + // Not empty, doesn't match, check next slot. + continue fluidslots; + } + } + } + + + + } + // Eat Input + + // Add Container to Output + } + } + } + } + } + }*/ + + } + + @Override + public FluidStack getFluid() { + return super.getFluid(); + } + + @Override + public int getFluidAmount() { + return super.getFluidAmount(); + } + + @Override + public int fill(FluidStack aFluid, boolean doFill) { + return super.fill(aFluid, doFill); + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return super.drain(maxDrain, doDrain); + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + super.setItemNBT(aNBT); + } + + @Override + public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { + if (aIndex >= 3 && aIndex <= 6) { + return SlotChemicalPlantInput.isItemValidForChemicalPlantSlot(aStack); + } + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(int aSide) { + return super.getAccessibleSlotsFromSide(aSide); + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + if (aIndex >= 3 && aIndex <= 6) { + return super.canInsertItem(aIndex, aStack, aSide); + } + return false; + } + + @Override + public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { + if (aIndex >= 7 && aIndex <= 11) { + return super.canExtractItem(aIndex, aStack, aSide); + } + return false; + } + + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + // TODO Auto-generated method stub + return super.canFill(aSide, aFluid); + } + + @Override + public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { + // TODO Auto-generated method stub + return super.canDrain(aSide, aFluid); + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { + // TODO Auto-generated method stub + return super.getTankInfo(aSide); + } + + @Override + public int fill_default( + ForgeDirection aSide, FluidStack aFluid, boolean doFill + ) { + // TODO Auto-generated method stub + return super.fill_default(aSide, aFluid, doFill); + } + + @Override + public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + // TODO Auto-generated method stub + return super.fill(aSide, aFluid, doFill); + } + + @Override + public FluidStack drain( + ForgeDirection aSide, FluidStack aFluid, boolean doDrain + ) { + // TODO Auto-generated method stub + return super.drain(aSide, aFluid, doDrain); + } + + @Override + public FluidStack drain( + ForgeDirection aSide, int maxDrain, boolean doDrain + ) { + // TODO Auto-generated method stub + return super.drain(aSide, maxDrain, doDrain); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_CompactFusionReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_CompactFusionReactor.java new file mode 100644 index 0000000000..2197ce193d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_CompactFusionReactor.java @@ -0,0 +1,702 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import java.util.ArrayList; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_DeluxeMachine; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_CompactFusionReactor extends GT_MetaTileEntity_DeluxeMachine { + + private boolean mCanProcessRecipe = false; + private boolean mCharging = false; + private long mChargeConsumed = 0; + + private GT_Recipe mLastRecipe; + private long mEUStore; + private boolean mRunningOnLoad = false; + private boolean mMachine = false; + private int mEfficiency, mEfficiencyIncrease, mEfficiencyMax = 0; + private int mStartUpCheck = 100, mUpdate = 0; + private FluidStack[] mOutputFluids = null; + + public GregtechMetaTileEntity_CompactFusionReactor(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, "It's like a midget Ra.", 1, 1, "PotionBrewer.png", ""); + } + + public GregtechMetaTileEntity_CompactFusionReactor(String aName, int aTier, String aDescription, + ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + @Override + public String[] getDescription() { + return new String[] { this.mDescription, "Not Very Fast, but not very big either.", + "Each side pair in/out puts to different slots.", "Top & Bottom Sides are Outputs.", + "Front & Back are Input Plasma 1.", "Sides are Input Plasma 2." }; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_CompactFusionReactor(this.mName, this.mTier, this.mDescription, + this.mTextures, this.mGUIName, this.mNEIName); + } + + public int tier() { + return this.mTier; + } + + public int tierOverclock() { + return this.mTier == 6 ? 0 : this.mTier == 7 ? 1 : 2; + } + + private GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, + final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + + 1]; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sSlowFusionRecipes; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return (aFluid.getFluid().getName().contains("plasma")) || (super.isFluidInputAllowed(aFluid)); + } + + @Override + public int getCapacity() { + return 32000; + } + + @Override + public void abortProcess() { + super.abortProcess(); + } + + long mFusionPoint = 20000000L; + + @Override + public int checkRecipe() { + Logger.MACHINE_INFO("Recipe Tick 1."); + if (!this.mCanProcessRecipe) { + Logger.MACHINE_INFO("Recipe Tick 1.1 - Cannot Process Recipe."); + if (this.mChargeConsumed < mFusionPoint) { + Logger.MACHINE_INFO("Recipe Tick 1.2 - Cannot Ignite Fusion, Charge too low."); + this.mCharging = true; + this.mCanProcessRecipe = false; + if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits((mFusionPoint / 100), false)) { + Logger.MACHINE_INFO("Recipe Tick 1.3 - Charging Internal storage. " + (mFusionPoint / 100) + "/" + + mFusionPoint); + mChargeConsumed += (mFusionPoint / 100); + } + } + else { + mChargeConsumed = 0; + this.mCharging = false; + this.mCanProcessRecipe = true; + + } + } + else { + Logger.MACHINE_INFO("Recipe Tick 1.1 - Try to Process Recipe."); + if (checkRecipeMulti()) { + Logger.MACHINE_INFO("Recipe Tick 1.2 - Process Recipe was Successful."); + return 2; + } + } + Logger.MACHINE_INFO("Recipe Tick 2. - Process Recipe failed."); + return 0; + } + + public ArrayList<FluidStack> getStoredFluids() { + ArrayList<FluidStack> mList = new ArrayList<FluidStack>(); + mList.add(this.mFluid); + mList.add(this.mFluid2); + return mList; + } + + public boolean checkRecipeMulti() { + ArrayList<FluidStack> tFluidList = getStoredFluids(); + int tFluidList_sS = tFluidList.size(); + for (int i = 0; i < tFluidList_sS - 1; i++) { + for (int j = i + 1; j < tFluidList_sS; j++) { + if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { + if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { + tFluidList.remove(j--); + tFluidList_sS = tFluidList.size(); + } + else { + tFluidList.remove(i--); + tFluidList_sS = tFluidList.size(); + break; + } + } + } + } + if (tFluidList.size() > 1) { + FluidStack[] tFluids = tFluidList.toArray(new FluidStack[tFluidList.size()]); + GT_Recipe tRecipe = getRecipeList().findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, false, + GT_Values.V[8], tFluids, new ItemStack[] {}); + if (tRecipe == null) { + return false; + } + if ((tRecipe == null && !mRunningOnLoad) || (tRecipe != null && maxEUStore() < tRecipe.mSpecialValue)) { + this.mLastRecipe = null; + Logger.MACHINE_INFO("Just plain bad."); + return false; + } + if (mRunningOnLoad || tRecipe.isRecipeInputEqual(true, tFluids, new ItemStack[] {})) { + this.mLastRecipe = tRecipe; + this.mEUt = (this.mLastRecipe.mEUt * overclock(this.mLastRecipe.mSpecialValue)); + this.mMaxProgresstime = this.mLastRecipe.mDuration / overclock(this.mLastRecipe.mSpecialValue); + + this.mEfficiencyIncrease = 10000; + + this.mOutputFluids = this.mLastRecipe.mFluidOutputs; + mRunningOnLoad = false; + return true; + } + } + return false; + } + + public int overclock(int mStartEnergy) { + if (tierOverclock() == 1) { + return 1; + } + if (tierOverclock() == 2) { + return mStartEnergy < 160000000 ? 2 : 1; + } + return mStartEnergy < 160000000 ? 4 : mStartEnergy < 320000000 ? 2 : 1; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean doesAutoOutputFluids() { + return true; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public long maxAmperesIn() { + return 16L; + } + + @Override + public long maxEUStore() { + return Long.MAX_VALUE; + } + + @Override + public void doExplosion(long aExplosionPower) { + super.doExplosion(aExplosionPower * 2); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + onRunningTickMulti(); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) + && (aBaseMetaTileEntity.getFrontFacing() != 1) && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) + && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { + if (MathUtils.randInt(0, 4) == 4) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), + aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), + (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), 0.0D, 0.0D, 0.0D); + aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.4F) - (tRandom.nextFloat() * 0.3F), + aBaseMetaTileEntity.getYCoord() + 0.2f + (tRandom.nextFloat() * 0.1F), + (aBaseMetaTileEntity.getZCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), 0.0D, 0.0D, 0.0D); + aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.6F) - (tRandom.nextFloat() * 0.9F), + aBaseMetaTileEntity.getYCoord() + 0.4f + (tRandom.nextFloat() * 0.3F), + (aBaseMetaTileEntity.getZCoord() + 1.8F) - (tRandom.nextFloat() * 2.6F), 0.0D, 0.0D, 0.0D); + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mCanProcessRecipe", this.mCanProcessRecipe); + aNBT.setBoolean("mCharging", this.mCharging); + aNBT.setLong("mChargeConsumed", this.mChargeConsumed); + aNBT.setInteger("mEfficiency", this.mEfficiency); + aNBT.setInteger("mEfficiencyIncrease", this.mEfficiencyIncrease); + aNBT.setInteger("mEfficiencyMax", this.mEfficiencyMax); + aNBT.setInteger("mStartUpCheck", this.mStartUpCheck); + aNBT.setInteger("mUpdate", mUpdate); + aNBT.setInteger("mEfficiencyIncrease", mEfficiencyIncrease); + aNBT.setBoolean("mRunningOnLoad", this.mRunningOnLoad); + aNBT.setBoolean("mMachine", this.mMachine); + aNBT.setLong("mEUStore", this.mEUStore); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (mMaxProgresstime > 0) + mRunningOnLoad = true; + this.mCanProcessRecipe = aNBT.getBoolean("mCanProcessRecipe"); + this.mCharging = aNBT.getBoolean("mCharging"); + this.mChargeConsumed = aNBT.getLong("mChargeConsumed"); + this.mEfficiency = aNBT.getInteger("mEfficiency"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mEfficiencyMax = aNBT.getInteger("mEfficiencyMax"); + this.mStartUpCheck = aNBT.getInteger("mStartUpCheck"); + this.mUpdate = aNBT.getInteger("mUpdate"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mRunningOnLoad = aNBT.getBoolean("mRunningOnLoad"); + this.mMachine = aNBT.getBoolean("mMachine"); + this.mEUStore = aNBT.getLong("mEUStore"); + super.loadNBTData(aNBT); + } + + @Override + public String[] getInfoData() { + String tier = tier() == 6 ? "I" : tier() == 7 ? "II" : "III"; + float plasmaOut = 0; + String fusionName = ""; + int powerRequired = 0; + if (this.mLastRecipe != null) { + fusionName = this.mLastRecipe.mFluidOutputs[0].getLocalizedName() + " Fusion."; + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; + } + } + + return new String[] { "Fusion Reactor MK " + tier, "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + this.getEUVar() + " / " + maxEUStore(), "Plasma Output: " + plasmaOut + "L/t", + "Current Recipe: " + fusionName }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active) }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue) }; + } + + @Override + public void onMachineBlockUpdate() { + this.mUpdate = 50; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + // Logger.MACHINE_INFO("1"); + if (mEfficiency < 0) + mEfficiency = 0; + if (mRunningOnLoad) { + Logger.MACHINE_INFO("2"); + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + checkRecipeMulti(); + } + if (--mUpdate == 0 || --mStartUpCheck == 0) { + Logger.MACHINE_INFO("3"); + mMachine = true; + } + if (mStartUpCheck < 0) { + //Logger.MACHINE_INFO("4"); + if (mMachine) { + //Logger.MACHINE_INFO("5"); + + if (aBaseMetaTileEntity.getStoredEU() + (2048 * tierOverclock()) < maxEUStore()) { + if (aBaseMetaTileEntity.increaseStoredEnergyUnits(2048 * tierOverclock(), true)) { + //Logger.MACHINE_INFO("5.5 A"); + } + else { + //Logger.MACHINE_INFO("5.5 B"); + } + } + if (this.mEUStore <= 0 && mMaxProgresstime > 0) { + Logger.MACHINE_INFO("6"); + stopMachine(); + this.mLastRecipe = null; + } + if (mMaxProgresstime > 0) { + Logger.MACHINE_INFO("7"); + this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt, true); + if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { + if (mOutputFluids != null) + for (FluidStack tStack : mOutputFluids) + if (tStack != null) + addOutput(tStack); + mEfficiency = Math.max(0, (mEfficiency + mEfficiencyIncrease)); + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + if (mOutputFluids != null && mOutputFluids.length > 0) { + + } + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + if (aBaseMetaTileEntity.isAllowedToWork()) + checkRecipeMulti(); + } + } + else { + //Logger.MACHINE_INFO("8"); + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() + || aBaseMetaTileEntity.hasInventoryBeenModified()) { + Logger.MACHINE_INFO("9"); + // turnCasingActive(mMaxProgresstime > 0); + if (aBaseMetaTileEntity.isAllowedToWork()) { + Logger.MACHINE_INFO("10"); + if (checkRecipeMulti()) { + Logger.MACHINE_INFO("11"); + if (this.mEUStore < this.mLastRecipe.mSpecialValue) { + Logger.MACHINE_INFO("12"); + mMaxProgresstime = 0; + // turnCasingActive(false); + } + aBaseMetaTileEntity.decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue, true); + } + } + if (mMaxProgresstime <= 0) + mEfficiency = Math.max(0, mEfficiency - 1000); + } + } + } + else { + // turnCasingActive(false); + Logger.MACHINE_INFO("Bad"); + this.mLastRecipe = null; + stopMachine(); + } + } + Logger.MACHINE_INFO("Good | "+mMaxProgresstime); + aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); + } + } + + public boolean onRunningTickMulti() { + if (this.getBaseMetaTileEntity().isServerSide()) { + if (mEUt < 0) { + if (!drainEnergyInput(((long) -mEUt * 10000) / Math.max(1000, mEfficiency))) { + this.mLastRecipe = null; + stopMachine(); + Logger.MACHINE_INFO("a1"); + return false; + } + } + if (this.mEUStore <= 0) { + this.mLastRecipe = null; + stopMachine(); + Logger.MACHINE_INFO("a2"); + return false; + } + } + return true; + } + + public boolean drainEnergyInput(long aEU) { + return false; + } + + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) + return false; + FluidStack copiedFluidStack = aLiquid.copy(); + this.mOutputFluid = copiedFluidStack; + return false; + } + + public void stopMachine() { + mEUt = 0; + mEfficiency = 0; + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + getBaseMetaTileEntity().disableWorking(); + } + + @Override + public boolean isLiquidInput(byte aSide) { + switch (aSide) { + case 0: + return true; + case 1: + return true; + case 2: + return true; + case 3: + return false; + case 4: + return false; + case 5: + return false; + default: + return false; + } + } + + @Override + public boolean isLiquidOutput(byte aSide) { + switch (aSide) { + case 0: + return false; + case 1: + return false; + case 2: + return false; + case 3: + return true; + case 4: + return true; + case 5: + return true; + default: + return true; + } + } + + @Override + public int fill(FluidStack aFluid, boolean doFill) { + return super.fill(aFluid, doFill); + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return super.drain(maxDrain, doDrain); + } + + @Override + public int getTankPressure() { + return 500; + } + + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return false; + } + else { + return super.canFill(aSide, aFluid); + } + } + + @Override + public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.canDrain(aSide, aFluid); + } + else { + return false; + } + } + + @Override + public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return 0; + } + else { + return super.fill_default(aSide, aFluid, doFill); + } + } + + @Override + public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.fill(aSide, aFluid, doFill); + } + else { + return 0; + } + } + + @Override + public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.drain(aSide, aFluid, doDrain); + } + else { + return null; + } + } + + @Override + public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.drain(aSide, maxDrain, doDrain); + } + else { + return null; + } + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + // TODO Auto-generated method stub + return super.onRightclick(aBaseMetaTileEntity, aPlayer); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, + float aY, float aZ) { + // TODO Auto-generated method stub + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + // TODO Auto-generated method stub + return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + // TODO Auto-generated method stub + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + return false; + } + + @Override + public void onExplosion() { + // TODO Auto-generated method stub + super.onExplosion(); + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 1) { + GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(212)), 10, 1.0F, aX, aY, + aZ); + } + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_PocketFusion.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_PocketFusion.java new file mode 100644 index 0000000000..6cae58ced2 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_PocketFusion.java @@ -0,0 +1,704 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import java.util.ArrayList; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_DeluxeMachine; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_PocketFusion extends GT_MetaTileEntity_DeluxeMachine { + + private boolean mCanProcessRecipe = false; + private boolean mCharging = false; + private long mChargeConsumed = 0; + + private GT_Recipe mLastRecipe; + private long mEUStore; + private boolean mRunningOnLoad = false; + private boolean mMachine = false; + private int mEfficiency, mEfficiencyIncrease, mEfficiencyMax = 0; + private int mStartUpCheck = 100, mUpdate = 0; + private FluidStack[] mOutputFluids = null; + + public GregtechMetaTileEntity_PocketFusion(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, "It's like a midget Ra.", 1, 1, "PotionBrewer.png", ""); + } + + public GregtechMetaTileEntity_PocketFusion(String aName, int aTier, String aDescription, + ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + @Override + public String[] getDescription() { + return new String[] { this.mDescription, "Not Very Fast, but not very big either.", + "Each side pair in/out puts to different slots.", "Top & Bottom Sides are Outputs.", + "Front & Back are Input Plasma 1.", "Sides are Input Plasma 2.", CORE.GT_Tooltip }; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_PocketFusion(this.mName, this.mTier, this.mDescription, + this.mTextures, this.mGUIName, this.mNEIName); + } + + public int tier() { + return this.mTier; + } + + public int tierOverclock() { + return this.mTier == 6 ? 0 : this.mTier == 7 ? 1 : 2; + } + + private GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, + final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 + : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + + 1]; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sSlowFusionRecipes; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return aSide == this.getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return (aFluid.getFluid().getName().contains("plasma")) || (super.isFluidInputAllowed(aFluid)); + } + + @Override + public int getCapacity() { + return 32000; + } + + @Override + public void abortProcess() { + super.abortProcess(); + } + + long mFusionPoint = 20000000L; + + @Override + public int checkRecipe() { + Logger.MACHINE_INFO("Recipe Tick 1."); + if (!this.mCanProcessRecipe) { + Logger.MACHINE_INFO("Recipe Tick 1.1 - Cannot Process Recipe."); + if (this.mChargeConsumed < mFusionPoint) { + Logger.MACHINE_INFO("Recipe Tick 1.2 - Cannot Ignite Fusion, Charge too low."); + this.mCharging = true; + this.mCanProcessRecipe = false; + if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits((mFusionPoint / 100), false)) { + Logger.MACHINE_INFO("Recipe Tick 1.3 - Charging Internal storage. " + (mFusionPoint / 100) + "/" + + mFusionPoint); + mChargeConsumed += (mFusionPoint / 100); + } + } + else { + mChargeConsumed = 0; + this.mCharging = false; + this.mCanProcessRecipe = true; + + } + } + else { + Logger.MACHINE_INFO("Recipe Tick 1.1 - Try to Process Recipe."); + if (checkRecipeMulti()) { + Logger.MACHINE_INFO("Recipe Tick 1.2 - Process Recipe was Successful."); + return 2; + } + } + Logger.MACHINE_INFO("Recipe Tick 2. - Process Recipe failed."); + return 0; + } + + public ArrayList<FluidStack> getStoredFluids() { + ArrayList<FluidStack> mList = new ArrayList<FluidStack>(); + mList.add(this.mFluid); + mList.add(this.mFluid2); + return mList; + } + + public boolean checkRecipeMulti() { + ArrayList<FluidStack> tFluidList = getStoredFluids(); + int tFluidList_sS = tFluidList.size(); + for (int i = 0; i < tFluidList_sS - 1; i++) { + for (int j = i + 1; j < tFluidList_sS; j++) { + if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { + if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { + tFluidList.remove(j--); + tFluidList_sS = tFluidList.size(); + } + else { + tFluidList.remove(i--); + tFluidList_sS = tFluidList.size(); + break; + } + } + } + } + if (tFluidList.size() > 1) { + FluidStack[] tFluids = tFluidList.toArray(new FluidStack[tFluidList.size()]); + GT_Recipe tRecipe = getRecipeList().findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, false, + GT_Values.V[8], tFluids, new ItemStack[] {}); + + if (tRecipe == null) { + return false; + } + + if ((tRecipe == null && !mRunningOnLoad) || (tRecipe != null && maxEUStore() < tRecipe.mSpecialValue)) { + this.mLastRecipe = null; + Logger.MACHINE_INFO("Just plain bad."); + return false; + } + if (mRunningOnLoad || tRecipe.isRecipeInputEqual(true, tFluids, new ItemStack[] {})) { + this.mLastRecipe = tRecipe; + this.mEUt = (this.mLastRecipe.mEUt * overclock(this.mLastRecipe.mSpecialValue)); + this.mMaxProgresstime = this.mLastRecipe.mDuration / overclock(this.mLastRecipe.mSpecialValue); + + this.mEfficiencyIncrease = 10000; + + this.mOutputFluids = this.mLastRecipe.mFluidOutputs; + mRunningOnLoad = false; + return true; + } + } + return false; + } + + public int overclock(int mStartEnergy) { + if (tierOverclock() == 1) { + return 1; + } + if (tierOverclock() == 2) { + return mStartEnergy < 160000000 ? 2 : 1; + } + return mStartEnergy < 160000000 ? 4 : mStartEnergy < 320000000 ? 2 : 1; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean doesAutoOutputFluids() { + return true; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public long maxAmperesIn() { + return 16L; + } + + @Override + public long maxEUStore() { + return Long.MAX_VALUE; + } + + @Override + public void doExplosion(long aExplosionPower) { + super.doExplosion(aExplosionPower * 2); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + onRunningTickMulti(); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) + && (aBaseMetaTileEntity.getFrontFacing() != 1) && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) + && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { + if (MathUtils.randInt(0, 4) == 4) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), + aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), + (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), 0.0D, 0.0D, 0.0D); + aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.4F) - (tRandom.nextFloat() * 0.3F), + aBaseMetaTileEntity.getYCoord() + 0.2f + (tRandom.nextFloat() * 0.1F), + (aBaseMetaTileEntity.getZCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), 0.0D, 0.0D, 0.0D); + aBaseMetaTileEntity.getWorld().spawnParticle("magicCrit", + (aBaseMetaTileEntity.getXCoord() + 0.6F) - (tRandom.nextFloat() * 0.9F), + aBaseMetaTileEntity.getYCoord() + 0.4f + (tRandom.nextFloat() * 0.3F), + (aBaseMetaTileEntity.getZCoord() + 1.8F) - (tRandom.nextFloat() * 2.6F), 0.0D, 0.0D, 0.0D); + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mCanProcessRecipe", this.mCanProcessRecipe); + aNBT.setBoolean("mCharging", this.mCharging); + aNBT.setLong("mChargeConsumed", this.mChargeConsumed); + aNBT.setInteger("mEfficiency", this.mEfficiency); + aNBT.setInteger("mEfficiencyIncrease", this.mEfficiencyIncrease); + aNBT.setInteger("mEfficiencyMax", this.mEfficiencyMax); + aNBT.setInteger("mStartUpCheck", this.mStartUpCheck); + aNBT.setInteger("mUpdate", mUpdate); + aNBT.setInteger("mEfficiencyIncrease", mEfficiencyIncrease); + aNBT.setBoolean("mRunningOnLoad", this.mRunningOnLoad); + aNBT.setBoolean("mMachine", this.mMachine); + aNBT.setLong("mEUStore", this.mEUStore); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (mMaxProgresstime > 0) + mRunningOnLoad = true; + this.mCanProcessRecipe = aNBT.getBoolean("mCanProcessRecipe"); + this.mCharging = aNBT.getBoolean("mCharging"); + this.mChargeConsumed = aNBT.getLong("mChargeConsumed"); + this.mEfficiency = aNBT.getInteger("mEfficiency"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mEfficiencyMax = aNBT.getInteger("mEfficiencyMax"); + this.mStartUpCheck = aNBT.getInteger("mStartUpCheck"); + this.mUpdate = aNBT.getInteger("mUpdate"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mEfficiencyIncrease = aNBT.getInteger("mEfficiencyIncrease"); + this.mRunningOnLoad = aNBT.getBoolean("mRunningOnLoad"); + this.mMachine = aNBT.getBoolean("mMachine"); + this.mEUStore = aNBT.getLong("mEUStore"); + super.loadNBTData(aNBT); + } + + @Override + public String[] getInfoData() { + String tier = tier() == 6 ? "I" : tier() == 7 ? "II" : "III"; + float plasmaOut = 0; + String fusionName = ""; + int powerRequired = 0; + if (this.mLastRecipe != null) { + fusionName = this.mLastRecipe.mFluidOutputs[0].getLocalizedName() + " Fusion."; + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; + } + } + + return new String[] { "Fusion Reactor MK " + tier, "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + this.getEUVar() + " / " + maxEUStore(), "Plasma Output: " + plasmaOut + "L/t", + "Current Recipe: " + fusionName }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active) }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Blue) }; + } + + @Override + public void onMachineBlockUpdate() { + this.mUpdate = 50; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + // Logger.MACHINE_INFO("1"); + if (mEfficiency < 0) + mEfficiency = 0; + if (mRunningOnLoad) { + Logger.MACHINE_INFO("2"); + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + checkRecipeMulti(); + } + if (--mUpdate == 0 || --mStartUpCheck == 0) { + Logger.MACHINE_INFO("3"); + mMachine = true; + } + if (mStartUpCheck < 0) { + //Logger.MACHINE_INFO("4"); + if (mMachine) { + //Logger.MACHINE_INFO("5"); + + if (aBaseMetaTileEntity.getStoredEU() + (2048 * tierOverclock()) < maxEUStore()) { + if (aBaseMetaTileEntity.increaseStoredEnergyUnits(2048 * tierOverclock(), true)) { + //Logger.MACHINE_INFO("5.5 A"); + } + else { + //Logger.MACHINE_INFO("5.5 B"); + } + } + if (this.mEUStore <= 0 && mMaxProgresstime > 0) { + Logger.MACHINE_INFO("6"); + stopMachine(); + this.mLastRecipe = null; + } + if (mMaxProgresstime > 0) { + Logger.MACHINE_INFO("7"); + this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt, true); + if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { + if (mOutputFluids != null) + for (FluidStack tStack : mOutputFluids) + if (tStack != null) + addOutput(tStack); + mEfficiency = Math.max(0, (mEfficiency + mEfficiencyIncrease)); + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + if (mOutputFluids != null && mOutputFluids.length > 0) { + + } + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + if (aBaseMetaTileEntity.isAllowedToWork()) + checkRecipeMulti(); + } + } + else { + //Logger.MACHINE_INFO("8"); + this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); + if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() + || aBaseMetaTileEntity.hasInventoryBeenModified()) { + Logger.MACHINE_INFO("9"); + // turnCasingActive(mMaxProgresstime > 0); + if (aBaseMetaTileEntity.isAllowedToWork()) { + Logger.MACHINE_INFO("10"); + if (checkRecipeMulti()) { + Logger.MACHINE_INFO("11"); + if (this.mEUStore < this.mLastRecipe.mSpecialValue) { + Logger.MACHINE_INFO("12"); + mMaxProgresstime = 0; + // turnCasingActive(false); + } + aBaseMetaTileEntity.decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue, true); + } + } + if (mMaxProgresstime <= 0) + mEfficiency = Math.max(0, mEfficiency - 1000); + } + } + } + else { + // turnCasingActive(false); + Logger.MACHINE_INFO("Bad"); + this.mLastRecipe = null; + stopMachine(); + } + } + Logger.MACHINE_INFO("Good | "+mMaxProgresstime); + aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); + } + } + + public boolean onRunningTickMulti() { + if (this.getBaseMetaTileEntity().isServerSide()) { + if (mEUt < 0) { + if (!drainEnergyInput(((long) -mEUt * 10000) / Math.max(1000, mEfficiency))) { + this.mLastRecipe = null; + stopMachine(); + Logger.MACHINE_INFO("a1"); + return false; + } + } + if (this.mEUStore <= 0) { + this.mLastRecipe = null; + stopMachine(); + Logger.MACHINE_INFO("a2"); + return false; + } + } + return true; + } + + public boolean drainEnergyInput(long aEU) { + return false; + } + + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) + return false; + FluidStack copiedFluidStack = aLiquid.copy(); + this.mOutputFluid = copiedFluidStack; + return false; + } + + public void stopMachine() { + mEUt = 0; + mEfficiency = 0; + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + getBaseMetaTileEntity().disableWorking(); + } + + @Override + public boolean isLiquidInput(byte aSide) { + switch (aSide) { + case 0: + return true; + case 1: + return true; + case 2: + return true; + case 3: + return false; + case 4: + return false; + case 5: + return false; + default: + return false; + } + } + + @Override + public boolean isLiquidOutput(byte aSide) { + switch (aSide) { + case 0: + return false; + case 1: + return false; + case 2: + return false; + case 3: + return true; + case 4: + return true; + case 5: + return true; + default: + return true; + } + } + + @Override + public int fill(FluidStack aFluid, boolean doFill) { + return super.fill(aFluid, doFill); + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return super.drain(maxDrain, doDrain); + } + + @Override + public int getTankPressure() { + return 500; + } + + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return false; + } + else { + return super.canFill(aSide, aFluid); + } + } + + @Override + public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.canDrain(aSide, aFluid); + } + else { + return false; + } + } + + @Override + public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return 0; + } + else { + return super.fill_default(aSide, aFluid, doFill); + } + } + + @Override + public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.fill(aSide, aFluid, doFill); + } + else { + return 0; + } + } + + @Override + public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.drain(aSide, aFluid, doDrain); + } + else { + return null; + } + } + + @Override + public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { + if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) { + return super.drain(aSide, maxDrain, doDrain); + } + else { + return null; + } + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + // TODO Auto-generated method stub + return super.onRightclick(aBaseMetaTileEntity, aPlayer); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, + float aY, float aZ) { + // TODO Auto-generated method stub + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + // TODO Auto-generated method stub + return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + // TODO Auto-generated method stub + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + return false; + } + + @Override + public void onExplosion() { + // TODO Auto-generated method stub + super.onExplosion(); + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 1) { + GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(212)), 10, 1.0F, aX, aY, + aZ); + } + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorColdTrap.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorColdTrap.java new file mode 100644 index 0000000000..85e2df42c9 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorColdTrap.java @@ -0,0 +1,67 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_ReactorColdTrap extends GT_MetaTileEntity_BasicMachine { + + public GregtechMetaTileEntity_ReactorColdTrap(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, + "Just like the Arctic", 2, 9, "Dehydrator.png", "", + new ITexture[]{ + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_SIDE_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_SIDE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_FRONT_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_FRONT), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_COLDTRAP_TOP) + } + ); + } + + public GregtechMetaTileEntity_ReactorColdTrap(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + @Override + public String[] getDescription() { + return new String[]{this.mDescription, "Does not require ice cubes", CORE.GT_Tooltip}; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_ReactorColdTrap(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sColdTrapRecipes; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (getRecipeList().containsInput(aStack)); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return super.isFluidInputAllowed(aFluid); + } + + @Override + public int getCapacity() { + return 16000 * Math.max(1, this.mTier); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorProcessingUnit.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorProcessingUnit.java new file mode 100644 index 0000000000..60e2ec8c0a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_ReactorProcessingUnit.java @@ -0,0 +1,67 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_ReactorProcessingUnit extends GT_MetaTileEntity_BasicMachine { + + public GregtechMetaTileEntity_ReactorProcessingUnit(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, + "Processes Nuclear things", 2, 9, "Dehydrator.png", "", + new ITexture[]{ + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_SIDE_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_SIDE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_FRONT_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_FRONT), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.OVERLAY_REACTOR_PROCESSINGUNIT_TOP) + } + ); + } + + public GregtechMetaTileEntity_ReactorProcessingUnit(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + @Override + public String[] getDescription() { + return new String[]{this.mDescription, CORE.GT_Tooltip}; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_ReactorProcessingUnit(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GTPP_Recipe.GTPP_Recipe_Map.sReactorProcessingUnitRecipes; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (getRecipeList().containsInput(aStack)); + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return super.isFluidInputAllowed(aFluid); + } + + @Override + public int getCapacity() { + return 8000 * Math.max(1, this.mTier); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java new file mode 100644 index 0000000000..ffaa77a0be --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java @@ -0,0 +1,560 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import gregtech.api.enums.GT_Values; +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 gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.helpers.ChargingHelper; + +public class GregtechMetaWirelessCharger extends GregtechMetaTileEntity { + + private boolean mHasBeenMapped = false; + private int mCurrentDimension = 0; + public int mMode = 0; + + public GregtechMetaWirelessCharger(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaWirelessCharger(final String aName, final int aTier, final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {this.mDescription, + "3 Modes, Long-Range, Local and Mixed.", + "Long-Range: Can supply 2A of power to a single player up to "+(GT_Values.V[this.mTier]*4)+"m away.", + "Local: Can supply several Amps to each player within "+this.mTier*20+"m.", + "Mixed: Provides both 2A of long range and 1A per player locally.", + "Mixed mode is more conservative of power and as a result only", + "Gets half the distances each singular mode gets.", + CORE.GT_Tooltip + }; + } + + public int getTier(){ + return this.mTier; + } + + public int getMode(){ + return this.mMode; + } + + public int getDimensionID(){ + return this.mCurrentDimension; + } + + public Map<UUID, EntityPlayer> getLocalMap(){ + return this.mLocalChargingMap; + } + + public Map<EntityPlayer, UUID> getLongRangeMap(){ + return this.mWirelessChargingMap; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; + } + + + public ITexture[] getFront(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; + } + + + public ITexture[] getBack(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getTop(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getSides(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; + } + + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom)}; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + + if (!this.getBaseMetaTileEntity().getWorld().playerEntities.isEmpty()){ + for (Object mTempPlayer : this.getBaseMetaTileEntity().getWorld().playerEntities){ + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP){ + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + + if (this.mMode >= 2){ + this.mMode = 0; + } + else { + this.mMode++; + } + if (this.mMode == 0){ + PlayerUtils.messagePlayer(aPlayer, "Now in Long-Range Charge Mode."); + } + else if (this.mMode == 1){ + PlayerUtils.messagePlayer(aPlayer, "Now in Local Charge Mode."); + } + else { + PlayerUtils.messagePlayer(aPlayer, "Now in Mixed Charge Mode."); + } + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaWirelessCharger(this.mName, this.mTier, this.mDescription, this.mTextures, this.mInventory.length); + } + + @Override public boolean isSimpleMachine() {return false;} + @Override public boolean isElectric() {return true;} + @Override public boolean isValidSlot(final int aIndex) {return true;} + @Override public boolean isFacingValid(final byte aFacing) {return true;} + @Override public boolean isEnetInput() {return true;} + @Override public boolean isEnetOutput() {return false;} + @Override public boolean isInputFacing(final byte aSide) {return aSide!=this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isOutputFacing(final byte aSide) {return aSide==this.getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isTeleporterCompatible() {return false;} + @Override public long getMinimumStoredEU() {return 0;} + @Override public long maxEUStore() {return GT_Values.V[this.mTier]*128;} + + @Override + public int getCapacity() { + return (int) (GT_Values.V[this.mTier]*32); + } + + @Override + public long maxEUInput() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + if (this.mMode == 0){ + return 2; + } + else if (this.mMode == 1){ + return this.mLocalChargingMap.size()*8; + } + else { + return ((this.mLocalChargingMap.size()*4)+this.mWirelessChargingMap.size()); + } + } + + @Override + public long maxAmperesOut() { + return 0; + } + @Override public int rechargerSlotStartIndex() {return 0;} + @Override public int dechargerSlotStartIndex() {return 0;} + @Override public int rechargerSlotCount() {return 0;} + @Override public int dechargerSlotCount() {return 0;} + @Override public int getProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyStored();} + @Override public int maxProgresstime() {return (int)this.getBaseMetaTileEntity().getUniversalEnergyCapacity();} + @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) + { + return true; + } + return true; + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + return new String[] { + this.getLocalName()}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) { + } + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mMode", this.mMode); + aNBT.setInteger("mCurrentDimension", this.mCurrentDimension); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mMode = aNBT.getInteger("mMode"); + this.mCurrentDimension = aNBT.getInteger("mCurrentDimension"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + + private Map<EntityPlayer, UUID> mWirelessChargingMap = new HashMap<EntityPlayer, UUID>(); + private Map<UUID, EntityPlayer> mLocalChargingMap = new HashMap<UUID, EntityPlayer>(); + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.getBaseMetaTileEntity().isServerSide()) { + + if (this.mCurrentDimension != aBaseMetaTileEntity.getWorld().provider.dimensionId){ + this.mCurrentDimension = aBaseMetaTileEntity.getWorld().provider.dimensionId; + } + + if (!mHasBeenMapped && ChargingHelper.addEntry(getTileEntityPosition(), this)){ + mHasBeenMapped = true; + } + + if (aTick % 20 == 0 && mHasBeenMapped){ + if (!aBaseMetaTileEntity.getWorld().playerEntities.isEmpty()){ + for (Object mTempPlayer : aBaseMetaTileEntity.getWorld().playerEntities){ + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP){ + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + + if (this.mMode == 1 || this.mMode == 2){ + int tempRange = (this.mMode == 1 ? this.mTier*20 : this.mTier*10); + if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) < tempRange){ + if (!mLocalChargingMap.containsKey(mTemp.getPersistentID())){ + mLocalChargingMap.put(mTemp.getPersistentID(), mTemp); + ChargingHelper.addValidPlayer(mTemp, this); + //PlayerUtils.messagePlayer(mTemp, "You have entered charging range. ["+tempRange+"m - Local]."); + } + } + else { + if (mLocalChargingMap.containsKey(mTemp.getPersistentID())){ + if (mLocalChargingMap.remove(mTemp.getPersistentID()) != null){ + //PlayerUtils.messagePlayer(mTemp, "You have left charging range. ["+tempRange+"m - Local]."); + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + } + if (this.mMode == 0 || this.mMode == 2){ + int tempRange = (int) (this.mMode == 0 ? 4*GT_Values.V[this.mTier] : 2*GT_Values.V[this.mTier]); + if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) <= tempRange){ + if (!mWirelessChargingMap.containsKey(mTemp)){ + if (mTemp.getDisplayName().equalsIgnoreCase(this.getBaseMetaTileEntity().getOwnerName())) { + mWirelessChargingMap.put(mTemp, mTemp.getPersistentID()); + ChargingHelper.addValidPlayer(mTemp, this); + PlayerUtils.messagePlayer(mTemp, "You have entered charging range. ["+tempRange+"m - Long-Range]."); + } + } + } + else { + if (mWirelessChargingMap.containsKey(mTemp)){ + if (mWirelessChargingMap.remove(mTemp) != null){ + PlayerUtils.messagePlayer(mTemp, "You have left charging range. ["+tempRange+"m - Long Range]."); + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + if (mWirelessChargingMap.containsKey(mTemp) && !mTemp.getDisplayName().equalsIgnoreCase(this.getBaseMetaTileEntity().getOwnerName())){ + if (mWirelessChargingMap.remove(mTemp) != null){ + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + /*if (this.mMode == 0 || this.mMode == 2){ + int tempRange = (int) (this.mMode == 0 ? 4*GT_Values.V[this.mTier] : 2*GT_Values.V[this.mTier]); + if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) < tempRange){ + if (!mWirelessChargingMap.containsKey(mTemp)){ + mWirelessChargingMap.put(mTemp, mTemp.getPersistentID()); + PlayerUtils.messagePlayer(mTemp, "You have entered charging range. ["+tempRange+"m]."); + ChargingHelper.addValidPlayer(mTemp, this); + } + } + else { + if (mWirelessChargingMap.containsKey(mTemp)){ + if (mWirelessChargingMap.remove(mTemp) != null){ + PlayerUtils.messagePlayer(mTemp, "You have left charging range. ["+tempRange+"m]."); + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + } */ + + } + } + } + } + + + } + } + + public BlockPos getTileEntityPosition(){ + return new BlockPos(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord(), this.getBaseMetaTileEntity().getWorld()); + } + + public BlockPos getPositionOfEntity(Entity mEntity){ + if (mEntity == null){ + return null; + } + return EntityUtils.findBlockPosUnderEntity(mEntity); + } + + public double getDistanceBetweenTwoPositions(BlockPos objectA, BlockPos objectB){ + if (objectA == null || objectB == null){ + return 0f; + } + int[] objectArray1 = new int[]{objectA.xPos, objectA.yPos, objectA.zPos}; + int[] objectArray2 = new int[]{objectB.xPos, objectB.yPos, objectB.zPos}; + + final double distance = Math.sqrt( + (objectArray2[0]-objectArray1[0])*(objectArray2[0]-objectArray1[0]) + +(objectArray2[1]-objectArray1[1])*(objectArray2[1]-objectArray1[1]) + +(objectArray2[2]-objectArray1[2])*(objectArray2[2]-objectArray1[2])); + return distance; + } + + @Override + public void onRemoval() { + + ChargingHelper.removeEntry(getTileEntityPosition(), this); + + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + if (!this.getBaseMetaTileEntity().getWorld().playerEntities.isEmpty()){ + for (Object mTempPlayer : this.getBaseMetaTileEntity().getWorld().playerEntities){ + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP){ + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + + + super.onRemoval(); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, + EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + + int tempRange; + + if (this.mMode == 0 || this.mMode == 2){ + tempRange = (int) (this.mMode == 0 ? 4*GT_Values.V[this.mTier] : 2*GT_Values.V[this.mTier]); + } + else { + tempRange = this.mMode == 1 ? this.mTier*20 : this.mTier*10; + } + + if (this.mMode == 2){ + PlayerUtils.messagePlayer(aPlayer, "Mixed Mode | Local: "+this.mTier*10+"m | Long: "+tempRange+"m"); + } + else if (this.mMode == 1){ + PlayerUtils.messagePlayer(aPlayer, "Local Mode: "+this.mTier*20+"m"); + + } + else { + PlayerUtils.messagePlayer(aPlayer, "Long-range Mode: "+tempRange+"m"); + + } + + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + + @Override + public void onServerStart() { + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + super.onServerStart(); + } + + @Override + public void onExplosion() { + ChargingHelper.removeEntry(getTileEntityPosition(), this); + super.onExplosion(); + } + + @Override + public void doExplosion(long aExplosionPower) { + ChargingHelper.removeEntry(getTileEntityPosition(), this); + super.doExplosion(aExplosionPower); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (!mHasBeenMapped && ChargingHelper.addEntry(getTileEntityPosition(), this)){ + mHasBeenMapped = true; + } + super.onPreTick(aBaseMetaTileEntity, aTick); + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java new file mode 100644 index 0000000000..b8f24d6c5e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java @@ -0,0 +1,323 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.misc; + +import java.util.ArrayList; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.*; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.ItemStackData; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GMTE_AmazonPackager extends GregtechMeta_MultiBlockBase { + + private long mVoltage; + private byte mTier; + private int mCasing; + private IStructureDefinition<GMTE_AmazonPackager> STRUCTURE_DEFINITION = null; + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GMTE_AmazonPackager(mName); + } + + public GMTE_AmazonPackager(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GMTE_AmazonPackager(String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Packager"; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "Generic3By3"; + } + + @Override + public IStructureDefinition<GMTE_AmazonPackager> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GMTE_AmazonPackager>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GMTE_AmazonPackager::addAmazonPackagerList, TAE.getIndexFromPage(2, 9), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings3Misc, 9 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + + + public final boolean addAmazonPackagerList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Amazon Warehouse") + .addInfo("This Multiblock is used for EXTREME packaging requirements") + .addInfo("Dust Schematics are inserted into the input busses") + .addInfo("If inserted into the controller, it is shared across all busses") + .addInfo("1x, 2x, 3x & Other Schematics are to be placed into the controller GUI slot") + .addInfo("Uncomparably fast compared to a single packager of the same tier") + .addInfo("Only uses 75% of the eu/t normally required") + .addInfo("Processes five items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Supply Depot Casings", 10) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher("GT++"); + return tt; + } + + private final void initFields() { + mVoltage = getMaxInputVoltage(); + mTier = (byte) Math.max(1, GT_Utility.getTier(mVoltage)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.getIndexFromPage(2, 1)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.getIndexFromPage(2, 1))}; + } + + + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes; + } + + public void sortInputBusses() { + for (GT_MetaTileEntity_Hatch_InputBus h : this.mInputBusses) { + h.updateSlots(); + } + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + + //Just the best place to check this~ + initFields(); + + ArrayList<ItemStack> tItems = getStoredInputs(); + if (this.getGUIItemStack() != null) { + tItems.add(this.getGUIItemStack()); + } + ArrayList<FluidStack> tFluids = getStoredFluids(); + ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); + FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); + boolean state = checkRecipeGeneric(tItemInputs, tFluidInputs, 5 * GT_Utility.getTier(this.getMaxInputVoltage()), 75, 500, 10000); + + + if (state) { + return true; + } + else { + tItems = getStoredInputs(); + AutoMap<ItemStackData> mCompleted = new AutoMap<ItemStackData>(); + AutoMap<ItemStackData> mSchematics = new AutoMap<ItemStackData>(); + for (ItemStack tInputItem : tItems) { + if (tInputItem != null) { + if (ItemList.Schematic_1by1.isStackEqual((Object) tInputItem) || ItemList.Schematic_2by2.isStackEqual((Object) tInputItem) || ItemList.Schematic_3by3.isStackEqual((Object) tInputItem)) { + mSchematics.put(new ItemStackData(tInputItem)); + } + } + } + if (mSchematics.size() > 0) { + for (ItemStackData g : mSchematics) { + for (ItemStack tInputItem : tItems) { + if (tInputItem != null) { + mCompleted.put(new ItemStackData(tInputItem)); + checkRecipe(tInputItem, g.getStack()); + } + } + } + } + + return mCompleted != null && mCompleted.size() > 0; + } + } + + public boolean checkRecipe(ItemStack inputStack, ItemStack schematicStack) { + if (GT_Utility.isStackValid((Object) inputStack) && GT_Utility.isStackValid((Object) schematicStack) + && GT_Utility.getContainerItem(inputStack, true) == null) { + ItemStack tOutputStack; + if (ItemList.Schematic_1by1.isStackEqual((Object) schematicStack)&& inputStack.stackSize >= 1) { + tOutputStack = GT_ModHandler.getRecipeOutput(new ItemStack[]{inputStack}); + if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { + final ItemStack input = inputStack; + --input.stackSize; + this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + //this.mMaxProgresstime = 16 / (1 << this.mTier - 1); + this.mMaxProgresstime = 2; + this.addOutput(tOutputStack); + updateSlots(); + return true; + } + return false; + } else if (ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) + && inputStack.stackSize >= 4) { + tOutputStack = GT_ModHandler.getRecipeOutput(new ItemStack[]{inputStack, + inputStack, null, inputStack, inputStack}); + if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { + final ItemStack input2 = inputStack; + input2.stackSize -= 4; + this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + //this.mMaxProgresstime = 32 / (1 << this.mTier - 1); + this.mMaxProgresstime = 4; + this.addOutput(tOutputStack); + updateSlots(); + return true; + } + return false; + } else if (ItemList.Schematic_3by3.isStackEqual((Object) schematicStack) + && inputStack.stackSize >= 9) { + tOutputStack = GT_ModHandler.getRecipeOutput(new ItemStack[]{inputStack, + inputStack, inputStack, inputStack, inputStack, + inputStack, inputStack, inputStack, inputStack}); + if (tOutputStack != null && this.allowPutStack(tOutputStack, schematicStack)) { + final ItemStack input3 = inputStack; + input3.stackSize -= 9; + this.mEUt = 32 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + //this.mMaxProgresstime = 64 / (1 << this.mTier - 1); + this.mMaxProgresstime = 6; + this.addOutput(tOutputStack); + updateSlots(); + return true; + } + return false; + } + } + return false; + } + + public boolean allowPutStack(final ItemStack aStack, ItemStack schematicStack) { + //If Schematic Static is not 1x1, 2x2, 3x3 + if (!ItemList.Schematic_1by1.isStackEqual((Object) schematicStack) && !ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) && !ItemList.Schematic_3by3.isStackEqual((Object) schematicStack)) { + return GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.containsInput(aStack); + } + //Something + if (GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.findRecipe((IHasWorldObjectAndCoords) this.getBaseMetaTileEntity(), true, GT_Values.V[this.mTier], + (FluidStack[]) null, new ItemStack[]{GT_Utility.copyAmount(64L, new Object[]{aStack}), schematicStack}) != null) { + return true; + } + //1x1 + if (ItemList.Schematic_1by1.isStackEqual((Object) schematicStack) + && GT_ModHandler.getRecipeOutput(new ItemStack[]{aStack}) != null) { + return true; + } + //2x2 + if (ItemList.Schematic_2by2.isStackEqual((Object) schematicStack) + && GT_ModHandler.getRecipeOutput(new ItemStack[]{aStack, aStack, null, aStack, aStack}) != null) { + return true; + } + //3x3 + if (ItemList.Schematic_3by3.isStackEqual((Object) schematicStack) && GT_ModHandler.getRecipeOutput( + new ItemStack[]{aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack}) != null) { + return true; + } + return false; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + public int getMaxEfficiency(ItemStack p0) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack arg0){ + return CORE.ConfigSwitches.pollutionPerSecondMultiPackager; + } + + @Override + public int getMaxParallelRecipes() { + return 9; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GregtechMTE_TeslaTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GregtechMTE_TeslaTower.java new file mode 100644 index 0000000000..7ddf16b36f --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GregtechMTE_TeslaTower.java @@ -0,0 +1,479 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.misc; + +import static gregtech.api.enums.GT_Values.*; + +import java.util.*; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.entity.EntityTeslaTowerLightning; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.MaterialUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraftforge.common.util.ForgeDirection; + +public class GregtechMTE_TeslaTower extends GregtechMeta_MultiBlockBase { + + private Block casingBlock; + private int casingMeta; + private int frameMeta; + private int casingTextureIndex; + + private ForgeDirection back; + + private int xLoc, yLoc, zLoc; + + protected int mRange; + */ +/** + * Machine Mode, + * {@value false} Attacks all entities, + * {@value true} Only attacks players. + *//* + + protected volatile boolean mMode = false; + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMTE_TeslaTower(mName); + } + + public GregtechMTE_TeslaTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + initFields(); + } + + public GregtechMTE_TeslaTower(String aName) { + super(aName); + initFields(); + } + + @Override + public String getMachineType() { + return "Weaponized Lighting Rod"; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String[] getTooltip() { + String casings = getCasingBlockItem().get(0).getDisplayName(); + return new String[]{ + "Controller Block for the Tesla Defence Tower Mk3200", + "Enemies within "+this.mRange+"m are blasted with a high energy plasma.", + "This uses 5,000,000EU per blast.", + "Can screwdriver to toggle mode between Players and all Entities.", + "Size(WxHxD): 3x7x3", "Controller (Front middle at bottom)", + "3x1x3 Base of " + casings, + "1x3x1 " + casings + " pillar (Center of base)", + "1x3x1 " + MaterialUtils.getMaterialName(getFrameMaterial()) + " Frame Boxes (Each pillar side and on top)", + "1x Maintenance Hatch (One of base casings)", + "1x " + VN[getMinTier()] + "+ Energy Hatch (Any bottom layer casing)"}; + } + + private final void initFields() { + casingBlock = ModBlocks.blockCasings2Misc; + casingMeta = getCasingBlockItem().get(0).getItemDamage(); + int frameId = 4096 + getFrameMaterial().mMetaItemSubID; + frameMeta = GregTech_API.METATILEENTITIES[frameId] != null ? GregTech_API.METATILEENTITIES[frameId].getTileEntityBaseType() : W; + casingTextureIndex = getCasingTextureIndex(); + mRange = 50; + } + + @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()), new GT_RenderedTexture(aActive ? gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex())}; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mMode", this.mMode); + aNBT.setInteger("mRange", this.mRange); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mMode = aNBT.getBoolean("mMode"); + this.mRange = aNBT.getInteger("mRange"); + super.loadNBTData(aNBT); + } + + private boolean isEnergyEnough() { + if (this.getEUVar() >= 5000000){ + return true; + } + return false; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + */ +/*if (!isEnergyEnough()) { + this.mProgresstime = 0; + this.mMaxProgresstime = 20; + this.getBaseMetaTileEntity().setActive(false); + stopMachine(); + } + else {*//* +*/ +/* + this.mProgresstime = 1; + this.mMaxProgresstime = 100; + this.getBaseMetaTileEntity().setActive(true);*//* + + //} + return false; + } + + @Override + public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + updateCoordinates(); + //check base layer + for (int xOff = -1 + back.offsetX; xOff <= 1 + back.offsetX; xOff++) { + for (int zOff = -1 + back.offsetZ; zOff <= 1 + back.offsetZ; zOff++) { + if (xOff == 0 && zOff == 0) continue; + + IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xOff, 0, zOff); + if (!checkCasingBlock(xOff, 0, zOff) + && !addMaintenanceToMachineList(tTileEntity, casingTextureIndex) + && !addEnergyInputToMachineList(tTileEntity, casingTextureIndex)){ + Logger.INFO("bad block"); + return false; + } + } + } + if(!checkHatches()){ + Logger.INFO("bad Hatches"); + return false; + } + if (GT_Utility.getTier(getMaxInputVoltage()) < getMinTier()){ + Logger.INFO("bad Voltage"); + return false; + } + //check tower + for (int yOff = 1; yOff < 4; yOff++) { + if (!checkCasingBlock(back.offsetX, yOff, back.offsetZ) + || !checkFrameBlock(back.offsetX + 1, yOff, back.offsetZ) + || !checkFrameBlock(back.offsetX - 1, yOff, back.offsetZ) + || !checkFrameBlock(back.offsetX, yOff, back.offsetZ + 1) + || !checkFrameBlock(back.offsetX, yOff, back.offsetZ - 1) + || !checkFrameBlock(back.offsetX, yOff + 3, back.offsetZ)){ + Logger.INFO("bad frame?"); + return false; + } + } + Logger.INFO("good"); + return true; + } + + private void updateCoordinates() { + casingTextureIndex = getCasingTextureIndex(); + mRange = 50; + xLoc = getBaseMetaTileEntity().getXCoord(); + yLoc = getBaseMetaTileEntity().getYCoord(); + zLoc = getBaseMetaTileEntity().getZCoord(); + back = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()); + } + + protected boolean checkCasingBlock(int xOff, int yOff, int zOff) { + Logger.INFO("Looking For Casing."); + return checkBlockAndMetaOffset(xOff, yOff, zOff, casingBlock, casingMeta); + } + //meta of frame is getTileEntityBaseType; frame should be checked using its drops (possible a high weight operation) + protected boolean checkFrameBlock(int xOff, int yOff, int zOff) { + Logger.INFO("Looking For Frame."); + return checkBlockAndMetaOffset(xOff, yOff, zOff, GregTech_API.sBlockMachines, frameMeta); + } + + protected boolean checkBlockAndMetaOffset(int xOff, int yOff, int zOff, Block block, int meta) { + return checkBlockAndMeta(xLoc + xOff, yLoc + yOff, zLoc + zOff, block, meta); + } + + private boolean checkBlockAndMeta(int x, int y, int z, Block block, int meta) { + Logger.INFO("Found: "+getBaseMetaTileEntity().getBlock(x, y, z).getLocalizedName()+" | Meta: "+getBaseMetaTileEntity().getMetaID(x, y, z)); + Logger.INFO("Expected: "+block.getLocalizedName()+" | Meta: "+meta); + return (meta == W || getBaseMetaTileEntity().getMetaID(x, y, z) == meta) + && getBaseMetaTileEntity().getBlock(x, y, z) == block; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + protected int getMinTier() { + return 7; + } + + protected boolean checkHatches() { + return !mMaintenanceHatches.isEmpty() && !mEnergyHatches.isEmpty(); + } + + private Map<Pair<Long, Long>, Entity> mInRange = new HashMap<Pair<Long, Long>, Entity>(); + + @SuppressWarnings("unchecked") + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + try { + if (this.getBaseMetaTileEntity().isServerSide()){ + if (this.mEnergyHatches.size() > 0) { + for (final GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches){ + if (isValidMetaTileEntity(tHatch)) { + long mHT = tHatch.getBaseMetaTileEntity().getInputVoltage(); + if (tHatch.getEUVar() >= mHT) { + for (int o=0;o<(tHatch.getEUVar()/mHT);o++){ + //1A + if (this.getEUVar()<(this.maxEUStore()-mHT)){ + tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mHT, false); + this.setEUVar(this.getEUVar()+mHT); + } + //2A + if (this.getEUVar()<(this.maxEUStore()-mHT)){ + tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mHT, false); + this.setEUVar(this.getEUVar()+mHT); + } + } + } + } + } + } + + if (aTick % 10 == 0){ + if (this.getEUVar() >= 5000000){ + //Logger.INFO("Can Zap."); + this.getBaseMetaTileEntity().enableWorking(); + this.getBaseMetaTileEntity().setActive(true); + if (this.mProgresstime <= 0){ + this.mProgresstime++; + } + else if (this.mProgresstime >= 100){ + this.mProgresstime = 0; + } + this.mMaxProgresstime = 10000; + } + //Logger.INFO("Allowed to be Working? "+this.getBaseMetaTileEntity().isAllowedToWork()); + //Logger.INFO("Working? "+this.getBaseMetaTileEntity().isActive()); + //Logger.INFO("Has Working just been enabled? "+this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()); + } + + + if (aTick % 20 == 0){ + List<Object> o = aBaseMetaTileEntity.getWorld().loadedEntityList; + //Clean up old entities first + if (this.mInRange.size() > 0){ + for (Entity j : this.mInRange.values()){ + if (((Entity) j).getDistance(this.xLoc, this.yLoc, this.zLoc) > this.mRange){ + mInRange.remove(new Pair<Long, Long>(((Entity) j).getUniqueID().getMostSignificantBits(), ((Entity) j).getUniqueID().getLeastSignificantBits()), (Entity) j); + } + } + } + //Add new entities + if (o.size() > 0){ + for (Object r : o){ + if (r instanceof Entity){ + if (!((Entity) r).getUniqueID().equals(getOwner())){ + if (((Entity) r).isEntityAlive() || r instanceof EntityLiving){ + if (((Entity) r).getDistance(this.xLoc, this.yLoc, this.zLoc) <= this.mRange){ + if (r instanceof EntityItem){ + //Do nothing + } + else { + if (!this.mMode){ + mInRange.put(new Pair<Long, Long>(((Entity) r).getUniqueID().getMostSignificantBits(), ((Entity) r).getUniqueID().getLeastSignificantBits()), (Entity) r); + } + else { + if (r instanceof EntityPlayer){ + mInRange.put(new Pair<Long, Long>(((Entity) r).getUniqueID().getMostSignificantBits(), ((Entity) r).getUniqueID().getLeastSignificantBits()), (Entity) r); + } + } + } + } + } + } + } + } + } + } + } + } + catch (Throwable r){ + + } + super.onPreTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + try { + if (this.getBaseMetaTileEntity().isServerSide()){ + //Handle Progress Time + if (this.getEUVar() >= 0 && !this.getBaseMetaTileEntity().isAllowedToWork()){ + this.mProgresstime = 20; + this.mMaxProgresstime = 40; + } + else if (this.getEUVar() >= 0 && this.getBaseMetaTileEntity().isAllowedToWork()){ + this.mProgresstime = 20; + this.mMaxProgresstime = 40; + } + + if (aTick % 10 == 0){ + if (this.mInRange.size() > 0){ + if (this.getEUVar() >= 5000000){ + + for (Entity f : mInRange.values()){ + if (f instanceof EntityLiving){ + int j1 = (int) f.posX; + int l1 = (int) f.posY; + int k1 = (int) f.posZ; + World world = aBaseMetaTileEntity.getWorld(); + + if (f.isEntityAlive() && !f.getUniqueID().equals(getOwner())){ + //if (world.canLightningStrikeAt(j1, l1+1, k1)){ + //if (isEnergyEnough() && world.addWeatherEffect(new EntityTeslaTowerLightning(world, (double)j1, (double)l1, (double)k1))){ + if (isEnergyEnough() && world.addWeatherEffect(new EntityTeslaTowerLightning(world, (double)j1, (double)l1, (double)k1, f, getOwner()))){ + if (f == null || f.isDead || !f.isEntityAlive()){ + this.mInRange.remove(new Pair<Long, Long>(f.getUniqueID().getMostSignificantBits(), f.getUniqueID().getLeastSignificantBits())); + } + this.setEUVar(this.getEUVar()-5000000); + } + //} + } + + } + } + } + } + } + } + } + catch (Throwable r){ + + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + + protected GregtechItemList getCasingBlockItem() { + return GregtechItemList.Casing_TeslaTower; + } + + protected Materials getFrameMaterial() { + */ +/*casingBlock = getCasingBlockItem().getBlock(); + casingMeta = getCasingBlockItem().get(0).getItemDamage(); + int frameId = 4096 + getFrameMaterial().mMetaItemSubID; + frameMeta = GregTech_API.METATILEENTITIES[frameId] != null ? GregTech_API.METATILEENTITIES[frameId].getTileEntityBaseType() : W; + *//* +return Materials.get("TungstenCarbide"); + } + + protected int getCasingTextureIndex() { + return TAE.GTPP_INDEX(30); + } + + public UUID getOwner(){ + return PlayerUtils.getPlayersUUIDByName(this.getBaseMetaTileEntity().getOwnerName()); + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public long maxAmperesIn() { + return 32; + } + + @Override + public long maxEUInput() { + return 131072; + } + + @Override + public long maxEUStore() { + return Integer.MAX_VALUE; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mMode = Utils.invertBoolean(mMode); + this.mInRange.clear(); + if (mMode){ + PlayerUtils.messagePlayer(aPlayer, "[Tesla Tower] Now only targetting players."); + } + else { + PlayerUtils.messagePlayer(aPlayer, "[Tesla Tower] Targetting all types of entities."); + } + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java new file mode 100644 index 0000000000..df01d01679 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java @@ -0,0 +1,403 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.List; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.core.lib.CORE; +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_IndustrialAlloySmelter extends GregtechMeta_MultiBlockBase { + + public static int CASING_TEXTURE_ID; + private HeatingCoilLevel mHeatingCapacity; + private int mLevel = 0; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialAlloySmelter> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialAlloySmelter(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 1); + } + + public GregtechMetaTileEntity_IndustrialAlloySmelter(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 1); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialAlloySmelter(this.mName); + } + + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID), new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "MultiFurnace.png"); + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sAlloySmelterRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialAlloySmelter; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Alloy Smelter"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Alloy Smelter") + .addInfo("Gains one parallel per voltage tier") + .addInfo("Gains one multiplier per coil tier") + .addInfo("parallel = tier * coil tier") + .addInfo("Gains 5% speed bonus per coil tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 5, 3, true) + .addController("Bottom center") + .addCasingInfo("Inconel Reinforced Casings", 10) + .addCasingInfo("Integral Encasement V", 8) + .addCasingInfo("Heating Coils", 16) + .addInputBus("Any Inconel Reinforced Casing", 1) + .addOutputBus("Any Inconel Reinforced Casing", 1) + .addEnergyHatch("Any Inconel Reinforced Casing", 1) + .addMaintenanceHatch("Any Inconel Reinforced Casing", 1) + .addMufflerHatch("Any Inconel Reinforced Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialAlloySmelter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialAlloySmelter>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"VVV", "V-V", "VVV"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialAlloySmelter::addIndustrialAlloySmelterList, CASING_TEXTURE_ID, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings3Misc, 1 + ) + ) + ) + ) + .addElement( + 'H', + ofCoil( + GregtechMetaTileEntity_IndustrialAlloySmelter::setCoilLevel, GregtechMetaTileEntity_IndustrialAlloySmelter::getCoilLevel + ) + ) + .addElement( + 'V', + ofBlock( + ModBlocks.blockCasingsTieredGTPP, 4 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addIndustrialAlloySmelterList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 4, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mLevel = 0; + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 4, 0) && mCasing >= 10 && getCoilLevel() != HeatingCoilLevel.None && (mLevel = getCoilLevel().getTier() + 1) > 0 && checkHatch(); + } + + @Override + public int getMaxParallelRecipes() { + return (this.mLevel * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + + @Override + public boolean checkRecipe(ItemStack aStack) { + FluidStack[] tFluids = getStoredFluids().toArray(new FluidStack[0]); + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tInputs = new ArrayList<>(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) { + tInputs.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + } + if (tInputs.size() > 1) { + ItemStack[] tItems = tInputs.toArray(new ItemStack[0]); + if (checkRecipeGeneric(tItems, tFluids, getMaxParallelRecipes(), 100, 5 * this.mLevel, 10000)) { + return true; + } + } + } + return false; + } + + @Override + public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, + int aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + Logger.WARNING("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = this.getRecipeMap().findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + + Logger.WARNING("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + Logger.WARNING("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + int tHeatCapacityDivTiers = (int) mHeatingCapacity.getHeat() / 900; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and + // considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + Logger.WARNING("Broke at " + parallelRecipes + "."); + break; + } + Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = mLevel * 5; + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + int rInt = 2; + + this.mEUt = (int) Math.max(Math.ceil(tTotalEUt), 1); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= (tHeatCapacityDivTiers >= rInt ? 4 : 2); + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) + tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.WARNING("GOOD RETURN - 1"); + return true; + + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java new file mode 100644 index 0000000000..35a92d5be3 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java @@ -0,0 +1,320 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialArcFurnace +extends GregtechMeta_MultiBlockBase { + + //862 + private static final int mCasingTextureID = TAE.getIndexFromPage(3, 3); + public static String mCasingName = "Tempered Arc Furnace Casing"; + private boolean mPlasmaMode = false; + private int mSize = 0; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialArcFurnace(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 3); + } + + public GregtechMetaTileEntity_IndustrialArcFurnace(final String aName) { + super(aName); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 3); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialArcFurnace(this.mName); + } + + @Override + public String getMachineType() { + return "(Plasma/Electric) Arc Furnace"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 3); + } + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for Industrial Arc Furnace") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes 8 items per voltage tier") + .addInfo("Max Size required to process Plasma recipes") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addController("Top center") + .addStructureInfo("Size: nx3xn [WxHxL] (Hollow)") + .addStructureInfo("n can be 3, 5 or 7") + .addCasingInfo(mCasingName, 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialArcFurnace>builder() + .addShape(mName + "3", new String[][]{ + {"CCC", "C~C", "CCC"}, + {"CCC", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + }) + .addShape(mName + "5", new String[][]{ + {"CCCCC", "CCCCC", "CC~CC", "CCCCC", "CCCCC"}, + {"CCCCC", "C---C", "C---C", "C---C", "CCCCC"}, + {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, + }) + .addShape(mName + "7", new String[][]{ + {"CCCCCCC", "CCCCCCC", "CCCCCCC", "CCC~CCC", "CCCCCCC", "CCCCCCC", "CCCCCCC"}, + {"CCCCCCC", "C-----C", "C-----C", "C-----C", "C-----C", "C-----C", "CCCCCCC"}, + {"CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC"}, + }) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialArcFurnace::addIndustrialArcFurnaceList, mCasingTextureID, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings4Misc, 3 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public void clearHatches() { + mOutputHatches.clear(); + mInputHatches.clear(); + mOutputBusses.clear(); + mInputBusses.clear(); + mEnergyHatches.clear(); + mMaintenanceHatches.clear(); + mMufflerHatches.clear(); + } + + public final boolean addIndustrialArcFurnaceList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + int size; + switch (stackSize.stackSize) { + case 1: size = 3; break; + case 2: size = 5; break; + default: size = 7; break; + } + buildPiece(mName + size, stackSize, hintsOnly, (size - 1) / 2, (size - 1) / 2, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mSize = 0; + if (checkPiece(mName + "3", 1, 1, 0)) { + mSize = 3; + return mCasing >= 10 && checkHatch(); + } + mCasing = 0; + clearHatches(); + if (checkPiece(mName + "5", 2, 2, 0)) { + mSize = 5; + return mCasing >= 10 && checkHatch(); + } + mCasing = 0; + clearHatches(); + if (checkPiece(mName + "7", 3, 3, 0)) { + mSize = 3; + return mCasing >= 10 && checkHatch(); + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @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(mCasingTextureID), + new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(mCasingTextureID)}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialExtruder"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mPlasmaMode ? GT_Recipe.GT_Recipe_Map.sPlasmaArcFurnaceRecipes : GT_Recipe.GT_Recipe_Map.sArcFurnaceRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return this.checkRecipeGeneric(this.mSize * 8 * GT_Utility.getTier(this.getMaxInputVoltage()), 100, 250); + } + + @Override + public int getMaxParallelRecipes() { + return (this.mSize * 8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialArcFurnace; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + + public byte getCasingMeta() { + return 3; + } + + public Block getCasingBlock2() { + return ModBlocks.blockCasings3Misc; + } + + + public byte getCasingMeta2() { + return 15; + } + + public byte getCasingTextureIndex() { + return (byte) mCasingTextureID; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (this.mSize > 3) { + this.mPlasmaMode = Utils.invertBoolean(mPlasmaMode); + if (mPlasmaMode) { + PlayerUtils.messagePlayer(aPlayer, "["+EnumChatFormatting.RED+"MODE"+EnumChatFormatting.RESET+"] "+EnumChatFormatting.LIGHT_PURPLE+"Plasma"+EnumChatFormatting.RESET); + } + else { + PlayerUtils.messagePlayer(aPlayer, "["+EnumChatFormatting.RED+"MODE"+EnumChatFormatting.RESET+"] "+EnumChatFormatting.YELLOW+"Electric"+EnumChatFormatting.RESET); + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mPlasmaMode", mPlasmaMode); + aNBT.setInteger("mSize", mSize); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mPlasmaMode = aNBT.getBoolean("mPlasmaMode"); + mSize = aNBT.getInteger("mSize"); + } + + @Override + public void onMachineBlockUpdate() { + mUpdate = 100; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java new file mode 100644 index 0000000000..8802a7148b --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java @@ -0,0 +1,263 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialCentrifuge +extends GregtechMeta_MultiBlockBase { + + private boolean mIsAnimated; + private static ITexture frontFace; + private static ITexture frontFaceActive; + private static CustomIcon GT9_5_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE5"); + private static CustomIcon GT9_5 = new CustomIcon("iconsets/LARGECENTRIFUGE5"); + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialCentrifuge> STRUCTURE_DEFINITION = null; + //public static double recipesComplete = 0; + + public GregtechMetaTileEntity_IndustrialCentrifuge(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + frontFaceActive = new GT_RenderedTexture(GT9_5_Active); + frontFace = new GT_RenderedTexture(GT9_5); + mIsAnimated = true; + } + + public GregtechMetaTileEntity_IndustrialCentrifuge(final String aName) { + super(aName); + mIsAnimated = true; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCentrifuge(this.mName); + } + + @Override + public String getMachineType() { + return "Centrifuge"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Centrifuge") + .addInfo("125% faster than using single block machines of the same voltage") + .addInfo("Disable animations with a screwdriver") + .addInfo("Only uses 90% of the eu/t normally required") + .addInfo("Processes six items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Centrifuge Casings", 10) + .addInputBus("Any Casing except front", 1) + .addOutputBus("Any Casing except front", 1) + .addInputHatch("Any Casing except front", 1) + .addOutputHatch("Any Casing except front", 1) + .addEnergyHatch("Any Casing except front", 1) + .addMaintenanceHatch("Any Casing except front", 1) + .addMufflerHatch("Any Casing except front", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCentrifuge> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCentrifuge>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialCentrifuge::addIndustrialCentrifugeList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 0 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + public final boolean addIndustrialCentrifugeList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(0)), aFacing == aSide ? aActive ? getFrontFacingTurbineTexture(aActive) : getFrontFacingTurbineTexture(aActive) : Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(0))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialCentrifuge"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sMultiblockCentrifugeRecipes_GT; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(6* GT_Utility.getTier(this.getMaxInputVoltage()), 90, 125); + } + + @Override + public int getMaxParallelRecipes() { + return (6 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 90; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasingsMisc; + } + + public byte getCasingMeta() { + return 0; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(0); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCentrifuge; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + this.mIsAnimated = !mIsAnimated; + Logger.INFO("Is Centrifuge animated "+this.mIsAnimated); + if (this.mIsAnimated) { + PlayerUtils.messagePlayer(aPlayer, "Using Animated Turbine Texture. "); + } + else { + PlayerUtils.messagePlayer(aPlayer, "Using Static Turbine Texture. "); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mIsAnimated", mIsAnimated); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("mIsAnimated")) { + mIsAnimated = aNBT.getBoolean("mIsAnimated"); + } + else { + mIsAnimated = true; + } + } + + public boolean usingAnimations() { + //Logger.INFO("Is animated? "+this.mIsAnimated); + return this.mIsAnimated; + } + + private ITexture getFrontFacingTurbineTexture(boolean isActive) { + if (usingAnimations()) { + if (isActive) { + return frontFaceActive; + } + } + return frontFace; + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java new file mode 100644 index 0000000000..21caf135b1 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java @@ -0,0 +1,230 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialCokeOven +extends GregtechMeta_MultiBlockBase { + private int mLevel = 0; + private int mCasing; + private int mCasing1; + private int mCasing2; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialCokeOven> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialCokeOven(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialCokeOven(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCokeOven(this.mName); + } + + @Override + public String getMachineType() { + return "Coke Oven"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Processes Logs and Coal into Charcoal and Coal Coke.") + .addInfo("Controller Block for the Industrial Coke Oven") + .addInfo("Gain 4% speed bonus per voltage tier increased") + .addInfo("Process 12x materials with Heat Resistant Casings") + .addInfo("Or 24x materials with Heat Proof Casings") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front middle at bottom") + .addCasingInfo("Structural Coke Oven Casings", 8) + .addCasingInfo("Heat Resistant/Proof Coke Oven Casings", 8) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCokeOven> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCokeOven>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "C-C", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialCokeOven::addIndustrialCokeOvenList, TAE.GTPP_INDEX(1), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 1 + ) + ) + ) + ) + .addElement( + 'H', + ofChain( + onElementPass( + x -> ++x.mCasing1, + ofBlock( + ModBlocks.blockCasingsMisc, 2 + ) + ), + onElementPass( + x -> ++x.mCasing2, + ofBlock( + ModBlocks.blockCasingsMisc, 3 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 2, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mCasing1 = 0; + mCasing2 = 0; + mLevel = 0; + if (checkPiece(mName, 1, 2, 0)) { + if (mCasing1 == 8) mLevel = 1; + if (mCasing2 == 8) mLevel = 2; + return mLevel > 0 && mCasing >= 8 && checkHatch(); + } + return false; + } + + public final boolean addIndustrialCokeOvenList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(1)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(1))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "CokeOven"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sCokeOvenRecipes; + + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); + } + + @Override + public int getMaxParallelRecipes() { + return this.mLevel * 12; + } + + @Override + public int getEuDiscountForParallelism() { + return (100-(GT_Utility.getTier(this.getMaxInputVoltage())*4)); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCokeOven; + } + + @Override + public int getAmountOfOutputs() { + return 24; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java new file mode 100644 index 0000000000..bf5f8aaeaf --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java @@ -0,0 +1,234 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialCuttingMachine +extends GregtechMeta_MultiBlockBase { + + private boolean mCuttingMode = true; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialCuttingMachine> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialCuttingMachine(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialCuttingMachine(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCuttingMachine(this.mName); + } + + @Override + public String getMachineType() { + return "Cutting Machine / Slicing Machine"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Cutting Factory") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Only uses 75% of the eu/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfo("Cutting Factory Frames", 26) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCuttingMachine> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCuttingMachine>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + {"C~C", "C-C", "C-C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialCuttingMachine::addIndustrialCuttingMachineList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 13 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 26 && checkHatch(); + } + + public final boolean addIndustrialCuttingMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(29)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(29))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialCuttingMachine"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mCuttingMode ? GT_Recipe.GT_Recipe_Map.sCutterRecipes : GT_Recipe.GT_Recipe_Map.sSlicerRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((4* GT_Utility.getTier(this.getMaxInputVoltage())), 75, 200); + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 75; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCuttingMachine; + } + + @Override + public int getAmountOfOutputs() { + return 2; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + + public byte getCasingMeta() { + return 13; + } + + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(29); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mCuttingMode = Utils.invertBoolean(mCuttingMode); + String aMode = mCuttingMode ? "Cutting" : "Slicing"; + PlayerUtils.messagePlayer(aPlayer, "Mode: "+aMode); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mCuttingMode", mCuttingMode); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("mCuttingMode")) { + mCuttingMode = aNBT.getBoolean("mCuttingMode"); + } + else { + mCuttingMode = true; + } + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java new file mode 100644 index 0000000000..44552ea2f7 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java @@ -0,0 +1,415 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.List; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.core.lib.CORE; +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_IndustrialDehydrator extends GregtechMeta_MultiBlockBase { + + private static int CASING_TEXTURE_ID; + private static String mCasingName = "Vacuum Casing"; + private HeatingCoilLevel mHeatingCapacity; + private boolean mDehydratorMode = false; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialDehydrator> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialDehydrator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(3, 10); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 10); + } + + public GregtechMetaTileEntity_IndustrialDehydrator(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(3, 10); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 10); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialDehydrator(mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 10); + } + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Vacuum Furnace") + .addInfo("Can toggle the operation temperature with a Screwdriver") + .addInfo("All Dehydrator recipes are Low Temp recipes") + .addInfo("Speed: 120% | Eu Usage: 50% | Parallel: 4") + .addInfo("Each 900K over the min. Heat Capacity grants 5% speedup (multiplicatively)") + .addInfo("Each 1800K over the min. Heat Capacity allows for one upgraded overclock") + .addInfo("Upgraded overclocks reduce recipe time to 25% and increase EU/t to 400%") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, true) + .addController("Bottom Center") + .addCasingInfo(mCasingName, 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialDehydrator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialDehydrator>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialDehydrator::addIndustrialDehydratorList, CASING_TEXTURE_ID, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings4Misc, 10 + ) + ) + ) + ) + .addElement( + 'H', + ofCoil( + GregtechMetaTileEntity_IndustrialDehydrator::setCoilLevel, GregtechMetaTileEntity_IndustrialDehydrator::getCoilLevel + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 4, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 4, 0) && mCasing >= 10 && getCoilLevel() != HeatingCoilLevel.None && checkHatch(); + } + + public final boolean addIndustrialDehydratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, + boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID), + new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active + : TexturesGtBlock.Overlay_Machine_Controller_Advanced) }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID) }; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mDehydratorMode ? GTPP_Recipe.GTPP_Recipe_Map.sChemicalDehydratorRecipes : GTPP_Recipe.GTPP_Recipe_Map.sVacuumFurnaceRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialDehydrator; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getMachineType() { + return "Vacuum Furnace / Dehydrator"; + } + + @Override + public int getMaxParallelRecipes() { + return 4; + } + + @Override + public int getEuDiscountForParallelism() { + return 50; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ElectricBlastFurnace"; + } + + public boolean checkRecipe(ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 120); + } + + @Override + public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, + int aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + Logger.WARNING("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = this.getRecipeMap().findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + + Logger.WARNING("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null || this.mHeatingCapacity.getHeat() < tRecipe.mSpecialValue) { + Logger.WARNING("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + int tHeatCapacityDivTiers = (int) (mHeatingCapacity.getHeat() - tRecipe.mSpecialValue) / 900; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and + // considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + Logger.WARNING("Broke at " + parallelRecipes + "."); + break; + } + Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + int rInt = 2; + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= (tHeatCapacityDivTiers >= rInt ? 4 : 2); + } + } + + if (tHeatCapacityDivTiers > 0) { + this.mEUt = (int) (this.mEUt * (Math.pow(0.95, tHeatCapacityDivTiers))); + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) + tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.WARNING("GOOD RETURN - 1"); + return true; + + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mDehydratorMode = Utils.invertBoolean(mDehydratorMode); + String aMode = mDehydratorMode ? "Dehydrator" : "Vacuum Furnace"; + PlayerUtils.messagePlayer(aPlayer, "Mode: "+aMode); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mDehydratorMode", mDehydratorMode); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mDehydratorMode = aNBT.getBoolean("mDehydratorMode"); + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } +} + + diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java new file mode 100644 index 0000000000..f6613980ca --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java @@ -0,0 +1,193 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialElectrolyzer +extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialElectrolyzer> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialElectrolyzer(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialElectrolyzer(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialElectrolyzer(this.mName); + } + + @Override + public String getMachineType() { + return "Electrolyzer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Electrolyzer") + .addInfo("180% faster than using single block machines of the same voltage") + .addInfo("Only uses 90% of the eu/t normally required") + .addInfo("Processes two items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Electrolyzer Casings", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialElectrolyzer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialElectrolyzer>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialElectrolyzer::addIndustrialElectrolyzerList, TAE.GTPP_INDEX(5), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 5 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + public final boolean addIndustrialElectrolyzerList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(5)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(5))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialElectrolyzer"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map.sMultiblockElectrolyzerRecipes_GT; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(2* GT_Utility.getTier(this.getMaxInputVoltage()), 90, 180); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialElectrolyzer; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 2* GT_Utility.getTier(this.getMaxInputVoltage()); + } + + @Override + public int getEuDiscountForParallelism() { + return 90; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java new file mode 100644 index 0000000000..a5c7f62578 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java @@ -0,0 +1,260 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import java.util.ArrayList; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialExtruder +extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialExtruder> STRUCTURE_DEFINITION = null; + + + public GregtechMetaTileEntity_IndustrialExtruder(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialExtruder(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialExtruder(this.mName); + } + + @Override + public String getMachineType() { + return "Extruder"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Material Extruder") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes four items per voltage tier") + .addInfo("Extrusion Shape for recipe goes in the Input Bus") + .addInfo("Each Input Bus can have a different shape!") + .addInfo("You can use several input buses per multiblock") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfo("Inconel Reinforced Casings", 28) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Back Center", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialExtruder> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialExtruder>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + {"C~C", "C-C", "C-C", "C-C", "CMC"}, + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialExtruder::addIndustrialExtruderList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + ) + ) + .addElement( + 'M', + ofHatchAdder( + GregtechMetaTileEntity_IndustrialExtruder::addIndustrialExtruderMufflerList, getCasingTextureIndex(), 2 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 28 && checkHatch(); + } + + public final boolean addIndustrialExtruderList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addIndustrialExtruderMufflerList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return this.mMufflerHatches.add((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(203)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(33)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(33))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialExtruder"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sExtruderRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + ItemStack[] inputs = new ItemStack[tBusItems.size()]; + int slot = 0; + for (ItemStack g : tBusItems) { + inputs[slot++] = g; + } + if (inputs.length > 0) { + int para = (4* GT_Utility.getTier(this.getMaxInputVoltage())); + log("Recipe. ["+inputs.length+"]["+para+"]"); + if (checkRecipeGeneric(inputs, new FluidStack[]{}, para, 100, 250, 10000)) { + log("Recipe 2."); + return true; + } + } + + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialExtruder; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta() { + return 1; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(33); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java new file mode 100644 index 0000000000..b6e072b653 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java @@ -0,0 +1,259 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import java.util.Random; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialMacerator +extends GregtechMeta_MultiBlockBase { + private int mCasing; + private int mPerLayer; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialMacerator> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialMacerator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialMacerator(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMacerator(this.mName); + } + + @Override + public String getMachineType() { + return "Macerator/Pulverizer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Maceration Stack") + .addInfo("60% faster than using single block machines of the same voltage") + .addInfo("Processes 8*tier materials at a time") + .addInfo("ULV = Tier 0, LV = Tier 1, etc.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 6, 3, true) + .addController("Bottom Center") + .addCasingInfo("Maceration Stack Casings", 26) + .addInputBus("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addOutputBus("One per layer except bottom layer", 2) + .addMufflerHatch("Any Casing", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMacerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMacerator>builder() + .addShape(mName + "top", transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + })) + .addShape(mName + "mid", transpose(new String[][]{ + {"CCC", "C-C", "CCC"}, + })) + .addShape(mName + "bottom", transpose(new String[][]{ + {"B~B", "BBB", "BBB"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialMacerator::addIndustrialMaceratorMidList, TAE.GTPP_INDEX(7), 2 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 7 + ) + ) + ) + ) + .addElement( + 'B', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialMacerator::addIndustrialMaceratorBottomList, TAE.GTPP_INDEX(7), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 7 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName + "bottom", stackSize, hintsOnly, 1, 0, 0); + buildPiece(mName + "mid", stackSize, hintsOnly, 1, 1, 0); + buildPiece(mName + "mid", stackSize, hintsOnly, 1, 2, 0); + buildPiece(mName + "mid", stackSize, hintsOnly, 1, 3, 0); + buildPiece(mName + "mid", stackSize, hintsOnly, 1, 4, 0); + buildPiece(mName + "top", stackSize, hintsOnly, 1, 5, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mPerLayer = 0; + if (checkPiece(mName + "bottom", 1, 0 ,0)) { + while (mPerLayer < 4) { + if (!checkPiece(mName + "mid", 1, mPerLayer + 1, 0) || + mPerLayer + 1 != mOutputBusses.size()) return false; + mPerLayer ++; + } + return checkPiece(mName + "top", 1, 5, 0) && mOutputBusses.size() == 5 && mCasing >= 26 && checkHatch(); + } + return false; + } + + public final boolean addIndustrialMaceratorBottomList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addIndustrialMaceratorMidList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(201)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(7)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_MatterFab_Active : TexturesGtBlock.Overlay_MatterFab)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(7))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MacerationStack"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; + } + + @Override + public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) && (aBaseMetaTileEntity.getFrontFacing() != 1) && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + aBaseMetaTileEntity.getWorld().spawnParticle("smoke", (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), 0.0D, 0.0D, 0.0D); + } + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 60, 7500); + } + + @Override + protected boolean doesMachineBoostOutput() { + return true; + } + + @Override + public int getMaxParallelRecipes() { + final long tVoltage = getMaxInputVoltage(); + final byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + return Math.max(1, 8 * tTier); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMacerator; + } + + @Override + public int getAmountOfOutputs() { + return 16; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java new file mode 100644 index 0000000000..5e405d426d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java @@ -0,0 +1,257 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import java.util.ArrayList; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialMixer +extends GregtechMeta_MultiBlockBase { + + public static int CASING_TEXTURE_ID; + public static String mCasingName = "Advanced Blast Furnace Casing"; + public static String mCasingName2 = "Advanced Blast Furnace Casing"; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialMixer> STRUCTURE_DEFINITION = null; + + + public GregtechMetaTileEntity_IndustrialMixer(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 2); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 2); + mCasingName2 = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockCasings4, 11); + } + + public GregtechMetaTileEntity_IndustrialMixer(final String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 2); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 2); + mCasingName2 = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockCasings4, 11); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMixer(this.mName); + } + + @Override + public String getMachineType() { + return "Mixer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 2); + } + if (mCasingName2.toLowerCase().contains(".name")) { + mCasingName2 = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockCasings4, 11); + } + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Mixer") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes eight recipes per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, false) + .addController("Second Layer Center") + .addCasingInfo(mCasingName, 16) + .addCasingInfo(mCasingName2, 2) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMixer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMixer>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"CCC", "CMC", "CCC"}, + {"C~C", "CMC", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialMixer::addIndustrialMixerList, CASING_TEXTURE_ID, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings3Misc, 2 + ) + ) + ) + ) + .addElement( + 'M', + ofBlock( + GregTech_API.sBlockCasings4, 11 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 2, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 2, 0) && mCasing >= 16 && checkHatch(); + } + + public final boolean addIndustrialMixerList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(203)); + } + + @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(CASING_TEXTURE_ID), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialMixer"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map.sMultiblockMixerRecipes_GT; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + ItemStack[] inputs = new ItemStack[tBusItems.size()]; + int slot = 0; + for (ItemStack g : tBusItems) { + inputs[slot++] = g; + } + if (inputs.length > 0) { + log("Recipe. ["+inputs.length+"]["+getMaxParallelRecipes()+"]"); + FluidStack[] fluid = this.getStoredFluids().toArray(new FluidStack[] {}); + if (checkRecipeGeneric(inputs,fluid , getMaxParallelRecipes(), getEuDiscountForParallelism(), 250, 10000)) { + log("Recipe 2."); + return true; + } + } + + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMixer; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java new file mode 100644 index 0000000000..a0909a4fff --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java @@ -0,0 +1,541 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.List; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.*; +import gtPlusPlus.core.lib.CORE; +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_IndustrialMultiMachine +extends GregtechMeta_MultiBlockBase { + + protected int mInternalMode = 0; + protected GT_Recipe[] mLastRecipeExtended = new GT_Recipe[9]; + private static final int MODE_COMPRESSOR = 0; + private static final int MODE_LATHE = 1; + private static final int MODE_MAGNETIC = 2; + private static final int MODE_FERMENTER = 3; + private static final int MODE_FLUIDEXTRACT = 4; + private static final int MODE_EXTRACTOR = 5; + private static final int MODE_LASER = 6; + private static final int MODE_AUTOCLAVE = 7; + private static final int MODE_FLUIDSOLIDIFY = 8; + private static final int[][] MODE_MAP = new int[][] {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}; + public static final String[] aToolTipNames = new String[9]; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialMultiMachine> STRUCTURE_DEFINITION = null; + + static { + for (int id = 0; id < 9; id++) { + String aNEI = GT_LanguageManager.getTranslation(getRecipeMap(id).mUnlocalizedName); + aToolTipNames[id] = aNEI != null ? aNEI : "BAD NEI NAME (Report to Github)"; + } + } + + + public GregtechMetaTileEntity_IndustrialMultiMachine(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialMultiMachine(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMultiMachine(this.mName); + } + + @Override + public String getMachineType() { + return "Nine in One"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + + String[] aBuiltStrings = new String[3]; + aBuiltStrings[0] = aToolTipNames[0] + ", " + aToolTipNames[1] + ", " + aToolTipNames[2]; + aBuiltStrings[1] = aToolTipNames[3] + ", " + aToolTipNames[4] + ", " + aToolTipNames[5]; + aBuiltStrings[2] = aToolTipNames[6] + ", " + aToolTipNames[7]; + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Multi-Machine") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Only uses 80% of the eu/t normally required") + .addInfo("Processes two items per voltage tier") + .addInfo("Machine Type: [A] - " + EnumChatFormatting.YELLOW + aBuiltStrings[0] + EnumChatFormatting.RESET) + .addInfo("Machine Type: [B] - " + EnumChatFormatting.YELLOW + aBuiltStrings[1] + EnumChatFormatting.RESET) + .addInfo("Machine Type: [C] - " + EnumChatFormatting.YELLOW + aBuiltStrings[2] + EnumChatFormatting.RESET) + .addInfo("Read Multi-Machine Manual for extra information") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Multi-Use Casings", 6) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMultiMachine> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMultiMachine>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialMultiMachine::addIndustrialMultiMachineList, getTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings3Misc, 2 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); + } + + public final boolean addIndustrialMultiMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @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(getTextureIndex()), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(getTextureIndex())}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "Generic3By3"; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + ArrayList<FluidStack> tFluids = getStoredFluids(); + //Logger.MACHINE_INFO("1"); + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + //Logger.MACHINE_INFO("2"); + if (isValidMetaTileEntity(tBus)) { + //Logger.MACHINE_INFO("3"); + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + + boolean aFoundCircuitInBus = false; + for (ItemStack aBusItem : tBusItems) { + if (ItemUtils.isControlCircuit(aBusItem)) { + aFoundCircuitInBus = true; + } + } + if (!aFoundCircuitInBus) { + continue; + } + + Object[] tempArray = tFluids.toArray(new FluidStack[] {}); + FluidStack[] properArray; + properArray = ((tempArray != null && tempArray.length > 0) ? (FluidStack[]) tempArray : new FluidStack[] {}); + + //Logger.MACHINE_INFO("4"); + if (checkRecipeGeneric(tBusItems.toArray(new ItemStack[]{}), properArray, + (2*GT_Utility.getTier(this.getMaxInputVoltage())), 80, 250, 10000)) return true; + } + return false; + + //return checkRecipeGeneric(2*GT_Utility.getTier(this.getMaxInputVoltage()), 90, 180); + } + + @Override + public int getMaxParallelRecipes() { + return (2 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 80; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (mInternalMode == 0) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeMetal; + } + else if (mInternalMode == 1) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeFluid; + } + else { //config 2 + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeMisc; + } + } + + public int getTextureIndex() { + return TAE.getIndexFromPage(2, 2); + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private ItemStack getCircuit(ItemStack[] t) { + for (ItemStack j : t) { + if (j.getItem() == CI.getNumberedCircuit(0).getItem()) { + if (j.getItemDamage() >= 20 && j.getItemDamage() <= 22) { + return j; + } + } + } + return null; + } + + private final int getCircuitID(ItemStack circuit) { + int H = circuit.getItemDamage(); + int T = (H == 20 ? 0 : (H == 21 ? 1 : (H == 22 ? 2 : -1))); + return MODE_MAP[this.mInternalMode][T]; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + private final GT_Recipe.GT_Recipe_Map getRecipeMap(ItemStack circuit) { + return getRecipeMap(getCircuitID(circuit)); + } + + private static final GT_Recipe.GT_Recipe_Map getRecipeMap(int aMode) { + if (aMode == MODE_COMPRESSOR) { + return GT_Recipe.GT_Recipe_Map.sCompressorRecipes; + } + else if (aMode == MODE_LATHE) { + return GT_Recipe.GT_Recipe_Map.sLatheRecipes; + } + else if (aMode == MODE_MAGNETIC) { + return GT_Recipe.GT_Recipe_Map.sPolarizerRecipes; + } + else if (aMode == MODE_FERMENTER) { + return GT_Recipe.GT_Recipe_Map.sFermentingRecipes; + } + else if (aMode == MODE_FLUIDEXTRACT) { + return GT_Recipe.GT_Recipe_Map.sFluidExtractionRecipes; + } + else if (aMode == MODE_EXTRACTOR) { + return GT_Recipe.GT_Recipe_Map.sExtractorRecipes; + } + else if (aMode == MODE_LASER) { + return GT_Recipe.GT_Recipe_Map.sLaserEngraverRecipes; + } + else if (aMode == MODE_AUTOCLAVE) { + return GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes; + } + else if (aMode == MODE_FLUIDSOLIDIFY) { + return GT_Recipe.GT_Recipe_Map.sFluidSolidficationRecipes; + } + else { + return null; + } + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, FluidStack[] aFluidInputs, + int aMaxParallelRecipes, int aEUPercent, + int aSpeedBonusPercent, int aOutputChanceRoll) { + + // Based on the Processing Array. A bit overkill, but very flexible. + + // Get Circuit info for this recipe. + ItemStack tCircuit = getCircuit(aItemInputs); + int tCircuitID = getCircuitID(tCircuit); + + Logger.MACHINE_INFO("Mode: "+tCircuitID); + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + + + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + GT_Recipe.GT_Recipe_Map tRecipeMap = this.getRecipeMap(tCircuit); + if (tRecipeMap == null) + return false; + GT_Recipe tRecipe = tRecipeMap.findRecipe( + getBaseMetaTileEntity(), this.mLastRecipeExtended[tCircuitID], false, + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + + // Remember last recipe - an optimization for findRecipe() + //this.mLastRecipe = tRecipe; //Let's not do this, it's bad. + //Instead, how about I use a array for types? + this.mLastRecipeExtended[tCircuitID] = tRecipe; + + if (tRecipe == null) { + Logger.MACHINE_INFO("BAD RETURN - 1|"+tCircuitID); + + if (aItemInputs.length > 0) { + Logger.MACHINE_INFO("Input Items: "+ItemUtils.getArrayStackNames(aItemInputs)); + } + if (aFluidInputs.length > 0) { + Logger.MACHINE_INFO("Input Fluids: "+ItemUtils.getFluidArrayStackNames(aFluidInputs)); + } + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + Logger.MACHINE_INFO("BAD RETURN - 2|"+tCircuitID); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + Logger.WARNING("parallelRecipes: "+parallelRecipes); + Logger.WARNING("aMaxParallelRecipes: "+aMaxParallelRecipes); + Logger.WARNING("tTotalEUt: "+tTotalEUt); + Logger.WARNING("tVoltage: "+tVoltage); + Logger.WARNING("tRecipeEUt: "+tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + Logger.WARNING("Broke at "+parallelRecipes+"."); + break; + } + Logger.WARNING("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + Logger.MACHINE_INFO("BAD RETURN - 3|"+tCircuitID); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int)Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.MACHINE_INFO("GOOD RETURN - 1|"+tCircuitID); + return true; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (mInternalMode < 2) { + mInternalMode++; + } + else { + mInternalMode = 0; + } + String mModeString = (mInternalMode == 0 ? "Metal" : mInternalMode == 1 ? "Fluid" : mInternalMode == 2 ? "Misc." : "null"); + PlayerUtils.messagePlayer(aPlayer, "Multi-Machine is now in "+mModeString+" mode."); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mInternalMode", mInternalMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mInternalMode = aNBT.getInteger("mInternalMode"); + super.loadNBTData(aNBT); + } + + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java new file mode 100644 index 0000000000..007d1a0d0f --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java @@ -0,0 +1,242 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import java.util.ArrayList; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +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.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialPlatePress extends GregtechMeta_MultiBlockBase { + + private boolean mFormingMode = false; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialPlatePress> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialPlatePress(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialPlatePress(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialPlatePress(this.mName); + } + + @Override + public String getMachineType() { + return "Bending Machine, Forming Press"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for Advanced Bending & Forming") + .addInfo("500% faster than using single block machines of the same voltage") + .addInfo("Processes four items per voltage tier") + .addInfo("Circuit for recipe goes in the Input Bus") + .addInfo("Each Input Bus can have a different Circuit/Shape!") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Material Press Machine Casings", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialPlatePress> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialPlatePress>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialPlatePress::addIndustrialPlatePressList, 50, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 4 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + public final boolean addIndustrialPlatePressList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(203)); + } + + @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(50), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(50)}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MaterialPress"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mFormingMode ? GT_Recipe.GT_Recipe_Map.sPressRecipes : GT_Recipe.GT_Recipe_Map.sBenderRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + tBus.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + + if (checkRecipeGeneric(tBusItems.toArray(new ItemStack[]{}), new FluidStack[]{}, + (4* GT_Utility.getTier(this.getMaxInputVoltage())), 100, 500, 10000)) return true; + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (this.mFormingMode) return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialPlatePress_ModeForming; + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialPlatePress_ModeBending; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mFormingMode", mFormingMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mFormingMode = aNBT.getBoolean("mFormingMode"); + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mFormingMode = Utils.invertBoolean(mFormingMode); + if (mFormingMode){ + PlayerUtils.messagePlayer(aPlayer, "Now running in Forming Press Mode."); + } + else { + PlayerUtils.messagePlayer(aPlayer, "Now running in Bending Mode."); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java new file mode 100644 index 0000000000..c5450fec5b --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java @@ -0,0 +1,225 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import java.util.Random; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialSifter +extends GregtechMeta_MultiBlockBase { + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialSifter> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialSifter(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialSifter(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialSifter(this.mName); + } + + @Override + public String getMachineType() { + return "Sifter"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Sifter") + .addInfo("400% faster than single-block machines of the same voltage") + .addInfo("Only uses 75% of the eu/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 3, 5, false) + .addController("Bottom Center") + .addCasingInfo("Sieve Grate", 18) + .addCasingInfo("Sieve Casings", 35) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialSifter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialSifter>builder() + .addShape(mName, transpose(new String[][]{ + {"CCCCC", "CMMMC", "CMMMC", "CMMMC", "CCCCC"}, + {"CCCCC", "CMMMC", "CMMMC", "CMMMC", "CCCCC"}, + {"CC~CC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialSifter::addIndustrialSifterList, TAE.GTPP_INDEX(21), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 5 + ) + ) + ) + ) + .addElement( + 'M', + ofBlock( + ModBlocks.blockCasings2Misc, 6 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 2, 2, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 2, 0) && mCasing >= 35 && mOutputBusses.size() >= 4 && checkHatch(); + } + + public final boolean addIndustrialSifterList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(21)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(21))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialSifter"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sSifterRecipes; + } + + @Override + public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) && (aBaseMetaTileEntity.getFrontFacing() != 1) && (aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0) && (!aBaseMetaTileEntity.getOpacityAtSide((byte) 1))) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + if (tRandom.nextFloat() > 0.4) return; + + final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 2; + final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 2; + + aBaseMetaTileEntity.getWorld().spawnParticle("smoke", + (aBaseMetaTileEntity.getXCoord() + xDir + 2.1F) - (tRandom.nextFloat() * 3.2F), + aBaseMetaTileEntity.getYCoord() + 2.5f + (tRandom.nextFloat() * 1.2F), + (aBaseMetaTileEntity.getZCoord() + zDir + 2.1F) - (tRandom.nextFloat() * 3.2F), + 0.0, 0.0, 0.0); + + } + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((4* GT_Utility.getTier(this.getMaxInputVoltage())), 75, 400, 10000); + } + + @Override + protected boolean doesMachineBoostOutput() { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 75; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialSifter; + } + + @Override + public int getAmountOfOutputs() { + return 16; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSinter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSinter.java new file mode 100644 index 0000000000..5a62c6c335 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSinter.java @@ -0,0 +1,268 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import java.util.ArrayList; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialSinter +extends GT_MetaTileEntity_MultiBlockBase { + + + RenderBlocks asdasd = RenderBlocks.getInstance(); + + public GregtechMetaTileEntity_IndustrialSinter(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialSinter(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialSinter(this.mName); + } + + @Override + public String[] getDescription() { + return new String[]{ + "Controller Block for the Industrial Sinter Furnace", + "Size: 3x5x3 [WxLxH] (Hollow)", "Controller (front centered)", + "2x Input Bus (side centered)", + "2x Output Bus (side centered)", + "1x Energy Hatch (top or bottom centered)", + "1x Maintenance Hatch (back centered)", + "Sinter Furnace Casings for the rest (32 at least!)", + "Causes " + 20 * this.getPollutionPerTick(null) + " Pollution per second", + CORE.GT_Tooltip + }; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(7)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(7))}; + } + + @Override + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "WireFactory.png"); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sWiremillRecipes; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing > 1; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + final ArrayList<ItemStack> tInputList = this.getStoredInputs(); + for (final ItemStack tInput : tInputList) { + final long tVoltage = this.getMaxInputVoltage(); + final byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + final GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sWiremillRecipes.findRecipe(this.getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], null, new ItemStack[]{tInput}); + if (tRecipe != null) { + if (tRecipe.isRecipeInputEqual(true, null, new ItemStack[]{tInput})) { + this.mEfficiency = (10000 - ((this.getIdealStatus() - this.getRepairStatus()) * 1000)); + this.mEfficiencyIncrease = 10000; + if (tRecipe.mEUt <= 16) { + this.mEUt = (tRecipe.mEUt * (1 << (tTier - 1)) * (1 << (tTier - 1))); + this.mMaxProgresstime = (tRecipe.mDuration / (1 << (tTier - 1))); + } else { + this.mEUt = tRecipe.mEUt; + this.mMaxProgresstime = tRecipe.mDuration; + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0)}; + this.updateSlots(); + return true; + } + } + } + return false; + } + + @Override + public boolean checkMachine(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + final int controllerX = aBaseMetaTileEntity.getXCoord(); + final int controllerY = aBaseMetaTileEntity.getYCoord(); + final int controllerZ = aBaseMetaTileEntity.getZCoord(); + + final byte tSide = this.getBaseMetaTileEntity().getBackFacing(); + if ((this.getBaseMetaTileEntity().getAirAtSideAndDistance(this.getBaseMetaTileEntity().getBackFacing(), 1)) && (this.getBaseMetaTileEntity().getAirAtSideAndDistance(this.getBaseMetaTileEntity().getBackFacing(), 2) && (this.getBaseMetaTileEntity().getAirAtSideAndDistance(this.getBaseMetaTileEntity().getBackFacing(), 3)))) { + int tAirCount = 0; + for (byte i = -1; i < 2; i = (byte) (i + 1)) { + for (byte j = -1; j < 2; j = (byte) (j + 1)) { + for (byte k = -1; k < 2; k = (byte) (k + 1)) { + if (this.getBaseMetaTileEntity().getAirOffset(i, j, k)) { + Logger.INFO("Found Air at: "+(controllerX+i)+" "+(controllerY+k)+" "+(controllerZ+k)); + //if (aBaseMetaTileEntity.getWorld().isRemote){ + //asdasd.renderStandardBlock(ModBlocks.MatterFabricatorEffectBlock, (controllerX+i), (controllerY+k), (controllerZ+k)); + //UtilsRendering.drawBlockInWorld((controllerX+i), (controllerY+k), (controllerZ+k), Color.YELLOW_GREEN); + //} + tAirCount++; + } + } + } + } + if (tAirCount != 10) { + Logger.INFO("False. Air != 10. Air == "+tAirCount); + //return false; + } + for (byte i = 2; i < 6; i = (byte) (i + 1)) { + //UtilsRendering.drawBlockInWorld((controllerX+i), (controllerY), (controllerZ), Color.LIME_GREEN); + IGregTechTileEntity tTileEntity; + if ((null != (tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityAtSideAndDistance(i, 2))) && + (tTileEntity.getFrontFacing() == this.getBaseMetaTileEntity().getFrontFacing()) && (tTileEntity.getMetaTileEntity() != null) && + ((tTileEntity.getMetaTileEntity() instanceof GregtechMetaTileEntity_IndustrialSinter))) { + //Utils.LOG_INFO("False 1"); + return false; + } + } + final int tX = this.getBaseMetaTileEntity().getXCoord(); + final int tY = this.getBaseMetaTileEntity().getYCoord(); + final int tZ = this.getBaseMetaTileEntity().getZCoord(); + for (byte i = -1; i < 2; i = (byte) (i + 1)) { + for (byte j = -1; j < 2; j = (byte) (j + 1)) { + if ((i != 0) || (j != 0)) { + for (byte k = 0; k < 5; k = (byte) (k + 1)) { + //UtilsRendering.drawBlockInWorld((controllerX+i), (controllerY+k), (controllerZ+k), Color.ORANGE); + if (((i == 0) || (j == 0)) && ((k == 1) || (k == 2) || (k == 3))) { + //UtilsRendering.drawBlockInWorld((controllerX+i), (controllerY+k), (controllerZ+k), Color.TOMATO); + if ((this.getBaseMetaTileEntity().getBlock(tX + (tSide == 5 ? k : tSide == 4 ? -k : i), tY + j, tZ + (tSide == 2 ? -k : tSide == 3 ? k : i)) == this.getCasingBlock()) && (this.getBaseMetaTileEntity().getMetaID(tX + (tSide == 5 ? k : tSide == 4 ? -k : i), tY + j, tZ + (tSide == 2 ? -k : tSide == 3 ? k : i)) == this.getCasingMeta())) { + } + else if (!this.addToMachineList(this.getBaseMetaTileEntity().getIGregTechTileEntity(tX + (tSide == 5 ? k : tSide == 4 ? -k : i), tY + j, tZ + (tSide == 2 ? -k : tSide == 3 ? k : i))) && (!this.addEnergyInputToMachineList(this.getBaseMetaTileEntity().getIGregTechTileEntity(tX + (tSide == 5 ? k : tSide == 4 ? -k : i), tY + j, tZ + (tSide == 2 ? -k : tSide == 3 ? k : i))))) { + Logger.INFO("False 2"); + return false; + } + } + else if ((this.getBaseMetaTileEntity().getBlock(tX + (tSide == 5 ? k : tSide == 4 ? -k : i), tY + j, tZ + (tSide == 2 ? -k : tSide == 3 ? k : i)) == this.getCasingBlock()) && (this.getBaseMetaTileEntity().getMetaID(tX + (tSide == 5 ? k : tSide == 4 ? -k : i), tY + j, tZ + (tSide == 2 ? -k : tSide == 3 ? k : i)) == this.getCasingMeta())) { + } + else { + Logger.INFO("False 3"); + return false; + } + } + } + } + } + if ((this.mOutputHatches.size() != 0) || (this.mInputHatches.size() != 0)) { + Logger.INFO("Use Busses, Not Hatches for Input/Output."); + return false; + } + if ((this.mInputBusses.size() != 2) || (this.mOutputBusses.size() != 2)) { + Logger.INFO("Incorrect amount of Input & Output busses."); + return false; + } + this.mMaintenanceHatches.clear(); + final IGregTechTileEntity tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityAtSideAndDistance(this.getBaseMetaTileEntity().getBackFacing(), 4); + if ((tTileEntity != null) && (tTileEntity.getMetaTileEntity() != null)) { + if ((tTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Maintenance)) { + this.mMaintenanceHatches.add((GT_MetaTileEntity_Hatch_Maintenance) tTileEntity.getMetaTileEntity()); + ((GT_MetaTileEntity_Hatch) tTileEntity.getMetaTileEntity()).mMachineBlock = this.getCasingTextureIndex(); + } else { + Logger.INFO("Maintenance hatch must be in the middle block on the back."); + return false; + } + } + if ((this.mMaintenanceHatches.size() != 1) || (this.mEnergyHatches.size() != 1)) { + Logger.INFO("Incorrect amount of Maintenance or Energy hatches."); + return false; + } + } else { + Logger.INFO("False 5"); + return false; + } + Logger.INFO("True"); + return true; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasingsMisc; + } + + + public byte getCasingMeta() { + return 6; + } + + + public byte getCasingTextureIndex() { + return 1; //TODO + } + + private boolean addToMachineList(final IGregTechTileEntity tTileEntity) { + return ((this.addMaintenanceToMachineList(tTileEntity, this.getCasingTextureIndex())) || (this.addInputToMachineList(tTileEntity, this.getCasingTextureIndex())) || (this.addOutputToMachineList(tTileEntity, this.getCasingTextureIndex())) || (this.addMufflerToMachineList(tTileEntity, this.getCasingTextureIndex()))); + } + + private boolean addEnergyInputToMachineList(final IGregTechTileEntity tTileEntity) { + return ((this.addEnergyInputToMachineList(tTileEntity, this.getCasingTextureIndex()))); + } +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java new file mode 100644 index 0000000000..01b887694a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java @@ -0,0 +1,224 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialThermalCentrifuge +extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialThermalCentrifuge> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialThermalCentrifuge(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialThermalCentrifuge(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialThermalCentrifuge(this.mName); + } + + @Override + public String getMachineType() { + return "Thermal Centrifuge"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Thermal Centrifuge") + .addInfo("150% faster than using single block machines of the same voltage") + .addInfo("Only uses 80% of the eu/t normally required") + .addInfo("Processes eight items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 2, 3, false) + .addController("Front Center") + .addCasingInfo("Thermal Processing Casings/Noise Hazard Sign Blocks", 8) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addMufflerHatch("Bottom Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialThermalCentrifuge> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialThermalCentrifuge>builder() + .addShape(mName, transpose(new String[][]{ + {"X~X", "XXX", "XXX"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialThermalCentrifuge::addIndustrialThermalCentrifugeList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 0 + ) + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + GregTech_API.sBlockCasings3, 9 + ) + ) + ) + ) + .addElement( + 'X', + ofChain( + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 0 + ) + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + GregTech_API.sBlockCasings3, 9 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 0, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 0, 0) && mCasing >= 8 && checkHatch(); + } + + public final boolean addIndustrialThermalCentrifugeList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public 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()), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex())}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialThermalCentrifuge"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sThermalCentrifugeRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((8* GT_Utility.getTier(this.getMaxInputVoltage())), 80, 150); + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 80; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialThermalCentrifuge; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(16); + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java new file mode 100644 index 0000000000..1f63995651 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java @@ -0,0 +1,261 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialVacuumFreezer extends GregtechMeta_MultiBlockBase { + + public static int CASING_TEXTURE_ID; + public static String mCryoFuelName = "Gelid Cryotheum"; + public static String mCasingName = "Advanced Cryogenic Casing"; + public static String mHatchName = "Cryotheum Hatch"; + public static FluidStack mFuelStack; + private boolean mHaveHatch; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialVacuumFreezer> STRUCTURE_DEFINITION = null; + + + public GregtechMetaTileEntity_IndustrialVacuumFreezer(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 10); + mCryoFuelName = mFuelStack.getLocalizedName(); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 10); + mHatchName = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 967); + } + + public GregtechMetaTileEntity_IndustrialVacuumFreezer(final String aName) { + super(aName); + mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 10); + mCryoFuelName = mFuelStack.getLocalizedName(); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 10); + mHatchName = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 967); + } + + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return (IMetaTileEntity) new GregtechMetaTileEntity_IndustrialVacuumFreezer(this.mName); + } + + @Override + public String getMachineType() { + return "Vacuum Freezer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 10); + } + if (mCryoFuelName.toLowerCase().contains(".")) { + mCryoFuelName = FluidUtils.getFluidStack("cryotheum", 1).getLocalizedName(); + } + if (mHatchName.toLowerCase().contains(".name")) { + mHatchName = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 967); + } + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Vacuum Freezer") + .addInfo("Speed: 200% | Eu Usage: 100% | Parallel: 4") + .addInfo("Consumes 1L of " + mCryoFuelName + "/t during operation") + .addInfo("Constructed exactly the same as a normal Vacuum Freezer") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo(mCasingName, 10) + .addStructureHint(mHatchName, 1) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialVacuumFreezer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialVacuumFreezer>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialVacuumFreezer::addIndustrialVacuumFreezerList, CASING_TEXTURE_ID, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings3Misc, 10 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mHaveHatch = false; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && mHaveHatch && checkHatch(); + } + + public final boolean addIndustrialVacuumFreezerList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 967) { + mHaveHatch = true; + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + + 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(CASING_TEXTURE_ID), + new GT_RenderedTexture((IIconContainer) (aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced))}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "VacuumFreezer"; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sAdvFreezerRecipes_GT; + } + + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + public boolean checkRecipe(final ItemStack aStack) { + return this.checkRecipeGeneric(4, 100, 100); + } + + @Override + public int getMaxParallelRecipes() { + return 4; + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialVacuumFreezer; + } + + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private volatile int mGraceTimer = 2; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + /*if (this.getBaseMetaTileEntity().isActive()) { + if (!this.depleteInput(mFuelStack.copy())) { + this.getBaseMetaTileEntity().setActive(false); + } + } */ + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (this.mStartUpCheck < 0) { + if (this.mMaxProgresstime > 0 && this.mProgresstime != 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + if (aTick % 10 == 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + if (!this.depleteInput(FluidUtils.getFluidStack("cryotheum", 10))) { + if (mGraceTimer-- == 0) { + this.causeMaintenanceIssue(); + this.stopMachine(); + mGraceTimer = 2; + } + } + } + } + } + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java new file mode 100644 index 0000000000..168d4ff6d6 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java @@ -0,0 +1,335 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import ic2.core.init.BlocksItems; +import ic2.core.init.InternalName; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialWashPlant +extends GregtechMeta_MultiBlockBase { + + private boolean mChemicalMode = false; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialWashPlant> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialWashPlant(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialWashPlant(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialWashPlant(this.mName); + } + + @Override + public String getMachineType() { + return "Ore Washer, Chemical Bath"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Ore Washing Plant") + .addInfo("Can be configured with a screwdriver to also process Chemical Bathing") + .addInfo("400% faster than using single block machines of the same voltage") + .addInfo("Processes four item per voltage tier") + .addInfo("Always requires an Input Hatch full of water to refill structure") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 3, 7, true) + .addController("Front Center") + .addCasingInfo("Wash Plant Casings", 40) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialWashPlant> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialWashPlant>builder() + .addShape(mName, transpose(new String[][]{ + {"CCCCC", "C C", "C C", "C C", "C C", "C C", "CCCCC"}, + {"CC~CC", "C C", "C C", "C C", "C C", "C C", "CCCCC"}, + {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialWashPlant::addIndustrialWashPlantList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 2, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 1, 0) && mCasing >= 40 && checkHatch(); + } + + public final boolean addIndustrialWashPlantList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a washer, water will flow out. + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + 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()), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex())}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialWashPlant"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mChemicalMode ? GT_Recipe.GT_Recipe_Map.sChemicalBathRecipes : GT_Recipe.GT_Recipe_Map.sOreWasherRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + if (checkForWater()) { + return checkRecipeGeneric((4 * GT_Utility.getTier(this.getMaxInputVoltage())), 100, 400); + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (4* GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (this.mChemicalMode) return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWashPlant_ModeChemBath; + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWashPlant_ModeWasher; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + + public byte getCasingMeta() { + return 4; + } + + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(11); + } + + public boolean checkForWater() { + + //Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + if (mDirectionX == 0){ + mCurrentDirectionX = 2; + mCurrentDirectionZ = 3; + mOffsetX_Lower = -2; + mOffsetX_Upper = 2; + mOffsetZ_Lower = -3; + mOffsetZ_Upper = 3; + } + else { + mCurrentDirectionX = 3; + mCurrentDirectionZ = 2; + mOffsetX_Lower = -3; + mOffsetX_Upper = 3; + mOffsetZ_Lower = -2; + mOffsetZ_Upper = 2; + } + + //if (aBaseMetaTileEntity.fac) + + final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * mCurrentDirectionX; + final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; ++h) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == Blocks.water) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + //Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = null; + if (tBlock == Blocks.air || tBlock == Blocks.flowing_water) { + fluidUsed = Blocks.water; + } + if (tBlock == Blocks.water) { + fluidUsed = BlocksItems.getFluidBlock(InternalName.fluidDistilledWater); + } + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getXCoord() + xDir + i, aBaseMetaTileEntity.getYCoord() + h, aBaseMetaTileEntity.getZCoord() + zDir + j, fluidUsed); + + + } + } + } + } + } + if (tBlock == Blocks.water) { + ++tAmount; + //Utils.LOG_WARNING("Found Water"); + } else if (tBlock == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)) { + ++tAmount; + ++tAmount; + //Utils.LOG_WARNING("Found Distilled Water"); + } + } + } + } + if ((tAmount >= 45)){ + Logger.WARNING("Filled structure."); + } + else { + Logger.WARNING("Did not fill structure."); + } + return (tAmount >= 45); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mChemicalMode", mChemicalMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mChemicalMode = aNBT.getBoolean("mChemicalMode"); + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mChemicalMode = Utils.invertBoolean(mChemicalMode); + if (mChemicalMode){ + PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Chemical Bath Mode."); + } + else { + PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Ore Washer Mode."); + } + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java new file mode 100644 index 0000000000..ccce25d925 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java @@ -0,0 +1,206 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_IndustrialWireMill +extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialWireMill> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialWireMill(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialWireMill(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialWireMill(this.mName); + } + + @Override + public String getMachineType() { + return "Wiremill"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Wire Factory") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Only uses 75% of the eu/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfo("Wire Factory Casings", 32) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialWireMill> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialWireMill>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + {"C~C", "C-C", "C-C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialWireMill::addIndustrialWireMillList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 32 && checkHatch(); + } + + public final boolean addIndustrialWireMillList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(204)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(6)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(6))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "IndustrialWireFactory"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sWiremillRecipes; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((4* GT_Utility.getTier(this.getMaxInputVoltage())), 75, 200); + } + + @Override + public int getMaxParallelRecipes() { + return (4* GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getEuDiscountForParallelism() { + return 75; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWireMill; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasingsMisc; + } + + public byte getCasingMeta() { + return 6; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(6); + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IronBlastFurnace.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IronBlastFurnace.java new file mode 100644 index 0000000000..5d6904bd46 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IronBlastFurnace.java @@ -0,0 +1,403 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import gregtech.GT_Mod; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; + +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_IronBlastFurnace; +import gtPlusPlus.xmod.gregtech.api.gui.GUI_IronBlastFurnace; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraftforge.common.util.ForgeDirection; + +public class GregtechMetaTileEntity_IronBlastFurnace +extends MetaTileEntity { + private static final ITexture[] FACING_SIDE = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top)}; + private static final ITexture[] FACING_FRONT = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_Off)}; + private static final ITexture[] FACING_ACTIVE = {new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_On)}; + public int mMaxProgresstime = 0; + public int mUpdate = 30; + public int mProgresstime = 0; + public boolean mMachine = false; + public ItemStack mOutputItem1; + public ItemStack mOutputItem2; + + public GregtechMetaTileEntity_IronBlastFurnace(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional, 4); + } + + public GregtechMetaTileEntity_IronBlastFurnace(final String aName) { + super(aName, 4); + } + + @Override + public String[] getDescription() { + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + return new String[]{"Iron is a much better furnace material!", + "Can be Automated", + "Multiblock: 3x3x5 hollow with opening on top", + "Same shape as Bronze/Bricked blast furnace, except one ring of 8 taller.", + "40 Iron Plated Bricks required", + }; + } + else { + return new String[]{"Sloooowly, Skip the Bronze age, Get some Steel!", + "Multiblock: 3x3x5 hollow with opening on top", + "40 Iron Plated Bricks required", + "----", + "Even though Iron melts hotter than bronze,", + "this machine is to help players skip looking", + "for tin and copper, which are not as common", + "as Iron is. This machine takes 5x longer than the bronze", + "blast furnace as a result.", + "----", + }; + } + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return aActive ? FACING_ACTIVE : FACING_FRONT; + } + return FACING_SIDE; + } + + @Override + public boolean isSteampowered() { + return false; + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public boolean isPneumatic() { + return false; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final byte aSide) { + return false; + } + + @Override + public boolean isOutputFacing(final byte aSide) { + return false; + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing > 1; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public int getProgresstime() { + return this.mProgresstime; + } + + @Override + public int maxProgresstime() { + return this.mMaxProgresstime; + } + + @Override + public int increaseProgress(final int aProgress) { + this.mProgresstime += aProgress; + return this.mMaxProgresstime - this.mProgresstime; + } + + @Override + public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aCoverID) { + return (GregTech_API.getCoverBehavior(aCoverID.toStack()).isSimpleCover()) && (super.allowCoverOnSide(aSide, aCoverID)); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IronBlastFurnace(this.mName); + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mProgresstime", this.mProgresstime); + aNBT.setInteger("mMaxProgresstime", this.mMaxProgresstime); + if (this.mOutputItem1 != null) { + final NBTTagCompound tNBT = new NBTTagCompound(); + this.mOutputItem1.writeToNBT(tNBT); + aNBT.setTag("mOutputItem1", tNBT); + } + if (this.mOutputItem2 != null) { + final NBTTagCompound tNBT = new NBTTagCompound(); + this.mOutputItem2.writeToNBT(tNBT); + aNBT.setTag("mOutputItem2", tNBT); + } + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mUpdate = 30; + this.mProgresstime = aNBT.getInteger("mProgresstime"); + this.mMaxProgresstime = aNBT.getInteger("mMaxProgresstime"); + this.mOutputItem1 = GT_Utility.loadItem(aNBT, "mOutputItem1"); + this.mOutputItem2 = GT_Utility.loadItem(aNBT, "mOutputItem2"); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_IronBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_IronBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); + } + + private boolean checkMachine() { + final int xDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetX; + final int zDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetZ; + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 4; j++) { //This is height + for (int k = -1; k < 2; k++) { + if (((xDir + i) != 0) || (j != 0) || ((zDir + k) != 0)) { + if ((i != 0) || (j == -1) || (k != 0)) { + if ((this.getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k) != ModBlocks.blockCasingsMisc) || (this.getBaseMetaTileEntity().getMetaIDOffset(xDir + i, j, zDir + k) != 10)) { + return false; + } + } else if ((!GT_Utility.arrayContains(this.getBaseMetaTileEntity().getBlockOffset(xDir + i, j, zDir + k), new Object[]{Blocks.lava, Blocks.flowing_lava, null})) && (!this.getBaseMetaTileEntity().getAirOffset(xDir + i, j, zDir + k))) { + return false; + } + } + } + } + } + return true; + } + + @Override + public void onMachineBlockUpdate() { + this.mUpdate = 30; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) { + if ((aBaseMetaTileEntity.isClientSide()) && + (aBaseMetaTileEntity.isActive())) { + aBaseMetaTileEntity.getWorld().spawnParticle("cloud", aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1) + Math.random(), aBaseMetaTileEntity.getOffsetY(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1) + Math.random(), 0.0D, 0.3D, 0.0D); + } + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate-- == 0) { + this.mMachine = this.checkMachine(); + } + if (this.mMachine) { + if (this.mMaxProgresstime > 0) { + if (++this.mProgresstime >= this.mMaxProgresstime) { + this.addOutputProducts(); + this.mOutputItem1 = null; + this.mOutputItem2 = null; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + try { + GT_Mod.instance.achievements.issueAchievement(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "steel"); + } catch (final Exception e) { + } + } + } else if (aBaseMetaTileEntity.isAllowedToWork()) { + this.checkRecipe(); + } + } + aBaseMetaTileEntity.setActive((this.mMaxProgresstime > 0) && (this.mMachine)); + if (aBaseMetaTileEntity.isActive()) { + if (aBaseMetaTileEntity.getAir(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1))) { + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), Blocks.lava, 1, 2); + this.mUpdate = 1; + } + if (aBaseMetaTileEntity.getAir(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1))) { + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), Blocks.lava, 1, 2); + this.mUpdate = 1; + } + } else { + if (aBaseMetaTileEntity.getBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1)) == Blocks.lava) { + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), Blocks.air, 0, 2); + this.mUpdate = 1; + } + if (aBaseMetaTileEntity.getBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1)) == Blocks.lava) { + aBaseMetaTileEntity.getWorld().setBlock(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord() + 1, aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1), Blocks.air, 0, 2); + this.mUpdate = 1; + } + } + } + } + + private void addOutputProducts() { + if (this.mOutputItem1 != null) { + if (this.mInventory[2] == null) { + this.mInventory[2] = GT_Utility.copy(new Object[]{this.mOutputItem1}); + } else if (GT_Utility.areStacksEqual(this.mInventory[2], this.mOutputItem1)) { + this.mInventory[2].stackSize = Math.min(this.mOutputItem1.getMaxStackSize(), this.mOutputItem1.stackSize + this.mInventory[2].stackSize); + } + } + if (this.mOutputItem2 != null) { + if (this.mInventory[3] == null) { + this.mInventory[3] = GT_Utility.copy(new Object[]{this.mOutputItem2}); + } else if (GT_Utility.areStacksEqual(this.mInventory[3], this.mOutputItem2)) { + this.mInventory[3].stackSize = Math.min(this.mOutputItem2.getMaxStackSize(), this.mOutputItem2.stackSize + this.mInventory[3].stackSize); + } + } + } + + private boolean spaceForOutput(final ItemStack aStack1, final ItemStack aStack2) { + if (((this.mInventory[2] == null) || (aStack1 == null) || (((this.mInventory[2].stackSize + aStack1.stackSize) <= this.mInventory[2].getMaxStackSize()) && (GT_Utility.areStacksEqual(this.mInventory[2], aStack1)))) && ( + (this.mInventory[3] == null) || (aStack2 == null) || (((this.mInventory[3].stackSize + aStack2.stackSize) <= this.mInventory[3].getMaxStackSize()) && (GT_Utility.areStacksEqual(this.mInventory[3], aStack2))))) { + return true; + } + return false; + } + + private int getProperTime(int time) { + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + return (int) (time/3); + } + else { + return time; + } + } + + private boolean checkRecipe() { + + if (!this.mMachine) { + return false; + } + if ((this.mInventory[0] != null) && (this.mInventory[1] != null) && (this.mInventory[0].stackSize >= 1)) { + if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "dustIron")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "ingotIron"))) { + if ((this.mInventory[1].getItem() == Items.coal) && (this.mInventory[1].stackSize >= 4) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 4*3); + this.mMaxProgresstime = getProperTime(36000); + return true; + } + if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 2) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 2*3); + this.mMaxProgresstime = getProperTime(4800); + return true; + } + if ((this.mInventory[0].stackSize >= 9) && ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCoal")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCharcoal"))) && (this.mInventory[1].stackSize >= 4) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 9); + this.getBaseMetaTileEntity().decrStackSize(1, 4*3); + this.mMaxProgresstime = getProperTime(64800); + return true; + } + } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "dustSteel")) { + if ((this.mInventory[1].getItem() == Items.coal) && (this.mInventory[1].stackSize >= 2) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 2L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 2*3); + this.mMaxProgresstime = getProperTime(3600); + return true; + } + if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 1) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 1L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 2L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 1*3); + this.mMaxProgresstime = getProperTime(2400); + return true; + } + if ((this.mInventory[0].stackSize >= 9) && ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCoal")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCharcoal"))) && (this.mInventory[1].stackSize >= 2) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 2L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 9); + this.getBaseMetaTileEntity().decrStackSize(1, 2*3); + this.mMaxProgresstime = getProperTime(32400); + return true; + } + } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[0], "blockIron")) { + if ((this.mInventory[1].getItem() == Items.coal) && (this.mInventory[1].stackSize >= 36) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 64); + this.mMaxProgresstime = getProperTime(64800); + return true; + } + if ((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "fuelCoke")) && (this.mInventory[1].stackSize >= 18) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Ash, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 18*3); + this.mMaxProgresstime = getProperTime(43200); + return true; + } + if (((GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCoal")) || (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[1], "blockCharcoal"))) && (this.mInventory[1].stackSize >= 4) && (this.spaceForOutput(this.mOutputItem1 = GT_OreDictUnificator.get(OrePrefixes.ingot, Materials.Steel, 9L), this.mOutputItem2 = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 4L)))) { + this.getBaseMetaTileEntity().decrStackSize(0, 1); + this.getBaseMetaTileEntity().decrStackSize(1, 4*3); + this.mMaxProgresstime = getProperTime(64800); + return true; + } + } + } + this.mOutputItem1 = null; + this.mOutputItem2 = null; + return false; + } + + @Override + public boolean isGivingInformation() { + return false; + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return aIndex > 1; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + if (aIndex < 2) { + } + return !GT_Utility.areStacksEqual(aStack, this.mInventory[0]); + } + + @Override + public byte getTileEntityBaseType() { + return 0; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java new file mode 100644 index 0000000000..59e6e78757 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java @@ -0,0 +1,666 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.core.lib.CORE; +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.GT_MetaTileEntity_Hatch_MillingBalls; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +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.util.DamageSource; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_IsaMill extends GregtechMeta_MultiBlockBase { + + protected boolean boostEu = false; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IsaMill> STRUCTURE_DEFINITION = null; + + private static ITexture frontFace; + private static ITexture frontFaceActive; + + private ArrayList<GT_MetaTileEntity_Hatch_MillingBalls> mMillingBallBuses = new ArrayList<GT_MetaTileEntity_Hatch_MillingBalls>(); + private static final DamageSource mIsaMillDamageSource = new DamageSource("gtpp.grinder").setDamageBypassesArmor(); + + public GregtechMetaTileEntity_IsaMill(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + frontFaceActive = new GT_RenderedTexture(new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE5")); + frontFace = new GT_RenderedTexture(new CustomIcon("iconsets/Grinder/GRINDER5")); + } + + public GregtechMetaTileEntity_IsaMill(String aName) { + super(aName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Grinding Machine") + .addInfo("Grind ores.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 7, false) + .addController("Front Center") + .addCasingInfo("IsaMill Exterior Casing", 40) + .addOtherStructurePart("IsaMill Gearbox", "Inner Blocks") + .addOtherStructurePart("IsaMill Piping", "8x, ring around controller") + .addStructureInfo("IsaMill Pipings must not be obstructed in front (only air blocks)") + .addOtherStructurePart("Milling Ball Hatch", "Any Casing") + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IsaMill> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IsaMill>builder() + .addShape(mName, transpose(new String[][]{ + {"DDD", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC"}, + {"D~D", "CGC", "CGC", "CGC", "CGC", "CGC", "CCC"}, + {"DDD", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IsaMill::addToMachineList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + ) + ) + .addElement( + 'D', + ofBlock( + getIntakeBlock(), getIntakeMeta() + ) + ) + .addElement( + 'G', + ofBlock( + getGearboxBlock(), getGearboxMeta() + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mMillingBallBuses.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 48 - 8 && checkHatch(); + } + + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(2)), + aFacing == aSide ? aActive ? frontFaceActive : frontFace : Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(2))}; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_MillingBalls) { + log("Found GT_MetaTileEntity_Hatch_MillingBalls"); + return addToMachineListInternal(mMillingBallBuses, aMetaTileEntity, aBaseCasingIndex); + } + return super.addToMachineList(aTileEntity, aBaseCasingIndex); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeDieselEngine.png"); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sOreMillRecipes; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mMillingBallBuses.clear(); + } + } + if (aTick % 20 == 0) { + checkForEntities(aBaseMetaTileEntity, aTick); + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + private final AutoMap<BlockPos> mFrontBlockPosCache = new AutoMap<BlockPos>(); + + public void checkForEntities(IGregTechTileEntity aBaseMetaTileEntity, long aTime) { + + if (aTime % 100 == 0) { + mFrontBlockPosCache.clear(); + } + if (mFrontBlockPosCache.isEmpty()) { + byte tSide = aBaseMetaTileEntity.getBackFacing(); + int aTileX = aBaseMetaTileEntity.getXCoord(); + int aTileY = aBaseMetaTileEntity.getYCoord(); + int aTileZ = aBaseMetaTileEntity.getZCoord(); + boolean xFacing = (tSide == 4 || tSide == 5); + boolean zFacing = (tSide == 2 || tSide == 3); + + // Check Casings + int aDepthOffset = (tSide == 2 || tSide == 4) ? 1 : -1; + for (int aHorizontalOffset = -1; aHorizontalOffset < 2; aHorizontalOffset++) { + for (int aVerticalOffset = -1; aVerticalOffset < 2; aVerticalOffset++) { + int aX = !xFacing ? (aTileX + aHorizontalOffset) : (aTileX + aDepthOffset); + int aY = aTileY + aVerticalOffset; + int aZ = !zFacing ? (aTileZ + aHorizontalOffset) : (aTileZ + aDepthOffset); + mFrontBlockPosCache.add(new BlockPos(aX, aY, aZ, aBaseMetaTileEntity.getWorld())); + } + } + } + + AutoMap<EntityLivingBase> aEntities = getEntities(mFrontBlockPosCache, aBaseMetaTileEntity.getWorld()); + if (!aEntities.isEmpty()) { + for (EntityLivingBase aFoundEntity : aEntities) { + if (aFoundEntity instanceof EntityPlayer) { + EntityPlayer aPlayer = (EntityPlayer) aFoundEntity; + if (PlayerUtils.isCreative(aPlayer) || !PlayerUtils.canTakeDamage(aPlayer)) { + continue; + } + else { + if (aFoundEntity.getHealth() > 0) { + EntityUtils.doDamage(aFoundEntity, mIsaMillDamageSource, (int) (aFoundEntity.getMaxHealth() / 5)); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { + generateParticles(aFoundEntity); + } + } + } + } + if (aFoundEntity.getHealth() > 0) { + EntityUtils.doDamage(aFoundEntity, mIsaMillDamageSource, Math.max(1, (int) (aFoundEntity.getMaxHealth() / 3))); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { + generateParticles(aFoundEntity); + } + } + } + } + } + + private static final AutoMap<EntityLivingBase> getEntities(AutoMap<BlockPos> aPositionsToCheck, World aWorld){ + AutoMap<EntityLivingBase> aEntities = new AutoMap<EntityLivingBase>(); + HashSet<Chunk> aChunksToCheck = new HashSet<Chunk>(); + if (!aPositionsToCheck.isEmpty()) { + Chunk aLocalChunk; + for (BlockPos aPos : aPositionsToCheck) { + aLocalChunk = aWorld.getChunkFromBlockCoords(aPos.xPos, aPos.zPos); + aChunksToCheck.add(aLocalChunk); + } + } + if (!aChunksToCheck.isEmpty()) { + AutoMap<EntityLivingBase> aEntitiesFound = new AutoMap<EntityLivingBase>(); + for (Chunk aChunk : aChunksToCheck) { + if (aChunk.isChunkLoaded) { + List[] aEntityLists = aChunk.entityLists; + for (List aEntitySubList : aEntityLists) { + for (Object aEntity : aEntitySubList) { + if (aEntity instanceof EntityLivingBase) { + EntityLivingBase aPlayer = (EntityLivingBase) aEntity; + aEntitiesFound.add(aPlayer); + } + } + } + } + } + if (!aEntitiesFound.isEmpty()) { + for (EntityLivingBase aEntity : aEntitiesFound) { + BlockPos aPlayerPos = EntityUtils.findBlockPosOfEntity(aEntity); + for (BlockPos aBlockSpaceToCheck : aPositionsToCheck) { + if (aBlockSpaceToCheck.equals(aPlayerPos)) { + aEntities.add(aEntity); + } + } + } + } + } + return aEntities; + } + + private static void generateParticles(EntityLivingBase aEntity) { + BlockPos aPlayerPosBottom = EntityUtils.findBlockPosOfEntity(aEntity); + BlockPos aPlayerPosTop = aPlayerPosBottom.getUp(); + AutoMap<BlockPos> aEntityPositions = new AutoMap<BlockPos>(); + aEntityPositions.add(aPlayerPosBottom); + aEntityPositions.add(aPlayerPosTop); + for (int i = 0; i < 64; i++) { + BlockPos aEffectPos = aEntityPositions.get(aEntity.height > 1f ? MathUtils.randInt(0, 1) : 0); + float aOffsetX = MathUtils.randFloat(-0.35f, 0.35f); + float aOffsetY = MathUtils.randFloat(-0.25f, 0.35f); + float aOffsetZ = MathUtils.randFloat(-0.35f, 0.35f); + aEntity.worldObj.spawnParticle("reddust", aEffectPos.xPos + aOffsetX, aEffectPos.yPos + 0.3f + aOffsetY, aEffectPos.zPos + aOffsetZ, 0.0D, 0.0D, 0.0D); + } + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + return checkRecipeGeneric(); + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public Block getIntakeBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getIntakeMeta() { + return 1; + } + + public Block getGearboxBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getGearboxMeta() { + return 2; + } + + public byte getCasingTextureIndex() { + return 66; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IsaMill(this.mName); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIsaMill; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public String[] getExtraInfoData() { + return new String[]{ + "IsaMill Grinding Machine", + "Current Efficiency: " + (mEfficiency / 100) + "%", + getIdealStatus() == getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance" + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Grinding Machine"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + /* + * Milling Ball Handling + */ + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> tItems = super.getStoredInputs(); + for (GT_MetaTileEntity_Hatch_MillingBalls tHatch : mMillingBallBuses) { + tHatch.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + tItems.addAll(tHatch.getContentUsageSlots()); + } + } + return tItems; + } + + + public int getMaxBallDurability(ItemStack aStack) { + return ItemGenericChemBase.getMaxBallDurability(aStack); + } + + private ItemStack findMillingBall(ItemStack[] aItemInputs) { + if (mMillingBallBuses.isEmpty() || mMillingBallBuses.size() > 1) { + return null; + } + else { + GT_MetaTileEntity_Hatch_MillingBalls aBus = mMillingBallBuses.get(0); + if (aBus != null) { + AutoMap<ItemStack> aAvailableItems = aBus.getContentUsageSlots(); + if (!aAvailableItems.isEmpty()) { + for (final ItemStack aInput : aItemInputs) { + if (ItemUtils.isMillingBall(aInput)) { + for (ItemStack aBall : aAvailableItems) { + if (GT_Utility.areStacksEqual(aBall, aInput, true)) { + Logger.INFO("Found a valid milling ball to use."); + return aBall; + } + } + } + } + } + } + } + return null; + } + + + private void damageMillingBall(ItemStack aStack) { + if (MathUtils.randFloat(0, 10000000)/10000000f < (1.2f - (0.2 * 1))) { + int damage = getMillingBallDamage(aStack) + 1; + log("damage milling ball "+damage); + if (damage >= getMaxBallDurability(aStack)) { + log("consuming milling ball"); + aStack.stackSize -= 1; + } + else { + setDamage(aStack,damage); + } + } + else { + log("not damaging milling ball"); + } + } + + private int getMillingBallDamage(ItemStack aStack) { + return ItemGenericChemBase.getMillingBallDamage(aStack); + } + + private void setDamage(ItemStack aStack,int aAmount) { + ItemGenericChemBase.setMillingBallDamage(aStack, aAmount); + } + + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, FluidStack[] aFluidInputs, + int aMaxParallelRecipes, int aEUPercent, + int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe, boolean isOC) { + + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + // checks if it has a milling ball with enough durability + ItemStack tMillingBallRecipe = findMillingBall(aItemInputs); + if (tMillingBallRecipe == null) { + log("does not have milling ball"); + return false; + } + + GT_Recipe tRecipe = findRecipe( + getBaseMetaTileEntity(), mLastRecipe, false, + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + log("aEUPercent "+aEUPercent); + log("mEUt "+tRecipe.mEUt); + + int parallelRecipes = 0; + + log("parallelRecipes: "+parallelRecipes); + log("aMaxParallelRecipes: "+1); + log("tTotalEUt: "+tTotalEUt); + log("tVoltage: "+tVoltage); + log("tEnergy: "+tEnergy); + log("tRecipeEUt: "+tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < 1 && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at "+parallelRecipes+"."); + break; + } + log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int)Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + + // Damage Milling ball once all is said and done. + if (tMillingBallRecipe != null) { + log("damaging milling ball"); + damageMillingBall(tMillingBallRecipe); + } + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java new file mode 100644 index 0000000000..81f8ba9edb --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java @@ -0,0 +1,414 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.isAir; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +import java.util.ArrayList; +import java.util.List; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.Textures; +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GasSpargingRecipe; +import gregtech.api.util.GasSpargingRecipeMap; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_SpargeTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_SpargeTower> { + + protected static final String STRUCTURE_PIECE_BASE = "base"; + protected static final String STRUCTURE_PIECE_LAYER = "layer"; + protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; + protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; + private static final IStructureDefinition<GregtechMetaTileEntity_SpargeTower> STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SpargeTower>builder() + .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][]{ + {"b~b", "bbb", "bbb"}, + })) + .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][]{ + {"lll", "lcl", "lll"} + })) + .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][]{ + {"lll", "l-l", "lll"} + })) + .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][]{ + {"lll", "lll", "lll"} + })) + .addElement('b', ofChain( + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, getCasingIndex(), 1), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addInputToMachineList, getCasingIndex(), 1), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 1), + onElementPass(GregtechMetaTileEntity_SpargeTower::onCasingFound, ofBlock(ModBlocks.blockCasings5Misc, 4)) + )) + .addElement('l', ofChain( + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, getCasingIndex(), 2), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addLayerOutputHatch, getCasingIndex(), 2), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 2), + onElementPass(GregtechMetaTileEntity_SpargeTower::onCasingFound, ofBlock(ModBlocks.blockCasings5Misc, 4)) + )) + .addElement('c', ofChain( + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addOutputToMachineList, getCasingIndex(), 3)), + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 3)), + onElementPass(t -> t.onTopLayerFound(true), ofBlock(ModBlocks.blockCasings5Misc, 4)), + isAir() + )) + .build(); + + protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); + protected int mHeight; + protected int mCasing; + protected boolean mTopLayerFound; + + public GregtechMetaTileEntity_SpargeTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_SpargeTower(String aName) { + super(aName); + } + + public static int getCasingIndex() { + return 68; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_SpargeTower(this.mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Gas Sparge Tower") + .addInfo("Controller block for the Sparging Tower") + .addInfo("Fluids are only put out at the correct height") + .addInfo("The correct height equals the slot number in the NEI recipe") + .addSeparator() + .beginStructureBlock(3, 8, 3, true) + .addController("Front bottom") + .addOtherStructurePart("Sparge Tower Exterior Casing", "45 (minimum)") + .addEnergyHatch("Any casing", 1, 2) + .addMaintenanceHatch("Any casing", 1, 2, 3) + .addInputHatch("2x Input Hatches (Any bottom layer casing)", 1) + .addOutputHatch("6x Output Hatches (At least one per layer except bottom layer)", 2, 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + if (aActive) + return new ITexture[]{ + BlockIcons.getCasingTextureForId(getCasingIndex()), + TextureFactory.builder().addIcon(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active).extFacing().build()}; + return new ITexture[]{ + BlockIcons.getCasingTextureForId(getCasingIndex()), + TextureFactory.builder().addIcon(TexturesGtBlock.Overlay_Machine_Controller_Advanced).extFacing().build()}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(getCasingIndex())}; + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DistillationTower.png"); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { + generateRecipes(); + } + return GTPP_Recipe_Map.sSpargeTowerRecipes; + } + + private static boolean generateRecipes() { + for (GasSpargingRecipe aRecipe : GasSpargingRecipeMap.mRecipes) { + GTPP_Recipe newRecipe = new GTPP_Recipe( + false, + new ItemStack[] {}, + new ItemStack[] {}, + null, + null, + aRecipe.mFluidInputs.clone(), + new FluidStack[] {}, + aRecipe.mDuration, + aRecipe.mEUt, + 0); + GTPP_Recipe_Map.sSpargeTowerRecipes.add(newRecipe); + } + if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { + return false; + } + return true; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + ArrayList<FluidStack> tFluidList = getStoredFluids(); + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(0, GT_Utility.getTier(tVoltage)); + FluidStack[] tFluids = tFluidList.toArray(new FluidStack[0]); + if (tFluids.length > 0) { + Logger.INFO("Found "+tFluids.length+" input fluids. Searching "+GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.size()+" recipes."); + GT_Recipe tRecipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids); + if (tRecipe != null) { + Logger.INFO("Found recipe!"); + if (tRecipe.isRecipeInputEqual(true, tFluids)) { + Logger.INFO("Found recipe that matches!"); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Reset outputs and progress stats + this.mEUt = 0; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + this.mLastRecipe = tRecipe; + + calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); + int aDevProgress = this.mMaxProgresstime / 10; + this.mMaxProgresstime = Math.max(1, aDevProgress); + this.mOutputItems = new ItemStack[]{}; + ArrayList<FluidStack> aFluidOutputs = getByproductsOfSparge(tRecipe.mFluidInputs[0], tRecipe.mFluidInputs[1]); + this.mOutputFluids = (FluidStack[]) aFluidOutputs.toArray(new FluidStack[0]); + updateSlots(); + Logger.INFO("Done!"); + return true; + } + } + else { + Logger.INFO("Did not find recipe!"); + } + } + this.mEUt = 0; + this.mEfficiency = 0; + Logger.INFO("Did not find recipe! (2)"); + return false; + } + + private static ArrayList<FluidStack> getByproductsOfSparge(final FluidStack aSpargeGas, final FluidStack aSpentFuel){ + GasSpargingRecipe aSpargeRecipe = GasSpargingRecipeMap.findRecipe(aSpargeGas, aSpentFuel); + ArrayList<FluidStack> aOutputGases = new ArrayList<FluidStack>(); + if (aSpargeRecipe == null) { + Logger.INFO("Did not find sparge recipe!"); + return aOutputGases; + } + int aSpargeGasAmount = aSpargeRecipe.mInputGas.amount; + + aOutputGases.add(aSpargeRecipe.mOutputSpargedFuel.copy()); + ArrayList<FluidStack> aTempMap = new ArrayList<FluidStack>(); + for (int i=2;i<aSpargeRecipe.mFluidOutputs.length;i++) { + int aGasAmount = MathUtils.randInt(0, (aSpargeRecipe.mMaxOutputQuantity[i-2]/100)); + FluidStack aOutput = aSpargeRecipe.mFluidOutputs[i].copy(); + aSpargeGasAmount -= aGasAmount; + FluidStack aSpargeOutput = null; + if (aGasAmount > 0) { + aSpargeOutput = new FluidStack(aOutput.getFluid(), aGasAmount); + } + aTempMap.add(aSpargeOutput); + } + Logger.INFO("Sparge gas left: "+aSpargeGasAmount); + if (aSpargeGasAmount > 0) { + aOutputGases.add(new FluidStack(aSpargeRecipe.mInputGas.getFluid(), aSpargeGasAmount)); + } + //Logger.INFO("Sparge Outputs: "+ItemUtils.getArrayStackNames(aTempMap)); + aOutputGases.addAll(aTempMap); + Logger.INFO("Sparge output size: "+aOutputGases.size()); + //Logger.INFO("Output of sparging: "+ItemUtils.getArrayStackNames(aOutputGases)); + return aOutputGases; + } + + protected void onCasingFound() { + mCasing++; + } + + protected void onTopLayerFound(boolean aIsCasing) { + mTopLayerFound = true; + if (aIsCasing) { + onCasingFound(); + } + } + + protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null || aTileEntity.isDead() || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output)) { + Logger.INFO("Bad Output Hatch"); + return false; + } + while (mOutputHatchesByLayer.size() < mHeight) { + mOutputHatchesByLayer.add(new ArrayList<>()); + } + GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) aTileEntity.getMetaTileEntity(); + tHatch.updateTexture(aBaseCasingIndex); + boolean addedHatch = mOutputHatchesByLayer.get(mHeight - 1).add(tHatch); + Logger.INFO("Added Hatch: "+addedHatch); + return addedHatch; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a freaking tower, it won't work + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SpargeTower> getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + // reset + mOutputHatchesByLayer.forEach(List::clear); + mHeight = 1; + mTopLayerFound = false; + mCasing = 0; + + // check base + if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) { + Logger.INFO("Bad Base. Height: "+mHeight); + return false; + } + + // check each layer + while (mHeight < 8 && checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0) && !mTopLayerFound) { + if (mOutputHatchesByLayer.get(mHeight - 1).isEmpty()) { + // layer without output hatch + Logger.INFO("Height: "+mHeight + " - Missing output on "+(mHeight - 1)); + return false; + } + // not top + mHeight++; + } + + // validate final invariants... + Logger.INFO("Height: "+mHeight); + Logger.INFO("Casings: "+mCasing); + Logger.INFO("Required: "+(7 * mHeight - 5)); + Logger.INFO("Found Top: "+mTopLayerFound); + return mCasing >= 45 && mTopLayerFound && mMaintenanceHatches.size() == 1; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + protected void addFluidOutputs(FluidStack[] mOutputFluids2) { + for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { + FluidStack tStack = mOutputFluids2[i] != null ? mOutputFluids2[i].copy() : null; + if (tStack == null) { + continue; + } + if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) { + dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); + } + } + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); + int tTotalHeight = 8; // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); + } + buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getMachineType() { + return "Gas Sparger"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean onPlungerRightClick(EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + int aLayerIndex = 0; + PlayerUtils.messagePlayer(aPlayer, "Trying to clear "+mOutputHatchesByLayer.size()+" layers of output hatches."); + for (List<GT_MetaTileEntity_Hatch_Output> layer : this.mOutputHatchesByLayer) { + int aHatchIndex = 0; + for (GT_MetaTileEntity_Hatch_Output hatch : layer) { + if (hatch.mFluid != null) { + PlayerUtils.messagePlayer(aPlayer, "Clearing "+hatch.mFluid.amount+"L of "+hatch.mFluid.getLocalizedName()+" from hatch "+aHatchIndex+" on layer "+aLayerIndex+"."); + hatch.mFluid = null; + } + aHatchIndex++; + } + aLayerIndex++; + } + return aLayerIndex > 0; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_AssemblyLine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_AssemblyLine.java new file mode 100644 index 0000000000..8c9e886e94 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_AssemblyLine.java @@ -0,0 +1,629 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import java.util.ArrayList; +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_DataAccess; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.util.minecraft.LangUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Naquadah; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_Adv_AssemblyLine + extends GregtechMeta_MultiBlockBase { + + public ArrayList<GT_MetaTileEntity_Hatch_DataAccess> mDataAccessHatches = new ArrayList<GT_MetaTileEntity_Hatch_DataAccess>(); + + public static String[] mCasingName = new String[5]; + private final int CASING_TEXTURE_ID = TAE.getIndexFromPage(0, 13); + private final int META_BaseCasing = 0; //4 + private final int META_ContainmentCasing = 15; //3 + private final int META_Shielding = 13; //1 + private final int META_PipeCasing = 1; //4 + private final int META_IntegralCasing = 6; //0 + private final int META_ContainmentChamberCasing = 2; //4 + + + public GregtechMetaTileEntity_Adv_AssemblyLine(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + mCasingName[0] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 0); + mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); + mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); + mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); + mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); + } + + public GregtechMetaTileEntity_Adv_AssemblyLine(String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_AssemblyLine(this.mName); + } + + public String[] getTooltip() { + if (mCasingName[0].toLowerCase().contains(".name")) { + mCasingName[0] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 0); + } + if (mCasingName[1].toLowerCase().contains(".name")) { + mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); + } + if (mCasingName[2].toLowerCase().contains(".name")) { + mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); + } + if (mCasingName[3].toLowerCase().contains(".name")) { + mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); + } + if (mCasingName[4].toLowerCase().contains(".name")) { + mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); + } + return new String[]{ + "Advanced Integrated Assembly Line" + }; + } + + private Block getCasing(int casingID) { + if (casingID == 1) { + return ModBlocks.blockCasingsMisc; + } + else if (casingID == 2) { + return ModBlocks.blockCasings2Misc; + } + else if (casingID == 3) { + return ModBlocks.blockCasings3Misc; + } + else if (casingID == 4) { + return ModBlocks.blockCasings4Misc; + } + else { + return ModBlocks.blockCasingsTieredGTPP; + } + } + + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(16), new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(16)}; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "AssemblyLine.png"); + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public boolean isFacingValid(byte aFacing) { + return aFacing > 1; + } + + public boolean checkRecipe(ItemStack aStack) { + if(GT_Values.D1)System.out.println("Start ALine recipe check"); + ArrayList<ItemStack> tDataStickList = getDataItems(2); + if (tDataStickList.size() == 0) return false; + if(GT_Values.D1)System.out.println("Stick accepted, " + tDataStickList.size() + " Data Sticks found"); + + ItemStack tStack[] = new ItemStack[15]; + FluidStack[] tFluids = new FluidStack[4]; + boolean findRecipe = false; + nextDS:for (ItemStack tDataStick : tDataStickList){ + NBTTagCompound tTag = tDataStick.getTagCompound(); + if (tTag == null) continue; + for (int i = 0; i < 15; i++) { + int count = tTag.getInteger("a"+i); + if (!tTag.hasKey("" + i) && count <= 0) continue; + if (mInputBusses.get(i) == null) { + continue nextDS; + } + + ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); + boolean flag = true; + if (count > 0) { + for (int j = 0; j < count; j++) { + tStack[i] = GT_Utility.loadItem(tTag, "a" + i + ":" + j); + if (tStack[i] == null) continue; + if(GT_Values.D1)System.out.println("Item "+i+" : "+tStack[i].getUnlocalizedName()); + if (GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) && tStack[i].stackSize <= stackInSlot.stackSize) { + flag = false; + break; + } + } + } + if (flag) { + tStack[i] = GT_Utility.loadItem(tTag, "" + i); + if (tStack[i] == null) { + flag = false; + continue; + } + if(GT_Values.D1)System.out.println("Item "+i+" : "+tStack[i].getUnlocalizedName()); + if (GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) && tStack[i].stackSize <= stackInSlot.stackSize) { + flag = false; + } + } + if(GT_Values.D1) System.out.println(i + (flag ? " not accepted" : " accepted")); + if (flag) continue nextDS; + } + + if(GT_Values.D1)System.out.println("All Items done, start fluid check"); + for (int i = 0; i < 4; i++) { + if (!tTag.hasKey("f" + i)) continue; + tFluids[i] = GT_Utility.loadFluid(tTag, "f" + i); + if (tFluids[i] == null) continue; + if(GT_Values.D1)System.out.println("Fluid "+i+" "+tFluids[i].getUnlocalizedName()); + if (mInputHatches.get(i) == null) { + continue nextDS; + } + FluidStack fluidInHatch = mInputHatches.get(i).mFluid; + if (fluidInHatch == null || !GT_Utility.areFluidsEqual(fluidInHatch, tFluids[i], true) || fluidInHatch.amount < tFluids[i].amount) { + if(GT_Values.D1)System.out.println(i+" not accepted"); + continue nextDS; + } + if(GT_Values.D1)System.out.println(i+" accepted"); + } + + if(GT_Values.D1)System.out.println("Input accepted, check other values"); + if (!tTag.hasKey("output")) continue; + mOutputItems = new ItemStack[]{GT_Utility.loadItem(tTag, "output")}; + if (mOutputItems[0] == null || !GT_Utility.isStackValid(mOutputItems[0])) + continue; + + if (!tTag.hasKey("time")) continue; + mMaxProgresstime = tTag.getInteger("time"); + if (mMaxProgresstime <= 0) continue; + + if (!tTag.hasKey("eu")) continue; + mEUt = tTag.getInteger("eu"); + + if(GT_Values.D1)System.out.println("Find avaiable recipe"); + findRecipe = true; + break; + } + if (!findRecipe) return false; + + if(GT_Values.D1)System.out.println("All checked start consuming inputs"); + for (int i = 0; i < 15; i++) { + if (tStack[i] == null) continue; + ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); + stackInSlot.stackSize -= tStack[i].stackSize; + } + + for (int i = 0; i < 4; i++) { + if (tFluids[i] == null) continue; + mInputHatches.get(i).mFluid.amount -= tFluids[i].amount; + if (mInputHatches.get(i).mFluid.amount <= 0) { + mInputHatches.get(i).mFluid = null; + } + } + if(GT_Values.D1)System.out.println("Check overclock"); + + byte tTier = (byte) Math.max(1, GT_Utility.getTier(getMaxInputVoltage())); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + if (mEUt <= 16) { + this.mEUt = (mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + if (this.mEUt > 0) { + this.mEUt = -this.mEUt; + } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + updateSlots(); + if(GT_Values.D1)System.out.println("Recipe sucessfull"); + return true; + } + + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 20) { + GT_Utility.doSoundAtClient(GregTech_API.sSoundList.get(212), 10, 1.0F, aX, aY, aZ); + } + } + + public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 4; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 4; + + // Counts for all Casing Types + int aBaseCasingCount = 0; + int aContainmentCasingCount = 0; + int aShieldingCount = 0; + int aPipeCount = 0; + int aIntegralCasingCount = 0; + int aContainmentChamberCount = 0; + + // Bottom Layer + aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, -7, xDir, zDir); + log("Bottom Layer is Valid. Moving to Layer 1."); + + // Layer 1 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -6, xDir, zDir); + aIntegralCasingCount += checkIntegralRing(aBaseMetaTileEntity, getCasing(0), this.META_IntegralCasing, -6, xDir, zDir); + aContainmentChamberCount += checkContainmentRing(aBaseMetaTileEntity, getCasing(4), this.META_ContainmentChamberCasing, -6, xDir, zDir); + log("Layer 1 is Valid. Moving to Layer 2."); + + // Layer 2 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -5, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -5, xDir, zDir); + log("Layer 2 is Valid. Moving to Layer 3."); + + // Layer 3 + aContainmentCasingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(3), this.META_ContainmentCasing, -4, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -4, xDir, zDir); + log("Layer 3 is Valid. Moving to Layer 4."); + + // Layer 4 + aContainmentCasingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(3), this.META_ContainmentCasing, -3, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -3, xDir, zDir); + log("Layer 4 is Valid. Moving to Layer 5."); + + // Layer 5 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -2, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -2, xDir, zDir); + log("Layer 5 is Valid. Moving to Layer 6."); + + // Layer 6 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -1, xDir, zDir); + aIntegralCasingCount += checkIntegralRing(aBaseMetaTileEntity, getCasing(0), this.META_IntegralCasing, -1, xDir, zDir); + aContainmentChamberCount += checkContainmentRing(aBaseMetaTileEntity, getCasing(4), this.META_ContainmentChamberCasing, -1, xDir, zDir); + log("Layer 6 is Valid. Moving to Top Layer."); + + // Top Layer + aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, 0, xDir, zDir); + + log("Found "+aBaseCasingCount+" "+mCasingName[0]+"s"); + log("Found "+aShieldingCount+" "+mCasingName[4]+"s"); + log("Found "+aPipeCount+" "+mCasingName[1]+"s"); + log("Found "+aContainmentCasingCount+" "+mCasingName[3]+"s"); + log("Found "+aIntegralCasingCount+" "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s"); + log("Found "+aContainmentChamberCount+" "+mCasingName[2]+"s"); + + // Try mesage player + String aOwnerName = this.getBaseMetaTileEntity().getOwnerName(); + EntityPlayer aOwner = null; + if (aOwnerName != null && aOwnerName.length() > 0) { + aOwner = PlayerUtils.getPlayer(aOwnerName); + } + + if (aShieldingCount != 128) { + log("Not enough "+mCasingName[4]+"s, require 128."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[4]+"s, require 128."); + } + return false; + } + if (aPipeCount != 20) { + log("Not enough "+mCasingName[1]+"s, require 20."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[1]+"s, require 20."); + } + return false; + } + if (aContainmentCasingCount != 64) { + log("Not enough "+mCasingName[3]+"s, require 64."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[3]+"s, require 64."); + } + return false; + } + if (aContainmentChamberCount != 42) { + log("Not enough "+mCasingName[2]+"s, require 42."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[2]+"s, require 42."); + } + return false; + } + if (aBaseCasingCount < 140) { + log("Not enough "+mCasingName[0]+"s, require 140 at a minimum."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[0]+"s, require 140 at a minimum."); + } + return false; + } + if (aIntegralCasingCount != 48) { + log("Not enough "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s, require 48."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s, require 48."); + } + return false; + } + log("LNR Formed."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Large Naquadah Reactor has formed successfully."); + } + return true; + } + + public boolean addNaquadahHatchToMachineInput(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_DataAccess) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return mDataAccessHatches.add((GT_MetaTileEntity_Hatch_DataAccess) aMetaTileEntity); + } + return false; + } + + public int checkEntireLayer(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -4; x < 5; x++) { + for (int z = -4; z < 5; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { + continue; + } + // Skip controller + if (aY == 0 && x == 0 && z == 0) { + continue; + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, true, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + public int checkOuterRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -4; x < 5; x++) { + for (int z = -4; z < 5; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { + continue; + } + + // If we are on the 5x5 ring, proceed + if ((x > -4 && x < 4 ) && (z > -4 && z < 4)) { + if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + } + else { + continue; + } + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + public int checkIntegralRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -3; x < 4; x++) { + for (int z = -3; z < 4; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { + continue; + } + + // If we are on the 5x5 ring, proceed + if ((x > -3 && x < 3 ) && (z > -3 && z < 3)) { + if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + } + else { + continue; + } + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + public int checkPipes(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -1; x < 2; x++) { + for (int z = -1; z < 2; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 1 && z == 1) || (x == -1 && z == -1) || (x == 1 && z == -1) || (x == -1 && z == 1) || (x == 0 && z == 0)) { + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Pipe has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + }; + } + } + } + return aCasingCount; + } + + public int checkContainmentRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -2; x < 3; x++) { + for (int z = -2; z < 3; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { + continue; + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + */ +/** + * @param state using bitmask, 1 for IntegratedCircuit, 2 for DataStick, 4 for DataOrb + *//* + + private boolean isCorrectDataItem(ItemStack aStack, int state){ + if ((state & 1) != 0 && ItemList.Circuit_Integrated.isStackEqual(aStack, true, true)) return true; + if ((state & 2) != 0 && ItemList.Tool_DataStick.isStackEqual(aStack, false, true)) return true; + if ((state & 4) != 0 && ItemList.Tool_DataOrb.isStackEqual(aStack, false, true)) return true; + return false; + } + + */ +/** + * @param state using bitmask, 1 for IntegratedCircuit, 2 for DataStick, 4 for DataOrb + *//* + + public ArrayList<ItemStack> getDataItems(int state) { + ArrayList<ItemStack> rList = new ArrayList<ItemStack>(); + if (GT_Utility.isStackValid(mInventory[1]) && isCorrectDataItem(mInventory[1], state)) { + rList.add(mInventory[1]); + } + for (GT_MetaTileEntity_Hatch_DataAccess tHatch : mDataAccessHatches) { + if (isValidMetaTileEntity(tHatch)) { + for (int i = 0; i < tHatch.getBaseMetaTileEntity().getSizeInventory(); i++) { + if (tHatch.getBaseMetaTileEntity().getStackInSlot(i) != null + && isCorrectDataItem(tHatch.getBaseMetaTileEntity().getStackInSlot(i), state)) + rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + } + return rList; + } + + public boolean addDataAccessToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_DataAccess) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return mDataAccessHatches.add((GT_MetaTileEntity_Hatch_DataAccess) aMetaTileEntity); + } + return false; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Assembly Line"; + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java new file mode 100644 index 0000000000..6d8ca49d7d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java @@ -0,0 +1,481 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Textures; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; + +public class GregtechMetaTileEntity_Adv_DistillationTower extends GregtechMeta_MultiBlockBase { + + private short mControllerY = 0; + private byte mMode = 0; + private boolean mUpgraded = false; + private IStructureDefinition<GregtechMetaTileEntity_Adv_DistillationTower> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Adv_DistillationTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Adv_DistillationTower(String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_DistillationTower(this.mName); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_DistillationTower> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_DistillationTower>builder() + .addShape(mName + "bottom", transpose(new String[][]{ + {"I~I", "III", "III"} + })) + .addShape(mName + "mid", transpose(new String[][]{ + {"CCC", "C-C", "CCC"} + })) + .addShape(mName + "top", transpose(new String[][]{ + {"MMM", "MMM", "MMM"} + })) + .addElement( + 'I', + ofHatchAdderOptional( + GregtechMetaTileEntity_Adv_DistillationTower::addAdvDistillationTowerBottomList, getCasingTextureID(), + 1, GregTech_API.sBlockCasings4, 1 + ) + ) + .addElement( + 'C', + ofHatchAdderOptional( + GregtechMetaTileEntity_Adv_DistillationTower::addAdvDistillationTowerMidList, getCasingTextureID(), + 2, GregTech_API.sBlockCasings4, 1 + ) + ) + .addElement( + 'M', + ofHatchAdderOptional( + GregtechMetaTileEntity_Adv_DistillationTower::addAdvDistillationTowerTopList, getCasingTextureID(), + 3, GregTech_API.sBlockCasings4, 1 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addAdvDistillationTowerBottomList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addAdvDistillationTowerMidList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addAdvDistillationTowerTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Advanced Distillation Tower") + .addInfo("T1 and T2 constructed identical to standard DT") + .addInfo("Right click the controller with screwdriver to change mode.") + .addInfo("Max parallel dictated by tower tier and mode") + .addInfo("DTower Mode: T1=4, T2=12") + .addInfo("Distilery Mode: Tower Tier * (4*InputTier)") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addCasingInfo("Clean Stainless Steel Machine Casing", 7) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addOutputHatch("One per layer except bottom", 2) + .addMufflerHatch("Top Center Casing", 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + int layer = Math.min(stackSize.stackSize + 2, 12); + buildPiece(mName + "bottom", stackSize, hintsOnly, 1, 0, 0); + for (int i = 1; i < layer - 1; i++) { + buildPiece(mName + "mid", stackSize, hintsOnly, 1, i, 0); + } + buildPiece(mName + "top", stackSize, hintsOnly, 1, layer - 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + if (!checkPiece(mName + "bottom", 1, 0, 0)) + return false; + int layer = 1; + while (checkPiece(mName + "mid", 1, layer, 0)) { + if (layer != mOutputHatches.size()) return false; + layer ++; + } + if (layer > 12 || !checkPiece(mName + "top", 1, layer, 0)) + return false; + return layer == mOutputHatches.size() && checkHatch(); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName()+(mUpgraded ? " T2" : ""), "MultiblockDisplay.png"); + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mMode == 0 ? GT_Recipe.GT_Recipe_Map.sDistillationRecipes : GT_Recipe.GT_Recipe_Map.sDistilleryRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a freaking tower, it won't work + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + if (this.mMode == 1) return CORE.ConfigSwitches.pollutionPerSecondMultiAdvDistillationTower_ModeDistillery; + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvDistillationTower_ModeDT; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mMode", mMode); + aNBT.setInteger("mCasingTier", this.mCasingTier); + aNBT.setBoolean("mUpgraded", mUpgraded); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mMode = aNBT.getByte("mMode"); + mCasingTier = aNBT.getInteger("mCasingTier"); + mUpgraded = aNBT.getBoolean("mUpgraded"); + super.loadNBTData(aNBT); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(203)); + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mMode++; + if (mMode > 1){ + mMode = 0; + PlayerUtils.messagePlayer(aPlayer, "Now running in Distillation Tower Mode."); + } + else { + PlayerUtils.messagePlayer(aPlayer, "Now running in Distillery Mode."); + } + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) return false; + FluidStack tLiquid = aLiquid.copy(); + for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) { + if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid) ? tHatch.outputsSteam() : tHatch.outputsLiquids()) { + if (tHatch.getBaseMetaTileEntity().getYCoord() == this.mControllerY + 1) { + int tAmount = tHatch.fill(tLiquid, false); + if (tAmount >= tLiquid.amount) { + return tHatch.fill(tLiquid, true) >= tLiquid.amount; + } else if (tAmount > 0) { + tLiquid.amount = tLiquid.amount - tHatch.fill(tLiquid, true); + } + } + } + } + return false; + } + + @Override + protected void addFluidOutputs(FluidStack[] mOutputFluids2) { + for (int i = 0; i < mOutputFluids2.length; i++) { + if (mOutputHatches.size() > i && mOutputHatches.get(i) != null && mOutputFluids2[i] != null && isValidMetaTileEntity(mOutputHatches.get(i))) { + if (mOutputHatches.get(i).getBaseMetaTileEntity().getYCoord() == this.mControllerY + 1 + i) { + mOutputHatches.get(i).fill(mOutputFluids2[i], true); + } + } + } + + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "DistillationTower"; + } + + @Override + public String getMachineType() { + return "Distillery, Distillation Tower"; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + // Run standard recipe handling for distillery recipes + if (mMode == 1) { + return this.checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 100); + } + else { + for (GT_MetaTileEntity_Hatch_Input hatch : mInputHatches) { + FluidStack tFluid = hatch.getFluid(); + if (tFluid != null) { + int para = (4* GT_Utility.getTier(this.getMaxInputVoltage())); + if (checkRecipeGeneric(null, new FluidStack[]{tFluid}, para,100, 250, 10000)) { + return true; + } + } + } + return false; + } + } + + @Override + public int getMaxParallelRecipes() { + if (this.mMode == 0) { + return getTierOfTower() == 1 ? 4 : getTierOfTower() == 2 ? 12 : 0; + } + else if (this.mMode == 1) { + return getTierOfTower() * (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + return 0; + } + + @Override + public int getEuDiscountForParallelism() { + return 15; + } + + private int getTierOfTower() { + return mUpgraded ? 2 : 1; + } + + private int mCasingTier = 0; + + private int getMachineCasingTier() { + return mCasingTier; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + + ITexture aOriginalTexture; + + // Check things exist client side (The worst code ever) + if (aBaseMetaTileEntity.getWorld() != null) { + + } + // Check the Tier Client Side + int aTier = mCasingTier; + + if (aTier == 0) { + aOriginalTexture = Textures.BlockIcons.getCasingTextureForId(49); + } + else if (aTier == 1) { + aOriginalTexture = Textures.BlockIcons.getCasingTextureForId(43); + } + else { + aOriginalTexture = Textures.BlockIcons.getCasingTextureForId(49); + } + + if (aSide == aFacing) { + return new ITexture[]{aOriginalTexture, new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER)}; + } + return new ITexture[]{aOriginalTexture}; + } + + private int getCasingTextureID() { + // Check the Tier Client Side + int aTier = mCasingTier; + + if (aTier == 1) { + return 49; + } + else if (aTier == 2) { + return 43; + } + else { + return 49; + } + } + + public boolean addToMachineList(IGregTechTileEntity aTileEntity) { + int aMaxTier = getMachineCasingTier(); + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock) { + GT_MetaTileEntity_TieredMachineBlock aMachineBlock = (GT_MetaTileEntity_TieredMachineBlock) aMetaTileEntity; + int aTileTier = aMachineBlock.mTier; + if (aTileTier > aMaxTier) { + Logger.INFO("Hatch tier too high."); + return false; + } + else { + return addToMachineList(aTileEntity, getCasingTextureID()); + } + } + else { + Logger.INFO("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. + return false; + } + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aTick % 20 == 0 && !mUpgraded) { + ItemStack aGuiStack = this.getGUIItemStack(); + if (aGuiStack != null) { + if (GT_Utility.areStacksEqual(aGuiStack, GregtechItemList.Distillus_Upgrade_Chip.get(1))) { + this.mUpgraded = true; + ItemUtils.depleteStack(aGuiStack); + } + } + } + // Silly Client Syncing + if (aBaseMetaTileEntity.isClientSide()) { + this.mCasingTier = getCasingTierOnClientSide(); + } + } + + + + @SideOnly(Side.CLIENT) + private final int getCasingTierOnClientSide() { + if (this == null || this.getBaseMetaTileEntity().getWorld() == null) { + return 0; + } + try { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + if (aBaseMetaTileEntity == null || aBaseMetaTileEntity.getWorld() == null || aBaseMetaTileEntity.getWorld().getChunkFromBlockCoords(aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getZCoord()) == null) { + return 0; + } + for (int i=1;i<10;i++) { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, i, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, i, 0); + if (aInitStructureCheck == null) { + continue; + } + if (aInitStructureCheck == GregTech_API.sBlockCasings4 && aInitStructureCheckMeta == 1) { + return 0; + } + else if (aInitStructureCheck == ModBlocks.blockCasingsTieredGTPP) { + return 1; + } + } + } + catch (Throwable t) { + //t.printStackTrace(); + } + return 0; + + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + aNBT.setBoolean("mUpgraded", mUpgraded); + super.setItemNBT(aNBT); + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java new file mode 100644 index 0000000000..ce54aef282 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java @@ -0,0 +1,484 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.List; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentTranslation; +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_Adv_EBF extends GregtechMeta_MultiBlockBase { + + public static int CASING_TEXTURE_ID; + public static String mHotFuelName = "Blazing Pyrotheum"; + public static String mCasingName = "Advanced Blast Furnace Casing"; + public static String mHatchName = "Pyrotheum Hatch"; + private IStructureDefinition<GregtechMetaTileEntity_Adv_EBF> STRUCTURE_DEFINITION = null; + private int mCasing; + private boolean mHaveHatch; + + private HeatingCoilLevel mHeatingCapacity; + private boolean isBussesSeparate = false; + + public GregtechMetaTileEntity_Adv_EBF(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 11); + mHotFuelName = FluidUtils.getFluidStack("pyrotheum", 1).getLocalizedName(); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 11); + mHatchName = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 968); + } + + public GregtechMetaTileEntity_Adv_EBF(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 11); + mHotFuelName = FluidUtils.getFluidStack("pyrotheum", 1).getLocalizedName(); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 11); + mHatchName = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 968); + } + + @Override + public String getMachineType() { + return "Blast Furnace"; + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_EBF(this.mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 11); + } + if (mHotFuelName.toLowerCase().contains(".")) { + mHotFuelName = FluidUtils.getFluidStack("pyrotheum", 1).getLocalizedName(); + } + if (mHatchName.toLowerCase().contains(".name")) { + mHatchName = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 968); + } + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Blast Furnace") + .addInfo("Speed: 120% | Eu Usage: 90% | Parallel: 8") + .addInfo("Consumes 10L of " + mHotFuelName + " per second during operation") + .addInfo("Constructed exactly the same as a normal EBF") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addController("Bottom center") + .addCasingInfo(mCasingName, 9) + .addInputHatch("Any Casing", 1) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addStructureHint(mHatchName, 1) + .addEnergyHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_EBF> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_EBF>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_Adv_EBF::addAdvEBFList, CASING_TEXTURE_ID, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings3Misc, 11 + ) + ) + ) + ) + .addElement( + 'H', + ofCoil( + GregtechMetaTileEntity_Adv_EBF::setCoilLevel, GregtechMetaTileEntity_Adv_EBF::getCoilLevel + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 3, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mHaveHatch = false; + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 3, 0) && mCasing >= 9 && mHaveHatch && getCoilLevel() != HeatingCoilLevel.None && checkHatch(); + } + + public final boolean addAdvEBFList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 968) { + mHaveHatch = true; + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, + boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID), + new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced) }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID) }; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ElectricBlastFurnace"; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sBlastRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + if (isBussesSeparate) { + FluidStack[] tFluids = getStoredFluids().toArray(new FluidStack[0]); + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tInputs = new ArrayList<>(); + if (isValidMetaTileEntity(tBus)) { + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) { + tInputs.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + } + if (tInputs.size() > 0) { + if (checkRecipeGeneric(tInputs.toArray(new ItemStack[0]), tFluids, 8, 90, 120, 10000)) { + return true; + } + } + } + return false; + } else { + return checkRecipeGeneric(8, 90, 120); + } + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvEBF; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, + int aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[] {}; + this.mOutputFluids = new FluidStack[] {}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + Logger.WARNING("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = this.getRecipeMap().findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + + Logger.WARNING("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null || this.mHeatingCapacity.getHeat() < tRecipe.mSpecialValue) { + Logger.WARNING("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + int tHeatCapacityDivTiers = (int) (mHeatingCapacity.getHeat() - tRecipe.mSpecialValue) / 900; + if (tHeatCapacityDivTiers > 0) + tRecipeEUt = (int) (tRecipeEUt * (Math.pow(0.95, tHeatCapacityDivTiers))); + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and + // considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + Logger.WARNING("Broke at " + parallelRecipes + "."); + break; + } + Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + "."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + Logger.WARNING("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + int tHalfHeatCapacityDivTiers = tHeatCapacityDivTiers / 2; + + this.mEUt = (int) Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + if (tHalfHeatCapacityDivTiers > 0) { + this.mMaxProgresstime = mMaxProgresstime / 4; + tHalfHeatCapacityDivTiers--; + } else { + this.mMaxProgresstime = mMaxProgresstime / 2; + } + if (this.mMaxProgresstime <= 1) { + break; + } + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) + tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.WARNING("GOOD RETURN - 1"); + return true; + + } + + private volatile int mGraceTimer = 2; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + //Try dry Pyrotheum after all other logic + if (this.mStartUpCheck < 0) { + if (this.mMaxProgresstime > 0 && this.mProgresstime != 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + if (aTick % 10 == 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + if (!this.depleteInput(FluidUtils.getFluidStack("pyrotheum", 5))) { + if (mGraceTimer-- == 0) { + this.causeMaintenanceIssue(); + this.stopMachine(); + mGraceTimer = 2; + } + } + } + } + } + + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + @Override + public int getEuDiscountForParallelism() { + return 90; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + isBussesSeparate = !isBussesSeparate; + aPlayer.addChatMessage(new ChatComponentTranslation(isBussesSeparate ? "interaction.separateBusses.enabled" : "interaction.separateBusses.disabled")); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("isBussesSeparate", isBussesSeparate); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + isBussesSeparate = aNBT.getBoolean("isBussesSeparate"); + super.loadNBTData(aNBT); + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java new file mode 100644 index 0000000000..56206f8178 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java @@ -0,0 +1,153 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import gregtech.api.enums.Dyes; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_FusionComputer; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; + +import java.lang.reflect.Method; + +public class GregtechMetaTileEntity_Adv_Fusion_MK4 extends GT_MetaTileEntity_FusionComputer { + + public static final Method mUpdateHatchTexture; + + static { + mUpdateHatchTexture = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); + } + + public GregtechMetaTileEntity_Adv_Fusion_MK4(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, 6); + } + + public GregtechMetaTileEntity_Adv_Fusion_MK4(String aName) { + super(aName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Fusion Reactor") + .addInfo("HARNESSING THE POWER OF A NEUTRON STAR") + .addSeparator() + .beginStructureBlock(15, 3, 15, false) + .addController("See diagram when placed") + .addCasingInfo("Fusion Machine Casings MK III", 79) + .addStructureInfo("Cover the coils with casing") + .addOtherStructurePart("Advanced Fusion Coils", "Center part of the ring") + .addEnergyHatch("1-16, Specified casings", 2) + .addInputHatch("2-16, Specified casings", 1) + .addOutputHatch("1-16, Specified casings", 3) + .addStructureInfo("ALL Hatches must be UHV or better") + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public int tier() { + return 9; + } + + @Override + public long maxEUStore() { + return (640010000L * 4) * (Math.min(16, this.mEnergyHatches.size())) / 8L; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_Fusion_MK4(mName); + } + + @Override + public Block getCasing() { + return getFusionCoil(); + } + + @Override + public int getCasingMeta() { + return 12; + } + + @Override + public Block getFusionCoil() { + return ModBlocks.blockCasings3Misc; + } + + @Override + public int getFusionCoilMeta() { + return 13; + } + + @Override + public int tierOverclock() { + return 8; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, + final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + ITexture[] sTexture; + if (aSide == aFacing) { + sTexture = new ITexture[]{ + new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, + Dyes.getModulation(-1, Dyes._NULL.mRGBa)), + new GT_RenderedTexture(this.getIconOverlay())}; + } else if (!aActive) { + sTexture = new ITexture[]{ + new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, + Dyes.getModulation(-1, Dyes._NULL.mRGBa))}; + } else { + sTexture = new ITexture[]{ + new GT_RenderedTexture(TexturesGtBlock.TEXTURE_CASING_FUSION_CASING_ULTRA, + Dyes.getModulation(-1, Dyes._NULL.mRGBa))}; + } + return sTexture; + } + + @Override + public ITexture getTextureOverlay() { + return new GT_RenderedTexture(this.mMaxProgresstime > 0 ? TexturesGtBlock.Casing_Machine_Screen_3 : TexturesGtBlock.Casing_Machine_Screen_1); + } + + public IIconContainer getIconOverlay() { + return this.mMaxProgresstime > 0 ? TexturesGtBlock.Casing_Machine_Screen_3 : TexturesGtBlock.Casing_Machine_Screen_1; + } + + public boolean turnCasingActive(final boolean status) { + try { + if (this.mEnergyHatches != null) { + for (final GT_MetaTileEntity_Hatch_Energy hatch : this.mEnergyHatches) { + mUpdateHatchTexture.invoke(hatch, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch2 : this.mOutputHatches) { + mUpdateHatchTexture.invoke(hatch2, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch3 : this.mInputHatches) { + mUpdateHatchTexture.invoke(hatch3, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + } + catch (Throwable t) { + return false; + } + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java new file mode 100644 index 0000000000..aff614184a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java @@ -0,0 +1,207 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.ItemList; +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.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.GregTech_API.sBlockCasings4; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_Adv_Implosion +extends GregtechMeta_MultiBlockBase { + + private String mCasingName; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_Adv_Implosion> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Adv_Implosion(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + mCasingName = ItemList.Casing_RobustTungstenSteel.get(1).getDisplayName(); + } + + public GregtechMetaTileEntity_Adv_Implosion(String aName) { + super(aName); + mCasingName = ItemList.Casing_RobustTungstenSteel.get(1).getDisplayName(); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_Implosion(this.mName); + } + + @Override + public String getMachineType() { + return "Implosion Compressor"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.contains("gt.blockcasings")) { + mCasingName = ItemList.Casing_RobustTungstenSteel.get(1).getDisplayName(); + } + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Implosion Compressor") + .addInfo("Speed: 100% | Eu Usage: 100% | Parallel: ((Tier/2)+1)") + .addInfo("Constructed exactly the same as a normal Implosion Compressor") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo(mCasingName, 10) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_Implosion> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_Implosion>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_Adv_Implosion::addAdvImplosionList, 48, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + sBlockCasings4, 0 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addAdvImplosionList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(48), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(48)}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ImplosionCompressor"; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sImplosionRecipes; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric((GT_Utility.getTier(this.getMaxInputVoltage())/2+1), 100, 100); + } + + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 20) { + GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(5)), 10, 1.0F, aX, aY, aZ); + } + } + + @Override + public String getSound() { + return (String) GregTech_API.sSoundList.get(Integer.valueOf(5)); + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvImplosion; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (GT_Utility.getTier(this.getMaxInputVoltage())/2+1); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java new file mode 100644 index 0000000000..3191f56889 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java @@ -0,0 +1,165 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.steam; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.GregTech_API.sBlockCasings1; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusInput; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusOutput; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_SteamMultiBase; +import net.minecraft.item.ItemStack; + +public class GregtechMetaTileEntity_SteamMacerator extends GregtechMeta_SteamMultiBase { + + private String mCasingName = "Bronze Plated Bricks"; + private IStructureDefinition<GregtechMetaTileEntity_SteamMacerator> STRUCTURE_DEFINITION = null; + private int mCasing; + + public GregtechMetaTileEntity_SteamMacerator(String aName) { + super(aName); + } + + public GregtechMetaTileEntity_SteamMacerator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { + return new GregtechMetaTileEntity_SteamMacerator(this.mName); + } + + @Override + protected GT_RenderedTexture getFrontOverlay() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR); + } + + @Override + protected GT_RenderedTexture getFrontOverlayActive() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR_ACTIVE); + } + + @Override + public String getMachineType() { + return "Macerator"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.contains("gt.blockcasings")) { + mCasingName = ItemList.Casing_BronzePlatedBricks.get(1).getDisplayName(); + } + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Steam Macerator") + .addInfo("Macerates " + getMaxParallelRecipes() + " ores at a time") + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo(mCasingName, 14) + .addStructureHint("Input Bus (Steam)", 1) + .addStructureHint("Output Bus (Steam)", 1) + .addStructureHint("Steam Hatch", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SteamMacerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SteamMacerator>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_SteamMacerator::addSteamMaceratorList, 10, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + sBlockCasings1, 10 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addSteamMaceratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase && aMetaTileEntity.getBaseMetaTileEntity().getMetaTileID() == 31040){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusOutput){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + fixAllMaintenanceIssue(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 14; + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; + } + + @Override + public ItemStack[] getOutputItems(GT_Recipe aRecipe) { + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[1]; + for (int h = 0; h < 1; h++) { + if (aRecipe.getOutput(h) != null) { + tOutputItems[h] = aRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + return tOutputItems; + } + + @Override + public int getOutputCount(ItemStack[] aOutputs) { + return 1; + } + + + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java new file mode 100644 index 0000000000..eae51e5c1d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java @@ -0,0 +1,656 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.lang.reflect.Field; +import java.util.ArrayList; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_Utility; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.helpers.CraftingHelper; +import gtPlusPlus.xmod.gregtech.common.helpers.autocrafter.AC_Helper_Utils; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GT4Entity_AutoCrafter extends GregtechMeta_MultiBlockBase { + + private MODE mMachineMode = MODE.ASSEMBLY; + private byte mTier = 1; + protected GT_Recipe mLastRecipeToBuffer; + private int mCasing; + private IStructureDefinition<GT4Entity_AutoCrafter> STRUCTURE_DEFINITION = null; + + /** The crafting matrix inventory (3x3). */ + public CraftingHelper mInventoryCrafter; + + public static enum MODE { + CRAFTING("CIRCUIT", "ASSEMBLY"), ASSEMBLY("CRAFTING", "DISASSEMBLY"), DISASSEMBLY("ASSEMBLY", "CIRCUIT"), CIRCUIT("DISASSEMBLY", "CRAFTING"); + + private final String lastMode; + private final String nextMode; + + MODE(String previous, String next) { + this.lastMode = previous; + this.nextMode = next; + } + + public MODE nextMode() { + return MODE.valueOf(this.nextMode); + } + + public MODE lastMode() { + return MODE.valueOf(this.lastMode); + } + + } + + public void onRightclick(EntityPlayer aPlayer) { + } + + public GT4Entity_AutoCrafter(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT4Entity_AutoCrafter(String mName) { + super(mName); + } + + @Override + public String getMachineType() { + String sType = "Assembler, Disassembler, "+((CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && !CORE.GTNH) ? "Circuit Assembler" : ""); + return sType; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_AutoCrafter(this.mName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + return super.onRunningTick(aStack); + //return true; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAutoCrafter; + } + + public int getAmountOfOutputs() { + return 1; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Highly Advanced Autocrafter") + .addInfo("Right Click with a Screwdriver to change mode") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Processes two items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Autocrafter Frame", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, + final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.getIndexFromPage(0, 10)), + new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE + : Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER) }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.getIndexFromPage(0, 10)) }; + } + + @Override + public IStructureDefinition<GT4Entity_AutoCrafter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GT4Entity_AutoCrafter>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GT4Entity_AutoCrafter::addAutoCrafterList, TAE.getIndexFromPage(0, 10), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 12 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + if (checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch()) { + setTier(); + return true; + } else return false; + } + + public final boolean addAutoCrafterList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + private static GT_Recipe_Map fCircuitMap; + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (this.mMachineMode == MODE.ASSEMBLY) { + return GT_Recipe.GT_Recipe_Map.sAssemblerRecipes; + } + else if (this.mMachineMode == MODE.CIRCUIT && !CORE.GTNH) { + if (fCircuitMap != null) { + return fCircuitMap; + } + GT_Recipe_Map r; + try { + Field f = ReflectionUtils.getField(GT_Recipe.GT_Recipe_Map.class, "sCircuitAssemblerRecipes"); + if (f != null) { + r = (GT_Recipe_Map) f.get(null); + if (r != null) { + fCircuitMap = r; + return r; + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + } + } + else if (this.mMachineMode == MODE.DISASSEMBLY || this.mMachineMode == MODE.CRAFTING) { + return null; + } + return GT_Recipe.GT_Recipe_Map.sAssemblerRecipes; + } + + private boolean isModernGT = true; + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (isModernGT && !CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + isModernGT = false; + } + //5.09 support + if (isModernGT && !CORE.GTNH) { + mMachineMode = mMachineMode.nextMode(); + if (mMachineMode == MODE.CRAFTING) { + PlayerUtils.messagePlayer(aPlayer, "Running the Auto-Crafter in mode: "+EnumChatFormatting.AQUA+"AutoCrafting"); + } else if (mMachineMode == MODE.ASSEMBLY) { + PlayerUtils.messagePlayer(aPlayer, "Running the Auto-Crafter in mode: "+EnumChatFormatting.GREEN+"Assembly"); + } else if (mMachineMode == MODE.DISASSEMBLY) { + PlayerUtils.messagePlayer(aPlayer, "Running the Auto-Crafter in mode: "+EnumChatFormatting.RED+"Disassembly"); + } else { + PlayerUtils.messagePlayer(aPlayer, "Running the Auto-Crafter in mode: "+EnumChatFormatting.YELLOW+"Circuit Assembly"); + } + } + //5.08 support + else { + if (mMachineMode.nextMode() == MODE.CIRCUIT) { + mMachineMode = MODE.ASSEMBLY; + } + else if (mMachineMode.nextMode() == MODE.CRAFTING) { + mMachineMode = MODE.ASSEMBLY; + } + else { + mMachineMode = mMachineMode.nextMode(); + } + + if (mMachineMode == MODE.CRAFTING) { + PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: "+EnumChatFormatting.AQUA+"AutoCrafting"); + } else if (mMachineMode == MODE.ASSEMBLY) { + PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: "+EnumChatFormatting.GREEN+"Assembly"); + } else { + PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: "+EnumChatFormatting.RED+"Disassembly"); + } + } + } + +// @Override +// public boolean checkRecipe(final ItemStack aStack) { +// +// final long tVoltage = this.getMaxInputVoltage(); +// final byte tTier = this.mTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); +// +// if (mMachineMode == MODE.DISASSEMBLY) { +// return doDisassembly(); +// } else if (mMachineMode == MODE.CRAFTING) { +// return doCrafting(aStack); +// } else { +// return super.checkRecipeGeneric(getMaxParallelRecipes(), 100, 200); +// } +// } + + private void setTier() { + long tVoltage = getMaxInputVoltage(); + this.mTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + if (mMachineMode == MODE.DISASSEMBLY) { + return doDisassembly(); + } else if (mMachineMode == MODE.CRAFTING) { + return doCrafting(aStack); + } else { + ArrayList<FluidStack> tFluids = getStoredFluids(); + //Logger.MACHINE_INFO("1"); + for (GT_MetaTileEntity_Hatch_InputBus tBus : mInputBusses) { + ArrayList<ItemStack> tBusItems = new ArrayList<ItemStack>(); + //Logger.MACHINE_INFO("2"); + if (isValidMetaTileEntity(tBus)) { + //Logger.MACHINE_INFO("3"); + for (int i = tBus.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tBus.getBaseMetaTileEntity().getStackInSlot(i) != null) + tBusItems.add(tBus.getBaseMetaTileEntity().getStackInSlot(i)); + } + } + + Object[] tempArray = tFluids.toArray(new FluidStack[] {}); + FluidStack[] properArray; + properArray = ((tempArray != null && tempArray.length > 0) ? (FluidStack[]) tempArray : new FluidStack[] {}); + + //Logger.MACHINE_INFO("4"); + if (checkRecipeGeneric(tBusItems.toArray(new ItemStack[]{}), properArray, + getMaxParallelRecipes(), 100, 200, 10000)) return true; + } + return false; + } + } + + @Override + public int getMaxParallelRecipes() { + return 2 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + public boolean doDisassembly() { + + final ArrayList<ItemStack> tInputList = this.getStoredInputs(); + for (int tInputList_sS = tInputList.size(), i = 0; i < tInputList_sS - 1; ++i) { + for (int j = i + 1; j < tInputList_sS; ++j) { + if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { + if (tInputList.get(i).stackSize < tInputList.get(j).stackSize) { + tInputList.remove(i--); + tInputList_sS = tInputList.size(); + break; + } + tInputList.remove(j--); + tInputList_sS = tInputList.size(); + } + } + } + final ItemStack[] tInputs = tInputList.toArray(new ItemStack[tInputList.size()]); + + ItemStack inputItem = tInputs[0]; + if (tInputs[0].stackSize <= 0) { + tInputs[0] = null; + this.updateSlots(); + } + int outputSlots = this.mOutputBusses.get(0).getSizeInventory(); + + if (this.mOutputBusses.size() > 1) { + outputSlots = 0; + for (GT_MetaTileEntity_Hatch_OutputBus r : this.mOutputBusses) { + outputSlots += r.getSizeInventory(); + } + } + + this.mOutputItems = new ItemStack[outputSlots]; + if (inputItem != null && inputItem.stackSize > 0) { + NBTTagCompound tNBT = inputItem.getTagCompound(); + if (tNBT != null) { + tNBT = tNBT.getCompoundTag("GT.CraftingComponents"); + if (tNBT != null) { + this.mEUt = 16 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + this.mMaxProgresstime = (100 - (8 * this.mTier)); + for (int i = 0; i < this.mOutputItems.length; ++i) { + if (this.getBaseMetaTileEntity().getRandomNumber(100) < 60 + 12 * this.mTier) { + this.mOutputItems[i] = GT_Utility.loadItem(tNBT, "Ingredient." + i); + if (this.mOutputItems[i] != null) { + this.mMaxProgresstime *= (int) 1.5; + } + } + } + + if (this.mTier > 5) { + this.mMaxProgresstime >>= this.mTier - 5; + } + if (this.mEUt > 0) + this.mEUt = (-this.mEUt); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + inputItem.stackSize--; + if (inputItem.stackSize <= 0) { + tInputs[0] = null; + } + this.updateSlots(); + return true; + + } + } + } + return false; + } + + private boolean doesCrafterHave9SlotInput() { + GT_MetaTileEntity_Hatch_InputBus craftingInput = null; + if (!this.mInputBusses.isEmpty()) { + for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses) { + if (x.mInventory.length == 9) { + craftingInput = x; + } + } + } + // Return if no input hatch set. + if (craftingInput == null) { + Logger.WARNING("Cannot do Auto-Crafting without a 9-slot Input Bus [MV]."); + return false; + + } else { + return true; + } + } + + private boolean doCrafting(ItemStack aStack) { + this.mMaxProgresstime = 0; + return false; // do nothing + /* + try { + // Set Crafting input hatch + if (!doesCrafterHave9SlotInput()) { + return false; + } + + // Read stored data from encrypted data stick. + ItemStack storedData_Output[] = NBTUtils.readItemsFromNBT(aStack, "Output"); + ItemStack storedData_Input[] = NBTUtils.readItemsFromNBT(aStack); + if (storedData_Output != null && storedData_Input != null) { + ItemStack loadedData[] = new ItemStack[9]; + if (storedData_Input.length >= 1) { + int number = 0; + for (ItemStack a : storedData_Input) { + if (a.getItem() == ModItems.ZZZ_Empty) { + // Utils.LOG_WARNING("Allocating free memory into crafting manager slot + // "+number+"."); + loadedData[number] = null; + } else { + // Utils.LOG_WARNING("Downloading "+a.getDisplayName()+" into crafting manager + // slot "+number+"."); + loadedData[number] = a; + } + number++; + } + } + + // Remove inputs here + ArrayList<ItemStack> mInputArray = new ArrayList<ItemStack>(); + ItemStack allInputs[]; + + for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses) { + if (x.mInventory.length > 0) { + for (ItemStack r : x.mInventory) { + if (r != null) { + mInputArray.add(r); + } + } + } + } + + if (mInputArray.isEmpty()) { + return false; + } else { + List<ItemStack> list = mInputArray; + allInputs = list.toArray(new ItemStack[list.size()]); + + if (allInputs != null && allInputs.length > 0) { + + this.mEUt = 8 * (1 << this.mTier - 1) * (1 << this.mTier - 1); + this.mMaxProgresstime = MathUtils.roundToClosestInt((50 - (5 + * MathUtils.randDouble(((this.mTier - 2) <= 0 ? 1 : (this.mTier - 2)), this.mTier)))); + + Logger.WARNING("MPT: " + mMaxProgresstime + " | " + mEUt); + this.getBaseMetaTileEntity().setActive(true); + + // Setup some vars + int counter = 0; + + ItemStack toUse[] = new ItemStack[9]; + + outerloop: for (ItemStack inputItem : loadedData) { + if (inputItem == null) { + toUse[counter] = null; + continue outerloop; + } + for (ItemStack r : allInputs) { + if (r != null) { + // Utils.LOG_WARNING("Input Bus Inventory Iteration - Found:" + // +r.getDisplayName()+" | "+allInputs.length); + if (GT_Utility.areStacksEqual(r, inputItem)) { + if (this.getBaseMetaTileEntity().isServerSide()) { + toUse[counter] = inputItem; + counter++; + continue outerloop; + } + + } + } + } + counter++; + } + + int mCorrectInputs = 0; + for (ItemStack isValid : toUse) { + if (isValid == null || this.depleteInput(isValid)) { + mCorrectInputs++; + } else { + Logger.WARNING("Input in Slot " + mCorrectInputs + " was not valid."); + } + } + + if (this.mTier > 5) { + this.mMaxProgresstime >>= this.mTier - 5; + } + if (this.mEUt > 0) + this.mEUt = (-this.mEUt); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + if (mCorrectInputs == 9) { + ItemStack mOutputItem = storedData_Output[0]; + NBTUtils.writeItemsToGtCraftingComponents(mOutputItem, loadedData, true); + this.addOutput(mOutputItem); + this.updateSlots(); + return true; + } else { + return false; + } + + } + } + } + } + // End Debug + catch (Throwable t) { + t.printStackTrace(); + this.mMaxProgresstime = 0; + } + + this.mMaxProgresstime = 0; + return false; + */ + } + + @Override + public String[] getExtraInfoData() { + final String tRunning = (this.mMaxProgresstime > 0 ? "Auto-Crafter running" : "Auto-Crafter stopped"); + final String tMaintainance = (this.getIdealStatus() == this.getRepairStatus() ? "No Maintainance issues" + : "Needs Maintainance"); + String tSpecialText = "" + (60 + 12 * this.mTier) + "% chance to recover disassembled parts."; + String tMode; + if (mMachineMode == MODE.DISASSEMBLY) { + tMode = "§cDisassembly"; + tSpecialText = "" + (60 + 12 * this.mTier) + "% chance to recover disassembled parts."; + } else if (mMachineMode == MODE.ASSEMBLY || mMachineMode == MODE.CIRCUIT) { + tMode = mMachineMode == MODE.ASSEMBLY ? "§aAssembly" : "§eCircuit Assembly"; + if (mLastRecipeToBuffer != null && mLastRecipeToBuffer.mOutputs[0].getDisplayName() != null) { + tSpecialText = "Currently processing: " + mLastRecipeToBuffer.mOutputs[0].getDisplayName(); + } else { + tSpecialText = "Currently processing: Nothing"; + } + } else { + tMode = "§dAuto-Crafting"; + tSpecialText = "Does Auto-Crafter have 9-slot input bus? " + doesCrafterHave9SlotInput(); + } + + return new String[] { "Large Scale Auto-Asesembler v1.01c", tRunning, tMaintainance, "Mode: " + tMode, + tSpecialText }; + } + + private String getMode() { + return this.mMachineMode.name(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + String mMode = getMode(); + aNBT.setString("mMode", mMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + String modeString = aNBT.getString("mMode"); + MODE newMode = MODE.valueOf(modeString); + this.mMachineMode = newMode; + super.loadNBTData(aNBT); + } + + @Override + public void explodeMultiblock() { + AC_Helper_Utils.removeCrafter(this); + super.explodeMultiblock(); + } + + @Override + public void onExplosion() { + AC_Helper_Utils.removeCrafter(this); + super.onExplosion(); + } + + @Override + public void onRemoval() { + AC_Helper_Utils.removeCrafter(this); + super.onRemoval(); + } + + @Override + public void doExplosion(long aExplosionPower) { + AC_Helper_Utils.removeCrafter(this); + super.doExplosion(aExplosionPower); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "Generic3By3"; + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java new file mode 100644 index 0000000000..65474d38ed --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java @@ -0,0 +1,354 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.*; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.general.ItemLavaFilter; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GT4Entity_ThermalBoiler +extends GregtechMeta_MultiBlockBase +{ + private int mCasing; + private IStructureDefinition<GT4Entity_ThermalBoiler> STRUCTURE_DEFINITION = null; + private int mSuperEfficencyIncrease = 0; + + public void onRightclick(EntityPlayer aPlayer) + { + getBaseMetaTileEntity().openGUI(aPlayer, 158); + } + + public GT4Entity_ThermalBoiler(int aID, String aName, String aNameRegional) + { + super(aID, aName, aNameRegional); + } + + public GT4Entity_ThermalBoiler(String mName) { + super(mName); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) + { + return new GT4Entity_ThermalBoiler(this.mName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) + { + return true; + } + + @Override + public String getMachineType() { + return "Boiler"; + } + + @Override + public int getDamageToComponent(ItemStack aStack){ + //log("Trying to damage component."); + return ItemList.Component_LavaFilter.get(1L).getClass().isInstance(aStack) ? 1 : 0; + } + + private static Item mLavaFilter; + + @Override + public boolean checkRecipe(ItemStack aStack) { + this.mSuperEfficencyIncrease=0; + + if (mLavaFilter == null) { + mLavaFilter = ItemList.Component_LavaFilter.getItem(); + } + + //Try reload new Lava Filter + if (aStack == null) { + ItemStack uStack = this.findItemInInventory(mLavaFilter); + if (uStack != null) { + this.setGUIItemStack(uStack); + aStack = this.getGUIItemStack(); + } + } + + + for (GT_Recipe tRecipe : GTPP_Recipe.GTPP_Recipe_Map.sThermalFuels.mRecipeList) { + FluidStack tFluid = tRecipe.mFluidInputs[0]; + if (tFluid != null) { + if (depleteInput(tFluid)) { + this.mMaxProgresstime = Math.max(1, runtimeBoost(tRecipe.mSpecialValue * 2)); + this.mEUt = getEUt(); + this.mEfficiencyIncrease = (this.mMaxProgresstime * getEfficiencyIncrease()); + + int loot_MAXCHANCE = 100000; + if (mLavaFilter.getClass().isInstance(aStack.getItem())) { + + if ((tRecipe.getOutput(0) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(0))) { + this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(0) }) }; + } + if ((tRecipe.getOutput(1) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(1))) { + this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(1) }) }; + } + if ((tRecipe.getOutput(2) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(2))) { + this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(2) }) }; + } + if ((tRecipe.getOutput(3) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(3))) { + this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(3) }) }; + } + if ((tRecipe.getOutput(4) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(4))) { + this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(4) }) }; + } + if ((tRecipe.getOutput(5) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(5))) { + this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(5) }) }; + } + + } + //Give Obsidian without Lava Filter + if (tFluid.isFluidEqual(GT_ModHandler.getLava(86))){ + if ((tRecipe.getOutput(6) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(6))) { + this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(6) }) }; + } + } + + + return true; + } + } + } + this.mMaxProgresstime = 0; + this.mEUt = 0; + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.mEUt > 0) { + if(this.mSuperEfficencyIncrease>0){ + this.mEfficiency = Math.min(10000, this.mEfficiency + this.mSuperEfficencyIncrease); + } + int tGeneratedEU = (int) (this.mEUt * 2L * this.mEfficiency / 10000L); + if (tGeneratedEU > 0) { + long amount = (tGeneratedEU + 160) / 160; + if (depleteInput(Materials.Water.getFluid(amount)) || depleteInput(GT_ModHandler.getDistilledWater(amount))) { + addOutput(GT_ModHandler.getSteam(tGeneratedEU)); + } else { + explodeMultiblock(); + } + } + return true; + } + return true; + } + + public int getEUt() { + return 400; + } + + public int getEfficiencyIncrease() { + return 12; + } + + int runtimeBoost(int mTime) { + return mTime * 150 / 100; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) + { + return false; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) + { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) + { + return CORE.ConfigSwitches.pollutionPerSecondMultiThermalBoiler; + } + + public int getAmountOfOutputs() + { + return 7; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Thermal Boiler Controller") + .addInfo("Converts Water & Heat into Steam") + .addInfo("Consult user manual for more information") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Thermal Containment Casings", 10) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(1)), + new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(1))}; + } + + @Override + public IStructureDefinition<GT4Entity_ThermalBoiler> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GT4Entity_ThermalBoiler>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GT4Entity_ThermalBoiler::addThermalBoilerList, TAE.getIndexFromPage(0, 1), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 11 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + public final boolean addThermalBoilerList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public void damageFilter(){ + ItemStack filter = this.mInventory[1]; + if (filter != null){ + if (filter.getItem() instanceof ItemLavaFilter){ + + long currentUse = ItemLavaFilter.getFilterDamage(filter); + + //Remove broken Filter + if (currentUse >= 100-1){ + this.mInventory[1] = null; + } + else { + //Do Damage + ItemLavaFilter.setFilterDamage(filter, currentUse+1); + } + } + } + + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()){ + // Reload Lava Filter + if (this.getGUIItemStack() == null) { + if (this.mInputBusses.size() > 0) { + for (GT_MetaTileEntity_Hatch_InputBus aBus : this.mInputBusses) { + for (ItemStack aStack : aBus.mInventory) { + if (aStack != null && aStack.getItem() instanceof ItemLavaFilter) { + this.setGUIItemStack(aStack); + } + } + } + } + } + + if (this.mEUt > 0){ + if (aTick % 600L == 0L){ + damageFilter(); + } + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "Generic3By3"; + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java new file mode 100644 index 0000000000..326cc01de7 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java @@ -0,0 +1,744 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.Triplet; +import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ElementalDataOrbHolder; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMTE_ElementalDuplicator extends GregtechMeta_MultiBlockBase { + + private int mSolidCasingTier = 0; + private int mMachineCasingTier = 0; + private int mPipeCasingTier = 0; + private int mCoilTier = 0; + private int checkCoil; + private int[] checkCasing = new int[8]; + private int checkMachine; + private int checkPipe; + private int maxTierOfHatch; + private int mCasing; + private IStructureDefinition<GregtechMTE_ElementalDuplicator> STRUCTURE_DEFINITION = null; + + private ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder> mReplicatorDataOrbHatches = new ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder>(); + + private static final HashMap<Integer, Triplet<Block, Integer, Integer>> mTieredBlockRegistry = new HashMap<Integer, Triplet<Block, Integer, Integer>>(); + + public GregtechMTE_ElementalDuplicator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_ElementalDuplicator(final String aName) { + super(aName); + } + + public static boolean registerMachineCasingForTier(int aTier, Block aBlock, int aMeta, int aCasingTextureID) { + int aSize = mTieredBlockRegistry.size(); + int aSize2 = aSize; + Triplet<Block, Integer, Integer> aCasingData = new Triplet<Block, Integer, Integer>(aBlock, aMeta, aCasingTextureID); + if (mTieredBlockRegistry.containsKey(aTier)) { + CORE.crash("Tried to register a Machine casing for tier "+aTier+" to the Chemical Plant, however this tier already contains one."); + } + mTieredBlockRegistry.put(aTier, aCasingData); + aSize = mTieredBlockRegistry.size(); + return aSize > aSize2; + } + + private static int getCasingTextureIdForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return 10; + } + int aCasingID = mTieredBlockRegistry.get(aTier).getValue_3(); + //Logger.INFO("Found casing texture ID "+aCasingID+" for tier "+aTier); + return aCasingID; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_ElementalDuplicator(this.mName); + } + + @Override + public String getMachineType() { + return "Replicator"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Replication Machine") + .addInfo("Now replication is less painful") + .addInfo("Please read to user manual for more information on construction & usage") + .addSeparator() + .addController("Bottom Center") + .addStructureHint("Catalyst Housing", 1) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addOutputHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + public void setMachineMeta(int meta) { + checkMachine = meta; + } + + public int getMachineMeta() { + return checkMachine; + } + + public void setPipeMeta(int meta) { + checkPipe = meta; + } + + public int getPipeMeta() { + return checkPipe; + } + + public void setCoilMeta(int meta) { + checkCoil = meta; + } + + public int getCoilMeta() { + return checkCoil; + } + + public int coilTier(int meta) { + switch (meta) { + case 0: return 1; + case 1: return 2; + case 2: return 3; + case 3: return 4; + case 4: return 5; + case 5: return 7; + case 6: return 8; + case 7: return 10; + case 8: return 11; + case 9: return 6; + case 10: return 9; + } + return 0; + } + + @Override + public IStructureDefinition<GregtechMTE_ElementalDuplicator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_ElementalDuplicator>builder() + .addShape(mName, transpose(new String[][]{ + {"XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX"}, + {"X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X"}, + {"X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X"}, + {"X X", " ", " HHH ", " HHH ", " HHH ", " ", "X X"}, + {"X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X"}, + {"X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X"}, + {"CCC~CCC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CCCCCCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMTE_ElementalDuplicator::addChemicalPlantList, getCasingTextureID(), 1 + ), + onElementPass( + x -> {++x.checkCasing[0]; ++x.mCasing;}, + ofSolidCasing(0) + ), + onElementPass( + x -> {++x.checkCasing[1]; ++x.mCasing;}, + ofSolidCasing(1) + ), + onElementPass( + x -> {++x.checkCasing[2]; ++x.mCasing;}, + ofSolidCasing(2) + ), + onElementPass( + x -> {++x.checkCasing[3]; ++x.mCasing;}, + ofSolidCasing(3) + ), + onElementPass( + x -> {++x.checkCasing[4]; ++x.mCasing;}, + ofSolidCasing(4) + ), + onElementPass( + x -> {++x.checkCasing[5]; ++x.mCasing;}, + ofSolidCasing(5) + ), + onElementPass( + x -> {++x.checkCasing[6]; ++x.mCasing;}, + ofSolidCasing(6) + ), + onElementPass( + x -> {++x.checkCasing[7]; ++x.mCasing;}, + ofSolidCasing(7) + ) + ) + ) + .addElement( + 'X', + ofChain( + onElementPass( + x -> {++x.checkCasing[0]; ++x.mCasing;}, + ofSolidCasing(0) + ), + onElementPass( + x -> {++x.checkCasing[1]; ++x.mCasing;}, + ofSolidCasing(1) + ), + onElementPass( + x -> {++x.checkCasing[2]; ++x.mCasing;}, + ofSolidCasing(2) + ), + onElementPass( + x -> {++x.checkCasing[3]; ++x.mCasing;}, + ofSolidCasing(3) + ), + onElementPass( + x -> {++x.checkCasing[4]; ++x.mCasing;}, + ofSolidCasing(4) + ), + onElementPass( + x -> {++x.checkCasing[5]; ++x.mCasing;}, + ofSolidCasing(5) + ), + onElementPass( + x -> {++x.checkCasing[6]; ++x.mCasing;}, + ofSolidCasing(6) + ), + onElementPass( + x -> {++x.checkCasing[7]; ++x.mCasing;}, + ofSolidCasing(7) + ) + ) + ) + .addElement( + 'M', + addTieredBlock( + GregTech_API.sBlockCasings1, GregtechMTE_ElementalDuplicator::setMachineMeta, GregtechMTE_ElementalDuplicator::getMachineMeta, 10 + ) + ) + .addElement( + 'H', + addTieredBlock( + GregTech_API.sBlockCasings5, GregtechMTE_ElementalDuplicator::setCoilMeta, GregtechMTE_ElementalDuplicator::getCoilMeta, 11 + ) + ) + .addElement( + 'P', + addTieredBlock( + GregTech_API.sBlockCasings2, GregtechMTE_ElementalDuplicator::setPipeMeta, GregtechMTE_ElementalDuplicator::getPipeMeta, 12, 16 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public static <T> IStructureElement<T> ofSolidCasing(int aIndex) { + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + Block target = mTieredBlockRegistry.get(aIndex).getValue_1(); + int targetMeta = mTieredBlockRegistry.get(aIndex).getValue_2(); + return target.equals(block) && meta == targetMeta; + } + + int getIndex(int size) { + if (size > 8) size = 8; + return size - 1; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2()); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock(x, y, z, mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2(), 3); + } + }; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 3, 6, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + for (int i = 0; i < 8; i++) { + checkCasing[i] = 0; + } + checkCoil = 0; + checkPipe = 0; + checkMachine = 0; + mSolidCasingTier = 0; + mMachineCasingTier = 0; + mPipeCasingTier = 0; + mCoilTier = 0; + mReplicatorDataOrbHatches.clear(); + if (checkPiece(mName, 3, 6, 0) && mCasing >= 80) { + for (int i = 0; i < 8; i++) { + if (checkCasing[i] == mCasing) { + mSolidCasingTier = i; + } + else if (checkCasing[i] > 0) + return false; + } + mMachineCasingTier = checkMachine - 1; + mPipeCasingTier = checkPipe - 12; + mCoilTier = coilTier(checkCoil - 1); + updateHatchTexture(); + return mMachineCasingTier >= maxTierOfHatch; + } + return false; + } + + public void updateHatchTexture() { + for (GT_MetaTileEntity_Hatch h : mReplicatorDataOrbHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mInputBusses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mMaintenanceHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mEnergyHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mOutputBusses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mInputHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mOutputHatches) h.updateTexture(getCasingTextureID()); + } + + public final boolean addChemicalPlantList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_ElementalDataOrbHolder){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + + ITexture aOriginalTexture; + + // Check things exist client side (The worst code ever) + if (aBaseMetaTileEntity.getWorld() != null) { + + } + int aCasingID = getCasingTextureID(); + aOriginalTexture = Textures.BlockIcons.getCasingTextureForId(aCasingID); + + if (aSide == aFacing) { + return new ITexture[]{aOriginalTexture, new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{aOriginalTexture}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList.size() == 0) { + generateRecipes(); + } + return GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT; + } + + public static void generateRecipes() { + for (GT_Recipe i : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlantRecipes.mRecipeList) { + GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.add(i); + } + } + + @Override + public int getMaxParallelRecipes() { + return 2 * getPipeCasingTier(); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + private int getSolidCasingTier() { + return this.mSolidCasingTier; + } + + private int getMachineCasingTier() { + return mMachineCasingTier; + } + + private int getPipeCasingTier() { + return mPipeCasingTier; + } + + private int getCasingTextureID() { + // Check the Tier Client Side + int aTier = mSolidCasingTier; + int aCasingID = getCasingTextureIdForTier(aTier); + return aCasingID; + } + + public boolean addToMachineList(IGregTechTileEntity aTileEntity) { + int aMaxTier = getMachineCasingTier(); + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock) { + GT_MetaTileEntity_TieredMachineBlock aMachineBlock = (GT_MetaTileEntity_TieredMachineBlock) aMetaTileEntity; + int aTileTier = aMachineBlock.mTier; + if (aTileTier > aMaxTier) { + log("Hatch tier too high."); + return false; + } + else { + return addToMachineList(aTileEntity, getCasingTextureID()); + } + } + else { + log("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. + return false; + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mSolidCasingTier", this.mSolidCasingTier); + aNBT.setInteger("mMachineCasingTier", this.mMachineCasingTier); + aNBT.setInteger("mPipeCasingTier", this.mPipeCasingTier); + aNBT.setInteger("mCoilTier", this.mCoilTier); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mSolidCasingTier = aNBT.getInteger("mSolidCasingTier"); + mMachineCasingTier = aNBT.getInteger("mMachineCasingTier"); + mPipeCasingTier = aNBT.getInteger("mPipeCasingTier"); + mCoilTier = aNBT.getInteger("mCoilTier"); + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_ElementalDataOrbHolder) { + log("Found GT_MetaTileEntity_Hatch_ElementalDataOrbHolder"); + ((GT_MetaTileEntity_Hatch_ElementalDataOrbHolder) aTileEntity).mRecipeMap = getRecipeMap(); + return addToMachineListInternal(mReplicatorDataOrbHatches, aMetaTileEntity, aBaseCasingIndex); + } + return super.addToMachineList(aTileEntity, aBaseCasingIndex); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 100; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + // Same speed bonus as pyro oven + public int getSpeedBonus() { + return 50 * (this.mCoilTier - 2); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mReplicatorDataOrbHatches.clear(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), getSpeedBonus()); + } + + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, FluidStack[] aFluidInputs, + int aMaxParallelRecipes, int aEUPercent, + int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe, boolean isOC) { + return false; + } + + private static final HashMap<Long, AutoMap<GT_Recipe>> mTieredRecipeMap = new HashMap<Long, AutoMap<GT_Recipe>>(); + private static final AutoMap<GT_Recipe> aTier0Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier1Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier2Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier3Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier4Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier5Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier6Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier7Recipes = new AutoMap<GT_Recipe>(); + private static boolean mInitRecipeCache = false; + + private static void initRecipeCaches() { + if (!mInitRecipeCache) { + mTieredRecipeMap.put((long) 0, aTier0Recipes); + mTieredRecipeMap.put((long) 1, aTier1Recipes); + mTieredRecipeMap.put((long) 2, aTier2Recipes); + mTieredRecipeMap.put((long) 3, aTier3Recipes); + mTieredRecipeMap.put((long) 4, aTier4Recipes); + mTieredRecipeMap.put((long) 5, aTier5Recipes); + mTieredRecipeMap.put((long) 6, aTier6Recipes); + mTieredRecipeMap.put((long) 7, aTier7Recipes); + for (GT_Recipe aRecipe : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList) { + if (aRecipe != null) { + switch (aRecipe.mSpecialValue) { + case 0: + aTier0Recipes.add(aRecipe); + continue; + case 1: + aTier1Recipes.add(aRecipe); + continue; + case 2: + aTier2Recipes.add(aRecipe); + continue; + case 3: + aTier3Recipes.add(aRecipe); + continue; + case 4: + aTier4Recipes.add(aRecipe); + continue; + case 5: + aTier5Recipes.add(aRecipe); + continue; + case 6: + aTier6Recipes.add(aRecipe); + continue; + case 7: + aTier7Recipes.add(aRecipe); + continue; + } + } + } + mInitRecipeCache = true; + } + } + + private static boolean areInputsEqual(GT_Recipe aComparator, ItemStack[] aInputs, FluidStack[] aFluids) { + int aInputCount = aComparator.mInputs.length; + if (aInputCount > 0) { + //Logger.INFO("Looking for recipe with "+aInputCount+" Items"); + int aMatchingInputs = 0; + recipe : for (ItemStack a : aComparator.mInputs) { + for (ItemStack b : aInputs) { + if (a.getItem() == b.getItem()) { + if (a.getItemDamage() == b.getItemDamage()) { + //Logger.INFO("Found matching Item Input - "+b.getUnlocalizedName()); + aMatchingInputs++; + continue recipe; + } + } + } + } + if (aMatchingInputs != aInputCount) { + return false; + } + } + int aFluidInputCount = aComparator.mFluidInputs.length; + if (aFluidInputCount > 0) { + //Logger.INFO("Looking for recipe with "+aFluidInputCount+" Fluids"); + int aMatchingFluidInputs = 0; + recipe : for (FluidStack b : aComparator.mFluidInputs) { + //Logger.INFO("Checking for fluid "+b.getLocalizedName()); + for (FluidStack a : aFluids) { + if (GT_Utility.areFluidsEqual(a, b)) { + //Logger.INFO("Found matching Fluid Input - "+b.getLocalizedName()); + aMatchingFluidInputs++; + continue recipe; + } + else { + //Logger.INFO("Found fluid which did not match - "+a.getLocalizedName()); + } + } + } + if (aMatchingFluidInputs != aFluidInputCount) { + return false; + } + } + Logger.INFO("Recipes Match!"); + return true; + } + + public GT_Recipe findRecipe(final GT_Recipe aRecipe, final long aVoltage, final long aSpecialValue, ItemStack[] aInputs, final FluidStack[] aFluids) { + if (!mInitRecipeCache) { + initRecipeCaches(); + } + if (this.getRecipeMap().mRecipeList.isEmpty()) { + log("No Recipes in Map to search through."); + return null; + } + else { + log("Checking tier "+aSpecialValue+" recipes and below. Using Input Voltage of "+aVoltage+"V."); + log("We have "+aInputs.length+" Items and "+aFluids.length+" Fluids."); + // Try check the cached recipe first + if (aRecipe != null) { + if (areInputsEqual(aRecipe, aInputs, aFluids)) { + if (aRecipe.mEUt <= aVoltage) { + Logger.INFO("Using cached recipe."); + return aRecipe; + } + } + } + + // Get all recipes for the tier + AutoMap<AutoMap<GT_Recipe>> aMasterMap = new AutoMap<AutoMap<GT_Recipe>>(); + for (long i=0;i<=aSpecialValue;i++) { + aMasterMap.add(mTieredRecipeMap.get(i)); + } + GT_Recipe aFoundRecipe = null; + + // Iterate the tiers recipes until we find the one with all inputs matching + master : for (AutoMap<GT_Recipe> aTieredMap : aMasterMap) { + for (GT_Recipe aRecipeToCheck : aTieredMap) { + if (areInputsEqual(aRecipeToCheck, aInputs, aFluids)) { + log("Found recipe with matching inputs!"); + if (aRecipeToCheck.mSpecialValue <= aSpecialValue) { + if (aRecipeToCheck.mEUt <= aVoltage) { + aFoundRecipe = aRecipeToCheck; + break master; + } + } + } + } + } + + // If we found a recipe, return it + if (aFoundRecipe != null) { + log("Found valid recipe."); + return aFoundRecipe; + } + } + log("Did not find valid recipe."); + return null; + } + + /* + * Catalyst Handling + */ + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> tItems = super.getStoredInputs(); + for (GT_MetaTileEntity_Hatch_ElementalDataOrbHolder tHatch : mReplicatorDataOrbHatches) { + tHatch.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + tItems.addAll(tHatch.getInventory()); + } + } + return tItems; + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FastNeutronReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FastNeutronReactor.java new file mode 100644 index 0000000000..3941d59edb --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FastNeutronReactor.java @@ -0,0 +1,231 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMTE_FastNeutronReactor +extends GregtechMeta_MultiBlockBase +{ + + private int mSuperEfficencyIncrease = 0; + + + public GregtechMTE_FastNeutronReactor(int aID, String aName, String aNameRegional) + { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_FastNeutronReactor(String mName) { + super(mName); + } + + @Override + public String getMachineType() { + return "Reactor"; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) + { + return new GregtechMTE_FastNeutronReactor(this.mName); + } + @Override + public boolean isFacingValid(byte aFacing) + { + return aFacing > 1; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) + { + return true; + } + + @Override + public int getDamageToComponent(ItemStack aStack){ + return 0; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + this.mSuperEfficencyIncrease=0; + if (processing_Stage_1()) { + if (processing_Stage_2()) { + if (processing_Stage_3()) { + if (processing_Stage_4()) { + + } + else { + //Stage 4 + } + } + else { + //Stage 3 + } + } + else { + //Stage 2 + } + } + else { + //Stage 1 + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + public boolean processing_Stage_1() { //Deplete Water, Add More Progress Time + for (GT_MetaTileEntity_Hatch_Input tRecipe : this.mInputHatches) { + if (tRecipe.getFluid() != null){ + FluidStack tFluid = FluidUtils.getFluidStack(tRecipe.getFluid(), 200); + if (tFluid != null) { + if (tFluid == GT_ModHandler.getDistilledWater(1)) { + if (depleteInput(tFluid)) { + this.mMaxProgresstime = Math.max(1, runtimeBoost(8 * 2)); + this.mEUt = getEUt(); + this.mEfficiencyIncrease = (this.mMaxProgresstime * getEfficiencyIncrease()); + return true; + } + } + + } + } + } + this.mMaxProgresstime = 0; + this.mEUt = 0; + return false; + } + public boolean processing_Stage_2() { + return false; + } + public boolean processing_Stage_3() { + return false; + } + public boolean processing_Stage_4() { + return false; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.mEUt > 0) { + if(this.mSuperEfficencyIncrease>0){ + this.mEfficiency = Math.min(10000, this.mEfficiency + this.mSuperEfficencyIncrease); + } + int tGeneratedEU = (int) (this.mEUt * 2L * this.mEfficiency / 10000L); + if (tGeneratedEU > 0) { + long amount = (tGeneratedEU + 160) / 160; + if (!depleteInput(GT_ModHandler.getDistilledWater(amount))) { + explodeMultiblock(); + } else { + addOutput(GT_ModHandler.getSteam(tGeneratedEU)); + } + } + return true; + } + return true; + } + + public int getEUt() { + return 0; //Default 400 + } + + public int getEfficiencyIncrease() { + return 0; //Default 12 + } + + int runtimeBoost(int mTime) { + return mTime * 150 / 100; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) + { + return true; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) + { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) + { + return 0; + } + + public int getAmountOfOutputs() + { + return 1; + } + + @Override + public String[] getTooltip() + { + return new String[]{ + "Fukushima-Daiichi Reactor No. 6", + "------------------------------------------", + "Boiling Water Reactor", + "Harness the power of Nuclear Fission", + "------------------------------------------", + "Consult user manual for more information", + }; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(1)), + new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(1))}; + } + + @Override + public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack arg1) { + return true; + } + + public boolean damageFilter(){ + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java new file mode 100644 index 0000000000..8a936525f0 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java @@ -0,0 +1,449 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.List; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.core.lib.CORE; +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.helpers.FlotationRecipeHandler; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMTE_FrothFlotationCell> STRUCTURE_DEFINITION = null; + + public GregtechMTE_FrothFlotationCell(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_FrothFlotationCell(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_FrothFlotationCell(this.mName); + } + + @Override + public String getMachineType() { + return "Flotation Cell"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Process that milled ore!") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfo("Inconel Reinforced Casing", 68) + .addCasingInfo("Flotation Casings", 52) + .addInputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addOutputHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + int aID = TAE.getIndexFromPage(2, 1); + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(aID), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(aID)}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sFlotationCellRecipes; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public IStructureDefinition<GregtechMTE_FrothFlotationCell> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_FrothFlotationCell>builder() + .addShape(mName, new String[][]{ + {" ", " ", " X ", " X~X ", " X ", " ", " "}, + {" ", " F ", " FFF ", " FF FF ", " FFF ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" ", " F ", " F F ", " F F ", " F F ", " F ", " "}, + {" CCC ", " CCCCC ", "CCCCCCC", "CCCCCCC", "CCCCCCC", " CCCCC ", " CCC "}, + {" CCC ", " CCCCC ", "CCCCCCC", "CCCCCCC", "CCCCCCC", " CCCCC ", " CCC "}, + }) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMTE_FrothFlotationCell::addFrothFlotationCellList, TAE.getIndexFromPage(2, 1), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings3Misc, 1 + ) + ) + ) + ) + .addElement( + 'F', + ofBlock( + ModBlocks.blockSpecialMultiCasings, 9 + ) + ) + .addElement( + 'X', + ofBlock( + ModBlocks.blockCasings3Misc, 1 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 3, 3, 0) && mCasing >= 68 - 4 && checkHatch(); + } + + public final boolean addFrothFlotationCellList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiFrothFlotationCell; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + // Fix GT bug + if (this.getBaseMetaTileEntity().getFrontFacing() == 0 && this.getBaseMetaTileEntity().getBackFacing() == 1) { + log("Fixing Bad Facing. (GT Bug)"); + this.getBaseMetaTileEntity().setFrontFacing((byte) 1); + } + } + + @Override + public boolean checkRecipe(ItemStack arg0) { + return super.checkRecipeGeneric(); + } + + 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. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = findRecipe( + getBaseMetaTileEntity(), mLastRecipe, false, + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + /* + * + * Material Hash checks + * Makes sure we can only ever use one type of material in this flotation cell. + * + */ + int aExpectedMaterialHash; + // Set the hash of expected material type + if (mLockedOreType == -1) { + mLockedOreType = FlotationRecipeHandler.getHashForMaterial(FlotationRecipeHandler.getMaterialOfMilledProduct(FlotationRecipeHandler.findMilledStack(aRecipe))); + } + // Set the hash for this recipe check + aExpectedMaterialHash = mLockedOreType; + + // Compute hash of current inputs + int aFoundMaterialHash = FlotationRecipeHandler.getHashForMaterial(FlotationRecipeHandler.getMaterialOfMilledProduct(FlotationRecipeHandler.findMilledStack(aItemInputs))); + + // Check hashes match + if (aExpectedMaterialHash != aFoundMaterialHash) { + log("Did not find the correct milled type."); + log("Found: "+aFoundMaterialHash); + log("Expected: "+mLockedOreType); + 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; + } + + /* + * Handle NBT + */ + + private int mLockedOreType = -1; + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + if (mLockedOreType != -1) { + aNBT.setInteger("mLockedOreType", mLockedOreType); + } + super.setItemNBT(aNBT); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + if (mLockedOreType != -1) { + aNBT.setInteger("mLockedOreType", mLockedOreType); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mLockedOreType = aNBT.getInteger("mLockedOreType"); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_LargeNaqReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_LargeNaqReactor.java new file mode 100644 index 0000000000..1ead7edad5 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_LargeNaqReactor.java @@ -0,0 +1,501 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.ArrayList; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.util.minecraft.LangUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Naquadah; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +public class GregtechMTE_LargeNaqReactor extends GregtechMeta_MultiBlockBase { + + public ArrayList<GT_MetaTileEntity_Hatch_Naquadah> mNaqHatches = new ArrayList<GT_MetaTileEntity_Hatch_Naquadah>(); + public static String[] mCasingName = new String[5]; + public static String mHatchName = "Naquadah Fuel Hatch"; + + private final int CASING_TEXTURE_ID = TAE.getIndexFromPage(0, 13); + private final int META_BaseCasing = 0; //4 + private final int META_ContainmentCasing = 15; //3 + private final int META_Shielding = 13; //1 + private final int META_PipeCasing = 1; //4 + private final int META_IntegralCasing = 6; //0 + private final int META_ContainmentChamberCasing = 2; //4 + + public GregtechMTE_LargeNaqReactor(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + mCasingName[0] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 0); + mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); + mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); + mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); + mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); + mHatchName = LangUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 969); + } + + public GregtechMTE_LargeNaqReactor(String aName) { + super(aName); + } + + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMTE_LargeNaqReactor(this.mName); + } + + public String[] getTooltip() { + if (mCasingName[0].toLowerCase().contains(".name")) { + mCasingName[0] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 0); + } + if (mCasingName[1].toLowerCase().contains(".name")) { + mCasingName[1] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 1); + } + if (mCasingName[2].toLowerCase().contains(".name")) { + mCasingName[2] = LangUtils.getLocalizedNameOfBlock(getCasing(4), 2); + } + if (mCasingName[3].toLowerCase().contains(".name")) { + mCasingName[3] = LangUtils.getLocalizedNameOfBlock(getCasing(3), 15); + } + if (mCasingName[4].toLowerCase().contains(".name")) { + mCasingName[4] = LangUtils.getLocalizedNameOfBlock(getCasing(1), 13); + } + if (mHatchName.toLowerCase().contains(".name")) { + mHatchName = LangUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 969); + } + return new String[]{ + "Naquadah reacts violently with potassium, ", + "resulting in massive explosions with radioactive potential.", + "Size: 3x4x12, WxHxL", + "Bottom Layer: "+mCasingName[0]+"s, (30x min)", + "Middle Layer: "+mCasingName[2]+"s (10x), with", + " "+mCasingName[3]+"s on either side", + " "+mCasingName[3]+"s also on each end (x26)", + "Middle Layer2: "+mCasingName[1]+" (12x total), with", + " "+mCasingName[4]+"s on either side (x24)", + "Top: Single row of "+mCasingName[0]+" along the middle (x12) ", + "", + "1x " + mHatchName + " (Any bottom layer casing)", + "1x " + "Maintenance Hatch" + " (Any bottom layer side casing)", + "1x " + "Energy Hatch" + " (Any top layer casing)", + + }; + } + + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, + boolean aActive, boolean aRedstone) { + return aSide == aFacing + ? new ITexture[]{BlockIcons.getCasingTextureForId(TAE.getIndexFromPage(3, 0)), + new GT_RenderedTexture(aActive + ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active + : TexturesGtBlock.Overlay_Machine_Controller_Default)} + : new ITexture[]{BlockIcons.getCasingTextureForId(TAE.getIndexFromPage(3, 0))}; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), + "AssemblyLine.png"); + } + + public GT_Recipe_Map getRecipeMap() { + return null; + } + + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + public boolean isFacingValid(byte aFacing) { + return aFacing == 1; + } + + public boolean checkRecipe(ItemStack aStack) { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) { + super.startSoundLoop(aIndex, aX, aY, aZ); + if (aIndex == 20) { + GT_Utility.doSoundAtClient((String) GregTech_API.sSoundList.get(Integer.valueOf(212)), 10, 1.0F, aX, aY, + aZ); + } + } + + @Override + public String getSound() { + return (String) GregTech_API.sSoundList.get(Integer.valueOf(212)); + } + + private Block getCasing(int casingID) { + if (casingID == 1) { + return ModBlocks.blockCasingsMisc; + } + else if (casingID == 2) { + return ModBlocks.blockCasings2Misc; + } + else if (casingID == 3) { + return ModBlocks.blockCasings3Misc; + } + else if (casingID == 4) { + return ModBlocks.blockCasings4Misc; + } + else { + return ModBlocks.blockCasingsTieredGTPP; + } + } + + + + //Casing3, Meta 10 - "Grate Machine Casing"); + //Casing2, Meta 0 - "Solid Steel Machine Casing" + //Casing2, Meta 5 - "Assembling Line Casing" + //Casing2, Meta 9 - "Assembler Machine Casing" + //Magic Glass - blockAlloyGlass + + public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 4; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 4; + + // Counts for all Casing Types + int aBaseCasingCount = 0; + int aContainmentCasingCount = 0; + int aShieldingCount = 0; + int aPipeCount = 0; + int aIntegralCasingCount = 0; + int aContainmentChamberCount = 0; + + // Bottom Layer + aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, -7, xDir, zDir); + log("Bottom Layer is Valid. Moving to Layer 1."); + + // Layer 1 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -6, xDir, zDir); + aIntegralCasingCount += checkIntegralRing(aBaseMetaTileEntity, getCasing(0), this.META_IntegralCasing, -6, xDir, zDir); + aContainmentChamberCount += checkContainmentRing(aBaseMetaTileEntity, getCasing(4), this.META_ContainmentChamberCasing, -6, xDir, zDir); + log("Layer 1 is Valid. Moving to Layer 2."); + + // Layer 2 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -5, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -5, xDir, zDir); + log("Layer 2 is Valid. Moving to Layer 3."); + + // Layer 3 + aContainmentCasingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(3), this.META_ContainmentCasing, -4, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -4, xDir, zDir); + log("Layer 3 is Valid. Moving to Layer 4."); + + // Layer 4 + aContainmentCasingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(3), this.META_ContainmentCasing, -3, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -3, xDir, zDir); + log("Layer 4 is Valid. Moving to Layer 5."); + + // Layer 5 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -2, xDir, zDir); + aPipeCount += checkPipes(aBaseMetaTileEntity, getCasing(4), this.META_PipeCasing, -2, xDir, zDir); + log("Layer 5 is Valid. Moving to Layer 6."); + + // Layer 6 + aShieldingCount += checkOuterRing(aBaseMetaTileEntity, getCasing(1), this.META_Shielding, -1, xDir, zDir); + aIntegralCasingCount += checkIntegralRing(aBaseMetaTileEntity, getCasing(0), this.META_IntegralCasing, -1, xDir, zDir); + aContainmentChamberCount += checkContainmentRing(aBaseMetaTileEntity, getCasing(4), this.META_ContainmentChamberCasing, -1, xDir, zDir); + log("Layer 6 is Valid. Moving to Top Layer."); + + // Top Layer + aBaseCasingCount += checkEntireLayer(aBaseMetaTileEntity, getCasing(4), META_BaseCasing, 0, xDir, zDir); + + log("Found "+aBaseCasingCount+" "+mCasingName[0]+"s"); + log("Found "+aShieldingCount+" "+mCasingName[4]+"s"); + log("Found "+aPipeCount+" "+mCasingName[1]+"s"); + log("Found "+aContainmentCasingCount+" "+mCasingName[3]+"s"); + log("Found "+aIntegralCasingCount+" "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s"); + log("Found "+aContainmentChamberCount+" "+mCasingName[2]+"s"); + + // Try mesage player + String aOwnerName = this.getBaseMetaTileEntity().getOwnerName(); + EntityPlayer aOwner = null; + if (aOwnerName != null && aOwnerName.length() > 0) { + aOwner = PlayerUtils.getPlayer(aOwnerName); + } + + if (aShieldingCount != 128) { + log("Not enough "+mCasingName[4]+"s, require 128."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[4]+"s, require 128."); + } + return false; + } + if (aPipeCount != 20) { + log("Not enough "+mCasingName[1]+"s, require 20."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[1]+"s, require 20."); + } + return false; + } + if (aContainmentCasingCount != 64) { + log("Not enough "+mCasingName[3]+"s, require 64."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[3]+"s, require 64."); + } + return false; + } + if (aContainmentChamberCount != 42) { + log("Not enough "+mCasingName[2]+"s, require 42."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[2]+"s, require 42."); + } + return false; + } + if (aBaseCasingCount < 140) { + log("Not enough "+mCasingName[0]+"s, require 140 at a minimum."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+mCasingName[0]+"s, require 140 at a minimum."); + } + return false; + } + if (aIntegralCasingCount != 48) { + log("Not enough "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s, require 48."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Not enough "+LangUtils.getLocalizedNameOfBlock(getCasing(0), 6)+"s, require 48."); + } + return false; + } + log("LNR Formed."); + if (aOwner != null) { + PlayerUtils.messagePlayer(aOwner, "Large Naquadah Reactor has formed successfully."); + } + return true; + } + + public boolean addNaquadahHatchToMachineInput(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Naquadah) { + this.updateTexture(aMetaTileEntity, aBaseCasingIndex); + return this.mNaqHatches.add((GT_MetaTileEntity_Hatch_Naquadah) aMetaTileEntity); + } else { + return false; + } + } + } + + public int checkEntireLayer(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -4; x < 5; x++) { + for (int z = -4; z < 5; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { + continue; + } + // Skip controller + if (aY == 0 && x == 0 && z == 0) { + continue; + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, true, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + public int checkOuterRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -4; x < 5; x++) { + for (int z = -4; z < 5; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 4 && z == 4) || (x == -4 && z == -4) || (x == 4 && z == -4) || (x == -4 && z == 4)) { + continue; + } + + // If we are on the 5x5 ring, proceed + if ((x > -4 && x < 4 ) && (z > -4 && z < 4)) { + if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + } + else { + continue; + } + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + public int checkIntegralRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -3; x < 4; x++) { + for (int z = -3; z < 4; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 3 && z == 3) || (x == -3 && z == -3) || (x == 3 && z == -3) || (x == -3 && z == 3)) { + continue; + } + + // If we are on the 5x5 ring, proceed + if ((x > -3 && x < 3 ) && (z > -3 && z < 3)) { + if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + } + else { + continue; + } + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + public int checkPipes(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -1; x < 2; x++) { + for (int z = -1; z < 2; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 1 && z == 1) || (x == -1 && z == -1) || (x == 1 && z == -1) || (x == -1 && z == 1) || (x == 0 && z == 0)) { + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Pipe has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + }; + } + } + } + return aCasingCount; + } + + public int checkContainmentRing(IGregTechTileEntity aBaseMetaTileEntity, Block aBlock, int aMeta, int aY, int xDir, int zDir) { + int aCasingCount = 0; + for (int x = -2; x < 3; x++) { + for (int z = -2; z < 3; z++) { + int aOffsetX = this.getBaseMetaTileEntity().getXCoord() + x; + int aOffsetY = this.getBaseMetaTileEntity().getYCoord() + aY; + int aOffsetZ = this.getBaseMetaTileEntity().getZCoord() + z; + //Skip the corners + if ((x == 2 && z == 2) || (x == -2 && z == -2) || (x == 2 && z == -2) || (x == -2 && z == 2)) { + continue; + } + + Block aCurrentBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, aY, zDir + z); + int aCurrentMeta = (int) aBaseMetaTileEntity.getMetaIDOffset(xDir + x, aY, zDir + z); + if (aCurrentBlock == aBlock && aCurrentMeta == aMeta) { + aCasingCount++; + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, aY, zDir + z); + if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, false, aCurrentBlock, aCurrentMeta, aBlock, aMeta)) { + log("Layer has error. Height: "+aY); + //this.getBaseMetaTileEntity().getWorld().setBlock(aOffsetX, aOffsetY, aOffsetZ, aBlock, aMeta, 3); + return 0; + } + } + } + return aCasingCount; + } + + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + public int getPollutionPerTick(ItemStack aStack) { + return 133; + } + + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Reactor"; + } +}*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_MiniFusionPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_MiniFusionPlant.java new file mode 100644 index 0000000000..9c2e3289c3 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_MiniFusionPlant.java @@ -0,0 +1,386 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.ArrayList; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ControlCore; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Plasma; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMTE_MiniFusionPlant extends GregtechMeta_MultiBlockBase { + + public long currentVoltage = GT_Values.V[7]; + public byte currentTier = 8; + + public void upvolt() { + byte f = currentTier; + if ((f+1) > 10) { + f = 8; + } + else { + f++; + } + this.currentTier = f; + updateVoltage(); + } + + public void downvolt() { + byte f = currentTier; + if ((f-1) < 8) { + f = 10; + } + else { + f--; + } + this.currentTier = f; + updateVoltage(); + } + + private long updateVoltage() { + this.currentVoltage = GT_Values.V[this.currentTier-1]; + return currentVoltage; + } + + public GregtechMTE_MiniFusionPlant(String aName) { + super(aName); + } + + public GregtechMTE_MiniFusionPlant(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMTE_MiniFusionPlant(this.mName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, + final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == this.getBaseMetaTileEntity().getBackFacing()) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(10)), + Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[(int) this.getInputTier()]}; + } + if (aSide == 1) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(10)), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[(int) this.getOutputTier()]}; + } + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(10)), + new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(10))}; + } + + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sSlowFusionRecipes; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Fusion Reactor"; + } + + @Override + public String[] getTooltip() { + return new String[] { + "Small scale fusion", + "16x slower than using Multiblock of the same voltage", + //"Input voltage can be changed within the GUI", + "Place Input/Output Hatches on sides and bottom", + "Power can only be inserted into the back", + //e"Power can only be extracted from the top", + TAG_HIDE_HATCHES + }; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + int xDir2 = ForgeDirection.getOrientation(aBaseMetaTileEntity.getFrontFacing()).offsetX; + int zDir2 = ForgeDirection.getOrientation(aBaseMetaTileEntity.getFrontFacing()).offsetZ; + int tAmount = 0; + + ForgeDirection aDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()); + + //Require air in front, I think + if (!aBaseMetaTileEntity.getAirOffset(xDir2, 0, zDir2)) { + Logger.INFO("Did not find air in front"); + return false; + } else { + for (int i = -1; i < 2; ++i) { + for (int j = -1; j < 2; ++j) { + for (int h = -1; h < 2; ++h) { + if (h != 0 || (xDir + i != 0 || zDir + j != 0) && (i != 0 || j != 0)) { + IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, + h, zDir + j); + if (this.addToMachineList(tTileEntity, TAE.GTPP_INDEX(10))) { + tAmount++; + } + } + } + } + } + } + Logger.INFO("Tanks found: "+tAmount); + return tAmount == 3; + } + + @Override + public boolean checkRecipe(ItemStack arg0) { + + + ArrayList tFluidList = this.getStoredFluids(); + int tFluidList_sS = tFluidList.size(); + + for (int tFluids = 0; tFluids < tFluidList_sS - 1; ++tFluids) { + for (int tRecipe = tFluids + 1; tRecipe < tFluidList_sS; ++tRecipe) { + if (GT_Utility.areFluidsEqual((FluidStack) tFluidList.get(tFluids), + (FluidStack) tFluidList.get(tRecipe))) { + if (((FluidStack) tFluidList.get(tFluids)).amount < ((FluidStack) tFluidList.get(tRecipe)).amount) { + tFluidList.remove(tFluids--); + tFluidList_sS = tFluidList.size(); + break; + } + + tFluidList.remove(tRecipe--); + tFluidList_sS = tFluidList.size(); + } + } + } + int aStep = 0; + //Logger.INFO("Step "+aStep++); + if (tFluidList.size() > 1) { + //Logger.INFO("Step "+aStep++); + FluidStack[] arg5 = (FluidStack[]) tFluidList.toArray(new FluidStack[tFluidList.size()]); + GT_Recipe arg6 = getRecipeMap().findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, + false, this.getMaxInputVoltage(), arg5, new ItemStack[0]); + if (arg6 == null && !this.mRunningOnLoad || (arg6 != null && this.maxEUStore() < (long) arg6.mSpecialValue)) { + //Logger.INFO("Bad Step "+aStep++); + //this.turnCasingActive(false); + this.mLastRecipe = null; + return false; + } + //Logger.INFO("Step "+aStep++); + + if (this.mRunningOnLoad || (arg6 != null && arg6.isRecipeInputEqual(true, arg5, new ItemStack[0]))) { + //Logger.INFO("Step "+aStep++); + this.mLastRecipe = arg6; + this.mEUt = this.mLastRecipe.mEUt * 1; + this.mMaxProgresstime = this.mLastRecipe.mDuration / 1; + this.mEfficiencyIncrease = 10000; + this.mOutputFluids = this.mLastRecipe.mFluidOutputs; + //this.turnCasingActive(true); + this.mRunningOnLoad = false; + return true; + } + //Logger.INFO("Step "+aStep++); + } + //Logger.INFO("Step "+aStep++); + + return false; + + + + + //return this.checkRecipeGeneric(this.getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); + } + + @Override + public int getMaxEfficiency(ItemStack arg0) { + return 10000; + } + + @Override + public boolean drainEnergyInput(long aEU) { + // Not applicable to this machine + return true; + } + + @Override + public boolean addEnergyOutput(long aEU) { + // Not applicable to this machine + return true; + } + + @Override + public long maxEUStore() { + return this.getMaxInputVoltage() * 256 * 512; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public String[] getExtraInfoData() { + String mode = EnumChatFormatting.BLUE + "" + currentVoltage + EnumChatFormatting.RESET; + String aOutput = EnumChatFormatting.BLUE + "" + mEUt + EnumChatFormatting.RESET; + String storedEnergyText; + if (this.getEUVar() > maxEUStore()) { + storedEnergyText = EnumChatFormatting.RED + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; + } else { + storedEnergyText = EnumChatFormatting.GREEN + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; + } + + return new String[]{ + "Stored EU: " + storedEnergyText, + "Capacity: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.maxEUStore()) + EnumChatFormatting.RESET, + "Voltage: " + mode, + "Output Voltage: " + aOutput + }; + } + + @Override + public void explodeMultiblock() { + super.explodeMultiblock(); + } + + @Override + public void doExplosion(long aExplosionPower) { + super.doExplosion(aExplosionPower); + } + + @Override + public long getMaxInputVoltage() { + return updateVoltage(); + } + + @Override + public long getInputTier() { + return (long) GT_Utility.getTier(maxEUInput()); + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(byte aSide) { + return (aSide == this.getBaseMetaTileEntity().getBackFacing()); + } + + @Override + public boolean isOutputFacing(byte aSide) { + return aSide == 1; + } + + @Override + public long maxAmperesIn() { + return 32; + } + + @Override + public long maxAmperesOut() { + return 1; + } + + @Override + public long maxEUInput() { + return updateVoltage(); + } + + @Override + public long maxEUOutput() { + return mEUt > 0 ? mEUt : 0; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + this.mWrench = true; + this.mScrewdriver = true; + this.mSoftHammer = true; + this.mHardHammer = true; + this.mSolderingTool = true; + this.mCrowbar = true; + } + + @Override + public boolean causeMaintenanceIssue() { + return true; + } + + @Override + public int getControlCoreTier() { + return this.currentTier; + } + + @Override + public int getPollutionPerTick(ItemStack arg0) { + return 0; + } + + @Override + public GT_MetaTileEntity_Hatch_ControlCore getControlCoreBus() { + GT_MetaTileEntity_Hatch_ControlCore x = new GT_MetaTileEntity_Hatch_ControlCore("", 0, "", null); + return (GT_MetaTileEntity_Hatch_ControlCore) x; + } + +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java new file mode 100644 index 0000000000..1f6ae41be2 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java @@ -0,0 +1,523 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +import java.util.Collection; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.material.nuclear.NUCLIDE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMTE_NuclearReactor extends GregtechMeta_MultiBlockBase<GregtechMTE_NuclearReactor> { + + protected int mFuelRemaining = 0; + + private int mCasing; + private IStructureDefinition<GregtechMTE_NuclearReactor> STRUCTURE_DEFINITION = null; + + + public GregtechMTE_NuclearReactor(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_NuclearReactor(final String aName) { + super(aName); + } + + @Override + public long maxEUStore() { + return (640000000L * (Math.min(16, this.mEnergyHatches.size()))) / 16L; + } + + @Override + public String getMachineType() { + return "Reactor"; + } + + @Override + public GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe_Map.sLiquidFluorineThoriumReactorRecipes; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Liquid Fluoride Thorium Reactor.") + .addInfo("Produces Heat & Energy from Radioactive Beta Decay.") + .addInfo("Outputs U233 every 10 seconds, on average") + .addInfo("Input Fluorine and Helium for bonus byproducts") + .addInfo("Input Li2BeF4 and a molten salt as fuel.") + .addInfo("LiFBeF2ThF4UF4, LiFBeF2ZrF4UF4 or LiFBeF2ZrF4U235") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(7, 4, 7, true) + .addController("Bottom Center") + .addCasingInfo("Hastelloy-N Reactor Casing", 27) + .addCasingInfo("Zeron-100 Reactor Shielding", 26) + .addInputHatch("Top or bottom layer edges", 1) + .addOutputHatch("Top or bottom layer edges", 1) + .addDynamoHatch("Top or bottom layer edges", 1) + .addMaintenanceHatch("Top or bottom layer edges", 1) + .addMufflerHatch("Top 3x3", 2) + .addStructureInfo("All dynamos must be IV or LuV tier.") + .addStructureInfo("All other hatches must be IV+ tier.") + .addStructureInfo("3x Output Hatches, 2x Input Hatches, 4x Dynamo Hatches") + .addStructureInfo("2x Maintenance Hatches, 4x Mufflers") + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public String[] getExtraInfoData() { + final String tRunning = (this.mMaxProgresstime>0 ? "Reactor running":"Reactor stopped"); + final String tMaintainance = (this.getIdealStatus() == this.getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance"); + + return new String[]{ + "Liquid Fluoride Thorium Reactor", + tRunning, + tMaintainance, + "Current Output: "+this.mEUt+" EU/t", + "Fuel Remaining: "+this.mFuelRemaining+" Litres", + "Current Efficiency: "+(this.mEfficiency/5)+"%", + "Current Efficiency (Raw): "+(this.mEfficiency), + "It requires you to have 100% Efficiency."}; + } + + @Override + public boolean allowCoverOnSide(final byte aSide, final GT_ItemStack aStack) { + return aSide != this.getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + boolean aWarmedUp = this.mEfficiency == this.getMaxEfficiency(null); + if (!aBaseMetaTileEntity.isActive() || !aWarmedUp){ + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12))}; + } + else if(aBaseMetaTileEntity.isActive() && aWarmedUp){ + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13)), + new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13))}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12))}; + + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MatterFabricator"; + } + + public final boolean addNuclearReactorEdgeList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo && (((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity).mTier >= 5 && ((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity).mTier <= 6)){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input && ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output && ((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addNuclearReactorTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler && ((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public IStructureDefinition<GregtechMTE_NuclearReactor> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_NuclearReactor>builder() + .addShape(mName, transpose(new String[][]{ + {"CCCCCCC", "COOOOOC", "COXXXOC", "COXXXOC", "COXXXOC", "COOOOOC", "CCCCCCC"}, + {"GGGGGGG", "G-----G", "G-----G", "G-----G", "G-----G", "G-----G", "GGGGGGG"}, + {"GGGGGGG", "G-----G", "G-----G", "G-----G", "G-----G", "G-----G", "GGGGGGG"}, + {"CCC~CCC", "COOOOOC", "COOOOOC", "COOOOOC", "COOOOOC", "COOOOOC", "CCCCCCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMTE_NuclearReactor::addNuclearReactorEdgeList, TAE.GTPP_INDEX(12), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 12 + ) + ) + ) + ) + .addElement( + 'X', + ofChain( + ofHatchAdder( + GregtechMTE_NuclearReactor::addNuclearReactorTopList, TAE.GTPP_INDEX(12), 2 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 12 + ) + ) + ) + ) + .addElement( + 'O', + ofBlock( + ModBlocks.blockCasingsMisc, 12 + ) + ) + .addElement( + 'G', + ofBlock( + ModBlocks.blockCasingsMisc, 13 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + if (checkPiece(mName, 3, 3, 0) && mCasing >= 27) { + if (mOutputHatches.size() >= 3 && mInputHatches.size() >= 2 && mDynamoHatches.size() == 4 && + mMufflerHatches.size() == 4 && mMaintenanceHatches.size() == 2) { + this.mWrench = true; + this.mScrewdriver = true; + this.mSoftHammer = true; + this.mHardHammer = true; + this.mSolderingTool = true; + this.mCrowbar = true; + this.turnCasingActive(false); + return true; + } + } + return false; + } + + // Alk's Life Lessons from Greg. + /* + [23:41:15] <GregoriusTechneticies> xdir and zdir are x2 and not x3 + [23:41:26] <GregoriusTechneticies> thats you issue + [23:44:33] <Alkalus> mmm? + [23:44:49] <Alkalus> Should they be x3? + [23:44:50] <GregoriusTechneticies> you just do a x2, what is for a 5x5 multiblock + [23:45:01] <GregoriusTechneticies> x3 is for a 7x7 one + [23:45:06] <Alkalus> I have no idea what that value does, tbh.. + [23:45:15] <GregoriusTechneticies> its the offset + [23:45:23] <Alkalus> Debugging checkMachine has been a pain and I usually trash designs that don't work straight up.. + [23:45:28] <GregoriusTechneticies> it determines the horizontal middle of the multiblock + [23:45:47] <GregoriusTechneticies> which is in your case THREE blocks away from the controller + [23:45:51] <Alkalus> Ahh + [23:45:57] <GregoriusTechneticies> and not 2 + [23:46:06] <Alkalus> Noted, thanks :D + */ + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return true; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_NuclearReactor(this.mName); + } + + public boolean turnCasingActive(final boolean status) { + //TODO + if (this.mDynamoHatches != null) { + for (final GT_MetaTileEntity_Hatch_Dynamo hatch : this.mDynamoHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + if (this.mMufflerHatches != null) { + for (final GT_MetaTileEntity_Hatch_Muffler hatch : this.mMufflerHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch : this.mInputHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + if (this.mMaintenanceHatches != null) { + for (final GT_MetaTileEntity_Hatch_Maintenance hatch : this.mMaintenanceHatches) { + hatch.mMachineBlock = status ? (byte) TAE.GTPP_INDEX(13) : (byte) TAE.GTPP_INDEX(12); + } + } + return true; + } + + public FluidStack[] getStoredFluidsAsArray() { + return getStoredFluids().toArray(new FluidStack[0]); + } + + public int getStoredFuel(GT_Recipe aRecipe) { + int aFuelStored = 0; + FluidStack aFuelFluid = null; + for (FluidStack aFluidInput : aRecipe.mFluidInputs) { + if (!aFluidInput.getFluid().equals(NUCLIDE.Li2BeF4.getFluid())) { + aFuelFluid = aFluidInput; + break; + } + } + if (aFuelFluid != null) { + for (GT_MetaTileEntity_Hatch_Input aInputHatch : this.mInputHatches) { + if (aInputHatch.getFluid() != null && aInputHatch.getFluidAmount() > 0) { + if (aInputHatch.getFluid().isFluidEqual(aFuelFluid)) { + aFuelStored += aInputHatch.getFluidAmount(); + } + } + } + } + return aFuelStored; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + // Warm up for 4~ minutes + Logger.WARNING("Checking LFTR recipes."); + if (mEfficiency < this.getMaxEfficiency(null)) { + this.mProgresstime = 0; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 2; + Logger.WARNING("Warming Up! "+this.mEfficiency+"/"+this.getMaxEfficiency(null)); + return true; + } + Logger.WARNING("Warmed up, checking LFTR recipes."); + + final FluidStack[] tFluids = getStoredFluidsAsArray(); + final Collection<GT_Recipe> tRecipeList = getRecipeMap().mRecipeList; + if(tFluids.length > 0 && tRecipeList != null && tRecipeList.size() > 0) { //Does input hatch have a LFTR fuel? + Logger.WARNING("Found more than one input fluid and a list of valid recipes."); + // Find a valid recipe + GT_Recipe aFuelProcessing = this.findRecipe(getBaseMetaTileEntity(), mLastRecipe, true, 0, tFluids, new ItemStack[] {}); + if (aFuelProcessing == null) { + Logger.WARNING("Did not find valid recipe for given inputs."); + return false; + } + else { + Logger.WARNING("Found recipe? "+(aFuelProcessing != null ? "true" : "false")); + for (FluidStack aFluidInput : aFuelProcessing.mFluidInputs) { + Logger.WARNING("Using "+aFluidInput.getLocalizedName()); + } + } + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + this.mLastRecipe = aFuelProcessing; + // Deplete Inputs + if (aFuelProcessing.mFluidInputs.length > 0) { + for (FluidStack aInputToConsume : aFuelProcessing.mFluidInputs) { + Logger.WARNING("Depleting "+aInputToConsume.getLocalizedName()+" - "+aInputToConsume.amount+"L"); + this.depleteInput(aInputToConsume); + } + } + // -- Try not to fail after this point - inputs have already been consumed! -- + this.mMaxProgresstime = (int)(aFuelProcessing.mDuration); + this.mEUt = aFuelProcessing.mSpecialValue * 4; + Logger.WARNING("Outputting "+this.mEUt+"eu/t"); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + Logger.WARNING("Recipe time: "+this.mMaxProgresstime); + mFuelRemaining = getStoredFuel(aFuelProcessing); //Record available fuel + + this.mOutputFluids = aFuelProcessing.mFluidOutputs.clone(); + updateSlots(); + Logger.WARNING("Recipe Good!"); + return true; + } + this.mEUt = 0; + this.mEfficiency = 0; + Logger.WARNING("Recipe Bad!"); + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void explodeMultiblock() { + this.mInventory[1] = null; + long explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + for (final MetaTileEntity tTileEntity : this.mInputBusses) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mOutputBusses) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mInputHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mOutputHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mDynamoHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mMufflerHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mEnergyHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mMaintenanceHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity().doExplosion(explodevalue); + } + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + this.getBaseMetaTileEntity().doExplosion(explodevalue); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.getWorld().isRemote) { + if (aBaseMetaTileEntity.isActive()){ + // Set casings active if we're warmed up. + if (this.mEfficiency == this.getMaxEfficiency(null)){ + this.turnCasingActive(true); + } + else { + this.turnCasingActive(false); + } + } + else { + this.turnCasingActive(false); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + // See if we're warmed up. + if (this.mEfficiency == this.getMaxEfficiency(null)){ + // Try output some Uranium-233 + if (MathUtils.randInt(1, 300) == 1){ + this.addOutput(ELEMENT.getInstance().URANIUM233.getFluidStack(MathUtils.randInt(1, 10))); + } + + } + return super.onRunningTick(aStack); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mFuelRemaining", this.mFuelRemaining); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mFuelRemaining = aNBT.getInteger("mFuelRemaining"); + super.loadNBTData(aNBT); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityGeneratorArray.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityGeneratorArray.java new file mode 100644 index 0000000000..cccee84c99 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityGeneratorArray.java @@ -0,0 +1,521 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +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.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntityGeneratorArray extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntityGeneratorArray> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntityGeneratorArray(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntityGeneratorArray(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityGeneratorArray(this.mName); + } + + @Override + public String getMachineType() { + return "Processing Array"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Generator Array") + .addInfo("Runs supplied generators as if placed in the world") + .addInfo("Place up to 16 Single Block GT Generators into the Controller") + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Robust Tungstensteel Machine Casings", 10) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addDynamoHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(48), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(48)}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ProcessingArray"; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + this.mMode = getModeFromInventorySlot(this.getGUIItemStack()); + if (this.mMode == MODE_NONE) { + return null; + } + else if (this.mMode == MODE_STEAM) { + return GTPP_Recipe.GTPP_Recipe_Map.sSteamTurbineFuels; + } + else if (this.mMode == MODE_DIESEL) { + return GT_Recipe.GT_Recipe_Map.sDieselFuels; + } + else if (this.mMode == MODE_GAS) { + return GT_Recipe.GT_Recipe_Map.sTurbineFuels; + } + else if (this.mMode == MODE_SEMIFLUID) { + return GTPP_Recipe.GTPP_Recipe_Map.sSemiFluidLiquidFuels; + } + else if (this.mMode == MODE_GEOTHERMAL) { + return GTPP_Recipe.GTPP_Recipe_Map.sThermalFuels; + } + else if (this.mMode == MODE_ROCKETFUEL) { + return GTPP_Recipe.GTPP_Recipe_Map.sRocketFuels; + } + else if (this.mMode == MODE_MAGIC_A) { + return GT_Recipe.GT_Recipe_Map.sMagicFuels; + } + else if (this.mMode == MODE_PLASMA) { + return GT_Recipe.GT_Recipe_Map.sPlasmaFuels; + } + else if (this.mMode == MODE_NAQUADAH) { + return GT_Recipe.GT_Recipe_Map.sFluidNaquadahReactorFuels; + } + return null; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + if (aStack != null && aStack.getUnlocalizedName().startsWith("gt.blockmachines.")) { + return true; + } + return false; + } + + public String mMachine = ""; + protected int fuelConsumption = 0; + protected int fuelValue = 0; + protected int fuelRemaining = 0; + protected boolean boostEu = false; + + int mMode = 0; + + private final static int MODE_STEAM = 0; + private final static int MODE_DIESEL = 1; + private final static int MODE_GAS = 2; + private final static int MODE_SEMIFLUID = 3; + private final static int MODE_GEOTHERMAL = 4; + private final static int MODE_ROCKETFUEL = 5; + private final static int MODE_MAGIC_A = 6; + private final static int MODE_MAGIC_B_DISABLED = 7; + private final static int MODE_PLASMA = 8; + private final static int MODE_NAQUADAH = 9; + private final static int MODE_NONE = 100; + + private final static int[] ID_STEAM = new int[] {962, 1120, 1121, 1122}; + private final static int[] ID_GAS = new int[] {961, 1115, 1116, 1117}; + private final static int[] ID_DIESEL = new int[] {960, 1110, 1111, 1112}; + private final static int[] ID_SEMIFLUID = new int[] {837, 838, 839}; + private final static int[] ID_GEOTHERMAL = new int[] {830, 831, 832}; + private final static int[] ID_ROCKETFUEL = new int[] {793, 794, 795}; + private final static int[] ID_MAGIC_A = new int[] {1123, 1124, 1125}; + private final static int[] ID_MAGIC_B_DISABLED = new int[] {1127, 1128, 1129, 1130}; + private final static int[] ID_PLASMA = new int[] {1196, 1197, 1198}; + private final static int[] ID_NAQUADAH = new int[] {1190, 1191, 1192}; + + private static final int getModeFromInventorySlot(ItemStack aStack) { + + if (aStack == null) { + return MODE_NONE; + } + + String aItemStackName = aStack == null ? "" : aStack.getUnlocalizedName(); + //Logger.INFO("Item Name: "+aItemStackName+" ("+aStack.getItemDamage()+")"); + if (aItemStackName.toLowerCase().contains("gt.blockmachines")) { + for (int g : ID_STEAM) { + if (aStack.getItemDamage() == g) { + return MODE_STEAM; + } + } + for (int g : ID_GAS) { + if (aStack.getItemDamage() == g) { + return MODE_GAS; + } + } + for (int g : ID_DIESEL) { + if (aStack.getItemDamage() == g) { + return MODE_DIESEL; + } + } + for (int g : ID_SEMIFLUID) { + if (aStack.getItemDamage() == g) { + return MODE_SEMIFLUID; + } + } + for (int g : ID_GEOTHERMAL) { + if (aStack.getItemDamage() == g) { + return MODE_GEOTHERMAL; + } + } + for (int g : ID_ROCKETFUEL) { + if (aStack.getItemDamage() == g) { + return MODE_ROCKETFUEL; + } + } + for (int g : ID_MAGIC_A) { + if (aStack.getItemDamage() == g) { + return MODE_MAGIC_A; + } + } + for (int g : ID_PLASMA) { + if (aStack.getItemDamage() == g) { + return MODE_PLASMA; + } + } + for (int g : ID_NAQUADAH) { + if (aStack.getItemDamage() == g) { + return MODE_NAQUADAH; + } + } + } + return MODE_NONE; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + + this.resetRecipeMapForAllInputHatches(); + this.mMode = getModeFromInventorySlot(aStack); + if (mMode == MODE_NONE) { + Logger.INFO("Did not find valid generator."); + return false; + } + else { + Logger.INFO("Changed Mode to "+mMode); + } + int aMulti = this.getGUIItemStack() != null ? this.getGUIItemStack().stackSize : 0; + if (aMulti > 16 || aMulti == 0) { + return false; + } + + + + ArrayList<FluidStack> tFluids = this.getStoredFluids(); + + Collection<GT_Recipe> tRecipeList = this.getRecipeMap().mRecipeList; + Logger.INFO("Got Recipe Map"); + if (tFluids.size() > 0 && tRecipeList != null) { + Logger.INFO("Found Fuels for Map."); + Iterator<FluidStack> arg3 = tFluids.iterator(); + int aCount = 0; + while (arg3.hasNext()) { + FluidStack hatchFluid1 = (FluidStack) arg3.next(); + Logger.INFO("Iterating Fluid Found "+(aCount++)+" | "+hatchFluid1.getLocalizedName()); + Iterator<GT_Recipe> arg5 = tRecipeList.iterator(); + + int Hatch = 0; + int totalFuelValue = 0; + while (arg5.hasNext()) { + Logger.INFO("Iterating Recipe "+(Hatch++)); + GT_Recipe aFuel = (GT_Recipe) arg5.next(); + FluidStack tLiquid; + boolean addedFuelOnce = false; + for (int a = 0; a < aMulti; a++) { + if ((tLiquid = GT_Utility.getFluidForFilledItem(aFuel.getRepresentativeInput(0), true)) != null + && hatchFluid1.isFluidEqual(tLiquid)) { + this.fuelConsumption = tLiquid.amount = this.boostEu + ? 4096 / aFuel.mSpecialValue + : 2048 / aFuel.mSpecialValue; + if (this.depleteInput(tLiquid)) { + Logger.INFO("Depleted Fuel"); + this.boostEu = this.depleteInput(Materials.Oxygen.getGas(2L)); + +/*if (!tFluids.contains(Materials.Lubricant.getFluid(1L))) { + Logger.INFO("No Lube."); + return false; + }*/ + + if (this.mRuntime % 72 == 0 || this.mRuntime == 0) { + this.depleteInput(Materials.Lubricant.getFluid(this.boostEu ? 2L : 1L)); + } + Logger.INFO("ADDING POWER"); + this.fuelRemaining = hatchFluid1.amount; + totalFuelValue++; + } + } + } + //Do things after consuming Fuel + if (totalFuelValue == aMulti) { + this.fuelValue = aFuel.mSpecialValue*aMulti; + this.mEUt = this.mEfficiency < 2000 ? 0 : aFuel.mSpecialValue*aMulti; + this.mProgresstime = aMulti; + this.mMaxProgresstime = aMulti; + this.mEfficiencyIncrease = 15*aMulti; + return true; + } + } + } + } + + this.mEUt = 0; + this.mEfficiency = 0; + return false; + } + + public static ItemStack[] clean(final ItemStack[] v) { + List<ItemStack> list = new ArrayList<ItemStack>(Arrays.asList(v)); + list.removeAll(Collections.singleton(null)); + return list.toArray(new ItemStack[list.size()]); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntityGeneratorArray> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntityGeneratorArray>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntityGeneratorArray::addGeneratorArrayList, 48, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + GregTech_API.sBlockCasings4, 0 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10; + } + + public final boolean addGeneratorArrayList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + /** + * Code from single blocks + */ + + public void tryProcessFuelItems(IGregTechTileEntity aBaseMetaTileEntity, ItemStack a) { + if (a != null + && aBaseMetaTileEntity.getUniversalEnergyStored() < this.maxEUOutput() * 20L + this.getMinimumStoredEU() + && GT_Utility.getFluidForFilledItem(a, true) == null) { + int tFuelValue; + tFuelValue = this.getFuelValue(a); + if (tFuelValue > 0) { + ItemStack tEmptyContainer1 = this.getEmptyContainer(a); + if (this.addOutput(tEmptyContainer1)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits((long) tFuelValue, true); + this.depleteInput(a); + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollutionPerTick(null)); + } + } + } + } + + public void tryProcessFuel(IGregTechTileEntity aBaseMetaTileEntity, long aTick, FluidStack mFluid) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10L == 0L) { + int tFuelValue; + if (mFluid != null) { + tFuelValue = this.getFuelValue(mFluid); + int tEmptyContainer = this.consumedFluidPerOperation(mFluid); + if (tFuelValue > 0 && tEmptyContainer > 0 && mFluid.amount > tEmptyContainer) { + long tFluidAmountToUse = Math.min((long) (mFluid.amount / tEmptyContainer), + (this.maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / (long) tFuelValue); + if (tFluidAmountToUse > 0L && aBaseMetaTileEntity + .increaseStoredEnergyUnits(tFluidAmountToUse * (long) tFuelValue, true)) { + PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10 * this.getPollutionPerTick(null)); + mFluid.amount = (int) ((long) mFluid.amount + - tFluidAmountToUse * (long) tEmptyContainer); + } + } + } + + //Check items + } + + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity + .getUniversalEnergyStored() >= this.maxEUOutput() + this.getMinimumStoredEU()); + } + + } + + public boolean isFluidInputAllowed(FluidStack aFluid) { + return this.getFuelValue(aFluid) > 0; + } + + + public int consumedFluidPerOperation(FluidStack aLiquid) { + return 1; + } + + public int getFuelValue(FluidStack aLiquid) { + if (aLiquid != null && this.getRecipeMap() != null) { + Collection<GT_Recipe> tRecipeList = this.getRecipeMap().mRecipeList; + if (tRecipeList != null) { + Iterator<GT_Recipe> arg3 = tRecipeList.iterator(); + + while (arg3.hasNext()) { + GT_Recipe tFuel = (GT_Recipe) arg3.next(); + FluidStack tLiquid; + if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null + && aLiquid.isFluidEqual(tLiquid)) { + return (int) ((long) tFuel.mSpecialValue * (long) this.mEfficiency + * (long) this.consumedFluidPerOperation(tLiquid) / 100L); + } + } + } + + return 0; + } else { + return 0; + } + } + + public int getFuelValue(ItemStack aStack) { + if (!GT_Utility.isStackInvalid(aStack) && this.getRecipeMap() != null) { + GT_Recipe tFuel = this.getRecipeMap().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, + (FluidStack[]) null, new ItemStack[]{aStack}); + return tFuel != null ? (int) ((long) tFuel.mSpecialValue * 1000L * (long) this.mEfficiency / 100L) : 0; + } else { + return 0; + } + } + + public ItemStack getEmptyContainer(ItemStack aStack) { + if (!GT_Utility.isStackInvalid(aStack) && this.getRecipeMap() != null) { + GT_Recipe tFuel = this.getRecipeMap().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, + (FluidStack[]) null, new ItemStack[]{aStack}); + return tFuel != null + ? GT_Utility.copy(new Object[]{tFuel.getOutput(0)}) + : GT_Utility.getContainerItem(aStack, true); + } else { + return null; + } + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java new file mode 100644 index 0000000000..83b8eae458 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java @@ -0,0 +1,332 @@ + +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import codechicken.nei.ItemStackMap; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.*; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.*; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.helpers.TreeFarmHelper; +import gtPlusPlus.xmod.gregtech.common.helpers.treefarm.TreeGenerator; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase { + + public static int CASING_TEXTURE_ID; + public static String mCasingName = "Advanced Cryogenic Casing"; + public static TreeGenerator mTreeData; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntityTreeFarm> STRUCTURE_DEFINITION = null; + + static { + new Thread("GTPP-TreeDataWorker") { + @Override + public void run() { + mTreeData = new TreeGenerator(); + } + }.start(); + } + + private static ItemStack aLeaves; + + public GregtechMetaTileEntityTreeFarm(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings2Misc, 15); + } + + public GregtechMetaTileEntityTreeFarm(final String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings2Misc, 15); + } + + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityTreeFarm(this.mName); + } + + @Override + public String getMachineType() { + return "Tree Farm"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings2Misc, 15); + } + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Converts EU to Oak Logs") + .addInfo("Eu Usage: 100% | Parallel: 1") + .addInfo("Requires a Saw or Chainsaw in GUI slot") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Sterile Farm Casing", 10) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + 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(CASING_TEXTURE_ID), + TextureFactory.of(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "VacuumFreezer"; + } + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + public boolean isCorrectMachinePart(final ItemStack aStack) { + // is correct part && either not powered tool or have enough power + return TreeFarmHelper.getPartType(aStack) != null && !GT_ModHandler.isElectricItem(aStack) || GT_ModHandler.canUseElectricItem(aStack, 1); + } + + public boolean checkRecipe(final ItemStack aStack) { + if (mTreeData == null) + // not finished somehow + return false; + if (aStack == null && !replaceTool()) + // no tool + return false; + if (!isCorrectMachinePart(aStack)) + // not a tool + return false; + if (mTreeData != null) { + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + this.mMaxProgresstime = 100; + this.mEUt = (int) tVoltage; + + 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); + } + + + int aChance = MathUtils.randInt(0, 10); + + try { + if (aChance < 8) { + ItemStackMap<Integer> allOutputs = new ItemStackMap<>(); + if (aLeaves == null) + aLeaves = ItemUtils.getSimpleStack(Blocks.leaves); + //1% Chance per Tick + for (int u = 0; u < (Math.max(4, (MathUtils.randInt((3 * tTier), 100) * tTier * tTier) / 14)); u++) { + AutoMap<ItemStack> aOutputs = mTreeData.generateOutput(0); + if (aOutputs.size() > 0) { + for (ItemStack aOutputItemStack : aOutputs) { + if (!GT_Utility.areStacksEqual(aLeaves, aOutputItemStack)) { + Integer oldStackSize = allOutputs.get(aOutputItemStack); + int oldStackSizeUnboxed = oldStackSize == null ? 0 : oldStackSize; + allOutputs.put(aOutputItemStack, oldStackSizeUnboxed + aOutputItemStack.stackSize); + } + } + } + } + + mOutputItems = allOutputs.entries().stream() + .map(e -> { + e.key.stackSize = e.value; + return e.key; + }).toArray(ItemStack[]::new); + } + } catch (Throwable t) { + t.printStackTrace(GT_Log.err); + } + return true; + } else { + return false; + } + } + + @Override + public boolean checkHatch() { + return super.checkHatch() && mEnergyHatches.size() == 1; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 - 8 && checkHatch(); + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntityTreeFarm> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntityTreeFarm>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"C~C", "C-C", "CCC"}, + {"CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntityTreeFarm::addTreeFarmList, CASING_TEXTURE_ID, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 15 + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addTreeFarmList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiTreeFarm; + } + + public int getDamageToComponent(final ItemStack aStack) { + return MathUtils.balance((int) (75 - ((GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).getMass()))), 5, 120); + } + + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public boolean replaceTool() { + ItemStack invItem = this.mInventory[1]; + if (invItem == null) { + for (GT_MetaTileEntity_Hatch_InputBus mInputBus : this.mInputBusses) { + for (int i = 0; i < mInputBus.mInventory.length; i++) { + ItemStack uStack = mInputBus.mInventory[i]; + if (uStack != null && TreeFarmHelper.getPartType(uStack) != null) { + this.setGUIItemStack(uStack); + return true; + } + } + } + } + return false; + } + + public boolean tryDamageTool(ItemStack invItem) { + if (invItem != null && invItem.getItem() instanceof GT_MetaGenerated_Tool) { + long aDmg = GT_MetaGenerated_Tool.getToolDamage(invItem); + long aDmgMax = GT_MetaGenerated_Tool.getToolMaxDamage(invItem); + if (aDmg < aDmgMax && GT_MetaGenerated_Tool.getPrimaryMaterial(invItem) != Materials._NULL) { + return GT_ModHandler.damageOrDechargeItem(invItem, 1, 0, null); + } + } + return false; + } + + @Override + public boolean doRandomMaintenanceDamage() { + ItemStack tSaw = mInventory[1]; + if (!isCorrectMachinePart(tSaw) || getRepairStatus() == 0) { + stopMachine(); + return false; + } + if (CORE.RANDOM.nextInt(200) == 0) { + if (!tryDamageTool(tSaw)) { + if (tSaw.getItem().isDamageable()) + addOutput(tSaw); + this.mInventory[1] = null; + if (!replaceTool()) + this.getBaseMetaTileEntity().disableWorking(); + tryDamageTool(tSaw); + } + } + return super.doRandomMaintenanceDamage(); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + replaceTool(); + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java new file mode 100644 index 0000000000..c84c5e162e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java @@ -0,0 +1,336 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_AlloyBlastSmelter +extends GregtechMeta_MultiBlockBase { + + private int mMode = 0; + private boolean isUsingControllerCircuit = false; + private static Item circuit; + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_AlloyBlastSmelter> STRUCTURE_DEFINITION = null; + + + public GregtechMetaTileEntity_AlloyBlastSmelter(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_AlloyBlastSmelter(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_AlloyBlastSmelter(this.mName); + } + + @Override + public String getMachineType() { + return "Fluid Alloy Cooker"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Alloy Blast Smelter") + .addInfo("20% Faster than the Electric Blast Furnace") + .addInfo("Allows Complex GT++ alloys to be created") + .addInfo("Circuit for recipe goes in the Input Bus or GUI slot") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, true) + .addController("Bottom Center") + .addCasingInfo("Blast Smelter Casings", 10) + .addCasingInfo("Blast Smelter Heat Containment Coils", 16) + .addInputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_AlloyBlastSmelter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_AlloyBlastSmelter>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CCC", "CCC"}, + {"HHH", "H-H", "HHH"}, + {"HHH", "H-H", "HHH"}, + {"C~C", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_AlloyBlastSmelter::addAlloyBlastSmelterList, TAE.GTPP_INDEX(15), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 15 + ) + ) + ) + ) + .addElement( + 'H', + ofBlock( + ModBlocks.blockCasingsMisc, 14 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 3, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 3, 0) && mCasing >= 10 && mEnergyHatches.size() == 1 && checkHatch(); + } + + public final boolean addAlloyBlastSmelterList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(208)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(15)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(15))}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public boolean requiresVanillaGtGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return "ElectricBlastFurnace"; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sAlloyBlastSmelterRecipes; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + if (this.getBaseMetaTileEntity().isServerSide()) { + //Get Controller Circuit + if (circuit == null) { + circuit = CI.getNumberedCircuit(0).getItem(); + } + if (aStack != null && aStack.getItem() == circuit) { + this.mMode = aStack.getItemDamage(); + return this.isUsingControllerCircuit = true; + } + else { + if (aStack == null) { + this.isUsingControllerCircuit = false; + return true; //Allowed empty + } + Logger.WARNING("Not circuit in GUI inputs."); + return this.isUsingControllerCircuit = false; + } + } + Logger.WARNING("No Circuit, clientside."); + return this.isUsingControllerCircuit = false; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + + if (this.getBaseMetaTileEntity().isServerSide()) { + //Get Controller Circuit + this.isUsingControllerCircuit = isCorrectMachinePart(aStack); + + final ArrayList<ItemStack> tInputList = this.getStoredInputs(); + for (int i = 0; i < (tInputList.size() - 1); i++) { + for (int j = i + 1; j < tInputList.size(); j++) { + if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { + if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) { + tInputList.remove(j--); + } else { + tInputList.remove(i--); + break; + } + } + } + } + + //Validity check + if ((isUsingControllerCircuit && tInputList.size() < 1) || (!isUsingControllerCircuit && tInputList.size() < 2)) { + Logger.WARNING("Not enough inputs."); + return false; + } + else if (isUsingControllerCircuit && tInputList.size() >= 1) { + tInputList.add(CI.getNumberedCircuit(this.mMode)); + } + + + final ItemStack[] tInputs = Arrays.copyOfRange(tInputList.toArray(new ItemStack[tInputList.size()]), 0, tInputList.size()); + + final ArrayList<FluidStack> tFluidList = this.getStoredFluids(); + for (int i = 0; i < (tFluidList.size() - 1); i++) { + for (int j = i + 1; j < tFluidList.size(); j++) { + if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { + if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { + tFluidList.remove(j--); + } else { + tFluidList.remove(i--); + break; + } + } + } + } + final FluidStack[] tFluids = Arrays.copyOfRange(tFluidList.toArray(new FluidStack[tInputList.size()]), 0, 1); + if (tInputList.size() > 1) { + final long tVoltage = this.getMaxInputVoltage(); + final byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + final GT_Recipe tRecipe = GTPP_Recipe.GTPP_Recipe_Map.sAlloyBlastSmelterRecipes.findRecipe(this.getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); + if ((tRecipe != null) && (tRecipe.isRecipeInputEqual(true, tFluids, tInputs))) { + Logger.WARNING("Found some Valid Inputs."); + this.mEfficiency = (10000 - ((this.getIdealStatus() - this.getRepairStatus()) * 1000)); + this.mEfficiencyIncrease = 10000; + if (tRecipe.mEUt <= 16) { + this.mEUt = (tRecipe.mEUt * (1 << (tTier - 1)) * (1 << (tTier - 1))); + this.mMaxProgresstime = (tRecipe.mDuration / (1 << (tTier - 1))); + } else { + this.mEUt = tRecipe.mEUt; + this.mMaxProgresstime = tRecipe.mDuration; + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + this.mOutputFluids = new FluidStack[]{tRecipe.getFluidOutput(0)}; + List<ItemStack> tOutPutItems = new ArrayList<ItemStack>(); + for (ItemStack tOut : tRecipe.mOutputs) { + if (ItemUtils.checkForInvalidItems(tOut)) { + tOutPutItems.add(tOut); + } + } + if (tOutPutItems.size() > 0) + this.mOutputItems = tOutPutItems.toArray(new ItemStack[tOutPutItems.size()]); + this.updateSlots(); + return true; + } + } + } + Logger.WARNING("Failed to find some Valid Inputs or Clientside."); + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiABS; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public int getAmountOfOutputs() { + return 2; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java new file mode 100644 index 0000000000..ecd4882516 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java @@ -0,0 +1,481 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.ArrayList; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.IonParticles; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_Cyclotron> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Cyclotron(int aID, String aName, String aNameRegional, int tier) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Cyclotron(String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Particle Accelerator"; + } + + public int tier(){ + return 5; + } + + @Override + public long maxEUStore() { + return 1800000000L; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return super.getServerGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + //return new CONTAINER_Cyclotron(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return super.getClientGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + //return new GUI_Cyclotron(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), Recipe_GT.Gregtech_Recipe_Map.sCyclotronRecipes.mNEIName); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Cyclotron(this.mName); + } + + @Override + public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { + return aSide != getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Cyclotron> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Cyclotron>builder() + .addShape(mName, transpose(new String[][]{ + { + " ", + " hhh ", + " hh hh ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " hh hh ", + " hhh ", + " ", + }, + { + " hhh ", + " hhccchh ", + " hcchhhcch ", + " hchh hhch ", + " hch hch ", + " hch hch ", + "hch hch", + "hch hch", + "hch hch", + " hch hch ", + " hch hch ", + " hchh hhch ", + " hcch~hcch ", + " hhccchh ", + " hhh ", + }, + { + " ", + " hhh ", + " hh hh ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " h h ", + " hh hh ", + " hhh ", + " ", + } + })) + .addElement( + 'h', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_Cyclotron::addCyclotronList, 44, 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasing(), getCasingMeta() + ) + ) + ) + ) + .addElement( + 'c', + ofBlock( + getCyclotronCoil(), getCyclotronCoilMeta() + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 7, 1, 12); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 7, 1, 12) && mCasing >= 40 && checkHatch(); + } + + public final boolean addCyclotronList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus && ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier >= 5){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy && ((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity).mTier >= 5){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus && ((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler && ((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input && ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public Block getCasing() { + return ModBlocks.blockCasings2Misc; + } + + public int getCasingMeta() { + return 10; + } + + public Block getCyclotronCoil() { + return ModBlocks.blockCasings2Misc; + } + + public int getCyclotronCoilMeta() { + return 9; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Super Magnetic Speed Shooter") + .addSeparator() + .addInfo("Particles are accelerated over 186 revolutions to 80% light speed") + .addInfo("Can produce a continuous beam current of 2.2 mA at 590 MeV") + .addInfo("Which will be extracted from the Isochronous Cyclotron") + .addSeparator() + .addInfo("Consists of the same layout as a Fusion Reactor") + .addInfo("Any external casing can be a hatch/bus, unlike Fusion") + .addInfo("Cyclotron Machine Casings around Cyclotron Coil Blocks") + .addInfo("All Hatches must be IV or better") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addCasingInfo("Cyclotron Machine Casings", 40) + .addCasingInfo("Cyclotron Coil", 32) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + ITexture[] sTexture; + if (aSide == aFacing) { + sTexture = new ITexture[]{Textures.BlockIcons.getCasingTextureForId(44), new GT_RenderedTexture(getIconOverlay())}; + } else { + if (!aActive) { + sTexture = new ITexture[]{Textures.BlockIcons.getCasingTextureForId(44)}; + } else { + sTexture = new ITexture[]{Textures.BlockIcons.getCasingTextureForId(44)}; + } + } + return sTexture; + } + + public IIconContainer getIconOverlay() { + if (this.getBaseMetaTileEntity().isActive()){ + return TexturesGtBlock.Overlay_MatterFab_Active_Animated; + } + return TexturesGtBlock.Overlay_MatterFab_Animated; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + + /*if (CORE.DEVENV) { + return this.checkRecipeGeneric(); + }*/ + this.fixAllMaintenanceIssue(); + + //log("Recipe Check."); + ArrayList<ItemStack> tItemList = getStoredInputs(); + ItemStack[] tItemInputs = tItemList.toArray(new ItemStack[tItemList.size()]); + ArrayList<FluidStack> tInputList = getStoredFluids(); + FluidStack[] tFluidInputs = tInputList.toArray(new FluidStack[tInputList.size()]); + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + GT_Recipe tRecipe = GTPP_Recipe.GTPP_Recipe_Map.sCyclotronRecipes.findRecipe(getBaseMetaTileEntity(), false, + gregtech.api.enums.GT_Values.V[tTier], tFluidInputs, tItemInputs); + if (tRecipe != null){ + if (tRecipe.isRecipeInputEqual(true, tFluidInputs, tItemInputs)) { + + this.mEfficiency = (10000 - ((getIdealStatus() - getRepairStatus()) * 1000)); + this.mEfficiencyIncrease = 10000; + this.mEUt = tRecipe.mEUt; + this.mMaxProgresstime = tRecipe.mDuration; + + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + final ItemStack[] outputs = new ItemStack[tRecipe.mOutputs.length]; + for (int i = 0; i < tRecipe.mOutputs.length; i++){ + if (this.getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(i)){ + Logger.WARNING("Adding a bonus output"); + outputs[i] = tRecipe.getOutput(i); + } + else { + Logger.WARNING("Adding null output"); + outputs[i] = null; + } + } + + for (ItemStack s : outputs) { + if (s != null) { + if (s.getItem() instanceof IonParticles) { + long aCharge = IonParticles.getChargeState(s); + if (aCharge == 0) { + IonParticles.setChargeState(s, MathUtils.getRandomFromArray(new int[] { + -5, -5, + -4, -4, -4, + -3, -3, -3, -3, -3, + -2, -2, -2, -2, -2, -2, -2, + -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, + 5, 5, 5, + 6, 6})); + } + } + } + } + + this.mOutputItems = outputs; + this.mOutputFluids = new FluidStack[] {tRecipe.getFluidOutput(0)}; + return true; + } + } + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.mOutputBusses.size() > 0) { + for (GT_MetaTileEntity_Hatch_OutputBus g : this.mOutputBusses) { + if (g != null) { + for (ItemStack s : g.mInventory) { + if (s != null) { + if (s.getItem() instanceof IonParticles) { + long aCharge = IonParticles.getChargeState(s); + if (aCharge == 0) { + IonParticles.setChargeState(s, MathUtils.getRandomFromArray(new int[] { + -5, -5, + -4, -4, -4, + -3, -3, -3, -3, -3, + -2, -2, -2, -2, -2, -2, -2, + -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, + 5, 5, 5, + 6, 6})); + } + } + } + } + } + } + } + this.fixAllMaintenanceIssue(); + return super.onRunningTick(aStack); + } + + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiCyclotron; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public String[] getExtraInfoData() { + String tier = tier() == 5 ? "I" : "II"; + float plasmaOut = 0; + int powerRequired = 0; + if (this.mLastRecipe != null) { + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float)this.mLastRecipe.getFluidOutput(0).amount / (float)this.mLastRecipe.mDuration; + } + } + + return new String[]{ + "COMET - Compact Cyclotron MK "+tier, + "EU Required: "+powerRequired+"EU/t", + "Stored EU: "+this.getEUVar()+" / "+maxEUStore()}; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @SuppressWarnings("deprecation") + public boolean turnCasingActive(final boolean status) { + if (this.mEnergyHatches != null) { + for (final GT_MetaTileEntity_Hatch_Muffler hatch : this.mMufflerHatches) { + hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { + hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch : this.mInputHatches) { + hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; + } + } + if (this.mMaintenanceHatches != null) { + for (final GT_MetaTileEntity_Hatch_Maintenance hatch : this.mMaintenanceHatches) { + hatch.mMachineBlock = status ? (byte) 44 : (byte) 44; + } + } + return true; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java new file mode 100644 index 0000000000..80eb09640d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java @@ -0,0 +1,623 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.*; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import ic2.core.init.BlocksItems; +import ic2.core.init.InternalName; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.WeightedRandomFishable; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_IndustrialFishingPond extends GregtechMeta_MultiBlockBase { + + private boolean isUsingControllerCircuit = false; + private static final Item circuit = CI.getNumberedCircuit(0).getItem(); + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_IndustrialFishingPond> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialFishingPond(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialFishingPond(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialFishingPond(this.mName); + } + + @Override + public String getMachineType() { + return "Fish Trap"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Fishing Pond") + .addInfo("Can process (Tier + 1) * 2 recipes") + .addInfo("Put a numbered circuit into the input bus.") + .addInfo("Circuit 14 for Fish") + .addInfo("Circuit 15 for Junk") + .addInfo("Circuit 16 for Treasure") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(9, 3, 9, true) + .addController("Front Center") + .addCasingInfo("Aquatic Casings", 64) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // fuck + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialFishingPond> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialFishingPond>builder() + .addShape(mName, transpose(new String[][]{ + {"XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", "X X", "XXXXXXXXX"}, + {"XXXX~XXXX", "X X", "X X", "X X", "X X", "X X", "X X", "X X", "XXXXXXXXX"}, + {"XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX"}, + })) + .addElement( + 'X', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_IndustrialFishingPond::addIndustrialFishingPondList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public final boolean addIndustrialFishingPondList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 4, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 4, 1, 0) && mCasing >= 64 && checkHatch(); + } + + @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()), + new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE + : Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER) }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex()) }; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + if (aStack != null) { + log("Found " + aStack.getDisplayName()); + if (aStack.getItem() == circuit) { + this.isUsingControllerCircuit = true; + this.mMode = aStack.getItemDamage(); + log("Found Circuit!"); + } else { + this.isUsingControllerCircuit = false; + } + } else { + this.isUsingControllerCircuit = false; + } + if (!hasGenerateRecipes) { + log("Generating Recipes."); + generateRecipes(); + } + if (hasGenerateRecipes) { + if (!checkForWater()) { + return false; + } + + log("Trying to run recipe."); + ArrayList<ItemStack> tItems = getStoredInputs(); + ArrayList<FluidStack> tFluids = getStoredFluids(); + ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); + FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); + + if (!isUsingControllerCircuit && tItems.size() == 0) { + return false; + } + + return checkRecipeGeneric(tItemInputs, tFluidInputs, getMaxParallelRecipes(), 100, 80, 100); + } + return true; + } + + @Override + public int getMaxParallelRecipes() { + return (2 * (GT_Utility.getTier(this.getMaxInputVoltage())+1)); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialFishingPond; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public int getCasingTextureIndex() { + return TAE.GTPP_INDEX(32); + } + + public boolean checkForWater() { + + // Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + mCurrentDirectionX = 4; + mCurrentDirectionZ = 4; + + mOffsetX_Lower = -4; + mOffsetX_Upper = 4; + mOffsetZ_Lower = -4; + mOffsetZ_Upper = 4; + + // if (aBaseMetaTileEntity.fac) + + final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX + * mCurrentDirectionX; + final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ + * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; h++) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + // byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = Blocks.water; + aBaseMetaTileEntity.getWorld().setBlock( + aBaseMetaTileEntity.getXCoord() + xDir + i, + aBaseMetaTileEntity.getYCoord() + h, + aBaseMetaTileEntity.getZCoord() + zDir + j, fluidUsed); + + } + } + } + } + } + tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { + ++tAmount; + // log("Found Water"); + } + } + } + } + + boolean isValidWater = tAmount >= 60; + + if (isValidWater) { + log("Filled structure."); + return true; + } + else { + + long aAvgVoltage = 0; + for (GT_MetaTileEntity_Hatch_Energy g : this.mEnergyHatches) { + if (g != null) { + aAvgVoltage += (g.maxEUInput() * g.maxAmperesIn()); + } + } + this.mEUt = (int) Math.max(30, aAvgVoltage); + this.mMaxProgresstime = (int) Math.max(((aAvgVoltage/8)*20/10), 100); + this.mProgresstime = 1; + log("Did not fill structure. Consuming "+aAvgVoltage+"eu/t to try fill."); + return false; + } + } + + private static AutoMap<AutoMap<WeightedRandomFishable>> categories = new AutoMap<AutoMap<WeightedRandomFishable>>(); + private static AutoMap<WeightedRandomFishable> categoryFish = new AutoMap<WeightedRandomFishable>(); + private static AutoMap<WeightedRandomFishable> categoryJunk = new AutoMap<WeightedRandomFishable>(); + private static AutoMap<WeightedRandomFishable> categoryLoot = new AutoMap<WeightedRandomFishable>(); + private static boolean hasGenerateRecipes = false; + private int mMode = 14; + private int mMax = 8; + + private boolean generateRecipes() { + if (!hasGenerateRecipes) { + categories.put(categoryFish); + categories.put(categoryJunk); + categories.put(categoryLoot); + for (WeightedRandomFishable h : FishPondFakeRecipe.fish) { + categoryFish.put(h); + } + for (WeightedRandomFishable h : FishPondFakeRecipe.junk) { + categoryJunk.put(h); + } + for (WeightedRandomFishable h : FishPondFakeRecipe.treasure) { + categoryLoot.put(h); + } + hasGenerateRecipes = true; + return true; + } else { + return true; + } + } + + private int getCircuit(ItemStack[] t) { + if (!this.isUsingControllerCircuit) { + for (ItemStack j : t) { + if (j.getItem() == CI.getNumberedCircuit(0).getItem()) { + // Fish + if (j.getItemDamage() == 14) { + mMax = 8 + (this.getMaxParallelRecipes() - 2); + this.mMode = 14; + break; + } + // Junk + else if (j.getItemDamage() == 15) { + this.mMode = 15; + mMax = 4; + break; + } + // Loot + else if (j.getItemDamage() == 16) { + this.mMode = 16; + mMax = 4; + break; + } else { + this.mMode = 0; + mMax = 0; + break; + } + } else { + this.mMode = 0; + mMax = 0; + break; + } + } + } + return this.mMode; + } + + // reflection map + private static Map<WeightedRandomFishable, ItemStack> reflectiveFishMap = new HashMap<WeightedRandomFishable, ItemStack>(); + + private ItemStack reflectiveFish(WeightedRandomFishable y) { + if (reflectiveFishMap.containsKey(y)) { + return reflectiveFishMap.get(y); + } + ItemStack t; + try { + t = (ItemStack) ReflectionUtils.getField(WeightedRandomFishable.class, "field_150711_b").get(y); + ItemStack k = ItemUtils.getSimpleStack(t, 1); + reflectiveFishMap.put(y, k); + return t; + } catch (IllegalArgumentException | IllegalAccessException e) { + } + return null; + } + + private ItemStack[] generateLoot(int mode) { + ItemStack[] mFishOutput = new ItemStack[this.mMax]; + if (this.mMode == 14) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) + for (WeightedRandomFishable g : categoryFish.values()) { + if (MathUtils.randInt(0, (65 - getMaxParallelRecipes())) <= 2) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else if (this.mMode == 15) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) + for (WeightedRandomFishable g : categoryJunk.values()) { + if (MathUtils.randInt(0, 100) <= 1) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else if (this.mMode == 16) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) + for (WeightedRandomFishable g : categoryLoot.values()) { + if (MathUtils.randInt(0, 1000) <= 2) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else { + mFishOutput = null; + } + return mFishOutput; + } + + @Override + public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, + int aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { + + + + //Control Core to control the Multiblocks behaviour. + int aControlCoreTier = getControlCoreTier(); + + //If no core, return false; + if (aControlCoreTier == 0 && CORE.ConfigSwitches.requireControlCores) { + log("Invalid/No Control Core"); + return false; + } + + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + log("Running checkRecipeGeneric(0)"); + + //Check to see if Voltage Tier > Control Core Tier + if (tTier > aControlCoreTier && CORE.ConfigSwitches.requireControlCores) { + return false; + } + + // Based on the Processing Array. A bit overkill, but very flexible. + getCircuit(aItemInputs); + + /* + * GT_Recipe tRecipe = this.getRecipeMap().findRecipe( getBaseMetaTileEntity(), + * mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, + * aItemInputs); + */ + + ItemStack[] mFishOutput = generateLoot(this.mMode); + mFishOutput = removeNulls(mFishOutput); + GT_Recipe g = new GTPP_Recipe(true, new ItemStack[] {}, mFishOutput, null, new int[] {}, aFluidInputs, mOutputFluids, 200, 16, 0); + aMaxParallelRecipes = this.canBufferOutputs(g, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("No Space"); + return false; + } + + log("Mode: " + this.mMode + " | Is loot valid? " + (mFishOutput != null)); + + int jslot = 0; + for (ItemStack x : mFishOutput) { + if (x != null) { + log( + "Slot " + jslot + " in mFishOutput contains " + x.stackSize + "x " + x.getDisplayName() + "."); + } else { + log("Slot " + jslot + " in mFishOutput was null."); + } + jslot++; + } + + // EU discount + float tRecipeEUt = (8 * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: "+parallelRecipes); + log("aMaxParallelRecipes: "+aMaxParallelRecipes); + log("tTotalEUt: "+tTotalEUt); + log("tVoltage: "+tVoltage); + log("tRecipeEUt: "+tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) { + log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int)(20 * tTimeFactor * 4); + + this.mEUt = (int)Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + + //Only Overclock as high as the control circuit. + byte tTierOld = tTier; + tTier = CORE.ConfigSwitches.requireControlCores ? (byte) aControlCoreTier : tTierOld; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + + log("Recipe Step. [3]"); + // Collect output item types + ItemStack[] tOutputItems = mFishOutput; + + int rslot = 0; + tOutputItems = removeNulls(mFishOutput); + + for (ItemStack x : tOutputItems) { + if (x != null) { + log( + "rSlot " + rslot + " in mFishOutput contains " + x.stackSize + "x " + x.getDisplayName() + "."); + } else { + log("rSlot " + rslot + " in mFishOutput was null."); + } + rslot++; + } + + // Commit outputs + this.mOutputItems = tOutputItems; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + return true; + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java new file mode 100644 index 0000000000..d9162cea89 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java @@ -0,0 +1,629 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.ArrayList; +import java.util.Collection; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GTPP_Recipe; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.RocketFuels; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.material.MISC_MATERIALS; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_AirIntake; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler_Adv; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_LargeRocketEngine extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargeRocketEngine> +{ + protected int fuelConsumption; + protected int fuelValue; + protected int fuelRemaining; + protected int freeFuelTicks = 0; + protected int euProduction = 0; + protected boolean boostEu; + + public static String mLubricantName = "Carbon Dioxide"; + public static String mCoolantName = "Liquid Hydrogen"; + + public static String mCasingName = "Turbodyne Casing"; + public static String mIntakeHatchName = "Tungstensteel Turbine Casing"; + public static String mGearboxName = "Inconel Reinforced Casing"; + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_LargeRocketEngine> STRUCTURE_DEFINITION = null; + + private final static int CASING_ID = TAE.getIndexFromPage(3, 11); + + public GregtechMetaTileEntity_LargeRocketEngine(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + this.fuelConsumption = 0; + this.fuelValue = 0; + this.fuelRemaining = 0; + this.boostEu = false; + } + + public GregtechMetaTileEntity_LargeRocketEngine(final String aName) { + super(aName); + this.fuelConsumption = 0; + this.fuelValue = 0; + this.fuelRemaining = 0; + this.boostEu = false; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 11); + } + if (mIntakeHatchName.toLowerCase().contains(".name")) { + mIntakeHatchName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 11); + } + if (mGearboxName.toLowerCase().contains(".name")) { + mGearboxName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 1); + } + if (mLubricantName.toLowerCase().contains(".")) { + mLubricantName = FluidUtils.getFluidStack("carbondioxide", 1).getLocalizedName(); + } + if (mCoolantName.toLowerCase().contains(".")) { + mCoolantName = FluidUtils.getFluidStack("liquidhydrogen", 1).getLocalizedName(); + } + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Rocket Engine") + .addInfo("Supply Rocket Fuels and 1000L(3000L boosted) of " + mLubricantName + " per hour to run") + .addInfo("Supply 4L of " + mCoolantName + " per second per 2100 eu/t to boost output (optional)") + .addInfo("Consumes 2000L/s of air per 16384 eu/t produced") + .addInfo("Produces as much energy as you put fuel in") + .addInfo("Produces 1500 pollution/S per 16384 eu/t produced") + .addInfo("When producing more then 32K eu/t fuel wil be consume less efficiently (3x - 1.5x eff@57Keu/t input energy)") + .addInfo("formula: x = input of energy (10K^(1/3)/ x^(1/3)) * (40K^(1/3)/ x^(1/3))") + .addInfo("Boosting will produce 3x the amount of power but will consume 3x fuel") + .addSeparator() + .beginStructureBlock(3, 3, 10, false) + .addController("Front Center") + .addCasingInfo(mCasingName, 64) + .addCasingInfo(mGearboxName, 8) + .addStructureHint("Air Intake Hatch", 1) + .addInputBus("Side center line", 1) + .addInputHatch("Side center line", 1) + .addMaintenanceHatch("Side center line", 1) + .addDynamoHatch("Top center line", 2) + .addMufflerHatch("Back Center", 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_LargeRocketEngine> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_LargeRocketEngine>builder() + .addShape(mName, transpose(new String[][]{ + {"CCC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CCC"}, + {"C~C", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "CMC"}, + {"CCC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CCC"}, + })) + .addElement( + 'C', + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + .addElement( + 'I', + ofBlock( + getGearboxBlock(), getGearboxMeta() + ) + ) + .addElement( + 'T', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_LargeRocketEngine::addLargeRocketEngineTopList, getCasingTextureIndex(), 2 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + ) + ) + .addElement( + 'S', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_LargeRocketEngine::addLargeRocketEngineSideList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + ) + ) + .addElement( + 'M', + ofHatchAdder( + GregtechMetaTileEntity_LargeRocketEngine::addLargeRocketEngineBackList, getCasingTextureIndex(), 3 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + this.mTecTechDynamoHatches.clear(); + this.mAllDynamoHatches.clear(); + this.mAirIntakes.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 64 - 48 && mAirIntakes.size() >= 8 && checkHatch(); + } + + public final boolean addLargeRocketEngineTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } if (LoadedMods.TecTech) { + if (isThisHatchMultiDynamo(aMetaTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + } + return false; + } + + public final boolean addLargeRocketEngineSideList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addLargeRocketEngineBackList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @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(CASING_ID), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced) }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_ID) }; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return this.getMaxEfficiency(aStack) > 0; + } + + @Override + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return super.getClientGUI(aID, aPlayerInventory, aBaseMetaTileEntity); + } + + public int getAir() { + if (this.mAirIntakes.isEmpty() || this.mAirIntakes.size() <= 0) { + return 0; + } + else { + int totalAir = 0; + FluidStack airstack = FluidUtils.getFluidStack("air", 1); + for (GT_MetaTileEntity_Hatch_AirIntake u : this.mAirIntakes) { + if (u != null && u.mFluid != null) { + // had this trow errors cousing the machine to stop probebly fixed + FluidStack f = u.mFluid; + if (f.isFluidEqual(airstack)) { + totalAir += f.amount; + } + } + } + return totalAir; + } + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + final ArrayList<FluidStack> tFluids = this.getStoredFluids(); + FluidStack air = FluidUtils.getFluidStack("air", 1); + + int aircount = getAir() ; + if (aircount < euProduction/100) { + //log("Not Enough Air to Run "+aircount); + return false; + } + else { + boolean hasIntakeAir = this.depleteInput(FluidUtils.getFluidStack(air, euProduction/100)); + if (!hasIntakeAir) { + //log("Could not consume Air to run "+aircount); + freeFuelTicks = 0; + return false; + } + } + // reste fuel ticks incase it does not reset when it stops + if (freeFuelTicks != 0 && this.mProgresstime == 0 && this.mEfficiency == 0) + freeFuelTicks = 0; + + //log("Running "+aircount); + log("looking at hatch"); + final Collection<GT_Recipe> tRecipeList = GTPP_Recipe.GTPP_Recipe_Map.sRocketFuels.mRecipeList; + + + if (tFluids.size() > 0 && tRecipeList != null) { + + if (tFluids.contains(MISC_MATERIALS.CARBON_DIOXIDE.getFluidStack(this.boostEu ? 3 : 1)) || tFluids.contains(FluidUtils.getFluidStack("carbondioxide", (this.boostEu ? 3 : 1)))) { + if (this.mRuntime % 72 == 0 || this.mRuntime == 0) { + if (!consumeCO2()) { + freeFuelTicks = 0; + return false; + } + } + } else + { + freeFuelTicks = 0; + return false; + } + + if (freeFuelTicks == 0) + this.boostEu = consumeLOH(); + + for (final FluidStack hatchFluid1 : tFluids) { + if (hatchFluid1.isFluidEqual(air)) { + continue; + } + + if (freeFuelTicks == 0) { + for (final GT_Recipe aFuel : tRecipeList) { + final FluidStack tLiquid; + tLiquid = aFuel.mFluidInputs[0]; + if (hatchFluid1.isFluidEqual(tLiquid)) { + if (!consumeFuel(aFuel,hatchFluid1.amount)) { + continue; + } + this.fuelValue = aFuel.mSpecialValue; + this.fuelRemaining = hatchFluid1.amount; + this.mEUt = (int) ((this.mEfficiency < 2000) ? 0 : GT_Values.V[5]<<1); + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = euProduction/2000; + return true; + //log(""); + } + } + + } else + { + this.mEfficiencyIncrease = euProduction/2000; + freeFuelTicks--; + this.mEUt = (int) ((this.mEfficiency < 1000) ? 0 : GT_Values.V[5]<<1); + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + return true; + } + + } + } + this.mEUt = 0; + this.mEfficiency = 0; + freeFuelTicks = 0; + return false; + } + + /** + * Consumes Fuel if required. Free Fuel Ticks are handled here. + * @param aFuel + * @return + */ + public boolean consumeFuel(GT_Recipe aFuel,int amount) { + amount *= this.boostEu ? 0.3 : 0.9; + freeFuelTicks = 0; + int value = aFuel.mSpecialValue * 3; + int energy = value * amount; + if (amount < 5) + return false; + FluidStack tLiquid = FluidUtils.getFluidStack(aFuel.mFluidInputs[0], (this.boostEu ? amount * 3 : amount)); + if (!this.depleteInput(tLiquid)) { + return false; + } + else { + this.fuelConsumption = this.boostEu ? amount * 3 : amount; + this.freeFuelTicks = 20; + setEUProduction(energy); + return true; + } + } + + public void setEUProduction(int energy){ + energy /= 20; + double energyEfficiency; + double tDevideEnergy = Math.cbrt(energy); + if (energy > 10000) { + //cbrt(10 000) / + energyEfficiency = ((double) 21.5443469/tDevideEnergy); + if (energy >= 40000) + //cbrt(40 000) / + energyEfficiency *= ((double)34.19951893/tDevideEnergy); + energyEfficiency *= energy; + } + else { + energyEfficiency = energy; + } + euProduction = (int) ((double) energyEfficiency * 1.84); + if (this.boostEu) + euProduction *= 3; + } + + public boolean consumeCO2() { + if (this.depleteInput(MISC_MATERIALS.CARBON_DIOXIDE.getFluidStack(this.boostEu ? 3 : 1)) || this.depleteInput(FluidUtils.getFluidStack("carbondioxide", (this.boostEu ? 3 : 1)))) { + return true; + } + else { + return false; + } + } + + public boolean consumeLOH() { + int LOHamount = (3 * euProduction)/1000; + return this.depleteInput(FluidUtils.getFluidStack(RocketFuels.Liquid_Hydrogen, LOHamount)); //(40 * ((long) euProduction / 10000)) + } + + @Override + public boolean addEnergyOutput(long aEU) { + if (aEU <= 0) { + return true; + } + if (mAllDynamoHatches.size() > 0) { + return addEnergyOutputMultipleDynamos(aEU, true); + } + return false; + } + + + public boolean addEnergyOutputMultipleDynamos(long aEU, boolean aAllowMixedVoltageDynamos) { + int injected = 0; + long totalOutput = 0; + long aFirstVoltageFound = -1; + boolean aFoundMixedDynamos = false; + for (GT_MetaTileEntity_Hatch aDynamo : mAllDynamoHatches) { + if( aDynamo == null ) { + return false; + } + if (isValidMetaTileEntity(aDynamo)) { + long aVoltage = aDynamo.maxEUOutput(); + long aTotal = aDynamo.maxAmperesOut() * aVoltage; + // Check against voltage to check when hatch mixing + if (aFirstVoltageFound == -1) { + aFirstVoltageFound = aVoltage; + } + else { + /** + * Calcualtes overclocked ness using long integers + * @param aEUt - recipe EUt + * @param aDuration - recipe Duration + * @param mAmperage - should be 1 ? + */ + //Long time calculation + if (aFirstVoltageFound != aVoltage) { + aFoundMixedDynamos = true; + } + } + totalOutput += aTotal; + } + } + + if (totalOutput < aEU || (aFoundMixedDynamos && !aAllowMixedVoltageDynamos)) { + explodeMultiblock(); + return false; + } + + long leftToInject; + //Long EUt calculation + long aVoltage; + //Isnt too low EUt check? + int aAmpsToInject; + int aRemainder; + + //xEUt *= 4;//this is effect of everclocking + for (GT_MetaTileEntity_Hatch aDynamo : mAllDynamoHatches) { + if (isValidMetaTileEntity(aDynamo)) { + leftToInject = aEU - injected; + aVoltage = aDynamo.maxEUOutput(); + aAmpsToInject = (int) (leftToInject / aVoltage); + aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); + long powerGain; + for (int i = 0; i < Math.min(aDynamo.maxAmperesOut(), aAmpsToInject + 1); i++) { + if (i == Math.min(aDynamo.maxAmperesOut(), aAmpsToInject)){ + powerGain = aRemainder; + }else{ + powerGain = aVoltage; + } + aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(powerGain, false); + injected += powerGain; + } + } + } + return injected > 0; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.mRuntime%20 == 0) { + if (mMufflerHatches.size() == 1 && mMufflerHatches.get(0) instanceof GT_MetaTileEntity_Hatch_Muffler_Adv) { + GT_MetaTileEntity_Hatch_Muffler_Adv tMuffler = (GT_MetaTileEntity_Hatch_Muffler_Adv) mMufflerHatches.get(0); + if (!tMuffler.hasValidFilter()) { + ArrayList<ItemStack> tInputs = getStoredInputs(); + for (ItemStack tItem : tInputs) { + if (tMuffler.isAirFilter(tItem)) { + tMuffler.mInventory[0] = tItem.copy(); + depleteInput(tItem); + updateSlots(); + break; + } + } + } + } + } + super.onRunningTick(aStack); + return true; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + public byte getCasingMeta() { + return 11; + } + + public Block getGearboxBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getGearboxMeta() { + return 1; + } + + public byte getCasingTextureIndex() { + return (byte) CASING_ID; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_LargeRocketEngine(this.mName); + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("freeFuelTicks", freeFuelTicks); + aNBT.setInteger("euProduction", euProduction); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + freeFuelTicks = aNBT.getInteger("freeFuelTicks"); + euProduction = aNBT.getInteger("euProduction"); + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 1; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return euProduction; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 75 * ( euProduction / 10000); + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return true; + } + + @Override + public String[] getExtraInfoData() { + return new String[] { + "Rocket Engine", + "Current Air: "+getAir(), + "Current Pollution: " + getPollutionPerTick(null), + "Time until next fuel consumption: "+freeFuelTicks, + "Current Output: " + this.mEUt * this.mEfficiency / 10000 + " EU/t", + "Fuel Consumption: " + (this.fuelConsumption) + "L/s", + "Fuel Value: " + this.fuelValue*3 + " EU/L", + "Fuel Remaining: " + this.fuelRemaining + " Litres", + "Current Efficiency: " + this.mEfficiency / 100 + "%", + (this.getIdealStatus() == this.getRepairStatus()) ? "No Maintainance issues" : "Needs Maintainance" }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Rocket Engine"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java new file mode 100644 index 0000000000..9be787e922 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java @@ -0,0 +1,341 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.ArrayList; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.block.Block; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_LargeSemifluidGenerator extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_LargeSemifluidGenerator> STRUCTURE_DEFINITION = null; + + protected int fuelConsumption = 0; + protected int fuelValue = 0; + protected int fuelRemaining = 0; + protected boolean boostEu = false; + + public GregtechMetaTileEntity_LargeSemifluidGenerator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_LargeSemifluidGenerator(String aName) { + super(aName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Semifluid Generator") + .addInfo("Engine Intake Casings must not be obstructed in front (only air blocks)") + .addInfo("Supply Semifluid Fuels and 2000L of Lubricant per hour to run.") + .addInfo("Supply 80L of Oxygen per second to boost output (optional).") + .addInfo("Default: Produces 2048EU/t at 100% efficiency") + .addInfo("Boosted: Produces 6144EU/t at 150% efficiency") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 4, false) + .addController("Front Center") + .addCasingInfo("Stable Titanium Machine Casing", 16) + .addCasingInfo("Steel Gear Box Machine Casing", 2) + .addCasingInfo("Engine Intake Machine Casing", 8) + .addInputHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .addDynamoHatch("Back Center", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(50), new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(50)}; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeDieselEngine.png"); + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + ArrayList<FluidStack> tFluids = getStoredFluids(); + + // Check for lubricant and oxygen first, so we can compute costs ahead of time. + // This will allow us to check costs without needing to actually try to deplete fluids + // (wasting earlier fluids in the check if later fluids turn out to be insufficient). + FluidStack lubricant = Materials.Lubricant.getFluid(0L); + FluidStack oxygen = Materials.Oxygen.getGas(0L); + for (FluidStack hatchFluid : tFluids) { + if (hatchFluid.isFluidEqual(lubricant)) { + lubricant.amount = Math.max(lubricant.amount, hatchFluid.amount); + } else if (hatchFluid.isFluidEqual(oxygen)) { + oxygen.amount = Math.max(oxygen.amount, hatchFluid.amount); + } + } + boostEu = oxygen.amount >= 4L; + long lubricantCost = boostEu ? 2L : 1L; + if (lubricant.amount < lubricantCost) { + return false; + } + + for (FluidStack hatchFluid : tFluids) { //Loops through hatches + GT_Recipe aFuel = GTPP_Recipe_Map.sSemiFluidLiquidFuels.findFuel(hatchFluid); + if (aFuel == null) { + // Not a valid semi-fluid fuel. + continue; + } + + int newEUt = boostEu ? 4096 : 2048; + fuelConsumption = newEUt / aFuel.mSpecialValue; //Calc fuel consumption + FluidStack tLiquid = new FluidStack(hatchFluid.getFluid(), fuelConsumption); + if(depleteInput(tLiquid)) { //Deplete that amount + // We checked beforehand, so both of these depletions should succeed. + // But check the return values anyway just to be safe. + if (boostEu) { + if (!depleteInput(Materials.Oxygen.getGas(4L))) { + return false; + } + } + //Deplete Lubricant. 2000L should = 1 hour of runtime (if baseEU = 2048) + if(mRuntime % 72 == 0 || mRuntime == 0) { + if(!depleteInput(Materials.Lubricant.getFluid(lubricantCost))) { + return false; + } + } + + fuelValue = aFuel.mSpecialValue; + fuelRemaining = hatchFluid.amount; //Record available fuel + this.mEUt = mEfficiency < 2000 ? 0 : newEUt; //Output 0 if startup is less than 20% + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 15; + return true; + } + } + + this.mEUt = 0; + this.mEfficiency = 0; + return false; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_LargeSemifluidGenerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_LargeSemifluidGenerator>builder() + .addShape(mName, transpose(new String[][]{ + {"III", "CCC", "CCC", "CCC"}, + {"I~I", "CGC", "CGC", "CMC"}, + {"III", "CCC", "CCC", "CCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_LargeSemifluidGenerator::addLargeSemifluidGeneratorList, getCasingTextureIndex(), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + getCasingBlock(), getCasingMeta() + ) + ) + ) + ) + .addElement( + 'G', + ofBlock( + getGearboxBlock(), getGearboxMeta() + ) + ) + .addElement( + 'I', + ofBlock( + getIntakeBlock(), getIntakeMeta() + ) + ) + .addElement( + 'M', + ofHatchAdder( + GregtechMetaTileEntity_LargeSemifluidGenerator::addLargeSemifluidGeneratorBackList, getCasingTextureIndex(), 2 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mDynamoHatches.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 16 && checkHatch(); + } + + public final boolean addLargeSemifluidGeneratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addLargeSemifluidGeneratorBackList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo || this.isThisHatchMultiDynamo(aTileEntity)){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public Block getCasingBlock() { + return GregTech_API.sBlockCasings4; + } + + public byte getCasingMeta() { + return 2; + } + + public Block getIntakeBlock() { + return GregTech_API.sBlockCasings4; + } + + public byte getIntakeMeta() { + return 13; + } + + public Block getGearboxBlock() { + return GregTech_API.sBlockCasings2; + } + + public byte getGearboxMeta() { + return 3; + } + + public byte getCasingTextureIndex() { + return 50; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_LargeSemifluidGenerator(this.mName); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + public int getMaxEfficiency(ItemStack aStack) { + return boostEu ? 15000 : 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiLargeSemiFluidGenerator; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return true; + } + + @Override + public String[] getExtraInfoData() { + return new String[]{ + "Large Semifluid Generator", + "Current Output: " + mEUt * mEfficiency / 10000 + " EU/t", + "Fuel Consumption: " + fuelConsumption + "L/t", + "Fuel Value: " + fuelValue + " EU/L", + "Fuel Remaining: " + fuelRemaining + " Litres", + "Current Efficiency: " + (mEfficiency / 100) + "%", + getIdealStatus() == getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance"}; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Semifluid Generator"; + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java new file mode 100644 index 0000000000..f016288547 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java @@ -0,0 +1,425 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.ArrayList; +import java.util.Collection; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.ConfigCategories; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.*; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.gui.GUI_MatterFab; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlockBase { + + public static int sUUAperUUM = 1; + public static int sUUASpeedBonus = 4; + public static int sDurationMultiplier = 3200; + + private int mMatterProduced = 0; + private int mScrapProduced = 0; + private int mAmplifierProduced = 0; + private int mScrapUsed = 0; + private int mAmplifierUsed = 0; + + public static String mCasingName1 = "Matter Fabricator Casing"; + public static String mCasingName2 = "Containment Casing"; + public static String mCasingName3 = "Matter Generation Coil"; + + private int mMode = 0; + + private final static int MODE_SCRAP = 1; + private final static int MODE_UU = 0; + + public static boolean sRequiresUUA = false; + private static FluidStack[] mUU = new FluidStack[2]; + private static ItemStack mScrap[] = new ItemStack[2]; + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_MassFabricator> STRUCTURE_DEFINITION = null; + + public int getAmplifierUsed(){ + return this.mAmplifierUsed; + } + + public int getMatterProduced(){ + return this.mMatterProduced; + } + + public GregtechMetaTileEntity_MassFabricator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + mCasingName1 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasingsMisc, 9); + mCasingName2 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 15); + mCasingName3 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasingsMisc, 8); + } + + public GregtechMetaTileEntity_MassFabricator(final String aName) { + super(aName); + mCasingName1 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasingsMisc, 9); + mCasingName2 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 15); + mCasingName3 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasingsMisc, 8); + } + + @Override + public String getMachineType() { + return "Mass Fabricator / Recycler"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + + if (mCasingName1.toLowerCase().contains(".name")) { + mCasingName1 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasingsMisc, 9); + } + if (mCasingName2.toLowerCase().contains(".name")) { + mCasingName2 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings3Misc, 15); + } + if (mCasingName3.toLowerCase().contains(".name")) { + mCasingName3 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasingsMisc, 8); + } + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Matter Fabricator") + .addInfo("Produces UU-A, UU-M & Scrap") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 4, 5, true) + .addController("Front Center") + .addCasingInfo(mCasingName3, 9) + .addCasingInfo(mCasingName2, 24) + .addCasingInfo(mCasingName1, 40) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(9)), + new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_MatterFab_Active_Animated : TexturesGtBlock.Overlay_MatterFab_Animated)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(9))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MatterFabricator"; + } + + public static ItemStack getScrapPile() { + if (mScrap[0] == null) { + mScrap[0] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrap")); + } + return mScrap[0]; + } + public static ItemStack getScrapBox() { + if (mScrap[1] == null) { + mScrap[1] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrapbox")); + } + return mScrap[1]; + } + + @Override + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_MatterFab(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MatterFabricator.png"); + } + + @Override + public void onConfigLoad(final GT_Config aConfig) { + super.onConfigLoad(aConfig); + sDurationMultiplier = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUM_Duration_Multiplier", sDurationMultiplier); + sUUAperUUM = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_per_UUM", sUUAperUUM); + sUUASpeedBonus = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_Speed_Bonus", sUUASpeedBonus); + sRequiresUUA = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_Requirement", sRequiresUUA); + //Materials.UUAmplifier.mChemicalFormula = ("Mass Fabricator Eff/Speed Bonus: x" + sUUASpeedBonus); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + ArrayList<ItemStack> tItems = getStoredInputs(); + ArrayList<FluidStack> tFluids = getStoredFluids(); + ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); + FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); + return checkRecipeGeneric(tItemInputs, tFluidInputs, 4, 80, 00, 100); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_MassFabricator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_MassFabricator>builder() + .addShape(mName, transpose(new String[][]{ + {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"}, + {"CGGGC", "G---G", "G---G", "G---G", "CGGGC"}, + {"CGGGC", "G---G", "G---G", "G---G", "CGGGC"}, + {"CC~CC", "CHHHC", "CHHHC", "CHHHC", "CCCCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_MassFabricator::addMassFabricatorList, TAE.GTPP_INDEX(9), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasingsMisc, 9 + ) + ) + ) + ) + .addElement( + 'H', + ofBlock( + ModBlocks.blockCasingsMisc, 8 + ) + ) + .addElement( + 'G', + ofBlock( + ModBlocks.blockCasings3Misc, 15 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 2, 3, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 3, 0) && mCasing >= 40 && checkHatch(); + } + + public final boolean addMassFabricatorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiMassFabricator; + } + + @Override + public int getAmountOfOutputs() { + return 10; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_MassFabricator(this.mName); + } + + public boolean doesHatchContainUUA() { + if (mUU[0] == null) { + mUU[0] = Materials.UUAmplifier.getFluid(100); + } + if (mUU[1] == null) { + mUU[1] = Materials.UUMatter.getFluid(100); + } + + if (mUU[0] != null && mUU[1] != null) { + for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { + if (g.getFluid() != null) { + if (g.mFluid.isFluidEqual(mUU[0])) { + return true; + } + } + } + } + + return false; + } + + + /** + * Special Recipe Handling + */ + + + @Override + public GT_Recipe_Map getRecipeMap() { + return this.mMode == MODE_SCRAP ? GT_Recipe_Map.sRecyclerRecipes : GTPP_Recipe.GTPP_Recipe_Map.sMatterFab2Recipes; + //return Recipe_GT.Gregtech_Recipe_Map.sMatterFab2Recipes; + } + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, FluidStack[] aFluidInputs, + int aMaxParallelRecipes, int aEUPercent, + int aSpeedBonusPercent, int aOutputChanceRoll) { + + if (this.mMode == MODE_SCRAP) { + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + GT_Recipe c = new GTPP_Recipe(false, new ItemStack[] { GT_Utility.copyAmount(1, aItemInputs[0]) }, + GT_ModHandler.getRecyclerOutput(GT_Utility.copyAmount(64, aItemInputs[0]), 0) == null ? null + : new ItemStack[] { ItemList.IC2_Scrap.get(1) }, + null, new int[] { 2000 }, null, null, 100, + (int) gregtech.api.enums.GT_Values.V[2], 0); + + // EU discount + float tRecipeEUt = (c.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!c.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at "+parallelRecipes+"."); + break; + } + log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + this.mEUt = (int) gregtech.api.enums.GT_Values.V[tTier]; + this.mMaxProgresstime = 10; + return true; + } + + return super.checkRecipeGeneric(c, getMaxParallelRecipes(), getEuDiscountForParallelism(), aSpeedBonusPercent, aOutputChanceRoll, true); + } + + //Return normal Recipe handling + return super.checkRecipeGeneric(aItemInputs, aFluidInputs, getMaxParallelRecipes(), getEuDiscountForParallelism(), aSpeedBonusPercent, aOutputChanceRoll, true); + } + + @Override + public int getMaxParallelRecipes() { + return this.mMode == MODE_SCRAP ? 32 : 2 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); + } + + @Override + public int getEuDiscountForParallelism() { + return 80; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + int aMode = this.mMode + 1; + if (aMode > 1) { + this.mMode = MODE_UU; + PlayerUtils.messagePlayer(aPlayer, "Mode ["+this.mMode+"]: Matter/AmpliFabricator"); + } + else if (aMode == 1) { + this.mMode = MODE_SCRAP; + PlayerUtils.messagePlayer(aPlayer, "Mode ["+this.mMode+"]: Recycler"); + } + else { + this.mMode = MODE_SCRAP; + PlayerUtils.messagePlayer(aPlayer, "Mode ["+this.mMode+"]: Recycler"); + } + GT_Recipe_Map r = this.getRecipeMap(); + final Collection<GT_Recipe> x = r.mRecipeList; + Logger.INFO("Dumping " + r.mUnlocalizedName + " Recipes for Debug. size: "+x.size()); + for (final GT_Recipe newBo : x) { + Logger.INFO("========================"); + Logger.INFO("Dumping Input: " + ItemUtils.getArrayStackNames(newBo.mInputs)); + Logger.INFO("Dumping Inputs " + ItemUtils.getFluidArrayStackNames(newBo.mFluidInputs)); + Logger.INFO("Dumping Duration: " + newBo.mDuration); + Logger.INFO("Dumping EU/t: " + newBo.mEUt); + Logger.INFO("Dumping Output: " + ItemUtils.getArrayStackNames(newBo.mOutputs)); + Logger.INFO("Dumping Output: " + ItemUtils.getFluidArrayStackNames(newBo.mFluidOutputs)); + Logger.INFO("========================"); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mScrapProduced", mScrapProduced); + aNBT.setInteger("mAmplifierProduced", mAmplifierProduced); + aNBT.setInteger("mMatterProduced", mMatterProduced); + aNBT.setInteger("mScrapUsed", mScrapUsed); + aNBT.setInteger("mAmplifierUsed", mAmplifierUsed); + aNBT.setInteger("mMode", mMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mScrapProduced = aNBT.getInteger("mScrapProduced"); + mAmplifierProduced = aNBT.getInteger("mAmplifierProduced"); + mMatterProduced = aNBT.getInteger("mMatterProduced"); + mScrapUsed = aNBT.getInteger("mScrapUsed"); + mAmplifierUsed = aNBT.getInteger("mAmplifierUsed"); + mMode = aNBT.getInteger("mMode"); + super.loadNBTData(aNBT); + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java new file mode 100644 index 0000000000..f86ecf3196 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java @@ -0,0 +1,238 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.item.ItemStack; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase { + + private int mCasing; + private IStructureDefinition<GregtechMetaTileEntity_Refinery> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Refinery(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Refinery(final String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Fuel Refinery"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Fission Fuel Processing Unit") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 9, 3, false) + .addController("Bottom Center") + .addCasingInfo("Hastelloy-X Structural Casing", 7) + .addCasingInfo("Incoloy-DS Fluid Containment Block", 5) + .addCasingInfo("Zeron-100 Reactor Shielding", 4) + .addCasingInfo("Hastelloy-N Sealant Blocks", 17) + .addInputHatch("Base platform", 1) + .addOutputHatch("Base platform", 1) + .addOutputBus("Base platform", 1) + .addMufflerHatch("Base platform", 1) + .addMaintenanceHatch("Base platform", 1) + .addEnergyHatch("Base platform", 1) + .addStructureInfo("Muffler's Tier must be LuV+") + .addStructureInfo("4x Input Hatches, 2x Output Hatches, 1x Output Bus") + .addStructureInfo("1x Muffler, 1x Maintenance Hatch, 1x Energy Hatch") + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(18)), new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(18))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return "MatterFabricator"; + } + + @Override + public GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sFissionFuelProcessing; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + //this.resetRecipeMapForAllInputHatches(); + for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { + g.mRecipeMap = null; + } + boolean ab = super.checkRecipeGeneric(); + //Logger.INFO("Did Recipe? "+ab); + return ab; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + public final boolean addRefineryList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler && ((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity).mTier >= 6) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Refinery> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Refinery>builder() + .addShape(mName, transpose(new String[][]{ + {" ", " N ", " "}, + {" N ", "NIN", " N "}, + {" N ", "NIN", " N "}, + {" N ", "NIN", " N "}, + {" Z ", "ZIZ", " Z "}, + {" N ", "NIN", " N "}, + {"XXX", "XXX", "XXX"}, + {"X~X", "XXX", "XXX"}, + })) + .addElement( + 'X', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_Refinery::addRefineryList, TAE.GTPP_INDEX(18), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 2 + ) + ) + ) + ) + .addElement( + 'I', + ofBlock( + ModBlocks.blockCasings2Misc, 3 + ) + ) + .addElement( + 'N', + ofBlock( + ModBlocks.blockCasings2Misc, 1 + ) + ) + .addElement( + 'Z', + ofBlock( + ModBlocks.blockCasingsMisc, 13 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 1, 7, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + if (checkPiece(mName, 1, 7, 0) && mCasing >= 7) { + if (this.mInputHatches.size() == 4 && this.mOutputHatches.size() == 2 && + this.mOutputBusses.size() == 1 && this.mMufflerHatches.size() == 1 && + this.mMaintenanceHatches.size() == 1 && this.mEnergyHatches.size() == 1) { + this.resetRecipeMapForAllInputHatches(this.getRecipeMap()); + return true; + } + } + return false; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiRefinery; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public int getAmountOfOutputs() { + return 5; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Refinery(this.mName); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java new file mode 100644 index 0000000000..d42b33a403 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java @@ -0,0 +1,702 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.tileentities.misc.TileEntitySolarHeater; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +public class GregtechMetaTileEntity_SolarTower +extends GregtechMeta_MultiBlockBase { + + //862 + private static final int mCasingTextureID = TAE.getIndexFromPage(3, 4); + public static String mCasingName = ""; + private int mHeight = 0; + private int mHeatLevel = 0; + + public GregtechMetaTileEntity_SolarTower(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 4); + } + + public GregtechMetaTileEntity_SolarTower(final String aName) { + super(aName); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 4); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_SolarTower(this.mName); + } + + @Override + public String getMachineType() { + return "Solar Tower"; + } + + @Override + public String[] getTooltip() { + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 4); + } + return new String[]{ + "Contributing Green Energy towards the future", + mCasingName+"s for the base of the tower", + }; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(212)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == 0 || aSide == 1) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.getIndexFromPage(3, 6)), + new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.getIndexFromPage(3, 6))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing <= 1; + } + + private Set<String> mCachedReflectors = new HashSet<String>(); + + public Set<String> getConnectedSolarReflectors(){ + Set<String> mValidTilePositions = new HashSet<String>(); + IGregTechTileEntity tTileEntity; + Map<String, BlockPos> mFastMap = new HashMap<String, BlockPos>(); + for (int x = -64; x <= 64; x++) { + for (int z = -64; z <= 64; z++) { + int aX, aY, aZ; + aX = this.getBaseMetaTileEntity().getXCoord(); + aY = this.mHeight; + aZ = this.getBaseMetaTileEntity().getZCoord(); + BlockPos b = new BlockPos(aX+x, aY, aZ+z, this.getBaseMetaTileEntity().getWorld()); + + tTileEntity = getBaseMetaTileEntity().getIGregTechTileEntity(aX + x, this.mHeight, aZ + z); + if (tTileEntity == null) { + continue; + } + else { + Logger.INFO("Found Tile Entity at "+b.getLocationString()); + if (tTileEntity.getMetaTileEntity() instanceof TileEntitySolarHeater) { + TileEntitySolarHeater mTile = (TileEntitySolarHeater) tTileEntity.getMetaTileEntity(); + if (mTile != null) { + b = new BlockPos(tTileEntity.getXCoord(), tTileEntity.getYCoord(), tTileEntity.getZCoord(), tTileEntity.getWorld()); + if (!mTile.mHasTower || mTile.mSolarTower == null) { + Logger.INFO("Found Solar Reflector, Injecting Data."); + mTile.setSolarTower(b); + } + mFastMap.put(b.getUniqueIdentifier(), b); + } + } + else { + continue; + } + } + + if (addToMachineList(tTileEntity, mCasingTextureID)) { + continue; + } + } + } + + for (BlockPos p : mFastMap.values()) { + if (mValidTilePositions.add(p.getUniqueIdentifier())); + } + mCachedReflectors = mValidTilePositions; + return mCachedReflectors; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + //this.mEfficiencyIncrease = 100; + //this.mMaxProgresstime = 100; + //this.mEUt = -4; + return true; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public void startProcess() { + this.sendLoopStart((byte) 1); + } + + @Override + public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + this.mHeight = 0; + for (int i = 0; i <= 19; i++) { + if (!checkLayer(i)) { + Logger.INFO("Invalid Structure on Y level "+i); + return false; + } + } + if (mMaintenanceHatches.size() != 1) { + Logger.INFO("Bad Hatches"); + return false; + } + + this.mHeight = this.getBaseMetaTileEntity().getYCoord() - 19; + Logger.INFO("Built Structure"); + if (!aBaseMetaTileEntity.getWorld().isRemote) + getConnectedSolarReflectors(); + return true; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + + public byte getCasingMeta() { + return 4; + } + + + public byte getCasingMeta2() { + return 5; + } + + + public byte getCasingMeta3() { + return 6; + } + + public boolean isValidCasingBlock(Block aBlock, int aMeta) { + if (aBlock == getCasingBlock() && aMeta == getCasingMeta()) { + return true; + } + if (aBlock == getCasingBlock() && aMeta == getCasingMeta2()) { + return true; + } + if (aBlock == getCasingBlock() && aMeta == getCasingMeta3()) { + return true; + } + Logger.INFO("Found "+(aBlock != null ? aBlock.getLocalizedName() : "Air") + "With Meta "+aMeta); + return false; + } + + public byte getCasingTextureIndex() { + return (byte) mCasingTextureID; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (this.mHeight > 3) {} + + + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mHeight", mHeight); + aNBT.setInteger("mHeatLevel", mHeatLevel); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mHeight = aNBT.getInteger("mHeight"); + mHeatLevel = aNBT.getInteger("mHeatLevel"); + } + + public boolean checkLayer(int aY) { + if (aY >= 0 && aY <= 6) { + return checkTopLayers(-aY); + } + if (aY >= 7 && aY <= 16) { + return checkTowerLayer(-aY); + } + else if (aY >= 17 && aY <= 19) { + return checkBaseLayer(-aY); + } + Logger.INFO("Bad Y level to check"); + return false; + } + + public boolean checkTopLayers(int aY) { + Block aBlock; + int aMeta; + + if (aY == 0) { + return true; + } else if (aY == -1) { + for (int x = -1; x <= 1; x++) { + for (int z = -1; z <= 1; z++) { + aBlock = this.getBaseMetaTileEntity().getBlockOffset(x, aY, z); + aMeta = this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z); + if (aBlock == getCasingBlock() && aMeta == getCasingMeta3()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + } + } else if (aY == -2 || aY == -6) { + for (int x = -2; x <= 2; x++) { + for (int z = -2; z <= 2; z++) { + aBlock = this.getBaseMetaTileEntity().getBlockOffset(x, aY, z); + aMeta = this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z); + //Edge Casing + if (x == -2 || x == 2 || z == -2 || z == 2) { + //Edge Corners + if ((x == 2 || x == -2) && (z == 2 | z == -2)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Outside Corner "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + else { + continue; + } + } + else { + //Edge Sides + if (aBlock == getCasingBlock() && aMeta == getCasingMeta3()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + } + + //Internal + else { + if (aBlock == getCasingBlock() && aMeta == getCasingMeta2()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block Internally on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + } + } + } + //Top Layers 7x7 + else if (aY == -3 || aY == -5) { + for (int x = -3; x <= 3; x++) { + for (int z = -3; z <= 3; z++) { + aBlock = this.getBaseMetaTileEntity().getBlockOffset(x, aY, z); + aMeta = this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z); + //Edge Casing + if (x == -3 || x == 3 || z == -3 || z == 3) { + + //3, 3 + //2, 3 + //3, 2 + + //Air Spacing + if (x == 3 && (z == -3 || z == -2 || z == 2 || z == 3)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Outside Corner "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + else { + continue; + } + } + else if (x == -3 && (z == -3 || z == -2 || z == 2 || z == 3)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Outside Corner "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + else { + continue; + } + } + else if (z == 3 && (x == -3 || x == -2 || x == 2 || x == 3)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Outside Corner "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + else { + continue; + } + } + else if (z == -3 && (x == -3 || x == -2 || x == 2 || x == 3)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Outside Corner "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + else { + continue; + } + } + else { + //Edge Sides + if (aBlock == getCasingBlock() && aMeta == getCasingMeta3()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + } + else if ((x == -2 || x == 2) & (z == -2 || z == 2)) { + if (aBlock == getCasingBlock() && aMeta == getCasingMeta3()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + //Internal + else { + if (aBlock == getCasingBlock() && aMeta == getCasingMeta2()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block Internally on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + } + } + } + //Midle Top Layer 9x9 + else if (aY == -4) { + //Check Inner 5x5 + for (int x = -2; x <= 2; x++) { + for (int z = -2; z <= 2; z++) { + if (getBaseMetaTileEntity().getBlockOffset(x, aY, z) != getCasingBlock() && this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z) != getCasingMeta2()) { + Logger.INFO("Error at offset: X:" + x + ", Y:" + aY + ", Z:" + z); + return false; + } + else { + continue; + } + } + } + //Check Pos Sides + for (int z = -1; z <= -1; z++) { + if (getBaseMetaTileEntity().getBlockOffset(3, aY, z) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(3, aY, z) == getCasingMeta2()) { + continue; + } else if (getBaseMetaTileEntity().getBlockOffset(-3, aY, z) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(-3, aY, z) == getCasingMeta2()) { + continue; + } else { + Logger.INFO("1 Error at offset: X:3/-3" + ", Y:" + aY + ", Z:" + z); + return false; + } + + } + for (int x = -1; x <= -1; x++) { + if (getBaseMetaTileEntity().getBlockOffset(x, aY, 3) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, 3) == getCasingMeta2()) { + continue; + } else if (getBaseMetaTileEntity().getBlockOffset(x, aY, -3) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, -3) == getCasingMeta2()) { + continue; + } else { + Logger.INFO("1 Error at offset: X:" + x + ", Y:" + aY + ", Z:3/-3"); + return false; + } + } + + //Corner Casings + for (int z = -2; z <= -2; z++) { + if (z == -2 || z == 2) { + if (getBaseMetaTileEntity().getBlockOffset(3, aY, z) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(3, aY, z) == getCasingMeta3()) { + continue; + } else if (getBaseMetaTileEntity().getBlockOffset(-3, aY, z) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(-3, aY, z) == getCasingMeta3()) { + continue; + } else { + Logger.INFO("2 Error at offset: X:3/-3" + ", Y:" + aY + ", Z:" + z); + return false; + } + } + } + for (int x = -2; x <= -2; x++) { + if (x == -2 || x == 2) { + if (getBaseMetaTileEntity().getBlockOffset(x, aY, 3) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, 3) == getCasingMeta3()) { + continue; + } else if (getBaseMetaTileEntity().getBlockOffset(x, aY, -3) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, -3) == getCasingMeta3()) { + continue; + } else { + Logger.INFO("2 Error at offset: X:" + x + ", Y:" + aY + ", Z:3/-3"); + return false; + } + } + } + //Check Sides Casings + for (int z = -1; z <= -1; z++) { + if (getBaseMetaTileEntity().getBlockOffset(4, aY, z) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(4, aY, z) == getCasingMeta3()) { + continue; + } else if (getBaseMetaTileEntity().getBlockOffset(-4, aY, z) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(-4, aY, z) == getCasingMeta3()) { + continue; + } else { + Logger.INFO("1 Error at offset: X:3/-3" + ", Y:" + aY + ", Z:" + z); + return false; + } + + } + for (int x = -1; x <= -1; x++) { + if (getBaseMetaTileEntity().getBlockOffset(x, aY, 4) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, 4) == getCasingMeta3()) { + continue; + } else if (getBaseMetaTileEntity().getBlockOffset(x, aY, -4) == getCasingBlock() + && this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, -4) == getCasingMeta3()) { + continue; + } else { + Logger.INFO("1 Error at offset: X:" + x + ", Y:" + aY + ", Z:3/-3"); + return false; + } + } + } + return true; + } + + public boolean checkTowerLayer(int aY) { + Block aBlock; + int aMeta; + for (int x = -1; x <= 1; x++) { + for (int z = -1; z <= 1; z++) { + aBlock = this.getBaseMetaTileEntity().getBlockOffset(x, aY, z); + aMeta = this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z); + if (x == -1 || x == 1 || z == -1 || z == 1) { + if (aBlock == getCasingBlock() && aMeta == getCasingMeta()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block Externally on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } else { + if (aBlock == getCasingBlock() && aMeta == getCasingMeta2()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block Internally on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + } + } + return true; + } + + public boolean checkBaseLayer(int aY) { + Block aBlock; + int aMeta; + + int requiredMeta = getCasingMeta2(); + if (aY == -19) { + requiredMeta = getCasingMeta(); + } + + for (int x = -3; x <= 3; x++) { + for (int z = -3; z <= 3; z++) { + aBlock = this.getBaseMetaTileEntity().getBlockOffset(x, aY, z); + aMeta = this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z); + + if ((x == 3 && z == 3) || (x == 2 && z == 2) || (x == 3 && z == 2) || (x == 2 && z == 3)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + return false; + } + } + else if ((x == -3 && z == -3) || (x == -2 && z == -2) || (x == -3 && z == -2) || (x == -2 && z == -3)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + return false; + } + } + else if ((x == -3 && z == 3) || (x == -2 && z == 2) || (x == -3 && z == 2) || (x == -2 && z == 3)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + return false; + } + } + else if ((x == 3 && z == -3) || (x == 2 && z == -2) || (x == 3 && z == -2) || (x == 2 && z == -3)) { + if (!getBaseMetaTileEntity().getAirOffset(x, aY, z)) { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + return false; + } + } + else { + IGregTechTileEntity tTileEntity = getBaseMetaTileEntity().getIGregTechTileEntityOffset(x, aY, z); + if (addToMachineList(tTileEntity, mCasingTextureID)) { + continue; + } + if (x == 0 && z == 0) { + if (aBlock == getCasingBlock() && aMeta == requiredMeta) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block Internally on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + else { + if (aBlock == getCasingBlock() && aMeta == getCasingMeta()) { + continue; + } else { + Logger.INFO("Error at offset: X:"+x+", Y:"+aY+", Z:"+z); + Logger.INFO("Found Bad Block Internally on Layer "+aY+": "+(aBlock != null ? aBlock.getLocalizedName() : "Air")+" | Meta: "+aMeta); + return false; + } + } + } + } + } + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + //Add Heat every second + if (aTick % 20 == 0) { + + //Add Heat First, if sources available + int aCacheSize = this.mCachedReflectors.size(); + if (aCacheSize > 0) { + int aCount = aCacheSize; + for (int i = 0; i < aCount; i++) { + this.mHeatLevel++; + } + } + + //Remove Heat, based on time of day + World w = this.getBaseMetaTileEntity().getWorld(); + if (w != null) { + int aRemovalFactor = 0; + if (w.isDaytime()) { + aRemovalFactor = 1; + } + else { + aRemovalFactor = 3; + } + for (int i = 0; i<MathUtils.randInt((aCacheSize/10), (aCacheSize*10)); i++){ + this.mHeatLevel -= aRemovalFactor; + } + } + } + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if (this.mCachedReflectors.isEmpty()) { + if (aTick % (30*20) == 0) { + this.getConnectedSolarReflectors(); + } + } + } + + @Override + public void onRemoval() { + this.mCachedReflectors.clear(); + super.onRemoval(); + } + + @Override + public String[] getExtraInfoData() { + return new String[] { + "Internal Heat Level: "+this.mHeatLevel, + "Connected Solar Reflectors: "+this.mCachedReflectors.size() + }; + } + + + + + + + + + +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java new file mode 100644 index 0000000000..4759457d8d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java @@ -0,0 +1,486 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.algae; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.List; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.core.lib.CORE; +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.AgriculturalChem; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_AlgaeFarm; +import ic2.core.init.BlocksItems; +import ic2.core.init.InternalName; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { + + private int mLevel = -1; + private int mCasing; + private IStructureDefinition<GregtechMTE_AlgaePondBase> STRUCTURE_DEFINITION = null; + private int checkMeta; + + public GregtechMTE_AlgaePondBase(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_AlgaePondBase(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_AlgaePondBase(this.mName); + } + + @Override + public String getMachineType() { + return "Algae Pond"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Grows Algae!") + .addInfo("Controller Block for the Algae Farm") + .addInfo("Provide compost to boost production by one tier") + .addInfo("Does not require power or maintenance") + .addInfo("All Machine Casings must be the same tier, this dictates machine speed.") + .addInfo("Fill Input Hatch with water.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(9, 3, 9, true) + .addController("Front Center") + .addCasingInfo("Machine Casings", 64) + .addCasingInfo("Sterile Farm Casings", 34) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + public void setMeta(int meta) { + checkMeta = meta; + } + + public int getMeta() { + return checkMeta; + } + + @Override + public IStructureDefinition<GregtechMTE_AlgaePondBase> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_AlgaePondBase>builder() + .addShape(mName, transpose(new String[][]{ + {"XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", "X X", "XXXXXXXXX"}, + {"XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", "X X", "XXXXXXXXX"}, + {"CCCC~CCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMTE_AlgaePondBase::addAlgaePondBaseList, TAE.getIndexFromPage(1, 15), 1 + ), + onElementPass( + x -> ++x.mCasing, + addTieredBlock( + GregTech_API.sBlockCasings1, GregtechMTE_AlgaePondBase::setMeta, GregtechMTE_AlgaePondBase::getMeta, 10 + ) + ) + ) + ) + .addElement( + 'X', + ofBlock( + ModBlocks.blockCasings2Misc, 15 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 4, 2, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mLevel = 0; + checkMeta = 0; + if (checkPiece(mName, 4, 2, 0) && mCasing >= 64 && checkMeta > 0) { + mLevel = checkMeta - 1; + return true; + } + return false; + } + + public final boolean addAlgaePondBaseList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + }else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // fuck + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + + int aID = TAE.getIndexFromPage(1, 15); + if (mLevel > -1) { + aID = mLevel; + } + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(aID), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(aID)}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + @Override + public int getMaxParallelRecipes() { + return 2; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + public boolean checkForWater() { + + // Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + mCurrentDirectionX = 4; + mCurrentDirectionZ = 4; + + mOffsetX_Lower = -4; + mOffsetX_Upper = 4; + mOffsetZ_Lower = -4; + mOffsetZ_Upper = 4; + + // if (aBaseMetaTileEntity.fac) + + final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX + * mCurrentDirectionX; + final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ + * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; h++) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + // byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = Blocks.water; + aBaseMetaTileEntity.getWorld().setBlock( + aBaseMetaTileEntity.getXCoord() + xDir + i, + aBaseMetaTileEntity.getYCoord() + h, + aBaseMetaTileEntity.getZCoord() + zDir + j, fluidUsed); + + } + } + } + } + } + tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { + ++tAmount; + // Logger.INFO("Found Water"); + } + } + } + } + + boolean isValidWater = tAmount >= 60; + + if (isValidWater) { + Logger.INFO("Filled structure."); + return true; + } + else { + return false; + } + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAlgaePond; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + this.fixAllMaintenanceIssue(); + // Silly Client Syncing + if (aBaseMetaTileEntity.isClientSide()) { + this.mLevel = getCasingTier(); + } + + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); + } + + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, FluidStack[] aFluidInputs, + int aMaxParallelRecipes, int aEUPercent, + int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { + + if (this.mLevel < 0) { + Logger.INFO("Bad Tier."); + return false; + } + + if (!checkForWater()) { + Logger.INFO("Not enough Water."); + return false; + } + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + + Logger.INFO("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = RecipeLoader_AlgaeFarm.getTieredRecipeFromCache(this.mLevel, isUsingCompost(aItemInputs)); + + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + return false; + } + if (tRecipe.mInputs.length > 0) { + for (ItemStack aInputToConsume : tRecipe.mInputs) { + this.depleteInput(aInputToConsume); + } + } + + + // -- Try not to fail after this point - inputs have already been consumed! -- + + + this.mMaxProgresstime = (int)(tRecipe.mDuration); + this.mEUt = 0; + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + Logger.INFO("Recipe time: "+this.mMaxProgresstime); + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= aMaxParallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < aMaxParallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + Logger.INFO("GOOD RETURN - 1"); + return true; + + } + + private boolean isUsingCompost(ItemStack[] aItemInputs) { + ItemStack aCompost = ItemUtils.getSimpleStack(AgriculturalChem.mCompost, 1); + for (ItemStack i : aItemInputs) { + if (GT_Utility.areStacksEqual(aCompost, i)) { + if (i.stackSize >= 8) { + return true; + } + } + } + return false; + } + + + private int getCasingTier() { + if (this.getBaseMetaTileEntity().getWorld() == null) { + return 0; + } + try { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(xDir, -1, zDir); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir, -1, zDir); + if (aInitStructureCheck == GregTech_API.sBlockCasings1) { + return aInitStructureCheckMeta; + } + return 0; + } + catch (Throwable t) { + t.printStackTrace(); + return 0; + } + } + + + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform1.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform1.java new file mode 100644 index 0000000000..018120d614 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform1.java @@ -0,0 +1,46 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.bedrock; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gtPlusPlus.core.material.ALLOY; +import gtPlusPlus.core.material.Material; + +public class GregtechMetaTileEntity_BedrockMiningPlatform1 extends GregtechMetaTileEntity_BedrockMiningPlatformBase { + public GregtechMetaTileEntity_BedrockMiningPlatform1(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_BedrockMiningPlatform1(final String aName) { + super(aName); + } + + public String[] getTooltip() { + return this.getDescriptionInternal("I"); + } + + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return (IMetaTileEntity) new GregtechMetaTileEntity_BedrockMiningPlatform1(this.mName); + } + + protected Material getFrameMaterial() { + return ALLOY.INCONEL_690; + } + + protected int getCasingTextureIndex() { + return TAE.getIndexFromPage(0, 14); + } + + protected int getRadiusInChunks() { + return 9; + } + + protected int getMinTier() { + return 5; + } + + protected int getBaseProgressTime() { + return (int) (420*(this.mProductionModifier/100)); + } +}*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform2.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform2.java new file mode 100644 index 0000000000..6b97cb7ee2 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatform2.java @@ -0,0 +1,46 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.bedrock; + +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.material.Material; + +public class GregtechMetaTileEntity_BedrockMiningPlatform2 extends GregtechMetaTileEntity_BedrockMiningPlatformBase { + public GregtechMetaTileEntity_BedrockMiningPlatform2(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_BedrockMiningPlatform2(final String aName) { + super(aName); + } + + public String[] getTooltip() { + return this.getDescriptionInternal("II"); + } + + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return (IMetaTileEntity) new GregtechMetaTileEntity_BedrockMiningPlatform2(this.mName); + } + + protected Material getFrameMaterial() { + return ELEMENT.getInstance().AMERICIUM241; + } + + protected int getCasingTextureIndex() { + return 62; + } + + protected int getRadiusInChunks() { + return 9; + } + + protected int getMinTier() { + return 5; + } + + protected int getBaseProgressTime() { + return 480; + } +}*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatformBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatformBase.java new file mode 100644 index 0000000000..05a05d53e0 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/bedrock/GregtechMetaTileEntity_BedrockMiningPlatformBase.java @@ -0,0 +1,683 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.bedrock; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gregtech.common.GT_Worldgen_GT_Ore_Layer; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.material.ORES; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.MiningUtils; +import gtPlusPlus.core.util.minecraft.OreDictUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.block.Block; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; + +public abstract class GregtechMetaTileEntity_BedrockMiningPlatformBase extends GregtechMeta_MultiBlockBase { + + protected double mProductionModifier = 0; + + + private static final ItemStack miningPipe; + private static final ItemStack miningPipeTip; + + private Block casingBlock; + private int casingMeta; + // private int frameMeta; + private int casingTextureIndex; + + private ForgeDirection back; + + private int xDrill; + private int yDrill; + private int zDrill; + + private int[] xCenter = new int[5]; + private int[] zCenter = new int[5]; + + public GregtechMetaTileEntity_BedrockMiningPlatformBase(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + this.initFields(); + } + + public GregtechMetaTileEntity_BedrockMiningPlatformBase(final String aName) { + super(aName); + this.initFields(); + } + + private void initFields() { + this.casingBlock = this.getCasingBlockItem().getBlock(); + this.casingMeta = this.getCasingBlockItem().get(0L, new Object[0]).getItemDamage(); + this.casingTextureIndex = this.getCasingTextureIndex(); + } + + 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(this.casingTextureIndex), + new GT_RenderedTexture( + (IIconContainer) (aActive ? Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_FRONT_ACTIVE + : Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_FRONT)) }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(this.casingTextureIndex) }; + } + + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, + final IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), + "OreDrillingPlant.png"); + } + + + public int getAmountOfOutputs() { + return 1; + } + + public void saveNBTData(final NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setDouble("mProductionModifier", mProductionModifier); + } + + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mProductionModifier = aNBT.getDouble("mProductionModifier"); + } + + public boolean checkRecipe(final ItemStack aStack) { + //this.setElectricityStats(); + + + if (true) { + return false; + } + + boolean[] didWork = new boolean[5]; + + if (!this.tryConsumeDrillingFluid()) { + Logger.INFO("No drilling Fluid."); + return false; + } + + if (MathUtils.isNumberEven((int) this.mProductionModifier)) { + if (!this.tryConsumePyrotheum()) { + Logger.INFO("No tryConsumePyrotheum Fluid."); + return false; + } + else { + mProductionModifier++; + } + } + else { + if (!this.tryConsumeCryotheum()) { + Logger.INFO("No tryConsumeCryotheum Fluid."); + return false; + } + else { + mProductionModifier++; + } + } + + for (int i = 0; i < 5; i++) { + process(); + didWork[i] = true; + } + + // Fail recipe handling if one pipe didn't handle properly, to try again + // next run. + for (boolean y : didWork) { + if (!y) { + Logger.INFO("[Bedrock Miner] Fail [x]"); + return false; + } + } + + this.mEUt = -8000; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 10000; + + return true; + } + + private boolean isEnergyEnough() { + long requiredEnergy = 512L + this.getMaxInputVoltage() * 4L; + for (final GT_MetaTileEntity_Hatch_Energy energyHatch : this.mEnergyHatches) { + requiredEnergy -= energyHatch.getEUVar(); + if (requiredEnergy <= 0L) { + return true; + } + } + return false; + } + + private void setElectricityStats() { + //this.mEfficiency = this.getCurrentEfficiency((ItemStack) null); + this.mEfficiencyIncrease = 10000; + final int overclock = 8 << GT_Utility.getTier(this.getMaxInputVoltage()); + //this.mEUt = -12 * overclock * overclock; + Logger.INFO("Trying to set EU to "+(12 * overclock * overclock)); + int mCombinedAvgTime = 0; + for (int g = 0; g < 5; g++) { + mCombinedAvgTime += this.getBaseProgressTime() / overclock; + } + Logger.INFO("Trying to set Max Time to "+(mCombinedAvgTime)); + //this.mMaxProgresstime = (mCombinedAvgTime / 5); + } + + private boolean tryConsumeDrillingFluid() { + boolean consumed = false; + boolean g = (this.getBaseMetaTileEntity().getWorld().getTotalWorldTime() % 2 == 0); + consumed = (g ? tryConsumePyrotheum() : tryConsumeCryotheum()); + if (consumed) { + //increaseProduction(g ? 2 : 1); + } + else { + //lowerProduction(g ? 5 : 3); + } + return consumed; + } + + private boolean tryConsumePyrotheum() { + return this.depleteInput(FluidUtils.getFluidStack("pyrotheum", 4)); + } + + private boolean tryConsumeCryotheum() { + return this.depleteInput(FluidUtils.getFluidStack("cryotheum", 4)); + } + + private void putMiningPipesFromInputsInController() { + final int maxPipes = 64; + if (this.isHasMiningPipes(maxPipes)) { + return; + } + ItemStack pipes = this.getStackInSlot(1); + for (final ItemStack storedItem : this.getStoredInputs()) { + if (!storedItem.isItemEqual(GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe)) { + continue; + } + if (pipes == null) { + this.setInventorySlotContents(1, + GT_Utility.copy(new Object[] { GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe })); + pipes = this.getStackInSlot(1); + } + if (pipes.stackSize == maxPipes) { + break; + } + final int needPipes = maxPipes - pipes.stackSize; + final int transferPipes = (storedItem.stackSize < needPipes) ? storedItem.stackSize : needPipes; + final ItemStack itemStack = pipes; + itemStack.stackSize += transferPipes; + final ItemStack itemStack2 = storedItem; + itemStack2.stackSize -= transferPipes; + } + this.updateSlots(); + } + + + + private boolean isHasMiningPipes(final int minCount) { + final ItemStack pipe = this.getStackInSlot(1); + return pipe != null && pipe.stackSize > minCount - 1 + && pipe.isItemEqual(GregtechMetaTileEntity_BedrockMiningPlatformBase.miningPipe); + } + + public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + this.updateCoordinates(); + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + int tAmount = 0; + if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { + return false; + } else { + + Block aCasing = Block.getBlockFromItem(getCasingBlockItem().getItem()); + + for (int i = -1; i < 2; ++i) { + for (int j = -1; j < 2; ++j) { + for (int h = -1; h < 2; ++h) { + if (h != 0 || (xDir + i != 0 || zDir + j != 0) && (i != 0 || j != 0)) { + IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, + h, zDir + j); + Block aBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + + if (!this.addToMachineList(tTileEntity, 48)) { + if (aBlock != aCasing) { + Logger.INFO("Found Bad Casing"); + return false; + } + if (aMeta != 3) { + Logger.INFO("Found Bad Meta"); + return false; + } + } + ++tAmount; + + + + /*if (!isValidBlockForStructure(tTileEntity, 48, true, aBlock, aMeta, sBlockCasings4, 0)) { + Logger.INFO("Bad centrifuge casing"); + return false; + }*/ + + } + } + } + } + return tAmount >= 10; + } + + } + + private void updateCoordinates() { + this.xDrill = this.getBaseMetaTileEntity().getXCoord(); + this.yDrill = this.getBaseMetaTileEntity().getYCoord()-1; + this.zDrill = this.getBaseMetaTileEntity().getZCoord(); + this.back = ForgeDirection.getOrientation((int) this.getBaseMetaTileEntity().getBackFacing()); + + // Middle + this.xCenter[0] = this.xDrill + this.back.offsetX; + this.zCenter[0] = this.zDrill + this.back.offsetZ; + + this.xCenter[1] = xCenter[0] + 1; + this.zCenter[1] = zCenter[0]; + + this.xCenter[2] = xCenter[0] - 1; + this.zCenter[2] = zCenter[0]; + + this.xCenter[3] = xCenter[0]; + this.zCenter[3] = zCenter[0] + 1; + + this.xCenter[4] = xCenter[0]; + this.zCenter[4] = zCenter[0] - 1; + + } + + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + protected GregtechItemList getCasingBlockItem() { + return GregtechItemList.Casing_BedrockMiner; + } + + protected abstract Material getFrameMaterial(); + + protected abstract int getCasingTextureIndex(); + + protected abstract int getRadiusInChunks(); + + protected abstract int getMinTier(); + + protected abstract int getBaseProgressTime(); + + protected String[] getDescriptionInternal(final String tierSuffix) { + final String casings = this.getCasingBlockItem().get(0L, new Object[0]).getDisplayName(); + return new String[] { + "Controller Block for the Experimental Deep Earth Drilling Platform - MK " + + ((tierSuffix != null) ? tierSuffix : ""), + "Size(WxHxD): 3x7x3, Controller (Front middle bottom)", "3x1x3 Base of " + casings, + "1x3x1 " + casings + " pillar (Center of base)", + "1x3x1 " + this.getFrameMaterial().getLocalizedName() + " Frame Boxes (Each pillar side and on top)", + "2x Input Hatch (Any bottom layer casing)", + "1x Input Bus for mining pipes (Any bottom layer casing; not necessary)", + "1x Output Bus (Any bottom layer casing)", "1x Maintenance Hatch (Any bottom layer casing)", + "1x " + GT_Values.VN[this.getMinTier()] + "+ Energy Hatch (Any bottom layer casing)", + "Radius is " + (this.getRadiusInChunks() << 4) + " blocks", + "Every tick, this machine altenates betweem consumption of Pyrotheum & Cryotheum", + "Pyrotheum is used to bore through the Mantle of the world", + "Cryotheum is used to keep the internal components cool",}; + } + + static { + miningPipe = GT_ModHandler.getIC2Item("miningPipe", 0L); + miningPipeTip = GT_ModHandler.getIC2Item("miningPipeTip", 0L); + } + + + + + + + + + + + + + + + + + + + + + + + + + + private AutoMap<ItemStack> mOutputs; + + public void process() { + ItemStack aOutput = generateOutputWithchance(); + if (aOutput != null) { + this.addOutput(aOutput); + Logger.INFO("Mined some "+aOutput.getDisplayName()); + } + this.updateSlots(); + } + + public ItemStack generateOutputWithchance() { + int aChance = MathUtils.randInt(0, 7500); + if (aChance < 100) { + return generateOutput(); + } + else { + return null; + } + } + + public ItemStack generateOutput() { + AutoMap<ItemStack> aData = generateOreForOutput(); + int aMax = aData.size()-1; + return aData.get(MathUtils.randInt(0, aMax)); + } + + /** + * Here we generate valid ores and also a basic loot set + */ + + public AutoMap<ItemStack> generateOreForOutput() { + + if (mOutputs != null) { + return mOutputs; + } + + AutoMap<GT_Worldgen_GT_Ore_Layer> aOverWorldOres = MiningUtils.getOresForDim(0); + AutoMap<GT_Worldgen_GT_Ore_Layer> aNetherOres = MiningUtils.getOresForDim(-1); + AutoMap<GT_Worldgen_GT_Ore_Layer> aEndOres = MiningUtils.getOresForDim(1); + + AutoMap<ItemStack> aTempMap = new AutoMap<ItemStack>(); + Block tOreBlock = GregTech_API.sBlockOres1; + Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Initial]"); + + for (GT_Worldgen_GT_Ore_Layer layer : aOverWorldOres) { + if (layer.mEnabled) { + ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); + ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); + ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); + ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + } + } + Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Overworld]"); + for (GT_Worldgen_GT_Ore_Layer layer : aNetherOres) { + if (layer.mEnabled) { + ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); + ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); + ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); + ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + } + } + Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Nether]"); + for (GT_Worldgen_GT_Ore_Layer layer : aEndOres) { + if (layer.mEnabled) { + ItemStack aTempOreStack1 = ItemUtils.simpleMetaStack(tOreBlock, layer.mPrimaryMeta, 1); + ItemStack aTempOreStack2 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSecondaryMeta, 1); + ItemStack aTempOreStack3 = ItemUtils.simpleMetaStack(tOreBlock, layer.mBetweenMeta, 1); + ItemStack aTempOreStack4 = ItemUtils.simpleMetaStack(tOreBlock, layer.mSporadicMeta, 1); + aTempMap.put(aTempOreStack1); + aTempMap.put(aTempOreStack2); + aTempMap.put(aTempOreStack3); + aTempMap.put(aTempOreStack4); + } + } + Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [End]"); + + addOreTypeToMap(ELEMENT.getInstance().IRON, 200, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().COPPER, 175, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().TIN, 150, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().GOLD, 150, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().SILVER, 110, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().NICKEL, 40, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().ZINC, 40, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().LEAD, 40, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().ALUMINIUM, 30, aTempMap); + addOreTypeToMap(ELEMENT.getInstance().THORIUM, 20, aTempMap); + Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Extra Common Ores]"); + + AutoMap<Pair<String, Integer>> mMixedOreData = new AutoMap<Pair<String, Integer>>(); + mMixedOreData.put(new Pair<String, Integer>("oreRuby", 30)); + mMixedOreData.put(new Pair<String, Integer>("oreSapphire", 25)); + mMixedOreData.put(new Pair<String, Integer>("oreEmerald", 25)); + mMixedOreData.put(new Pair<String, Integer>("oreLapis", 40)); + mMixedOreData.put(new Pair<String, Integer>("oreRedstone", 40)); + + if (LoadedMods.Thaumcraft || (OreDictUtils.containsValidEntries("oreAmber") && OreDictUtils.containsValidEntries("oreCinnabar"))) { + mMixedOreData.put(new Pair<String, Integer>("oreAmber", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreCinnabar", 20)); + } + if (LoadedMods.Railcraft || OreDictUtils.containsValidEntries("oreSaltpeter")) { + mMixedOreData.put(new Pair<String, Integer>("oreSaltpeter", 10)); + } + if (LoadedMods.IndustrialCraft2 || OreDictUtils.containsValidEntries("oreUranium")) { + mMixedOreData.put(new Pair<String, Integer>("oreUranium", 10)); + } + if (OreDictUtils.containsValidEntries("oreSulfur")) { + mMixedOreData.put(new Pair<String, Integer>("oreSulfur", 15)); + } + if (OreDictUtils.containsValidEntries("oreSilicon")) { + mMixedOreData.put(new Pair<String, Integer>("oreSilicon", 15)); + } + if (OreDictUtils.containsValidEntries("oreApatite")) { + mMixedOreData.put(new Pair<String, Integer>("oreApatite", 25)); + } + + mMixedOreData.put(new Pair<String, Integer>("oreFirestone", 2)); + mMixedOreData.put(new Pair<String, Integer>("oreBismuth", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreLithium", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreManganese", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreBeryllium", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreCoal", 75)); + mMixedOreData.put(new Pair<String, Integer>("oreLignite", 75)); + mMixedOreData.put(new Pair<String, Integer>("oreSalt", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreCalcite", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreBauxite", 20)); + mMixedOreData.put(new Pair<String, Integer>("oreAlmandine", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreGraphite", 25)); + mMixedOreData.put(new Pair<String, Integer>("oreGlauconite", 15)); + mMixedOreData.put(new Pair<String, Integer>("orePyrolusite", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreGrossular", 15)); + mMixedOreData.put(new Pair<String, Integer>("oreTantalite", 15)); + + for (Pair<String, Integer> g : mMixedOreData) { + for (int i=0; i<g.getValue();i++) { + aTempMap.put(ItemUtils.getItemStackOfAmountFromOreDict(g.getKey(), 1)); + } + } + Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [Extra Mixed Ores]"); + + + addOreTypeToMap(ELEMENT.STANDALONE.RUNITE, 2, aTempMap); + addOreTypeToMap(ELEMENT.STANDALONE.GRANITE, 8, aTempMap); + Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [OSRS Ores]"); + + + AutoMap<Material> aMyOreMaterials = new AutoMap<Material>(); + aMyOreMaterials.add(ORES.CROCROITE); + aMyOreMaterials.add(ORES.GEIKIELITE); + aMyOreMaterials.add(ORES.NICHROMITE); + aMyOreMaterials.add(ORES.TITANITE); + aMyOreMaterials.add(ORES.ZIMBABWEITE); + aMyOreMaterials.add(ORES.ZIRCONILITE); + aMyOreMaterials.add(ORES.GADOLINITE_CE); + aMyOreMaterials.add(ORES.GADOLINITE_Y); + aMyOreMaterials.add(ORES.LEPERSONNITE); + aMyOreMaterials.add(ORES.SAMARSKITE_Y); + aMyOreMaterials.add(ORES.SAMARSKITE_YB); + aMyOreMaterials.add(ORES.XENOTIME); + aMyOreMaterials.add(ORES.YTTRIAITE); + aMyOreMaterials.add(ORES.YTTRIALITE); + aMyOreMaterials.add(ORES.YTTROCERITE); + aMyOreMaterials.add(ORES.ZIRCON); + aMyOreMaterials.add(ORES.POLYCRASE); + aMyOreMaterials.add(ORES.ZIRCOPHYLLITE); + aMyOreMaterials.add(ORES.ZIRKELITE); + aMyOreMaterials.add(ORES.LANTHANITE_LA); + aMyOreMaterials.add(ORES.LANTHANITE_CE); + aMyOreMaterials.add(ORES.LANTHANITE_ND); + aMyOreMaterials.add(ORES.AGARDITE_Y); + aMyOreMaterials.add(ORES.AGARDITE_CD); + aMyOreMaterials.add(ORES.AGARDITE_LA); + aMyOreMaterials.add(ORES.AGARDITE_ND); + aMyOreMaterials.add(ORES.HIBONITE); + aMyOreMaterials.add(ORES.CERITE); + aMyOreMaterials.add(ORES.FLUORCAPHITE); + aMyOreMaterials.add(ORES.FLORENCITE); + aMyOreMaterials.add(ORES.CRYOLITE); + aMyOreMaterials.add(ORES.LAUTARITE); + aMyOreMaterials.add(ORES.LAFOSSAITE); + aMyOreMaterials.add(ORES.DEMICHELEITE_BR); + aMyOreMaterials.add(ORES.COMANCHEITE); + aMyOreMaterials.add(ORES.PERROUDITE); + aMyOreMaterials.add(ORES.HONEAITE); + aMyOreMaterials.add(ORES.ALBURNITE); + aMyOreMaterials.add(ORES.MIESSIITE); + aMyOreMaterials.add(ORES.KASHINITE); + aMyOreMaterials.add(ORES.IRARSITE); + aMyOreMaterials.add(ORES.RADIOBARITE); + aMyOreMaterials.add(ORES.DEEP_EARTH_REACTOR_FUEL_DEPOSIT); + + for (Material aOreType : aMyOreMaterials) { + if (aOreType == ORES.DEEP_EARTH_REACTOR_FUEL_DEPOSIT || aOreType == ORES.RADIOBARITE) { + addOreTypeToMap(aOreType, 4, aTempMap); + } + else { + addOreTypeToMap(aOreType, 7, aTempMap); + } + } + + //Cleanup Map + Logger.INFO("Ore Map contains "+aTempMap.size()+" values. [GT++]"); + AutoMap<ItemStack> aCleanUp = new AutoMap<ItemStack>(); + for (ItemStack verify : aTempMap) { + if (!ItemUtils.checkForInvalidItems(verify)) { + aCleanUp.put(verify); + } + } + Logger.INFO("Cleanup Map contains "+aCleanUp.size()+" values."); + for (ItemStack remove : aCleanUp) { + aTempMap.remove(remove); + } + + //Generate Massive Map + AutoMap<ItemStack> aFinalMap = new AutoMap<ItemStack>(); + for (ItemStack aTempItem : aTempMap) { + int aTempMulti = MathUtils.randInt(20, 50); + for (int i=0;i<aTempMulti;i++) { + aFinalMap.put(aTempItem.copy()); + } + } + Logger.INFO("Final Ore Map contains "+aFinalMap.size()+" values."); + mOutputs = aFinalMap; + return mOutputs; + } + + + private static void addOreTypeToMap(Material aMaterial, int aAmount, AutoMap<ItemStack> aMap) { + for (int i=0; i<aAmount;i++) { + aMap.add(aMaterial.getOre(1)); + } + } + + + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Miner"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + + + + + + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java new file mode 100644 index 0000000000..42912c4fa8 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java @@ -0,0 +1,1046 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.chemplant; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.Triplet; +import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.GT_MetaTileEntity_Hatch_Catalysts; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { + + private int mSolidCasingTier = 0; + private int mMachineCasingTier = 0; + private int mPipeCasingTier = 0; + private int mCoilTier = 0; + private int checkCoil; + private int[] checkCasing = new int[8]; + private int checkMachine; + private int checkPipe; + private int maxTierOfHatch; + private int mCasing; + private IStructureDefinition<GregtechMTE_ChemicalPlant> STRUCTURE_DEFINITION = null; + + private ArrayList<GT_MetaTileEntity_Hatch_Catalysts> mCatalystBuses = new ArrayList<GT_MetaTileEntity_Hatch_Catalysts>(); + + private static final HashMap<Integer, Triplet<Block, Integer, Integer>> mTieredBlockRegistry = new HashMap<Integer, Triplet<Block, Integer, Integer>>(); + + public GregtechMTE_ChemicalPlant(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_ChemicalPlant(final String aName) { + super(aName); + } + + public static boolean registerMachineCasingForTier(int aTier, Block aBlock, int aMeta, int aCasingTextureID) { + int aSize = mTieredBlockRegistry.size(); + int aSize2 = aSize; + Triplet<Block, Integer, Integer> aCasingData = new Triplet<Block, Integer, Integer>(aBlock, aMeta, aCasingTextureID); + if (mTieredBlockRegistry.containsKey(aTier)) { + CORE.crash("Tried to register a Machine casing for tier "+aTier+" to the Chemical Plant, however this tier already contains one."); + } + mTieredBlockRegistry.put(aTier, aCasingData); + aSize = mTieredBlockRegistry.size(); + return aSize > aSize2; + } + + private static int getCasingTextureIdForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return 10; + } + int aCasingID = mTieredBlockRegistry.get(aTier).getValue_3(); + //Logger.INFO("Found casing texture ID "+aCasingID+" for tier "+aTier); + return aCasingID; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_ChemicalPlant(this.mName); + } + + @Override + public String getMachineType() { + return "Chemical Plant"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Chemical Plant") + .addInfo("Heavy Industry, now right at your doorstep!") + .addInfo("Please read the user manual for more information on construction and usage") + .addSeparator() + .addController("Bottom Center") + .addStructureHint("Catalyst Housing", 1) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addOutputHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + public void setMachineMeta(int meta) { + checkMachine = meta; + } + + public int getMachineMeta() { + return checkMachine; + } + + public void setPipeMeta(int meta) { + checkPipe = meta; + } + + public int getPipeMeta() { + return checkPipe; + } + + public void setCoilMeta(int meta) { + checkCoil = meta; + } + + public int getCoilMeta() { + return checkCoil; + } + + public int coilTier(int meta) { + switch (meta) { + case 0: return 1; + case 1: return 2; + case 2: return 3; + case 3: return 4; + case 4: return 5; + case 5: return 7; + case 6: return 8; + case 7: return 10; + case 8: return 11; + case 9: return 6; + case 10: return 9; + } + return 0; + } + + @Override + public IStructureDefinition<GregtechMTE_ChemicalPlant> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_ChemicalPlant>builder() + .addShape(mName, transpose(new String[][]{ + {"XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX"}, + {"X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X"}, + {"X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X"}, + {"X X", " ", " HHH ", " HHH ", " HHH ", " ", "X X"}, + {"X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X"}, + {"X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X"}, + {"CCC~CCC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CCCCCCC"}, + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMTE_ChemicalPlant::addChemicalPlantList, getCasingTextureID(), 1 + ), + onElementPass( + x -> {++x.checkCasing[0]; ++x.mCasing;}, + ofSolidCasing(0) + ), + onElementPass( + x -> {++x.checkCasing[1]; ++x.mCasing;}, + ofSolidCasing(1) + ), + onElementPass( + x -> {++x.checkCasing[2]; ++x.mCasing;}, + ofSolidCasing(2) + ), + onElementPass( + x -> {++x.checkCasing[3]; ++x.mCasing;}, + ofSolidCasing(3) + ), + onElementPass( + x -> {++x.checkCasing[4]; ++x.mCasing;}, + ofSolidCasing(4) + ), + onElementPass( + x -> {++x.checkCasing[5]; ++x.mCasing;}, + ofSolidCasing(5) + ), + onElementPass( + x -> {++x.checkCasing[6]; ++x.mCasing;}, + ofSolidCasing(6) + ), + onElementPass( + x -> {++x.checkCasing[7]; ++x.mCasing;}, + ofSolidCasing(7) + ) + ) + ) + .addElement( + 'X', + ofChain( + onElementPass( + x -> {++x.checkCasing[0]; ++x.mCasing;}, + ofSolidCasing(0) + ), + onElementPass( + x -> {++x.checkCasing[1]; ++x.mCasing;}, + ofSolidCasing(1) + ), + onElementPass( + x -> {++x.checkCasing[2]; ++x.mCasing;}, + ofSolidCasing(2) + ), + onElementPass( + x -> {++x.checkCasing[3]; ++x.mCasing;}, + ofSolidCasing(3) + ), + onElementPass( + x -> {++x.checkCasing[4]; ++x.mCasing;}, + ofSolidCasing(4) + ), + onElementPass( + x -> {++x.checkCasing[5]; ++x.mCasing;}, + ofSolidCasing(5) + ), + onElementPass( + x -> {++x.checkCasing[6]; ++x.mCasing;}, + ofSolidCasing(6) + ), + onElementPass( + x -> {++x.checkCasing[7]; ++x.mCasing;}, + ofSolidCasing(7) + ) + ) + ) + .addElement( + 'M', + addTieredBlock( + GregTech_API.sBlockCasings1, GregtechMTE_ChemicalPlant::setMachineMeta, GregtechMTE_ChemicalPlant::getMachineMeta, 10 + ) + ) + .addElement( + 'H', + addTieredBlock( + GregTech_API.sBlockCasings5, GregtechMTE_ChemicalPlant::setCoilMeta, GregtechMTE_ChemicalPlant::getCoilMeta, 11 + ) + ) + .addElement( + 'P', + addTieredBlock( + GregTech_API.sBlockCasings2, GregtechMTE_ChemicalPlant::setPipeMeta, GregtechMTE_ChemicalPlant::getPipeMeta, 12, 16 + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public static <T> IStructureElement<T> ofSolidCasing(int aIndex) { + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + Block target = mTieredBlockRegistry.get(aIndex).getValue_1(); + int targetMeta = mTieredBlockRegistry.get(aIndex).getValue_2(); + return target.equals(block) && meta == targetMeta; + } + + int getIndex(int size) { + if (size > 8) size = 8; + return size - 1; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2()); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock(x, y, z, mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_1(), mTieredBlockRegistry.get(getIndex(trigger.stackSize)).getValue_2(), 3); + } + }; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName , stackSize, hintsOnly, 3, 6, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + for (int i = 0; i < 8; i++) { + checkCasing[i] = 0; + } + checkCoil = 0; + checkPipe = 0; + checkMachine = 0; + mSolidCasingTier = 0; + mMachineCasingTier = 0; + mPipeCasingTier = 0; + mCoilTier = 0; + mCatalystBuses.clear(); + if (checkPiece(mName, 3, 6, 0) && mCasing >= 80) { + for (int i = 0; i < 8; i++) { + if (checkCasing[i] == mCasing) { + mSolidCasingTier = i; + } + else if (checkCasing[i] > 0) + return false; + } + mMachineCasingTier = checkMachine - 1; + mPipeCasingTier = checkPipe - 12; + mCoilTier = coilTier(checkCoil - 1); + updateHatchTexture(); + return mMachineCasingTier >= maxTierOfHatch; + } + return false; + } + + public void updateHatchTexture() { + for (GT_MetaTileEntity_Hatch h : mCatalystBuses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mInputBusses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mMaintenanceHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mEnergyHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mOutputBusses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mInputHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mOutputHatches) h.updateTexture(getCasingTextureID()); + } + + public final boolean addChemicalPlantList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Catalysts){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus){ + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){ + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy){ + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + + ITexture aOriginalTexture; + + // Check things exist client side (The worst code ever) + if (aBaseMetaTileEntity.getWorld() != null) { + + } + int aCasingID = getCasingTextureID(); + aOriginalTexture = Textures.BlockIcons.getCasingTextureForId(aCasingID); + + if (aSide == aFacing) { + return new ITexture[]{aOriginalTexture, new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{aOriginalTexture}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList.size() == 0) { + generateRecipes(); + } + return GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT; + } + + public static void generateRecipes() { + for (GT_Recipe i : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlantRecipes.mRecipeList) { + GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.add(i); + } + } + + @Override + public int getMaxParallelRecipes() { + return 2 * getPipeCasingTier(); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + private int getSolidCasingTier() { + return this.mSolidCasingTier; + } + + private int getMachineCasingTier() { + return mMachineCasingTier; + } + + private int getPipeCasingTier() { + return mPipeCasingTier; + } + + private int getCasingTextureID() { + // Check the Tier Client Side + int aTier = mSolidCasingTier; + return getCasingTextureIdForTier(aTier); + } + + public boolean addToMachineList(IGregTechTileEntity aTileEntity) { + int aMaxTier = getMachineCasingTier(); + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock) { + GT_MetaTileEntity_TieredMachineBlock aMachineBlock = (GT_MetaTileEntity_TieredMachineBlock) aMetaTileEntity; + int aTileTier = aMachineBlock.mTier; + if (aTileTier > aMaxTier) { + log("Hatch tier too high."); + return false; + } + else { + return addToMachineList(aTileEntity, getCasingTextureID()); + } + } + else { + log("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. + return false; + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mSolidCasingTier", this.mSolidCasingTier); + aNBT.setInteger("mMachineCasingTier", this.mMachineCasingTier); + aNBT.setInteger("mPipeCasingTier", this.mPipeCasingTier); + aNBT.setInteger("mCoilTier", this.mCoilTier); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mSolidCasingTier = aNBT.getInteger("mSolidCasingTier"); + mMachineCasingTier = aNBT.getInteger("mMachineCasingTier"); + mPipeCasingTier = aNBT.getInteger("mPipeCasingTier"); + mCoilTier = aNBT.getInteger("mCoilTier"); + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Catalysts) { + log("Found GT_MetaTileEntity_Hatch_Catalysts"); + return addToMachineListInternal(mCatalystBuses, aMetaTileEntity, aBaseCasingIndex); + } + return super.addToMachineList(aTileEntity, aBaseCasingIndex); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + // Same speed bonus as pyro oven + public int getSpeedBonus() { + return 50 * (this.mCoilTier - 2); + } + + public int getMaxCatalystDurability() { + return 50; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mCatalystBuses.clear(); + } + } + // Silly Client Syncing + if (aBaseMetaTileEntity.isClientSide()) { + if (this != null && this.getBaseMetaTileEntity() != null && this.getBaseMetaTileEntity().getWorld() != null) { + this.mSolidCasingTier = getCasingTierOnClientSide(); + markDirty(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), getSpeedBonus()); + } + + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, FluidStack[] aFluidInputs, + int aMaxParallelRecipes, int aEUPercent, + int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe, boolean isOC) { + + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + //GT_Recipe tRecipe = findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + GT_Recipe tRecipe = findRecipe(mLastRecipe, gregtech.api.enums.GT_Values.V[tTier], getSolidCasingTier(), aItemInputs, aFluidInputs); + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + // checks if it has a catalyst + ItemStack tCatalystRecipe = findCatalyst(aItemInputs); + boolean aDoesRecipeNeedCatalyst = false; + for (ItemStack aInputItem : tRecipe.mInputs) { + if (ItemUtils.isCatalyst(aInputItem)) { + aDoesRecipeNeedCatalyst = true; + break; + } + } + if (aDoesRecipeNeedCatalyst) { + if (tCatalystRecipe == null) { + log("does not have catalyst"); + return false; + } + if (mCatalystBuses.size() != 1) { + log("does not have correct number of catalyst hatches. (Required 1, found "+mCatalystBuses.size()+")"); + return false; + } + } + + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe.mSpecialValue > this.mSolidCasingTier) { + log("solid tier is too low"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // checks if it has enough catalyst durability + ArrayList<ItemStack>tCatalysts = null; + int tMaxParallelCatalyst = aMaxParallelRecipes; + if (tCatalystRecipe != null) { + tCatalysts = new ArrayList<ItemStack>(); + tMaxParallelCatalyst = getCatalysts(aItemInputs, tCatalystRecipe, aMaxParallelRecipes, tCatalysts); + log("Can process "+tMaxParallelCatalyst+" recipes. If less than "+aMaxParallelRecipes+", catalyst does not have enough durability."); + } + + if (tMaxParallelCatalyst == 0) { + log("found not enough catalysts"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + log("aEUPercent "+aEUPercent); + log("mEUt "+tRecipe.mEUt); + + int parallelRecipes = 0; + + log("parallelRecipes: "+parallelRecipes); + log("aMaxParallelRecipes: "+tMaxParallelCatalyst); + log("tTotalEUt: "+tTotalEUt); + log("tVoltage: "+tVoltage); + log("tEnergy: "+tEnergy); + log("tRecipeEUt: "+tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < tMaxParallelCatalyst && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at "+parallelRecipes+"."); + break; + } + log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + // -- Try not to fail after this point - inputs have already been consumed! -- + + + // Convert speed bonus to duration multiplier + // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. + aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int)Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + tOutputItems = removeNulls(tOutputItems); + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Damage catalyst once all is said and done. + if (tCatalystRecipe != null) { + log("damaging catalyst"); + damageCatalyst(tCatalystRecipe, parallelRecipes); + } + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + for (GT_MetaTileEntity_Hatch_Catalysts h : mCatalystBuses) { + h.updateSlots(); + h.tryFillUsageSlots(); + } + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + private static final HashMap<Long, AutoMap<GT_Recipe>> mTieredRecipeMap = new HashMap<Long, AutoMap<GT_Recipe>>(); + private static final AutoMap<GT_Recipe> aTier0Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier1Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier2Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier3Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier4Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier5Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier6Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier7Recipes = new AutoMap<GT_Recipe>(); + private static boolean mInitRecipeCache = false; + + private static void initRecipeCaches() { + if (!mInitRecipeCache) { + mTieredRecipeMap.put((long) 0, aTier0Recipes); + mTieredRecipeMap.put((long) 1, aTier1Recipes); + mTieredRecipeMap.put((long) 2, aTier2Recipes); + mTieredRecipeMap.put((long) 3, aTier3Recipes); + mTieredRecipeMap.put((long) 4, aTier4Recipes); + mTieredRecipeMap.put((long) 5, aTier5Recipes); + mTieredRecipeMap.put((long) 6, aTier6Recipes); + mTieredRecipeMap.put((long) 7, aTier7Recipes); + for (GT_Recipe aRecipe : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList) { + if (aRecipe != null) { + switch (aRecipe.mSpecialValue) { + case 0: + aTier0Recipes.add(aRecipe); + continue; + case 1: + aTier1Recipes.add(aRecipe); + continue; + case 2: + aTier2Recipes.add(aRecipe); + continue; + case 3: + aTier3Recipes.add(aRecipe); + continue; + case 4: + aTier4Recipes.add(aRecipe); + continue; + case 5: + aTier5Recipes.add(aRecipe); + continue; + case 6: + aTier6Recipes.add(aRecipe); + continue; + case 7: + aTier7Recipes.add(aRecipe); + continue; + } + } + } + mInitRecipeCache = true; + } + } + + private static boolean areInputsEqual(GT_Recipe aComparator, ItemStack[] aInputs, FluidStack[] aFluids) { + int aInputCount = aComparator.mInputs.length; + if (aInputCount > 0) { + //Logger.INFO("Looking for recipe with "+aInputCount+" Items"); + int aMatchingInputs = 0; + recipe : for (ItemStack a : aComparator.mInputs) { + for (ItemStack b : aInputs) { + if (a.getItem() == b.getItem()) { + if (a.getItemDamage() == b.getItemDamage()) { + //Logger.INFO("Found matching Item Input - "+b.getUnlocalizedName()); + aMatchingInputs++; + continue recipe; + } + } + } + } + if (aMatchingInputs != aInputCount) { + return false; + } + } + int aFluidInputCount = aComparator.mFluidInputs.length; + if (aFluidInputCount > 0) { + //Logger.INFO("Looking for recipe with "+aFluidInputCount+" Fluids"); + int aMatchingFluidInputs = 0; + recipe : for (FluidStack b : aComparator.mFluidInputs) { + //Logger.INFO("Checking for fluid "+b.getLocalizedName()); + for (FluidStack a : aFluids) { + if (GT_Utility.areFluidsEqual(a, b)) { + //Logger.INFO("Found matching Fluid Input - "+b.getLocalizedName()); + aMatchingFluidInputs++; + continue recipe; + } + else { + //Logger.INFO("Found fluid which did not match - "+a.getLocalizedName()); + } + } + } + if (aMatchingFluidInputs != aFluidInputCount) { + return false; + } + } + Logger.INFO("Recipes Match!"); + return true; + } + + public GT_Recipe findRecipe(final GT_Recipe aRecipe, final long aVoltage, final long aSpecialValue, ItemStack[] aInputs, final FluidStack[] aFluids) { + if (!mInitRecipeCache) { + initRecipeCaches(); + } + if (this.getRecipeMap().mRecipeList.isEmpty()) { + log("No Recipes in Map to search through."); + return null; + } + else { + log("Checking tier "+aSpecialValue+" recipes and below. Using Input Voltage of "+aVoltage+"V."); + log("We have "+aInputs.length+" Items and "+aFluids.length+" Fluids."); + // Try check the cached recipe first + if (aRecipe != null) { + if (areInputsEqual(aRecipe, aInputs, aFluids)) { + if (aRecipe.mEUt <= aVoltage) { + Logger.INFO("Using cached recipe."); + return aRecipe; + } + } + } + + // Get all recipes for the tier + AutoMap<AutoMap<GT_Recipe>> aMasterMap = new AutoMap<AutoMap<GT_Recipe>>(); + for (long i=0;i<=aSpecialValue;i++) { + aMasterMap.add(mTieredRecipeMap.get(i)); + } + GT_Recipe aFoundRecipe = null; + + // Iterate the tiers recipes until we find the one with all inputs matching + master : for (AutoMap<GT_Recipe> aTieredMap : aMasterMap) { + for (GT_Recipe aRecipeToCheck : aTieredMap) { + if (areInputsEqual(aRecipeToCheck, aInputs, aFluids)) { + log("Found recipe with matching inputs!"); + if (aRecipeToCheck.mSpecialValue <= aSpecialValue) { + if (aRecipeToCheck.mEUt <= aVoltage) { + aFoundRecipe = aRecipeToCheck; + break master; + } + } + } + } + } + + // If we found a recipe, return it + if (aFoundRecipe != null) { + log("Found valid recipe."); + return aFoundRecipe; + } + } + log("Did not find valid recipe."); + return null; + } + + private int getCatalysts(ItemStack[] aItemInputs, ItemStack aRecipeCatalyst, int aMaxParrallel, ArrayList<ItemStack> aOutPut) { + int allowedParallel = 0; + for (final ItemStack aInput : aItemInputs) { + if (aRecipeCatalyst.isItemEqual(aInput)) { + int aDurabilityRemaining = getMaxCatalystDurability() - getDamage(aInput); + return Math.min(aMaxParrallel, aDurabilityRemaining); + } + } + return allowedParallel; + } + + private ItemStack findCatalyst(ItemStack[] aItemInputs) { + if (aItemInputs != null) { + for (final ItemStack aInput : aItemInputs) { + if (aInput != null) { + if (ItemUtils.isCatalyst(aInput)) { + return aInput; + } + } + } + } + return null; + } + + + private void damageCatalyst(ItemStack aStack, int parallelRecipes) { + for (int i=0; i<parallelRecipes; i++){ + if (MathUtils.randFloat(0, 10000000)/10000000f < (1.2f - (0.2 * this.mPipeCasingTier))) { + int damage = getDamage(aStack) + 1; + log("damage catalyst "+damage); + if (damage >= getMaxCatalystDurability()) { + log("consume catalyst"); + addOutput(CI.getEmptyCatalyst(1)); + aStack.stackSize -= 1; + } + else { + log("damaging catalyst"); + setDamage(aStack, damage); + } + } + else { + log("not consuming catalyst"); + } + } + } + + private int getDamage(ItemStack aStack) { + return ItemGenericChemBase.getCatalystDamage(aStack); + } + + private void setDamage(ItemStack aStack,int aAmount) { + ItemGenericChemBase.setCatalystDamage(aStack, aAmount); + } + + @SideOnly(Side.CLIENT) + private final int getCasingTierOnClientSide() { + + if (this == null || this.getBaseMetaTileEntity().getWorld() == null) { + return 0; + } + try { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 3; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 3; + if (xDir == 0) { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(zDir, 1, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(zDir, 1, 0); + } + else { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 1, xDir); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 1, xDir); + } + for (int aTier : mTieredBlockRegistry.keySet()) { + Triplet<Block, Integer, Integer> aData = mTieredBlockRegistry.get(aTier); + if (aData.getValue_1() == aInitStructureCheck && aData.getValue_2() == aInitStructureCheckMeta) { + return aTier; + } + } + return 0; + } + catch (Throwable t) { + t.printStackTrace(); + return 0; + } + } + + /* + * Catalyst Handling + */ + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> tItems = super.getStoredInputs(); + for (GT_MetaTileEntity_Hatch_Catalysts tHatch : mCatalystBuses) { + tHatch.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + tItems.addAll(tHatch.getContentUsageSlots()); + } + } + return tItems; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java new file mode 100644 index 0000000000..f52f02b5de --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java @@ -0,0 +1,179 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import java.util.ArrayList; + +import gregtech.GT_Mod; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +public class GT_MTE_LargeTurbine_SHSteam extends GregtechMetaTileEntity_LargerTurbineBase { + + public boolean achievement = false; + private boolean looseFit=false; + + public GT_MTE_LargeTurbine_SHSteam(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT_MTE_LargeTurbine_SHSteam(String aName) { + super(aName); + } + + public String[] getTooltip() { + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 9); + } + return new String[]{ + "Controller Block for the XL High Pressure Steam Turbine", + "Size(WxHxD): 3x3x4 (Hollow), Controller (Front centered)", + "1x Superheated Steam Input Hatch (Side centered)", + "1x Maintenance Hatch (Side centered)", + "1x Dynamo Hatch (Back centered)", + "1x Output Hatch for Steam (Side centered)", + mCasingName+"s for the rest (24 at least!)", + "Needs a Turbine Item (Inside controller GUI)", + "Output depending on Rotor and fitting", + "Use screwdriver to adjust fitting of turbine"}; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MTE_LargeTurbine_SHSteam(mName); + } + + @Override + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + @Override + public byte getCasingMeta() { + return 9; + } + + @Override + public byte getCasingTextureIndex() { + return 59; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff) { + if(looseFit) { + aOptFlow*=4; + if(aBaseEff>10000){ + aOptFlow*=Math.pow(1.1f,((aBaseEff-7500)/10000F)*20f); + aBaseEff=7500; + }else if(aBaseEff>7500){ + aOptFlow*=Math.pow(1.1f,((aBaseEff-7500)/10000F)*20f); + aBaseEff*=0.75f; + }else{ + aBaseEff*=0.75f; + } + } + int tEU = 0; + int totalFlow = 0; // Byproducts are based on actual flow + int flow = 0; + int remainingFlow = MathUtils.safeInt((long)(aOptFlow * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + this.realOptFlow = aOptFlow; + + storedFluid=0; + for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { + String fluidName = aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)); + if (fluidName.equals("ic2.fluidSuperheatedSteam")) { + flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + if (!achievement) { + try { + GT_Mod.achievements.issueAchievement(this.getBaseMetaTileEntity().getWorld().getPlayerEntityByName(this.getBaseMetaTileEntity().getOwnerName()), "efficientsteam"); + } catch (Exception e) { + } + achievement = true; + } + }else if(fluidName.equals("fluid.steam") || fluidName.equals("ic2.fluidSteam") || fluidName.equals("fluid.mfr.steam.still.name")){ + depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); + } + } + if(totalFlow<=0)return 0; + tEU = totalFlow; + addOutput(GT_ModHandler.getSteam(totalFlow)); + if (totalFlow != aOptFlow) { + float efficiency = 1.0f - Math.abs((totalFlow - aOptFlow) / (float)aOptFlow); + //if(totalFlow>aOptFlow){efficiency = 1.0f;} + tEU *= efficiency; + tEU = Math.max(1, MathUtils.safeInt((long)tEU * (long)aBaseEff / 10000L)); + } else { + tEU = MathUtils.safeInt((long)tEU * (long)aBaseEff / 10000L); + } + + return tEU; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aSide == getBaseMetaTileEntity().getFrontFacing()) { + looseFit^=true; + GT_Utility.sendChatToPlayer(aPlayer, looseFit ? "Fitting: Loose - More Flow" : "Fitting: Tight - More Efficiency"); + } + super.onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return (looseFit && CORE.RANDOM.nextInt(4)==0)?0:1; + } + + @Override + public String[] getExtraInfoData() { + super.looseFit = looseFit; + return super.getInfoData(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("turbineFitting",looseFit); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + looseFit=aNBT.getBoolean("turbineFitting"); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Large Super-heated Steam Turbine"; + } + +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java new file mode 100644 index 0000000000..2e6f6149e7 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java @@ -0,0 +1,189 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import static gtPlusPlus.core.lib.CORE.RANDOM; + +import java.util.ArrayList; + +import gregtech.GT_Mod; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +public class GT_MTE_LargeTurbine_Steam extends GregtechMetaTileEntity_LargerTurbineBase { + + private float water; + private boolean achievement = false; + private boolean looseFit=false; + + public GT_MTE_LargeTurbine_Steam(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + + public GT_MTE_LargeTurbine_Steam(String aName) { + super(aName); + } + + public String[] getTooltip() { + if (mCasingName.toLowerCase().contains(".name")) { + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, 8); + } + return new String[]{ + "Controller Block for the XL Steam Turbine", + "Size(WxHxD): 3x3x4 (Hollow), Controller (Front centered)", + "1x Steam Input Hatch (Side centered)", + "1x Maintenance Hatch (Side centered)", + "1x Dynamo Hatch (Back centered)", + "1x Output Hatch for Distilled Water (Side centered)", + mCasingName+"s for the rest (24 at least!)", + "Needs a Turbine Item (Inside controller GUI)", + "Output depending on Rotor and fitting", + "Use screwdriver to adjust fitting of turbine"}; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MTE_LargeTurbine_Steam(mName); + } + + @Override + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + @Override + public byte getCasingMeta() { + return 8; + } + + @Override + public byte getCasingTextureIndex() { + return 16; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + private int useWater(float input) { + water = water + input; + int usage = (int) water; + water = water - usage; + return usage; + } + + @Override + int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff) { + if(looseFit) { + aOptFlow*=4; + if(aBaseEff>10000){ + aOptFlow*=Math.pow(1.1f,((aBaseEff-7500)/10000F)*20f); + aBaseEff=7500; + }else if(aBaseEff>7500){ + aOptFlow*=Math.pow(1.1f,((aBaseEff-7500)/10000F)*20f); + aBaseEff*=0.75f; + }else{ + aBaseEff*=0.75f; + } + } + int tEU = 0; + int totalFlow = 0; // Byproducts are based on actual flow + int flow = 0; + int remainingFlow = MathUtils.safeInt((long)(aOptFlow * 1.25f)); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + this.realOptFlow = aOptFlow; + + storedFluid=0; + for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { // loop through each hatch; extract inputs and track totals. + String fluidName = aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)); + if (fluidName.equals("fluid.steam") || fluidName.equals("ic2.fluidSteam") || fluidName.equals("fluid.mfr.steam.still.name")) { + flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + if (!achievement) { + GT_Mod.achievements.issueAchievement(this.getBaseMetaTileEntity().getWorld().getPlayerEntityByName(this.getBaseMetaTileEntity().getOwnerName()), "muchsteam"); + achievement = true; + } + }else if(fluidName.equals("ic2.fluidSuperheatedSteam")){ + depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); + } + } + if(totalFlow<=0)return 0; + tEU = totalFlow; + int waterToOutput = useWater(totalFlow / 160.0f); + addOutput(GT_ModHandler.getDistilledWater(waterToOutput)); + if (totalFlow != aOptFlow) { + float efficiency = 1.0f - Math.abs((totalFlow - aOptFlow) / (float)aOptFlow); + //if(totalFlow>aOptFlow){efficiency = 1.0f;} + tEU *= efficiency; + tEU = Math.max(1, MathUtils.safeInt((long)tEU * (long)aBaseEff / 20000L)); + } else { + tEU = MathUtils.safeInt((long)tEU * (long)aBaseEff / 20000L); + } + + return tEU; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aSide == getBaseMetaTileEntity().getFrontFacing()) { + looseFit^=true; + GT_Utility.sendChatToPlayer(aPlayer, looseFit ? "Fitting: Loose - More Flow" : "Fitting: Tight - More Efficiency"); + } + super.onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ); + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return (looseFit && RANDOM.nextInt(4)==0)?0:1; + } + + + @Override + public String[] getExtraInfoData() { + super.looseFit = looseFit; + return super.getInfoData(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("turbineFitting",looseFit); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + looseFit=aNBT.getBoolean("turbineFitting"); + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Large Steam Turbine"; + } + +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java new file mode 100644 index 0000000000..9da724c6eb --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java @@ -0,0 +1,663 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import java.util.ArrayList; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Turbine; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.StaticFields59; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.turbine.LargeTurbineTextureHandler; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraftforge.fluids.FluidStack; + +public abstract class GregtechMetaTileEntity_LargerTurbineBase extends GregtechMeta_MultiBlockBase { + + protected int baseEff = 0; + protected int optFlow = 0; + protected double realOptFlow = 0; + protected int storedFluid = 0; + protected int counter = 0; + protected boolean looseFit=false; + + private final int mCasingTextureID; + public static String mCasingName; + + public ArrayList<GT_MetaTileEntity_Hatch_Turbine> mTurbineRotorHatches = new ArrayList<GT_MetaTileEntity_Hatch_Turbine>(); + + public GregtechMetaTileEntity_LargerTurbineBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, getCasingMeta()); + mCasingTextureID = getTAE(); + GT9_5_Active = getCasingMeta() == 8 ? LargeTurbineTextureHandler.frontFaceActive_4 : LargeTurbineTextureHandler.frontFaceHPActive_4; + GT9_5 = getCasingMeta() == 8 ? LargeTurbineTextureHandler.frontFace_4 : LargeTurbineTextureHandler.frontFaceHP_4; + frontFaceActive = new GT_RenderedTexture(GT9_5_Active); + frontFace = new GT_RenderedTexture(GT9_5); + + } + public GregtechMetaTileEntity_LargerTurbineBase(String aName) { + super(aName); + mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, getCasingMeta()); + mCasingTextureID = getTAE(); + GT9_5_Active = getCasingMeta() == 8 ? LargeTurbineTextureHandler.frontFaceActive_4 : LargeTurbineTextureHandler.frontFaceHPActive_4; + GT9_5 = getCasingMeta() == 8 ? LargeTurbineTextureHandler.frontFace_4 : LargeTurbineTextureHandler.frontFaceHP_4; + frontFaceActive = new GT_RenderedTexture(GT9_5_Active); + frontFace = new GT_RenderedTexture(GT9_5); + } + + public final int getTAE() { + return TAE.getIndexFromPage(3, getCasingMeta()); + } + + public final String getCasingNaming() { + return ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings4Misc, getCasingMeta()); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeTurbine.png"); + } + + @Override + public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + return checkMachine2(aBaseMetaTileEntity, aStack); + } + + public boolean checkMachine2(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + //9 high + //7x7 + + this.mDynamoHatches.clear(); + this.mTurbineRotorHatches.clear(); + this.mMaintenanceHatches.clear(); + this.mMufflerHatches.clear(); + this.mInputHatches.clear(); + this.mOutputHatches.clear(); + + for (int i=0;i>-9;i--) { + if (!getLayer(i)) { + Logger.INFO("Bad Layer: "+(+i)); + return false; + } + } + + Logger.INFO("Hatches | Found "+mTurbineRotorHatches.size()+" Rotor Assemblies, "+12+" are required."); + Logger.INFO("Hatches | Found "+mMaintenanceHatches.size()+" Maint. hatches, "+1+" are required."); + Logger.INFO("Hatches | Found "+mDynamoHatches.size()+" Dynamos, "+1+" or more are required."); + Logger.INFO("Hatches | Found "+mMufflerHatches.size()+" Mufflers, "+4+" are required."); + Logger.INFO("Hatches | Found "+mInputHatches.size()+" Input Hatches, "+1+" or more are required."); + Logger.INFO("Hatches | Found "+mOutputHatches.size()+" Output Hatches, "+1+" ore more are required."); + + if (mTurbineRotorHatches.size() != 12 || + mMaintenanceHatches.size() != 1 || + mDynamoHatches.size() < 1 || + mMufflerHatches.size() != 4 || + mInputHatches.size() < 1 || + mOutputHatches.size() < 1 + ) { + return false; + } + Logger.INFO("Built Structure"); + return true; + } + + + public boolean getLayer(int aY) { + if (aY == 0 || aY == -2 || aY == -3 || aY == -5 || aY == -6 || aY == -8) { + return checkNormalLayer(aY); + } + else { + return checkTurbineLayer(aY); + } + } + + public boolean checkNormalLayer(int aY) { + Block tBlock; + int tMeta; + for (int x = -3; x <= 3; x++) { + for (int z = -3; z <= 3; z++) { + tBlock = this.getBaseMetaTileEntity().getBlockOffset(x, aY, z); + tMeta = this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z); + IGregTechTileEntity tTileEntity; + + if (aY == 0 && x == 0 && z == 0) { + continue; + } + else if ((x == 0 && z == -3) || (x == 0 && z == 3) || (x == 3 && z == 0) || (x == -3 && z == 0) || + ((aY == 0) && (x == 0 && z == -2) || (x == 0 && z == 2) || (x == 2 && z == 0) || (x == -2 && z == 0))) { + tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityOffset(x, aY, z); + if (this.addToMachineList(tTileEntity, this.mCasingTextureID)) { + Logger.INFO("Added Hatch at offset "+x+", "+aY+", "+z+" | Type: "+tTileEntity.getInventoryName()); + continue; + } + } + else if (isValidCasingBlock(tBlock, tMeta)) { + continue; + } else { + if (tBlock != null) { + log("Offset: "+x+", "+aY+", "+z); + log("Found "+tBlock.getLocalizedName()+" with Meta "+tMeta); + log("Expected "+getCasingBlock().getLocalizedName()+" with Meta "+getCasingMeta()); + } + return false; + } + } + } + return true; + } + + + public boolean checkTurbineLayer(int aY) { + if (!checkTurbineLayerX(aY)) { + return checkTurbineLayerZ(aY); + } + else { + return true; + } + } + + public boolean checkTurbineLayerX(int aY) { + Logger.INFO("checking X"); + Block tBlock; + int tMeta; + for (int x = -3; x <= 3; x++) { + for (int z = -3; z <= 3; z++) { + tBlock = this.getBaseMetaTileEntity().getBlockOffset(x, aY, z); + tMeta = this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z); + + if ((x == 0 && z == -3) || (x == 0 && z == 3) || (x == 3 && z == 0) || (x == -3 && z == 0) || + ((aY == 0) && (x == 0 && z == -2) || (x == 0 && z == 2) || (x == 2 && z == 0) || (x == -2 && z == 0))) { + IGregTechTileEntity tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityOffset(x, aY, z); + if (this.addToMachineList(tTileEntity, this.mCasingTextureID)) { + Logger.INFO("Added Hatch at offset "+x+", "+aY+", "+z+" | Type: "+tTileEntity.getInventoryName()); + continue; + } + } + + + if (x == -2 || x == 2) { + + //Find Hatches on the ends + if (z == -3 || z == 3) { + IGregTechTileEntity tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityOffset(x, aY, z); + if (this.addTurbineHatch(tTileEntity, this.mCasingTextureID)) { + log("Found x axis Turbine Assembly at Offset: "+x+", "+aY+", "+z); + continue; + } + else { + log("Missing x axis Turbine Assembly at Offset: "+x+", "+aY+", "+z); + } + } + + if (isValidTurbineBlock(tBlock, tMeta)) { + continue; + } + else { + return false; + } + } + else { + if (isValidCasingBlock(tBlock, tMeta)) { + continue; + } + else { + return false; + } + } + } + } + return true; + } + + public boolean checkTurbineLayerZ(int aY) { + Logger.INFO("checking Z"); + Block tBlock; + int tMeta; + for (int x = -3; x <= 3; x++) { + for (int z = -3; z <= 3; z++) { + tBlock = this.getBaseMetaTileEntity().getBlockOffset(x, aY, z); + tMeta = this.getBaseMetaTileEntity().getMetaIDOffset(x, aY, z); + + if ((x == 0 && z == -3) || (x == 0 && z == 3) || (x == 3 && z == 0) || (x == -3 && z == 0) || + ((aY == 0) && (x == 0 && z == -2) || (x == 0 && z == 2) || (x == 2 && z == 0) || (x == -2 && z == 0))) { + IGregTechTileEntity tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityOffset(x, aY, z); + if (this.addToMachineList(tTileEntity, this.mCasingTextureID)) { + Logger.INFO("Added Hatch at offset "+x+", "+aY+", "+z+" | Type: "+tTileEntity.getInventoryName()); + continue; + } + } + + if (z == -2 || z == 2) { + + //Find Hatches on the ends + if (x == -3 || x == 3) { + IGregTechTileEntity tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityOffset(x, aY, z); + if (this.addTurbineHatch(tTileEntity, this.mCasingTextureID)) { + log("Found z axis Turbine Assembly at Offset: "+x+", "+aY+", "+z); + continue; + } + else { + log("Missing z axis Turbine Assembly at Offset: "+x+", "+aY+", "+z); + } + } + + if (isValidTurbineBlock(tBlock, tMeta)) { + continue; + } + else { + return false; + } + } + else { + if (isValidCasingBlock(tBlock, tMeta)) { + continue; + } + else { + return false; + } + } + } + } + return true; + } + + public boolean isValidCasingBlock(Block aBlock, int aMeta) { + if (GregTech_API.sBlockMachines == aBlock) { + return true; + } + if (Block.isEqualTo(aBlock, getCasingBlock()) && (int) aMeta == (int) getCasingMeta()) { + return true; + } + log("Found "+(aBlock != null ? aBlock.getLocalizedName() : "Air") + " With Meta "+aMeta+", Expected "+getCasingBlock().getLocalizedName()+" With Meta "+getCasingMeta()); + return false; + } + + public boolean isValidTurbineBlock(Block aBlock, int aMeta) { + if (aBlock == getCasingBlock() && aMeta == getCasingMetaTurbine()) { + return true; + } + log("Found "+(aBlock != null ? aBlock.getLocalizedName() : "Air") + " With Meta "+aMeta+", Expected "+getCasingBlock().getLocalizedName()+" With Meta "+getCasingMetaTurbine()); + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + public abstract byte getCasingMeta(); + + public byte getCasingMetaTurbine() { + return 7; + } + + public abstract byte getCasingTextureIndex(); + + @Override + public boolean checkRecipe(ItemStack aStack) { + if((counter&7)==0 && (aStack==null || !(aStack.getItem() instanceof GT_MetaGenerated_Tool) || aStack.getItemDamage() < 170 || aStack.getItemDamage() >179)) { + stopMachine(); + return false; + } + ArrayList<FluidStack> tFluids = getStoredFluids(); + if (tFluids.size() > 0) { + if (baseEff == 0 || optFlow == 0 || counter >= 512 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled() + || this.getBaseMetaTileEntity().hasInventoryBeenModified()) { + counter = 0; + baseEff = MathUtils.safeInt((long)((5F + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack)) * 1000F)); + optFlow = MathUtils.safeInt((long)Math.max(Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolStats(aStack).getSpeedMultiplier() + * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed + * 50)); + if(optFlow<=0 || baseEff<=0){ + stopMachine();//in case the turbine got removed + return false; + } + } else { + counter++; + } + } + else { + Logger.INFO("Did not find any valid input fluids."); + } + + int newPower = fluidIntoPower(tFluids, optFlow, baseEff); // How much the turbine should be producing with this flow + int difference = newPower - this.mEUt; // difference between current output and new output + + // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the difference in power level (per tick) + // This is how much the turbine can actually change during this tick + int maxChangeAllowed = Math.max(10, MathUtils.safeInt((long)Math.abs(difference)/100)); + + if (Math.abs(difference) > maxChangeAllowed) { // If this difference is too big, use the maximum allowed change + int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. + this.mEUt += change; // Apply the change + } else { + this.mEUt = newPower; + } + + if (this.mEUt <= 0) { + //stopMachine(); + this.mEUt=0; + this.mEfficiency=0; + return false; + } else { + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 10; + if(this.mDynamoHatches.size()>0){ + for(GT_MetaTileEntity_Hatch dynamo:mDynamoHatches) + if(isValidMetaTileEntity(dynamo) && dynamo.maxEUOutput() < mEUt) + explodeMultiblock(); + } + return true; + } + } + + abstract int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff); + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + public int getMaxEfficiency(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) { + return 0; + } + if (aStack.getItem() instanceof GT_MetaGenerated_Tool_01) { + return 10000; + } + return 0; + } + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return true; + } + + @Override + public String[] getExtraInfoData() { + int mPollutionReduction=0; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { + if (isValidMetaTileEntity(tHatch)) { + mPollutionReduction=Math.max(StaticFields59.calculatePollutionReducation(tHatch, 100),mPollutionReduction); + } + } + + String tRunning = mMaxProgresstime>0 ? + + EnumChatFormatting.GREEN+StatCollector.translateToLocal("GT5U.turbine.running.true")+EnumChatFormatting.RESET : + EnumChatFormatting.RED+StatCollector.translateToLocal("GT5U.turbine.running.false")+EnumChatFormatting.RESET; + String tMaintainance = getIdealStatus() == getRepairStatus() ? + EnumChatFormatting.GREEN+StatCollector.translateToLocal("GT5U.turbine.maintenance.false")+EnumChatFormatting.RESET : + EnumChatFormatting.RED+StatCollector.translateToLocal("GT5U.turbine.maintenance.true")+EnumChatFormatting.RESET ; + int tDura = 0; + + if (mInventory[1] != null && mInventory[1].getItem() instanceof GT_MetaGenerated_Tool_01) { + tDura = MathUtils.safeInt((long)(100.0f / GT_MetaGenerated_Tool.getToolMaxDamage(mInventory[1]) * (GT_MetaGenerated_Tool.getToolDamage(mInventory[1]))+1)); + } + + long storedEnergy=0; + long maxEnergy=0; + for(GT_MetaTileEntity_Hatch_Dynamo tHatch : mDynamoHatches) { + if (isValidMetaTileEntity(tHatch)) { + storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU(); + maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity(); + } + } + String[] ret = new String[]{ + // 8 Lines available for information panels + tRunning + ": " + EnumChatFormatting.RED+mEUt+EnumChatFormatting.RESET+" EU/t", */ +/* 1 *//* + + tMaintainance, */ +/* 2 *//* + + StatCollector.translateToLocal("GT5U.turbine.efficiency")+": "+EnumChatFormatting.YELLOW+(mEfficiency/100F)+EnumChatFormatting.RESET+"%", */ +/* 2 *//* + + StatCollector.translateToLocal("GT5U.multiblock.energy")+": " + EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET +" EU / "+ */ +/* 3 *//* + + EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET +" EU", + StatCollector.translateToLocal("GT5U.turbine.flow")+": "+EnumChatFormatting.YELLOW+MathUtils.safeInt((long)realOptFlow)+EnumChatFormatting.RESET+" L/t" + */ +/* 4 *//* + + EnumChatFormatting.YELLOW+" ("+(looseFit?StatCollector.translateToLocal("GT5U.turbine.loose"):StatCollector.translateToLocal("GT5U.turbine.tight"))+")", */ +/* 5 *//* + + StatCollector.translateToLocal("GT5U.turbine.fuel")+": "+EnumChatFormatting.GOLD+storedFluid+EnumChatFormatting.RESET+"L", */ +/* 6 *//* + + StatCollector.translateToLocal("GT5U.turbine.dmg")+": "+EnumChatFormatting.RED+Integer.toString(tDura)+EnumChatFormatting.RESET+"%", */ +/* 7 *//* + + StatCollector.translateToLocal("GT5U.multiblock.pollution")+": "+ EnumChatFormatting.GREEN + mPollutionReduction+ EnumChatFormatting.RESET+" %" */ +/* 8 *//* + + }; + if (!this.getClass().getName().contains("Steam")) + ret[4]=StatCollector.translateToLocal("GT5U.turbine.flow")+": "+EnumChatFormatting.YELLOW+MathUtils.safeInt((long)realOptFlow)+EnumChatFormatting.RESET+" L/t"; + return ret; + + + } + + @Override + public boolean isGivingInformation() { + return true; + } + + + public boolean polluteEnvironment(int aPollutionLevel) { + mPollution += aPollutionLevel; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { + if (isValidMetaTileEntity(tHatch)) { + if (mPollution >= 1000) { + if (tHatch.polluteEnvironment()) { + mPollution -= 1000; + } + } else { + break; + } + } + } + return mPollution < 1000; + } + @Override + public long maxAmperesOut() { + return 16; + } + + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (!KeyboardUtils.isShiftKeyDown()) { + //super.onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ); + } + else { + this.mIsAnimated = Utils.invertBoolean(mIsAnimated); + if (this.mIsAnimated) { + PlayerUtils.messagePlayer(aPlayer, "Using Animated Turbine Texture."); + } + else { + PlayerUtils.messagePlayer(aPlayer, "Using Static Turbine Texture."); + } + if (mTurbineRotorHatches.size() > 0) { + for (GT_MetaTileEntity_Hatch_Turbine h : mTurbineRotorHatches) { + if (h != null) { + h.mUsingAnimation = mIsAnimated; + } + } + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mIsAnimated", mIsAnimated); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mIsAnimated = aNBT.getBoolean("mIsAnimated"); + } + + private boolean mIsAnimated = true; + public ITexture frontFace; + public ITexture frontFaceActive; + private CustomIcon GT9_5_Active; + private CustomIcon GT9_5; + + public boolean usingAnimations() { + return mIsAnimated; + } + + @Override + public final ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[1][aColorIndex + 1], aFacing == aSide ? getFrontFacingTurbineTexture(aActive) : Textures.BlockIcons.getCasingTextureForId(getTAE())}; + } + + protected ITexture getFrontFacingTurbineTexture(boolean isActive) { + if (usingAnimations()) { + if (isActive) { + return frontFaceActive; + } + } + return frontFace; + } + + public boolean addTurbineHatch(final IGregTechTileEntity aTileEntity, + final int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine) { + log("Found GT_MetaTileEntity_Hatch_Turbine"); + updateTexture(aTileEntity, aBaseCasingIndex); + GT_MetaTileEntity_Hatch_Turbine aTurbineHatch = (GT_MetaTileEntity_Hatch_Turbine) aMetaTileEntity; + IGregTechTileEntity g = this.getBaseMetaTileEntity(); + if (aTurbineHatch.setController(new BlockPos(g.getXCoord(), g.getYCoord(), g.getZCoord(), g.getWorld()))) { + Logger.INFO("Injected Controller into Turbine Assembly."); + return this.mTurbineRotorHatches.add(aTurbineHatch); + } + else { + Logger.INFO("Failed to inject controller into Turbine Assembly Hatch."); + } + } + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + if (mUpdate == 0 || this.mStartUpCheck == 0) { + this.mTurbineRotorHatches.clear(); + } + } + if (aTick % 20 == 0 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()) { + enableAllTurbineHatches(); + } + + } + @Override + public void startProcess() { + super.startProcess(); + enableAllTurbineHatches(); + } + @Override + public void onMachineBlockUpdate() { + super.onMachineBlockUpdate(); + } + @Override + public boolean onRunningTick(ItemStack aStack) { + return super.onRunningTick(aStack); + } + @Override + public void stopMachine() { + super.stopMachine(); + disableAllTurbineHatches(); + } + @Override + public void onRemoval() { + super.onRemoval(); + for (GT_MetaTileEntity_Hatch_Turbine h : this.mTurbineRotorHatches) { + h.clearController(); + } + disableAllTurbineHatches(); + this.mTurbineRotorHatches.clear(); + } + + public boolean enableAllTurbineHatches() { + return updateTurbineHatches(this.isMachineRunning()) > 0; + } + public boolean disableAllTurbineHatches() { + return updateTurbineHatches(false) > 0; + } + + private Long mLastHatchUpdate; + public int updateTurbineHatches(boolean aState) { + int aUpdated = 0; + if (mLastHatchUpdate == null) { + mLastHatchUpdate = System.currentTimeMillis()/1000; + } + if (this.mTurbineRotorHatches.isEmpty() || ((System.currentTimeMillis()/1000)-mLastHatchUpdate) <= 2) { + return 0; + } + for (GT_MetaTileEntity_Hatch_Turbine h : this.mTurbineRotorHatches) { + h.setActive(aState); + aUpdated++; + } + + mLastHatchUpdate = System.currentTimeMillis()/1000; + return aUpdated; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + +} +*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_MultiTank.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_MultiTank.java new file mode 100644 index 0000000000..6ed14eb2a9 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_MultiTank.java @@ -0,0 +1,621 @@ +/* +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.storage; + +import java.util.ArrayList; +import java.util.Arrays; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +public class GregtechMetaTileEntity_MultiTank +extends GregtechMeta_MultiBlockBase { + public GregtechMetaTileEntity_MultiTank(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + private short multiblockCasingCount = 0; + private int mInternalSaveClock = 0; + private final short storageMultiplier = 1; + private int maximumFluidStorage = 128000; + private FluidStack internalStorageTank = null; + private final NBTTagCompound internalCraftingComponentsTag = new NBTTagCompound(); + + @Override + public String getMachineType() { + return "Fluid Tank"; + } + + @Override + public String[] getExtraInfoData() { + final ArrayList<GT_MetaTileEntity_Hatch_Energy> mTier = this.mEnergyHatches; + if (!mTier.isEmpty()){ + final int temp = mTier.get(0).mTier; + if (this.internalStorageTank == null) { + return new String[]{ + GT_Values.VOLTAGE_NAMES[temp]+" Large Fluid Tank", + "Stored Fluid: No Fluid", + "Internal | Current: "+Integer.toString(0) + "L", + "Internal | Maximum: "+Integer.toString(this.maximumFluidStorage) + "L"}; + } + return new String[]{ + GT_Values.VOLTAGE_NAMES[temp]+" Large Fluid Tank", + "Stored Fluid: "+this.internalStorageTank.getLocalizedName(), + "Internal | Current: "+Integer.toString(this.internalStorageTank.amount) + "L", + "Internal | Maximum: "+Integer.toString(this.maximumFluidStorage) + "L"}; + } + return new String[]{ + "Voltage Tier not set -" +" Large Fluid Tank", + "Stored Fluid: No Fluid", + "Internal | Current: "+Integer.toString(0) + "L", + "Internal | Maximum: "+Integer.toString(this.maximumFluidStorage) + "L"}; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + */ +/*final NBTTagCompound gtCraftingComponentsTag = aNBT.getCompoundTag("GT.CraftingComponents"); + if (gtCraftingComponentsTag != null){ + + Utils.LOG_WARNING("Got Crafting Tag"); + + if (this.internalStorageTank != null){ + Utils.LOG_WARNING("mFluid was not null, Saving TileEntity NBT data."); + + gtCraftingComponentsTag.setString("xFluid", this.internalStorageTank.getFluid().getName()); + gtCraftingComponentsTag.setInteger("xAmount", this.internalStorageTank.amount); + gtCraftingComponentsTag.setLong("xAmountMax", this.maximumFluidStorage); + + aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); + } + else { + Utils.LOG_WARNING("mFluid was null, Saving TileEntity NBT data."); + gtCraftingComponentsTag.removeTag("xFluid"); + gtCraftingComponentsTag.removeTag("xAmount"); + gtCraftingComponentsTag.removeTag("xAmountMax"); + gtCraftingComponentsTag.setLong("xAmountMax", this.maximumFluidStorage); + + + aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); + } + }*//* + + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + */ +/*final NBTTagCompound gtCraftingComponentsTag = aNBT.getCompoundTag("GT.CraftingComponents"); + String xFluid = null; + int xAmount = 0; + if (gtCraftingComponentsTag.hasNoTags()){ + if (this.internalStorageTank != null){ + Utils.LOG_WARNING("mFluid was not null, Creating TileEntity NBT data."); + gtCraftingComponentsTag.setInteger("xAmount", this.internalStorageTank.amount); + gtCraftingComponentsTag.setString("xFluid", this.internalStorageTank.getFluid().getName()); + aNBT.setTag("GT.CraftingComponents", gtCraftingComponentsTag); + } + } + else { + + //internalCraftingComponentsTag = gtCraftingComponentsTag.getCompoundTag("backupTag"); + + if (gtCraftingComponentsTag.hasKey("xFluid")){ + Utils.LOG_WARNING("xFluid was not null, Loading TileEntity NBT data."); + xFluid = gtCraftingComponentsTag.getString("xFluid"); + } + if (gtCraftingComponentsTag.hasKey("xAmount")){ + Utils.LOG_WARNING("xAmount was not null, Loading TileEntity NBT data."); + xAmount = gtCraftingComponentsTag.getInteger("xAmount"); + } + if ((xFluid != null) && (xAmount != 0)){ + Utils.LOG_WARNING("Setting Internal Tank, loading "+xAmount+"L of "+xFluid); + this.setInternalTank(xFluid, xAmount); + } + }*//* + + } + + private boolean setInternalTank(final String fluidName, final int amount){ + final FluidStack temp = FluidUtils.getFluidStack(fluidName, amount); + if (temp != null){ + if (this.internalStorageTank == null){ + this.internalStorageTank = temp; + Logger.WARNING(temp.getFluid().getName()+" Amount: "+temp.amount+"L"); + } + else{ + Logger.WARNING("Retained Fluid."); + Logger.WARNING(this.internalStorageTank.getFluid().getName()+" Amxount: "+this.internalStorageTank.amount+"L"); + } + this.markDirty(); + return true; + } + return false; + } + + @Override + public void onLeftclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + this.tryForceNBTUpdate(); + super.onLeftclick(aBaseMetaTileEntity, aPlayer); + } + + @Override + public boolean onWrenchRightClick(final byte aSide, final byte aWrenchingSide, final EntityPlayer aPlayer, final float aX, final float aY, final float aZ) { + this.tryForceNBTUpdate(); + return super.onWrenchRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); + } + + @Override + public void onRemoval() { + this.tryForceNBTUpdate(); + super.onRemoval(); + } + + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + if ((this.internalStorageTank != null) && this.internalStorageTank.amount >= this.maximumFluidStorage){ + if (this.internalStorageTank.amount > this.maximumFluidStorage){ + this.internalStorageTank.amount = this.maximumFluidStorage; + } + this.stopMachine(); + } + + if (this.mInternalSaveClock != 20){ + this.mInternalSaveClock++; + } + else { + this.mInternalSaveClock = 0; + this.tryForceNBTUpdate(); + } + + } + + public GregtechMetaTileEntity_MultiTank(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_MultiTank(this.mName); + } + + @Override + public String[] getTooltip() { + return new String[]{ + "Controller Block for the Multitank", + "Size: 3xHx3 (Block behind controller must be air)", + "Structure must be at least 4 blocks tall, maximum 20.", + "Each casing within the structure adds 128000L storage.", + "Multitank Exterior Casings (16 at least!)", + "Controller (front centered)", + "1x Input hatch", + "1x Output hatch", + "1x Energy Hatch", + }; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(11)), new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Screen_Logo : TexturesGtBlock.Overlay_Machine_Screen_Logo)}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(11))}; + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return null; + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing > 1; + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + + final ArrayList<ItemStack> tInputList = this.getStoredInputs(); + for (int i = 0; i < (tInputList.size() - 1); i++) { + for (int j = i + 1; j < tInputList.size(); j++) { + if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { + if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) { + tInputList.remove(j--); + } else { + tInputList.remove(i--); + break; + } + } + } + } + final ItemStack[] tInputs = Arrays.copyOfRange(tInputList.toArray(new ItemStack[tInputList.size()]), 0, 2); + + final ArrayList<FluidStack> tFluidList = this.getStoredFluids(); + for (int i = 0; i < (tFluidList.size() - 1); i++) { + for (int j = i + 1; j < tFluidList.size(); j++) { + if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { + if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { + tFluidList.remove(j--); + } else { + tFluidList.remove(i--); + break; + } + } + } + } + final FluidStack[] tFluids = Arrays.copyOfRange(tFluidList.toArray(new FluidStack[1]), 0, 1); + + if (tFluids.length >= 2){ + Logger.WARNING("Bad"); + return false; + } + + final ArrayList<Pair<GT_MetaTileEntity_Hatch_Input, Boolean>> rList = new ArrayList<>(); + int slotInputCount = 0; + for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { + boolean containsFluid = false; + if (isValidMetaTileEntity(tHatch)) { + slotInputCount++; + for (int i=0; i<tHatch.getBaseMetaTileEntity().getSizeInventory(); i++) { + if (tHatch.canTankBeEmptied()){containsFluid=true;} + } + rList.add(new Pair<>(tHatch, containsFluid)); + } + } + if ((tFluids.length <= 0) || (slotInputCount > 1)){ + Logger.WARNING("Bad"); + return false; + } + + Logger.WARNING("Okay - 2"); + if (this.internalStorageTank == null){ + Logger.WARNING("Okay - 3"); + if ((rList.get(0).getKey().mFluid != null) && (rList.get(0).getKey().mFluid.amount > 0)){ + Logger.WARNING("Okay - 4"); + Logger.WARNING("Okay - 1"+" rList.get(0).getKey().mFluid.amount: "+rList.get(0).getKey().mFluid.amount */ +/*+" internalStorageTank:"+internalStorageTank.amount*//* +); + final FluidStack tempFluidStack = rList.get(0).getKey().mFluid; + final Fluid tempFluid = tempFluidStack.getFluid(); + this.internalStorageTank = FluidUtils.getFluidStack(tempFluid.getName(), tempFluidStack.amount); + rList.get(0).getKey().mFluid.amount = 0; + Logger.WARNING("Okay - 1.1"+" rList.get(0).getKey().mFluid.amount: "+rList.get(0).getKey().mFluid.amount +" internalStorageTank:"+this.internalStorageTank.amount); + return true; + } + Logger.WARNING("No Fluid in hatch."); + return false; + } + else if (this.internalStorageTank.isFluidEqual(rList.get(0).getKey().mFluid)){ + Logger.WARNING("Storing "+rList.get(0).getKey().mFluid.amount+"L"); + Logger.WARNING("Contains "+this.internalStorageTank.amount+"L"); + + + int tempAdd = 0; + tempAdd = rList.get(0).getKey().getFluidAmount(); + rList.get(0).getKey().mFluid = null; + Logger.WARNING("adding "+tempAdd); + this.internalStorageTank.amount = this.internalStorageTank.amount + tempAdd; + Logger.WARNING("Tank now Contains "+this.internalStorageTank.amount+"L of "+this.internalStorageTank.getFluid().getName()+"."); + + + //Utils.LOG_WARNING("Tank"); + return true; + } + else { + final FluidStack superTempFluidStack = rList.get(0).getKey().mFluid; + Logger.WARNING("is input fluid equal to stored fluid? "+(this.internalStorageTank.isFluidEqual(superTempFluidStack))); + if (superTempFluidStack != null) { + Logger.WARNING("Input hatch[0] Contains "+superTempFluidStack.amount+"L of "+superTempFluidStack.getFluid().getName()+"."); + } + Logger.WARNING("Large Multi-Tank Contains "+this.internalStorageTank.amount+"L of "+this.internalStorageTank.getFluid().getName()+"."); + + if (this.internalStorageTank.amount <= 0){ + Logger.WARNING("Internal Tank is empty, sitting idle."); + return false; + } + + if ((this.mOutputHatches.get(0).mFluid == null) || this.mOutputHatches.isEmpty() || (this.mOutputHatches.get(0).mFluid.isFluidEqual(this.internalStorageTank) && (this.mOutputHatches.get(0).mFluid.amount < this.mOutputHatches.get(0).getCapacity()))){ + Logger.WARNING("Okay - 3"); + final int tempCurrentStored = this.internalStorageTank.amount; + int tempResult = 0; + final int tempHatchSize = this.mOutputHatches.get(0).getCapacity(); + final int tempHatchCurrentHolding = this.mOutputHatches.get(0).getFluidAmount(); + final int tempHatchRemainingSpace = tempHatchSize - tempHatchCurrentHolding; + final FluidStack tempOutputFluid = this.internalStorageTank; + if (tempHatchRemainingSpace <= 0){ + return false; + } + Logger.WARNING("Okay - 3.1.x"+" hatchCapacity: "+tempHatchSize +" tempCurrentStored: "+tempCurrentStored+" output hatch holds: "+tempHatchCurrentHolding+" tank has "+tempHatchRemainingSpace+"L of space left."); + + if (tempHatchSize >= tempHatchRemainingSpace){ + Logger.WARNING("Okay - 3.1.1"+" hatchCapacity: "+tempHatchSize +" tempCurrentStored: "+tempCurrentStored+" output hatch holds: "+tempHatchCurrentHolding+" tank has "+tempHatchRemainingSpace+"L of space left."); + + int adder; + if ((tempCurrentStored > 0) && (tempCurrentStored <= tempHatchSize)){ + adder = tempCurrentStored; + if (adder >= tempHatchRemainingSpace){ + adder = tempHatchRemainingSpace; + } + } + else { + adder = 0; + if (tempCurrentStored >= tempHatchRemainingSpace){ + adder = tempHatchRemainingSpace; + } + } + + tempResult = adder; + tempOutputFluid.amount = tempResult; + Logger.WARNING("Okay - 3.1.2"+" result: "+tempResult +" tempCurrentStored: "+tempCurrentStored + " filling output hatch with: "+tempOutputFluid.amount+"L of "+tempOutputFluid.getFluid().getName()); + this.mOutputHatches.get(0).fill(tempOutputFluid, true); + //mOutputHatches.get(0).mFluid.amount = tempResult; + this.internalStorageTank.amount = (tempCurrentStored-adder); + Logger.WARNING("Okay - 3.1.3"+" internalTankStorage: "+this.internalStorageTank.amount +"L | output hatch contains: "+this.mOutputHatches.get(0).mFluid.amount+"L of "+this.mOutputHatches.get(0).mFluid.getFluid().getName()); + */ +/*if (internalStorageTank.amount <= 0) + internalStorageTank = null;*//* + + } + Logger.WARNING("Tank ok."); + return true; + } + } + //this.getBaseMetaTileEntity().(tFluids[0].amount, true); + Logger.WARNING("Tank"); + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { + Logger.WARNING("Must be hollow."); + return false; + } + int tAmount = 0; + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int h = -1; h < 19; h++) { + if ((h != 0) || ((((xDir + i) != 0) || ((zDir + j) != 0)) && ((i != 0) || (j != 0)))) { + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); + if ((!this.addMaintenanceToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addOutputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!this.addEnergyInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11)))) { + if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != ModBlocks.blockCasingsMisc) { + if (h < 3){ + Logger.WARNING("Casing Expected."); + return false; + } + else if (h >= 3){ + //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); + } + } + if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j) != 11) { + if (h < 3){ + Logger.WARNING("Wrong Meta."); + return false; + } + else if (h >= 3){ + //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); + } + } + if (h < 3){ + tAmount++; + } + else if (h >= 3){ + if ((aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) == Blocks.air) || aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j).getUnlocalizedName().contains("residual")){ + Logger.WARNING("Found air"); + } + else { + Logger.WARNING("Layer "+(h+2)+" is complete. Adding "+(64000*9)+"L storage to the tank."); + tAmount++; + } + } + } + } + } + } + } + this.multiblockCasingCount = (short) tAmount; + this.maximumFluidStorage = getMaximumTankStorage(tAmount); + Logger.INFO("Your Multitank can be 20 blocks tall."); + Logger.INFO("Casings Count: "+this.multiblockCasingCount+" Valid Multiblock: "+(tAmount >= 16)+" Tank Storage Capacity:"+this.maximumFluidStorage+"L"); + this.tryForceNBTUpdate(); + return tAmount >= 16; + } + + */ +/*public int countCasings() { + Utils.LOG_INFO("Counting Machine Casings"); + try{ + if (this.getBaseMetaTileEntity().getWorld() == null){ + Utils.LOG_INFO("Tile Entity's world was null for casing count."); + return 0; + } + if (this.getBaseMetaTileEntity() == null){ + Utils.LOG_INFO("Tile Entity was null for casing count."); + return 0; + } + } catch(NullPointerException r){ + Utils.LOG_INFO("Null Pointer Exception caught."); + return 0; + } + int xDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetZ; + if (!this.getBaseMetaTileEntity().getAirOffset(xDir, 0, zDir)) { + Utils.LOG_INFO("Failed due to air being misplaced."); + Utils.LOG_WARNING("Must be hollow."); + return 0; + } + int tAmount = 0; + Utils.LOG_INFO("Casing Count set to 0."); + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int h = -1; h < 19; h++) { + if ((h != 0) || (((xDir + i != 0) || (zDir + j != 0)) && ((i != 0) || (j != 0)))) { + IGregTechTileEntity tTileEntity = this.getBaseMetaTileEntity().getIGregTechTileEntityOffset(xDir + i, h, zDir + j); + if ((!addMaintenanceToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addOutputToMachineList(tTileEntity, TAE.GTPP_INDEX(11))) && (!addEnergyInputToMachineList(tTileEntity, TAE.GTPP_INDEX(11)))) { + if (this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j) != ModBlocks.blockCasingsMisc) { + if (h < 3){ + Utils.LOG_WARNING("Casing Expected."); + return 0; + } + else if (h >= 3){ + //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); + } + } + if (this.getBaseMetaTileEntity().getMetaIDOffset(xDir + i, h, zDir + j) != 11) { + if (h < 3){ + Utils.LOG_WARNING("Wrong Meta."); + return 0; + } + else if (h >= 3){ + //Utils.LOG_WARNING("Your Multitank can be 20 blocks tall."); + } + } + if (h < 3){ + tAmount++; + } + else if (h >= 3){ + if (this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j) == Blocks.air || this.getBaseMetaTileEntity().getBlockOffset(xDir + i, h, zDir + j).getUnlocalizedName().contains("residual")){ + Utils.LOG_WARNING("Found air"); + } + else { + Utils.LOG_WARNING("Layer "+(h+2)+" is complete. Adding "+(64000*9)+"L storage to the tank."); + tAmount++; + } + } + } + } + } + } + } + Utils.LOG_INFO("Finished counting."); + multiblockCasingCount = (short) tAmount; + //Utils.LOG_INFO("Your Multitank can be 20 blocks tall."); + Utils.LOG_INFO("Casings Count: "+tAmount+" Valid Multiblock: "+(tAmount >= 16)+" Tank Storage Capacity:"+getMaximumTankStorage(tAmount)+"L"); + return tAmount; + }*//* + + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 5; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private static short getStorageMultiplier(final int casingCount){ + final int tsm = 1*casingCount; + if (tsm <= 0){ + return 1; + } + return (short) tsm; + } + + private static int getMaximumTankStorage(final int casingCount){ + final int multiplier = getStorageMultiplier(casingCount); + final int tempTankStorageMax = 128000*multiplier; + if (tempTankStorageMax <= 0){return 128000;} + return tempTankStorageMax; + } + + private boolean tryForceNBTUpdate(){ +*/ +/* + //Block is invalid. + if ((this == null) || (this.getBaseMetaTileEntity() == null)){ + Utils.LOG_WARNING("Block was not valid for saving data."); + return false; + } + + //Don't need this to run clientside. + if (!this.getBaseMetaTileEntity().isServerSide()) { + return false; + } + + //Internal Tag was not valid. + try{ + if (this.internalCraftingComponentsTag == null){ + Utils.LOG_WARNING("Internal NBT data tag was null."); + return false; + } + } catch (final NullPointerException x){ + Utils.LOG_WARNING("Caught null NBT."); + } + + //Internal tag was valid. + this.saveNBTData(this.internalCraftingComponentsTag); + + + //Mark block for update + int x,y,z = 0; + x = this.getBaseMetaTileEntity().getXCoord(); + y = this.getBaseMetaTileEntity().getYCoord(); + z = this.getBaseMetaTileEntity().getZCoord(); + this.getBaseMetaTileEntity().getWorld().markBlockForUpdate(x, y, z); + + //Mark block dirty, let chunk know it's data has changed and it must be saved to disk. (Albeit slowly) + this.getBaseMetaTileEntity().markDirty();*//* + + return true; + } +}*/ diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java new file mode 100644 index 0000000000..a90c962cae --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -0,0 +1,657 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.storage; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.preloader.asm.AsmConfig; +import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_PowerSubStation; +import gtPlusPlus.xmod.gregtech.api.gui.GUI_PowerSubStation; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBattery; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBattery; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_PowerSubStationController> { + + protected long mAverageEuUsage = 0; + protected long mTotalEnergyAdded = 0; + protected long mTotalEnergyConsumed = 0; + protected long mTotalEnergyLost = 0; + protected boolean mIsOutputtingPower = false; + protected long mBatteryCapacity = 0; + + private final int ENERGY_TAX = 2; + + private int mCasing; + private int[] cellCount = new int[6]; + private IStructureDefinition<GregtechMetaTileEntity_PowerSubStationController> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_PowerSubStationController(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_PowerSubStationController(final String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Energy Buffer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("[BUG] GUI does not work until structure is assembled correctly. (Do Not Report issue)") + .addInfo("Consumes " + this.ENERGY_TAX + "% of the average voltage of all energy type hatches") + .addInfo("Does not require maintenance") + .addInfo("Can be built with variable height between " + (CELL_HEIGHT_MIN + 2) + "-" + (CELL_HEIGHT_MAX + 2) + "") + .addInfo("Hatches can be placed nearly anywhere") + .addInfo("HV Energy/Dynamo Hatches are the lowest tier you can use") + .addInfo("Supports voltages >= UHV using MAX tier components.") + .addSeparator() + .addController("Bottom Center") + .addCasingInfo("Sub-Station External Casings", 10) + .addDynamoHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + if (aSide == aFacing) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(24)), + new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER)}; + } + if (aSide == this.getBaseMetaTileEntity().getBackFacing()) { + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(24)), + mIsOutputtingPower ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[(int) this.getOutputTier()] : Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[(int) this.getInputTier()]}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(23))}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (mBatteryCapacity <= 0) return false; + if (!aBaseMetaTileEntity.isClientSide()) { + aBaseMetaTileEntity.openGUI(aPlayer); + } + return true; + } + + @Override + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_PowerSubStation(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "Ergon Energy - Sub Station"); + } + + @Override + public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_PowerSubStation(aPlayerInventory, aBaseMetaTileEntity); + } + + private void checkMachineProblem(String msg, int xOff, int yOff, int zOff) { + final IGregTechTileEntity te = this.getBaseMetaTileEntity(); + final Block tBlock = te.getBlockOffset(xOff, yOff, zOff); + final byte tMeta = te.getMetaIDOffset(xOff, yOff, zOff); + String name = tBlock.getLocalizedName(); + String problem = msg + ": (" + xOff + ", " + yOff + ", " + zOff + ") " + name + ":" + tMeta; + checkMachineProblem(problem); + } + private void checkMachineProblem(String msg) { + if (!AsmConfig.disableAllLogging) { + Logger.INFO("Power Sub-Station problem: " + msg); + } + } + + public static int getCellTier(Block aBlock, int aMeta) { + if (aBlock == ModBlocks.blockCasings2Misc && aMeta == 7) { + return 4; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 4) { + return 5; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 5) { + return 6; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 6) { + return 7; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 7) { + return 8; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 8) { + return 9; + } else { + return -1; + } + } + + public static int getMetaFromTier(int tier) { + if (tier == 4) return 7; + if (tier >= 5 && tier <= 9) return tier - 1; + return 0; + } + + public static Block getBlockFromTier(int tier) { + switch (tier) { + case 4: return ModBlocks.blockCasings2Misc; + case 5: case 6: case 7: case 8: case 9: return ModBlocks.blockCasings3Misc; + default: return null; + } + } + + public static int getMaxHatchTier(int aCellTier) { + switch(aCellTier) { + case 9: + return CORE.GTNH ? 15 : 9; + default: + if (aCellTier < 4) { + return 0; + } + else { + return aCellTier; + } + } + } + + public static final int CELL_HEIGHT_MAX = 16; + public static final int CELL_HEIGHT_MIN = 2; + + @Override + public IStructureDefinition<GregtechMetaTileEntity_PowerSubStationController> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_PowerSubStationController>builder() + .addShape(mName + "bottom", transpose(new String[][]{ + {"CC~CC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"} + })) + .addShape(mName + "mid", transpose(new String[][]{ + {"CCCCC", "CHHHC", "CHHHC", "CHHHC", "CCCCC"} + })) + .addShape(mName + "top", transpose(new String[][]{ + {"CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC"} + })) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_PowerSubStationController::addPowerSubStationList, TAE.GTPP_INDEX(24), 1 + ), + onElementPass( + x -> ++x.mCasing, + ofBlock( + ModBlocks.blockCasings2Misc, 8 + ) + ) + ) + ) + .addElement( + 'H', + ofChain( + onElementPass( + x -> ++x.cellCount[0], + ofCell(4) + ), + onElementPass( + x -> ++x.cellCount[1], + ofCell(5) + ), + onElementPass( + x -> ++x.cellCount[2], + ofCell(6) + ), + onElementPass( + x -> ++x.cellCount[3], + ofCell(7) + ), + onElementPass( + x -> ++x.cellCount[4], + ofCell(8) + ), + onElementPass( + x -> ++x.cellCount[5], + ofCell(9) + ) + ) + ) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public static <T> IStructureElement<T> ofCell(int aIndex) { + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + int tier = getCellTier(block, meta); + return aIndex == tier; + } + + public int getIndex(int size) { + if (size > 6) size = 6; + return size + 3; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, getBlockFromTier(getIndex(trigger.stackSize)), getMetaFromTier(getIndex(trigger.stackSize))); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock(x, y, z, getBlockFromTier(getIndex(trigger.stackSize)), getMetaFromTier(getIndex(trigger.stackSize)), 3); + } + }; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + int layer = Math.min(stackSize.stackSize + 3, 18); + buildPiece(mName + "bottom" , stackSize, hintsOnly, 2, 0, 0); + for (int i = 1; i < layer - 1; i++) { + buildPiece(mName + "mid", stackSize, hintsOnly, 2, i, 0); + } + buildPiece(mName + "top", stackSize, hintsOnly, 2, layer - 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mAllEnergyHatches.clear(); + mAllDynamoHatches.clear(); + for (int i = 0; i < 6; i++) { + cellCount[i] = 0; + } + if (!checkPiece(mName + "bottom", 2, 0, 0)) + return false; + int layer = 1; + while (checkPiece(mName + "mid", 2, layer, 0)) { + layer ++; + } + if (layer > 19 || !checkPiece(mName + "top", 2, layer, 0)) + return false; + int level = 0; + for (int i = 0; i < 6; i++) { + if (cellCount[i] != 0) { + if (level == 0) level = i + 4; + else return false; + } + } + int tier = getMaxHatchTier(level); + long volSum = 0; + for (GT_MetaTileEntity_Hatch hatch : mAllDynamoHatches) { + if (hatch.mTier > tier || hatch.mTier < 3) return false; + volSum += (8 << (hatch.mTier * 2)); + } + for (GT_MetaTileEntity_Hatch hatch : mAllEnergyHatches) { + if (hatch.mTier > tier || hatch.mTier < 3) return false; + volSum += (8 << (hatch.mTier * 2)); + } + mBatteryCapacity = getCapacityFromCellTier(level) * cellCount[level - 4]; + if (mAllEnergyHatches.size() + mAllDynamoHatches.size() > 0) { + mAverageEuUsage = volSum / (mAllEnergyHatches.size() + mAllDynamoHatches.size()); + } + else mAverageEuUsage = 0; + fixAllMaintenanceIssue(); + return true; + } + + public final boolean addPowerSubStationList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } if (LoadedMods.TecTech) { + if (isThisHatchMultiDynamo(aMetaTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (isThisHatchMultiEnergy(aMetaTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + } + return false; + } + + // Define storage capacity of smallest cell tier (EV) and compute higher tiers from it + private static final long CELL_TIER_EV_CAPACITY = 100 * 1000 * 1000; // one lapotronic orb + private static final long CELL_TIER_MULTIPLIER = 4; // each tier's capacity is this many times the previous tier + + public static long getCapacityFromCellTier(int aOverallCellTier) { + // Use integer math instead of `Math.pow` to avoid range/precision errors + if (aOverallCellTier < 4) return 0; + aOverallCellTier -= 4; + long capacity = CELL_TIER_EV_CAPACITY; + while (aOverallCellTier > 0) { + capacity *= CELL_TIER_MULTIPLIER; + aOverallCellTier--; + } + return capacity; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_PowerSubStationController(this.mName); + } + + //mTotalEnergyAdded + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setLong("mAverageEuUsage", this.mAverageEuUsage); + + //Usage Stats + aNBT.setLong("mTotalEnergyAdded", this.mTotalEnergyAdded); + aNBT.setLong("mTotalEnergyLost", this.mTotalEnergyLost); + aNBT.setLong("mTotalEnergyConsumed", this.mTotalEnergyConsumed); + aNBT.setLong("mTotalRunTime", this.mTotalRunTime); + aNBT.setBoolean("mIsOutputtingPower", this.mIsOutputtingPower); + aNBT.setLong("mBatteryCapacity", this.mBatteryCapacity); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + + // Best not to get a long if the Tag Map is holding an int + if (aNBT.hasKey("mAverageEuUsage")) { + this.mAverageEuUsage = aNBT.getLong("mAverageEuUsage"); + } + + //Usage Stats + this.mTotalEnergyAdded = aNBT.getLong("mTotalEnergyAdded"); + this.mTotalEnergyLost = aNBT.getLong("mTotalEnergyLost"); + this.mTotalEnergyConsumed = aNBT.getLong("mTotalEnergyConsumed"); + this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); + + this.mIsOutputtingPower = aNBT.getBoolean("mIsOutputtingPower"); + + this.mBatteryCapacity = aNBT.getLong("mBatteryCapacity"); + + super.loadNBTData(aNBT); + } + + @Override + public boolean checkRecipe(final ItemStack aStack) { + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + this.mEUt = 0; + this.mEfficiencyIncrease = 10000; + this.fixAllMaintenanceIssue(); + return true; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + private void drawEnergyFromHatch(MetaTileEntity aHatch) { + if (!isValidMetaTileEntity(aHatch)) return; + + long stored = aHatch.getEUVar(); + long voltage = aHatch.maxEUInput() * aHatch.maxAmperesIn(); + + if (voltage > stored) { + return; + } + + if (this.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false)) { + aHatch.setEUVar((stored - voltage)); + this.mTotalEnergyAdded += voltage; + } + } + + private void addEnergyToHatch(MetaTileEntity aHatch) { + if (!isValidMetaTileEntity(aHatch)) return; + + long voltage = aHatch.maxEUOutput() * aHatch.maxAmperesOut(); + + if (aHatch.getEUVar() > aHatch.maxEUStore() - voltage) return; + + if (this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(voltage, false)) { + aHatch.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false); + this.mTotalEnergyConsumed+=voltage; + } + + } + + private long computeEnergyTax() { + float mTax = mAverageEuUsage * (ENERGY_TAX / 100f); + + // Increase tax up to 2x if machine is not fully repaired + mTax = mTax * (1f + (10000f - mEfficiency) / 10000f); + + return MathUtils.roundToClosestLong(mTax); + } + + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + this.fixAllMaintenanceIssue(); + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + // First, decay overcharge (0.1% of stored energy plus 1000 EU per tick) + if (this.getEUVar() > this.mBatteryCapacity) { + long energy = (long) (this.getEUVar() * 0.999f) - 1000; + this.setEUVar(energy); + } + + // Pay Tax + long mDecrease = computeEnergyTax(); + this.mTotalEnergyLost += Math.min(mDecrease, this.getEUVar()); + this.setEUVar(Math.max(0, this.getEUVar() - mDecrease)); + + // Input Power + for (Object THatch : this.mDischargeHatches) { + GT_MetaTileEntity_Hatch_OutputBattery tHatch = (GT_MetaTileEntity_Hatch_OutputBattery) THatch; + drawEnergyFromHatch(tHatch); + } + for (GT_MetaTileEntity_Hatch tHatch : this.mAllEnergyHatches) { + drawEnergyFromHatch(tHatch); + } + + // Output Power + for (Object THatch : this.mChargeHatches) { + GT_MetaTileEntity_Hatch_InputBattery tHatch = (GT_MetaTileEntity_Hatch_InputBattery) THatch; + addEnergyToHatch(tHatch); + } + for (GT_MetaTileEntity_Hatch tHatch : this.mAllDynamoHatches) { + addEnergyToHatch(tHatch); + } + + return true; + + } + + @Override + public boolean drainEnergyInput(long aEU) { + // Not applicable to this machine + return true; + } + + @Override + public boolean addEnergyOutput(long aEU) { + // Not applicable to this machine + return true; + } + + @Override + public long maxEUStore() { + return mBatteryCapacity; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public String[] getExtraInfoData() { + String mode; + if (mIsOutputtingPower) { + mode = EnumChatFormatting.GOLD + "Output" + EnumChatFormatting.RESET; + } else { + mode = EnumChatFormatting.BLUE + "Input" + EnumChatFormatting.RESET; + } + + String storedEnergyText; + if (this.getEUVar() > this.mBatteryCapacity) { + storedEnergyText = EnumChatFormatting.RED + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; + } else { + storedEnergyText = EnumChatFormatting.GREEN + GT_Utility.formatNumbers(this.getEUVar()) + EnumChatFormatting.RESET; + } + + int errorCode = this.getBaseMetaTileEntity().getErrorDisplayID(); + boolean mMaint = (errorCode != 0); + + return new String[]{ + "Ergon Energy - District Sub-Station", + "Stored EU: " + storedEnergyText, + "Capacity: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.maxEUStore()) + EnumChatFormatting.RESET, + "Running Costs: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(this.computeEnergyTax()) + EnumChatFormatting.RESET + " EU/t", + "Controller Mode: " + mode, + "Requires Maintenance: " + (!mMaint ? EnumChatFormatting.GREEN : EnumChatFormatting.RED)+ mMaint + EnumChatFormatting.RESET +" | Code: ["+(!mMaint ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + errorCode + EnumChatFormatting.RESET +"]", + "----------------------", + "Stats for Nerds", + "Total Input: " + EnumChatFormatting.BLUE + GT_Utility.formatNumbers(this.mTotalEnergyAdded) + EnumChatFormatting.RESET + " EU", + "Total Output: " + EnumChatFormatting.GOLD + GT_Utility.formatNumbers(this.mTotalEnergyConsumed) + EnumChatFormatting.RESET + " EU", + "Total Costs: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(this.mTotalEnergyLost) + EnumChatFormatting.RESET + " EU", + }; + } + + @Override + public void explodeMultiblock() { + // TODO Auto-generated method stub + super.explodeMultiblock(); + } + + @Override + public void doExplosion(long aExplosionPower) { + // TODO Auto-generated method stub + super.doExplosion(aExplosionPower); + } + + @Override + public long getMaxInputVoltage() { + return 32768; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isEnetInput() { + return !mIsOutputtingPower; + } + + @Override + public boolean isEnetOutput() { + return mIsOutputtingPower; + } + + @Override + public boolean isInputFacing(byte aSide) { + return (aSide == this.getBaseMetaTileEntity().getBackFacing() && !mIsOutputtingPower); + } + + @Override + public boolean isOutputFacing(byte aSide) { + return (aSide == this.getBaseMetaTileEntity().getBackFacing() && mIsOutputtingPower); + } + + @Override + public long maxAmperesIn() { + return 32; + } + + @Override + public long maxAmperesOut() { + return 32; + } + + @Override + public long maxEUInput() { + return 32768; + } + + @Override + public long maxEUOutput() { + return 32768; + } + + @Override + public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mIsOutputtingPower = Utils.invertBoolean(mIsOutputtingPower); + if (mIsOutputtingPower) { + PlayerUtils.messagePlayer(aPlayer, "Sub-Station is now outputting power from the controller."); + } + else { + PlayerUtils.messagePlayer(aPlayer, "Sub-Station is now inputting power into the controller."); + } + } + +}
\ No newline at end of file |