diff --git a/gradle.properties b/gradle.properties index cc89f9cf5..8299ab7b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ aechannel=stable aebuild=7 aegroup=appeng aebasename=appliedenergistics2 -trousers=omni-fixes-v46s +trousers=omni-fixes-v46t ######################################################### # Versions # diff --git a/src/main/java/appeng/fluids/helper/DualityFluidInterface.java b/src/main/java/appeng/fluids/helper/DualityFluidInterface.java index 4786a248c..4e76ddf1f 100644 --- a/src/main/java/appeng/fluids/helper/DualityFluidInterface.java +++ b/src/main/java/appeng/fluids/helper/DualityFluidInterface.java @@ -91,12 +91,10 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable private int isWorking = -1; private int priority; - private final MEMonitorPassThrough items = new MEMonitorPassThrough<>( new NullInventory(), AEApi.instance() - .storage() - .getStorageChannel( IItemStorageChannel.class ) ); - private final MEMonitorPassThrough fluids = new MEMonitorPassThrough<>( new NullInventory(), AEApi.instance() - .storage() - .getStorageChannel( IFluidStorageChannel.class ) ); + private final MEMonitorPassThrough items = new MEMonitorPassThrough<>( new NullInventory(), AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); + private final MEMonitorPassThrough fluids = new MEMonitorPassThrough<>( new NullInventory(), AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ); + private boolean resetConfigCache; + private IMEMonitor configCachedHandler; public DualityFluidInterface( final AENetworkProxy networkProxy, final IFluidInterfaceHost ih ) { @@ -146,7 +144,12 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable { if( this.hasConfig() ) { - return (IMEMonitor) new InterfaceInventory( this ); + if( resetConfigCache ) + { + resetConfigCache = false; + configCachedHandler = new InterfaceInventory( this ); + } + return (IMEMonitor) configCachedHandler; } return (IMEMonitor) this.fluids; @@ -450,7 +453,12 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable if( inventory == this.config ) { + boolean cfg = hasConfig(); this.readConfig(); + if( cfg != hasConfig ) + { + resetConfigCache = true; + } } else if( inventory == this.tanks ) { @@ -555,7 +563,6 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable InterfaceInventory( final DualityFluidInterface tileInterface ) { super( tileInterface.tanks ); - this.setActionSource( new MachineSource( tileInterface.iHost ) ); } @Override diff --git a/src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java b/src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java index 007ac402d..88c3d87fa 100644 --- a/src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java +++ b/src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java @@ -232,18 +232,11 @@ public class FluidHandlerAdapter implements IMEInventory, IBaseMo for( IFluidTankProperties tankProperty : tankProperties ) { - FluidStack newFS = tankProperty.getContents(); - if( this.mode == StorageFilter.EXTRACTABLE_ONLY && newFS != null ) + if( this.mode == StorageFilter.EXTRACTABLE_ONLY && this.fluidHandler.drain( 1, false ) == null ) { - if( this.fluidHandler.drain( 1, false ) == null ) - { - newFS = null; - } - } - if( newFS != null ) - { - currentlyOnStorage.add( AEFluidStack.fromFluidStack( newFS ) ); + continue; } + currentlyOnStorage.add( AEFluidStack.fromFluidStack( tankProperty.getContents() ) ); } for ( final IAEFluidStack is : currentlyCached ) diff --git a/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java b/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java index ddf48e404..572e2893a 100644 --- a/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java +++ b/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java @@ -338,6 +338,7 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni { this.monitor = (ITickingMonitor) inv; this.monitor.setActionSource( new MachineSource( this ) ); + this.monitor.setMode( (StorageFilter) this.getConfigManager().getSetting( Settings.STORAGE_FILTER ) ); } if( inv != null ) diff --git a/src/main/java/appeng/me/storage/MEMonitorIFluidHandler.java b/src/main/java/appeng/me/storage/MEMonitorIFluidHandler.java index 2a3a9dc4a..b28f28b8b 100644 --- a/src/main/java/appeng/me/storage/MEMonitorIFluidHandler.java +++ b/src/main/java/appeng/me/storage/MEMonitorIFluidHandler.java @@ -19,14 +19,11 @@ package appeng.me.storage; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; +import java.util.*; import java.util.Map.Entry; -import java.util.NavigableMap; import java.util.concurrent.ConcurrentSkipListMap; +import appeng.fluids.util.AEFluidStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; @@ -48,16 +45,14 @@ import appeng.api.storage.data.IItemList; public class MEMonitorIFluidHandler implements IMEMonitor, ITickingMonitor { private final IFluidHandler handler; - private final IItemList list = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList(); + private IItemList cache = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList(); private final HashMap, Object> listeners = new HashMap<>(); - private final NavigableMap memory; private IActionSource mySource; private StorageFilter mode = StorageFilter.EXTRACTABLE_ONLY; public MEMonitorIFluidHandler( final IFluidHandler handler ) { this.handler = handler; - this.memory = new ConcurrentSkipListMap<>(); } @Override @@ -82,11 +77,6 @@ public class MEMonitorIFluidHandler implements IMEMonitor, ITicki return input.copy(); } - if( type == Actionable.MODULATE ) - { - this.onTick(); - } - if( filled == input.getStackSize() ) { return null; @@ -94,6 +84,15 @@ public class MEMonitorIFluidHandler implements IMEMonitor, ITicki final IAEFluidStack o = input.copy(); o.setStackSize( input.getStackSize() - filled ); + + if( type == Actionable.MODULATE ) + { + IAEFluidStack added = o.copy(); + this.cache.add( added ); + this.postDifference( Collections.singletonList( added ) ); + this.onTick(); + } + return o; } @@ -107,13 +106,18 @@ public class MEMonitorIFluidHandler implements IMEMonitor, ITicki return null; } - if( type == Actionable.MODULATE ) - { - this.onTick(); - } - final IAEFluidStack o = request.copy(); o.setStackSize( removed.amount ); + + if( type == Actionable.MODULATE ) + { + IAEFluidStack cachedStack = this.cache.findPrecise( request ); + if( cachedStack != null ) + { + cachedStack.decStackSize( o.getStackSize() ); + this.postDifference( Collections.singletonList( o.copy().setStackSize( -o.getStackSize() ) ) ); + } + } return o; } @@ -126,111 +130,51 @@ public class MEMonitorIFluidHandler implements IMEMonitor, ITicki @Override public TickRateModulation onTick() { - final List changes = new ArrayList<>(); - - this.list.resetStatus(); - int high = 0; boolean changed = false; - final IFluidTankProperties[] props = this.handler.getTankProperties(); - for( int slot = 0; slot < this.handler.getTankProperties().length; ++slot ) + final List changes = new ArrayList<>(); + final IFluidTankProperties[] tankProperties = this.handler.getTankProperties(); + + IItemList currentlyOnStorage = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList(); + + for( IFluidTankProperties tankProperty : tankProperties ) { - final CachedFluidStack old = this.memory.get( slot ); - high = Math.max( high, slot ); - - final FluidStack newIS = !props[slot].canDrain() && this.getMode() == StorageFilter.EXTRACTABLE_ONLY ? null : props[slot].getContents(); - final FluidStack oldIS = old == null ? null : old.fluidStack; - - if( isDifferent( newIS, oldIS ) ) + if( this.mode == StorageFilter.EXTRACTABLE_ONLY && this.handler.drain( 1, false ) == null ) { - final CachedFluidStack cis = new CachedFluidStack( newIS ); - this.memory.put( slot, cis ); - - if( old != null && old.aeStack != null ) - { - old.aeStack.setStackSize( -old.aeStack.getStackSize() ); - changes.add( old.aeStack ); - } - - if( cis.aeStack != null ) - { - changes.add( cis.aeStack ); - this.list.add( cis.aeStack ); - } - - changed = true; + continue; } - else + currentlyOnStorage.add( AEFluidStack.fromFluidStack( tankProperty.getContents() ) ); + } + + for( final IAEFluidStack is : cache ) + { + is.setStackSize( -is.getStackSize() ); + } + + for( final IAEFluidStack is : currentlyOnStorage ) + { + cache.add( is ); + } + + for( final IAEFluidStack is : cache ) + { + if( is.getStackSize() != 0 ) { - final int newSize = newIS == null ? 0 : newIS.amount; - final int diff = newSize - ( oldIS == null ? 0 : oldIS.amount ); - - IAEFluidStack stack = null; - - if( newIS != null ) - { - stack = ( old == null || old.aeStack == null ? AEApi.instance() - .storage() - .getStorageChannel( IFluidStorageChannel.class ) - .createStack( newIS ) : old.aeStack.copy() ); - } - if( stack != null ) - { - stack.setStackSize( newSize ); - this.list.add( stack ); - } - - if( diff != 0 && stack != null ) - { - final CachedFluidStack cis = new CachedFluidStack( newIS ); - this.memory.put( slot, cis ); - - final IAEFluidStack a = stack.copy(); - a.setStackSize( diff ); - changes.add( a ); - changed = true; - } + changes.add( is ); } } - // detect dropped items; should fix non IISided Inventory Changes. - final NavigableMap end = this.memory.tailMap( high, false ); - if( !end.isEmpty() ) - { - for( final CachedFluidStack cis : end.values() ) - { - if( cis != null && cis.aeStack != null ) - { - final IAEFluidStack a = cis.aeStack.copy(); - a.setStackSize( -a.getStackSize() ); - changes.add( a ); - changed = true; - } - } - end.clear(); - } + cache = currentlyOnStorage; if( !changes.isEmpty() ) { this.postDifference( changes ); + changed = true; } return changed ? TickRateModulation.URGENT : TickRateModulation.SLOWER; } - private static boolean isDifferent( FluidStack a, FluidStack b ) - { - if( a == b ) - { - return false; - } - if( a == null || b == null ) - { - return true; - } - return !a.getFluid().equals( b.getFluid() ); - } - private void postDifference( final Iterable a ) { if( a != null ) @@ -291,9 +235,9 @@ public class MEMonitorIFluidHandler implements IMEMonitor, ITicki @Override public IItemList getAvailableItems( final IItemList out ) { - for( final CachedFluidStack is : this.memory.values() ) + for( final IAEFluidStack fs : cache ) { - out.addStorage( is.aeStack ); + out.addStorage( fs ); } return out; @@ -302,7 +246,7 @@ public class MEMonitorIFluidHandler implements IMEMonitor, ITicki @Override public IItemList getStorageList() { - return this.list; + return this.cache; } private StorageFilter getMode() @@ -326,24 +270,4 @@ public class MEMonitorIFluidHandler implements IMEMonitor, ITicki this.mySource = mySource; } - private static class CachedFluidStack - { - - private final FluidStack fluidStack; - private final IAEFluidStack aeStack; - - CachedFluidStack( final FluidStack is ) - { - if( is == null ) - { - this.fluidStack = null; - this.aeStack = null; - } - else - { - this.fluidStack = is.copy(); - this.aeStack = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createStack( is ); - } - } - } } diff --git a/src/main/java/appeng/me/storage/MEMonitorIInventory.java b/src/main/java/appeng/me/storage/MEMonitorIInventory.java index dd208f990..a477884d6 100644 --- a/src/main/java/appeng/me/storage/MEMonitorIInventory.java +++ b/src/main/java/appeng/me/storage/MEMonitorIInventory.java @@ -46,7 +46,6 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo { private final InventoryAdaptor adaptor; - private final IItemList list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); private IItemList cache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); private final HashMap, Object> listeners = new HashMap<>(); @@ -158,11 +157,11 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo for( final ItemSlot is : adaptor ) { - final ItemStack newIS = !is.isExtractable() && this.getMode() == StorageFilter.EXTRACTABLE_ONLY ? ItemStack.EMPTY : is.getItemStack(); - if( !newIS.isEmpty() ) + if( this.mode == StorageFilter.EXTRACTABLE_ONLY && !is.isExtractable() ) { - currentlyOnStorage.add( is.getAEItemStack() ); + continue; } + currentlyOnStorage.add( is.getAEItemStack() ); } for( final IAEItemStack is : cache ) @@ -265,7 +264,7 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo @Override public IItemList getStorageList() { - return this.list; + return this.cache; } private StorageFilter getMode() diff --git a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java index 0d6d15873..ce8b1c336 100644 --- a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java @@ -320,13 +320,13 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor currentlyOnStorage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); - for ( final ItemSlot is : this ) + for( final ItemSlot is : this ) { - final ItemStack newIS = !is.isExtractable() && this.getMode() == StorageFilter.EXTRACTABLE_ONLY ? ItemStack.EMPTY : is.getItemStack(); - if( !newIS.isEmpty() ) + if( this.mode == StorageFilter.EXTRACTABLE_ONLY && !is.isExtractable() ) { - currentlyOnStorage.add( is.getAEItemStack() ); + continue; } + currentlyOnStorage.add( is.getAEItemStack() ); } for ( final IAEItemStack is : currentlyCached )