Skip to content

Commit

Permalink
notify fluid
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Jul 15, 2024
1 parent c7c1754 commit 4528738
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/main/java/appeng/fluids/helper/DualityFluidInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAEItemStack>());
this.fluids.setInternal(new NullInventory<IAEFluidStack>());
this.items.setInternal(new NullInventory<>());
this.fluids.setInternal(new NullInventory<>());
}

this.notifyNeighbors();
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/fluids/util/AEFluidInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/appeng/fluids/util/AENetworkFluidInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/appeng/fluids/util/IAEFluidInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4528738

Please sign in to comment.