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

Vengeance Spirit Regex Cache #599

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ All changes are toggleable via config files.
* **Fix Cabbage Drop:** Fixes Cabbage not dropping the correct items in some situations
* **Preserved Blocks Fix:** Prevents HWYLA/TOP crashes with preserved blocks
* **Fix Quake Hammer Texture:** Fixes the Quake Hammer using the incorrect config option to control its size
* **EvilCraft**
* **Vengeance Spirit Regex Cache:** Cache the result of Vengeance Spirit checks against the config, which may attempt to build and check against hundreds of Regex Patterns every tick
* **The Farlanders**
* **Duplication Fixes:** Fixes various duplication exploits
* **Thermal Expansion**
Expand Down
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ final def mod_dependencies = [
'curse.maven:compactmachines-224218:2707509' : [debug_compact_machines],
'curse.maven:cqrepoured-303422:3953103' : [debug_cqrepoured],
'curse.maven:ctm-267602:2915363' : [debug_chisel],
'curse.maven:cyclops-core-232758:3159497' : [debug_evilcraft],
'curse.maven:effortlessbuilding-302113:2847346' : [debug_effortless_building],
'curse.maven:elementary-staffs-346007:2995593' : [debug_elementary_staffs],
'curse.maven:elenaidodge2-442962:3343308' : [debug_elenai_dodge_2],
'curse.maven:emojicord-349107:4000684' : [debug_emojicord],
'curse.maven:enderstorage-245174:2755787' : [debug_enderstorage],
'curse.maven:epic-siege-mod-229449:3356157' : [debug_epic_siege_mod],
'curse.maven:evilcraft-74610:2811267' : [debug_evilcraft],
'curse.maven:extrautilities-225561:2678374' : [debug_extra_utilities_2],
'curse.maven:forestry-59751:2918418' : [debug_forestry, debug_binnies_mods],
'curse.maven:forgemultipartcbe-258426:2755790' : [debug_forgemultipartcbe, debug_project_red],
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ debug_enderio = false
debug_enderstorage = false
debug_epic_siege_mod = false
debug_erebus = false
debug_evilcraft = false
debug_extra_utilities_2 = false
debug_forestry = false
debug_forgemultipartcbe = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public class UTConfigMods
@Config.Name("The Erebus")
public static final ErebusCategory EREBUS = new ErebusCategory();

@Config.LangKey("cfg.universaltweaks.modintegration.evilcraft")
@Config.Name("EvilCraft")
public static final EvilCraftCategory EVIL_CRAFT = new EvilCraftCategory();

@Config.LangKey("cfg.universaltweaks.modintegration.extrautilities")
@Config.Name("Extra Utilities 2")
public static final ExtraUtilitiesCategory EXTRA_UTILITIES = new ExtraUtilitiesCategory();
Expand Down Expand Up @@ -562,6 +566,14 @@ public static class ErebusCategory
public boolean utFixQuakeHammerTexture = true;
}

public static class EvilCraftCategory
{
@Config.RequiresMcRestart
@Config.Name("Vengeance Spirit Regex Cache")
@Config.Comment("Cache the result of Vengeance Spirit checks against the config, which may attempt to build and check against hundreds of Regex Patterns every tick")
public boolean utVengeanceSpiritCache = true;
}

public static class ExtraUtilitiesCategory
{
@Config.RequiresMcRestart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class UTMixinLoader implements ILateMixinLoader
put("mixins.mods.erebus.cabbage.json", () -> loaded("erebus") && UTConfigMods.EREBUS.utCabbageDrop);
put("mixins.mods.erebus.json", () -> loaded("erebus"));
put("mixins.mods.erebus.quakehammer.json", () -> loaded("erebus") && UTConfigMods.EREBUS.utFixQuakeHammerTexture);
put("mixins.mods.evilcraft.vengeancespirit.json", () -> loaded("evilcraft") && UTConfigMods.EVIL_CRAFT.utVengeanceSpiritCache);
put("mixins.mods.extrautilities.breakcreativemill.json", () -> loaded("extrautils2") && UTConfigMods.EXTRA_UTILITIES.utFixCreativeMillHarvestability);
put("mixins.mods.extrautilities.deepdarkstats.json", () -> loaded("extrautils2") && UTConfigMods.EXTRA_UTILITIES.utDeepDarkStats);
put("mixins.mods.extrautilities.dupes.json", () -> loaded("extrautils2") && UTConfigMods.EXTRA_UTILITIES.utDuplicationFixesToggle);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package mod.acgaming.universaltweaks.mods.evilcraft.vengeancespirit.mixin;

import net.minecraft.util.ResourceLocation;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.sugar.Local;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import org.cyclops.evilcraft.entity.monster.VengeanceSpirit;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

// Courtesy of WaitingIdly
@Mixin(value = VengeanceSpirit.class, remap = false)
public class UTVengeanceSpiritMixin
{
@Unique
private static final Object2BooleanMap<ResourceLocation> REGEX_CACHE_MAP = new Object2BooleanOpenHashMap<>();

/**
* @author WaitingIdly
* @reason check if the ResourceLocation for the target entity is cached, and use it if so
*/
@Inject(method = {"canSustain", "canSustainClass"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ResourceLocation;toString()Ljava/lang/String;", remap = true), cancellable = true)
private static void utUseCache(CallbackInfoReturnable<Boolean> cir, @Local ResourceLocation id)
{
if (REGEX_CACHE_MAP.containsKey(id)) cir.setReturnValue(REGEX_CACHE_MAP.getBoolean(id));
}

/**
* @author WaitingIdly
* @reason cache the return result
*/
@ModifyReturnValue(method = {"canSustain", "canSustainClass"}, at = @At("RETURN"))
private static boolean utStoreReturnValue(boolean original, @Local ResourceLocation id)
{
REGEX_CACHE_MAP.put(id, original);
return original;
}

/**
* @author WaitingIdly
* @reason clear the cache when reloading the blacklist
*/
@Inject(method = "setBlacklist", at = @At("HEAD"))
private static void utClearCache(CallbackInfo ci)
{
REGEX_CACHE_MAP.clear();
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/universaltweaks/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ cfg.universaltweaks.modintegration.emojicord=Emojicord
cfg.universaltweaks.modintegration.enderio=Ender IO
cfg.universaltweaks.modintegration.enderstorage=Ender Storage
cfg.universaltweaks.modintegration.erebus=The Erebus
cfg.universaltweaks.modintegration.evilcraft=EvilCraft
cfg.universaltweaks.modintegration.esm=Epic Siege Mod
cfg.universaltweaks.modintegration.extrautilities=Extra Utilities 2
cfg.universaltweaks.modintegration.forestry=Forestry
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/mixins.mods.evilcraft.vengeancespirit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.mods.evilcraft.vengeancespirit.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTVengeanceSpiritMixin"]
}
Loading