Posted November 10, 20204 yr 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 Edited November 11, 20204 yr by AustinTan new update
November 10, 20204 yr You're trying to give a singleton a changing state. You need to add a tile entity and store the data there to do your checks.
November 11, 20204 yr Author Sorry for the late reply! Now that I store the data in the title entity and then I realized that I used the wrong method for what I am trying to do I want to set so that the player cannot break the block not cannot get the block after it break do you know what method should I use? Because I don't and I've been searching for quite sometime and I still have no idea!
November 11, 20204 yr Author 28 minutes ago, diesieben07 said: You need to subscribe to PlayerEvent.BreakSpeed and set the speed to 0 if you want it to be unminable. I used this but it's still the same what did I do wrong? event.setNewSpeed(0); EDIT: it worked I fixed it Thanks you! Edited November 11, 20204 yr by AustinTan
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.