Skip to content

Commit

Permalink
Fix fluid stack not doubling (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
firenoo authored Aug 5, 2023
1 parent 64977b8 commit 3d01f50
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,18 @@ public boolean useRealItems() {

static boolean canDouble(SlotFake[] slots, int mult) {
for (Slot s : slots) {
if (s.getStack() != null) {
long result = (long) s.getStack().stackSize * mult;
if (result > Integer.MAX_VALUE) {
return false;
ItemStack st = s.getStack();
if (st != null) {
if (st.getItem() instanceof ItemFluidPacket) {
long result = (long) ItemFluidPacket.getFluidAmount(st) * mult;
if (result > Integer.MAX_VALUE) {
return false;
}
} else {
long result = (long) s.getStack().stackSize * mult;
if (result > Integer.MAX_VALUE) {
return false;
}
}
}
}
Expand All @@ -540,8 +548,11 @@ static void doubleStacksInternal(SlotFake[] slots, int mult) {
for (final Slot s : enabledSlots) {
ItemStack st = s.getStack();
if (st != null) {
st.stackSize *= mult;
s.putStack(st);
if (st.getItem() instanceof ItemFluidPacket) {
ItemFluidPacket.setFluidAmount(st, ItemFluidPacket.getFluidAmount(st) * mult);
} else {
st.stackSize *= mult;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
Expand Down Expand Up @@ -88,6 +89,22 @@ public static FluidStack getFluidStack(@Nullable IAEItemStack stack) {
return stack != null ? getFluidStack(stack.getItemStack()) : null;
}

public static void setFluidAmount(ItemStack stack, int amount) {
if (stack == null || !stack.hasTagCompound()
|| stack.getTagCompound().hasKey("FluidStack", Constants.NBT.TAG_COMPOUND)) {
return;
}
stack.getTagCompound().getCompoundTag("FluidStack").setInteger("Amount", amount);
}

public static int getFluidAmount(ItemStack stack) {
if (stack == null || !stack.hasTagCompound()) {
return 0;
}
// Default to 0 if no tag exists
return stack.getTagCompound().getCompoundTag("FluidStack").getInteger("Amount");
}

@Nullable
public static ItemStack newStack(@Nullable FluidStack fluid) {
if (fluid == null || fluid.amount == 0) {
Expand Down

0 comments on commit 3d01f50

Please sign in to comment.