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

Im trying to get the "ServerPlayerEntity", with Minecraft.getInstance().player I get the normal PlayerEntity how do I get the "ServerPlayerEntity".

6 minutes ago, Laxo said:

Im trying to get the "ServerPlayerEntity", with Minecraft.getInstance().player I get the normal PlayerEntity how do I get the "ServerPlayerEntity".

Minecraft.getInstance().player will return a ClientPlayerEntity, you can't get the ServerPlayer via Minecraft.getInstance().player

  • Author
1 minute ago, Luis_ST said:

Minecraft.getInstance().player will return a ClientPlayerEntity, you can't get the ServerPlayer via Minecraft.getInstance().player

Ohhh okay, and how do I get the server player?

Just now, Laxo said:

Ohhh okay, and how do I get the server player?

where exactly do you need a ServerPlayerEntity

  • Author
3 minutes ago, Luis_ST said:

where exactly do you need a ServerPlayerEntity

Well Im trying to open a gui for a player in with network hooks

4 minutes ago, Laxo said:

Well Im trying to open a gui for a player in with network hooks

show your code, so that I can understand which "side" (server|client) your code is execute

  • Author
Just now, diesieben07 said:

Which player. There is not just one player on a server.

I understand well I am trying to get the player that was picked by the event, and make him open a GUI.

 

Quote

 

    @OnlyIn(Dist.CLIENT)
    @SubscribeEvent
    public void initGui(GuiOpenEvent event) {
        if(event.getGui() instanceof IngameMenuScreen) {
            event.setCanceled(true);
            PlayerEntity entityPlayer = Minecraft.getInstance().player;
                BlockPos blockPosition = new BlockPos((int) entityPlayer.getPosX(), (int) entityPlayer.getPosition().getY(), (int) entityPlayer.getPosZ());
                NetworkHooks.openGui((ServerPlayerEntity) entityPlayer, new INamedContainerProvider() {

                    @Override
                    public ITextComponent getDisplayName() {
                        return new StringTextComponent("CustomEscapeGui");
                    }

                    @Override
                    public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) {
                        return new CustomEscapeGui.GuiContainerMod(id, inventory, new PacketBuffer(Unpooled.buffer()).writeBlockPos(_bpos));
                    }
                }, blockPosition);
            

        }
    }

 

 

5 minutes ago, Laxo said:

I understand well I am trying to get the player that was picked by the event, and make him open a GUI.

do not use "@OnlyIn(Dist.CLIENT)"
and this is the worng way to do this.
whenever a screen is opened, this is prevented and your screen is opened
you also create an infinite cycle (StackOverflowError),
you create a container that triggers the event again

when exactly do you want to open a container?

Edited by Luis_ST

  • Author
1 minute ago, Luis_ST said:

do not use "@OnlyIn(Dist.CLIENT)"
and this is the worng way to do this.
whenever a screen is opened, this is prevented and your screnn is opened
you also create an infinite cycle (StackOverflowError follows),
you create a container that triggers the event again

Okay thank you sir

  • Author
3 minutes ago, Luis_ST said:

when exactly do you want to open a container?

I want to replace the normal Escape Menu so right after the user pressed the button

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.