Fix ME Interface deadlocking (#478)

This commit is contained in:
Yang Xizhi
2025-03-10 15:35:31 +08:00
committed by GitHub
parent 9c021867f0
commit fabc9bd82c
5 changed files with 34 additions and 3 deletions
@@ -224,8 +224,8 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable
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();
@@ -491,6 +491,16 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable
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) {
@@ -14,7 +14,7 @@ import java.util.Objects;
public class AEFluidInventory implements IAEFluidTank {
private final IAEFluidStack[] fluids;
private final IAEFluidInventory handler;
protected final IAEFluidInventory handler;
private int capacity;
private IFluidTankProperties[] props = null;
@@ -35,8 +35,16 @@ public class AENetworkFluidInventory extends AEFluidInventory {
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 {
@@ -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) {
}
}
@@ -8,6 +8,7 @@ import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.item.AEItemStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.wrapper.RangedWrapper;
@@ -37,8 +38,16 @@ public class AppEngNetworkInventory extends AppEngInternalOversizedInventory {
if (overflow != null && overflow.getStackSize() == originAmt) {
return super.insertItem(slot, stack, simulate);
} else if (overflow != null) {
if (!simulate) {
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 {
if (!simulate) {
this.getTileEntity().onChangeInventory(this, slot, InvOperation.INSERT, ItemStack.EMPTY, stack);
}
return ItemStack.EMPTY;
}
} else {