Jump to content

[1.7.10] Alternating model, can it be done?


Erfurt

Recommended Posts

Hey guys,

 

So I'm making a cosmetic mod that adds in hedges, and at the moment I'm at the point where I would like to change the model of the middle section of the wall, so that it would be the same width and height as the post has. However I have no idea if I can alter the model, and if so if it will change the model for Cobblestone Wall as well? Is there a way to do this, or do I have to make a new model for my mod?

 

Any help here would be great, I haven't been able to find anything by myself, but that might be because I'm searching for the wrong stuff

Link to comment
Share on other sites

So... you wish to make a block with a custom model? Google custom rendered block, there should be plenty of tutorials available.

well, we need some more. those out there weren't very useful when i needed them.

 

 

i made a custom block a month ago (1.7.10) - simple non-cubic block, no inventory, no animation, not a single reason to use a tile entity.

let me tell you it was a nightmare. a long one.

 

there's a bunch of tutorials on youtube telling you to use a tile entity special renderer (TESR). i didn't want to go that way because the block is as simple as can be.

although it seemed like those youngsters that recorded TESR tutorials didn't have too much concern for potential lag, at least those things seemed to work at the end of the tutorial.

 

the right way to go was simple block rendering handler interface (ISBRH).... but, there was no usable tutorial. just a few that make some intro about what calls what, and what the order of things is.

 

---------

so - back to topic (original posters problem):

1: don't bother with techne; you need neither the model file nor the texture. you will use vanilla textures so your hedge will look good with any resource pack.

 

2: you need the renderer. make a class GloriousHedgeRenderer that implements ISimpleBlockRenderingHandler. have the eclipse insert method headers for you.

 

3a: the main thing here is the renderWorldBlock method. we'll write it now. you need this one line before anything.

renderer.renderAllFaces = true;

 

3c: start with a center column:

renderer.setRenderBounds(4/16D, 0D, 4/16D, 12/16D, 12/16D, 12/16D);
renderer.renderStandardBlock(Blocks.leavesOrWhatever, x, y, z); ---------x,y,z are the parameters, leave those alone

here, i went from 25% (4/16) to 75% (12/16) on the X-axis (parameters 1 and 4), same for Z-axis (parameters 3 and 6) and from the bottom to 75% for Y axis.

 

now you do four more pairs of those two calls, if there is an adjacent block:

3d: *check if there is a hedge block in negative-X direction (world.getBlock call). if there is, draw another leaf block from 0 to 25% on X and 25 to 75% on Z.

3e: *similar for positive X

3f: *similar for negative Z

3g: *check if there is a hedge block in positive-Z direction. if there is, draw another leaf block from 75 to 100% on Z and 25 to 75% on X.

 

3b: before everything check for a hedge block above - set the Y top variable to either 100% or 80%. use that variable in setRenderBounds as a fifth parameter.

 

3h: that's it. end the function with:

			renderer.setRenderBounds(0, 0, 0, 1, 1, 1);
		renderer.renderAllFaces = false;
		return true;

 

15: when you see that it works, consider drawing it using 2 calls instead of 5. a simple optimization that you should definitely do.

 

4: ok, we have the rendering method - now, we need to connect the block to the renderer. for that we use an integer number called renderer id. you get if from a call to RenderingRegistry.getNextAvailableRenderId(), which you will do once and only once. i'll show you how i did it. in the renderer class add:

	@Override
public int getRenderId()
{
	return getRenderIdInternal();
}

public static int getRenderIdInternal()
{
	if (rendererId == 0)
	{
		rendererId = RenderingRegistry.getNextAvailableRenderId();	
	}
	return rendererId;
}

and in the block class, you add:

    public int getRenderType()
    {
        return PlateRenderer.getRenderIdInternal();
    }

part of it already exists in renderer class, just overwrite existing getRenderId part.

that's it. as long as block.getRenderType and renderer.getRenderId always return the same value, this will work. most people get the renderer id on the block instead of renderer, it doesn't matter really.

 

5: in the block constructor, i have the code this.setBlockTextureName("minecraft:dirt"); you might not need it, i don't remember 100% but i think you do.

 

6 we need to register the renderer. in the client proxy, add this method:

	public void RegisterRenderers()
{
	RenderingRegistry.registerBlockHandler(ErfurtsHedgeRenderer.getInstance());
}

in the common proxy, add the same thing, except empty. and in the Initialization method of the main mod class, call proxy.RegisterRenderers();

 

that's it. you got the oak leaf hedge. you need to change the drawing above to use your block's metadata, which hopefully matches leaf metadata (by now you have already made the item that places the 6 variations of hedge blocks)

 

troubleshooting:

if you see nothing rendered, you messed up something with the renderer ids.

if you get a crash saying "already tesselating" or "not tesselating", you weren't listening and added some code from other examples.

 

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.