From 90fbf2dc9512c5fdf34c016b8131a0014d32a6ba Mon Sep 17 00:00:00 2001 From: 1024_byteeeee <2270484921@qq.com> Date: Thu, 22 Aug 2024 12:16:25 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=B7=BB=E5=8A=A0stro?= =?UTF-8?q?ngLeash=E8=A7=84=E5=88=99=20#120?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../club/mcams/carpet/AmsServerSettings.java | 3 ++ .../rule/strongLeash/LeashableMixin.java | 31 ++++++++++++ .../strongLeash/PathAwareEntityMixin.java | 48 +++++++++++++++++++ src/main/resources/amscarpet.mixins.json | 2 + .../assets/carpetamsaddition/lang/en_us.yml | 2 + .../assets/carpetamsaddition/lang/zh_cn.yml | 3 ++ .../rule/strongLeash/LeashableMixin.java | 48 +++++++++++++++++++ .../strongLeash/PathAwareEntityMixin.java | 31 ++++++++++++ 8 files changed, 168 insertions(+) create mode 100644 src/main/java/club/mcams/carpet/mixin/rule/strongLeash/LeashableMixin.java create mode 100644 src/main/java/club/mcams/carpet/mixin/rule/strongLeash/PathAwareEntityMixin.java create mode 100644 versions/1.21.1/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/LeashableMixin.java create mode 100644 versions/1.21.1/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/PathAwareEntityMixin.java diff --git a/src/main/java/club/mcams/carpet/AmsServerSettings.java b/src/main/java/club/mcams/carpet/AmsServerSettings.java index 19c3574d..b825f876 100644 --- a/src/main/java/club/mcams/carpet/AmsServerSettings.java +++ b/src/main/java/club/mcams/carpet/AmsServerSettings.java @@ -489,6 +489,9 @@ public class AmsServerSettings { @Rule(categories = {AMS, FEATURE, BUGFIX}) public static boolean fakePlayerInteractLikeClient = false; + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean strongLeash = false; + /* * 区块加载规则 */ diff --git a/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/LeashableMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/LeashableMixin.java new file mode 100644 index 00000000..2e48b4aa --- /dev/null +++ b/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/LeashableMixin.java @@ -0,0 +1,31 @@ +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 A Minecraft Server and contributors + * + * Carpet AMS Addition 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. + * + * Carpet AMS Addition 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 Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.strongLeash; + +import club.mcams.carpet.utils.compat.DummyInterface; + +import org.spongepowered.asm.mixin.Mixin; + +import top.byteeeee.annotationtoolbox.annotation.GameVersion; + +@GameVersion(version = "Minecraft >= 1.21.1") +@Mixin(DummyInterface.class) +public interface LeashableMixin {} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/PathAwareEntityMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/PathAwareEntityMixin.java new file mode 100644 index 00000000..84fd3116 --- /dev/null +++ b/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/PathAwareEntityMixin.java @@ -0,0 +1,48 @@ +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 A Minecraft Server and contributors + * + * Carpet AMS Addition 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. + * + * Carpet AMS Addition 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 Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.strongLeash; + +import club.mcams.carpet.AmsServerSettings; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; + +import net.minecraft.entity.mob.PathAwareEntity; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import top.byteeeee.annotationtoolbox.annotation.GameVersion; + +@GameVersion(version = "Minecraft < 1.21.1") +@Mixin(PathAwareEntity.class) +public abstract class PathAwareEntityMixin { + @ModifyExpressionValue( + method = "updateLeash", + at = @At( + value = "CONSTANT", + args = "floatValue=10.0F" + ), + require = 1 + ) + private float modifyMaxLeashDetachDistance(float original) { + return AmsServerSettings.strongLeash ? Math.max(original, Float.MAX_VALUE) : original; + } +} diff --git a/src/main/resources/amscarpet.mixins.json b/src/main/resources/amscarpet.mixins.json index 99f10372..898604fb 100644 --- a/src/main/resources/amscarpet.mixins.json +++ b/src/main/resources/amscarpet.mixins.json @@ -136,6 +136,8 @@ "rule.softBlock.AbstractBlockMixin", "rule.softBlock.AbstractBlockStateInvoker", "rule.stackableDiscount.VillageGossipTypeAccessor", + "rule.strongLeash.LeashableMixin", + "rule.strongLeash.PathAwareEntityMixin", "rule.superBow.EnchantmentMixin", "rule.superBow.InfinityEnchantmentMixin", "rule.undyingCoral.CoralBlockBlockMixin", diff --git a/src/main/resources/assets/carpetamsaddition/lang/en_us.yml b/src/main/resources/assets/carpetamsaddition/lang/en_us.yml index d0004666..74d840f3 100644 --- a/src/main/resources/assets/carpetamsaddition/lang/en_us.yml +++ b/src/main/resources/assets/carpetamsaddition/lang/en_us.yml @@ -407,6 +407,8 @@ carpetamsaddition: '0': 'Requires client support' fakePlayerInteractLikeClient: desc: Fix some cases that fake player interact differently from the client + strongLeash: + desc: The leash will not break due to excessive distance # 计划刻催熟规则: scheduledRandomTickCactus: diff --git a/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml b/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml index 93d5793e..519d619e 100644 --- a/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml +++ b/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml @@ -504,6 +504,9 @@ carpetamsaddition: fakePlayerInteractLikeClient: name: 假人交互同步客户端行为 desc: 修复几个假人和盔甲架、矿车、船在特定情况下与客户端相应行为结果不一样的问题 + strongLeash: + name: 强力拴绳 + desc: 使拴绳不会因为距离过远而断裂 # 计划刻催熟规则: scheduledRandomTickCactus: diff --git a/versions/1.21.1/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/LeashableMixin.java b/versions/1.21.1/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/LeashableMixin.java new file mode 100644 index 00000000..97b89f37 --- /dev/null +++ b/versions/1.21.1/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/LeashableMixin.java @@ -0,0 +1,48 @@ +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 A Minecraft Server and contributors + * + * Carpet AMS Addition 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. + * + * Carpet AMS Addition 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 Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.strongLeash; + +import club.mcams.carpet.AmsServerSettings; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; + +import net.minecraft.entity.Leashable; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import top.byteeeee.annotationtoolbox.annotation.GameVersion; + +@GameVersion(version = "Minecraft >= 1.21.1") +@Mixin(Leashable.class) +public interface LeashableMixin { + @ModifyExpressionValue( + method = "tickLeash", + at = @At( + value = "CONSTANT", + args = "doubleValue=10.0F" + ), + require = 1 + ) + private static double modifyMaxLeashDetachDistance(double original) { + return AmsServerSettings.strongLeash ? Math.max(original, Double.MAX_VALUE) : original; + } +} diff --git a/versions/1.21.1/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/PathAwareEntityMixin.java b/versions/1.21.1/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/PathAwareEntityMixin.java new file mode 100644 index 00000000..ba21c629 --- /dev/null +++ b/versions/1.21.1/src/main/java/club/mcams/carpet/mixin/rule/strongLeash/PathAwareEntityMixin.java @@ -0,0 +1,31 @@ +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 A Minecraft Server and contributors + * + * Carpet AMS Addition 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. + * + * Carpet AMS Addition 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 Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.strongLeash; + +import club.mcams.carpet.utils.compat.DummyClass; + +import org.spongepowered.asm.mixin.Mixin; + +import top.byteeeee.annotationtoolbox.annotation.GameVersion; + +@GameVersion(version = "Minecraft < 1.21.1") +@Mixin(DummyClass.class) +public abstract class PathAwareEntityMixin {}