Gapherd Posted June 6, 2023 Posted June 6, 2023 (edited) 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); } } Edited June 7, 2023 by Gapherd The issue was solved Quote
ChampionAsh5357 Posted June 7, 2023 Posted June 7, 2023 19 hours ago, Gapherd said: @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); } This is not how you add slots. See https://docs.minecraftforge.net/en/1.19.x/gui/menus/#data-synchronization Quote
Gapherd Posted June 7, 2023 Author Posted June 7, 2023 2 hours ago, ChampionAsh5357 said: This is not how you add slots. See https://docs.minecraftforge.net/en/1.19.x/gui/menus/#data-synchronization 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.