Fluid cleanup and performance improvements (#3581)
Use custom gui widget with custom synchronization for rendering fake fluid slots.
This commit is contained in:
@@ -21,14 +21,11 @@ package appeng.fluids.parts;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Verify;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
@@ -44,10 +41,8 @@ import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
@@ -120,15 +115,10 @@ public class PartFluidExportBus extends PartSharedFluidBus
|
||||
{
|
||||
for( int i = 0; i < this.getConfig().getSlots(); i++ )
|
||||
{
|
||||
final IAEItemStack stack = this.getConfig().getAEStackInSlot( i );
|
||||
|
||||
if( stack != null && stack.getDefinition() != null )
|
||||
IAEFluidStack fluid = this.getConfig().getFluidInSlot( i );
|
||||
if( fluid != null )
|
||||
{
|
||||
final IFluidHandlerItem ifh = stack.getDefinition().getCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null );
|
||||
|
||||
Verify.verifyNotNull( ifh, "IFluidHandlerItem is null" );
|
||||
|
||||
final AEFluidStack toExtract = AEFluidStack.fromFluidStack( ifh.drain( Integer.MAX_VALUE, false ) );
|
||||
final IAEFluidStack toExtract = fluid.copy();
|
||||
|
||||
toExtract.setStackSize( this.calculateAmountToSend() );
|
||||
|
||||
|
||||
@@ -21,15 +21,12 @@ package appeng.fluids.parts;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Verify;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
@@ -44,7 +41,6 @@ import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
@@ -157,20 +153,10 @@ public class PartFluidImportBus extends PartSharedFluidBus
|
||||
{
|
||||
for( int i = 0; i < this.getConfig().getSlots(); i++ )
|
||||
{
|
||||
final IAEItemStack stack = this.getConfig().getAEStackInSlot( i );
|
||||
|
||||
if( stack != null && stack.getDefinition() != null )
|
||||
final IAEFluidStack stack = this.getConfig().getFluidInSlot( i );
|
||||
if( stack != null && stack.equals( fluid ) )
|
||||
{
|
||||
final IFluidHandlerItem fh = stack.getDefinition().getCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null );
|
||||
|
||||
Verify.verifyNotNull( fh, "IFluidHandlerItem is null" );
|
||||
|
||||
final FluidStack filtered = fh.drain( Integer.MAX_VALUE, false );
|
||||
|
||||
if( filtered != null && filtered.isFluidEqual( fluid ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -180,8 +166,7 @@ public class PartFluidImportBus extends PartSharedFluidBus
|
||||
{
|
||||
for( int i = 0; i < this.getConfig().getSlots(); i++ )
|
||||
{
|
||||
final IAEItemStack stack = this.getConfig().getAEStackInSlot( i );
|
||||
|
||||
final IAEFluidStack stack = this.getConfig().getFluidInSlot( i );
|
||||
if( stack != null )
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -30,7 +30,9 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
@@ -45,6 +47,7 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.fluids.helper.DualityFluidInterface;
|
||||
@@ -216,4 +219,21 @@ public class PartFluidInterface extends PartBasicState implements IGridTickable,
|
||||
return this.duality.getCapability( capabilityClass, this.getSide().getFacing() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades( Upgrades u )
|
||||
{
|
||||
return this.duality.getInstalledUpgrades( u );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( String name )
|
||||
{
|
||||
return this.duality.getInventoryByName( name );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,8 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
@@ -64,14 +60,15 @@ import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.IStorageMonitorableAccessor;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.capabilities.Capabilities;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
@@ -80,9 +77,7 @@ import appeng.me.storage.ITickingMonitor;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.parts.misc.PartSharedStorageBus;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.prioritylist.FuzzyPriorityList;
|
||||
import appeng.util.prioritylist.PrecisePriorityList;
|
||||
|
||||
@@ -92,7 +87,7 @@ import appeng.util.prioritylist.PrecisePriorityList;
|
||||
* @version rv6 - 22/05/2018
|
||||
* @since rv6 22/05/2018
|
||||
*/
|
||||
public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMonitorHandlerReceiver<IAEFluidStack>
|
||||
public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMonitorHandlerReceiver<IAEFluidStack>, IAEFluidInventory
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_base" );
|
||||
@PartModels
|
||||
@@ -103,7 +98,7 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_has_channel" ) );
|
||||
|
||||
private final IActionSource source;
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 63 );
|
||||
private final AEFluidInventory config = new AEFluidInventory( this, 63 );
|
||||
private boolean cached = false;
|
||||
private ITickingMonitor monitor = null;
|
||||
private MEInventoryHandler<IAEFluidStack> handler = null;
|
||||
@@ -198,7 +193,9 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
|
||||
protected void resetCache( final boolean fullReset )
|
||||
{
|
||||
if( this.getHost() == null || this.getHost().getTile() == null || this.getHost().getTile().getWorld() == null || this.getHost().getTile().getWorld().isRemote )
|
||||
if( this.getHost() == null || this.getHost().getTile() == null || this.getHost().getTile().getWorld() == null || this.getHost()
|
||||
.getTile()
|
||||
.getWorld().isRemote )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -239,27 +236,14 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
public void onFluidInventoryChanged( IAEFluidTank inv, int slot )
|
||||
{
|
||||
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
|
||||
if( inv == this.config )
|
||||
{
|
||||
this.resetCache( true );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "config" ) )
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
@@ -287,7 +271,9 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
{
|
||||
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 )
|
||||
@@ -342,23 +328,17 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
|
||||
for( int x = 0; x < this.config.getSlots() && x < slotsToUse; x++ )
|
||||
{
|
||||
final IAEItemStack is = this.config.getAEStackInSlot( x );
|
||||
final IAEFluidStack is = this.config.getFluidInSlot( x );
|
||||
if( is != null )
|
||||
{
|
||||
// Because we store filtered fluid as buckets, we need to grab the fluid from the stack
|
||||
IFluidHandlerItem fh = FluidUtil.getFluidHandler( is.createItemStack() );
|
||||
if( fh == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
FluidStack fluid = fh.drain( Integer.MAX_VALUE, false );
|
||||
priorityList.add( AEFluidStack.fromFluidStack( fluid ) );
|
||||
priorityList.add( is );
|
||||
}
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
this.handler.setPartitionList( new FuzzyPriorityList<IAEFluidStack>( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
|
||||
this.handler.setPartitionList(
|
||||
new FuzzyPriorityList<IAEFluidStack>( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -488,6 +468,11 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "Duplicates" )
|
||||
@Nonnull
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,6 @@ import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
@@ -40,9 +39,10 @@ import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ import appeng.util.Platform;
|
||||
public abstract class PartSharedFluidBus extends PartUpgradeable implements IGridTickable
|
||||
{
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 9 );
|
||||
private final AEFluidInventory config = new AEFluidInventory( null, 9 );
|
||||
private boolean lastRedstone;
|
||||
|
||||
public PartSharedFluidBus( ItemStack is )
|
||||
@@ -144,17 +144,6 @@ public abstract class PartSharedFluidBus extends PartUpgradeable implements IGri
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "config" ) )
|
||||
{
|
||||
return this.getConfig();
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
protected int calculateAmountToSend()
|
||||
{
|
||||
double amount = this.getChannel().transferFactor();
|
||||
@@ -178,22 +167,23 @@ public abstract class PartSharedFluidBus extends PartUpgradeable implements IGri
|
||||
public void readFromNBT( NBTTagCompound extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.getConfig().readFromNBT( extra, "config" );
|
||||
this.config.readFromNBT( extra, "config" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( NBTTagCompound extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.getConfig().writeToNBT( extra, "config" );
|
||||
this.config.writeToNBT( extra, "config" );
|
||||
}
|
||||
|
||||
public AppEngInternalAEInventory getConfig()
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
|
||||
protected IFluidStorageChannel getChannel(){
|
||||
protected IFluidStorageChannel getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user