Jump to content

Entity render a few tick and then disappear


zerozhou

Recommended Posts

I'm doing the render things. Don't know why after the entity spawn, the render rendered for a few ticks and didn't work.... The render is not called after the first few ticks.

code is like

The entity

private int livetime;
public EntityMagicRenderTest(World par1World, double x, double y, double z) {
	super(par1World);
	this.setPosition(x,y,z);
	livetime = 200;
}
public EntityMagicRenderTest(World par1World, double x, double y, double z, int deadline) {
	super(par1World);
	this.setPosition(x,y,z);
	livetime = deadline;
}

public EntityMagicRenderTest(World par1World) {
	super(par1World);
}
@Override
protected void entityInit() {
}

@Override
public void onUpdate() {
	super.onUpdate();
	--livetime;
	if (livetime <= 0) {
		this.setDead();
	}
	//this.setPosition(this.posX, this.posY, this.posZ);

        
	if (!this.worldObj.isRemote && livetime % 20 == 0) {
		System.out.println("livetime = " + livetime);
		System.out.println(this.posX + " " + this.posY + " " + this.posZ);
	}
}

 

the renderer:

 

	public void doRender(Entity entity, double d0, double d1, double d2,
		float f, float f1) {


	System.out.println("try render");

	GL11.glPushMatrix();
	bindEntityTexture(entity);
        GL11.glTranslatef((float)d0, (float)d1, (float)d2);


	GL11.glRotatef(180F -renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
    	GL11.glRotatef(-renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
    	
        Tessellator t = Tessellator.instance;
        t.startDrawingQuads();
        t.setNormal(0, 0, 0);
        
        t.addVertexWithUV(-0.5, -0.5, 0.0, 0, 0);
        t.addVertexWithUV(-0.5, 0.5, 0.0, 0, 1);
        t.addVertexWithUV(0.5, 0.5, 0.0, 0.5, 1);
        t.addVertexWithUV(0.5, -0.5, 0.0, 0.5, 0);
        
        t.addVertexWithUV(-0.5, -0.5, 0.0, 0, 0);
        t.addVertexWithUV(0.5, -0.5, 0.0, 0.5, 0);
        t.addVertexWithUV(0.5, 0.5, 0.0, 0.5, 1);
        t.addVertexWithUV(-0.5, 0.5, 0.0, 0, 1);
        
        t.draw();
        
        GL11.glPopMatrix();
}

 

I've successed for a time.. But suddenly it didnt work again..

Link to comment
Share on other sites

well to me that seems normal as you have a liveTime variable and you kill your entity when its under 0, maybe i missed something,

 

does it stop rendering BEFORE it dies ?

 

remember that server and client are 2 different program, maybe if youre testing with an actual client + server the server tick faster then the client or vice versa so there is a desynchronisation, in this case i would recommend DataWatching your livetime

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

I'm new to render. So it's just for test so I simply set the livetime. I know the difference between the client and the server.

 

And yes, it stop rendering BEFORE it die as I could see messages in the onUpdate() method of the entity.

 

And I try to delete "--livetime;". But nothing change. The "rendered entity" appear 2-3 ticks and then disappear while the entity is still alive.

Link to comment
Share on other sites

I use a item and spawn it in the position where the player stand. And as there is almost nothing in the entity, I don't know if I can hit it, I'll try later. In my success case I try to make it move and succeed, and now I delete the code about its movement, so I think it could not move extremmelly far.

Link to comment
Share on other sites

I think the client's livetime variable is never set so it stays at 0. Then in the update method this line will (also) trigger on the client:

if (livetime <= 0) {
		this.setDead();
	}

 

Solution would be to add a server check:

if (!worldObj.isRemote && livetime <= 0) {
		this.setDead();
	}

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

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.