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 6f99528 commit be822aa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ author = masa
mod_file_name = tweakeroo-fabric

# Current mod version
mod_version = 0.20.999-sakura.2
mod_version = 0.20.999-sakura.3

# Required malilib version
malilib_version = 0.19.999-sakura.1
malilib_id = c9b950bef7
malilib_version = 0.19.999-sakura.2
malilib_id = 3244b550e0

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public static class Generic
public static final ConfigInteger STRUCTURE_BLOCK_MAX_SIZE = new ConfigInteger ("structureBlockMaxSize", 128, 1, 256, "The maximum dimensions for a Structure Block's saved area");
public static final ConfigString TOOL_SWITCHABLE_SLOTS = new ConfigString ("toolSwitchableSlots", "1-9", "The slots that the Tool Switch tweak is allowed to put tools to.\nNote that Tool Switch can also switch to other slots in the hotbar,\nif they already have the preferred tool, but it will only\nswap new tools to these slots");
public static final ConfigString TOOL_SWITCH_IGNORED_SLOTS = new ConfigString ("toolSwitchIgnoredSlots", "", "The slots where the Tool Switch tweak does not work when they are active.");
public static final ConfigBoolean TOOL_SWAP_BETTER_ENCHANTS = new ConfigBoolean ("toolSwapBetterEnchants", false, "Consider a Tools' Enchantments and Rarity\nfor Tool swapping, only after comparing if\nit's the correct tool to use on the target.");
public static final ConfigBoolean WEAPON_SWAP_BETTER_ENCHANTS = new ConfigBoolean ("weaponSwapBetterEnchants", false, "Consider a Weapons' Enchantments and Rarity\nfor Weapon swapping, only after comparing if \nit's the correct Weapon to use on the target.");
public static final ConfigBoolean ZOOM_ADJUST_MOUSE_SENSITIVITY = new ConfigBoolean ("zoomAdjustMouseSensitivity", true, "If enabled, then the mouse sensitivity is reduced\nwhile the zoom feature is enabled and the zoom key is active");
public static final ConfigDouble ZOOM_FOV = new ConfigDouble ("zoomFov", 30, 0.01, 359.99, "The FOV value used for the zoom feature");

Expand Down Expand Up @@ -194,6 +196,8 @@ public static class Generic
STRUCTURE_BLOCK_MAX_SIZE,
TOOL_SWITCHABLE_SLOTS,
TOOL_SWITCH_IGNORED_SLOTS,
TOOL_SWAP_BETTER_ENCHANTS,
WEAPON_SWAP_BETTER_ENCHANTS,
ZOOM_FOV
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public abstract class MixinServerChunkLoadingManager
{
@Inject(method = "unloadChunks", cancellable = true, at = @At(value = "FIELD",
target = "Lnet/minecraft/server/world/ServerChunkLoadingManager;currentChunkHolders:Lit/unimi/dsi/fastutil/longs/Long2ObjectLinkedOpenHashMap;"))
target = "Lnet/minecraft/server/world/ServerChunkLoadingManager;chunkHolders:Lit/unimi/dsi/fastutil/longs/Long2ObjectLinkedOpenHashMap;"))
private void tweakeroo_disableSaving20ChunksEveryTick(BooleanSupplier shouldKeepTicking, CallbackInfo ci)
{
if (Configs.Disable.DISABLE_CONSTANT_CHUNK_SAVING.getBooleanValue())
Expand Down
42 changes: 15 additions & 27 deletions src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,26 +425,19 @@ public static void trySwitchToWeapon(Entity entity)

private static boolean isBetterWeapon(ItemStack testedStack, ItemStack previousWeapon, Entity entity)
{
//int itemWeight = 0;

if (previousWeapon.isEmpty())
{
return true;
}
if (testedStack.isEmpty() == false)

if (testedStack.isEmpty() == false && matchesWeaponMapping(testedStack, entity) && (makesMoreDamage(testedStack, previousWeapon) || matchesWeaponMapping(previousWeapon, entity) == false))
{
// TODO Experimental Code
/*
itemWeight += matchesWeaponMapping(testedStack, entity) ? 1 : -1;
itemWeight += hasTheSameOrBetterRarity(testedStack, previousWeapon) ? 1 : -1;
itemWeight += hasSameOrBetterWeaponEnchantments(testedStack, previousWeapon) ? 1 : -1;
itemWeight += makesMoreDamage(testedStack, previousWeapon) ? 1 : -1;
itemWeight -= matchesWeaponMapping(previousWeapon, entity) ? 1 : -1;
return itemWeight > 0;
*/

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

return true;
}

return false;
Expand Down Expand Up @@ -543,24 +536,19 @@ public static int getEnchantmentLevel(ItemStack stack, @Nonnull RegistryKey<Ench

private static boolean isBetterTool(ItemStack testedStack, ItemStack previousTool, BlockState state)
{
//int itemWeight = 0;

if (previousTool.isEmpty())
{
return true;
}
if (testedStack.isEmpty() == false)
{
// TODO Experimental code
/*
itemWeight += hasTheSameOrBetterRarity(testedStack, previousTool) ? 1 : -1;
itemWeight += hasSameOrBetterToolEnchantments(testedStack, previousTool) ? 1 : -1;
itemWeight += isMoreEffectiveTool(testedStack, previousTool, state) ? 1 : -1;

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

return testedStack.isEmpty() == false && isMoreEffectiveTool(testedStack, previousTool, state);
return true;
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@

"depends": {
"minecraft": ">=1.21",
"malilib": ">=0.19.999-sakura.1"
"malilib": ">=0.19.999-sakura.2"
}
}

0 comments on commit be822aa

Please sign in to comment.