Jump to content

Recommended Posts

Posted (edited)

Hello! I just wanted to ask if somebody could point me in the right direction in terms of making entity renderers. I'm just stuck in understanding stuff like the MatrixStack in the following code:

 

 

 
 
 
 
Spoiler

package net.minecraft.client.renderer.entity;

 

import com.mojang.blaze3d.matrix.MatrixStack;

import com.mojang.blaze3d.vertex.IVertexBuilder;

import net.minecraft.client.renderer.IRenderTypeBuffer;

import net.minecraft.client.renderer.Vector3f;

import net.minecraft.client.renderer.entity.model.TridentModel;

import net.minecraft.client.renderer.texture.OverlayTexture;

import net.minecraft.entity.projectile.TridentEntity;

import net.minecraft.util.ResourceLocation;

import net.minecraft.util.math.MathHelper;

import net.minecraftforge.api.distmarker.Dist;

import net.minecraftforge.api.distmarker.OnlyIn;

 

@OnlyIn(Dist.CLIENT)

public class TridentRenderer extends EntityRenderer<TridentEntity> {

   public static final ResourceLocation field_203087_a = new ResourceLocation("textures/entity/trident.png");

   private final TridentModel field_203088_f = new TridentModel();

 

   public TridentRenderer(EntityRendererManager p_i48828_1_) {

      super(p_i48828_1_);

   }

 

   public void func_225623_a_(TridentEntity p_225623_1_, float p_225623_2_, float p_225623_3_, MatrixStack p_225623_4_, IRenderTypeBuffer p_225623_5_, int p_225623_6_) {

      p_225623_4_.func_227860_a_();

      p_225623_4_.func_227863_a_(Vector3f.field_229181_d_.func_229187_a_(MathHelper.lerp(p_225623_3_, p_225623_1_.prevRotationYaw, p_225623_1_.rotationYaw) - 90.0F));

      p_225623_4_.func_227863_a_(Vector3f.field_229183_f_.func_229187_a_(MathHelper.lerp(p_225623_3_, p_225623_1_.prevRotationPitch, p_225623_1_.rotationPitch) + 90.0F));

      IVertexBuilder ivertexbuilder = net.minecraft.client.renderer.ItemRenderer.func_229113_a_(p_225623_5_, this.field_203088_f.func_228282_a_(this.getEntityTexture(p_225623_1_)), false, p_225623_1_.func_226572_w_());

      this.field_203088_f.func_225598_a_(p_225623_4_, ivertexbuilder, p_225623_6_, OverlayTexture.field_229196_a_, 1.0F, 1.0F, 1.0F, 1.0F);

      p_225623_4_.func_227865_b_();

      super.func_225623_a_(p_225623_1_, p_225623_2_, p_225623_3_, p_225623_4_, p_225623_5_, p_225623_6_);

   }

 

   public ResourceLocation getEntityTexture(TridentEntity entity) {

      return field_203087_a;

   }

}

 

I've also seen it be used with methods like push() and pop() in here https://github.com/mekanism/Mekanism/blob/1.15x/src/main/java/mekanism/client/render/entity/RenderFlame.java (not my code).

I'm honestly just lost on whats happening or if I even need to understand it to make a renderer for my entity.

 

Help would be greatly appreciated!

Edited by chubel10
Posted

Just to add on to what I said:

 

I'm mostly confused because I thought the model controlled everything having to do with hitboxes, sizes and stuff but I already completely changed my model and the hitbox and length of the entity is unchanged —as well as the code of the renderer which I copy pasted from another vanilla class but I can't really read or understand due to all of the weird "func_227860_a_"s and the like which don't really help.

 

Thanks in advance!

Posted
12 minutes ago, chubel10 said:

I'm mostly confused because I thought the model controlled everything having to do with hitboxes, sizes and stuff but I already completely changed my model and the hitbox and length of the entity is unchanged —as well as the code of the renderer which I copy pasted from another vanilla class but I can't really read or understand due to all of the weird "func_227860_a_"s and the like which don't really help.

Model controls the entity's appearance; it doesn't control the collision box (which is used in code that handles physics). An entity can have a huge model and a small collision box at the same time.

 

MatrixStack is used to record the transformation of rendering via a stack. It is similar to the stack manipulation of GlStateManager in earlier versions.

An example of updating from GlStateManager to MatrixStack is this.

 

As for the obfuscated names, you should update your Forge to latest. The mapping has been updated in the later versions (I was using 31.1.0 and experienced the same thing).

  • Like 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

Stacks in rendering is something like:

Each matrix in stack holds a series of transformations (position, rotation, scale). When you render something, it undergoes the transformation of all recorded transformation in the stack. When you pop a matrix (let's call it matrix A), it removes all the transformations after the pushing of matrix A.

 

For example (pseudocode):

pushMatrix();
translate(3, 0, 2); // move 3 units on x axis, and 2 units on z axis
renderModelA();

pushMatrix();
rotate(180, 1, 0, 0); // rotate 180 around the x axis
renderModelB();
popMatrix();

scale(2, 2, 2); // scale 2 on all axis
renderModelC();
popMatrix();

Model A would be rendered with translation of 3, 0, 2.

Model B would be rendered rotated 180 around x axis and translated 3, 0, 2.

Model C would be rendered 2x the size and translated 3, 0, 2. Since the matrix involving the rotation is already popped at the time Model C is rendered, the rotation does not apply to Model C.

  • Like 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

Hello! Sorry for taking so long to reply.

 

On 4/22/2020 at 10:32 PM, DavidM said:

An example of updating from GlStateManager to MatrixStack is this.

Thank you for providing some code! But how did you deal with the obfuscated names? Like did you climb definitions until you reached a method without obfuscated names in order to understand it?

 

On 4/22/2020 at 10:32 PM, DavidM said:

As for the obfuscated names, you should update your Forge to latest. The mapping has been updated in the later versions (I was using 31.1.0 and experienced the same thing).

Thanks for the tip.

How could I go about updating my forge? do I have to do the whole setup thing again and copy my code or is there some fancy terminal code that I should learn?

 

On 4/22/2020 at 10:41 PM, DavidM said:

Stacks

All of your stack explanations were really helpful and they are much obliged. I'll look into your code and try to implement it !

 

Thanks in advance!

Posted (edited)
7 hours ago, chubel10 said:

Thank you for providing some code! But how did you deal with the obfuscated names? Like did you climb definitions until you reached a method without obfuscated names in order to understand it?

I used an assortment of guessing, looking at vanilla usage, and looking at the code in the obfuscated method (I didn't realize the MCP names were in place in the latest version at that time).

 

7 hours ago, chubel10 said:

How could I go about updating my forge? do I have to do the whole setup thing again and copy my code or is there some fancy terminal code that I should learn?

AFAIK the only thing that changes across minor versions is the build.gradle file. To update, simply download the newest mdk, replace your  build.gradle with the new one, and edit it to fit your need (add mod id, dependencies, etc). Make sure to re-import the workspace after that.

Edited by DavidM
  • Like 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
On 4/22/2020 at 10:32 PM, DavidM said:

Model controls the entity's appearance; it doesn't control the collision box

Sorry, just one last question. Where can I change this collision box?

  • chubel10 changed the title to [Solved][1.15.2] Help with entity renderers
Posted (edited)

searched a while but here

 

for the hitbox/collision box:

needs to be in your entity.java

@Override

public float getRenderScale() {

return this.isChild() ? 0.75F : 1.8F; }

 

Edited by talhanation

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.