Skip to content

Commit

Permalink
Fix Sonar issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Dec 15, 2024
1 parent 30e7fe2 commit 0cbcf68
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Repairable;
import org.jetbrains.annotations.Nullable;

/**
Expand Down Expand Up @@ -64,20 +65,22 @@ private static void attack(LivingEntity attacker, Entity target, ItemStack item,
* @param directHit whether the hit is direct ({@code true}) or indirect ({@code false}).
* @param seconds fire duration.
*/
@SuppressWarnings("DataFlowIssue")
private static void consumeItem(LivingEntity attacker, ItemStack item, boolean directHit, int seconds) {
if (!(attacker instanceof Player player && player.isCreative())) {
if (((isCandle(item) && ModConfig.getConsumeCandle()) || (isTorch(item) && ModConfig.getConsumeTorch())) && (directHit || ModConfig.getConsumeWithIndirectHits()) && (ModConfig.getConsumeWithoutFire() || seconds > 0)) {
item.shrink(1);
} else if (
ModConfig.getIndirectHitToolDamage() > 0 &&
attacker.getMainHandItem().has(DataComponents.TOOL) &&
attacker.getMainHandItem().has(DataComponents.REPAIRABLE) &&
attacker.getMainHandItem().has(DataComponents.MAX_DAMAGE) &&
attacker.getMainHandItem().get(DataComponents.REPAIRABLE).items().unwrapKey().isPresent() &&
attacker.getMainHandItem().get(DataComponents.REPAIRABLE).items().unwrapKey().get().toString().equals(ItemTags.WOODEN_TOOL_MATERIALS.toString())
attacker.getMainHandItem() instanceof ItemStack tool &&
tool.has(DataComponents.TOOL) &&
tool.has(DataComponents.REPAIRABLE) &&
tool.has(DataComponents.MAX_DAMAGE) &&
tool.get(DataComponents.MAX_DAMAGE) instanceof Integer durability &&
tool.get(DataComponents.REPAIRABLE) instanceof Repairable repairable &&
repairable.items().unwrapKey().isPresent() &&
repairable.items().unwrapKey().get().toString().equals(ItemTags.WOODEN_TOOL_MATERIALS.toString())
) {
attacker.getMainHandItem().hurtAndBreak((attacker.getMainHandItem().get(DataComponents.MAX_DAMAGE) * ModConfig.getIndirectHitToolDamage() + 99) / 100, attacker, EquipmentSlot.MAINHAND);
tool.hurtAndBreak((durability * ModConfig.getIndirectHitToolDamage() + 99) / 100, attacker, EquipmentSlot.MAINHAND);
}
}
}
Expand Down

0 comments on commit 0cbcf68

Please sign in to comment.