Jump to content

Recommended Posts

Posted

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

Posted
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

Posted
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?

Posted
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

Posted
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

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

        }
    }

 

 

Posted (edited)
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
Posted
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

Posted
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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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