# [1.7.2]Rotate Block

## Recommended Posts

Hey,

I want to rotate my block, when I look into the direction like a furnace or a pumpkin.

I had a look into it, but found out nothing.

Thanks for help!

##### Share on other sites

Assuming you mean that you want the block to rotate just when you first place it down, add this code to your block's class:

```public void onBlockAdded(World par1World, int par2, int par3, int par4) {
this.setDefaultDirection(par1World, par2, par3, par4);
}

private void setDefaultDirection(World par1World, int par2, int par3, int par4) {
if (!par1World.isRemote) {
Block l = par1World.getBlock(par2, par3, par4 - 1);
Block i1 = par1World.getBlock(par2, par3, par4 + 1);
Block j1 = par1World.getBlock(par2 - 1, par3, par4);
Block k1 = par1World.getBlock(par2 + 1, par3, par4);
byte b0 = 3;
if (l.func_149730_j() && !i1.func_149730_j())
b0 = 3;

if (i1.func_149730_j() && !l.func_149730_j())
b0 = 2;

if (j1.func_149730_j() && !k1.func_149730_j())
b0 = 5;

if (k1.func_149730_j() && !j1.func_149730_j())
b0 = 4;

}
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
return (side == world.getBlockMetadata(x, y, z)) ? this.frontIcon : this.blockIcon;
}
```

##### Share on other sites

You'll need to use block metadata to keep track of the orientation that the player places the block in, and you can use a method that pistons use to determine block facing:

```@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
// no need to figure out the right orientation again when the piston block can do it for us
int direction = BlockPistonBase.determineOrientation(world, x, y, z, entity);
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
return (side == world.getBlockMetadata(x, y, z)) ? this.frontIcon : this.blockIcon;
}
```

Note that you'll need to define a field "frontIcon" that contains the IIcon of the texture you want to draw on the front.

I like to make mods, just like you. Here's one worth checking out

##### Share on other sites

Use mine if you only want the block to face north-south-east-west (like a furnace or a pumpkin). Use Jwosty's method if you want the front to be able to go up and down also (like a piston).

Thank you guys!

## 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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• ### Posts

• I've been looking through everything as possible to fix this for the past year. I already have my drivers updated. i uninstalled and reinstalled both mc and forge. I've done it with java as well. none of the online suggestions work but the thing is when i mod with pixelmon everything works same with crazy craft but other mods like a solo leveling one or better mc i get this and its always completely random modpacks that do this and its weird cause non official modpacks seem to work. i just want to play modded minecraft and im starting to get frustrated cause nothing i do or people suggest works.
• There is no link to the log
• heres my latest log. What ends up happening is after it loads all the mods up in stage 1, it will launch phase 2 and just stay stuck on the red mojang screen. I have sufficient Ram being allocated too so thats not the issue.
• bius

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...