mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-15 03:35:42 +00:00
Add validation to printer slots (#1099)
This commit is contained in:
parent
24ed0ca723
commit
34dc915d57
@ -7,6 +7,7 @@ package dan200.computercraft.shared.peripheral.printer;
|
||||
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.util.SingleIntArray;
|
||||
import dan200.computercraft.shared.util.ValidatingSlot;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@ -33,13 +34,13 @@ public class ContainerPrinter extends Container
|
||||
addDataSlots( properties );
|
||||
|
||||
// Ink slot
|
||||
addSlot( new Slot( inventory, 0, 13, 35 ) );
|
||||
addSlot( new ValidatingSlot( inventory, 0, 13, 35, TilePrinter::isInk ) );
|
||||
|
||||
// In-tray
|
||||
for( int x = 0; x < 6; x++ ) addSlot( new Slot( inventory, x + 1, 61 + x * 18, 22 ) );
|
||||
for( int x = 0; x < 6; x++ ) addSlot( new ValidatingSlot( inventory, x + 1, 61 + x * 18, 22, TilePrinter::isPaper ) );
|
||||
|
||||
// Out-tray
|
||||
for( int x = 0; x < 6; x++ ) addSlot( new Slot( inventory, x + 7, 61 + x * 18, 49 ) );
|
||||
for( int x = 0; x < 6; x++ ) addSlot( new ValidatingSlot( inventory, x + 7, 61 + x * 18, 49, o -> false ) );
|
||||
|
||||
// Player inv
|
||||
for( int y = 0; y < 3; y++ )
|
||||
|
@ -308,7 +308,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
return ColourUtils.getStackColour( stack ) != null;
|
||||
}
|
||||
|
||||
private static boolean isPaper( @Nonnull ItemStack stack )
|
||||
static boolean isPaper( @Nonnull ItemStack stack )
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
return item == Items.PAPER
|
||||
|
@ -10,17 +10,21 @@ import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ValidatingSlot extends Slot
|
||||
{
|
||||
public ValidatingSlot( IInventory inventoryIn, int index, int xPosition, int yPosition )
|
||||
private final Predicate<ItemStack> predicate;
|
||||
|
||||
public ValidatingSlot( IInventory inventoryIn, int index, int xPosition, int yPosition, Predicate<ItemStack> predicate )
|
||||
{
|
||||
super( inventoryIn, index, xPosition, yPosition );
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayPlace( @Nonnull ItemStack stack )
|
||||
{
|
||||
return true; // inventory.isItemValidForSlot( slotNumber, stack );
|
||||
return predicate.test( stack );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user