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/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; + } + + +} diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index 69c5dc2f..e86b9d96 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,7 +49,7 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I LiquidTank tank; double tubeY = Double.NaN; int aimY = 0; - + private IPowerProvider powerProvider; public TilePump() { @@ -62,10 +63,10 @@ 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 (tube.posY - aimY > 0.01) { tubeY = tube.posY - 0.01; @@ -210,6 +211,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 +231,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; } } } @@ -257,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