Jump to content

Recommended Posts

Posted

I am working on a new block which uses ISimpleBlockRenderingHandler and this one is having issues.

 

For some reason it is pulling in textures from other blocks and not using the textures I have for it at all.

I am not really sure what is going on but here is a picture.

TgCVHXb.png

 

I'm pretty sure it has something to do with these lines.

Tessellator tessellator = Tessellator.instance;
	IIcon k = block.getIcon(0, i);

	if (overrideBlockTexture != null) {
		k = overrideBlockTexture;
	}

	double d3 = (double) k.getMinU();
	double d4 = (double) k.getMinV();
	double d5 = (double) k.getMaxU();
	double d6 = (double) k.getMaxV();

 

But here is the whole file just in case.

 

package grim3212.mc.spikes;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class RenderSpike implements ISimpleBlockRenderingHandler {

@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
	if (modelId == Spikes.spikeRenderID && block == Spikes.spike) {
		Tessellator tessellator = Tessellator.instance;
		float f = block.getMixedBrightnessForBlock(world, x, y, z);
		tessellator.setColorOpaque_F(f, f, f);
		renderSpike((BlockSpike) block, world.getBlockMetadata(x, y, z), x, y, z, renderer.overrideBlockTexture);
		return true;
	} else {
		return false;
	}
}

@Override
public boolean shouldRender3DInInventory(int modelId) {
	return false;
}

@Override
public int getRenderId() {
	return Spikes.spikeRenderID;
}

public static void renderSpike(BlockSpike block, int i, double d, double d1, double d2, IIcon overrideBlockTexture) {
	Tessellator tessellator = Tessellator.instance;
	IIcon k = block.getIcon(0, i);

	if (overrideBlockTexture != null) {
		k = overrideBlockTexture;
	}

	double d3 = (double) k.getMinU();
	double d4 = (double) k.getMinV();
	double d5 = (double) k.getMaxU();
	double d6 = (double) k.getMaxV();
	if (i == 6 || i == 12 || i == 4 || i == 10 || i == 2 || i ==  {
		double d7 = 0.0D;
		d7 = d3;
		d3 = d4;
		d4 = d7;
		d7 = d5;
		d5 = d6;
		d6 = d7;
	}
	double d8 = (d + 0.5D) - 0.44999998807907104D;
	double d9 = d + 0.5D + 0.44999998807907104D;
	double d10 = (d2 + 0.5D) - 0.44999998807907104D;
	double d11 = d2 + 0.5D + 0.44999998807907104D;
	double d12 = (d1 + 0.5D) - 0.44999998807907104D;
	double d13 = d1 + 0.5D + 0.44999998807907104D;
	if (i == 1 || i == 6 || i == 7 || i == 12) {
		tessellator.addVertexWithUV(d8, d1 + 1.0D, d10, d3, d5);
		tessellator.addVertexWithUV(d8, d1 + 0.0D, d10, d3, d6);
		tessellator.addVertexWithUV(d9, d1 + 0.0D, d11, d4, d6);
		tessellator.addVertexWithUV(d9, d1 + 1.0D, d11, d4, d5);
		tessellator.addVertexWithUV(d9, d1 + 1.0D, d11, d3, d5);
		tessellator.addVertexWithUV(d9, d1 + 0.0D, d11, d3, d6);
		tessellator.addVertexWithUV(d8, d1 + 0.0D, d10, d4, d6);
		tessellator.addVertexWithUV(d8, d1 + 1.0D, d10, d4, d5);
		tessellator.addVertexWithUV(d8, d1 + 1.0D, d11, d3, d5);
		tessellator.addVertexWithUV(d8, d1 + 0.0D, d11, d3, d6);
		tessellator.addVertexWithUV(d9, d1 + 0.0D, d10, d4, d6);
		tessellator.addVertexWithUV(d9, d1 + 1.0D, d10, d4, d5);
		tessellator.addVertexWithUV(d9, d1 + 1.0D, d10, d3, d5);
		tessellator.addVertexWithUV(d9, d1 + 0.0D, d10, d3, d6);
		tessellator.addVertexWithUV(d8, d1 + 0.0D, d11, d4, d6);
		tessellator.addVertexWithUV(d8, d1 + 1.0D, d11, d4, d5);
	} else if (i == 4 || i == 10 || i == 5 || i == 11) {
		tessellator.addVertexWithUV(d + 1.0D, d12, d10, d3, d5);
		tessellator.addVertexWithUV(d + 0.0D, d12, d10, d3, d6);
		tessellator.addVertexWithUV(d + 0.0D, d13, d11, d4, d6);
		tessellator.addVertexWithUV(d + 1.0D, d13, d11, d4, d5);
		tessellator.addVertexWithUV(d + 1.0D, d13, d11, d3, d5);
		tessellator.addVertexWithUV(d + 0.0D, d13, d11, d3, d6);
		tessellator.addVertexWithUV(d + 0.0D, d12, d10, d4, d6);
		tessellator.addVertexWithUV(d + 1.0D, d12, d10, d4, d5);
		tessellator.addVertexWithUV(d + 1.0D, d12, d11, d3, d5);
		tessellator.addVertexWithUV(d + 0.0D, d12, d11, d3, d6);
		tessellator.addVertexWithUV(d + 0.0D, d13, d10, d4, d6);
		tessellator.addVertexWithUV(d + 1.0D, d13, d10, d4, d5);
		tessellator.addVertexWithUV(d + 1.0D, d13, d10, d3, d5);
		tessellator.addVertexWithUV(d + 0.0D, d13, d10, d3, d6);
		tessellator.addVertexWithUV(d + 0.0D, d12, d11, d4, d6);
		tessellator.addVertexWithUV(d + 1.0D, d12, d11, d4, d5);
	} else if (i == 2 || i == 8 || i == 3 || i == 9) {
		tessellator.addVertexWithUV(d8, d12, d2 + 1.0D, d3, d5);
		tessellator.addVertexWithUV(d8, d12, d2 + 0.0D, d3, d6);
		tessellator.addVertexWithUV(d9, d13, d2 + 0.0D, d4, d6);
		tessellator.addVertexWithUV(d9, d13, d2 + 1.0D, d4, d5);
		tessellator.addVertexWithUV(d9, d13, d2 + 1.0D, d3, d5);
		tessellator.addVertexWithUV(d9, d13, d2 + 0.0D, d3, d6);
		tessellator.addVertexWithUV(d8, d12, d2 + 0.0D, d4, d6);
		tessellator.addVertexWithUV(d8, d12, d2 + 1.0D, d4, d5);
		tessellator.addVertexWithUV(d8, d13, d2 + 1.0D, d3, d5);
		tessellator.addVertexWithUV(d8, d13, d2 + 0.0D, d3, d6);
		tessellator.addVertexWithUV(d9, d12, d2 + 0.0D, d4, d6);
		tessellator.addVertexWithUV(d9, d12, d2 + 1.0D, d4, d5);
		tessellator.addVertexWithUV(d9, d12, d2 + 1.0D, d3, d5);
		tessellator.addVertexWithUV(d9, d12, d2 + 0.0D, d3, d6);
		tessellator.addVertexWithUV(d8, d13, d2 + 0.0D, d4, d6);
		tessellator.addVertexWithUV(d8, d13, d2 + 1.0D, d4, d5);
	}
}
}

 

Thanks

 

EDIT:

 

This has been solved

 

This

double d3 = (double) k.getMinU();
double d4 = (double) k.getMinV();
double d5 = (double) k.getMaxU();
double d6 = (double) k.getMaxV();

 

Should be like this... I had them flipped around.

double d3 = (double) k.getMinU();
double d4 = (double) k.getMaxU();
double d5 = (double) k.getMinV();
double d6 = (double) k.getMaxV();

Posted

Hi

 

Dude, that code sure is hard to follow, couldn't you name the variables something meaningful? :-) 

 

What texture do you want it to use?  The standard block textures are all stitched together in a big single texture, so if you are using an icon on a different texture sheet which has a different number of items, the boundaries won't match up.

 

Are you sure that the Tessellator is bound to the correct texture sheet?  How did you register your texture (icons)?

 

I'm pretty sure you already know about the Tessellator, but just in case you don't this link might be helpful

http://greyminecraftcoder.blogspot.com.au/2013/08/the-tessellator.html

 

This one on lighting might be useful too, since I don't think that this code will do what you expect:

			float f = block.getMixedBrightnessForBlock(world, x, y, z);
		tessellator.setColorOpaque_F(f, f, f);

http://greyminecraftcoder.blogspot.com.au/2013/08/lighting.html

-TGG

Posted

Alright, I am really sorry about the code. I should have cleaned it up before I was asking for help but I totally forgot.

 

Anyway I ended up solving it.

 

These

double d3 = (double) k.getMinU();
double d4 = (double) k.getMinV();
double d5 = (double) k.getMaxU();
double d6 = (double) k.getMaxV();

 

Should be like this... I had them flipped around.

double d3 = (double) k.getMinU();
double d4 = (double) k.getMaxU();
double d5 = (double) k.getMinV();
double d6 = (double) k.getMaxV();

 

But I did look into the lighting like you said and you were right... It was not doing what I wanted so I now have that working too.

 

But everything is now fixed so thank you!

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.