diff options
author | Martin Robertz <dream-master@gmx.net> | 2021-09-10 08:13:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-10 08:13:11 +0200 |
commit | 68893713798da6107dabadd5ef2773794a5a8200 (patch) | |
tree | 2bb9fcb204aed3559c15b468224eb0a42e15b04a /src | |
parent | e894c267b04fa2bd8adc189ec651fdaa7790d554 (diff) | |
parent | 8c64f13922200ef1c5c8a5196752bc6797b2cc71 (diff) | |
download | GT5-Unofficial-68893713798da6107dabadd5ef2773794a5a8200.tar.gz GT5-Unofficial-68893713798da6107dabadd5ef2773794a5a8200.tar.bz2 GT5-Unofficial-68893713798da6107dabadd5ef2773794a5a8200.zip |
Merge pull request #657 from repo-alt/experimental
Allow configurable non-GT blocks in cleanroom structure
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/gregtech/GT_Mod.java | 3 | ||||
-rw-r--r-- | src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java | 135 |
2 files changed, 107 insertions, 31 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index f42e9a5ced..5266eb246c 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -28,6 +28,7 @@ import gregtech.common.items.GT_MetaGenerated_Tool_01; import gregtech.common.items.behaviors.Behaviour_DataOrb; import gregtech.common.misc.GT_Command; import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Massfabricator; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_Cleanroom; import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase; import gregtech.loaders.ExtraIcons; import gregtech.loaders.load.GT_CoverBehaviorLoader; @@ -379,6 +380,8 @@ public class GT_Mod implements IGT_Mod { gregtechproxy.mExplosionItemDrop = tMainConfig.get("general", "ExplosionItemDrops", false).getBoolean(false); gregtechproxy.mUndergroundOil.getConfig(tMainConfig, "undergroundfluid"); gregtechproxy.mEnableCleanroom = tMainConfig.get("general", "EnableCleanroom", true).getBoolean(true); + if (gregtechproxy.mEnableCleanroom) + GT_MetaTileEntity_Cleanroom.loadConfig(tMainConfig); gregtechproxy.mLowGravProcessing = Loader.isModLoaded(GT_Values.MOD_ID_GC_CORE) && tMainConfig.get("general", "LowGravProcessing", true).getBoolean(true); gregtechproxy.mUseGreatlyShrukenReplacementList = tMainConfig.get("general", "GTNH Optimised Material Loading", true).getBoolean(true); Calendar now = Calendar.getInstance(); 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 80bfb20009..905cb7c2f1 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; @@ -89,7 +94,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; @@ -184,8 +189,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))) { @@ -200,32 +203,44 @@ 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?" - ); + else { + String key = tBlock.getUnlocalizedName() + ":"+ tMeta; + if (config.containsKey(key)) { // check with meta first + otherBlocks.compute(key, (k, v) -> v == null ? 1 : v + 1); + } + else { + key = tBlock.getUnlocalizedName(); + if (config.containsKey(key)) { + otherBlocks.compute(key, (k, v) -> v == null ? 1 : v + 1); + } + else { + if (debugCleanroom) + GT_Log.out.println("Cleanroom: not allowed block " + tBlock.getUnlocalizedName()); + return false; + } } - return false; } } } @@ -234,9 +249,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); @@ -247,12 +273,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) { @@ -342,4 +364,55 @@ public class GT_MetaTileEntity_Cleanroom extends GT_MetaTileEntity_MultiBlockBas public boolean explodesOnComponentBreak(ItemStack aStack) { return false; } + + private static class ConfigEntry { + int percentage; + int allowedCount; + int meta; + ConfigEntry(int percentage, int count, int meta) { + this.percentage = percentage; + this.allowedCount = count; + this.meta = meta; + } + } + private final static HashMap<String, ConfigEntry> config = new HashMap<>(); + + private static final String category = "cleanroom_allowed_blocks"; + private static final int wildcard_meta = Short.MAX_VALUE; + + 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_0", "Name","BW_GlasBlocks"); + cfg.get("cleanroom_allowed_blocks.bw_reinforced_glass_0", "Percentage",50); + cfg.get("cleanroom_allowed_blocks.bw_reinforced_glass_0", "Meta",0); + 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); + cfg.get("cleanroom_allowed_blocks.warded_glass", "Name","tile.blockCosmeticOpaque"); + cfg.get("cleanroom_allowed_blocks.warded_glass", "Meta",2); + cfg.get("cleanroom_allowed_blocks.warded_glass", "Percentage",50); + } + 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")) { + if (cc.containsKey("Meta")) + config.put(name+":"+cc.get("Meta").getInt(), new ConfigEntry(0, cc.get("Count").getInt(), cc.get("Meta").getInt())); + else + config.put(name, new ConfigEntry(0, cc.get("Count").getInt(), wildcard_meta)); + } + else if (cc.containsKey("Percentage")) { + if (cc.containsKey("Meta")) + config.put(name+":"+cc.get("Meta").getInt(), new ConfigEntry(cc.get("Percentage").getInt(), 0, cc.get("Meta").getInt())); + else + config.put(name, new ConfigEntry(cc.get("Percentage").getInt(), 0, wildcard_meta)); + } + } + } } |