diff options
7 files changed, 303 insertions, 31 deletions
diff --git a/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java b/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java index c1fcf24110..65469bb457 100644 --- a/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java +++ b/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java @@ -61,7 +61,7 @@ public class COMPAT_HANDLER { //GregtechPowerSubStation.run(); GregtechDehydrator.run(); GregtechAdvancedBoilers.run(); - GregtechPollutionDetector.run(); + GregtechPollutionDevices.run(); GregtechTieredFluidTanks.run(); GregtechIndustrialMultiTank.run(); GregtechGeothermalThermalGenerator.run(); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java b/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java index 26b2c71a5d..3e63f63a20 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java @@ -165,7 +165,9 @@ public enum GregtechItemList implements GregtechItemContainer { Boiler_Advanced_LV, Boiler_Advanced_MV, Boiler_Advanced_HV, //Fancy Pollution Devices - Pollution_Detector + Pollution_Detector, + Pollution_Cleaner_ULV, Pollution_Cleaner_LV, Pollution_Cleaner_MV, Pollution_Cleaner_HV, Pollution_Cleaner_EV, + Pollution_Cleaner_IV, Pollution_Cleaner_LuV, Pollution_Cleaner_ZPM, Pollution_Cleaner_UV, Pollution_Cleaner_MAX ; public static final GregtechItemList[] diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java new file mode 100644 index 0000000000..a2d1c9bb1d --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java @@ -0,0 +1,252 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import static gregtech.api.enums.GT_Values.V; + +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_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gregtech.common.GT_Pollution; +import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gtPlusPlus.core.util.Utils; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_BasicMachine { + + protected int mPollutionReduction = 0; + protected int mBaseEff = 2500; + protected int mOptimalAirFlow = 0; + protected boolean mHasPollution = false; + + private int mDamageFactorLow = 5; + private float mDamageFactorHigh = (float) 0.6000000238418579; + + public GregtechMetaAtmosphericReconditioner(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, "Making sure you don't live in Gwalior", 1, 1, "Massfabricator.png", "", + new ITexture[]{ + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_MASSFAB), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_MASSFAB), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB) + }); + } + + public GregtechMetaAtmosphericReconditioner(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + public GregtechMetaAtmosphericReconditioner(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaAtmosphericReconditioner(this.mName, this.mTier, this.mDescriptionArray, this.mTextures, this.mGUIName, this.mNEIName); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mOptimalAirFlow = aNBT.getInteger("mOptimalAirFlow"); + } + + @Override + public long maxAmperesIn() { + return 4; + } + + @Override + public long getMinimumStoredEU() { + return V[mTier] * 2; + } + + @Override + public long maxEUStore() { + return V[mTier] * 256; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + if (getBaseMetaTileEntity().isServerSide()) { + + } + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + //Only try once/sec. + if (aTick % 20L == 0L){ + Utils.LOG_INFO("Pollution Cleaner [1]"); + + //Check if machine can work. + if ((aBaseMetaTileEntity.isAllowedToWork())/* && (getBaseMetaTileEntity().getRedstone())*/){ + Utils.LOG_INFO("Pollution Cleaner [2] | "+aBaseMetaTileEntity.getStoredEU()+" | "+getMinimumStoredEU()); + + //Check if enough power to work. + if (aBaseMetaTileEntity.getStoredEU() >= getMinimumStoredEU()) { + Utils.LOG_INFO("Pollution Cleaner [3]"); + + //Drain some power. + aBaseMetaTileEntity.decreaseStoredEnergyUnits((long) Math.pow(2, mTier), false); + + //Get Inventory Item + ItemStack aStack = this.mInventory[0]; + + //Get Current Pollution Amount. + int mCurrentPollution = getCurrentChunkPollution(); + + //Do nothing if there is no pollution or machine is not active. + if(this.mHasPollution && mCurrentPollution > 0){ + Utils.LOG_INFO("Pollution Cleaner [4]"); + + //Use a Turbine + if(aStack != null && (aStack.getItem() instanceof GT_MetaGenerated_Tool) && aStack.getItemDamage() >= 170 && aStack.getItemDamage() <= 179){ + Utils.LOG_INFO("Found Turbine."); + mBaseEff = (int) ((50.0F + (10.0F * ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack))) * 100); + mOptimalAirFlow = (int) Math.max(Float.MIN_NORMAL, ((GT_MetaGenerated_Tool) aStack.getItem()).getToolStats(aStack).getSpeedMultiplier() + * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed * 50); + + //Make sure we have a valid Turbine and Eff/Airflow + if (this.mBaseEff > 0 && this.mOptimalAirFlow > 0){ + Utils.LOG_INFO("Pollution Cleaner [5]"); + + //Log Debug information. + Utils.LOG_INFO("mBaseEff[1]:"+mBaseEff); + Utils.LOG_INFO("mOptimalAirFlow[1]:"+mOptimalAirFlow); + + //Calculate The Voltage we are running + long tVoltage = maxEUInput(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + //Check Sides for Air, + //More air means more pollution processing. + int mAirSides = getFreeSpaces(); + + //If no sides are free, how will you process the atmosphere? + if (mAirSides > 0){ + mPollutionReduction += (((mTier*2)*50)*mAirSides); //Was originally *100 + Utils.LOG_INFO("mPollutionReduction[1]:"+mPollutionReduction); + + //I stole this code + mPollutionReduction = GT_Utility.safeInt((long)mPollutionReduction*this.mBaseEff)/10000; + Utils.LOG_INFO("mPollutionReduction[2]:"+mPollutionReduction); + mPollutionReduction = GT_Utility.safeInt((long)mPollutionReduction*this.mOptimalAirFlow/10000); + Utils.LOG_INFO("mPollutionReduction[3]:"+mPollutionReduction); + + //Set a temp to remove variable to aleviate duplicate code. + int toRemove = 0; + + Utils.LOG_INFO("mCurrentPollution[4]:"+mCurrentPollution); + if (mPollutionReduction >= mCurrentPollution){ + //Clean some Air. + toRemove = mPollutionReduction; + } + else { + //Makes sure we don't get negative pollution. + toRemove = mCurrentPollution; + } + + //We are good to clean + if (toRemove > 0){ + removePollution(toRemove); + aBaseMetaTileEntity.setActive(true); + Utils.LOG_INFO("mNewPollution[4]:"+getCurrentChunkPollution()); + } //End of pollution removal block. + } //End of valid air sides block. + } //End of valid toolstats block. + } //End of correct inventory item block. + } //End of Has Pollution block. + } //End of power check block. + } //End of can work block. + else { //Disable Machine. + aBaseMetaTileEntity.setActive(false); + } + } //End of 1/sec action block. + } //End of is serverside block. + } + + +public int getCurrentChunkPollution(){ + return getCurrentChunkPollution(this.getBaseMetaTileEntity()); +} + +public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity){ + int mCurrentChunkPollution = GT_Pollution.getPollution(aBaseMetaTileEntity); + if (mCurrentChunkPollution > 0){ + mHasPollution = true; + } + else { + mHasPollution = false; + } + return mCurrentChunkPollution; +} + +public boolean doDamageToTurbine(){ + try{ + if(mInventory[0].getItem() instanceof GT_MetaGenerated_Tool_01 && + ((GT_MetaGenerated_Tool) mInventory[0].getItem()).getToolStats(mInventory[0]).getSpeedMultiplier()>0 && + GT_MetaGenerated_Tool.getPrimaryMaterial(mInventory[0]).mToolSpeed>0 ) { + return ((GT_MetaGenerated_Tool) mInventory[0].getItem()).doDamage(mInventory[0], 10L*(long) Math.min(-mEUt / mDamageFactorLow, Math.pow(-mEUt, this.mDamageFactorHigh))); + } + } + 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){ + int before = getCurrentChunkPollution(); + GT_Pollution.addPollution(this.getBaseMetaTileEntity(), -toRemove); + int after = getCurrentChunkPollution(); + return (after<before); +} + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java index 784648dfed..f967be41a9 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java @@ -9,6 +9,7 @@ import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Pollution; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.player.PlayerUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; @@ -64,7 +65,7 @@ public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { public ITexture[] getFront(final byte aColor) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2)}; } @@ -177,7 +178,7 @@ public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { } else { PlayerUtils.messagePlayer(playerIn, "This chunk contains "+getCurrentChunkPollution()+" pollution."); - PlayerUtils.messagePlayer(playerIn, "Average over last ten minutes: "+this.mAveragePollution+" pollution."); + PlayerUtils.messagePlayer(playerIn, "Average over last ten minutes: "+getAveragePollutionOverLastTen()+" pollution."); } } @@ -342,6 +343,7 @@ public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { } //Update Pollution array once a minute if (this.mSecondTimer >= 60){ + Utils.sendServerMessage("Udating Average of pollution array. Using Array slot"+this.mArrayPos); this.mSecondTimer = 0; if (this.mArrayPos<this.mAveragePollutionArray.length){ this.mAveragePollutionArray[this.mArrayPos] = this.mCurrentPollution; @@ -358,6 +360,7 @@ public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { 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]; @@ -372,6 +375,7 @@ public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { else { returnValue = getCurrentChunkPollution(); } + Utils.LOG_INFO("| DEBUG: "+returnValue +" | ArrayPos:"+this.mArrayPos+" | Counter:"+counter+" | Total:"+total+" |"); return returnValue; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechAdvancedBoilers.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechAdvancedBoilers.java index 5dae3f5602..ea1279126d 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechAdvancedBoilers.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechAdvancedBoilers.java @@ -22,9 +22,9 @@ public class GregtechAdvancedBoilers { private static void run1(){ //Boilers - GregtechItemList.Boiler_Advanced_LV.set(new GT_MetaTileEntity_Boiler_LV(756, "Advanced Boiler [LV]", 1).getStackForm(1L)); - GregtechItemList.Boiler_Advanced_MV.set(new GT_MetaTileEntity_Boiler_MV(757, "Advanced Boiler [MV]", 2).getStackForm(1L)); - GregtechItemList.Boiler_Advanced_HV.set(new GT_MetaTileEntity_Boiler_HV(758, "Advanced Boiler [HV]", 3).getStackForm(1L)); + GregtechItemList.Boiler_Advanced_LV.set(new GT_MetaTileEntity_Boiler_LV(753, "Advanced Boiler [LV]", 1).getStackForm(1L)); + GregtechItemList.Boiler_Advanced_MV.set(new GT_MetaTileEntity_Boiler_MV(754, "Advanced Boiler [MV]", 2).getStackForm(1L)); + GregtechItemList.Boiler_Advanced_HV.set(new GT_MetaTileEntity_Boiler_HV(755, "Advanced Boiler [HV]", 3).getStackForm(1L)); ItemStack chassisT1 = ItemUtils.getItemStackWithMeta(true, "miscutils:itemBoilerChassis", "Boiler_Chassis_T1", 0, 1); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechPollutionDetector.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechPollutionDetector.java deleted file mode 100644 index fddbbb9e4c..0000000000 --- a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechPollutionDetector.java +++ /dev/null @@ -1,24 +0,0 @@ -package gtPlusPlus.xmod.gregtech.registration.gregtech; - -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; -import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaPollutionDetector; - -public class GregtechPollutionDetector { - - public static void run(){ - if (gtPlusPlus.core.lib.LoadedMods.Gregtech){ - Utils.LOG_INFO("Gregtech5u Content | Registering Pollution Detector."); - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { - run1(); - } - } - } - - private static void run1(){ - //759 - GregtechItemList.Pollution_Detector.set(new GregtechMetaPollutionDetector(759, "pollutiondetector.01.tier.single", "Pollution Detection Device", 0, "Tells you if you're living in Gwalior yet.", 0).getStackForm(1L)); - } - -} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechPollutionDevices.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechPollutionDevices.java new file mode 100644 index 0000000000..0fefa02091 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechPollutionDevices.java @@ -0,0 +1,38 @@ +package gtPlusPlus.xmod.gregtech.registration.gregtech; + +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaAtmosphericReconditioner; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaPollutionDetector; + +public class GregtechPollutionDevices { + + public static void run(){ + if (gtPlusPlus.core.lib.LoadedMods.Gregtech){ + Utils.LOG_INFO("Gregtech5u Content | Registering Anti-Pollution Devices."); + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + run1(); + } + } + } + + private static void run1(){ + //759 + GregtechItemList.Pollution_Detector.set(new GregtechMetaPollutionDetector(756, "pollutiondetector.01.tier.single", "Pollution Detection Device", 0, "Tells you if you're living in Gwalior yet.", 0).getStackForm(1L)); + + GregtechItemList.Pollution_Cleaner_ULV.set(new GregtechMetaAtmosphericReconditioner(757, "pollutioncleaner.01.tier.single", "Pollution Scrubber", 0).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_LV.set(new GregtechMetaAtmosphericReconditioner(758, "pollutioncleaner.02.tier.single", "Upgraded Pollution Scrubber", 1).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_MV.set(new GregtechMetaAtmosphericReconditioner(759, "pollutioncleaner.03.tier.single", "Advanced Pollution Scrubber", 2).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_HV.set(new GregtechMetaAtmosphericReconditioner(760, "pollutioncleaner.04.tier.single", "Precision Pollution Scrubber", 3).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_EV.set(new GregtechMetaAtmosphericReconditioner(761, "pollutioncleaner.05.tier.single", "Air Recycler", 4).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_IV.set(new GregtechMetaAtmosphericReconditioner(762, "pollutioncleaner.06.tier.single", "Upgraded Air Recycler", 5).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_LuV.set(new GregtechMetaAtmosphericReconditioner(763, "pollutioncleaner.07.tier.single", "Advanced Air Recycler", 6).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_ZPM.set(new GregtechMetaAtmosphericReconditioner(764, "pollutioncleaner.08.tier.single", "Precision Air Recycler", 7).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_UV.set(new GregtechMetaAtmosphericReconditioner(765, "pollutioncleaner.09.tier.single", "Atmospheric Cleaner", 8).getStackForm(1L)); + GregtechItemList.Pollution_Cleaner_MAX.set(new GregtechMetaAtmosphericReconditioner(766, "pollutioncleaner.10.tier.single", "Biosphere Cleanser", 9).getStackForm(1L)); + + //767 is free but not 768 + } + +} |