2013-05-23 01:01:19 -04:00
|
|
|
package net.minecraftforge.fluids;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
2013-11-12 01:05:13 -08:00
|
|
|
import net.minecraft.util.StatCollector;
|
2013-05-23 01:01:19 -04:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.BiMap;
|
|
|
|
|
import com.google.common.collect.HashBiMap;
|
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
|
|
2013-12-16 20:18:48 -05:00
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
|
|
|
|
2013-05-23 01:01:19 -04:00
|
|
|
/**
|
|
|
|
|
* Handles Fluid registrations. Fluids MUST be registered in order to function.
|
2013-07-27 23:36:27 +02:00
|
|
|
*
|
2013-05-23 01:01:19 -04:00
|
|
|
* @author King Lemming, CovertJaguar (LiquidDictionary)
|
2013-07-27 23:36:27 +02:00
|
|
|
*
|
2013-05-23 01:01:19 -04:00
|
|
|
*/
|
2014-01-17 21:55:48 -08:00
|
|
|
@SuppressWarnings("unused")
|
2013-07-16 21:40:49 -07:00
|
|
|
public abstract class FluidRegistry
|
|
|
|
|
{
|
2013-12-12 23:32:18 -08:00
|
|
|
/*
|
2013-05-23 01:01:19 -04:00
|
|
|
static int maxID = 0;
|
|
|
|
|
|
|
|
|
|
static HashMap<String, Fluid> fluids = new HashMap();
|
|
|
|
|
static BiMap<String, Integer> fluidIDs = HashBiMap.create();
|
2013-09-05 12:08:16 -04:00
|
|
|
static BiMap<Block, Fluid> fluidBlocks;
|
|
|
|
|
|
2013-11-12 01:05:13 -08:00
|
|
|
public static final Fluid WATER = new Fluid("water") {
|
|
|
|
|
@Override
|
|
|
|
|
public String getLocalizedName() {
|
|
|
|
|
return StatCollector.translateToLocal("tile.water.name");
|
|
|
|
|
}
|
|
|
|
|
}.setBlockID(Block.waterStill.blockID).setUnlocalizedName(Block.waterStill.getUnlocalizedName());
|
|
|
|
|
|
|
|
|
|
public static final Fluid LAVA = new Fluid("lava") {
|
|
|
|
|
@Override
|
|
|
|
|
public String getLocalizedName() {
|
|
|
|
|
return StatCollector.translateToLocal("tile.lava.name");
|
|
|
|
|
}
|
|
|
|
|
}.setBlockID(Block.lavaStill.blockID).setLuminosity(15).setDensity(3000).setViscosity(6000).setTemperature(1300).setUnlocalizedName(Block.lavaStill.getUnlocalizedName());
|
2013-05-23 01:01:19 -04:00
|
|
|
|
|
|
|
|
public static int renderIdFluid = -1;
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
static
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
registerFluid(WATER);
|
|
|
|
|
registerFluid(LAVA);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
private FluidRegistry(){}
|
2013-05-23 01:01:19 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called by Forge to prepare the ID map for server -> client sync.
|
2013-12-12 23:32:18 -08:00
|
|
|
* /
|
2013-07-16 21:40:49 -07:00
|
|
|
static void initFluidIDs(BiMap<String, Integer> newfluidIDs)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
maxID = newfluidIDs.size();
|
|
|
|
|
fluidIDs.clear();
|
|
|
|
|
fluidIDs.putAll(newfluidIDs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register a new Fluid. If a fluid with the same name already exists, registration is denied.
|
2013-07-27 23:36:27 +02:00
|
|
|
*
|
2013-05-23 01:01:19 -04:00
|
|
|
* @param fluid
|
|
|
|
|
* The fluid to register.
|
|
|
|
|
* @return True if the fluid was successfully registered; false if there is a name clash.
|
2013-12-12 23:32:18 -08:00
|
|
|
* /
|
2013-07-16 21:40:49 -07:00
|
|
|
public static boolean registerFluid(Fluid fluid)
|
|
|
|
|
{
|
|
|
|
|
if (fluidIDs.containsKey(fluid.getName()))
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
fluids.put(fluid.getName(), fluid);
|
|
|
|
|
fluidIDs.put(fluid.getName(), ++maxID);
|
|
|
|
|
|
|
|
|
|
MinecraftForge.EVENT_BUS.post(new FluidRegisterEvent(fluid.getName(), maxID));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static boolean isFluidRegistered(Fluid fluid)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return fluidIDs.containsKey(fluid.getName());
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static boolean isFluidRegistered(String fluidName)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return fluidIDs.containsKey(fluidName);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static Fluid getFluid(String fluidName)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return fluids.get(fluidName);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static Fluid getFluid(int fluidID)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return fluids.get(getFluidName(fluidID));
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static String getFluidName(int fluidID)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return fluidIDs.inverse().get(fluidID);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static String getFluidName(FluidStack stack)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return getFluidName(stack.fluidID);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static int getFluidID(String fluidName)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return fluidIDs.get(fluidName);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static FluidStack getFluidStack(String fluidName, int amount)
|
|
|
|
|
{
|
|
|
|
|
if (!fluidIDs.containsKey(fluidName))
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new FluidStack(getFluidID(fluidName), amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a read-only map containing Fluid Names and their associated Fluids.
|
2013-12-12 23:32:18 -08:00
|
|
|
* /
|
2013-07-16 21:40:49 -07:00
|
|
|
public static Map<String, Fluid> getRegisteredFluids()
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return ImmutableMap.copyOf(fluids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a read-only map containing Fluid Names and their associated IDs.
|
2013-12-12 23:32:18 -08:00
|
|
|
* /
|
2013-07-16 21:40:49 -07:00
|
|
|
public static Map<String, Integer> getRegisteredFluidIDs()
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return ImmutableMap.copyOf(fluidIDs);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 12:08:16 -04:00
|
|
|
public static Fluid lookupFluidForBlock(Block block)
|
|
|
|
|
{
|
|
|
|
|
if (fluidBlocks == null)
|
|
|
|
|
{
|
2013-09-14 18:13:58 -04:00
|
|
|
fluidBlocks = HashBiMap.create();
|
2013-09-05 12:08:16 -04:00
|
|
|
for (Fluid fluid : fluids.values())
|
|
|
|
|
{
|
|
|
|
|
if (fluid.canBePlacedInWorld() && Block.blocksList[fluid.getBlockID()] != null)
|
|
|
|
|
{
|
|
|
|
|
fluidBlocks.put(Block.blocksList[fluid.getBlockID()], fluid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fluidBlocks.get(block);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public static class FluidRegisterEvent extends Event
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
public final String fluidName;
|
|
|
|
|
public final int fluidID;
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public FluidRegisterEvent(String fluidName, int fluidID)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
this.fluidName = fluidName;
|
|
|
|
|
this.fluidID = fluidID;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-12 23:32:18 -08:00
|
|
|
*/
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|