Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8] Block state reset after right click


shucke
 Share

Recommended Posts

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.

Link to comment
Share on other sites

oops my bad :P

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Ok, first of all: @SideOnly does not do what you think it does.

 

onItemUse does not get called because your onBlockActivated always returns true (which makes Minecraft think your Block "handled" the right click, so the Item action does not take place).

onItemUseFirst will not be called on the server if it returns false on the client, same with the other methods.

Link to comment
Share on other sites

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.