Skip to content

Commit

Permalink
✅ 新增规则
Browse files Browse the repository at this point in the history
  • Loading branch information
1024-byteeeee committed May 17, 2024
1 parent b58269c commit 5cb025a
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/main/java/club/mcams/carpet/AmsServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/club/mcams/carpet/AmsServerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/*
* 区块加载规则
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <https://www.gnu.org/licenses/>.
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

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();
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<Integer> cir) {
if (AmsServerSettings.quickVillagerLevelUp && this.invokerGetVillagerData().getLevel() < 5) {
this.invokerLevelUp();
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<ItemEntity> 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);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<Double> {
private static final Translator translator = new Translator("validator.renewableNetherScrap");

@Override
public Double validate(ServerCommandSource serverCommandSource, ParsedRule<Double> parsedRule, Double aDouble, String s) {
return aDouble >= 0.0D && aDouble <= 1.0D ? aDouble : null;
}

@Override
public String description() {
return translator.tr("value_range").getString();
}
}
6 changes: 5 additions & 1 deletion src/main/resources/amscarpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -142,7 +145,8 @@
"rule.bedRockFlying.ClientPlayerEntityMixin",
"rule.maxClientInteractionReachDistance.ClientPlayerInteractionManagerMixin",
"rule.maxClientInteractionReachDistance.GameRendererMixin",
"rule.maxPlayerInteractionRange.GameRendererMixin"
"rule.maxPlayerInteractionRange.GameRendererMixin",
"rule.test.TextFieldWidgetMixin"
],
"server": [],
"injectors": {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/assets/carpetamsaddition/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ carpetamsaddition:
value_range: '设定的值必须为 1 - 32'
easyGetPitcherPod:
value_range: '设定的值必须为 1 - 100 或 0'
renewableNetherScrap:
value_range: '设定的值必须为 0 - 1'

carpet_translations:
category:
Expand Down Expand Up @@ -468,6 +470,14 @@ carpetamsaddition:
commandGetPlayerSkull:
name: 获取玩家头颅
desc: 使用 “/getPlayerSkull” 命令来获取一名在线玩家的头颅
quickVillagerLevelUp:
name: 快速升级村民
desc: 每次打开交易屏幕时村民都会升级
renewableNetheriteScrap:
name: 可再生下界合金碎片
desc: 自定义僵尸猪灵掉落下界合金碎片的概率
extra:
'0': '允许设定的范围:0 - 1'

# 计划刻催熟规则:
scheduledRandomTickCactus:
Expand Down

0 comments on commit 5cb025a

Please sign in to comment.