From 32b378438fbef2de14f973cd1cbb153f223dcacb Mon Sep 17 00:00:00 2001 From: topi-banana Date: Sun, 8 Sep 2024 16:45:46 +0900 Subject: [PATCH] added rule "fixedTickMemoriesEntityAI" --- common.gradle | 2 +- .../vulpeus_carpet/VulpeusCarpetSettings.java | 10 ++- .../MixinMemory.java | 61 +++++++++++++++++++ .../vulpeus_carpet/utils/DummyClass.java | 24 ++++++++ .../assets/vulpeus_carpet/lang/en_us.yml | 3 + src/main/resources/vulpeus_carpet.mixins.json | 1 + versions/1.20.1/gradle.properties | 6 +- 7 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/mixins/fixedTickMemoriesEntityAI/MixinMemory.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/utils/DummyClass.java diff --git a/common.gradle b/common.gradle index dcdb654..322b14c 100644 --- a/common.gradle +++ b/common.gradle @@ -38,7 +38,7 @@ dependencies { // dependencies // library mods - include(modImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_api_version))) +// include(modImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_api_version))) include(modImplementation("me.fallenbreath:conditional-mixin-fabric:${project.conditionalmixin_version}")) include(annotationProcessor(implementation("io.github.llamalad7:mixinextras-fabric:${project.mixinextras_version}"))) diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetSettings.java b/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetSettings.java index df79499..6d0f4d0 100644 --- a/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetSettings.java +++ b/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetSettings.java @@ -20,9 +20,7 @@ package com.vulpeus.vulpeus_carpet; -import static carpet.api.settings.RuleCategory.COMMAND; -import static carpet.api.settings.RuleCategory.OPTIMIZATION; -import static carpet.api.settings.RuleCategory.SURVIVAL; +import static carpet.api.settings.RuleCategory.*; import carpet.api.settings.Rule; @@ -48,6 +46,12 @@ public class VulpeusCarpetSettings { @Rule(categories = {VULPEUS}) public static boolean disableSOECrash = false; + //#if MC<=12001 + //$$ @Rule(categories = {BUGFIX, VULPEUS}) + //#endif + public static boolean fixedTickMemoriesEntityAI = false; + @Rule(categories = {OPTIMIZATION, VULPEUS}) public static boolean optimizedDragonRespawn = false; + } diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/mixins/fixedTickMemoriesEntityAI/MixinMemory.java b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/fixedTickMemoriesEntityAI/MixinMemory.java new file mode 100644 index 0000000..21ba4b7 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/fixedTickMemoriesEntityAI/MixinMemory.java @@ -0,0 +1,61 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 VulpeusServer and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.mixins.fixedTickMemoriesEntityAI; + +import com.vulpeus.vulpeus_carpet.VulpeusCarpetSettings; +import me.fallenbreath.conditionalmixin.api.annotation.Condition; +import me.fallenbreath.conditionalmixin.api.annotation.Restriction; +import net.minecraft.entity.ai.brain.Memory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +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; + +@Restriction(require = @Condition(value = "minecraft", versionPredicates = "<=1.20.1")) +@Mixin(Memory.class) +public abstract class MixinMemory { + + @Unique + private boolean tickFlag = false; + + @Shadow + public abstract void tick(); + + @Inject(method = "isExpired", at = @At(value = "HEAD", target = "Lnet/minecraft/entity/ai/brain/Brain;tickMemories()V")) + public void isExpired(CallbackInfoReturnable cir) { + if (VulpeusCarpetSettings.fixedTickMemoriesEntityAI) { + this.tickFlag = true; + tick(); + } + } + + @Inject(method = "tick", at = @At(value = "HEAD", target = "Lnet/minecraft/entity/ai/brain/Brain;tickMemories()V"), cancellable = true) + public void tick(CallbackInfo ci) { + if (VulpeusCarpetSettings.fixedTickMemoriesEntityAI && this.tickFlag) { + this.tickFlag = false; + ci.cancel(); + } + } + +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/utils/DummyClass.java b/src/main/java/com/vulpeus/vulpeus_carpet/utils/DummyClass.java new file mode 100644 index 0000000..9ad2e2d --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/utils/DummyClass.java @@ -0,0 +1,24 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 VulpeusServer and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.utils; + +public class DummyClass { +} diff --git a/src/main/resources/assets/vulpeus_carpet/lang/en_us.yml b/src/main/resources/assets/vulpeus_carpet/lang/en_us.yml index 43ce8ac..3220dd4 100644 --- a/src/main/resources/assets/vulpeus_carpet/lang/en_us.yml +++ b/src/main/resources/assets/vulpeus_carpet/lang/en_us.yml @@ -21,5 +21,8 @@ carpet: disableSOECrash: desc: yeet the server crash caused by StackOverflowError. + fixedTickMemoriesEntityAI: + desc: fixed MC-254100 + optimizedDragonRespawn: desc: Optimize dragon respawn method. Ported from carpet AMS addition. \ No newline at end of file diff --git a/src/main/resources/vulpeus_carpet.mixins.json b/src/main/resources/vulpeus_carpet.mixins.json index 53087bd..a9fab2c 100644 --- a/src/main/resources/vulpeus_carpet.mixins.json +++ b/src/main/resources/vulpeus_carpet.mixins.json @@ -6,6 +6,7 @@ "mixins": [ "commandSit.MixinArmorStandEntity", "disableCrash.MixinMinecraftServer", + "fixedTickMemoriesEntityAI.MixinMemory", "optimizedDragonRespawn.IMixinBlockPatternTestTransform", "optimizedDragonRespawn.MixinEnderDragonFight", "playerActions.PlayerCommandMixin", diff --git a/versions/1.20.1/gradle.properties b/versions/1.20.1/gradle.properties index af3e41c..bb3512b 100644 --- a/versions/1.20.1/gradle.properties +++ b/versions/1.20.1/gradle.properties @@ -1,10 +1,10 @@ # Fabric Properties # check these on https://fallen-breath.github.io/fabric-versions/?&version=1.20.1 minecraft_version=1.20.1 - yarn_mappings=1.20.1+build.10 + yarn_mappings=1.20.1+build.2 # Fabric Mod Metadata - minecraft_dependency=>=1.20.1 + minecraft_dependency=>=1.20 # Build Information # The target mc versions for the mod during mod publishing, separated with \n @@ -12,4 +12,4 @@ # Dependencies fabric_api_version=0.92.2+1.20.1 - carpet_version=1.20.2-1.4.118+v230921 \ No newline at end of file + carpet_version=1.20-1.4.112+v230608 \ No newline at end of file