hopefully fix storage busses for good

1
This commit is contained in:
PrototypeTrousers
2021-07-31 23:04:53 -03:00
parent 6be96956a9
commit cbdad7c58e
9 changed files with 102 additions and 77 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ aechannel=stable
aebuild=7 aebuild=7
aegroup=appeng aegroup=appeng
aebasename=appliedenergistics2 aebasename=appliedenergistics2
trousers=omni-fixes-v45k trousers=omni-fixes-v45l
######################################################### #########################################################
# Versions # # Versions #
@@ -26,6 +26,8 @@ import appeng.api.config.Settings;
import appeng.api.config.StorageFilter; import appeng.api.config.StorageFilter;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.me.GridAccessException; import appeng.me.GridAccessException;
import appeng.util.inv.ItemSlot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.fluids.capability.IFluidTankProperties;
@@ -73,7 +75,8 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
this.mode = ( (StorageFilter) partFluidStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) ); this.mode = ( (StorageFilter) partFluidStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
this.access = ( (AccessRestriction) partFluidStorageBus.getConfigManager().getSetting( Settings.ACCESS ) ); 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 @Override
@@ -92,26 +95,14 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
if( type == Actionable.MODULATE ) if( type == Actionable.MODULATE )
{ {
IAEFluidStack added; IAEFluidStack added = input.copy().setStackSize( input.getStackSize() - remaining );
if( remaining == 0 )
{
added = input;
}
else
{
added = input.copy().setStackSize( input.getStackSize() - remaining );
}
this.cache.currentlyCached.add( added ); this.cache.currentlyCached.add( added );
if( access.hasPermission( AccessRestriction.READ ) ) this.postDifference( Collections.singletonList( added ) );
{
postDifference( Collections.singletonList( added ) );
}
try try
{ {
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
} }
catch( GridAccessException ignore ) catch( GridAccessException ex )
{ {
// meh // meh
} }
@@ -142,17 +133,14 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
IAEFluidStack cachedStack = this.cache.currentlyCached.findPrecise( request ); IAEFluidStack cachedStack = this.cache.currentlyCached.findPrecise( request );
if( cachedStack != null ) if( cachedStack != null )
{ {
cachedStack.decStackSize( gathered.amount ); cachedStack.decStackSize( gatheredAEFluidstack.getStackSize() );
if( access.hasPermission( AccessRestriction.READ ) ) this.postDifference( Collections.singletonList( gatheredAEFluidstack.copy().setStackSize( -gatheredAEFluidstack.getStackSize() ) ) );
{
postDifference( Collections.singletonList( gatheredAEFluidstack.copy().setStackSize( -gathered.amount ) ) );
}
} }
try try
{ {
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
} }
catch( GridAccessException ignore ) catch( GridAccessException ex )
{ {
// meh // meh
} }
@@ -26,6 +26,7 @@ import java.util.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import appeng.fluids.helper.IConfigurableFluidInventory; import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.util.ConfigManager;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -167,11 +168,23 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
final boolean fullReset = this.resetCacheLogic == 2; final boolean fullReset = this.resetCacheLogic == 2;
this.resetCacheLogic = 0; this.resetCacheLogic = 0;
final IMEInventory<IAEFluidStack> in = this.getInternalHandler(); final MEInventoryHandler<IAEFluidStack> in = this.getInternalHandler();
IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList(); IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
boolean denyRead = false;
if( in != null ) 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 ); before = in.getAvailableItems( before );
in.setBaseAccess( currentAccess );
} }
this.cached = false; this.cached = false;
@@ -180,15 +193,17 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
this.handlerHash = 0; this.handlerHash = 0;
} }
final IMEInventory<IAEFluidStack> out = this.getInternalHandler(); final MEInventoryHandler<IAEFluidStack> out = this.getInternalHandler();
if( in != out ) if( in != out || denyRead )
{ {
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList(); IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
if( out != null )
if( out != null && !denyRead )
{ {
after = out.getAvailableItems( after ); after = out.getAvailableItems( after );
} }
Platform.postListChanges( before, after, this, this.source ); Platform.postListChanges( before, after, this, this.source );
} }
} }
@@ -264,13 +279,22 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
@Override @Override
public void postChange( final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource source ) public void postChange( final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> 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 try
{ {
if( this.getProxy().isActive() ) if( this.getProxy().isActive() )
{ {
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source ); this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source );
} }
} catch ( final GridAccessException e ) }
catch( final GridAccessException e )
{ {
// :( // :(
} }
@@ -41,7 +41,7 @@ public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler
this.setInternal( i ); this.setInternal( i );
} }
protected IMEInventory<T> getInternal() public IMEInventory<T> getInternal()
{ {
return this.internal; return this.internal;
} }
@@ -75,6 +75,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) ); this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) );
} }
this.cache = new InventoryCache( this.itemHandler, this.mode ); this.cache = new InventoryCache( this.itemHandler, this.mode );
this.cache.update();
} }
@Override @Override
@@ -121,21 +122,9 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
if( type == Actionable.MODULATE ) if( type == Actionable.MODULATE )
{ {
IAEItemStack added; IAEItemStack added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() );
if( remaining.isEmpty() )
{
added = iox;
}
else
{
added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() );
}
this.cache.currentlyCached.add( added ); this.cache.currentlyCached.add( added );
if( access.hasPermission( AccessRestriction.READ ) ) this.postDifference( Collections.singletonList( added ) );
{
postDifference( Collections.singletonList( added ) );
}
try try
{ {
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
@@ -144,7 +133,6 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
{ {
// meh // meh
} }
} }
return AEItemStack.fromItemStack( remaining ); return AEItemStack.fromItemStack( remaining );
@@ -218,14 +206,11 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
IAEItemStack gatheredAEItemStack = AEItemStack.fromItemStack( gathered ); IAEItemStack gatheredAEItemStack = AEItemStack.fromItemStack( gathered );
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( gatheredAEItemStack ); IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( request );
if( cachedStack != null ) if( cachedStack != null )
{ {
cachedStack.decStackSize( gatheredAEItemStack.getStackSize() ); cachedStack.decStackSize( gatheredAEItemStack.getStackSize() );
if( access.hasPermission( AccessRestriction.READ ) ) this.postDifference( Collections.singletonList( gatheredAEItemStack.copy().setStackSize( -gatheredAEItemStack.getStackSize() ) ) );
{
postDifference( Collections.singletonList( gatheredAEItemStack.copy().setStackSize( -gatheredAEItemStack.getStackSize() ) ) );
}
} }
try try
{ {
@@ -5,7 +5,6 @@ import appeng.api.AEApi;
import appeng.api.config.AccessRestriction; import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.config.Settings; import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.networking.security.IActionSource; import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor; import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickRateModulation;
@@ -41,7 +40,6 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
private final IItemRepository itemRepository; private final IItemRepository itemRepository;
private final IGridProxyable proxyable; private final IGridProxyable proxyable;
private final InventoryCache cache; private final InventoryCache cache;
private StorageFilter mode;
private AccessRestriction access; private AccessRestriction access;
private ItemStack stackCache; private ItemStack stackCache;
@@ -54,9 +52,9 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
if( this.proxyable instanceof PartStorageBus ) if( this.proxyable instanceof PartStorageBus )
{ {
PartStorageBus partStorageBus = (PartStorageBus) this.proxyable; PartStorageBus partStorageBus = (PartStorageBus) this.proxyable;
this.mode = ( ( StorageFilter ) partStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) ); this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) );
} }
this.cache.update();
} }
@Override @Override
@@ -95,20 +93,9 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
if( type == Actionable.MODULATE ) if( type == Actionable.MODULATE )
{ {
IAEItemStack added; IAEItemStack added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() );
if( remaining.isEmpty() )
{
added = iox;
}
else
{
added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() );
}
this.cache.currentlyCached.add( added ); this.cache.currentlyCached.add( added );
if( access.hasPermission( AccessRestriction.READ ) ) this.postDifference( Collections.singletonList( added ) );
{
postDifference( Collections.singletonList( added ) );
}
try try
{ {
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
@@ -146,16 +133,12 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
IAEItemStack extractedAEItemStack = AEItemStack.fromItemStack( extracted ); IAEItemStack extractedAEItemStack = AEItemStack.fromItemStack( extracted );
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( extractedAEItemStack ); IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( request );
if( cachedStack != null ) if (cachedStack != null)
{ {
cachedStack.decStackSize( extractedAEItemStack.getStackSize() ); cachedStack.decStackSize( extractedAEItemStack.getStackSize() );
if( access.hasPermission( AccessRestriction.READ ) ) this.postDifference( Collections.singletonList( extractedAEItemStack.copy().setStackSize( -extractedAEItemStack.getStackSize() ) ) );
{
postDifference( Collections.singletonList( extractedAEItemStack.copy().setStackSize( -extractedAEItemStack.getStackSize() ) ) );
} }
}
try try
{ {
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
@@ -22,6 +22,7 @@ package appeng.parts.misc;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import appeng.api.config.AccessRestriction;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@@ -55,6 +56,7 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
{ {
private boolean wasActive = false; private boolean wasActive = false;
private int priority = 0; private int priority = 0;
protected boolean accessChanged;
public PartSharedStorageBus( ItemStack is ) public PartSharedStorageBus( ItemStack is )
{ {
@@ -146,6 +148,10 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
@Override @Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue ) public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{ {
if( settingName instanceof AccessRestriction )
{
this.accessChanged = true;
}
this.resetCache( true ); this.resetCache( true );
this.getHost().markForSave(); this.getHost().markForSave();
} }
@@ -23,6 +23,9 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; 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 com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -121,6 +124,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
private int handlerHash = 0; private int handlerHash = 0;
private boolean wasActive = false; private boolean wasActive = false;
private byte resetCacheLogic = 0; private byte resetCacheLogic = 0;
private boolean accessChanged;
@Reflected @Reflected
public PartStorageBus( final ItemStack is ) public PartStorageBus( final ItemStack is )
@@ -172,6 +176,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
@Override @Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue ) public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{ {
if( settingName instanceof AccessRestriction )
{
this.accessChanged = true;
}
this.resetCache( true ); this.resetCache( true );
this.getHost().markForSave(); this.getHost().markForSave();
} }
@@ -258,13 +266,22 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
@Override @Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source ) public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> 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 try
{ {
if( this.getProxy().isActive() ) if( this.getProxy().isActive() )
{ {
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, this.mySrc ); 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; final boolean fullReset = this.resetCacheLogic == 2;
this.resetCacheLogic = 0; this.resetCacheLogic = 0;
final IMEInventory<IAEItemStack> in = this.getInternalHandler(); final MEInventoryHandler<IAEItemStack> in = this.getInternalHandler();
IItemList<IAEItemStack> before = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); IItemList<IAEItemStack> before = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
boolean denyRead = false;
if( in != null ) 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 ); before = in.getAvailableItems( before );
accessChanged = false;
in.setBaseAccess( currentAccess );
} }
this.cached = false; this.cached = false;
@@ -360,16 +390,19 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
this.handlerHash = 0; this.handlerHash = 0;
} }
final IMEInventory<IAEItemStack> out = this.getInternalHandler(); final MEInventoryHandler<IAEItemStack> out = this.getInternalHandler();
if( in != out ) if( in != out || denyRead )
{ {
IItemList<IAEItemStack> after = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); IItemList<IAEItemStack> after = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
if( out != null )
if( out != null && !denyRead )
{ {
after = out.getAvailableItems( after ); after = out.getAvailableItems( after );
} }
Platform.postListChanges( before, after, this, this.mySrc ); Platform.postListChanges( before, after, this, this.mySrc );
} }
} }
@@ -36,6 +36,7 @@ public final class ConfigManager implements IConfigManager
{ {
private final Map<Settings, Enum<?>> settings = new EnumMap<>( Settings.class ); private final Map<Settings, Enum<?>> settings = new EnumMap<>( Settings.class );
private final IConfigManagerHost target; private final IConfigManagerHost target;
private Map<Settings, Enum<?>> oldSettings = new EnumMap<>( Settings.class );
public ConfigManager( final IConfigManagerHost tile ) public ConfigManager( final IConfigManagerHost tile )
{ {
@@ -72,10 +73,15 @@ public final class ConfigManager implements IConfigManager
{ {
final Enum<?> oldValue = this.getSetting( settingName ); final Enum<?> oldValue = this.getSetting( settingName );
this.settings.put( settingName, newValue ); this.settings.put( settingName, newValue );
this.oldSettings.put( settingName, oldValue );
this.target.updateSetting( this, settingName, newValue ); this.target.updateSetting( this, settingName, newValue );
return oldValue; return oldValue;
} }
public Enum<?> getOldSetting(final Settings settingName){
return this.oldSettings.get( settingName );
}
/** /**
* save all settings using config manager. * save all settings using config manager.
* *