diff options
author | repo_alt <wvk17@yandex.ru> | 2021-09-08 19:20:23 +0300 |
---|---|---|
committer | repo_alt <wvk17@yandex.ru> | 2021-09-08 19:20:23 +0300 |
commit | 9829fdf6ef13c2784897d836d41751908fb2e62f (patch) | |
tree | 80a1fd2164846dd880f048e075adf6215269c298 /src/main/java/gregtech/common/tileentities | |
parent | 7e4f97f71661c524e9598583091cb6d2ed0fd5b6 (diff) | |
download | GT5-Unofficial-9829fdf6ef13c2784897d836d41751908fb2e62f.tar.gz GT5-Unofficial-9829fdf6ef13c2784897d836d41751908fb2e62f.tar.bz2 GT5-Unofficial-9829fdf6ef13c2784897d836d41751908fb2e62f.zip |
Allow configurable non-GT blocks in cleanroom structure
Diffstat (limited to 'src/main/java/gregtech/common/tileentities')
-rw-r--r-- | src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java | 109 |
1 files changed, 78 insertions, 31 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java index e486596fe6..203fe4a08d 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java @@ -1,5 +1,8 @@ package gregtech.common.tileentities.machines.multi; +import java.util.HashMap; +import java.util.Map; + import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.gui.GT_GUIContainer_MultiMachine; @@ -17,6 +20,8 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.input.Keyboard; @@ -91,7 +96,7 @@ public class GT_MetaTileEntity_Cleanroom extends GT_MetaTileEntity_MultiBlockBas int mDoorCount = 0; int mHullCount = 0; int mPlascreteCount = 0; - int mGlassCount = 0; + HashMap<String, Integer> otherBlocks = new HashMap<>(); boolean doorState = false; this.mUpdate = 100; @@ -186,8 +191,6 @@ public class GT_MetaTileEntity_Cleanroom extends GT_MetaTileEntity_MultiBlockBas } } else if (tBlock == GregTech_API.sBlockReinforced && tMeta == 2) { mPlascreteCount++; - } else if (tBlock != null && tBlock.getUnlocalizedName().equals("blockAlloyGlass")) { - ++mGlassCount; } else { IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(dX, dY, dZ); if ((!this.addMaintenanceToMachineList(tTileEntity, 210)) && (!this.addEnergyInputToMachineList(tTileEntity, 210))) { @@ -202,32 +205,35 @@ public class GT_MetaTileEntity_Cleanroom extends GT_MetaTileEntity_MultiBlockBas } mDoorCount++; } else { - if (tTileEntity == null) { - if (debugCleanroom) { - GT_Log.out.println( - "Cleanroom: Missing block? Not a tTileEntity" - ); - } - return false; - } - IMetaTileEntity aMetaTileEntity = tTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - if (debugCleanroom) { - GT_Log.out.println( + if (tTileEntity != null) { + IMetaTileEntity aMetaTileEntity = tTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + if (debugCleanroom) { + GT_Log.out.println( "Cleanroom: Missing block? Not a aMetaTileEntity" - ); + ); + } + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_BasicHull) { + mHullCount++; + } + else { + if (debugCleanroom) { + GT_Log.out.println( + "Cleanroom: Incorrect GT block? " + tBlock.getUnlocalizedName() + ); + } + return false; } - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_BasicHull) { - mHullCount++; } else { - if (debugCleanroom) { - GT_Log.out.println( - "Cleanroom: Incorrect block?" - ); + if (config.containsKey(tBlock.getUnlocalizedName())) + otherBlocks.compute(tBlock.getUnlocalizedName(), (k,v) -> v == null ? 1 : v + 1 ); + else { + if (debugCleanroom) + GT_Log.out.println("Cleanroom: not allowed block " + tBlock.getUnlocalizedName()); + return false; } - return false; } } } @@ -236,9 +242,20 @@ public class GT_MetaTileEntity_Cleanroom extends GT_MetaTileEntity_MultiBlockBas } } } - if (this.mMaintenanceHatches.size() != 1 || this.mEnergyHatches.size() != 1 || mDoorCount != 2 || mHullCount > 10) { + if (this.mMaintenanceHatches.size() != 1 || this.mEnergyHatches.size() != 1 || mDoorCount > 2 || mHullCount > 10) { return false; } + if (mPlascreteCount < 20) + return false; + float ratio = (((float) mPlascreteCount) / 100f); + for (Map.Entry<String, Integer> e : otherBlocks.entrySet()) { + ConfigEntry ce = config.get(e.getKey()); + if (ce.allowedCount > 0) { // count has priority + if (e.getValue() > ce.allowedCount) + return false; + } else if (e.getValue() > ratio * ce.percentage) + return false; + } setCallbacks(x, y, z, aBaseMetaTileEntity); @@ -249,12 +266,8 @@ public class GT_MetaTileEntity_Cleanroom extends GT_MetaTileEntity_MultiBlockBas byte t = (byte) Math.max(1, (byte) (15 / (10000f / this.mEfficiency))); aBaseMetaTileEntity.setInternalOutputRedstoneSignal(i, t); } - - float ratio = (((float) mPlascreteCount) / 100f) * GT_Values.cleanroomGlass; - this.mHeight = -y; - - return mPlascreteCount >= 20 && mGlassCount < (int) Math.floor(ratio); + return true; } private void setCallbacks(int x, int y, int z, IGregTechTileEntity aBaseMetaTileEntity) { @@ -344,4 +357,38 @@ public class GT_MetaTileEntity_Cleanroom extends GT_MetaTileEntity_MultiBlockBas public boolean explodesOnComponentBreak(ItemStack aStack) { return false; } + + private static class ConfigEntry { + int percentage; + int allowedCount; + ConfigEntry(int percentage, int count) { + this.percentage = percentage; + this.allowedCount = count; + } + } + private final static HashMap<String, ConfigEntry> config = new HashMap<>(); + + private static final String category = "cleanroom_allowed_blocks"; + + private static void setDefaultConfigValues(Configuration cfg) { + cfg.get("cleanroom_allowed_blocks.reinforced_glass", "Name","blockAlloyGlass"); + cfg.get("cleanroom_allowed_blocks.reinforced_glass", "Percentage",5); + cfg.get("cleanroom_allowed_blocks.bw_reinforced_glass", "Name","BW_GlasBlocks"); + cfg.get("cleanroom_allowed_blocks.bw_reinforced_glass", "Percentage",100); + cfg.get("cleanroom_allowed_blocks.elevator", "Name","tile.openblocks.elevator"); + cfg.get("cleanroom_allowed_blocks.elevator", "Count",1); + cfg.get("cleanroom_allowed_blocks.travel_anchor", "Name","tile.blockTravelAnchor"); + cfg.get("cleanroom_allowed_blocks.travel_anchor", "Count",1); + } + public static void loadConfig(Configuration cfg) { + if (!cfg.hasCategory(category)) + setDefaultConfigValues(cfg); + for (ConfigCategory cc : cfg.getCategory(category).getChildren()) { + String name = cc.get("Name").getString(); + if (cc.containsKey("Count")) + config.put(name, new ConfigEntry(0, cc.get("Count").getInt())); + else if (cc.containsKey("Percentage")) + config.put(name, new ConfigEntry(cc.get("Percentage").getInt(), 0)); + } + } } |