-
Posts
2 -
Joined
-
Last visited
Gapherd's Achievements
Tree Puncher (2/8)
0
Reputation
-
[SOLVED] Can't make "mayPlace" function of Slot work properly
Gapherd replied to Gapherd's topic in Modder Support
Actually, the ClientSide was calling the DispenserMenu superclass instead of my implementation. So, the ClientSide would permit to move the item to the slot, and then in the SeverSide it would block. Causing the flickery effect. I wrote a new Menu and Screen class for my Ejector, without inheriting DispenserMenu, registered them and it worked. Thanks for the help. -
Gapherd started following [SOLVED] Can't make "mayPlace" function of Slot work properly
-
I'm trying to make a new type of Dispenser, inheriting the Dropper's properties. Firstly I want the Dispenser's menu slots to permit just the Bucket item, but when the player puts another item on the slot it will first receive the item and remove it afterward, causing a flickery effect on the slots as it's shown on the gif bellow: https://giphy.com/gifs/dy2NpO3WuKqGM1FvtM Bellow I'm printing the relevant classes: public class EjectorBlock extends DropperBlock { public EjectorBlock(Properties properties) { super(properties); } @Override public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { return new EjectorBlockEntity(blockPos, blockState); } @Override public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { if (!level.isClientSide()) { BlockEntity blockEntity = level.getBlockEntity(blockPos); if (blockEntity instanceof EjectorBlockEntity) { player.openMenu((EjectorBlockEntity) blockEntity); } } return InteractionResult.sidedSuccess(level.isClientSide); } } public class EjectorBlockEntity extends DispenserBlockEntity { public EjectorBlockEntity(BlockPos blockPos, BlockState blockState) { super(ModBlockEntities.EJECTOR_BLOCK_ENTITY.get(), blockPos, blockState); } @Override protected Component getDefaultName() { return Component.literal("Ejector"); } @Override protected AbstractContainerMenu createMenu(int id, Inventory inventory) { return new EjectorMenu(id, inventory, this); } } public class EjectorMenu extends DispenserMenu { private class BucketSlot extends Slot { public BucketSlot(Container container, int slot, int x, int y) { super(container, slot, x, y); } @Override public boolean mayPlace(ItemStack p_40231_) { return Items.BUCKET.equals(p_40231_.getItem()); } } public EjectorMenu(int id, Inventory inventory, Container container) { super(id, inventory, container); } @Override protected Slot addSlot(Slot slot) { if (this.slots.size() < 9) { return super.addSlot(new BucketSlot(slot.container, slot.getSlotIndex(), slot.x, slot.y)); } return super.addSlot(slot); } }