Merge pull request #857 from immibis/nether-pump
pumping.controlList again.
This commit is contained in:
commit
43c904ed02
5 changed files with 111 additions and 5 deletions
|
@ -42,6 +42,7 @@ import buildcraft.factory.BptBlockTank;
|
||||||
import buildcraft.factory.FactoryProxy;
|
import buildcraft.factory.FactoryProxy;
|
||||||
import buildcraft.factory.FactoryProxyClient;
|
import buildcraft.factory.FactoryProxyClient;
|
||||||
import buildcraft.factory.GuiHandler;
|
import buildcraft.factory.GuiHandler;
|
||||||
|
import buildcraft.factory.PumpDimensionList;
|
||||||
import buildcraft.factory.TileAutoWorkbench;
|
import buildcraft.factory.TileAutoWorkbench;
|
||||||
import buildcraft.factory.TileHopper;
|
import buildcraft.factory.TileHopper;
|
||||||
import buildcraft.factory.TileMiningWell;
|
import buildcraft.factory.TileMiningWell;
|
||||||
|
@ -83,6 +84,8 @@ public class BuildCraftFactory {
|
||||||
|
|
||||||
public static boolean allowMining = true;
|
public static boolean allowMining = true;
|
||||||
|
|
||||||
|
public static PumpDimensionList pumpDimensionList;
|
||||||
|
|
||||||
@Instance("BuildCraft|Factory")
|
@Instance("BuildCraft|Factory")
|
||||||
public static BuildCraftFactory instance;
|
public static BuildCraftFactory instance;
|
||||||
|
|
||||||
|
@ -156,6 +159,8 @@ public class BuildCraftFactory {
|
||||||
public void initialize(FMLPreInitializationEvent evt) {
|
public void initialize(FMLPreInitializationEvent evt) {
|
||||||
allowMining = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "mining.enabled", true).getBoolean(true);
|
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 miningWellId = BuildCraftCore.mainConfiguration.getBlock("miningWell.id", DefaultProps.MINING_WELL_ID);
|
||||||
Property plainPipeId = BuildCraftCore.mainConfiguration.getBlock("drill.id", DefaultProps.DRILL_ID);
|
Property plainPipeId = BuildCraftCore.mainConfiguration.getBlock("drill.id", DefaultProps.DRILL_ID);
|
||||||
Property autoWorkbenchId = BuildCraftCore.mainConfiguration.getBlock("autoWorkbench.id", DefaultProps.AUTO_WORKBENCH_ID);
|
Property autoWorkbenchId = BuildCraftCore.mainConfiguration.getBlock("autoWorkbench.id", DefaultProps.AUTO_WORKBENCH_ID);
|
||||||
|
|
|
@ -89,6 +89,6 @@ public class BlockIndex implements Comparable<BlockIndex> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return i + j << 8 + k << 16;
|
return (i * 37 + j) * 37 + k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ public class DefaultProps {
|
||||||
|
|
||||||
public static final String DEFAULT_LANGUAGE = "en_US";
|
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 WOODEN_GEAR_ID = 19100;
|
||||||
public static int STONE_GEAR_ID = 19101;
|
public static int STONE_GEAR_ID = 19101;
|
||||||
public static int IRON_GEAR_ID = 19102;
|
public static int IRON_GEAR_ID = 19102;
|
||||||
|
|
86
common/buildcraft/factory/PumpDimensionList.java
Normal file
86
common/buildcraft/factory/PumpDimensionList.java
Normal file
|
@ -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<Entry>();
|
||||||
|
|
||||||
|
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<Entry>(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<Entry> entries;
|
||||||
|
|
||||||
|
public boolean isLiquidAllowed(LiquidStack liquid, int dim) {
|
||||||
|
for(Entry e : entries)
|
||||||
|
if(e.matches(liquid, dim))
|
||||||
|
return e.isWhitelist;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||||
import net.minecraftforge.liquids.LiquidStack;
|
import net.minecraftforge.liquids.LiquidStack;
|
||||||
import net.minecraftforge.liquids.LiquidTank;
|
import net.minecraftforge.liquids.LiquidTank;
|
||||||
import buildcraft.BuildCraftCore;
|
import buildcraft.BuildCraftCore;
|
||||||
|
import buildcraft.BuildCraftFactory;
|
||||||
import buildcraft.api.core.Position;
|
import buildcraft.api.core.Position;
|
||||||
import buildcraft.api.power.IPowerProvider;
|
import buildcraft.api.power.IPowerProvider;
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
|
@ -211,6 +212,8 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I
|
||||||
|
|
||||||
addToPumpIfLiquid(new BlockIndex(x, y, z), markedBlocks, lastFound, pumpList, liquidId);
|
addToPumpIfLiquid(new BlockIndex(x, y, z), markedBlocks, lastFound, pumpList, liquidId);
|
||||||
|
|
||||||
|
long timeoutTime = System.currentTimeMillis() + 1000;
|
||||||
|
|
||||||
while (lastFound.size() > 0) {
|
while (lastFound.size() > 0) {
|
||||||
TreeSet<BlockIndex> visitIteration = new TreeSet<BlockIndex>(lastFound);
|
TreeSet<BlockIndex> visitIteration = new TreeSet<BlockIndex>(lastFound);
|
||||||
lastFound.clear();
|
lastFound.clear();
|
||||||
|
@ -228,6 +231,9 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I
|
||||||
pumpList = blocksToPump.get(index.j + 1);
|
pumpList = blocksToPump.get(index.j + 1);
|
||||||
|
|
||||||
addToPumpIfLiquid(new BlockIndex(index.i, index.j + 1, index.k), markedBlocks, lastFound, pumpList, liquidId);
|
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) {
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue