Jump to content

Recommended Posts

Posted

So I've cloned vanilla hoppers to a new format (unique logic to the automation process - I've added 3 slots that determine the "filter" of allowed items so as to remove the need for redstone in sorting. I am calling it a "filter." Novel name, right?) and I am curious: considering all I've done is a simple cloning and Hoppers don't use traditional stand-alone renderers, what would be the simplest way to say... change the color? Is there some simple access to render-time and a hue modifier or something to that effect? I honestly don't feel that trying to port the rendering method(s) tucked away in the Block renderer to an ISBRH is worth it, so if there's not a superficial hack this thing is staying grey! I'm actually open to suggestions because all I need the modification for is to be able to visually discern which are hoppers and which are filters.

I'll need help, and I'll give help. Just ask, you know I will!

Posted

Just make a TileEntitySpecialRenderer implementing ISimpleBlockRenderingHandler and only use the renderWorldBlock() method. To render the block just call the renderBlockHopperMetadata() method in RenderBlocks. You can use the Tessellators instance to manipulate the colors it has a method to do so. Also make sure to only return true in renderWorldBlock() if you actually render something otherwise the game will crash. You might also have to bind the default block texture atlas first for the textures to work. You can use this line of code to do so:

Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);

 

Good Luck

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

The BlockRenderer uses a predefined texture, the Texture Atlas which is basically a huge texture containing all block textures. It then uses the UV coordinates given by the registered IIcon to find the hoppers texture on the atlas. Since these are hard-coded into the RenderBlocks class you cant change them. The only method to change the texture would be to render it dynamically (every frame) and manually bind a texture. But then you could also render a model without using RenderBlocks.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

Well thats the thing is I'm more of a logic programmer and haven't played with much rendering - MC or otherwise - so advice here can save me literally hours! I thought coming into it using the simple handler wouldn't be so simple, but I may give that a shot.

I'll need help, and I'll give help. Just ask, you know I will!

Posted
  On 9/28/2014 at 10:42 PM, Busti said:

The BlockRenderer uses a predefined texture, the Texture Atlas which is basically a huge texture containing all block textures. It then uses the UV coordinates given by the registered IIcon to find the hoppers texture on the atlas. Since these are hard-coded into the RenderBlocks class you cant change them. The only method to change the texture would be to render it dynamically (every frame) and manually bind a texture. But then you could also render a model without using RenderBlocks.

 

See, the first part of your reply is why I thought it would be more involved, like copying the code over and converting to tesselators or wahtever... and the second part is what i dont want to try! But yoi convinced me to try the ISBRH.

I'll need help, and I'll give help. Just ask, you know I will!

Posted

Okay, I have to play the noob here...

 

public class FilterRenderer extends TileEntitySpecialRenderer 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) {		

	// i'm not sure what the last boolean is... 50/50 chance!
	Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
	return renderer.renderBlockHopperMetadata((BlockHopper)block, x, y, z, modelId, true);
}

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

@Override
public int getRenderId() {
	// ?
	return Block.getIdFromBlock(IShop.filter);
}

@Override
public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_,
		double p_147500_4_, double p_147500_6_, float p_147500_8_) {
	// it made me implement this.... what to do?
}

}

 

And I tried to register as such...

RenderingRegistry.registerBlockHandler(new FilterRenderer());

 

But how is it impelented? By the ID assignement? Or the render type in the Block class?

/**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return 38;
    }

 

Here's the whole block class just in case...

 

  Reveal hidden contents

 

I'll need help, and I'll give help. Just ask, you know I will!

Posted

O.K., I found this on the wiki, and found out how to register properly, which did actually kick it to the rendering class I made.

 

	IShop.filter.renderID = RenderingRegistry.getNextAvailableRenderId();
	RenderingRegistry.registerBlockHandler(IShop.filter.renderID, new FilterRenderer());

 

But then, this line had issue in that the Boolean set to false would ignore the blocks directional metadata, and set to true would through a render error that it was already tessellating:

 

return renderer.renderBlockHopperMetadata((BlockHopper)block, x, y, z, modelId, true);

 

So I changed it to

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
		Block block, int modelId, RenderBlocks renderer) {		

	// i'm not sure what the last boolean is... 50/50 chance!
	Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
	return renderer.renderBlockHopper((BlockHopper)block, x, y, z);
}

 

...and BOOM! Now to get the color change per your suggestion...

I'll need help, and I'll give help. Just ask, you know I will!

Posted

And the final version of my renderer, with the rendering from metadata method copied and cleaned up a bit, so I can play with the color. Note: it only changes the color of the inside of the hopper (which is fine enough for what I wanted) but its calling an IIcon which could easily enough be overridden if someone else finds this and needs to do that.

 

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
		Block block, int modelId, RenderBlocks renderer) {		

	Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
	return this.renderBlockHopperMetadata(renderer, (BlockHopper)block, x, y, z, renderer.blockAccess.getBlockMetadata(x, y, z), false);
}

public boolean renderBlockHopperMetadata(RenderBlocks renderer, BlockHopper p_147799_1_, int p_147799_2_, int p_147799_3_, int p_147799_4_, int p_147799_5_, boolean p_147799_6_) {
	Tessellator tessellator = Tessellator.instance;
	int i1 = BlockHopper.getDirectionFromMetadata(p_147799_5_);
	double d0 = 0.625D;
	renderer.setRenderBounds(0.0D, d0, 0.0D, 1.0D, 1.0D, 1.0D);

	renderer.renderStandardBlock(p_147799_1_, p_147799_2_, p_147799_3_, p_147799_4_);

	float f1;

	if (!p_147799_6_) {
		tessellator.setBrightness(p_147799_1_.getMixedBrightnessForBlock(renderer.blockAccess, p_147799_2_, p_147799_3_, p_147799_4_));
		int j1 = p_147799_1_.colorMultiplier(renderer.blockAccess, p_147799_2_, p_147799_3_, p_147799_4_);
		float f = (float) (j1 >> 16 & 255) / 255.0F;
		f1 = (float) (j1 >> 8 & 255) / 255.0F;
		float f2 = (float) (j1 & 255) / 255.0F;

		if (EntityRenderer.anaglyphEnable) {
			float f3 = (f * 30.0F + f1 * 59.0F + f2 * 11.0F) / 100.0F;
			float f4 = (f * 30.0F + f1 * 70.0F) / 100.0F;
			float f5 = (f * 30.0F + f2 * 70.0F) / 100.0F;
			f = f3;
			f1 = f4;
			f2 = f5;
		}

	}

	IIcon iicon = BlockHopper.getHopperIcon("hopper_outside");
	IIcon iicon1 = BlockHopper.getHopperIcon("hopper_inside");
	f1 = 0.125F;

	tessellator.setColorOpaque(150, 25, 25);

	renderer.renderFaceXPos(p_147799_1_, (double) ((float) p_147799_2_ - 1.0F + f1), (double) p_147799_3_, (double) p_147799_4_, iicon);
	renderer.renderFaceXNeg(p_147799_1_, (double) ((float) p_147799_2_ + 1.0F - f1), (double) p_147799_3_, (double) p_147799_4_, iicon);
	renderer.renderFaceZPos(p_147799_1_, (double) p_147799_2_, (double) p_147799_3_, (double) ((float) p_147799_4_ - 1.0F + f1), iicon);
	renderer.renderFaceZNeg(p_147799_1_, (double) p_147799_2_, (double) p_147799_3_, (double) ((float) p_147799_4_ + 1.0F - f1), iicon);
	renderer.renderFaceYPos(p_147799_1_, (double) p_147799_2_, (double) ((float) p_147799_3_ - 1.0F) + d0, (double) p_147799_4_, iicon1);

	renderer.setOverrideBlockTexture(iicon);
	double d3 = 0.25D;
	double d4 = 0.25D;
	renderer.setRenderBounds(d3, d4, d3, 1.0D - d3, d0 - 0.002D, 1.0D - d3);

	renderer.renderStandardBlock(p_147799_1_, p_147799_2_, p_147799_3_, p_147799_4_);

	if (!p_147799_6_) {
		double d1 = 0.375D;
		double d2 = 0.25D;
		renderer.setOverrideBlockTexture(iicon);

		if (i1 == 0) {
			renderer.setRenderBounds(d1, 0.0D, d1, 1.0D - d1, 0.25D, 1.0D - d1);
			renderer.renderStandardBlock(p_147799_1_, p_147799_2_, p_147799_3_, p_147799_4_);
		}

		if (i1 == 2) {
			renderer.setRenderBounds(d1, d4, 0.0D, 1.0D - d1, d4 + d2, d3);
			renderer.renderStandardBlock(p_147799_1_, p_147799_2_, p_147799_3_, p_147799_4_);
		}

		if (i1 == 3) {
			renderer.setRenderBounds(d1, d4, 1.0D - d3, 1.0D - d1, d4 + d2, 1.0D);
			renderer.renderStandardBlock(p_147799_1_, p_147799_2_, p_147799_3_, p_147799_4_);
		}

		if (i1 == 4) {
			renderer.setRenderBounds(0.0D, d4, d1, d3, d4 + d2, 1.0D - d1);
			renderer.renderStandardBlock(p_147799_1_, p_147799_2_, p_147799_3_, p_147799_4_);
		}

		if (i1 == 5) {
			renderer.setRenderBounds(1.0D - d3, d4, d1, 1.0D, d4 + d2, 1.0D - d1);
			renderer.renderStandardBlock(p_147799_1_, p_147799_2_, p_147799_3_, p_147799_4_);
		}
	}

	renderer.clearOverrideBlockTexture();
	return true;
}

I'll need help, and I'll give help. Just ask, you know I will!

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.