2013-05-23 05:01:19 +00:00
|
|
|
|
|
|
|
package net.minecraftforge.fluids;
|
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
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;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Minecraft Forge Fluid Implementation
|
|
|
|
*
|
|
|
|
* This class is a fluid (liquid or gas) equivalent to "Item." It describes the nature of a fluid
|
|
|
|
* and contains its general properties.
|
|
|
|
*
|
|
|
|
* These properties do not have inherent gameplay mechanics - they are provided so that mods may
|
|
|
|
* choose to take advantage of them.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The default values can be used as a reference point for mods adding fluids such as oil or heavy
|
|
|
|
* water.
|
|
|
|
*
|
|
|
|
* @author King Lemming
|
|
|
|
*
|
|
|
|
*/
|
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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Default value is approximately the real-life density of water in kg/m^3.
|
|
|
|
*/
|
|
|
|
protected int density = 1000;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Viscosity ("thickness") of the fluid - completely arbitrary; negative values are not
|
|
|
|
* permissible.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Useful for rendering the fluid in containers and the world.
|
|
|
|
*
|
|
|
|
* Generally this is associated with negative density fluids.
|
|
|
|
*/
|
|
|
|
protected boolean isGaseous;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there is a Block implementation of the Fluid, the BlockID is linked here.
|
|
|
|
*
|
|
|
|
* 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-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-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-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-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(); }
|
|
|
|
public int getViscosity(FluidStack stack){ return getViscosity(); }
|
|
|
|
public boolean isGaseous(FluidStack stack){ return isGaseous(); }
|
|
|
|
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(); }
|
|
|
|
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(); }
|
|
|
|
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-05-23 05:01:19 +00:00
|
|
|
}
|