Jump to content

Custom Tile Entity Renderer statically linked between models?


Markolo

Recommended Posts

For some reason, all of my Tile Entities are using the same model animation. I looked through and I couldn't find anything statically linked. I'm probably derping hard and could use some help please. I have searched all around the internet, without the slightest clue. I am fairly new to Forge(As well as Java), so please go easy on me.<3 I'm just trying my best to learn the API and stuff.

 

ClientProxy

 

 

@Override

    public void registerRenderers() {

    ClientRegistry.bindTileEntitySpecialRenderer(FrictionEntity.class, new FrictionRender());

    }

 

 

 

Mod File

 

 

public static CommonProxy proxy;

     

public Block Friction;

 

      @EventHandler

      public void preInit(FMLPreInitializationEvent event) {

      Friction = new Friction();

      GameRegistry.registerBlock(Friction, "Friction");

      }

 

      @EventHandler

      public void load(FMLInitializationEvent event) {

              proxy.registerRenderers();

              GameRegistry.registerTileEntity(FrictionEntity.class, "FrictionEntity");

      }

 

 

 

Renderer

 

 

public class FrictionRender extends TileEntitySpecialRenderer{

 

private static final ResourceLocation res = new ResourceLocation("demonology:textures/model/friction.png");

private FrictionModel model;

 

public FrictionRender(){

this.model = new FrictionModel();

}

 

@Override

public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {

FrictionEntity entity = (FrictionEntity) tileentity;

        GL11.glPushMatrix();

        GL11.glTranslatef((float)x, (float)y, (float)z);

        GL11.glTranslatef(0.5F, 1.5F, 0.5F);

       

        Minecraft.getMinecraft().renderEngine.bindTexture(res);

 

        GL11.glPushMatrix();

        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

        GL11.glRotatef(entity.direction * 90, 0.0F, 1.0F, 0.0F);

        model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

       

        if(entity.on){

        entity.ballX += 0.1;

        this.model.Ball.offsetX = entity.ballX;

        }

       

        GL11.glPopMatrix();

        GL11.glPopMatrix();

}

 

 

 

Model

 

 

public class FrictionModel extends ModelBase{

    ModelRenderer Base;

    ModelRenderer Roof;

    ModelRenderer RightSide;

    ModelRenderer LeftSide;

    ModelRenderer Ball;

    ModelRenderer Pipe;

 

  public FrictionModel(){

    textureWidth = 128;

    textureHeight = 128;

   

      Base = new ModelRenderer(this, 0, 0);

      Base.addBox(0F, 0F, 0F, 16, 1, 16);

      Base.setRotationPoint(-8F, 23F, -8F);

      Base.setTextureSize(128, 128);

      Base.mirror = true;

      setRotation(Base, 0F, 0F, 0F);

      Roof = new ModelRenderer(this, 0, 0);

      Roof.addBox(0F, 0F, 0F, 16, 1, 16);

      Roof.setRotationPoint(-8F, 8F, -8F);

      Roof.setTextureSize(128, 128);

      Roof.mirror = true;

      setRotation(Roof, 0F, 0F, 0F);

      RightSide = new ModelRenderer(this, 0, 19);

      RightSide.addBox(0F, 0F, 0F, 1, 14, 16);

      RightSide.setRotationPoint(-8F, 9F, -8F);

      RightSide.setTextureSize(128, 128);

      RightSide.mirror = true;

      setRotation(RightSide, 0F, 0F, 0F);

      LeftSide = new ModelRenderer(this, 0, 19);

      LeftSide.addBox(0F, 0F, 0F, 1, 14, 16);

      LeftSide.setRotationPoint(7F, 9F, -8F);

      LeftSide.setTextureSize(128, 128);

      LeftSide.mirror = true;

      setRotation(LeftSide, 0F, 0F, 0F);

      Ball = new ModelRenderer(this, 66, 0);

      Ball.addBox(0F, 0F, 0F, 4, 4, 4);

      Ball.setRotationPoint(-2F, 19F, -2F);

      Ball.setTextureSize(128, 128);

      Ball.mirror = true;

      setRotation(Ball, 0F, 0F, 0F);

      Pipe = new ModelRenderer(this, 84, 5);

      Pipe.addBox(0F, 0F, 0F, 6, 6, 16);

      Pipe.setRotationPoint(-3F, 13F, -8F);

      Pipe.setTextureSize(128, 128);

      Pipe.mirror = true;

      setRotation(Pipe, 0F, 0F, 0F);

  }

 

  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5){

  super.render(entity, f, f1, f2, f3, f4, f5);

  setRotationAngles(f, f1, f2, f3, f4, f5);

  Base.render(f5);

  Roof.render(f5);

  RightSide.render(f5);

  LeftSide.render(f5);

  Ball.render(f5);

  Pipe.render(f5);

  }

 

