From 645b3a35e683b5dddc5374d4449df87db6d4737d Mon Sep 17 00:00:00 2001 From: immibis Date: Fri, 17 May 2013 10:48:55 +1200 Subject: [PATCH 1/3] Added pumping.controlList option. Also fixed BlockIndex hashcode (massively speeding up pump searches) and added a timeout for pump searches. --- common/buildcraft/BuildCraftFactory.java | 5 +++++ common/buildcraft/core/BlockIndex.java | 2 +- common/buildcraft/core/DefaultProps.java | 2 ++ common/buildcraft/factory/TilePump.java | 22 ++++++++++++++++++++-- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/BuildCraftFactory.java b/common/buildcraft/BuildCraftFactory.java index f5883f42..a4733148 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -42,6 +42,7 @@ import buildcraft.factory.BptBlockTank; import buildcraft.factory.FactoryProxy; import buildcraft.factory.FactoryProxyClient; import buildcraft.factory.GuiHandler; +import buildcraft.factory.PumpDimensionList; import buildcraft.factory.TileAutoWorkbench; import buildcraft.factory.TileHopper; import buildcraft.factory.TileMiningWell; @@ -82,6 +83,8 @@ public class BuildCraftFactory { public static boolean hopperDisabled; public static boolean allowMining = true; + + public static PumpDimensionList pumpDimensionList; @Instance("BuildCraft|Factory") public static BuildCraftFactory instance; @@ -155,6 +158,8 @@ public class BuildCraftFactory { @PreInit public void initialize(FMLPreInitializationEvent evt) { allowMining = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "mining.enabled", true).getBoolean(true); + + pumpDimensionList = new PumpDimensionList(BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "pumping.controlList", DefaultProps.PUMP_DIMENSION_LIST).getString()); Property miningWellId = BuildCraftCore.mainConfiguration.getBlock("miningWell.id", DefaultProps.MINING_WELL_ID); Property plainPipeId = BuildCraftCore.mainConfiguration.getBlock("drill.id", DefaultProps.DRILL_ID); diff --git a/common/buildcraft/core/BlockIndex.java b/common/buildcraft/core/BlockIndex.java index 1c5c4c92..2c1470d8 100644 --- a/common/buildcraft/core/BlockIndex.java +++ b/common/buildcraft/core/BlockIndex.java @@ -89,6 +89,6 @@ public class BlockIndex implements Comparable { @Override public int hashCode() { - return i + j << 8 + k << 16; + return (i * 37 + j) * 37 + k; } } diff --git a/common/buildcraft/core/DefaultProps.java b/common/buildcraft/core/DefaultProps.java index 21fe2f7f..c7f1fca0 100644 --- a/common/buildcraft/core/DefaultProps.java +++ b/common/buildcraft/core/DefaultProps.java @@ -32,6 +32,8 @@ public class DefaultProps { public static final String DEFAULT_LANGUAGE = "en_US"; + public static String PUMP_DIMENSION_LIST = "+/*/*,+/-1/Lava"; + public static int WOODEN_GEAR_ID = 19100; public static int STONE_GEAR_ID = 19101; public static int IRON_GEAR_ID = 19102; diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index 69c5dc2f..46e5f0d6 100644 --- a/common/buildcraft/factory/TilePump.java +++ b/common/buildcraft/factory/TilePump.java @@ -25,6 +25,7 @@ import net.minecraftforge.liquids.LiquidContainerRegistry; import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.liquids.LiquidTank; import buildcraft.BuildCraftCore; +import buildcraft.BuildCraftFactory; import buildcraft.api.core.Position; import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; @@ -48,6 +49,8 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I LiquidTank tank; double tubeY = Double.NaN; int aimY = 0; + + private boolean explodeNextTick; private IPowerProvider powerProvider; @@ -62,11 +65,16 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I @Override public void updateEntity() { super.updateEntity(); - + if (tube == null) return; - + if (!CoreProxy.proxy.isRenderWorld(worldObj)) { + if (explodeNextTick) { + worldObj.newExplosion(null, xCoord+0.5, yCoord+0.5, zCoord+0.5, 3.0f, false, true); + return; + } + if (tube.posY - aimY > 0.01) { tubeY = tube.posY - 0.01; @@ -85,6 +93,11 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I if (isPumpableLiquid(index)) { LiquidStack liquidToPump = Utils.liquidFromBlockId(worldObj.getBlockId(index.i, index.j, index.k)); + if(!BuildCraftFactory.pumpDimensionList.isLiquidAllowed(liquidToPump, worldObj.provider.dimensionId)) { + explodeNextTick = true; + return; + } + if (tank.fill(liquidToPump, false) == liquidToPump.amount) { if (powerProvider.useEnergy(10, 10, true) == 10) { @@ -210,6 +223,8 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I return; addToPumpIfLiquid(new BlockIndex(x, y, z), markedBlocks, lastFound, pumpList, liquidId); + + long timeoutTime = System.currentTimeMillis() + 1000; while (lastFound.size() > 0) { TreeSet visitIteration = new TreeSet(lastFound); @@ -228,6 +243,9 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I pumpList = blocksToPump.get(index.j + 1); addToPumpIfLiquid(new BlockIndex(index.i, index.j + 1, index.k), markedBlocks, lastFound, pumpList, liquidId); + + if(System.currentTimeMillis() > timeoutTime) + return; } } } From 2a643d4c45abcccab94e5f3e47cf81b13f40a3d4 Mon Sep 17 00:00:00 2001 From: immibis Date: Fri, 17 May 2013 20:03:37 +1200 Subject: [PATCH 2/3] Added missing class. --- .../buildcraft/factory/PumpDimensionList.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 common/buildcraft/factory/PumpDimensionList.java diff --git a/common/buildcraft/factory/PumpDimensionList.java b/common/buildcraft/factory/PumpDimensionList.java new file mode 100644 index 00000000..b2334831 --- /dev/null +++ b/common/buildcraft/factory/PumpDimensionList.java @@ -0,0 +1,86 @@ +package buildcraft.factory; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import net.minecraftforge.liquids.LiquidDictionary; +import net.minecraftforge.liquids.LiquidStack; + +public class PumpDimensionList { + public PumpDimensionList(String string) { + + entries = new LinkedList(); + + for(String entryString : string.trim().split(",")) { + + Entry e = new Entry(); + + if(entryString.startsWith("+/")) { + e.isWhitelist = true; + } else if(entryString.startsWith("-/")) { + e.isWhitelist = false; + } else + throw new RuntimeException("Malformed pumping.controlList entry: "+entryString+" (must start with +/ or -/)"); + + entryString = entryString.substring(2); + int i = entryString.indexOf('/'); + + if(i < 0) + throw new RuntimeException("Malformed pumping.controlList entry: "+entryString+" (missing second /)"); + + String dimIDString = entryString.substring(0, i); + + if(dimIDString.equals("*")) + e.matchAnyDim = true; + else + e.dimID = Integer.parseInt(dimIDString); + + e.liquidName = entryString.substring(i + 1); + if(e.liquidName.equals("*")) + e.matchAnyLiquid = true; + + entries.add(0, e); + } + + entries = new ArrayList(entries); + } + + private class Entry { + boolean isWhitelist; + LiquidStack liquidStack; + String liquidName; + int dimID; + boolean matchAnyLiquid; + boolean matchAnyDim; + + private void initLiquidStack() { + liquidStack = LiquidDictionary.getLiquid(liquidName, 1); + if(liquidStack == null) + throw new RuntimeException("Configuration error: unknown liquid "+liquidName+" in pumping.controlList"); + } + + boolean matches(LiquidStack liquid, int dim) { + if(!matchAnyLiquid) { + if(liquidStack == null) + initLiquidStack(); + if(!liquidStack.isLiquidEqual(liquid)) + return false; + } + if(!matchAnyDim && dimID != dim) + return false; + return true; + } + } + + private List entries; + + public boolean isLiquidAllowed(LiquidStack liquid, int dim) { + for(Entry e : entries) + if(e.matches(liquid, dim)) + return e.isWhitelist; + return false; + } + + +} From a14a6276275f76c5bea57a471ef0cfa650972299 Mon Sep 17 00:00:00 2001 From: immibis Date: Sat, 18 May 2013 11:33:57 +1200 Subject: [PATCH 3/3] Removed explosions, pumps will just ignore disallowed liquids. --- common/buildcraft/factory/TilePump.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index 46e5f0d6..e86b9d96 100644 --- a/common/buildcraft/factory/TilePump.java +++ b/common/buildcraft/factory/TilePump.java @@ -50,8 +50,6 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I double tubeY = Double.NaN; int aimY = 0; - private boolean explodeNextTick; - private IPowerProvider powerProvider; public TilePump() { @@ -70,11 +68,6 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I return; if (!CoreProxy.proxy.isRenderWorld(worldObj)) { - if (explodeNextTick) { - worldObj.newExplosion(null, xCoord+0.5, yCoord+0.5, zCoord+0.5, 3.0f, false, true); - return; - } - if (tube.posY - aimY > 0.01) { tubeY = tube.posY - 0.01; @@ -93,11 +86,6 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I if (isPumpableLiquid(index)) { LiquidStack liquidToPump = Utils.liquidFromBlockId(worldObj.getBlockId(index.i, index.j, index.k)); - if(!BuildCraftFactory.pumpDimensionList.isLiquidAllowed(liquidToPump, worldObj.provider.dimensionId)) { - explodeNextTick = true; - return; - } - if (tank.fill(liquidToPump, false) == liquidToPump.amount) { if (powerProvider.useEnergy(10, 10, true) == 10) { @@ -275,7 +263,14 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I } private boolean isLiquid(BlockIndex index) { - return index != null && (Utils.liquidFromBlockId(worldObj.getBlockId(index.i, index.j, index.k)) != null); + if(index == null) + return false; + + LiquidStack liquid = Utils.liquidFromBlockId(worldObj.getBlockId(index.i, index.j, index.k)); + if(liquid == null) + return false; + + return BuildCraftFactory.pumpDimensionList.isLiquidAllowed(liquid, worldObj.provider.dimensionId); } @Override