Markolo Posted September 2, 2014 Posted September 2, 2014 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 Reveal hidden contents @Override public void registerRenderers() { ClientRegistry.bindTileEntitySpecialRenderer(FrictionEntity.class, new FrictionRender()); } Mod File Reveal hidden contents 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 Reveal hidden contents 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 Reveal hidden contents 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); } Quote
Vinther Posted September 2, 2014 Posted September 2, 2014 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. Quote
Markolo Posted September 2, 2014 Author Posted September 2, 2014 On 9/2/2014 at 8:53 PM, Vinther said: 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 Quote
TheGreyGhost Posted September 3, 2014 Posted September 3, 2014 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 Quote
sequituri Posted September 3, 2014 Posted September 3, 2014 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... Quote -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
Markolo Posted September 3, 2014 Author Posted September 3, 2014 On 9/3/2014 at 12:44 AM, TheGreyGhost said: 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 Quote
Recommended Posts
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.