From 2a643d4c45abcccab94e5f3e47cf81b13f40a3d4 Mon Sep 17 00:00:00 2001 From: immibis Date: Fri, 17 May 2013 20:03:37 +1200 Subject: [PATCH] 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; + } + + +}