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.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.Event;
|
import net.minecraftforge.event.Event;
|
||||||
|
|
||||||
|
import com.google.common.collect.BiMap;
|
||||||
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +19,7 @@ import com.google.common.collect.ImmutableMap;
|
||||||
public abstract class LiquidDictionary
|
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.
|
* When creating liquids you should call this function.
|
||||||
|
@ -37,6 +39,7 @@ public abstract class LiquidDictionary
|
||||||
return existing.copy();
|
return existing.copy();
|
||||||
}
|
}
|
||||||
liquids.put(name, liquid.copy());
|
liquids.put(name, liquid.copy());
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.post(new LiquidRegisterEvent(name, liquid));
|
MinecraftForge.EVENT_BUS.post(new LiquidRegisterEvent(name, liquid));
|
||||||
return liquid;
|
return liquid;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +65,10 @@ public abstract class LiquidDictionary
|
||||||
return liquid;
|
return liquid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LiquidStack getCanonicalLiquid(String name)
|
||||||
|
{
|
||||||
|
return liquids.get(name);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Get an immutable list of the liquids defined
|
* Get an immutable list of the liquids defined
|
||||||
*
|
*
|
||||||
|
@ -86,10 +93,15 @@ public abstract class LiquidDictionary
|
||||||
this.Liquid = liquid.copy();
|
this.Liquid = liquid.copy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
getOrCreateLiquid("Water", new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME));
|
getOrCreateLiquid("Water", new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME));
|
||||||
getOrCreateLiquid("Lava", new LiquidStack(Block.lavaStill, 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;
|
package net.minecraftforge.liquids;
|
||||||
|
|
||||||
import static cpw.mods.fml.relauncher.Side.CLIENT;
|
import static cpw.mods.fml.relauncher.Side.CLIENT;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockFluid;
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -119,6 +123,14 @@ public class LiquidStack
|
||||||
@SideOnly(CLIENT)
|
@SideOnly(CLIENT)
|
||||||
public Icon getRenderingIcon()
|
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;
|
return renderingIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,4 +139,16 @@ public class LiquidStack
|
||||||
{
|
{
|
||||||
this.renderingIcon = icon;
|
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;
|
this.tankPressure = pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getLiquidName()
|
||||||
|
{
|
||||||
|
return liquid!= null ? LiquidDictionary.findLiquidName(liquid) : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue