Should fix problems with FluidStacks in later Forge versions. Also prevents hoppers from putting too many items into the input slot of the Research Station
This commit is contained in:
parent
a0ffb84891
commit
eec200f133
|
@ -5,6 +5,8 @@ import net.minecraft.nbt.JsonToNBT;
|
||||||
import net.minecraft.nbt.NBTBase;
|
import net.minecraft.nbt.NBTBase;
|
||||||
import net.minecraft.nbt.NBTException;
|
import net.minecraft.nbt.NBTException;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -13,31 +15,24 @@ public class JsonFluidStack implements JsonSerializer<JsonFluidStack>, JsonDeser
|
||||||
{
|
{
|
||||||
public static final Gson jsonSerializer = (new GsonBuilder()).registerTypeAdapter(JsonFluidStack.class, new JsonFluidStack()).create();
|
public static final Gson jsonSerializer = (new GsonBuilder()).registerTypeAdapter(JsonFluidStack.class, new JsonFluidStack()).create();
|
||||||
|
|
||||||
public int fluidID;
|
public Fluid fluid;
|
||||||
public int amount;
|
public int amount;
|
||||||
public NBTTagCompound tag;
|
public NBTTagCompound tag;
|
||||||
|
|
||||||
public JsonFluidStack()
|
public JsonFluidStack()
|
||||||
{
|
{
|
||||||
this.fluidID = Integer.MIN_VALUE;
|
this.fluid = null;
|
||||||
this.amount = 0;
|
this.amount = 0;
|
||||||
this.tag = null;
|
this.tag = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonFluidStack(FluidStack fluidStack)
|
public JsonFluidStack(FluidStack fluidStack)
|
||||||
{
|
{
|
||||||
this.fluidID = fluidStack.fluidID;
|
this.fluid = fluidStack.getFluid();
|
||||||
this.amount = fluidStack.amount;
|
this.amount = fluidStack.amount;
|
||||||
this.tag = fluidStack.tag;
|
this.tag = fluidStack.tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonFluidStack(int fluidID, int amount, NBTTagCompound tag)
|
|
||||||
{
|
|
||||||
this.fluidID = fluidID;
|
|
||||||
this.amount = amount;
|
|
||||||
this.tag = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonFluidStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
public JsonFluidStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||||
{
|
{
|
||||||
|
@ -46,9 +41,9 @@ public class JsonFluidStack implements JsonSerializer<JsonFluidStack>, JsonDeser
|
||||||
JsonObject jsonObject = (JsonObject) json;
|
JsonObject jsonObject = (JsonObject) json;
|
||||||
JsonFluidStack jsonFluidStack = new JsonFluidStack();
|
JsonFluidStack jsonFluidStack = new JsonFluidStack();
|
||||||
|
|
||||||
if (jsonObject.has("fluidID"))
|
if (jsonObject.has("fluidName"))
|
||||||
{
|
{
|
||||||
jsonFluidStack.fluidID = jsonObject.get("fluidID").getAsInt();
|
jsonFluidStack.fluid = FluidRegistry.getFluid(jsonObject.get("fluidName").getAsString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -92,7 +87,7 @@ public class JsonFluidStack implements JsonSerializer<JsonFluidStack>, JsonDeser
|
||||||
{
|
{
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
|
||||||
jsonObject.addProperty("fluidID", src.fluidID);
|
jsonObject.addProperty("fluidName", src.fluid.getName());
|
||||||
jsonObject.addProperty("amount", src.amount);
|
jsonObject.addProperty("amount", src.amount);
|
||||||
|
|
||||||
if (src.tag != null)
|
if (src.tag != null)
|
||||||
|
@ -106,6 +101,6 @@ public class JsonFluidStack implements JsonSerializer<JsonFluidStack>, JsonDeser
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("fluidID: %s, amount: %s, tag: %s", fluidID, amount, tag);
|
return String.format("fluid: %s, amount: %s, tag: %s", fluid, amount, tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,7 +443,7 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
|
||||||
else if (objectType.equalsIgnoreCase("FluidStack"))
|
else if (objectType.equalsIgnoreCase("FluidStack"))
|
||||||
{
|
{
|
||||||
JsonFluidStack jsonFluidStack = JsonFluidStack.jsonSerializer.fromJson(jsonWrappedStack.get("objectData"), JsonFluidStack.class);
|
JsonFluidStack jsonFluidStack = JsonFluidStack.jsonSerializer.fromJson(jsonWrappedStack.get("objectData"), JsonFluidStack.class);
|
||||||
FluidStack fluidStack = new FluidStack(jsonFluidStack.fluidID, jsonFluidStack.amount, jsonFluidStack.tag);
|
FluidStack fluidStack = new FluidStack(jsonFluidStack.fluid, jsonFluidStack.amount, jsonFluidStack.tag);
|
||||||
|
|
||||||
if (stackSize > 0)
|
if (stackSize > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -103,6 +103,7 @@ public class ItemAlchemicalBag extends ItemEE implements IOwnable
|
||||||
|
|
||||||
// Set a UUID on the Alchemical Bag, if one doesn't exist already
|
// Set a UUID on the Alchemical Bag, if one doesn't exist already
|
||||||
NBTHelper.setUUID(itemStack);
|
NBTHelper.setUUID(itemStack);
|
||||||
|
// TODO Do a scan of inventory and if we find a bag with the same UUID, change it's UUID
|
||||||
NBTHelper.setBoolean(itemStack, Names.NBT.ALCHEMICAL_BAG_GUI_OPEN, true);
|
NBTHelper.setBoolean(itemStack, Names.NBT.ALCHEMICAL_BAG_GUI_OPEN, true);
|
||||||
entityPlayer.openGui(EquivalentExchange3.instance, GUIs.ALCHEMICAL_BAG.ordinal(), entityPlayer.worldObj, (int) entityPlayer.posX, (int) entityPlayer.posY, (int) entityPlayer.posZ);
|
entityPlayer.openGui(EquivalentExchange3.instance, GUIs.ALCHEMICAL_BAG.ordinal(), entityPlayer.worldObj, (int) entityPlayer.posX, (int) entityPlayer.posY, (int) entityPlayer.posZ);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class TileEntityResearchStation extends TileEntityEE implements IInventor
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit()
|
public int getInventoryStackLimit()
|
||||||
{
|
{
|
||||||
return 64;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,7 +22,8 @@ public class FluidHelper
|
||||||
{
|
{
|
||||||
if (fluidStack2 != null)
|
if (fluidStack2 != null)
|
||||||
{
|
{
|
||||||
if (fluidStack1.fluidID == fluidStack2.fluidID)
|
// if (fluidStack1.fluidID == fluidStack2.fluidID)
|
||||||
|
if (FluidRegistry.getFluidID(fluidStack1.getFluid()) == FluidRegistry.getFluidID(fluidStack2.getFluid()))
|
||||||
{
|
{
|
||||||
if (fluidStack1.amount == fluidStack2.amount)
|
if (fluidStack1.amount == fluidStack2.amount)
|
||||||
{
|
{
|
||||||
|
@ -56,7 +57,7 @@ public class FluidHelper
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (fluidStack1.fluidID - fluidStack2.fluidID);
|
return (FluidRegistry.getFluidID(fluidStack1.getFluid()) - FluidRegistry.getFluidID(fluidStack2.getFluid()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -84,8 +85,10 @@ public class FluidHelper
|
||||||
if (!FluidRegistry.isFluidRegistered("milk"))
|
if (!FluidRegistry.isFluidRegistered("milk"))
|
||||||
{
|
{
|
||||||
Fluid milk = new Fluid("milk").setUnlocalizedName(Names.Fluids.MILK);
|
Fluid milk = new Fluid("milk").setUnlocalizedName(Names.Fluids.MILK);
|
||||||
FluidRegistry.registerFluid(milk);
|
if (FluidRegistry.registerFluid(milk))
|
||||||
FluidContainerRegistry.registerFluidContainer(new FluidStack(milk, 1000), new ItemStack(Items.milk_bucket), new ItemStack(Items.bucket));
|
{
|
||||||
|
FluidContainerRegistry.registerFluidContainer(new FluidStack(milk, 1000), new ItemStack(Items.milk_bucket), new ItemStack(Items.bucket));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue