Jump to content

Recommended Posts

Posted (edited)

How can I get Forge Capabilities from a player using

onRenderTick(TickEvent.RenderTickEvent event) {

to render kindoff gui, drawString for example.

Minecraft.getMinecraft().player is now EntityPlayerSP not EntityPlayerMP, so NBT also doesn't work. Maybe I should sync it somehow?

Anyway, Im trying use Capabilities, but on client side also it's empty.

 

Should I use other event? Which one then? I want to render specified drawString/drawTexturedModalRect when player is holding right mouse button on specified item.

Previously I was able to do that using NBTs and Item#onUpdateTick, then checking on client onRenderTick if player is holding specified item and draw value from player nbt.

That's a short explanation of what I want to do.

 

Thanks for advice!

Edited by dnzdnz686
Posted

Entity::getCapability allows you to get a specified capability data. As EntityPlayer(and EntityPlayerSP) are child classes of Entity you can use this method just fine.

 

11 minutes ago, dnzdnz686 said:

Minecraft.getMinecraft().player is now EntityPlayerSP not EntityPlayerMP

Minecraft.player was never EntityPlayerMP as EntityPlayerMP is a multiplayer player entity.

 

11 minutes ago, dnzdnz686 said:

NBT also doesn't work

NBT has nothing to do with getting the data of a capability.

 

12 minutes ago, dnzdnz686 said:

Anyway, Im trying use Capabilities, but on client side also it's empty.

Capabilities are common and are present on both client and server. What exactly have you tried?

 

11 minutes ago, dnzdnz686 said:

I want to render specified drawString/drawTexturedModalRect when player is holding right mouse button on specified item.

You can simply check that the active itemstack contains the desired item(if the item has a use duration) or if the currently selected itemstack contains the desired item and the right mouse button is pressed down.

Posted
1 minute ago, V0idWa1k3r said:

Entity::getCapability allows you to get a specified capability data. As EntityPlayer(and EntityPlayerSP) are child classes of Entity you can use this method just fine.

 

Minecraft.player was never EntityPlayerMP as EntityPlayerMP is a multiplayer player entity.

 

NBT has nothing to do with getting the data of a capability.

 

Capabilities are common and are present on both client and server. What exactly have you tried?

 

You can simply check that the active itemstack contains the desired item(if the item has a use duration) or if the currently selected itemstack contains the desired item and the right mouse button is pressed down.

Capabilities are common yes, aka both on the server and client, however, the capability data is only saved on the server. As per official documentation.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted
20 minutes ago, V0idWa1k3r said:

Minecraft.player was never EntityPlayerMP as EntityPlayerMP is a multiplayer player entity.

Yeah, it was EntityClientPlayerMP, my bad.

 

23 minutes ago, V0idWa1k3r said:

NBT has nothing to do with getting the data of a capability.

I know. I mean, I used NBT before, when I was able to. But now NBT is different on Client and Server.

For example Im setting nbt string in Item#onUsingTick. Then I want to read it from Minecraft.getMinecraft().player.getEntityData() (because TickEvent.RenderTickEvent doesn't have any entity or player field), and there is no such string.

 

So I decided to use new DataStorage. I've tried to change TickEvent.RenderTickEvent to LivingEntityUseItemEvent.Tick, but error appear on bindTexture, "java.lang.RuntimeException: No OpenGL context found in the current thread.". So Im done at the moment.

 

20 minutes ago, Matryoshika said:

Capabilities are common yes, aka both on the server and client, however, the capability data is only saved on the server. As per official documentation.

Exactly. So how am I able to read any data from client? Should I use Custom Packets for such a thing?

Posted
1 minute ago, dnzdnz686 said:

So I decided to use new DataStorage. I've tried to change TickEvent.RenderTickEvent to LivingEntityUseItemEvent.Tick, but error appear on bindTexture, "java.lang.RuntimeException: No OpenGL context found in the current thread.". So Im done at the moment.

All redering must be done on the rendering thread. You need to use render-related events. You can still access capabilities and such from the render thread just fine.

 

2 minutes ago, dnzdnz686 said:

Exactly. So how am I able to read any data from client? Should I use Custom Packets for such a thing?

If the data you need is only present on a server then yes, you need a custom packet to sync the data to the client.

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.