Java Code Examples for net.minecraft.server.network.ServerPlayerEntity#canMine()
The following examples show how to use
net.minecraft.server.network.ServerPlayerEntity#canMine() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CarpetExpression.java From fabric-carpet with MIT License | 5 votes |
private boolean tryBreakBlock_copy_from_ServerPlayerInteractionManager(ServerPlayerEntity player, BlockPos blockPos_1) { //this could be done little better, by hooking up event handling not in try_break_block but wherever its called // so we can safely call it here // but that woudl do for now. BlockState blockState_1 = player.world.getBlockState(blockPos_1); if (!player.getMainHandStack().getItem().canMine(blockState_1, player.world, blockPos_1, player)) { return false; } else { BlockEntity blockEntity_1 = player.world.getBlockEntity(blockPos_1); Block block_1 = blockState_1.getBlock(); if ((block_1 instanceof CommandBlock || block_1 instanceof StructureBlock || block_1 instanceof JigsawBlock) && !player.isCreativeLevelTwoOp()) { player.world.updateListeners(blockPos_1, blockState_1, blockState_1, 3); return false; } else if (player.canMine(player.world, blockPos_1, player.interactionManager.getGameMode())) { return false; } else { block_1.onBreak(player.world, blockPos_1, blockState_1, player); boolean boolean_1 = player.world.removeBlock(blockPos_1, false); if (boolean_1) { block_1.onBroken(player.world, blockPos_1, blockState_1); } if (player.isCreative()) { return true; } else { ItemStack itemStack_1 = player.getMainHandStack(); boolean boolean_2 = player.isUsingEffectiveTool(blockState_1); itemStack_1.postMine(player.world, blockState_1, blockPos_1, player); if (boolean_1 && boolean_2) { ItemStack itemStack_2 = itemStack_1.isEmpty() ? ItemStack.EMPTY : itemStack_1.copy(); block_1.afterBreak(player.world, player, blockPos_1, blockState_1, blockEntity_1, itemStack_2); } return true; } } } }
Example 2
Source File: EntityPlayerActionPack.java From fabric-carpet with MIT License | 4 votes |
@Override boolean execute(ServerPlayerEntity player, Action action) { HitResult hit = getTarget(player); switch (hit.getType()) { case ENTITY: { EntityHitResult entityHit = (EntityHitResult) hit; player.attack(entityHit.getEntity()); player.resetLastAttackedTicks(); player.updateLastActionTime(); player.swingHand(Hand.MAIN_HAND); return true; } case BLOCK: { EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack(); if (ap.blockHitDelay > 0) { ap.blockHitDelay--; return false; } BlockHitResult blockHit = (BlockHitResult) hit; BlockPos pos = blockHit.getBlockPos(); Direction side = blockHit.getSide(); // rather should be canNotMine if (player.canMine(player.world, pos, player.interactionManager.getGameMode())) return false; if (ap.currentBlock != null && player.world.getBlockState(ap.currentBlock).isAir()) { ap.currentBlock = null; return false; } BlockState state = player.world.getBlockState(pos); boolean blockBroken = false; if (player.interactionManager.getGameMode().isCreative()) { player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight()); ap.blockHitDelay = 5; blockBroken = true; } else if (ap.currentBlock == null || !ap.currentBlock.equals(pos)) { if (ap.currentBlock != null) { player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.server.getWorldHeight()); } player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight()); boolean notAir = !state.isAir(); if (notAir && ap.curBlockDamageMP == 0) { state.onBlockBreakStart(player.world, pos, player); } if (notAir && state.calcBlockBreakingDelta(player, player.world, pos) >= 1) { ap.currentBlock = null; //instamine?? blockBroken = true; } else { ap.currentBlock = pos; ap.curBlockDamageMP = 0; } } else { ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.world, pos); if (ap.curBlockDamageMP >= 1) { player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.server.getWorldHeight()); ap.currentBlock = null; ap.blockHitDelay = 5; blockBroken = true; } player.world.setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10)); } player.updateLastActionTime(); player.swingHand(Hand.MAIN_HAND); return blockBroken; } } return false; }