Jump to content

Recommended Posts

Posted

Hello. I have a big problem. I'made a tile entity block with special renderer, and if i place even one (sic!) block and do absolutely nothing, it start devouring more and more memory until the game crashes with "Out of memory" notification.

Is there any solution of this problem?

My code:

 

TESR

package net.row.src.client.renderer.tileentity;

import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.row.src.RoW;
import net.row.src.client.model.rail.ModelRailRight;
import net.row.src.client.model.rail.ModelRailX01;
import net.row.src.client.model.rail.ModelRailX05;
import net.row.src.client.model.rail.ModelRailX10;
import net.row.src.tileentity.TileEntityWideRail;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class TileEntityWideRailRenderer extends TileEntitySpecialRenderer {
    
protected ModelBase model;

    public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f){
        GL11.glPushMatrix();
        GL11.glTranslatef((float)d, (float)d1, (float)d2);
        TileEntityWideRail tile = (TileEntityWideRail)tileentity;
        if(tile != null){
        	renderBlockRail(tile, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, RoW.rails);
        }
        GL11.glPopMatrix();
    } 
    public void renderBlockRail(TileEntityWideRail tileEntity, World world, int i, int j, int k, Block block){
    	Tessellator tessellator = Tessellator.instance;
    	float f = block.getBlockBrightness(world, i, j, k);
        int l = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
        int l1 = l % 65536;
        int l2 = l / 65536;
        tessellator.setColorOpaque_F(f, f, f);
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)l1, (float)l2); 
        int dir = world.getBlockMetadata(i, j, k);
        if(tileEntity != null){
        	switch (tileEntity.mId){
        		default: bindTextureByName("/mods/RoW/textures/rails/rails_1.png");
        		model = new ModelRailX01();	break;
        		case 1:  bindTextureByName("/mods/RoW/textures/rails/rails_5.png");
        		model = new ModelRailX05();	break;
        		case 2:  bindTextureByName("/mods/RoW/textures/rails/rails_10.png");
        		model = new ModelRailX10();break;
        		case 3:  bindTextureByName("/mods/RoW/textures/rails/rails_right.png");
        		model = new ModelRailRight();break;
        		case 4:  bindTextureByName("/mods/RoW/textures/rails/rails_left.png");
        		model = new ModelRailRight();break;
        	}
        	GL11.glPushMatrix();
        		GL11.glTranslatef(0.5F, 0F, 0.5F);
        		GL11.glRotatef(dir * (-90F), 0F, 1F, 0F);
        		GL11.glTranslatef(0.0F, 0F, -0.5F);
        		GL11.glScalef(-1.0F, -1.0F, 1.0F);
        		model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        	GL11.glPopMatrix();
        }
    }

}

One of my models

package net.row.src.client.model.rail;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

@SideOnly(Side.CLIENT)
public class ModelRailX01 extends ModelBase
{
    ModelRenderer Sleeper1;
    ModelRenderer Sleeper2;
    ModelRenderer Foot1;
    ModelRenderer Foot2;
    ModelRenderer Web1;
    ModelRenderer Web2;
    ModelRenderer Head1;
    ModelRenderer Head2;
  
  public ModelRailX01()
  {
    textureWidth = 128;
    textureHeight = 32;
    
      Sleeper1 = new ModelRenderer(this, 0, 0);
      Sleeper1.addBox(-20F, -1F, 2F, 40, 2, 4);
      Sleeper1.setRotationPoint(0F, -1F, 0F);
      Sleeper1.setTextureSize(128, 32);
      Sleeper1.mirror = true;
      setRotation(Sleeper1, 0F, 0F, 0F);
      Sleeper2 = new ModelRenderer(this, 0, 6);
      Sleeper2.addBox(-20F, -1F, 10F, 40, 2, 4);
      Sleeper2.setRotationPoint(0F, -1F, 0F);
      Sleeper2.setTextureSize(128, 32);
      Sleeper2.mirror = true;
      setRotation(Sleeper2, 0F, 0F, 0F);
      Foot1 = new ModelRenderer(this, 0, 12);
      Foot1.addBox(0F, 0F, -3F, 16, 1, 6);
      Foot1.setRotationPoint(-13F, -3F, 0F);
      Foot1.setTextureSize(128, 32);
      Foot1.mirror = true;
      setRotation(Foot1, 0F, -1.570796F, 0F);
      Foot2 = new ModelRenderer(this, 0, 19);
      Foot2.addBox(0F, 0F, -3F, 16, 1, 6);
      Foot2.setRotationPoint(13F, -3F, 0F);
      Foot2.setTextureSize(128, 32);
      Foot2.mirror = true;
      setRotation(Foot2, 0F, -1.570796F, 0F);
      Web1 = new ModelRenderer(this, 44, 18);
      Web1.addBox(0F, -1F, -0.5F, 16, 2, 1);
      Web1.setRotationPoint(-13F, -4F, 0F);
      Web1.setTextureSize(128, 32);
      Web1.mirror = true;
      setRotation(Web1, 0F, -1.570796F, 0F);
      Web2 = new ModelRenderer(this, 44, 21);
      Web2.addBox(0F, -1F, -0.5F, 16, 2, 1);
      Web2.setRotationPoint(13F, -4F, 0F);
      Web2.setTextureSize(128, 32);
      Web2.mirror = true;
      setRotation(Web2, 0F, -1.570796F, 0F);
      Head1 = new ModelRenderer(this, 44, 12);
      Head1.addBox(0F, 0F, -1F, 16, 1, 2);
      Head1.setRotationPoint(-13F, -6F, 0F);
      Head1.setTextureSize(128, 32);
      Head1.mirror = true;
      setRotation(Head1, 0F, -1.570796F, 0F);
      Head2 = new ModelRenderer(this, 44, 15);
      Head2.addBox(0F, 0F, -1F, 16, 1, 2);
      Head2.setRotationPoint(13F, -6F, 0F);
      Head2.setTextureSize(128, 32);
      Head2.mirror = true;
      setRotation(Head2, 0F, -1.570796F, 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, entity);
    Sleeper1.render(f5);
    Sleeper2.render(f5);
    Foot1.render(f5);
    Foot2.render(f5);
    Web1.render(f5);
    Web2.render(f5);
    Head1.render(f5);
    Head2.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, Entity entity)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  }

}

 

Help please?

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted

You're creating a new model every frame and never releasing them.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.