Fluid cleanup and performance improvements (#3581)
Use custom gui widget with custom synchronization for rendering fake fluid slots.
This commit is contained in:
@@ -22,7 +22,6 @@ package appeng.fluids.container;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -37,13 +36,10 @@ import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.implementations.ContainerUpgradeable;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.fluids.container.slots.OptionalSlotFakeFluid;
|
||||
import appeng.fluids.container.slots.SlotFakeFluid;
|
||||
import appeng.fluids.parts.PartFluidStorageBus;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.iterators.NullIterator;
|
||||
|
||||
|
||||
@@ -52,7 +48,7 @@ import appeng.util.iterators.NullIterator;
|
||||
* @version rv6 - 22/05/2018
|
||||
* @since rv6 22/05/2018
|
||||
*/
|
||||
public class ContainerFluidStorageBus extends ContainerUpgradeable
|
||||
public class ContainerFluidStorageBus extends ContainerFluidConfigurable
|
||||
{
|
||||
|
||||
private final PartFluidStorageBus storageBus;
|
||||
@@ -78,31 +74,39 @@ public class ContainerFluidStorageBus extends ContainerUpgradeable
|
||||
@Override
|
||||
protected void setupConfig()
|
||||
{
|
||||
final int xo = 8;
|
||||
final int yo = 23 + 6;
|
||||
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
|
||||
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlotToContainer(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlotToContainer(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlotToContainer(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlotToContainer(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer() ) )
|
||||
.setNotDraggable() );
|
||||
}
|
||||
|
||||
final IItemHandler config = this.getUpgradeable().getInventoryByName( "config" );
|
||||
for( int y = 0; y < 7; y++ )
|
||||
@Override
|
||||
protected boolean isValidForConfig( int slot, IAEFluidStack fs )
|
||||
{
|
||||
if( this.supportCapacity() )
|
||||
{
|
||||
for( int x = 0; x < 9; x++ )
|
||||
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
|
||||
|
||||
final int y = slot / 9;
|
||||
|
||||
if( y >= upgrades + 2 )
|
||||
{
|
||||
if( y < 2 )
|
||||
{
|
||||
this.addSlotToContainer( new SlotFakeFluid( config, y * 9 + x, xo + x * 18, yo + y * 18 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addSlotToContainer( new OptionalSlotFakeFluid( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
|
||||
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) ).setNotDraggable() );
|
||||
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) ).setNotDraggable() );
|
||||
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) ).setNotDraggable() );
|
||||
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) ).setNotDraggable() );
|
||||
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer() ) ).setNotDraggable() );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,36 +146,39 @@ public class ContainerFluidStorageBus extends ContainerUpgradeable
|
||||
|
||||
public void clear()
|
||||
{
|
||||
ItemHandlerUtil.clear( this.getUpgradeable().getInventoryByName( "config" ) );
|
||||
IAEFluidTank h = this.storageBus.getConfig();
|
||||
for( int i = 0; i < h.getSlots(); ++i )
|
||||
{
|
||||
h.setFluidInSlot( i, null );
|
||||
}
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
|
||||
public void partition()
|
||||
{
|
||||
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
|
||||
IAEFluidTank h = this.storageBus.getConfig();
|
||||
|
||||
final IMEInventory<IAEFluidStack> cellInv = this.storageBus.getInternalHandler();
|
||||
|
||||
Iterator<IAEFluidStack> i = new NullIterator<>();
|
||||
if( cellInv != null )
|
||||
{
|
||||
final IItemList<IAEFluidStack> list = cellInv.getAvailableItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList() );
|
||||
final IItemList<IAEFluidStack> list = cellInv
|
||||
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList() );
|
||||
i = list.iterator();
|
||||
}
|
||||
|
||||
for( int x = 0; x < inv.getSlots(); x++ )
|
||||
for( int x = 0; x < h.getSlots(); x++ )
|
||||
{
|
||||
if( i.hasNext() && this.isSlotEnabled( ( x / 9 ) - 2 ) )
|
||||
{
|
||||
final ItemStack g = i.next().asItemStackRepresentation();
|
||||
ItemHandlerUtil.setStackInSlot( inv, x, g );
|
||||
h.setFluidInSlot( x, i.next() );
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.EMPTY );
|
||||
h.setFluidInSlot( x, null );
|
||||
}
|
||||
}
|
||||
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
|
||||
@@ -194,4 +201,10 @@ public class ContainerFluidStorageBus extends ContainerUpgradeable
|
||||
{
|
||||
this.storageFilter = storageFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory()
|
||||
{
|
||||
return this.storageBus.getConfig();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user