Jump to content

Random Render Brightness and Entities float away! Help! (Please :) )


Jamezo97

Recommended Posts

Hey guys,

I've been moving my mod from Risugami's modloader to forge. It's all been going great, and I'm beginning to love forge.

 

However I have a few bugs I can't seem to squish, I looked around, but couldn't find anything to fix them, I'm sure there are ways, so I'll ask here.

 

For one of my blocks, I have a custom TileEntity renderer, and in that I render the whole block just using the Tessellator class. It looks fine, however if you look at the block at certain angles, it goes really dark. I've tried everything to do with brightness and colour, but I just can't seem to fix it.

So does anyone know how to make sure the block stays a constant brightness. My code is here:

 

package net.minecraft.mypeople;

import java.util.Random;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;

import org.lwjgl.opengl.GL11;

public class TileEntityCentrifugeRenderer extends TileEntitySpecialRenderer{

static RenderItem itemRenderer = new RenderItem();

@Override
public void renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f) {
	this.renderCentrifuge((TileEntityCentrifuge)tileentity, d0, d1, d2, f);
}

public static void renderCentrifuge(TileEntityCentrifuge tec, double x, double y, double z, float f) {
	GL11.glPushMatrix();
	bind("/MyPeople/CentrifugeBlock.png");
	GL11.glDisable(GL11.GL_LIGHTING);
/*		Tessellator t = Tessellator.instance;
	t.setBrightness(983055);
	GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);*/
	GL11.glTranslated(x, y, z);
	renderBase();
	GL11.glTranslatef(.5f, .5f, .5f);
	GL11.glRotatef(tec != null?tec.getSpin(f):0, 0, 1, 0);
	GL11.glTranslatef(-.5f, -.5f, -.5f);
	renderSpin(tec);
	GL11.glEnable(GL11.GL_LIGHTING);
	GL11.glPopMatrix();
}

private static void renderSpin(TileEntityCentrifuge tec) {
	Tessellator t = Tessellator.instance;
	t.setColorRGBA(255, 255, 255, 255);
	t.setBrightness(145);
	//GL11.glDisable(GL11.GL_LIGHTING);
	drawPole(t);
	//GL11.glEnable(GL11.GL_LIGHTING);
	GL11.glDisable(GL11.GL_CULL_FACE);
	drawHoldersAndItems(t, tec);
	GL11.glEnable(GL11.GL_CULL_FACE);
}

public static void drawHoldersAndItems(Tessellator t, TileEntityCentrifuge tec){
	t.startDrawingQuads();
	t.addVertexWithUV(.125, .9375, .5625, .125, 0);
	t.addVertexWithUV(.875, .9375, .5625, .125, .875);
	t.addVertexWithUV(.875, .9375, .4375, 0, .875);
	t.addVertexWithUV(.125, .9375, .4375, 0, 0);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(.5625, .9376, .875, .125, 0);
	t.addVertexWithUV(.5625, .9376, .125, .125, .875);
	t.addVertexWithUV(.4375, .9376, .125, 0, .875);
	t.addVertexWithUV(.4375, .9376, .875, 0, 0);
	t.draw();

	float angle = 0;
	ItemStack s1 = null, s2 = null, s3 = null, s4 = null;
	if(tec != null){
		angle = (tec.speed / ((float)tec.spinSpeedMax))*65f;
		s1 = tec.getStackInSlot(0);
		s2 = tec.getStackInSlot(1);
		s3 = tec.getStackInSlot(2);
		s4 = tec.getStackInSlot(3);
	}

	GL11.glPushMatrix();
	GL11.glTranslatef(.125f, .9375f, .5f);
	GL11.glRotatef(-angle, 0, 0, 1);
	t.startDrawingQuads();
	t.addVertexWithUV(0, 0, 0, 0, 0);
	t.addVertexWithUV(.0625, 0, 0, .0625, 0);
	t.addVertexWithUV(.0625, -.125, 0, .0625, .125);
	t.addVertexWithUV(0, -.125, 0, 0, .125);
	t.draw();
	if(s1 != null){
		GL11.glRotatef(90, 0, 1, 0);
		GL11.glScalef(.4f, .4f, .4f);
		GL11.glTranslatef(-.5f, -1.1f, .1f);
		renderItemstack(s1);
		bind("/MyPeople/CentrifugeBlock.png");
	}
	GL11.glPopMatrix();

	GL11.glPushMatrix();
	GL11.glTranslatef(.5f, .9375f, .875f);
	GL11.glRotatef(-angle, 1, 0, 0);
	t.startDrawingQuads();
	t.addVertexWithUV(0, 0, 0, 0, 0);
	t.addVertexWithUV(0, 0, -.0625, .0625, 0);
	t.addVertexWithUV(0, -.125, -.0625, .0625, .125);
	t.addVertexWithUV(0, -.125, 0, 0, .125);
	t.draw();
	if(s2 != null){
		GL11.glScalef(.4f, .4f, .4f);
		GL11.glTranslatef(-.5f, -1.1f, -.05f);
		renderItemstack(s2);
		bind("/MyPeople/CentrifugeBlock.png");
	}
	GL11.glPopMatrix();

	GL11.glPushMatrix();
	GL11.glTranslatef(.875f, .9375f, .5f);
	GL11.glRotatef(angle, 0, 0, 1);
	t.startDrawingQuads();
	t.addVertexWithUV(0, 0, 0, 0, 0);
	t.addVertexWithUV(-.0625, 0, 0, .0625, 0);
	t.addVertexWithUV(-.0625, -.125, 0, .0625, .125);
	t.addVertexWithUV(0, -.125, 0, 0, .125);
	t.draw();
	if(s3 != null){
		GL11.glRotatef(90, 0, 1, 0);
		GL11.glScalef(.4f, .4f, .4f);
		GL11.glTranslatef(-.5f, -1.1f, -.05f);
		renderItemstack(s3);
		bind("/MyPeople/CentrifugeBlock.png");
	}
	GL11.glPopMatrix();

	GL11.glPushMatrix();
	GL11.glTranslatef(.5f, .9375f, .125f);
	GL11.glRotatef(angle, 1, 0, 0);
	t.startDrawingQuads();
	t.addVertexWithUV(0, 0, 0, 0, 0);
	t.addVertexWithUV(0, 0, .0625, .0625, 0);
	t.addVertexWithUV(0, -.125, .0625, .0625, .125);
	t.addVertexWithUV(0, -.125, 0, 0, .125);
	t.draw();
	if(s4 != null){
		GL11.glScalef(.4f, .4f, .4f);
		GL11.glTranslatef(-.5f, -1.1f, .1f);
		renderItemstack(s4);
		bind("/MyPeople/CentrifugeBlock.png");
	}
	GL11.glPopMatrix();
}

