1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| public class DarkCrystalDiamondAxeItem extends AxeItem { private static final int COOLDOWN_TIME = 100;
public DarkCrystalDiamondAxeItem(ToolMaterial material, float attackDamage, float attackSpeed, Settings settings) { super(material, attackDamage, attackSpeed, settings); }
@Override public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { if (!(miner instanceof PlayerEntity player)) { return false; }
if (state.isIn(BlockTags.OVERWORLD_NATURAL_LOGS)) { int brokenBlocks = 0; if (!world.isClient) { showWoodInVertical(world, player);
brokenBlocks++; world.breakBlock(pos, true, player); brokenBlocks += checkAndBreakAbove(world, pos.up(), state, player);
stack.damage(brokenBlocks, player, (p) -> p.sendToolBreakStatus(Hand.MAIN_HAND)); } return true; }
return false; }
private int checkAndBreakAbove(World world, BlockPos pos, BlockState originalState, PlayerEntity player) { BlockState aboveState = world.getBlockState(pos);
int brokenCount = 0;
if (aboveState.isIn(BlockTags.OVERWORLD_NATURAL_LOGS) && aboveState.equals(originalState)) { world.breakBlock(pos, true, player); brokenCount++;
brokenCount += checkAndBreakAbove(world, pos.up(), originalState, player); } return brokenCount; } public void showWoodInVertical(World world, PlayerEntity player) { BlockPos playerPos = player.getBlockPos(); for (int i = 1; i <= 5; i++) { BlockPos checkPos = playerPos.up(i); BlockState blockState = world.getBlockState(checkPos); if (blockState.isIn(BlockTags.OVERWORLD_NATURAL_LOGS)) { world.playSound(null, checkPos, SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 1.0f, 1.0f); } } }
@Override public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { if (attacker instanceof PlayerEntity user) { if (user.getItemCooldownManager().isCoolingDown(stack.getItem())) { return true; }
stack.damage(1, attacker, e -> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
target.addStatusEffect(new StatusEffectInstance(ModStatusEffects.BADLY_WOUNDED, 80, 0));
user.getItemCooldownManager().set(stack.getItem(), COOLDOWN_TIME); }
return true; }
}
|