diff --git a/src/main/java/dev/hybridlabs/aquatic/mixin/PlayerEntityMixin.java b/src/main/java/dev/hybridlabs/aquatic/mixin/PlayerEntityMixin.java index e2869dffd..d9fbfd0e1 100644 --- a/src/main/java/dev/hybridlabs/aquatic/mixin/PlayerEntityMixin.java +++ b/src/main/java/dev/hybridlabs/aquatic/mixin/PlayerEntityMixin.java @@ -1,5 +1,6 @@ package dev.hybridlabs.aquatic.mixin; +import com.google.common.collect.ImmutableList; import dev.hybridlabs.aquatic.access.CustomPlayerEntityData; import dev.hybridlabs.aquatic.effect.HybridAquaticStatusEffects; import dev.hybridlabs.aquatic.entity.shark.HybridAquaticSharkEntity; @@ -17,6 +18,7 @@ import net.minecraft.item.ToolItem; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.tag.FluidTags; +import net.minecraft.util.collection.DefaultedList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -25,6 +27,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.ArrayList; +import java.util.List; + @Mixin(PlayerEntity.class) public abstract class PlayerEntityMixin implements CustomPlayerEntityData { @@ -97,7 +102,7 @@ private void tickDownCustomHurtTime(CallbackInfo ci) { // Gives Resistance and Slowness if player has Turtle chestplate equipped updateTurtleChestplate(); // Repairs coral tools in the water - repairCoralTools(10); + repairCoralTools(5); } @Unique @@ -141,16 +146,27 @@ private void updateTurtleChestplate() { @Unique private void repairCoralTools(int tickDelay) { var player = (PlayerEntity)(Object)this; + var inventory = player.getInventory(); if (player.isSubmergedIn(FluidTags.WATER)) { if (coralRepairTick > tickDelay) { - player.getItemsEquipped().forEach(itemStack -> { - if (itemStack.getItem() instanceof ToolItem tool && - tool.getMaterial() == HybridAquaticToolMaterials.CORAL && - itemStack.isDamaged()) { - itemStack.setDamage(itemStack.getDamage() - 1); - } - }); + List> combinedInventory = ImmutableList.of(inventory.main, inventory.offHand); + List coralItems = new ArrayList<>(); + for(List list: combinedInventory) { + for (ItemStack itemStack: list) { + if (itemStack.getItem() instanceof ToolItem tool && + tool.getMaterial() == HybridAquaticToolMaterials.CORAL && + itemStack.isDamaged()) { + coralItems.add(itemStack); + } + } + } + + if(!coralItems.isEmpty()) { + ItemStack item = coralItems.get(player.getRandom().nextInt(coralItems.size())); + item.setDamage(item.getDamage() - 1); + inventory.markDirty(); + } coralRepairTick = 0; }