diff --git a/src/main/java/appeng/fluids/helper/DualityFluidInterface.java b/src/main/java/appeng/fluids/helper/DualityFluidInterface.java index 0c49bf82f0e..64b0adfa786 100644 --- a/src/main/java/appeng/fluids/helper/DualityFluidInterface.java +++ b/src/main/java/appeng/fluids/helper/DualityFluidInterface.java @@ -224,8 +224,8 @@ public void gridChanged() { this.items.setInternal(this.gridProxy.getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))); this.fluids.setInternal(this.gridProxy.getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))); } catch (final GridAccessException gae) { - this.items.setInternal(new NullInventory()); - this.fluids.setInternal(new NullInventory()); + this.items.setInternal(new NullInventory<>()); + this.fluids.setInternal(new NullInventory<>()); } this.notifyNeighbors(); @@ -491,6 +491,16 @@ public void onFluidInventoryChanged(IAEFluidTank inv, int slot) { onFluidInventoryChanged(inv, slot, null, null, null); } + @Override + public void onFluidInventoryChanged(final IAEFluidTank inventory, FluidStack added, FluidStack removed) { + if (inventory == this.tanks) { + if (added != null) { + iHost.onStackReturnNetwork(AEFluidStack.fromFluidStack(added)); + } + this.saveChanges(); + } + } + @Override public void onFluidInventoryChanged(final IAEFluidTank inventory, final int slot, InvOperation operation, FluidStack added, FluidStack removed) { if (this.isWorking == slot) { diff --git a/src/main/java/appeng/fluids/util/AEFluidInventory.java b/src/main/java/appeng/fluids/util/AEFluidInventory.java index df07a4be3da..f704ecb1ec3 100644 --- a/src/main/java/appeng/fluids/util/AEFluidInventory.java +++ b/src/main/java/appeng/fluids/util/AEFluidInventory.java @@ -14,7 +14,7 @@ public class AEFluidInventory implements IAEFluidTank { private final IAEFluidStack[] fluids; - private final IAEFluidInventory handler; + protected final IAEFluidInventory handler; private int capacity; private IFluidTankProperties[] props = null; diff --git a/src/main/java/appeng/fluids/util/AENetworkFluidInventory.java b/src/main/java/appeng/fluids/util/AENetworkFluidInventory.java index bf5906d02ad..aaffa978ee9 100644 --- a/src/main/java/appeng/fluids/util/AENetworkFluidInventory.java +++ b/src/main/java/appeng/fluids/util/AENetworkFluidInventory.java @@ -35,8 +35,16 @@ public int fill(final FluidStack fluid, final boolean doFill) { if (overflow != null && overflow.getStackSize() == originAmt) { return super.fill(fluid, doFill); } else if (overflow != null) { + if (doFill) { + FluidStack added = fluid.copy(); + added.amount = (int) (fluid.amount - overflow.getStackSize()); + this.handler.onFluidInventoryChanged(this, added, null); + } return (int) (originAmt - overflow.getStackSize()); } else { + if (doFill) { + this.handler.onFluidInventoryChanged(this, fluid, null); + } return originAmt; } } else { diff --git a/src/main/java/appeng/fluids/util/IAEFluidInventory.java b/src/main/java/appeng/fluids/util/IAEFluidInventory.java index de3ccc24e9b..92110a2f0f1 100644 --- a/src/main/java/appeng/fluids/util/IAEFluidInventory.java +++ b/src/main/java/appeng/fluids/util/IAEFluidInventory.java @@ -28,4 +28,8 @@ public interface IAEFluidInventory { default void onFluidInventoryChanged(final IAEFluidTank inv, final int slot, InvOperation operation, FluidStack added, FluidStack removed) { } + + default void onFluidInventoryChanged(final IAEFluidTank inv, FluidStack added, FluidStack removed) { + } + } diff --git a/src/main/java/appeng/tile/inventory/AppEngNetworkInventory.java b/src/main/java/appeng/tile/inventory/AppEngNetworkInventory.java index f23a5981ac7..fdae1e0be01 100644 --- a/src/main/java/appeng/tile/inventory/AppEngNetworkInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngNetworkInventory.java @@ -39,7 +39,9 @@ public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate return super.insertItem(slot, stack, simulate); } else if (overflow != null) { if (!simulate) { - this.getTileEntity().onChangeInventory(this, slot, InvOperation.INSERT, ItemStack.EMPTY, stack); + ItemStack added = stack.copy(); + added.setCount((int) (stack.getCount() - overflow.getStackSize())); + this.getTileEntity().onChangeInventory(this, slot, InvOperation.INSERT, ItemStack.EMPTY, added); } return overflow.createItemStack(); } else {