From 3db8d0185f421879963ecc00d7e28d57464a4cc6 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Sat, 23 Oct 2021 17:56:15 -0300 Subject: [PATCH] fix security terminal and portable cell stored items not showing --- .../items/contents/PortableCellViewer.java | 31 +++++++++++++++++++ .../appeng/me/helpers/MEMonitorHandler.java | 4 +-- .../java/appeng/me/storage/DriveWatcher.java | 17 +++++----- .../me/storage/SecurityStationInventory.java | 16 ++++++++++ .../java/appeng/tile/storage/TileChest.java | 22 ++----------- 5 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/main/java/appeng/items/contents/PortableCellViewer.java b/src/main/java/appeng/items/contents/PortableCellViewer.java index 52ee538ce..584fbcee9 100644 --- a/src/main/java/appeng/items/contents/PortableCellViewer.java +++ b/src/main/java/appeng/items/contents/PortableCellViewer.java @@ -19,6 +19,7 @@ package appeng.items.contents; +import appeng.api.networking.security.IActionSource; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -42,6 +43,8 @@ import appeng.me.helpers.MEMonitorHandler; import appeng.util.ConfigManager; import appeng.util.Platform; +import java.util.Collections; + public class PortableCellViewer extends MEMonitorHandler implements IPortableCell, IInventorySlotAware { @@ -83,6 +86,34 @@ public class PortableCellViewer extends MEMonitorHandler implement return usePowerMultiplier.divide( this.ips.extractAEPower( this.target, amt, Actionable.MODULATE ) ); } + @Override + public IAEItemStack injectItems( IAEItemStack input, Actionable mode, IActionSource src ) + { + final long size = input.getStackSize(); + + final IAEItemStack injected = super.injectItems( input, mode, src ); + + if( mode == Actionable.MODULATE && ( injected == null || injected.getStackSize() != size ) ) + { + this.notifyListenersOfChange( Collections.singletonList( input.copy().setStackSize( input.getStackSize() - ( injected == null ? 0 : injected.getStackSize() ) ) ), null); + } + + return injected; + } + + @Override + public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src ) + { + final IAEItemStack extractable = super.extractItems( request, mode, src ); + + if( mode == Actionable.MODULATE && extractable != null ) + { + this.notifyListenersOfChange( Collections.singletonList( request.copy().setStackSize( -extractable.getStackSize() ) ), null ); + } + + return extractable; + } + @Override public > IMEMonitor getInventory( IStorageChannel channel ) { diff --git a/src/main/java/appeng/me/helpers/MEMonitorHandler.java b/src/main/java/appeng/me/helpers/MEMonitorHandler.java index 29e4b9f9d..e9e013788 100644 --- a/src/main/java/appeng/me/helpers/MEMonitorHandler.java +++ b/src/main/java/appeng/me/helpers/MEMonitorHandler.java @@ -28,8 +28,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; -import com.google.common.collect.ImmutableList; - import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.networking.security.IActionSource; @@ -93,7 +91,7 @@ public class MEMonitorHandler> implements IMEMonitor return this.internalHandler; } - protected void postChangesToListeners( final Iterable changes, final IActionSource src ) + public void postChangesToListeners( final Iterable changes, final IActionSource src ) { this.notifyListenersOfChange( changes, src ); } diff --git a/src/main/java/appeng/me/storage/DriveWatcher.java b/src/main/java/appeng/me/storage/DriveWatcher.java index 4eec8c12b..89d997897 100644 --- a/src/main/java/appeng/me/storage/DriveWatcher.java +++ b/src/main/java/appeng/me/storage/DriveWatcher.java @@ -23,7 +23,6 @@ import appeng.core.features.registries.cell.CreativeCellHandler; import appeng.me.GridAccessException; import appeng.me.helpers.MachineSource; import appeng.tile.storage.TileDrive; -import com.google.common.collect.ImmutableList; import net.minecraft.item.ItemStack; import appeng.api.config.Actionable; @@ -63,9 +62,9 @@ public class DriveWatcher> extends MEInventoryHandler { final long size = input.getStackSize(); - final T a = super.injectItems( input, type, src ); + final T remainder = super.injectItems( input, type, src ); - if( type == Actionable.MODULATE && ( a == null || a.getStackSize() != size ) ) + if( type == Actionable.MODULATE && ( remainder == null || remainder.getStackSize() != size ) ) { final int newStatus = this.getStatus(); @@ -78,7 +77,7 @@ public class DriveWatcher> extends MEInventoryHandler { try { - this.drive.getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), Collections.singletonList( input.copy().setStackSize( input.getStackSize() - ( a == null ? 0 : a.getStackSize() ) ) ), this.source ); + this.drive.getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), Collections.singletonList( input.copy().setStackSize( input.getStackSize() - ( remainder == null ? 0 : remainder.getStackSize() ) ) ), this.source ); } catch ( GridAccessException e ) { e.printStackTrace(); @@ -86,15 +85,15 @@ public class DriveWatcher> extends MEInventoryHandler } } - return a; + return remainder; } @Override public T extractItems( final T request, final Actionable type, final IActionSource src ) { - final T a = super.extractItems( request, type, src ); + final T extractable = super.extractItems( request, type, src ); - if( type == Actionable.MODULATE && a != null ) + if( type == Actionable.MODULATE && extractable != null ) { final int newStatus = this.getStatus(); @@ -107,7 +106,7 @@ public class DriveWatcher> extends MEInventoryHandler { try { - this.drive.getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), Collections.singletonList( request.copy().setStackSize( -a.getStackSize() ) ), this.source ); + this.drive.getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), Collections.singletonList( request.copy().setStackSize( -extractable.getStackSize() ) ), this.source ); } catch ( GridAccessException e ) { e.printStackTrace(); @@ -115,6 +114,6 @@ public class DriveWatcher> extends MEInventoryHandler } } - return a; + return extractable; } } diff --git a/src/main/java/appeng/me/storage/SecurityStationInventory.java b/src/main/java/appeng/me/storage/SecurityStationInventory.java index b4b9fb23f..d34ee0bd4 100644 --- a/src/main/java/appeng/me/storage/SecurityStationInventory.java +++ b/src/main/java/appeng/me/storage/SecurityStationInventory.java @@ -19,6 +19,8 @@ package appeng.me.storage; +import appeng.me.helpers.MEMonitorHandler; +import appeng.me.helpers.MachineSource; import com.mojang.authlib.GameProfile; import appeng.api.AEApi; @@ -35,16 +37,20 @@ import appeng.api.storage.data.IItemList; import appeng.me.GridAccessException; import appeng.tile.misc.TileSecurityStation; +import java.util.Collections; + public class SecurityStationInventory implements IMEInventoryHandler { private final IItemList storedItems = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); private final TileSecurityStation securityTile; + private final MachineSource src; public SecurityStationInventory( final TileSecurityStation ts ) { this.securityTile = ts; + this.src = new MachineSource( securityTile ); } @Override @@ -61,6 +67,11 @@ public class SecurityStationInventory implements IMEInventoryHandler ) securityTile.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) ).postChangesToListeners( Collections.singletonList( input.copy() ), this.src ); + } + this.getStoredItems().add( input ); this.securityTile.inventoryChanged(); return null; @@ -101,6 +112,11 @@ public class SecurityStationInventory implements IMEInventoryHandler ) securityTile.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) ).postChangesToListeners( Collections.singletonList( target.copy().setStackSize( -target.getStackSize() ) ), this.src ); + } + target.setStackSize( 0 ); this.securityTile.inventoryChanged(); return output; diff --git a/src/main/java/appeng/tile/storage/TileChest.java b/src/main/java/appeng/tile/storage/TileChest.java index 9c98d07d8..d2bad8df9 100644 --- a/src/main/java/appeng/tile/storage/TileChest.java +++ b/src/main/java/appeng/tile/storage/TileChest.java @@ -742,16 +742,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal { if( TileChest.this.getProxy().isActive() && this.getInternalHandler().getCellInv() != null ) { - try - { - TileChest.this.getProxy().getStorage().postAlterationOfStoredItems( - this.getChannel(), - Collections.singletonList( input.copy().setStackSize( input.getStackSize() - ( injected == null ? 0 : injected.getStackSize() ) ) ), - TileChest.this.mySrc ); - } catch ( GridAccessException e ) - { - e.printStackTrace(); - } + TileChest.this.cellHandler.postChangesToListeners(Collections.singletonList( input.copy().setStackSize( input.getStackSize() - ( injected == null ? 0 : injected.getStackSize() ) ) ), TileChest.this.mySrc ); } } return injected; @@ -803,16 +794,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal { if( TileChest.this.getProxy().isActive() && this.getInternalHandler().getCellInv() != null ) { - try - { - TileChest.this.getProxy().getStorage().postAlterationOfStoredItems( - this.getChannel(), - Collections.singletonList( request.copy().setStackSize( -extracted.getStackSize() ) ), - TileChest.this.mySrc ); - } catch ( GridAccessException e ) - { - e.printStackTrace(); - } + TileChest.this.cellHandler.postChangesToListeners(Collections.singletonList( request.copy().setStackSize( -extracted.getStackSize() ) ), TileChest.this.mySrc ); } } return extracted;