public static void drawPole(Tessellator t){
	double top = .9375;


	t.startDrawingQuads();
	t.addVertexWithUV(.4375, top, .4375, .5, 0);
	t.addVertexWithUV(.5625, top, 0.4375, .625, 0);
	t.addVertexWithUV(.5625, .125, 0.4375, .625, .75);
	t.addVertexWithUV(.4375, .125, .4375, .5, .75);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(.5625, top, 0.5625, .5, 0);
	t.addVertexWithUV(.4375, top, .5625, .625, 0);
	t.addVertexWithUV(.4375, .125, .5625, .625, .75);
	t.addVertexWithUV(.5625, .125, 0.5625, .5, .75);
	t.draw();

	t.startDrawingQuads();
	t.addVertexWithUV(.4375, top, .5625, .5, 0);
	t.addVertexWithUV(.4375, top, .4375, .625, 0);
	t.addVertexWithUV(.4375, .125, .4375, .625, .75);
	t.addVertexWithUV(.4375, .125, .5625, .5, .75);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(.5625, top, .4375, .5, 0);
	t.addVertexWithUV(.5625, top, .5625, .625, 0);
	t.addVertexWithUV(.5625, .125, .5625, .625, .75);
	t.addVertexWithUV(.5625, .125, .4375, .5, .75);
	t.draw();
}

public static void renderBase(){
	Tessellator t = Tessellator.instance;
	drawEnds(t);
	drawTops(t);
	drawSides(t);
}

public static void drawSides(Tessellator t){
	t.startDrawingQuads();
	t.addVertexWithUV(.375, .125, 1, .125, 0);
	t.addVertexWithUV(.375, .125, 0, .125, 1);
	t.addVertexWithUV(.375, 0, 0, 0, 1);
	t.addVertexWithUV(.375, 0, 1, 0, 0);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(.625, .125, 0, .125, 0);
	t.addVertexWithUV(.625, .125, 1, .125, 1);
	t.addVertexWithUV(.625, 0, 1, 0, 1);
	t.addVertexWithUV(.625, 0, 0, 0, 0);
	t.draw();


	t.startDrawingQuads();
	t.addVertexWithUV(0, .125, .375, .125, 0);
	t.addVertexWithUV(1, .125, .375, .125, 1);
	t.addVertexWithUV(1, 0, .375, 0, 1);
	t.addVertexWithUV(0, 0, .375, 0, 0);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(1, .125, .625, .125, 0);
	t.addVertexWithUV(0, .125, .625, .125, 1);
	t.addVertexWithUV(0, 0, .625, 0, 1);
	t.addVertexWithUV(1, 0, .625, 0, 0);
	t.draw();



}

public static void drawTops(Tessellator t){
	t.startDrawingQuads();
	t.addVertexWithUV(.375, .125, 0, 0, 1);
	t.addVertexWithUV(.375, .125, 1, 0, 0);
	t.addVertexWithUV(.625, .125, 1, .25, 0);
	t.addVertexWithUV(.625, .125, 0, .25, 1);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(0, .125, .625, .25, 1);
	t.addVertexWithUV(1, .125, .625, .25, 0);
	t.addVertexWithUV(1, .125, .375, .5, 0);
	t.addVertexWithUV(0, .125, .375, .5, 1);
	t.draw();

	t.startDrawingQuads();
	t.addVertexWithUV(.375, 0, 1, 0, 1);
	t.addVertexWithUV(.375, 0, 0, 0, 0);
	t.addVertexWithUV(.625, 0, 0, .25, 0);
	t.addVertexWithUV(.625, 0, 1, .25, 1);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(1, 0, .625, .25, 1);
	t.addVertexWithUV(0, 0, .625, .25, 0);
	t.addVertexWithUV(0, 0, .375, .5, 0);
	t.addVertexWithUV(1, 0, .375, .5, 1);

	t.draw();
}

