Skip to content

Commit

Permalink
Fixes yeet "DisableConstantChunkSaving",
Browse files Browse the repository at this point in the history
Re-activates Experimental Tool and Weapon Swapping behind a Config option, ONLY AFTER testing that the original code passes; and make it only compare Tool/Weapon Enchantments and Rarity; which allows for a much better result.
  • Loading branch information
sakura-ryoko committed Jun 19, 2024
1 parent be822aa commit e3986ab
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.ObjectInputFilter;
import java.util.*;
import java.util.function.Predicate;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -430,14 +431,17 @@ private static boolean isBetterWeapon(ItemStack testedStack, ItemStack previousW
return true;
}

if (testedStack.isEmpty() == false && matchesWeaponMapping(testedStack, entity) && (makesMoreDamage(testedStack, previousWeapon) || matchesWeaponMapping(previousWeapon, entity) == false))
if (testedStack.isEmpty() == false)
{
if (Configs.Generic.WEAPON_SWAP_BETTER_ENCHANTS.getBooleanValue())
if (matchesWeaponMapping(testedStack, entity) && (makesMoreDamage(testedStack, previousWeapon) || matchesWeaponMapping(previousWeapon, entity) == false))
{
return hasTheSameOrBetterRarity(testedStack, previousWeapon) && hasSameOrBetterWeaponEnchantments(testedStack, previousWeapon);
}
if (Configs.Generic.WEAPON_SWAP_BETTER_ENCHANTS.getBooleanValue())
{
return hasTheSameOrBetterRarity(testedStack, previousWeapon) && hasSameOrBetterWeaponEnchantments(testedStack, previousWeapon);
}

return true;
return true;
}
}

return false;
Expand Down Expand Up @@ -541,14 +545,17 @@ private static boolean isBetterTool(ItemStack testedStack, ItemStack previousToo
return true;
}

if (testedStack.isEmpty() == false && isMoreEffectiveTool(testedStack, previousTool, state))
if (testedStack.isEmpty() == false)
{
if (Configs.Generic.TOOL_SWAP_BETTER_ENCHANTS.getBooleanValue())
if (isMoreEffectiveTool(testedStack, previousTool, state))
{
return hasTheSameOrBetterRarity(testedStack, previousTool) && hasSameOrBetterToolEnchantments(testedStack, previousTool);
}
if (Configs.Generic.TOOL_SWAP_BETTER_ENCHANTS.getBooleanValue())
{
return hasTheSameOrBetterRarity(testedStack, previousTool) && hasSameOrBetterToolEnchantments(testedStack, previousTool);
}

return true;
return true;
}
}

return false;
Expand Down Expand Up @@ -817,9 +824,6 @@ private static void repairModeHandleSlot(PlayerEntity player, EquipmentSlot type
}
}

/**
* Adds the enchantment checks for Tools or Weapons
*/
private static int findRepairableItemNotInRepairableSlot(Slot targetSlot, PlayerEntity player)
{
ScreenHandler containerPlayer = player.currentScreenHandler;
Expand All @@ -834,8 +838,6 @@ private static int findRepairableItemNotInRepairableSlot(Slot targetSlot, Player
if ((slot.id - 36) != player.getInventory().selectedSlot &&
stack.isDamageable() && stack.isDamaged() && targetSlot.canInsert(stack) &&
getEnchantmentLevel(stack, Enchantments.MENDING) > 0)
//(hasSameOrBetterToolEnchantments(stack, targetSlot.getStack()) ||
//hasSameOrBetterWeaponEnchantments(stack, targetSlot.getStack())))
{
return slot.id;
}
Expand Down

0 comments on commit e3986ab

Please sign in to comment.