Jump to content

Recommended Posts

Posted

Hi, i'm a starter in MineCraft Modding, and have met a problem about Icon rotate.

 

The Problem is that:

i have a set of Icon(for block's top side) with an arrow, and i want the arrow(well the icon direction) always be the direction player is facing(when placed).

I have figured out that i can get the direction player facing through:

 


int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

 

And also know i should use a ISimpleBlockRenderingHandler and its method:

 

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

 

to do do rotate. but i'm not sure what should i write in this method?

i.e.

 

i get the top Icon as Variable  topIcon, and the direction blockDirection, what's the next step i should do?

 

thx a lot for your help :)

Posted

You should be able to simply use metadata to handle which face shows the icon, or if it's not about which face, which version of the icon is shown, but that would require 1 icon per direction.

 

Since you are using ISBRH anyway, you can instead use the GL11.glRotatef function to rotate the icon before you render it - take a look at the vanilla block rendering code, especially for buttons, levers, and that kind of thing, for examples.

Posted

Since you are using ISBRH anyway, you can instead use the GL11.glRotatef function to rotate the icon before you render it - take a look at the vanilla block rendering code, especially for buttons, levers, and that kind of thing, for examples.

 

i have looked vanilla block rendering code for piston, but got confused about the following codes:

 

switch (i1)
            {
                case 0:
                    this.uvRotateEast = 3;
                    this.uvRotateWest = 3;
                    this.uvRotateSouth = 3;
                    this.uvRotateNorth = 3;
                    this.setRenderBounds(0.0D, 0.25D, 0.0D, 1.0D, 1.0D, 1.0D);
                    break;
                case 1:
                    this.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 0.75D, 1.0D);
                    break;
                case 2:
                    this.uvRotateSouth = 1;
                    this.uvRotateNorth = 2;
                    this.setRenderBounds(0.0D, 0.0D, 0.25D, 1.0D, 1.0D, 1.0D);
                    break;
                case 3:
                    this.uvRotateSouth = 2;
                    this.uvRotateNorth = 1;
                    this.uvRotateTop = 3;
                    this.uvRotateBottom = 3;
                    this.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.75D);
                    break;
                case 4:
                    this.uvRotateEast = 1;
                    this.uvRotateWest = 2;
                    this.uvRotateTop = 2;
                    this.uvRotateBottom = 1;
                    this.setRenderBounds(0.25D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
                    break;
                case 5:
                    this.uvRotateEast = 2;
                    this.uvRotateWest = 1;
                    this.uvRotateTop = 1;
                    this.uvRotateBottom = 2;
                    this.setRenderBounds(0.0D, 0.0D, 0.0D, 0.75D, 1.0D, 1.0D);

 

obviously its rotating the block, but what dose uvRorate mean? these magical number really confused me... maybe u can explain it for me? thx

Posted

Honestly I'm not really sure what those mean, but if you are intent on using the ISBRH to render 1 icon with different rotations, you should look at using the Tessellator, specifically #addVertexWithUV.

 

Depending on the block's metadata (which you would set based on the player's facing / pitch when the block is placed), you would change the order of the rendering vertices, e.g. starting at x=16 and going to x=0 instead of 0->16 to invert the icon along the x axis.

 

The easy route, though 'less optimal', is to simply create 4 different icons, one for the arrow facing each direction, and register all 4 as your block icons, then return the correct one from #getIcon based on the block's metadata. Simple and effective, no need to mess with difficult rendering code - sounds like a win to me, though I know some would disagree.

Posted

Honestly I'm not really sure what those mean, but if you are intent on using the ISBRH to render 1 icon with different rotations, you should look at using the Tessellator, specifically #addVertexWithUV.

 

yeah, tyvm, also figured it out by reading http://greyminecraftcoder.blogspot.de/2013/08/the-tessellator.html this page, and do i need to use tessellator's draw method at end or it's find just to define how to draw it?

 

to be honest, i'm not going to create an icon for each direction, because the block i want it to rotate has 8 states and therefore i'll need 8*4=32 icons for them.... u know thats really quiet much xD

Posted

If you need 32 states, then no, I wouldn't recommend a separate icon for each one. I only suggested that because it sounded like you had 4 states, 6 at most, in which case it wouldn't be so bad.

 

I assume you have a TileEntity, then, to store that many states? Metadata can only handle up to 16, so you may want to use metadata for block rotation and the TE for whatever else you need, or vice versa.

 

Yes, you need to call #draw after you have added all the vertices, otherwise nothing will show up on the screen ;)

Posted

If you need 32 states, then no, I wouldn't recommend a separate icon for each one. I only suggested that because it sounded like you had 4 states, 6 at most, in which case it wouldn't be so bad.

 

I assume you have a TileEntity, then, to store that many states? Metadata can only handle up to 16, so you may want to use metadata for block rotation and the TE for whatever else you need, or vice versa.

 

Yes, you need to call #draw after you have added all the vertices, otherwise nothing will show up on the screen ;)

 

yeah, because of 32(in fact 2*4*4, 2 groups and 4 states for 4 directions) states i need a TE to store them. thank you again for the help, its solved now :)

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.