Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround Axe Enchantments on Paxel by Checking an Axe #7903

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/tools/java/mekanism/tools/common/item/ItemMekanismPaxel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.TagKey;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.Attribute;
Expand All @@ -26,7 +27,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;
Expand All @@ -37,26 +37,28 @@
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");

private final IPaxelMaterial material;
private final AttributeCache attributeCache;
private static final TagKey<Block> MINEABLE_WITH_PAXEL = ToolsTags.Blocks.MINEABLE_WITH_PAXEL;
ChampionAsh5357 marked this conversation as resolved.
Show resolved Hide resolved

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);
Expand All @@ -81,7 +83,7 @@ public boolean canPerformAction(ItemStack stack, ToolAction action) {

@Override
public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state) {
return super.getDestroySpeed(stack, state) == 1 ? 1 : material.getPaxelEfficiency();
return state.is(MINEABLE_WITH_PAXEL) ? material.getPaxelEfficiency() : 1;
}

/**
Expand Down Expand Up @@ -189,4 +191,15 @@ public void addToBuilder(ImmutableMultimap.Builder<Attribute, AttributeModifier>
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));
}

@Override
public boolean isCorrectToolForDrops(BlockState state) {
thiakil marked this conversation as resolved.
Show resolved Hide resolved
// Some modded items may not check the stack sensitive version
ChampionAsh5357 marked this conversation as resolved.
Show resolved Hide resolved
return state.is(MINEABLE_WITH_PAXEL) && TierSortingRegistry.isCorrectTierForDrops(getTier(), state);
}

@Override
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
return state.is(MINEABLE_WITH_PAXEL) && TierSortingRegistry.isCorrectTierForDrops(getTier(), state);
}
}