Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by ArcaneDiver

  • 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);

                }
            }
        }
    }

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.