diff --git a/src/main/java/club/mcams/carpet/AmsServer.java b/src/main/java/club/mcams/carpet/AmsServer.java index c6e72680..24680495 100644 --- a/src/main/java/club/mcams/carpet/AmsServer.java +++ b/src/main/java/club/mcams/carpet/AmsServer.java @@ -137,13 +137,13 @@ public void onServerLoaded(MinecraftServer server) { } @Override - public void onServerClosed(MinecraftServer minecraftServer) { - CraftingRuleUtil.clearAmsDatapacks(minecraftServer); + public void onServerClosed(MinecraftServer server) { + CraftingRuleUtil.clearAmsDatapacks(server); } @Override - public void onServerLoadedWorlds(MinecraftServer minecraftServer) { - CraftingRuleUtil.loadAmsDatapacks(minecraftServer); + public void onServerLoadedWorlds(MinecraftServer server) { + CraftingRuleUtil.loadAmsDatapacks(server); } @Override diff --git a/src/main/java/club/mcams/carpet/AmsServerSettings.java b/src/main/java/club/mcams/carpet/AmsServerSettings.java index d48aebfa..a9c498d7 100644 --- a/src/main/java/club/mcams/carpet/AmsServerSettings.java +++ b/src/main/java/club/mcams/carpet/AmsServerSettings.java @@ -31,6 +31,7 @@ //#if MC>=12000 //$$ import club.mcams.carpet.validators.rule.easyGetPitcherPod.CountValidator; //#endif +import club.mcams.carpet.validators.rule.renewableNetherScrap.DropRateValidator; import club.mcams.carpet.settings.CraftingRule; import club.mcams.carpet.settings.Rule; @@ -437,6 +438,17 @@ public class AmsServerSettings { ) public static String commandGetPlayerSkull = "false"; + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean quickVillagerLevelUp = false; + + @Rule( + options = {"0.0", "0.01", "0.1", "1.0"}, + categories = {AMS, FEATURE, SURVIVAL}, + validators = DropRateValidator.class, + strict = false + ) + public static double renewableNetheriteScrap = 0.0D; + /* * 区块加载规则 */ diff --git a/src/main/java/club/mcams/carpet/utils/compat/LiteralTextUtil.java b/src/main/java/club/mcams/carpet/mixin/rule/quickVillagerLevelUp/VillagerEntityInvoker.java similarity index 51% rename from src/main/java/club/mcams/carpet/utils/compat/LiteralTextUtil.java rename to src/main/java/club/mcams/carpet/mixin/rule/quickVillagerLevelUp/VillagerEntityInvoker.java index 7a26ba66..0eac2a2e 100644 --- a/src/main/java/club/mcams/carpet/utils/compat/LiteralTextUtil.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/quickVillagerLevelUp/VillagerEntityInvoker.java @@ -2,7 +2,7 @@ * This file is part of the Carpet AMS Addition project, licensed under the * GNU Lesser General Public License v3.0 * - * Copyright (C) 2023 A Minecraft Server and contributors + * 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 @@ -11,27 +11,26 @@ * * 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 + * 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 . + * along with Carpet AMS Addition. If not, see . */ -package club.mcams.carpet.utils.compat; +package club.mcams.carpet.mixin.rule.quickVillagerLevelUp; -import net.minecraft.text.*; +import net.minecraft.entity.passive.VillagerEntity; +import net.minecraft.village.VillagerData; -public class LiteralTextUtil { - //#if MC<11900 - public static LiteralText compatText(String text) { - return new LiteralText(text); - } - //#endif +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; - //#if MC>=11900 - //$$ public static MutableText compatText(String text) { - //$$ return Text.literal(text); - //$$ } - //#endif +@Mixin(VillagerEntity.class) +public interface VillagerEntityInvoker { + @Invoker("levelUp") + void invokerLevelUp(); + + @Invoker("getVillagerData") + VillagerData invokerGetVillagerData(); } diff --git a/src/main/java/club/mcams/carpet/mixin/rule/quickVillagerLevelUp/VillagerEntityMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/quickVillagerLevelUp/VillagerEntityMixin.java new file mode 100644 index 00000000..6e9346cb --- /dev/null +++ b/src/main/java/club/mcams/carpet/mixin/rule/quickVillagerLevelUp/VillagerEntityMixin.java @@ -0,0 +1,40 @@ +/* + * 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.quickVillagerLevelUp; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.entity.passive.VillagerEntity; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(VillagerEntity.class) +public abstract class VillagerEntityMixin implements VillagerEntityInvoker{ + @Inject(method = "getExperience", at = @At("HEAD")) + private void quickLevelUp(CallbackInfoReturnable cir) { + if (AmsServerSettings.quickVillagerLevelUp && this.invokerGetVillagerData().getLevel() < 5) { + this.invokerLevelUp(); + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/renewableNetherScrap/EntityMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/renewableNetherScrap/EntityMixin.java new file mode 100644 index 00000000..45cc7794 --- /dev/null +++ b/src/main/java/club/mcams/carpet/mixin/rule/renewableNetherScrap/EntityMixin.java @@ -0,0 +1,66 @@ +/* + * 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.renewableNetherScrap; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.ItemEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.entity.mob.ZombifiedPiglinEntity; + +import org.jetbrains.annotations.Nullable; + +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.CallbackInfoReturnable; + +@Mixin(Entity.class) +public abstract class EntityMixin { + + @Shadow + @Nullable + public abstract ItemEntity dropStack(ItemStack stack, float yOffset); + + @Unique + private boolean isFirstDrop = true; + + @Inject(method = "dropStack(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/entity/ItemEntity;", at = @At("TAIL"), cancellable = true) + private void dropNetheriteScrap(CallbackInfoReturnable cir) { + if (AmsServerSettings.renewableNetheriteScrap != 0.0D && isFirstDrop) { + Entity entity = (Entity) (Object) this; + if (entity instanceof ZombifiedPiglinEntity && !((ZombifiedPiglinEntity) entity).isBaby()) { + double random = Math.random(); + double rate = AmsServerSettings.renewableNetheriteScrap; + if (random < rate) { + ItemStack netherScrapStack = new ItemStack(Items.NETHERITE_SCRAP); + ItemEntity netherScrapItemEntity = this.dropStack(netherScrapStack, 1.1F); + isFirstDrop = false; + cir.setReturnValue(netherScrapItemEntity); + } + } + } + } +} diff --git a/src/main/java/club/mcams/carpet/validators/rule/renewableNetherScrap/DropRateValidator.java b/src/main/java/club/mcams/carpet/validators/rule/renewableNetherScrap/DropRateValidator.java new file mode 100644 index 00000000..fba418da --- /dev/null +++ b/src/main/java/club/mcams/carpet/validators/rule/renewableNetherScrap/DropRateValidator.java @@ -0,0 +1,42 @@ +/* + * 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.validators.rule.renewableNetherScrap; + +import carpet.settings.ParsedRule; +import carpet.settings.Validator; + +import club.mcams.carpet.translations.Translator; + +import net.minecraft.server.command.ServerCommandSource; + +public class DropRateValidator extends Validator { + private static final Translator translator = new Translator("validator.renewableNetherScrap"); + + @Override + public Double validate(ServerCommandSource serverCommandSource, ParsedRule parsedRule, Double aDouble, String s) { + return aDouble >= 0.0D && aDouble <= 1.0D ? aDouble : null; + } + + @Override + public String description() { + return translator.tr("value_range").getString(); + } +} diff --git a/src/main/resources/amscarpet.mixins.json b/src/main/resources/amscarpet.mixins.json index 94c1a4b6..92742966 100644 --- a/src/main/resources/amscarpet.mixins.json +++ b/src/main/resources/amscarpet.mixins.json @@ -102,10 +102,13 @@ "rule.preventAdministratorCheat.TeleportCommandMixin", "rule.preventAdministratorCheat.TimeCommandMixin", "rule.preventAdministratorCheat.WeatherCommandMixin", + "rule.quickVillagerLevelUp.VillagerEntityInvoker", + "rule.quickVillagerLevelUp.VillagerEntityMixin", "rule.redstoneComponentSound.DaylightDetectorBlockMixin", "rule.redstoneComponentSound.RedstoneWireBlockMixin", "rule.redstoneComponentSound.RepeaterBlockMixin", "rule.regeneratingDragonEgg.EnderDragonFightMixin", + "rule.renewableNetherScrap.EntityMixin", "rule.safeFlight_invulnerable.ServerPlayerEntityMixin", "rule.safePointedDripstone.PointedDripstoneBlockMixin", "rule.scheduledRandomTick.AbstractPlantPartBlockMixin", @@ -142,7 +145,8 @@ "rule.bedRockFlying.ClientPlayerEntityMixin", "rule.maxClientInteractionReachDistance.ClientPlayerInteractionManagerMixin", "rule.maxClientInteractionReachDistance.GameRendererMixin", - "rule.maxPlayerInteractionRange.GameRendererMixin" + "rule.maxPlayerInteractionRange.GameRendererMixin", + "rule.test.TextFieldWidgetMixin" ], "server": [], "injectors": { diff --git a/src/main/resources/assets/carpetamsaddition/lang/en_us.yml b/src/main/resources/assets/carpetamsaddition/lang/en_us.yml index f2e9a71f..d2954c8c 100644 --- a/src/main/resources/assets/carpetamsaddition/lang/en_us.yml +++ b/src/main/resources/assets/carpetamsaddition/lang/en_us.yml @@ -102,6 +102,8 @@ carpetamsaddition: value_range: 'The value must be 1 - 32' easyGetPitcherPod: value_range: 'The value must be 2 - 100 or 0' + renewableNetherScrap: + value_range: 'The value must be 0 - 1' carpet_translations: category: @@ -378,6 +380,12 @@ carpetamsaddition: desc: When a player dies, they will drop their own skull commandGetPlayerSkull: desc: Use the "/getPlayerSkull" command to get a online player skull + quickVillagerLevelUp: + desc: Each time the trading screen is opened, the villager will level up + renewableNetheriteScrap: + desc: Customize the drop rate of netherite scrap from zombified piglin + extra: + '0': 'The range of values: 0 - 1' # 计划刻催熟规则: scheduledRandomTickCactus: diff --git a/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml b/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml index 3533f978..78e2c006 100644 --- a/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml +++ b/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml @@ -102,6 +102,8 @@ carpetamsaddition: value_range: '设定的值必须为 1 - 32' easyGetPitcherPod: value_range: '设定的值必须为 1 - 100 或 0' + renewableNetherScrap: + value_range: '设定的值必须为 0 - 1' carpet_translations: category: @@ -468,6 +470,14 @@ carpetamsaddition: commandGetPlayerSkull: name: 获取玩家头颅 desc: 使用 “/getPlayerSkull” 命令来获取一名在线玩家的头颅 + quickVillagerLevelUp: + name: 快速升级村民 + desc: 每次打开交易屏幕时村民都会升级 + renewableNetheriteScrap: + name: 可再生下界合金碎片 + desc: 自定义僵尸猪灵掉落下界合金碎片的概率 + extra: + '0': '允许设定的范围:0 - 1' # 计划刻催熟规则: scheduledRandomTickCactus: