fix expanded processing pattern terminal not refreshing when placing

patterns on the encoding output slot
This commit is contained in:
PrototypeTrousers
2022-05-30 22:28:50 -03:00
parent 1c197c0f20
commit 5b1f98b2d8
@@ -10,7 +10,9 @@ import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation; import appeng.util.inv.InvOperation;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
@@ -29,500 +31,523 @@ import static appeng.helpers.PatternHelper.PROCESSING_OUTPUT_LIMIT;
public class ContainerExpandedProcessingPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket public class ContainerExpandedProcessingPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket
{ {
private final IItemHandler crafting; private final IItemHandler crafting;
private final SlotFakeCraftingMatrix[] gridSlots = new SlotFakeCraftingMatrix[PROCESSING_INPUT_LIMIT]; private final SlotFakeCraftingMatrix[] gridSlots = new SlotFakeCraftingMatrix[PROCESSING_INPUT_LIMIT];
private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[PROCESSING_OUTPUT_LIMIT]; private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[PROCESSING_OUTPUT_LIMIT];
private final SlotRestrictedInput patternSlotIN; private final SlotRestrictedInput patternSlotIN;
private final SlotRestrictedInput patternSlotOUT; private final SlotRestrictedInput patternSlotOUT;
private final PartExpandedProcessingPatternTerminal expandedProcessingPatternTerminal; private final PartExpandedProcessingPatternTerminal expandedProcessingPatternTerminal;
public ContainerExpandedProcessingPatternTerm( InventoryPlayer ip, ITerminalHost monitorable ) public ContainerExpandedProcessingPatternTerm( InventoryPlayer ip, ITerminalHost monitorable )
{ {
super( ip, monitorable, false ); super( ip, monitorable, false );
this.expandedProcessingPatternTerminal = (PartExpandedProcessingPatternTerminal) monitorable; this.expandedProcessingPatternTerminal = (PartExpandedProcessingPatternTerminal) monitorable;
final IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName( "pattern" ); final IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName( "pattern" );
final IItemHandler output = this.getExpandedPatternTerminal().getInventoryByName( "output" ); final IItemHandler output = this.getExpandedPatternTerminal().getInventoryByName( "output" );
this.crafting = this.getExpandedPatternTerminal().getInventoryByName( "crafting" ); this.crafting = this.getExpandedPatternTerminal().getInventoryByName( "crafting" );
for( int y = 0; y < 4; y++ ) for( int y = 0; y < 4; y++ )
{ {
for( int x = 0; x < 4; x++ ) for( int x = 0; x < 4; x++ )
{ {
this.addSlotToContainer( this.gridSlots[x + y * 4] = new SlotFakeCraftingMatrix( this.crafting, x + y * 4, 4 + x * 18, -85 + y * 18 ) ); this.addSlotToContainer( this.gridSlots[x + y * 4] = new SlotFakeCraftingMatrix( this.crafting, x + y * 4, 4 + x * 18, -85 + y * 18 ) );
} }
} }
for( int y = 0; y < 3; y++ ) for( int y = 0; y < 3; y++ )
{ {
for( int x = 0; x < 2; x++ ) for( int x = 0; x < 2; x++ )
{ {
this.addSlotToContainer( this.outputSlots[x + y * 2] = new SlotPatternOutputs( output, this, x + y * 2, 96 + x * 18, -76 + y * 18, 0, 0, 1 ) ); this.addSlotToContainer( this.outputSlots[x + y * 2] = new SlotPatternOutputs( output, this, x + y * 2, 96 + x * 18, -76 + y * 18, 0, 0, 1 ) );
this.outputSlots[x + y * 2].setRenderDisabled( false ); this.outputSlots[x + y * 2].setRenderDisabled( false );
this.outputSlots[x + y * 2].setIIcon( -1 ); this.outputSlots[x + y * 2].setIIcon( -1 );
} }
} }
this.addSlotToContainer( this.patternSlotIN = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9, this.getInventoryPlayer() ) ); this.addSlotToContainer( this.patternSlotIN = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9, this.getInventoryPlayer() ) );
this.addSlotToContainer( this.patternSlotOUT = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34, this.getInventoryPlayer() ) ); this.addSlotToContainer( this.patternSlotOUT = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34, this.getInventoryPlayer() ) );
this.patternSlotOUT.setStackLimit( 1 ); this.patternSlotOUT.setStackLimit( 1 );
this.bindPlayerInventory( ip, 0, 0 ); this.bindPlayerInventory( ip, 0, 0 );
} }
@Override @Override
public ItemStack transferStackInSlot( final EntityPlayer p, final int idx ) public ItemStack transferStackInSlot( final EntityPlayer p, final int idx )
{ {
if( Platform.isClient() ) if( Platform.isClient() )
{ {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
if( this.inventorySlots.get( idx ) instanceof SlotPlayerInv || this.inventorySlots.get( idx ) instanceof SlotPlayerHotBar ) if( this.inventorySlots.get( idx ) instanceof SlotPlayerInv || this.inventorySlots.get( idx ) instanceof SlotPlayerHotBar )
{ {
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots! final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots!
ItemStack itemStack = clickSlot.getStack(); ItemStack itemStack = clickSlot.getStack();
if( AEApi.instance().definitions().materials().blankPattern().isSameAs( itemStack ) ) if( AEApi.instance().definitions().materials().blankPattern().isSameAs( itemStack ) )
{ {
IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName( "pattern" ); IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName( "pattern" );
ItemStack remainder = patternInv.insertItem( 0, itemStack, false ); ItemStack remainder = patternInv.insertItem( 0, itemStack, false );
clickSlot.putStack( remainder ); clickSlot.putStack( remainder );
} }
} }
return super.transferStackInSlot( p, idx ); return super.transferStackInSlot( p, idx );
} }
@Override @Override
public void saveChanges() public void saveChanges()
{ {
} }
@Override @Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack ) public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{ {
} }
public void encodeAndMoveToInventory() public void encodeAndMoveToInventory()
{ {
encode(); encode();
ItemStack output = this.patternSlotOUT.getStack(); ItemStack output = this.patternSlotOUT.getStack();
if( !output.isEmpty() ) if( !output.isEmpty() )
{ {
if( !getPlayerInv().addItemStackToInventory( output ) ) if( !getPlayerInv().addItemStackToInventory( output ) )
{ {
getPlayerInv().player.dropItem( output, false ); getPlayerInv().player.dropItem( output, false );
} }
this.patternSlotOUT.putStack( ItemStack.EMPTY ); this.patternSlotOUT.putStack( ItemStack.EMPTY );
} }
} }
public void encode() public void encode()
{ {
ItemStack output = this.patternSlotOUT.getStack(); ItemStack output = this.patternSlotOUT.getStack();
final ItemStack[] in = this.getInputs(); final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs(); final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly. // if there is no input, this would be silly.
if( in == null || out == null ) if( in == null || out == null )
{ {
return; return;
} }
// first check the output slots, should either be null, or a pattern // first check the output slots, should either be null, or a pattern
if( !output.isEmpty() && !this.isPattern( output ) ) if( !output.isEmpty() && !this.isPattern( output ) )
{ {
return; return;
} // if nothing is there we should snag a new pattern. } // if nothing is there we should snag a new pattern.
else if( output.isEmpty() ) else if( output.isEmpty() )
{ {
output = this.patternSlotIN.getStack(); output = this.patternSlotIN.getStack();
if( output.isEmpty() || !this.isPattern( output ) ) if( output.isEmpty() || !this.isPattern( output ) )
{ {
return; // no blanks. return; // no blanks.
} }
// remove one, and clear the input slot. // remove one, and clear the input slot.
output.setCount( output.getCount() - 1 ); output.setCount( output.getCount() - 1 );
if( output.getCount() == 0 ) if( output.getCount() == 0 )
{ {
this.patternSlotIN.putStack( ItemStack.EMPTY ); this.patternSlotIN.putStack( ItemStack.EMPTY );
} }
// add a new encoded pattern. // add a new encoded pattern.
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack( 1 ); Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack( 1 );
if( maybePattern.isPresent() ) if( maybePattern.isPresent() )
{ {
output = maybePattern.get(); output = maybePattern.get();
this.patternSlotOUT.putStack( output ); this.patternSlotOUT.putStack( output );
} }
} }
// encode the slot. // encode the slot.
final NBTTagCompound encodedValue = new NBTTagCompound(); final NBTTagCompound encodedValue = new NBTTagCompound();
final NBTTagList tagIn = new NBTTagList(); final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList(); final NBTTagList tagOut = new NBTTagList();
for( final ItemStack i : in ) for( final ItemStack i : in )
{ {
tagIn.appendTag( this.createItemTag( i ) ); tagIn.appendTag( this.createItemTag( i ) );
} }
for( final ItemStack i : out ) for( final ItemStack i : out )
{ {
tagOut.appendTag( this.createItemTag( i ) ); tagOut.appendTag( this.createItemTag( i ) );
} }
encodedValue.setTag( "in", tagIn ); encodedValue.setTag( "in", tagIn );
encodedValue.setTag( "out", tagOut ); encodedValue.setTag( "out", tagOut );
encodedValue.setBoolean( "crafting", false ); encodedValue.setBoolean( "crafting", false );
encodedValue.setBoolean( "substitute", false ); encodedValue.setBoolean( "substitute", false );
output.setTagCompound( encodedValue ); output.setTagCompound( encodedValue );
} }
boolean isPattern( final ItemStack output ) boolean isPattern( final ItemStack output )
{ {
if( output.isEmpty() ) if( output.isEmpty() )
{ {
return false; return false;
} }
final IDefinitions definitions = AEApi.instance().definitions(); final IDefinitions definitions = AEApi.instance().definitions();
boolean isPattern = definitions.items().encodedPattern().isSameAs( output ); boolean isPattern = definitions.items().encodedPattern().isSameAs( output );
isPattern |= definitions.materials().blankPattern().isSameAs( output ); isPattern |= definitions.materials().blankPattern().isSameAs( output );
return isPattern; return isPattern;
} }
NBTBase createItemTag( final ItemStack i ) NBTBase createItemTag( final ItemStack i )
{ {
final NBTTagCompound c = new NBTTagCompound(); final NBTTagCompound c = new NBTTagCompound();
if( !i.isEmpty() ) if( !i.isEmpty() )
{ {
i.writeToNBT( c ); i.writeToNBT( c );
} }
return c; return c;
} }
@Override @Override
public boolean isSlotEnabled( final int idx ) public boolean isSlotEnabled( final int idx )
{ {
return true; return true;
} }
protected ItemStack[] getInputs() protected ItemStack[] getInputs()
{ {
final ItemStack[] input = new ItemStack[16]; final ItemStack[] input = new ItemStack[16];
boolean hasValue = false; boolean hasValue = false;
for( int x = 0; x < this.gridSlots.length; x++ ) for( int x = 0; x < this.gridSlots.length; x++ )
{ {
input[x] = this.gridSlots[x].getStack(); input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() ) if( !input[x].isEmpty() )
{ {
hasValue = true; hasValue = true;
} }
} }
if( hasValue ) if( hasValue )
{ {
return input; return input;
} }
return null; return null;
} }
protected ItemStack[] getOutputs() protected ItemStack[] getOutputs()
{ {
final List<ItemStack> list = new ArrayList<>( 3 ); final List<ItemStack> list = new ArrayList<>( 3 );
boolean hasValue = false; boolean hasValue = false;
for( final OptionalSlotFake outputSlot : this.outputSlots ) for( final OptionalSlotFake outputSlot : this.outputSlots )
{ {
final ItemStack out = outputSlot.getStack(); final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() > 0 ) if( !out.isEmpty() && out.getCount() > 0 )
{ {
list.add( out ); list.add( out );
hasValue = true; hasValue = true;
} }
} }
if( hasValue ) if( hasValue )
{ {
return list.toArray( new ItemStack[0] ); return list.toArray( new ItemStack[0] );
} }
return null; return null;
} }
public void clear() public void clear()
{ {
for( final Slot s : this.gridSlots ) for( final Slot s : this.gridSlots )
{ {
s.putStack( ItemStack.EMPTY ); s.putStack( ItemStack.EMPTY );
} }
for( final Slot s : this.outputSlots ) for( final Slot s : this.outputSlots )
{ {
s.putStack( ItemStack.EMPTY ); s.putStack( ItemStack.EMPTY );
} }
this.detectAndSendChanges(); this.detectAndSendChanges();
} }
@Override @Override
public IItemHandler getInventoryByName( final String name ) public IItemHandler getInventoryByName( final String name )
{ {
if( name.equals( "player" ) ) if( name.equals( "player" ) )
{ {
return new PlayerInvWrapper( this.getInventoryPlayer() ); return new PlayerInvWrapper( this.getInventoryPlayer() );
} }
return this.getExpandedPatternTerminal().getInventoryByName( name ); return this.getExpandedPatternTerminal().getInventoryByName( name );
} }
@Override @Override
public boolean useRealItems() public boolean useRealItems()
{ {
return false; return false;
} }
public PartExpandedProcessingPatternTerminal getExpandedPatternTerminal() public PartExpandedProcessingPatternTerminal getExpandedPatternTerminal()
{ {
return this.expandedProcessingPatternTerminal; return this.expandedProcessingPatternTerminal;
} }
public void multiply( int multiple ) public void multiply( int multiple )
{ {
ItemStack[] input = new ItemStack[gridSlots.length]; ItemStack[] input = new ItemStack[gridSlots.length];
boolean canMultiplyInputs = true; boolean canMultiplyInputs = true;
boolean canMultiplyOutputs = true; boolean canMultiplyOutputs = true;
for( int x = 0; x < this.gridSlots.length; x++ ) for( int x = 0; x < this.gridSlots.length; x++ )
{ {
input[x] = this.gridSlots[x].getStack(); input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getCount() * multiple > input[x].getMaxStackSize() ) if( !input[x].isEmpty() && input[x].getCount() * multiple > input[x].getMaxStackSize() )
{ {
canMultiplyInputs = false; canMultiplyInputs = false;
} }
} }
for( final OptionalSlotFake outputSlot : this.outputSlots ) for( final OptionalSlotFake outputSlot : this.outputSlots )
{ {
final ItemStack out = outputSlot.getStack(); final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() * multiple > out.getMaxStackSize() ) if( !out.isEmpty() && out.getCount() * multiple > out.getMaxStackSize() )
{ {
canMultiplyOutputs = false; canMultiplyOutputs = false;
} }
} }
if( canMultiplyInputs && canMultiplyOutputs ) if( canMultiplyInputs && canMultiplyOutputs )
{ {
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots ) for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{ {
ItemStack stack = craftingSlot.getStack(); ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
craftingSlot.getStack().setCount( stack.getCount() * multiple ); craftingSlot.getStack().setCount( stack.getCount() * multiple );
} }
} }
for( OptionalSlotFake outputSlot : this.outputSlots ) for( OptionalSlotFake outputSlot : this.outputSlots )
{ {
ItemStack stack = outputSlot.getStack(); ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
outputSlot.getStack().setCount( stack.getCount() * multiple ); outputSlot.getStack().setCount( stack.getCount() * multiple );
} }
} }
} }
} }
public void divide( int divide ) public void divide( int divide )
{ {
ItemStack[] input = new ItemStack[gridSlots.length]; ItemStack[] input = new ItemStack[gridSlots.length];
boolean canDivideInputs = true; boolean canDivideInputs = true;
boolean canDivideOutputs = true; boolean canDivideOutputs = true;
for( int x = 0; x < this.gridSlots.length; x++ ) for( int x = 0; x < this.gridSlots.length; x++ )
{ {
input[x] = this.gridSlots[x].getStack(); input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getCount() % divide != 0 ) if( !input[x].isEmpty() && input[x].getCount() % divide != 0 )
{ {
canDivideInputs = false; canDivideInputs = false;
} }
} }
for( final OptionalSlotFake outputSlot : this.outputSlots ) for( final OptionalSlotFake outputSlot : this.outputSlots )
{ {
final ItemStack out = outputSlot.getStack(); final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() % divide != 0 ) if( !out.isEmpty() && out.getCount() % divide != 0 )
{ {
canDivideOutputs = false; canDivideOutputs = false;
} }
} }
if( canDivideInputs && canDivideOutputs ) if( canDivideInputs && canDivideOutputs )
{ {
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots ) for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{ {
ItemStack stack = craftingSlot.getStack(); ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
craftingSlot.getStack().setCount( stack.getCount() / divide ); craftingSlot.getStack().setCount( stack.getCount() / divide );
} }
} }
for( OptionalSlotFake outputSlot : this.outputSlots ) for( OptionalSlotFake outputSlot : this.outputSlots )
{ {
ItemStack stack = outputSlot.getStack(); ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
outputSlot.getStack().setCount( stack.getCount() / divide ); outputSlot.getStack().setCount( stack.getCount() / divide );
} }
} }
} }
} }
public void increase( int increase ) public void increase( int increase )
{ {
ItemStack[] input = new ItemStack[gridSlots.length]; ItemStack[] input = new ItemStack[gridSlots.length];
boolean canIncreaseInputs = true; boolean canIncreaseInputs = true;
boolean canIncreaseOutputs = true; boolean canIncreaseOutputs = true;
for( int x = 0; x < this.gridSlots.length; x++ ) for( int x = 0; x < this.gridSlots.length; x++ )
{ {
input[x] = this.gridSlots[x].getStack(); input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getCount() + increase > input[x].getMaxStackSize() ) if( !input[x].isEmpty() && input[x].getCount() + increase > input[x].getMaxStackSize() )
{ {
canIncreaseInputs = false; canIncreaseInputs = false;
} }
} }
for( final OptionalSlotFake outputSlot : this.outputSlots ) for( final OptionalSlotFake outputSlot : this.outputSlots )
{ {
final ItemStack out = outputSlot.getStack(); final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() + increase > out.getMaxStackSize() ) if( !out.isEmpty() && out.getCount() + increase > out.getMaxStackSize() )
{ {
canIncreaseOutputs = false; canIncreaseOutputs = false;
} }
} }
if( canIncreaseInputs && canIncreaseOutputs ) if( canIncreaseInputs && canIncreaseOutputs )
{ {
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots ) for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{ {
ItemStack stack = craftingSlot.getStack(); ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
craftingSlot.getStack().setCount( stack.getCount() + increase ); craftingSlot.getStack().setCount( stack.getCount() + increase );
} }
} }
for( OptionalSlotFake outputSlot : this.outputSlots ) for( OptionalSlotFake outputSlot : this.outputSlots )
{ {
ItemStack stack = outputSlot.getStack(); ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
outputSlot.getStack().setCount( stack.getCount() + increase ); outputSlot.getStack().setCount( stack.getCount() + increase );
} }
} }
} }
} }
public void decrease( int decrease ) public void decrease( int decrease )
{ {
ItemStack[] input = new ItemStack[gridSlots.length]; ItemStack[] input = new ItemStack[gridSlots.length];
boolean canDecreaseInputs = true; boolean canDecreaseInputs = true;
boolean canDecreaseOutputs = true; boolean canDecreaseOutputs = true;
for( int x = 0; x < this.gridSlots.length; x++ ) for( int x = 0; x < this.gridSlots.length; x++ )
{ {
input[x] = this.gridSlots[x].getStack(); input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getCount() - decrease < 1 ) if( !input[x].isEmpty() && input[x].getCount() - decrease < 1 )
{ {
canDecreaseInputs = false; canDecreaseInputs = false;
} }
} }
for( final OptionalSlotFake outputSlot : this.outputSlots ) for( final OptionalSlotFake outputSlot : this.outputSlots )
{ {
final ItemStack out = outputSlot.getStack(); final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() - decrease < 1 ) if( !out.isEmpty() && out.getCount() - decrease < 1 )
{ {
canDecreaseOutputs = false; canDecreaseOutputs = false;
} }
} }
if( canDecreaseInputs && canDecreaseOutputs ) if( canDecreaseInputs && canDecreaseOutputs )
{ {
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots ) for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{ {
ItemStack stack = craftingSlot.getStack(); ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
craftingSlot.getStack().setCount( stack.getCount() - decrease ); craftingSlot.getStack().setCount( stack.getCount() - decrease );
} }
} }
for( OptionalSlotFake outputSlot : this.outputSlots ) for( OptionalSlotFake outputSlot : this.outputSlots )
{ {
ItemStack stack = outputSlot.getStack(); ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
outputSlot.getStack().setCount( stack.getCount() - decrease ); outputSlot.getStack().setCount( stack.getCount() - decrease );
} }
} }
} }
} }
public void maximizeCount() public void maximizeCount()
{ {
ItemStack[] input = new ItemStack[gridSlots.length]; ItemStack[] input = new ItemStack[gridSlots.length];
boolean canGrowInputs = true; boolean canGrowInputs = true;
boolean canGrowOutputs = true; boolean canGrowOutputs = true;
int maxInputStackGrowth = 0; int maxInputStackGrowth = 0;
int maxOutputStackGrowth = 0; int maxOutputStackGrowth = 0;
for( int x = 0; x < this.gridSlots.length; x++ ) for( int x = 0; x < this.gridSlots.length; x++ )
{ {
input[x] = this.gridSlots[x].getStack(); input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getMaxStackSize() - input[x].getCount() > maxInputStackGrowth ) if( !input[x].isEmpty() && input[x].getMaxStackSize() - input[x].getCount() > maxInputStackGrowth )
{ {
maxInputStackGrowth = input[x].getMaxStackSize() - input[x].getCount(); maxInputStackGrowth = input[x].getMaxStackSize() - input[x].getCount();
} }
if( !input[x].isEmpty() && input[x].getCount() + maxInputStackGrowth > input[x].getMaxStackSize() ) if( !input[x].isEmpty() && input[x].getCount() + maxInputStackGrowth > input[x].getMaxStackSize() )
{ {
canGrowInputs = false; canGrowInputs = false;
} }
} }
for( final OptionalSlotFake outputSlot : this.outputSlots ) for( final OptionalSlotFake outputSlot : this.outputSlots )
{ {
final ItemStack out = outputSlot.getStack(); final ItemStack out = outputSlot.getStack();
{ {
maxOutputStackGrowth = out.getMaxStackSize() - out.getCount(); maxOutputStackGrowth = out.getMaxStackSize() - out.getCount();
} }
if( !out.isEmpty() && out.getCount() + maxOutputStackGrowth > out.getMaxStackSize() ) if( !out.isEmpty() && out.getCount() + maxOutputStackGrowth > out.getMaxStackSize() )
{ {
canGrowOutputs = false; canGrowOutputs = false;
} }
} }
if( canGrowInputs && canGrowOutputs ) if( canGrowInputs && canGrowOutputs )
{ {
int maxStackGrowth = Math.min( maxInputStackGrowth, maxOutputStackGrowth ); int maxStackGrowth = Math.min( maxInputStackGrowth, maxOutputStackGrowth );
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots ) for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{ {
ItemStack stack = craftingSlot.getStack(); ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
craftingSlot.getStack().setCount( stack.getCount() + maxStackGrowth ); craftingSlot.getStack().setCount( stack.getCount() + maxStackGrowth );
} }
} }
for( OptionalSlotFake outputSlot : this.outputSlots ) for( OptionalSlotFake outputSlot : this.outputSlots )
{ {
ItemStack stack = outputSlot.getStack(); ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
outputSlot.getStack().setCount( stack.getCount() + maxStackGrowth ); outputSlot.getStack().setCount( stack.getCount() + maxStackGrowth );
} }
} }
} }
} }
@Override
public void onSlotChange( final Slot s )
{
if( s == this.patternSlotOUT && Platform.isServer() )
{
for( final IContainerListener listener : this.listeners )
{
for( final Slot slot : this.inventorySlots )
{
if( slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix )
{
listener.sendSlotContents( this, slot.slotNumber, slot.getStack() );
}
}
if( listener instanceof EntityPlayerMP )
{
( (EntityPlayerMP) listener ).isChangingQuantityOnly = false;
}
}
this.detectAndSendChanges();
}
}
} }