diff --git a/src/tools/java/mekanism/tools/common/item/ItemMekanismPaxel.java b/src/tools/java/mekanism/tools/common/item/ItemMekanismPaxel.java index 477583d6a95..0da6dacfe9c 100644 --- a/src/tools/java/mekanism/tools/common/item/ItemMekanismPaxel.java +++ b/src/tools/java/mekanism/tools/common/item/ItemMekanismPaxel.java @@ -26,7 +26,6 @@ import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.AxeItem; -import net.minecraft.world.item.DiggerItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; @@ -37,12 +36,13 @@ import net.minecraft.world.level.block.CampfireBlock; import net.minecraft.world.level.block.LevelEvent; import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.TierSortingRegistry; import net.minecraftforge.common.ToolAction; import net.minecraftforge.common.ToolActions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class ItemMekanismPaxel extends DiggerItem implements IHasRepairType, IAttributeRefresher { +public class ItemMekanismPaxel extends AxeItem implements IHasRepairType, IAttributeRefresher { private static final ToolAction PAXEL_DIG = ToolAction.get("paxel_dig"); @@ -50,13 +50,13 @@ public class ItemMekanismPaxel extends DiggerItem implements IHasRepairType, IAt private final AttributeCache attributeCache; public ItemMekanismPaxel(MaterialCreator material, Item.Properties properties) { - super(material.getPaxelDamage(), material.getPaxelAtkSpeed(), material, ToolsTags.Blocks.MINEABLE_WITH_PAXEL, properties); + super(material, material.getPaxelDamage(), material.getPaxelAtkSpeed(), properties); this.material = material; this.attributeCache = new AttributeCache(this, material.attackDamage, material.paxelDamage, material.paxelAtkSpeed); } public ItemMekanismPaxel(VanillaPaxelMaterialCreator material, Item.Properties properties) { - super(material.getPaxelDamage(), material.getPaxelAtkSpeed(), material.getVanillaTier(), ToolsTags.Blocks.MINEABLE_WITH_PAXEL, properties); + super(material.getVanillaTier(), material.getPaxelDamage(), material.getPaxelAtkSpeed(), properties); this.material = material; //Don't add the material's damage as a listener as the vanilla component is not configurable this.attributeCache = new AttributeCache(this, material.paxelDamage, material.paxelAtkSpeed); @@ -75,13 +75,13 @@ public float getAttackDamage() { @Override public boolean canPerformAction(ItemStack stack, ToolAction action) { - return action == PAXEL_DIG || ToolActions.DEFAULT_AXE_ACTIONS.contains(action) || ToolActions.DEFAULT_PICKAXE_ACTIONS.contains(action) || - ToolActions.DEFAULT_SHOVEL_ACTIONS.contains(action); + return action == PAXEL_DIG || ToolActions.DEFAULT_PICKAXE_ACTIONS.contains(action) || + ToolActions.DEFAULT_SHOVEL_ACTIONS.contains(action) || super.canPerformAction(stack, action); } @Override public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state) { - return super.getDestroySpeed(stack, state) == 1 ? 1 : material.getPaxelEfficiency(); + return state.is(ToolsTags.Blocks.MINEABLE_WITH_PAXEL) ? material.getPaxelEfficiency() : 1; } /** @@ -92,32 +92,36 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state @NotNull @Override public InteractionResult useOn(UseOnContext context) { + // Attempt to use the paxel as an axe + InteractionResult axeResult = super.useOn(context); + if (axeResult != InteractionResult.PASS) { + return axeResult; + } + Level world = context.getLevel(); BlockPos blockpos = context.getClickedPos(); Player player = context.getPlayer(); BlockState blockstate = world.getBlockState(blockpos); - BlockState resultToSet = useAsAxe(blockstate, context); - if (resultToSet == null) { - //We cannot strip the item that was right-clicked, so attempt to use the paxel as a shovel - if (context.getClickedFace() == Direction.DOWN) { - return InteractionResult.PASS; - } - BlockState foundResult = blockstate.getToolModifiedState(context, ToolActions.SHOVEL_FLATTEN, false); - if (foundResult != null && world.isEmptyBlock(blockpos.above())) { - //We can flatten the item as a shovel - world.playSound(player, blockpos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); - resultToSet = foundResult; - } else if (blockstate.getBlock() instanceof CampfireBlock && blockstate.getValue(CampfireBlock.LIT)) { - //We can use the paxel as a shovel to extinguish a campfire - if (!world.isClientSide) { - world.levelEvent(null, LevelEvent.SOUND_EXTINGUISH_FIRE, blockpos, 0); - } - CampfireBlock.dowse(player, world, blockpos, blockstate); - resultToSet = blockstate.setValue(CampfireBlock.LIT, false); - } - if (resultToSet == null) { - return InteractionResult.PASS; + BlockState resultToSet = null; + //We cannot strip the item that was right-clicked, so attempt to use the paxel as a shovel + if (context.getClickedFace() == Direction.DOWN) { + return InteractionResult.PASS; + } + BlockState foundResult = blockstate.getToolModifiedState(context, ToolActions.SHOVEL_FLATTEN, false); + if (foundResult != null && world.isEmptyBlock(blockpos.above())) { + //We can flatten the item as a shovel + world.playSound(player, blockpos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); + resultToSet = foundResult; + } else if (blockstate.getBlock() instanceof CampfireBlock && blockstate.getValue(CampfireBlock.LIT)) { + //We can use the paxel as a shovel to extinguish a campfire + if (!world.isClientSide) { + world.levelEvent(null, LevelEvent.SOUND_EXTINGUISH_FIRE, blockpos, 0); } + CampfireBlock.dowse(player, world, blockpos, blockstate); + resultToSet = blockstate.setValue(CampfireBlock.LIT, false); + } + if (resultToSet == null) { + return InteractionResult.PASS; } if (!world.isClientSide) { ItemStack stack = context.getItemInHand(); @@ -132,31 +136,6 @@ public InteractionResult useOn(UseOnContext context) { return InteractionResult.sidedSuccess(world.isClientSide); } - @Nullable - private BlockState useAsAxe(BlockState state, UseOnContext context) { - Level world = context.getLevel(); - BlockPos blockpos = context.getClickedPos(); - Player player = context.getPlayer(); - BlockState resultToSet = state.getToolModifiedState(context, ToolActions.AXE_STRIP, false); - if (resultToSet != null) { - world.playSound(player, blockpos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); - return resultToSet; - } - resultToSet = state.getToolModifiedState(context, ToolActions.AXE_SCRAPE, false); - if (resultToSet != null) { - world.playSound(player, blockpos, SoundEvents.AXE_SCRAPE, SoundSource.BLOCKS, 1.0F, 1.0F); - world.levelEvent(player, LevelEvent.PARTICLES_SCRAPE, blockpos, 0); - return resultToSet; - } - resultToSet = state.getToolModifiedState(context, ToolActions.AXE_WAX_OFF, false); - if (resultToSet != null) { - world.playSound(player, blockpos, SoundEvents.AXE_WAX_OFF, SoundSource.BLOCKS, 1.0F, 1.0F); - world.levelEvent(player, LevelEvent.PARTICLES_WAX_OFF, blockpos, 0); - return resultToSet; - } - return null; - } - @Override public int getEnchantmentValue() { return material.getPaxelEnchantability(); @@ -189,4 +168,15 @@ public void addToBuilder(ImmutableMultimap.Builder builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Tool modifier", getAttackDamage(), Operation.ADDITION)); builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Tool modifier", material.getPaxelAtkSpeed(), Operation.ADDITION)); } + + // Need to override both method as DiggerItem performs two different behaviors + @Override + public boolean isCorrectToolForDrops(BlockState state) { + return state.is(ToolsTags.Blocks.MINEABLE_WITH_PAXEL) && TierSortingRegistry.isCorrectTierForDrops(getTier(), state); + } + + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return state.is(ToolsTags.Blocks.MINEABLE_WITH_PAXEL) && TierSortingRegistry.isCorrectTierForDrops(getTier(), state); + } } \ No newline at end of file