Jump to content

How to get the server Player Entity


Laxo

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

        }
    }

 

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.