I have an item which when useOn-ed should remove the block/change it to AIR.
I am using the line below:
level.removeBlock(positionClicked, false);
Once I run the client, the block is briefly removed and then reappears. I've also tried removing the block with:
level.destroyBlock(positionClicked, false);
level.setBlock(positionClicked, Blocks.AIR.defaultBlockState(), 1);
My guess is that I am not registering something correctly/the removed blocks are not applied to the client.
Full code:
public class TeleportationItem extends Item {
public TeleportationItem(Properties pProperties) {
super(pProperties);
}
@Override
public InteractionResult useOn(UseOnContext pContext) {
Level level = pContext.getLevel();
if (level.isClientSide){
BlockPos blockpos = pContext.getClickedPos();
BlockState blockstate = level.getBlockState(blockpos);
level.removeBlock(positionClicked, false);
//level.setBlock(positionClicked, Blocks.AIR.defaultBlockState(), 1);
// level.destroyBlock(positionClicked, false);
return super.useOn(pContext);
}
return super.useOn(pContext);
}
}