Jump to content

Recommended Posts

Posted

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) {
super.onBlockAdded(par1World, par2, par3, 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;

	par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
}
}

@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;
}

Lead DivineRPG Developer

Posted

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);
world.setBlockMetadataWithNotify(x, y, z, direction, 2);
}

@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

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.