public static void drawEnds(Tessellator t){
	t.startDrawingQuads();
	t.addVertexWithUV(.375, 0, 0, 0, 1);
	t.addVertexWithUV(.375, .125, 0, 0, .875);
	t.addVertexWithUV(.625, .125, 0, .25, .875);
	t.addVertexWithUV(.625, 0, 0, .25, 1);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(.375, .125, 1, 0, 1);
	t.addVertexWithUV(.375, 0, 1, 0, .875);
	t.addVertexWithUV(.625, 0, 1, .25, .875);
	t.addVertexWithUV(.625, .125, 1, .25, 1);
	t.draw();

	t.startDrawingQuads();
	t.addVertexWithUV(1, 0, .375, 0, 1);
	t.addVertexWithUV(1, .125, .375, 0, .875);
	t.addVertexWithUV(1, .125, .625, .25, .875);
	t.addVertexWithUV(1, 0, .625, .25, 1);
	t.draw();
	t.startDrawingQuads();
	t.addVertexWithUV(0, .125, .375, 0, 1);
	t.addVertexWithUV(0, 0, .375, 0, .875);
	t.addVertexWithUV(0, 0, .625, .25, .875);
	t.addVertexWithUV(0, .125, .625, .25, 1);
	t.draw();
}

public static void renderItemstack(ItemStack stack){
	Icon ico = stack.getItem().getIconIndex(stack);
	float f12 = 0.0625F;
        if (stack.func_94608_d() == 0)
        {
            bind("/terrain.png");
        }
        else
        {
            bind("/gui/items.png");
        }
        int colour = stack.getItem().getColorFromItemStack(stack, 0);
        int red = (colour >> 16) & 0xff;
        int green = (colour >>  & 0xff;
        int blue = colour & 0xff;
        float redF = ((float)red)/255.0f;
        float greenF = ((float)green)/255.0f;
        float blueF = ((float)blue)/255.0f;
        GL11.glColor4f(redF, greenF, blueF, 1.0f);
        ItemRenderer.renderItemIn2D(Tessellator.instance, ico.func_94212_f(), ico.func_94206_g(), ico.func_94209_e(), ico.func_94210_h(), ico.func_94213_j(), ico.func_94208_k(), f12);
}

public static void bind(String s){
	if(RenderManager.instance != null && RenderManager.instance.renderEngine != null){
		RenderManager.instance.renderEngine.func_98187_b(s);
	}
}

}

 

I know my code is far from perfect. I probably should use a Model, however then I'd need to map out a texture file and stuff, and this works fine (kinda), so I'll just do it this way.

 

 

Anyway, the second one:

In my mod I have an entity called a 'clone' or a 'myperson'. However for some random reason, whenever you open up the world, or spawn the clone, they float away(well, walk, but it's not normal, they walk in a perfect straight line, and slowly slow down), and then once they move far enough away, they suddenly teleport back to their starting position (after about 4 seconds)

I've registered my entity like so:

		RenderingRegistry.registerEntityRenderingHandler(net.minecraft.mypeople.EntityMyPerson.class, new RenderMyPerson());

	EntityRegistry.registerGlobalEntityID(net.minecraft.mypeople.EntityMyPerson.class, "MyPerson", cloneID, 0x00afaf, 0x463aa5);

	EntityRegistry.registerModEntity(net.minecraft.mypeople.EntityMyPerson.class, "MyPerson", cloneID, this, 80, 3, false);

 

 

 

Have I missed anything I have to do? I kinda just guessed on how to get this working...

So yeah, any help is greatly appreciated. If I've left anything out, just ask and I'll tell.

 

Oh, and the floating away, is only happening on the client. I checked the motionX and motionZ for both the client and server, and the values only changed on the client..

 

Thankyou! :)

Link to comment
Share on other sites

What kind of entity code? My EntityMyPerson.class file is 1600 lines long.

It pretty much just extends the 'EntityLiving' class, has a few EntityAI tasks. But I really doubt that the issue is in my code. It worked perfectly fine with Risugami's modloader, and even when the mod was loaded with the forge Modloader instead of Risugami's, it worked fine. But now since I've used Forge's mod system, it's started doing this. And also, if it was my code, shouldn't it be happening on both the client side and the server? For it to only occur on the client, means that there is something funky going on with the spawning packets. Do I have to do anything for them?

 

And the brightness. If I render a block using the RenderBlocks class, the brightness is fine, but doing it straight through the tessellator gives me this bug, so I assume I'm just missing some code which sets the brightness. At the moment I've just disabled brightness when rendering my block...

 

 

Edit:

On second thoughts, maybe it is my code. Just made a test entity, and when I spawned it, it was perfectly fine...

 

Hmmm

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.