mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +00:00
Fix #834 Fix machine fluid handling for IFluidContainerItem
This commit is contained in:
1 parent
614305c690
commit
f49bcfd020
1 file changed
+23
-23
@@ -23,6 +23,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.utils.StackUtils;
|
||||
|
||||
@@ -120,10 +121,10 @@ public final class FluidHelper {
|
||||
}
|
||||
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int slot) {
|
||||
return drainContainers(fluidHandler, inv, slot, slot);
|
||||
return drainContainers(fluidHandler, inv, slot, slot, Defaults.BUCKET_VOLUME);
|
||||
}
|
||||
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, int maxAmount) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
|
||||
@@ -135,36 +136,39 @@ public final class FluidHelper {
|
||||
if (fluidInContainer == null) {
|
||||
return false;
|
||||
}
|
||||
if (fluidInContainer.amount > maxAmount) {
|
||||
fluidInContainer.amount = maxAmount;
|
||||
}
|
||||
|
||||
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||
if (used < fluidInContainer.amount) {
|
||||
|
||||
ItemStack drainedItem = getDrainedContainer(input, used);
|
||||
if (ItemStack.areItemStacksEqual(input, drainedItem)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack emptyItem = getEmptyContainer(input);
|
||||
|
||||
if (output != null && emptyItem != null) {
|
||||
if (output != null && drainedItem != null) {
|
||||
if (outputSlot == inputSlot) {
|
||||
if (input.stackSize > 1) {
|
||||
return false;
|
||||
}
|
||||
} else if (!StackUtils.isIdenticalItem(output, emptyItem)) {
|
||||
} else if (!StackUtils.isIdenticalItem(output, drainedItem)) {
|
||||
return false;
|
||||
} else if (output.stackSize + emptyItem.stackSize > output.getMaxStackSize()) {
|
||||
} else if (output.stackSize + drainedItem.stackSize > output.getMaxStackSize()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
|
||||
|
||||
if (emptyItem != null) {
|
||||
if (drainedItem != null) {
|
||||
if (outputSlot == inputSlot) {
|
||||
inv.setInventorySlotContents(outputSlot, emptyItem);
|
||||
inv.setInventorySlotContents(outputSlot, drainedItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (output == null) {
|
||||
inv.setInventorySlotContents(outputSlot, emptyItem);
|
||||
inv.setInventorySlotContents(outputSlot, drainedItem);
|
||||
} else {
|
||||
output.stackSize++;
|
||||
}
|
||||
@@ -206,15 +210,6 @@ public final class FluidHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ItemStack getEmptyContainer(ItemStack container) {
|
||||
Item item = container.getItem();
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return item.getContainerItem(container);
|
||||
}
|
||||
|
||||
public static ItemStack getDrainedContainer(ItemStack container, int drainAmount) {
|
||||
if (container == null) {
|
||||
return null;
|
||||
@@ -225,15 +220,20 @@ public final class FluidHelper {
|
||||
}
|
||||
|
||||
Item item = container.getItem();
|
||||
if (item instanceof IFluidContainerItem) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
} else if (item instanceof IFluidContainerItem) {
|
||||
ItemStack drained = container.copy();
|
||||
drained.stackSize = 1;
|
||||
IFluidContainerItem containerItem = (IFluidContainerItem) item;
|
||||
containerItem.drain(drained, drainAmount, true);
|
||||
return drained;
|
||||
} else {
|
||||
if (drainAmount < Defaults.BUCKET_VOLUME) {
|
||||
return container;
|
||||
}
|
||||
return item.getContainerItem(container);
|
||||
}
|
||||
|
||||
return getEmptyContainer(container);
|
||||
}
|
||||
|
||||
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
|
||||
|
||||
Reference in new issue
Block a user