2013-05-23 05:01:19 +00:00
|
|
|
package net.minecraftforge.fluids;
|
|
|
|
|
|
|
|
import java.util.Locale;
|
2013-07-27 23:06:16 +00:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
2013-05-23 05:01:19 +00:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.util.Icon;
|
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ForgeDummyContainer;
|
|
|
|
import cpw.mods.fml.common.FMLLog;
|
|
|
|
import cpw.mods.fml.common.LoaderException;
|
2013-09-13 22:04:31 +00:00
|
|
|
import net.minecraft.item.EnumRarity;
|
2013-05-23 05:01:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Minecraft Forge Fluid Implementation
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* This class is a fluid (liquid or gas) equivalent to "Item." It describes the nature of a fluid
|
|
|
|
* and contains its general properties.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* These properties do not have inherent gameplay mechanics - they are provided so that mods may
|
|
|
|
* choose to take advantage of them.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* Fluid implementations are not required to actively use these properties, nor are objects
|
|
|
|
* interfacing with fluids required to make use of them, but it is encouraged.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* The default values can be used as a reference point for mods adding fluids such as oil or heavy
|
|
|
|
* water.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* @author King Lemming
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
*/
|
2013-07-17 04:40:49 +00:00
|
|
|
public class Fluid
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
/** The unique identification name for this fluid. */
|
|
|
|
protected final String fluidName;
|
|
|
|
|
|
|
|
/** The unlocalized name of this fluid. */
|
|
|
|
protected String unlocalizedName;
|
|
|
|
|
|
|
|
/** The Icons for this fluid. */
|
|
|
|
protected Icon stillIcon;
|
|
|
|
protected Icon flowingIcon;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The light level emitted by this fluid.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* Default value is 0, as most fluids do not actively emit light.
|
|
|
|
*/
|
|
|
|
protected int luminosity = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Density of the fluid - completely arbitrary; negative density indicates that the fluid is
|
|
|
|
* lighter than air.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* Default value is approximately the real-life density of water in kg/m^3.
|
|
|
|
*/
|
|
|
|
protected int density = 1000;
|
|
|
|
|
2013-08-01 03:15:42 +00:00
|
|
|
/**
|
|
|
|
* Temperature of the fluid - completely arbitrary; higher temperature indicates that the fluid is
|
|
|
|
* hotter than air.
|
|
|
|
*
|
|
|
|
* Default value is approximately the real-life room temperature of water in degrees Kelvin.
|
|
|
|
*/
|
|
|
|
protected int temperature = 295;
|
|
|
|
|
2013-05-23 05:01:19 +00:00
|
|
|
/**
|
|
|
|
* Viscosity ("thickness") of the fluid - completely arbitrary; negative values are not
|
|
|
|
* permissible.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* Default value is approximately the real-life density of water in m/s^2 (x10^-3).
|
|
|
|
*/
|
|
|
|
protected int viscosity = 1000;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This indicates if the fluid is gaseous.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* Useful for rendering the fluid in containers and the world.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* Generally this is associated with negative density fluids.
|
|
|
|
*/
|
|
|
|
protected boolean isGaseous;
|
|
|
|
|
2013-09-13 22:04:31 +00:00
|
|
|
/**
|
|
|
|
* The rarity of the fluid.
|
|
|
|
*
|
|
|
|
* Used primarily in tool tips.
|
|
|
|
*/
|
2013-09-24 05:54:46 +00:00
|
|
|
protected EnumRarity rarity = EnumRarity.common;
|
2013-09-13 22:04:31 +00:00
|
|
|
|
2013-05-23 05:01:19 +00:00
|
|
|
/**
|
|
|
|
* If there is a Block implementation of the Fluid, the BlockID is linked here.
|
2013-07-27 23:06:16 +00:00
|
|
|
*
|
2013-05-23 05:01:19 +00:00
|
|
|
* The default value of -1 should remain for any Fluid without a Block implementation.
|
|
|
|
*/
|
|
|
|
protected int blockID = -1;
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Fluid(String fluidName)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.fluidName = fluidName.toLowerCase(Locale.ENGLISH);
|
|
|
|
this.unlocalizedName = fluidName;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Fluid setUnlocalizedName(String unlocalizedName)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.unlocalizedName = unlocalizedName;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Fluid setBlockID(int blockID)
|
|
|
|
{
|
|
|
|
if (this.blockID == -1 || this.blockID == blockID)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.blockID = blockID;
|
2013-07-17 04:40:49 +00:00
|
|
|
}
|
|
|
|
else if (!ForgeDummyContainer.forceDuplicateFluidBlockCrash)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
FMLLog.warning("A mod has attempted to assign BlockID " + blockID + " to the Fluid '" + fluidName + "' but this Fluid has already been linked to BlockID "
|
|
|
|
+ this.blockID + ". Configure your mods to prevent this from happening.");
|
2013-07-17 04:40:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
FMLLog.severe("A mod has attempted to assign BlockID " + blockID + " to the Fluid '" + fluidName + "' but this Fluid has already been linked to BlockID "
|
|
|
|
+ this.blockID + ". Configure your mods to prevent this from happening.");
|
|
|
|
throw new LoaderException(new RuntimeException("A mod has attempted to assign BlockID " + blockID + " to the Fluid '" + fluidName
|
|
|
|
+ "' but this Fluid has already been linked to BlockID " + this.blockID + ". Configure your mods to prevent this from happening."));
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Fluid setBlockID(Block block)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return setBlockID(block.blockID);
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Fluid setLuminosity(int luminosity)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.luminosity = luminosity;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Fluid setDensity(int density)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.density = density;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-08-01 03:15:42 +00:00
|
|
|
public Fluid setTemperature(int temperature)
|
|
|
|
{
|
|
|
|
this.temperature = temperature;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Fluid setViscosity(int viscosity)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.viscosity = viscosity;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Fluid setGaseous(boolean isGaseous)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.isGaseous = isGaseous;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-09-13 22:04:31 +00:00
|
|
|
public Fluid setRarity(EnumRarity rarity)
|
|
|
|
{
|
|
|
|
this.rarity = rarity;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final String getName()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return this.fluidName;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final int getID()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return FluidRegistry.getFluidID(this.fluidName);
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final int getBlockID()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return blockID;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final boolean canBePlacedInWorld()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return blockID != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the localized name of this fluid.
|
|
|
|
*/
|
2013-07-17 04:40:49 +00:00
|
|
|
public String getLocalizedName()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
String s = this.getUnlocalizedName();
|
|
|
|
return s == null ? "" : StatCollector.translateToLocal(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the unlocalized name of this fluid.
|
|
|
|
*/
|
2013-07-17 04:40:49 +00:00
|
|
|
public String getUnlocalizedName()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return "fluid." + this.unlocalizedName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns 0 for "/terrain.png". ALL FLUID TEXTURES MUST BE ON THIS SHEET.
|
|
|
|
*/
|
2013-07-17 04:40:49 +00:00
|
|
|
public final int getSpriteNumber()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default Accessors */
|
2013-07-17 04:40:49 +00:00
|
|
|
public final int getLuminosity()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return this.luminosity;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final int getDensity()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return this.density;
|
|
|
|
}
|
|
|
|
|
2013-08-01 03:15:42 +00:00
|
|
|
public final int getTemperature()
|
|
|
|
{
|
|
|
|
return this.temperature;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final int getViscosity()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return this.viscosity;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final boolean isGaseous()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return this.isGaseous;
|
|
|
|
}
|
2013-09-13 22:04:31 +00:00
|
|
|
|
|
|
|
public EnumRarity getRarity()
|
|
|
|
{
|
|
|
|
return rarity;
|
|
|
|
}
|
2013-05-23 05:01:19 +00:00
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public int getColor()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final Fluid setStillIcon(Icon stillIcon)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.stillIcon = stillIcon;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final Fluid setFlowingIcon(Icon flowingIcon)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
this.flowingIcon = flowingIcon;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final Fluid setIcons(Icon stillIcon, Icon flowingIcon)
|
|
|
|
{
|
|
|
|
return this.setStillIcon(stillIcon).setFlowingIcon(flowingIcon);
|
2013-05-23 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public final Fluid setIcons(Icon commonIcon)
|
|
|
|
{
|
|
|
|
return this.setStillIcon(commonIcon).setFlowingIcon(commonIcon);
|
2013-05-23 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Icon getIcon(){ return getStillIcon(); }
|
2013-05-23 05:01:19 +00:00
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Icon getStillIcon()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return this.stillIcon;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public Icon getFlowingIcon()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
return this.flowingIcon;
|
|
|
|
}
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
/* Stack-based Accessors */
|
|
|
|
public int getLuminosity(FluidStack stack){ return getLuminosity(); }
|
|
|
|
public int getDensity(FluidStack stack){ return getDensity(); }
|
2013-08-01 03:15:42 +00:00
|
|
|
public int getTemperature(FluidStack stack){ return getTemperature(); }
|
2013-07-17 04:40:49 +00:00
|
|
|
public int getViscosity(FluidStack stack){ return getViscosity(); }
|
|
|
|
public boolean isGaseous(FluidStack stack){ return isGaseous(); }
|
2013-09-13 22:04:31 +00:00
|
|
|
public EnumRarity getRarity(FluidStack stack){ return getRarity(); }
|
2013-07-17 04:40:49 +00:00
|
|
|
public int getColor(FluidStack stack){ return getColor(); }
|
|
|
|
public Icon getIcon(FluidStack stack){ return getIcon(); }
|
|
|
|
/* World-based Accessors */
|
|
|
|
public int getLuminosity(World world, int x, int y, int z){ return getLuminosity(); }
|
|
|
|
public int getDensity(World world, int x, int y, int z){ return getDensity(); }
|
2013-08-01 03:15:42 +00:00
|
|
|
public int getTemperature(World world, int x, int y, int z){ return getTemperature(); }
|
2013-07-17 04:40:49 +00:00
|
|
|
public int getViscosity(World world, int x, int y, int z){ return getViscosity(); }
|
|
|
|
public boolean isGaseous(World world, int x, int y, int z){ return isGaseous(); }
|
2013-09-13 22:04:31 +00:00
|
|
|
public EnumRarity getRarity(World world, int x, int y, int z){ return getRarity(); }
|
2013-07-17 04:40:49 +00:00
|
|
|
public int getColor(World world, int x, int y, int z){ return getColor(); }
|
|
|
|
public Icon getIcon(World world, int x, int y, int z){ return getIcon(); }
|
2013-07-27 23:06:16 +00:00
|
|
|
|
|
|
|
private static Map<String, String> legacyNames = Maps.newHashMap();
|
|
|
|
static String convertLegacyName(String fluidName)
|
|
|
|
{
|
|
|
|
return fluidName != null && legacyNames.containsKey(fluidName) ? legacyNames.get(fluidName) : fluidName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a legacy liquid name with the Fluids system
|
|
|
|
* @param legacyName The legacy name to recognize
|
|
|
|
* @param canonicalName The canonical fluid name it will become
|
|
|
|
*/
|
|
|
|
public static void registerLegacyName(String legacyName, String canonicalName)
|
|
|
|
{
|
|
|
|
legacyNames.put(legacyName.toLowerCase(Locale.ENGLISH), canonicalName);
|
|
|
|
}
|
2013-05-23 05:01:19 +00:00
|
|
|
}
|