mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 15:03:04 +00:00
General code cleanup of Fluid system. Made Fluid icons and associated functions non-sided.
This commit is contained in:
1 parent
f7ab5684e9
commit
acb6777ab5
18 files changed
+995
-887
No files matched your search
@@ -14,35 +14,36 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
* @author King Lemming, SirSengir (LiquidStack)
|
||||
*
|
||||
*/
|
||||
public class FluidStack {
|
||||
|
||||
public class FluidStack
|
||||
{
|
||||
public int fluidID;
|
||||
public int amount;
|
||||
public NBTTagCompound tag;
|
||||
|
||||
public FluidStack(Fluid fluid, int amount) {
|
||||
|
||||
public FluidStack(Fluid fluid, int amount)
|
||||
{
|
||||
this.fluidID = fluid.getID();
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public FluidStack(int fluidID, int amount) {
|
||||
|
||||
public FluidStack(int fluidID, int amount)
|
||||
{
|
||||
this.fluidID = fluidID;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public FluidStack(int fluidID, int amount, NBTTagCompound nbt) {
|
||||
|
||||
public FluidStack(int fluidID, int amount, NBTTagCompound nbt)
|
||||
{
|
||||
this(fluidID, amount);
|
||||
|
||||
if (nbt != null) {
|
||||
if (nbt != null)
|
||||
{
|
||||
tag = (NBTTagCompound) nbt.copy();
|
||||
}
|
||||
}
|
||||
|
||||
public FluidStack(FluidStack stack, int amount) {
|
||||
|
||||
public FluidStack(FluidStack stack, int amount)
|
||||
{
|
||||
this(stack.fluidID, amount, stack.tag);
|
||||
}
|
||||
|
||||
@@ -50,40 +51,43 @@ public class FluidStack {
|
||||
* This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack
|
||||
* will return as null.
|
||||
*/
|
||||
public static FluidStack loadFluidStackFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
if (nbt == null || FluidRegistry.getFluid(nbt.getString("FluidName")) == null) {
|
||||
public static FluidStack loadFluidStackFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
if (nbt == null || FluidRegistry.getFluid(nbt.getString("FluidName")) == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
FluidStack stack = new FluidStack(FluidRegistry.getFluidID(nbt.getString("FluidName")), nbt.getInteger("Amount"));
|
||||
|
||||
if (nbt.hasKey("Tag")) {
|
||||
if (nbt.hasKey("Tag"))
|
||||
{
|
||||
stack.tag = nbt.getCompoundTag("Tag");
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setString("FluidName", FluidRegistry.getFluidName(fluidID));
|
||||
nbt.setInteger("Amount", amount);
|
||||
|
||||
if (tag != null) {
|
||||
if (tag != null)
|
||||
{
|
||||
nbt.setTag("Tag", tag);
|
||||
}
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public final Fluid getFluid() {
|
||||
|
||||
public final Fluid getFluid()
|
||||
{
|
||||
return FluidRegistry.getFluid(fluidID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A copy of this FluidStack
|
||||
*/
|
||||
public FluidStack copy() {
|
||||
|
||||
public FluidStack copy()
|
||||
{
|
||||
return new FluidStack(fluidID, amount, tag);
|
||||
}
|
||||
|
||||
@@ -94,21 +98,21 @@ public class FluidStack {
|
||||
* The FluidStack for comparison
|
||||
* @return true if the Fluids (IDs and NBT Tags) are the same
|
||||
*/
|
||||
public boolean isFluidEqual(FluidStack other) {
|
||||
|
||||
public boolean isFluidEqual(FluidStack other)
|
||||
{
|
||||
return other != null && fluidID == other.fluidID && isFluidStackTagEqual(other);
|
||||
}
|
||||
|
||||
private boolean isFluidStackTagEqual(FluidStack other) {
|
||||
|
||||
private boolean isFluidStackTagEqual(FluidStack other)
|
||||
{
|
||||
return tag == null ? other.tag == null : other.tag == null ? false : tag.equals(other.tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the NBT Tags are equal. Useful if the FluidIDs are known to be equal.
|
||||
*/
|
||||
public static boolean areFluidStackTagsEqual(FluidStack stack1, FluidStack stack2) {
|
||||
|
||||
public static boolean areFluidStackTagsEqual(FluidStack stack1, FluidStack stack2)
|
||||
{
|
||||
return stack1 == null && stack2 == null ? true : stack1 == null || stack2 == null ? false : stack1.isFluidStackTagEqual(stack2);
|
||||
}
|
||||
|
||||
@@ -118,8 +122,8 @@ public class FluidStack {
|
||||
* @param other
|
||||
* @return true if this FluidStack contains the other FluidStack (same fluid and >= amount)
|
||||
*/
|
||||
public boolean containsFluid(FluidStack other) {
|
||||
|
||||
public boolean containsFluid(FluidStack other)
|
||||
{
|
||||
return isFluidEqual(other) && amount >= other.amount;
|
||||
}
|
||||
|
||||
@@ -130,8 +134,8 @@ public class FluidStack {
|
||||
* - the FluidStack for comparison
|
||||
* @return true if the two FluidStacks are exactly the same
|
||||
*/
|
||||
public boolean isFluidStackIdentical(FluidStack other) {
|
||||
|
||||
public boolean isFluidStackIdentical(FluidStack other)
|
||||
{
|
||||
return isFluidEqual(other) && amount == other.amount;
|
||||
}
|
||||
|
||||
@@ -143,20 +147,24 @@ public class FluidStack {
|
||||
* The ItemStack for comparison
|
||||
* @return true if the Fluids (IDs and NBT Tags) are the same
|
||||
*/
|
||||
public boolean isFluidEqual(ItemStack other) {
|
||||
|
||||
if (other == null) {
|
||||
public boolean isFluidEqual(ItemStack other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (other.getItem() instanceof IFluidContainerItem) {
|
||||
|
||||
if (other.getItem() instanceof IFluidContainerItem)
|
||||
{
|
||||
return isFluidEqual(((IFluidContainerItem) other.getItem()).getFluid(other));
|
||||
}
|
||||
|
||||
return isFluidEqual(FluidContainerRegistry.getFluidForFilledItem(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
|
||||
public final int hashCode()
|
||||
{
|
||||
return fluidID;
|
||||
}
|
||||
|
||||
@@ -166,12 +174,13 @@ public class FluidStack {
|
||||
* This is included for use in data structures.
|
||||
*/
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
|
||||
if (!(o instanceof FluidStack)) {
|
||||
public final boolean equals(Object o)
|
||||
{
|
||||
if (!(o instanceof FluidStack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return isFluidEqual((FluidStack) o);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user