Some tweaks to the liquid dictionary, to allow for canonical liquid stacks for things like rendering
This commit is contained in:
parent
ce2ebc1d04
commit
83d4be5a05
3 changed files with 43 additions and 2 deletions
|
@ -7,6 +7,8 @@ import net.minecraft.block.Block;
|
|||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +19,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
public abstract class LiquidDictionary
|
||||
{
|
||||
|
||||
private static Map<String, LiquidStack> liquids = new HashMap<String, LiquidStack>();
|
||||
private static BiMap<String, LiquidStack> liquids = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* When creating liquids you should call this function.
|
||||
|
@ -37,6 +39,7 @@ public abstract class LiquidDictionary
|
|||
return existing.copy();
|
||||
}
|
||||
liquids.put(name, liquid.copy());
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new LiquidRegisterEvent(name, liquid));
|
||||
return liquid;
|
||||
}
|
||||
|
@ -62,6 +65,10 @@ public abstract class LiquidDictionary
|
|||
return liquid;
|
||||
}
|
||||
|
||||
public static LiquidStack getCanonicalLiquid(String name)
|
||||
{
|
||||
return liquids.get(name);
|
||||
}
|
||||
/**
|
||||
* Get an immutable list of the liquids defined
|
||||
*
|
||||
|
@ -92,4 +99,9 @@ public abstract class LiquidDictionary
|
|||
getOrCreateLiquid("Water", new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME));
|
||||
getOrCreateLiquid("Lava", new LiquidStack(Block.lavaStill, LiquidContainerRegistry.BUCKET_VOLUME));
|
||||
}
|
||||
|
||||
public static String findLiquidName(LiquidStack reference)
|
||||
{
|
||||
return liquids.inverse().get(reference);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package net.minecraftforge.liquids;
|
||||
|
||||
import static cpw.mods.fml.relauncher.Side.CLIENT;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFluid;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -119,6 +123,14 @@ public class LiquidStack
|
|||
@SideOnly(CLIENT)
|
||||
public Icon getRenderingIcon()
|
||||
{
|
||||
if (itemID == Block.waterStill.blockID)
|
||||
{
|
||||
return BlockFluid.func_94424_b("water");
|
||||
}
|
||||
else if (itemID == Block.lavaStill.blockID)
|
||||
{
|
||||
return BlockFluid.func_94424_b("lava");
|
||||
}
|
||||
return renderingIcon;
|
||||
}
|
||||
|
||||
|
@ -127,4 +139,16 @@ public class LiquidStack
|
|||
{
|
||||
this.renderingIcon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode()
|
||||
{
|
||||
return Objects.hashCode(itemID, itemMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object ob)
|
||||
{
|
||||
return ob instanceof LiquidStack && Objects.equal(((LiquidStack)ob).itemID, itemID) && Objects.equal(((LiquidStack)ob).itemMeta, itemMeta);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,4 +139,9 @@ public class LiquidTank implements ILiquidTank {
|
|||
this.tankPressure = pressure;
|
||||
}
|
||||
|
||||
|
||||
public String getLiquidName()
|
||||
{
|
||||
return liquid!= null ? LiquidDictionary.findLiquidName(liquid) : null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue