Posted February 16, 201510 yr Title said it all actually, my block state resets when i right click on it with an empty hand. So this is the block code. public abstract class BlockRotateable extends BlockBaseContainer implements IRotateable{ public static final PropertyEnum DIRECTION = PropertyEnum.create("direction", EnumFacing.class); public BlockRotateable(String name, Material material) { super(name, material); this.isBlockContainer = true; } public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { return true; } public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){ return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(DIRECTION, facing); } public final EnumFacing getDirection(World worldObj, BlockPos pos){ return (EnumFacing) worldObj.getBlockState(pos).getValue(DIRECTION); } @Override public void setRotation(World world, BlockPos pos, EnumFacing rotation) { IBlockState state = world.getBlockState(pos).withProperty(DIRECTION, rotation); world.setBlockState(pos, state); } public IBlockState getStateFromMeta(int meta){ return this.getDefaultState().withProperty(DIRECTION, DirectionHelper.byIndex(meta)); } public int getMetaFromState(IBlockState state){ return ((EnumFacing)state.getValue(DIRECTION)).getIndex(); } protected BlockState createBlockState(){ return new BlockState(this, new IProperty[] {DIRECTION}); } } Im probally missing something but i cant figure out what. Any help is much appreciated EDIT: i am using the onItemUseFirst method in a item class to change the block state. http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
February 16, 201510 yr Author oops my bad here it is public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ){ Block block = world.getBlockState(pos).getBlock(); if(block instanceof IRotateable){ EnumFacing facing = ((IRotateable) block).getDirection(world, pos); ((IRotateable) block).setRotation(world, pos, DirectionHelper.getNext(facing)); System.out.println(((IRotateable) block).getDirection(world, pos)); return true; } return false; } http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
February 16, 201510 yr Author So i put the !world.isRemote check and it turns out the method does not get called on the servers side. I thought it would because it doesn't have a SideOnly annotation. I already tried the onItemUse method but that doesn't seem to call when i right click the desired block. Is there another method that does the same thing as the onItemUseFirst method? http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
February 16, 201510 yr Author Aaahhh thanks for the explanation So now i checked in the block if the item held is an instance of an Wrench and all works well now. Thanks for helping out! http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
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.