  private void setRotation(ModelRenderer model, float x, float y, float z){

    model.rotateAngleX = x;

    model.rotateAngleY = y;

    model.rotateAngleZ = z;

  }

 

  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5){

    super.setRotationAngles(f, f1, f2, f3, f4, f5, null);

  }

 

  public void renderModel(float f5){

  Base.render(f5);

  Roof.render(f5);

  RightSide.render(f5);

  LeftSide.render(f5);

  Ball.render(f5);

  Pipe.render(f5);

  }

 

 

Link to comment
Share on other sites

I can't be entirely sure as I've not messed around with this kind of stuff enough, but I would say it's most likely using only one instance of the renderer for all TileEntities of the same type.

 

So you should store any animation state data in the entity itself.

Link to comment
Share on other sites

I can't be entirely sure as I've not messed around with this kind of stuff enough, but I would say it's most likely using only one instance of the renderer for all TileEntities of the same type.

 

So you should store any animation state data in the entity itself.

Thank you for replying! But i've sadly tried that and it still renders all the same. :c
Link to comment
Share on other sites

Post your code?

 

I gather by "animation" you mean the model "ball X offset position"

 

Vinther is right, you have only one instance of FrictionRender, so when you change its model animation during one call to renderTileEntityAt(), it affects other TileEntities, since you update your this.model.Ball.offsetX after the model render not before.  Although, that would just make the animation wrong, not the same for all TileEntities, so I'm not certain I have understood the symptoms properly.

 

I also think it's a bad idea to update the animation in renderTileEntityAt(), i.e.

 

entity.ballX += 0.1;

 

As the framerate changes, the animation speed will change too (and will be jerky).

 

Much better to either update the animation parameters in the TileEntity tick update (fixed at 20 ticks per second), or to calculate the animation from the system time eg System.nanoTime.

 

for example

 

in updateEntity()

 

ballX += BALL_X_CHANGE_PER_TICK;

 

 

or in renderTileEntityAt()

 

final double BALL_X_SPEED = 1.0;  // metres per second
final double NS_PER_SECOND = 1e9;
ballX = ballStartX + BALL_X_SPEED * System.nanoTime() / NS_PER_SECOND;

The major difference is whether the animation continues while the game is paused or not.

 

-TGG

Link to comment
Share on other sites

If I remember correctly, the float f parameter to renderTileEntityAt(...) gives the partial ticks that occurred since last call. This number is used to determined animation motion interpolation in most renderers. You should not have to use nanotime. You can if you want to, that a matter of taste.

Mostly I have seen mojang use two variable for last position, and net tick position (computed on the server side) and the client uses partial tick to determine the interpolated animation reference. Last + (Next - Last)/ partialTicks = Current...

Link to comment
Share on other sites

Post your code?

 

I gather by "animation" you mean the model "ball X offset position"

 

Vinther is right, you have only one instance of FrictionRender, so when you change its model animation during one call to renderTileEntityAt(), it affects other TileEntities, since you update your this.model.Ball.offsetX after the model render not before.  Although, that would just make the animation wrong, not the same for all TileEntities, so I'm not certain I have understood the symptoms properly.

 

I also think it's a bad idea to update the animation in renderTileEntityAt(), i.e.

 

entity.ballX += 0.1;

 

As the framerate changes, the animation speed will change too (and will be jerky).

 

Much better to either update the animation parameters in the TileEntity tick update (fixed at 20 ticks per second), or to calculate the animation from the system time eg System.nanoTime.

 

for example

 

in updateEntity()

 

ballX += BALL_X_CHANGE_PER_TICK;

 

 

or in renderTileEntityAt()

 

final double BALL_X_SPEED = 1.0;  // metres per second
final double NS_PER_SECOND = 1e9;
ballX = ballStartX + BALL_X_SPEED * System.nanoTime() / NS_PER_SECOND;

The major difference is whether the animation continues while the game is paused or not.

 

-TGG

Hello, thank you for your reply. You make a valid point. However, I have already tried using it inside of my Entity.... Still renders the same as other models. I know the float is relative to time and "entity.ballX += 0.1;" is just used to test to see if they render the same/differently. But of course, i'll try it again and see if I can get it working again. Thank you again though. <3
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.