Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

RenderPlayerEvent is not working(1.16.5)


ElTotisPro50
 Share

Recommended Posts

Hi, i made a keybind and when i press it it should modify my player, like the rotation of any part or something but it is doing nothing

@SubscribeEvent
    public static void playerRotations(RenderPlayerEvent.Pre event)
    {
        if(ModKeys.testKey.isKeyDown())
        {
            event.getPlayer().sendStatusMessage(new StringTextComponent("Hola"),false);
            event.getRenderer().getEntityModel().bipedRightArm.rotateAngleX = 180f;
        }
    }

It is sending the message but is not rotating my arm, or head or anything that i put after .biped, i also tried RenderPlayerEvent.Post and is not working neither,as I said is not the playerRotations() event because is displaying the message and i have more events in this class that does work, i tried using math:

event.getRenderer().getEntityModel().bipedRightArm.rotateAngleX = (float) Math.toRadians(180f);

but nothing is working, i need a solution because i made this in 1.12.2 and it worked, the only thing that changed was .getEntityModel(), in 1.12.2 it was getMainModel() 

 

Link to comment
Share on other sites

On 11/28/2021 at 7:45 PM, ElTotisPro50 said:

Is not working :(

check if your event is getting fired, first (and you must be in 3rd person on singleplayer for it to work).

second, modifying those values doesn't do anything. It is already rendered (in post) or the values will be overwritten for rendering (in pre). You need to cancel the rendering and do it yourself. I do it with the field model#visible = false in pre, then in post, set it to true, then modify the rotation points and angles, then render it using the render method that takes the buffer, vertex builder, ...

it would be much easier to use rightArmPose = ... in PRE. 

Link to comment
Share on other sites

1 hour ago, matthew123 said:

check if your event is getting fired, first (and you must be in 3rd person on singleplayer for it to work).

second, modifying those values doesn't do anything. It is already rendered (in post) or the values will be overwritten for rendering (in pre). You need to cancel the rendering and do it yourself. I do it with the field model#visible = false in pre, then in post, set it to true, then modify the rotation points and angles, then render it using the render method that takes the buffer, vertex builder, ...

it would be much easier to use rightArmPose = ... in PRE. 

Ok i didnt undertand absolutely anything, even that i learned minecraft modding 1 year ago, can you post a image with code of how can i do that please?

Link to comment
Share on other sites

14 minutes ago, ElTotisPro50 said:

Ok i didnt undertand absolutely anything, even that i learned minecraft modding 1 year ago, can you post a image with code of how can i do that please?

I myself learned modding a couple weeks ago and did not have any trouble following the suggestion from dieseben07 which was: "cancel the event and do the rendering yourself". If you want to get anywhere with modding, you need to learn it properly.

On PlayerRenderEvent.pre, take the arm model, and set the visible field to false. In RenderPlayerEvent.post, set the field to true, then adjust the x, y, z fields of the arm model (the rotation points). Y is either 20 or 17.5 if crouching (i believe). Use some trigonometry to calculate the rest from the player's rotations. Then you have the xRot, ... fields which you can modify. You might need some math for that too.

After you're done modifying the pose, call render for the arm model. It takes the matrix stack from the event, a vertex builder, ... you can see an example of using this from the vanilla rendering code. I actually learned how to do this by studying vanilla code. You should too! All the code you need is there.

Link to comment
Share on other sites

7 hours ago, matthew123 said:

I myself learned modding a couple weeks ago and did not have any trouble following the suggestion from dieseben07 which was: "cancel the event and do the rendering yourself". If you want to get anywhere with modding, you need to learn it properly.

On PlayerRenderEvent.pre, take the arm model, and set the visible field to false. In RenderPlayerEvent.post, set the field to true, then adjust the x, y, z fields of the arm model (the rotation points). Y is either 20 or 17.5 if crouching (i believe). Use some trigonometry to calculate the rest from the player's rotations. Then you have the xRot, ... fields which you can modify. You might need some math for that too.

After you're done modifying the pose, call render for the arm model. It takes the matrix stack from the event, a vertex builder, ... you can see an example of using this from the vanilla rendering code. I actually learned how to do this by studying vanilla code. You should too! All the code you need is there.

Nope, i need a example with code, because i dont know what you mean by "On PlayerRenderEvent.Pre and .Post", im using a key event to work, RenderPlayerEvent is a minecraft class and i cant modify it, i dont know what you mean by that, even if that sound silly thats how i program, i cant just read a solution and do it because i dont know how to do it i need a example, most programers dont need a guide with examples but i do, even i know java, c++ and python

Link to comment
Share on other sites

5 hours ago, ElTotisPro50 said:

Nope, i need a example with code, because i dont know what you mean by "On PlayerRenderEvent.Pre and .Post", im using a key event to work, RenderPlayerEvent is a minecraft class and i cant modify it, i dont know what you mean by that, even if that sound silly thats how i program, i cant just read a solution and do it because i dont know how to do it i need a example, most programers dont need a guide with examples but i do, even i know java, c++ and python

You should read the documentation from mcforge.readthedocs.io.

"On RenderPlayerEvent.Pre" is exactly what is sounds like : on that event, do as instructed above.

"I even know java, c++ and python" irrelevant. Programming is not necessarily about how many languages you've learned, but how well you can use one of them. Just being familiar with an OOP language would have made it possible to study the vanilla code. 

I'll tell you again. On RenderPlayerEvent.Pre set the visible field on the rightArm model to false, and in post, set it to true, then set it's x, y, z position and rotation values (look at how vanilla does it). Then call the render method passing in the matrix from the event object. Also see how vanilla does it.

This example is not very good for practical purposes, but I hope is enough to satisfy the stack overflow trend:

@SubscribeEvent
public void renderPlayerPre(RenderPlayerEvent.Pre event) {
    event.getRenderer().getModel().rightArm.visible = false;
}
@SubscribeEvent
public void renderPlayerPost(RenderPlayerEvent.Post event) {
        PlayerEntity player = event.getPlayer();
        PlayerModel<AbstractClientPlayerEntity> model = event.getRenderer().getModel();
        ModelRenderer rightArm = model.rightArm;
        rightArm.visible = true;
        // rotation point
        rightArm.x = -MathHelper.cos((float) Math.toRadians(player.yRot)) * 5.0F;
        rightArm.y = 20;
        rightArm.z = -MathHelper.sin((float) Math.toRadians(player.yRot)) * 5.0F;
        // rotation
        rightArm.xRot = (float) Math.toRadians(42);
        rightArm.yRot = (float) -Math.toRadians(player.yBodyRot);
        rightArm.render(
                event.getMatrixStack(),
                event.getBuffers().getBuffer(RenderType.entitySolid(((AbstractClientPlayerEntity)player).getSkinTextureLocation())),
                Minecraft.getInstance().getEntityRenderDispatcher().getPackedLightCoords(player, 1f),
                OverlayTexture.NO_OVERLAY);
}

 

Link to comment
Share on other sites

7 hours ago, matthew123 said:

You should read the documentation from mcforge.readthedocs.io.

"On RenderPlayerEvent.Pre" is exactly what is sounds like : on that event, do as instructed above.

"I even know java, c++ and python" irrelevant. Programming is not necessarily about how many languages you've learned, but how well you can use one of them. Just being familiar with an OOP language would have made it possible to study the vanilla code. 

I'll tell you again. On RenderPlayerEvent.Pre set the visible field on the rightArm model to false, and in post, set it to true, then set it's x, y, z position and rotation values (look at how vanilla does it). Then call the render method passing in the matrix from the event object. Also see how vanilla does it.

This example is not very good for practical purposes, but I hope is enough to satisfy the stack overflow trend:

@SubscribeEvent
public void renderPlayerPre(RenderPlayerEvent.Pre event) {
    event.getRenderer().getModel().rightArm.visible = false;
}
@SubscribeEvent
public void renderPlayerPost(RenderPlayerEvent.Post event) {
        PlayerEntity player = event.getPlayer();
        PlayerModel<AbstractClientPlayerEntity> model = event.getRenderer().getModel();
        ModelRenderer rightArm = model.rightArm;
        rightArm.visible = true;
        // rotation point
        rightArm.x = -MathHelper.cos((float) Math.toRadians(player.yRot)) * 5.0F;
        rightArm.y = 20;
        rightArm.z = -MathHelper.sin((float) Math.toRadians(player.yRot)) * 5.0F;
        // rotation
        rightArm.xRot = (float) Math.toRadians(42);
        rightArm.yRot = (float) -Math.toRadians(player.yBodyRot);
        rightArm.render(
                event.getMatrixStack(),
                event.getBuffers().getBuffer(RenderType.entitySolid(((AbstractClientPlayerEntity)player).getSkinTextureLocation())),
                Minecraft.getInstance().getEntityRenderDispatcher().getPackedLightCoords(player, 1f),
                OverlayTexture.NO_OVERLAY);
}

 

rightArm.render( event.getMatrixStack(), event.getBuffers().getBuffer(RenderType.entitySolid(((AbstractClientPlayerEntity)player).getSkinTextureLocation())), Minecraft.getInstance().getEntityRenderDispatcher().getPackedLightCoords(player, 1f), OverlayTexture.NO_OVERLAY); has errors, im using the forge mappings :/, getEntityRenderDispatcher does not exist... im so angry because mojang ALL THE TIME has to change almost the entire code of minecraft, in 1.12.2 you needed 1 LINE OF CODE, wtf (There are like 3 things that doest exist, getEntityRenderDispatcher , getSkinTextureLocation, getPackedLightCoords(player, 1f))

Edited by ElTotisPro50
Link to comment
Share on other sites

1 hour ago, ElTotisPro50 said:

rightArm.render( event.getMatrixStack(), event.getBuffers().getBuffer(RenderType.entitySolid(((AbstractClientPlayerEntity)player).getSkinTextureLocation())), Minecraft.getInstance().getEntityRenderDispatcher().getPackedLightCoords(player, 1f), OverlayTexture.NO_OVERLAY); has errors, im using the forge mappings :/, getEntityRenderDispatcher does not exist... im so angry because mojang ALL THE TIME has to change almost the entire code of minecraft, in 1.12.2 you needed 1 LINE OF CODE, wtf (There are like 3 things that doest exist, getEntityRenderDispatcher , getSkinTextureLocation, getPackedLightCoords(player, 1f))

Then analyze the vanilla code and find the right names!!!

Link to comment
Share on other sites

1 hour ago, matthew123 said:

Then analyze the vanilla code and find the right names!!!

affter a bit of time this worked:

@SubscribeEvent
    public static void renderPlayerPre(RenderPlayerEvent.Pre event)
    {
        //here i was canceling the pre event so...
        event.getRenderer().getEntityModel().bipedLeftArm.showModel = false;
    }

    @SubscribeEvent
    public static void renderPlayerPost(RenderPlayerEvent.Post event)
    {
        PlayerEntity player = event.getPlayer();
        PlayerModel<AbstractClientPlayerEntity> model = event.getRenderer().getEntityModel();
        ModelRenderer rightArm = model.bipedLeftArm;
        rightArm.showModel = true;
        rightArm.render(
                event.getMatrixStack(),
                event.getBuffers().getBuffer(RenderType.getEntitySolid(((AbstractClientPlayerEntity)player).getLocationSkin())),
                Minecraft.getInstance().getRenderManager().getPackedLight(player, 1f), OverlayTexture.NO_OVERLAY);
    }

But just one more thing, i promess no more questions..., the hand is like this: https://imgur.com/a/KTVudC3, and there is no offsetX, Y, or Z, do i need arm.rotationPointSOMETHING to move the hand wherever i want?

Link to comment
Share on other sites

1 hour ago, ElTotisPro50 said:

affter a bit of time this worked:

@SubscribeEvent
    public static void renderPlayerPre(RenderPlayerEvent.Pre event)
    {
        //here i was canceling the pre event so...
        event.getRenderer().getEntityModel().bipedLeftArm.showModel = false;
    }

    @SubscribeEvent
    public static void renderPlayerPost(RenderPlayerEvent.Post event)
    {
        PlayerEntity player = event.getPlayer();
        PlayerModel<AbstractClientPlayerEntity> model = event.getRenderer().getEntityModel();
        ModelRenderer rightArm = model.bipedLeftArm;
        rightArm.showModel = true;
        rightArm.render(
                event.getMatrixStack(),
                event.getBuffers().getBuffer(RenderType.getEntitySolid(((AbstractClientPlayerEntity)player).getLocationSkin())),
                Minecraft.getInstance().getRenderManager().getPackedLight(player, 1f), OverlayTexture.NO_OVERLAY);
    }

But just one more thing, i promess no more questions..., the hand is like this: https://imgur.com/a/KTVudC3, and there is no offsetX, Y, or Z, do i need arm.rotationPointSOMETHING to move the hand wherever i want?

seriously, why don't you analyze the darn code? just look for float fields.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hey,   Is it already possible to login and authenticate when your account has been migrated? Currently I just get the error Migrated.
    • Amplifier is like the strength of the effect, for example movement speed boost with amplifier 0 will be Speed I, and 1 will be Speed II, 2 will be Speed III. Effect is just an...effect type, EffectInstance contains all information for the actual effect being applied to the entity (duration, amplifier...etc). For example there's only an effect type "Speed", but for an EffectInstance it could be: "Level 2 Speed for 10 seconds" "Level 4 Speed for 2 seconds"...   The first method applyEffectTick is called when a effect is impacting the entity, the first arg is the entity that has the effect/is affected by the effect, and amplifier is the strength of the effect. The second method isDurationEFfectTick is to check whether the effect should impact/affect the entity this tick (the effects usually don't trigger every tick!), if true, then the first method is called.  
    • Hi, I have enchantment named "Stun" that can be applied to weapon and that has 3 levels: Level 1 - 10% chance to stun mob for 1 sec Level 2 - 20% chance to stun mob for 2 secs Level 3 - 30% chance to stun mob for 3 secs Plan is to apply MobEffect named StunnedMobEffect on doPostAttack in enchantment. StunnedMobEffect should have variable duration based on the level of enchantment that was applied on weapon. I am trying to find an example on how to do the following: How can I set duration of effect dynamically? How can I track whether duration has expired? I have found these two methods that can be overriden:   public void applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) { public boolean isDurationEffectTick(int pDuration, int pAmplifier) { But looking at the source code of MobEffect class, I can't figure out what pAmplifier is? Any hints / samples on this would be appreciated.          
    • 2022-01-22 07:41:00,800 main WARN Advanced terminal features are not available in this environment [07:41:00] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [07:41:00] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.2 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0x7ff95560) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0x7ff95560         at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:41)         at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95)         at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:41)         at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55)         at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47)         at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62)         at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55)         at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)         at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63)         at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60)         at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) i have the same how do i fix it  
    • Hi, I'm facing an issue that a custom datapack is always loaded before the mod's datapack. Means the users/players are not able to override mod's configurations/data at all. I've tried to alternate the order of datapack by using the /datapack commands, however the actual loading order does not change at all. (I can confirm that both datapacks are working as usual by disabling one of them at a time, the correspond data is loaded correctly), is it the mod's problem or...? Thanks.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.