Posted April 7, 201411 yr 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!
April 7, 201411 yr 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
April 8, 201411 yr 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
April 8, 201411 yr 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). Lead DivineRPG Developer
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.