001 package net.minecraftforge.liquids; 002 003 import java.util.HashMap; 004 import java.util.Map; 005 006 /** 007 * When creating liquids you should register them with this class. 008 * 009 * @author CovertJaguar <railcraft.wikispaces.com> 010 */ 011 public abstract class LiquidDictionary 012 { 013 014 private static Map<String, LiquidStack> liquids = new HashMap<String, LiquidStack>(); 015 016 /** 017 * When creating liquids you should call this function. 018 * 019 * Upon passing it a name and liquid item it will return either 020 * a preexisting implementation of that liquid or the liquid passed in. 021 * 022 * 023 * @param name the name of the liquid 024 * @param liquid the liquid to use if one doesn't exist 025 * @return 026 */ 027 public static LiquidStack getOrCreateLiquid(String name, LiquidStack liquid) 028 { 029 LiquidStack existing = liquids.get(name); 030 if(existing != null) { 031 return existing.copy(); 032 } 033 liquids.put(name, liquid.copy()); 034 return liquid; 035 } 036 037 /** 038 * Returns the liquid matching the name, 039 * if such a liquid exists. 040 * 041 * Can return null. 042 * 043 * @param name the name of the liquid 044 * @param amount the amout of liquid 045 * @return 046 */ 047 public static LiquidStack getLiquid(String name, int amount) 048 { 049 LiquidStack liquid = liquids.get(name); 050 if(liquid == null) 051 return null; 052 053 liquid = liquid.copy(); 054 liquid.amount = amount; 055 return liquid; 056 } 057 }