Posted May 23, 20205 yr Hey, how can i associate my custom ContainerScreen to my own entity? Like horse inventory. In order to when i click E to open inventory my custom container should display. But that doesn't append. I have already register the screen in the ScreenManager. Here is my custom entity: public class RidableDolphinEnitity extends DolphinEntity implements INamedContainerProvider { protected Inventory inventory = new Inventory(2); public RidableDolphinEnitity(EntityType<RidableDolphinEnitity> type, World worldIn) { super(type, worldIn); } public Inventory getInventory() { return inventory; } @Nullable @Override public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) { return new RidableDolphinContainer(id, inventory, getInventory()); } @Override public ITextComponent getDisplayName() { return TextComponentUtils.toTextComponent(() -> "Dolphin Inventory"); } } Edited May 25, 20205 yr by ArcaneDiver
May 25, 20205 yr Author I tried to implement this by modifing the container on GuiOpenEvent and PlayerContainerEvent.Open but i sadly discovered that PlayerContainerEvent.Open doesn't fire for the Container of the player then how can i say "when i press E open my container"? Here is the code of events: @SubscribeEvent public static void onDolphinContainerOpen(PlayerContainerEvent.Open event) { // Never fires :C ServerPlayerEntity playerEntity = (ServerPlayerEntity) event.getPlayer(); if(playerEntity.getRidingEntity() instanceof RidableDolphinEnitity) { RidableDolphinEnitity dolphin = (RidableDolphinEnitity) playerEntity.getRidingEntity(); playerEntity.openContainer = new RidableDolphinContainer(playerEntity.currentWindowId, playerEntity.inventory, dolphin.getInventory()); } } @SubscribeEvent public static void onDolphinGuiOpen(GuiOpenEvent event) { if(event.getGui() instanceof ContainerScreen) { ClientPlayerEntity player = Minecraft.getInstance().player; if (player != null && player.getRidingEntity() instanceof RidableDolphinEnitity) { RidableDolphinEnitity dolphin = (RidableDolphinEnitity) player.getRidingEntity(); if(!(event.getGui() instanceof RidableDolphinScreen)) { ContainerScreen<?> oldScreen = (ContainerScreen) event.getGui(); Container oldContainer = oldScreen.getContainer(); RidableDolphinContainer container = new RidableDolphinContainer(oldContainer.windowId, player.inventory, dolphin.getInventory()); RidableDolphinScreen screen = new RidableDolphinScreen(container, player.inventory, dolphin.getDisplayName()); player.openContainer = container; event.setGui(screen); } } } }
May 25, 20205 yr Author I resolved by use a KeyBindingEvent and sending a packet to the server which calls NetworkHooks.openGui
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.