Posted May 21, 20214 yr Im trying to get the "ServerPlayerEntity", with Minecraft.getInstance().player I get the normal PlayerEntity how do I get the "ServerPlayerEntity".
May 21, 20214 yr 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
May 21, 20214 yr 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?
May 21, 20214 yr Just now, Laxo said: Ohhh okay, and how do I get the server player? where exactly do you need a ServerPlayerEntity
May 21, 20214 yr 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
May 21, 20214 yr 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
May 21, 20214 yr 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); } }
May 21, 20214 yr 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 May 21, 20214 yr by Luis_ST
May 21, 20214 yr 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
May 21, 20214 yr 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.