How do I make only the player who place the block can break the Block?
I dont know the problem is that I used the wrong method to get the name of the player who placed the block or that I used the canHarvestBlock in a wrong way.
I am very new to this !
This is the onBlockPlacedBy and canHarvestBlock:
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
if(placer instanceof PlayerEntity) {
permission = placer.getName().toString();
}
}
@Override
public boolean canHarvestBlock(BlockState state, IBlockReader world, BlockPos pos, PlayerEntity player) {
if(player.getName().getString() == permission) {
return state.getBlock().canHarvestBlock(state, world, pos, player);
}
return false;
}
Permission variable:
public static String permission = null;
EDIT: I solve the problem above but now my problem is that I the method I used was wrong! I don't know what method should I use in order to not let player to break the block