Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author

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

  • 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?

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.