diff --git a/gradle.properties b/gradle.properties index 6cee1f068..0a4b8eff8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ aechannel=stable aebuild=7 aegroup=appeng aebasename=appliedenergistics2 -trousers=omni-fixes-v45k +trousers=omni-fixes-v45l ######################################################### # Versions # diff --git a/src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java b/src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java index f613a1bb6..007ac402d 100644 --- a/src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java +++ b/src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java @@ -26,6 +26,8 @@ import appeng.api.config.Settings; import appeng.api.config.StorageFilter; import appeng.api.storage.data.IAEItemStack; import appeng.me.GridAccessException; +import appeng.util.inv.ItemSlot; +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; @@ -73,7 +75,8 @@ public class FluidHandlerAdapter implements IMEInventory, IBaseMo this.mode = ( (StorageFilter) partFluidStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) ); this.access = ( (AccessRestriction) partFluidStorageBus.getConfigManager().getSetting( Settings.ACCESS ) ); } - this.cache = new FluidHandlerAdapter.InventoryCache( this.fluidHandler, this.mode); + this.cache = new FluidHandlerAdapter.InventoryCache( this.fluidHandler, this.mode ); + this.cache.update(); } @Override @@ -92,26 +95,14 @@ public class FluidHandlerAdapter implements IMEInventory, IBaseMo if( type == Actionable.MODULATE ) { - IAEFluidStack added; - if( remaining == 0 ) - { - added = input; - } - else - { - added = input.copy().setStackSize( input.getStackSize() - remaining ); - } + IAEFluidStack added = input.copy().setStackSize( input.getStackSize() - remaining ); this.cache.currentlyCached.add( added ); - if( access.hasPermission( AccessRestriction.READ ) ) - { - postDifference( Collections.singletonList( added ) ); - } - + this.postDifference( Collections.singletonList( added ) ); try { this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); } - catch( GridAccessException ignore ) + catch( GridAccessException ex ) { // meh } @@ -142,17 +133,14 @@ public class FluidHandlerAdapter implements IMEInventory, IBaseMo IAEFluidStack cachedStack = this.cache.currentlyCached.findPrecise( request ); if( cachedStack != null ) { - cachedStack.decStackSize( gathered.amount ); - if( access.hasPermission( AccessRestriction.READ ) ) - { - postDifference( Collections.singletonList( gatheredAEFluidstack.copy().setStackSize( -gathered.amount ) ) ); - } + cachedStack.decStackSize( gatheredAEFluidstack.getStackSize() ); + this.postDifference( Collections.singletonList( gatheredAEFluidstack.copy().setStackSize( -gatheredAEFluidstack.getStackSize() ) ) ); } try { this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); } - catch( GridAccessException ignore ) + catch( GridAccessException ex ) { // meh } diff --git a/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java b/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java index c8444932e..a74b4885c 100644 --- a/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java +++ b/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java @@ -26,6 +26,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import appeng.fluids.helper.IConfigurableFluidInventory; +import appeng.util.ConfigManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -167,11 +168,23 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni final boolean fullReset = this.resetCacheLogic == 2; this.resetCacheLogic = 0; - final IMEInventory in = this.getInternalHandler(); + final MEInventoryHandler in = this.getInternalHandler(); IItemList before = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList(); + boolean denyRead = false; if( in != null ) { + AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS ); + AccessRestriction oldAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getOldSetting( Settings.ACCESS ); + if( oldAccess.hasPermission( AccessRestriction.READ ) && !currentAccess.hasPermission( AccessRestriction.READ ) ) + { + denyRead = true; + } + if( accessChanged ) + { + in.setBaseAccess( oldAccess ); + } before = in.getAvailableItems( before ); + in.setBaseAccess( currentAccess ); } this.cached = false; @@ -180,15 +193,17 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni this.handlerHash = 0; } - final IMEInventory out = this.getInternalHandler(); + final MEInventoryHandler out = this.getInternalHandler(); - if( in != out ) + if( in != out || denyRead ) { IItemList after = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList(); - if( out != null ) + + if( out != null && !denyRead ) { after = out.getAvailableItems( after ); } + Platform.postListChanges( before, after, this, this.source ); } } @@ -264,13 +279,22 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni @Override public void postChange( final IBaseMonitor monitor, final Iterable change, final IActionSource source ) { + if( this.source.machine().map( machine -> machine == this ).orElse( false ) && monitor != null ) + { + AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS ); + if( !currentAccess.hasPermission( AccessRestriction.READ ) ) + { + return; + } + } try { if( this.getProxy().isActive() ) { this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source ); } - } catch ( final GridAccessException e ) + } + catch( final GridAccessException e ) { // :( } diff --git a/src/main/java/appeng/me/storage/MEPassThrough.java b/src/main/java/appeng/me/storage/MEPassThrough.java index d9caa15f1..c2314f716 100644 --- a/src/main/java/appeng/me/storage/MEPassThrough.java +++ b/src/main/java/appeng/me/storage/MEPassThrough.java @@ -41,7 +41,7 @@ public class MEPassThrough> implements IMEInventoryHandler this.setInternal( i ); } - protected IMEInventory getInternal() + public IMEInventory getInternal() { return this.internal; } diff --git a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java index 2577150e1..0d6d15873 100644 --- a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java @@ -75,6 +75,7 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor, IBaseMonitor, IBaseMonitor, IBaseMonitor, IBaseMonitor< private final IItemRepository itemRepository; private final IGridProxyable proxyable; private final InventoryCache cache; - private StorageFilter mode; private AccessRestriction access; private ItemStack stackCache; @@ -54,9 +52,9 @@ class ItemRepositoryAdapter implements IMEInventory, IBaseMonitor< if( this.proxyable instanceof PartStorageBus ) { PartStorageBus partStorageBus = (PartStorageBus) this.proxyable; - this.mode = ( ( StorageFilter ) partStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) ); this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) ); } + this.cache.update(); } @Override @@ -95,20 +93,9 @@ class ItemRepositoryAdapter implements IMEInventory, IBaseMonitor< if( type == Actionable.MODULATE ) { - IAEItemStack added; - if( remaining.isEmpty() ) - { - added = iox; - } - else - { - added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() ); - } + IAEItemStack added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() ); this.cache.currentlyCached.add( added ); - if( access.hasPermission( AccessRestriction.READ ) ) - { - postDifference( Collections.singletonList( added ) ); - } + this.postDifference( Collections.singletonList( added ) ); try { this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); @@ -146,16 +133,12 @@ class ItemRepositoryAdapter implements IMEInventory, IBaseMonitor< IAEItemStack extractedAEItemStack = AEItemStack.fromItemStack( extracted ); if( mode == Actionable.MODULATE ) { - IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( extractedAEItemStack ); - if( cachedStack != null ) + IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( request ); + if (cachedStack != null) { cachedStack.decStackSize( extractedAEItemStack.getStackSize() ); - if( access.hasPermission( AccessRestriction.READ ) ) - { - postDifference( Collections.singletonList( extractedAEItemStack.copy().setStackSize( -extractedAEItemStack.getStackSize() ) ) ); - } + this.postDifference( Collections.singletonList( extractedAEItemStack.copy().setStackSize( -extractedAEItemStack.getStackSize() ) ) ); } - try { this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); diff --git a/src/main/java/appeng/parts/misc/PartSharedStorageBus.java b/src/main/java/appeng/parts/misc/PartSharedStorageBus.java index 18a3fb1bd..04dee9a90 100644 --- a/src/main/java/appeng/parts/misc/PartSharedStorageBus.java +++ b/src/main/java/appeng/parts/misc/PartSharedStorageBus.java @@ -22,6 +22,7 @@ package appeng.parts.misc; import java.util.Collections; import java.util.List; +import appeng.api.config.AccessRestriction; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; @@ -55,6 +56,7 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG { private boolean wasActive = false; private int priority = 0; + protected boolean accessChanged; public PartSharedStorageBus( ItemStack is ) { @@ -146,6 +148,10 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG @Override public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue ) { + if( settingName instanceof AccessRestriction ) + { + this.accessChanged = true; + } this.resetCache( true ); this.getHost().markForSave(); } diff --git a/src/main/java/appeng/parts/misc/PartStorageBus.java b/src/main/java/appeng/parts/misc/PartStorageBus.java index 0327d2a52..6c93ce812 100644 --- a/src/main/java/appeng/parts/misc/PartStorageBus.java +++ b/src/main/java/appeng/parts/misc/PartStorageBus.java @@ -23,6 +23,9 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import appeng.fluids.parts.FluidHandlerAdapter; +import appeng.me.storage.MEPassThrough; +import appeng.util.ConfigManager; import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -121,6 +124,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC private int handlerHash = 0; private boolean wasActive = false; private byte resetCacheLogic = 0; + private boolean accessChanged; @Reflected public PartStorageBus( final ItemStack is ) @@ -172,6 +176,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC @Override public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue ) { + if( settingName instanceof AccessRestriction ) + { + this.accessChanged = true; + } this.resetCache( true ); this.getHost().markForSave(); } @@ -258,13 +266,22 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC @Override public void postChange( final IBaseMonitor monitor, final Iterable change, final IActionSource source ) { + if( this.mySrc.machine().map( machine -> machine == this ).orElse( false ) && monitor != null ) + { + AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS ); + if( !currentAccess.hasPermission( AccessRestriction.READ ) ) + { + return; + } + } try { if( this.getProxy().isActive() ) { this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, this.mySrc ); } - } catch ( final GridAccessException e ) + } + catch( final GridAccessException e ) { // :( } @@ -347,11 +364,24 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC final boolean fullReset = this.resetCacheLogic == 2; this.resetCacheLogic = 0; - final IMEInventory in = this.getInternalHandler(); + final MEInventoryHandler in = this.getInternalHandler(); IItemList before = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); + boolean denyRead = false; if( in != null ) { + AccessRestriction currentAccess = ( AccessRestriction ) ( ( ConfigManager ) this.getConfigManager() ).getSetting( Settings.ACCESS ); + AccessRestriction oldAccess = ( AccessRestriction ) ( ( ConfigManager ) this.getConfigManager() ).getOldSetting( Settings.ACCESS ); + if( oldAccess.hasPermission( AccessRestriction.READ ) && !currentAccess.hasPermission( AccessRestriction.READ ) ) + { + denyRead = true; + } + if( accessChanged ) + { + in.setBaseAccess( oldAccess ); + } before = in.getAvailableItems( before ); + accessChanged = false; + in.setBaseAccess( currentAccess ); } this.cached = false; @@ -360,16 +390,19 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC this.handlerHash = 0; } - final IMEInventory out = this.getInternalHandler(); + final MEInventoryHandler out = this.getInternalHandler(); - if( in != out ) + if( in != out || denyRead ) { IItemList after = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); - if( out != null ) + + if( out != null && !denyRead ) { after = out.getAvailableItems( after ); } + Platform.postListChanges( before, after, this, this.mySrc ); + } } diff --git a/src/main/java/appeng/util/ConfigManager.java b/src/main/java/appeng/util/ConfigManager.java index c4c33a92e..bf25c269d 100644 --- a/src/main/java/appeng/util/ConfigManager.java +++ b/src/main/java/appeng/util/ConfigManager.java @@ -36,6 +36,7 @@ public final class ConfigManager implements IConfigManager { private final Map> settings = new EnumMap<>( Settings.class ); private final IConfigManagerHost target; + private Map> oldSettings = new EnumMap<>( Settings.class ); public ConfigManager( final IConfigManagerHost tile ) { @@ -72,10 +73,15 @@ public final class ConfigManager implements IConfigManager { final Enum oldValue = this.getSetting( settingName ); this.settings.put( settingName, newValue ); + this.oldSettings.put( settingName, oldValue ); this.target.updateSetting( this, settingName, newValue ); return oldValue; } + public Enum getOldSetting(final Settings settingName){ + return this.oldSettings.get( settingName ); + } + /** * save all settings using config manager. *