Skip to content

Commit

Permalink
✅ 新增规则
Browse files Browse the repository at this point in the history
  • Loading branch information
1024-byteeeee committed Apr 23, 2024
1 parent 66799d1 commit ae12aea
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 14 deletions.
20 changes: 16 additions & 4 deletions src/main/java/club/mcams/carpet/AmsServerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public class AmsServerSettings {
public static boolean carpetAlwaysSetDefault = false;

//#if MC>=11900
@GameVersion(version = "Minecraft >= 1.19")
//$$ @GameVersion(version = "Minecraft >= 1.19")
//$$ @Rule(categories = {AMS, EXPERIMENTAL})
//$$ public static boolean experimentalContentCheckDisabled = false;
//#endif
Expand All @@ -355,7 +355,7 @@ public class AmsServerSettings {
public static boolean fertilizableSmallFlower = false;

@Rule(categories = {AMS, FEATURE, SURVIVAL})
public static boolean harmlessPointedDripstone = false;
public static boolean safePointedDripstone = false;

//#if MC>=11700
@GameVersion(version = "Minecraft >= 1.17")
Expand All @@ -376,7 +376,7 @@ public class AmsServerSettings {
public static boolean ironGolemNoDropFlower = false;

//#if MC>=12000
@GameVersion(version = "Minecraft >= 1.20")
//$$ @GameVersion(version = "Minecraft >= 1.20")
//$$ @Rule(
//$$ options = {"0"},
//$$ categories = {AMS, FEATURE, SURVIVAL},
Expand All @@ -392,6 +392,18 @@ public class AmsServerSettings {
)
public static String commandGoto = "false";

@Rule(
options = {"false", "all", "realPlayerOnly", "fakePlayerOnly"},
categories = {AMS, SURVIVAL}
)
public static String sendPlayerDeathLocation = "false";

@Rule(categories = {AMS, FEATURE, SURVIVAL})
public static boolean perfectInvisibility = false;

@Rule(categories = {AMS, FEATURE, SURVIVAL})
public static boolean sneakInvisibility = false;

/*
* 区块加载规则
*/
Expand Down Expand Up @@ -483,7 +495,7 @@ public class AmsServerSettings {
//#endif

//#if MC>=12003
@GameVersion(version = "Minecraft 1.20.3 - 1.20.5")
//$$ @GameVersion(version = "Minecraft 1.20.3 - 1.20.5")
//$$ @SuppressWarnings("unused")
//$$ @CraftingRule(
//$$ recipes = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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.helpers.rule.sendPlayerDeathLocation;

import club.mcams.carpet.helpers.FakePlayerHelper;
import club.mcams.carpet.translations.Translator;
import club.mcams.carpet.utils.MessageTextEventUtils.ClickEventUtil;
import club.mcams.carpet.utils.MessageTextEventUtils.HoverEventUtil;
import club.mcams.carpet.utils.Messenger;
import club.mcams.carpet.utils.compat.DimensionWrapper;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.world.World;

public class PlayerDeathLocationContext {
private static final Translator translator = new Translator("rule.sendPlayerDeathLocation");

public static void sendMessage(MinecraftServer server, ServerPlayerEntity player, World world) {
final Text copyButton = copyButton(player);
String message = formatMessage(player, world);
Messenger.sendServerMessage(server, Messenger.s(message).formatted(Formatting.RED).append(copyButton));
}

public static void realPlayerSendMessage(MinecraftServer server, ServerPlayerEntity player, World world) {
if (!FakePlayerHelper.isFakePlayer(player)) {
sendMessage(server, player, world);
}
}

public static void fakePlayerSendMessage(MinecraftServer server, ServerPlayerEntity player, World world) {
if (FakePlayerHelper.isFakePlayer(player)) {
sendMessage(server, player, world);
}
}

private static String getPlayerName(ServerPlayerEntity player) {
return player.getName().getString();
}

private static DimensionWrapper getDimension(World world) {
return DimensionWrapper.of(world);
}

private static String getPlayerPos(ServerPlayerEntity player) {
return player.getBlockPos().getX() + ", " + player.getBlockPos().getY() + ", " + player.getBlockPos().getZ();
}

private static Text copyButton(ServerPlayerEntity player) {
BaseText hoverText = Messenger.s(translator.tr("copy").getString(), "y");
String copyCoordText = getPlayerPos(player).replace(",", ""); // 1, 0, -24 -> 1 0 -24

return
Messenger.s(" [C] ").setStyle(
Style.EMPTY.withColor(Formatting.GREEN).withBold(true).
withClickEvent(ClickEventUtil.event(ClickEventUtil.COPY_TO_CLIPBOARD, copyCoordText)).
withHoverEvent(HoverEventUtil.event(HoverEventUtil.SHOW_TEXT, hoverText))
);
}

// Alex 死亡位置 @ minecraft:overworld -> [ 888, 20, 999 ]
private static String formatMessage(ServerPlayerEntity player, World world) {
String playerName = getPlayerName(player);
DimensionWrapper dimension = getDimension(world);
return String.format(
"%s %s @ %s -> [ %s ]",
playerName,
translator.tr("location").getString(),
dimension,
getPlayerPos(player)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.perfectInvisibility_sneakInvisibility;

import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(Entity.class)
public interface EntityInvoker {
@Invoker("isInvisible")
boolean invokeIsInvisible();

@Invoker("isSneaky")
boolean invokeIsSneaky();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.perfectInvisibility_sneakInvisibility;

import club.mcams.carpet.AmsServerSettings;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;

import net.minecraft.entity.LivingEntity;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin implements EntityInvoker {
@ModifyReturnValue(method = "getAttackDistanceScalingFactor", at = @At("RETURN"))
private double modifyAttackDistanceScalingFactor(double original) {
if (AmsServerSettings.perfectInvisibility && this.invokeIsInvisible()) {
return 0.0D;
} else {
return original;
}
}

@ModifyReturnValue(method = "getAttackDistanceScalingFactor", at = @At("RETURN"))
private double sneakInvisibility(double original) {
if (AmsServerSettings.sneakInvisibility && this.invokeIsSneaky()) {
return 0.0D;
} else {
return original;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.sendPlayerDeathLocation;

import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ServerPlayerEntity.class)
public interface ServerPlayerEntityInvoker {
//#if MC>=12000
//$$ @Invoker("getServerWorld")
//#else
@Invoker("getWorld")
//#endif
ServerWorld invokeGetWorld();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.sendPlayerDeathLocation;

import club.mcams.carpet.AmsServer;
import club.mcams.carpet.AmsServerSettings;
import club.mcams.carpet.helpers.rule.sendPlayerDeathLocation.PlayerDeathLocationContext;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;

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.CallbackInfo;

import java.util.Objects;

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin implements ServerPlayerEntityInvoker {
@Inject(method = "onDeath", at = @At("TAIL"))
private void sendDeathLocation(CallbackInfo ci) {
if (!Objects.equals(AmsServerSettings.sendPlayerDeathLocation, "false")) {
MinecraftServer server = AmsServer.minecraftServer;
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
World world = this.invokeGetWorld();
switch (AmsServerSettings.sendPlayerDeathLocation) {
case "all":
PlayerDeathLocationContext.sendMessage(server, player, world);
break;
case "realPlayerOnly":
PlayerDeathLocationContext.realPlayerSendMessage(server, player, world);
break;
case "fakePlayerOnly":
PlayerDeathLocationContext.fakePlayerSendMessage(server, player, world);
break;
}
}
}
}
6 changes: 5 additions & 1 deletion src/main/resources/amscarpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"rule.foliageGenerateDisabled.FoliagePlacerMixin",
"rule.foliageGenerateDisabled.HugeFungusFeatureMixin",
"rule.ghastFireballExplosionDamageSourceFix.FireballEntityMixin",
"rule.harmlessPointedDripstone.PointedDripstoneBlockMixin",
"rule.safePointedDripstone.PointedDripstoneBlockMixin",
"rule.hopperSuctionDisabled.HopperBlockEntityMixin",
"rule.infiniteDurability.ItemStackMixin",
"rule.infiniteTrades.TradeOfferMixin",
Expand All @@ -79,6 +79,8 @@
"rule.noFamilyPlanning.PassiveEntityMixin",
"rule.optimizedDragonRespawn.BlockPatternTestTransformInvoker",
"rule.optimizedDragonRespawn.EnderDragonFightMixin",
"rule.perfectInvisibility_sneakInvisibility.EntityInvoker",
"rule.perfectInvisibility_sneakInvisibility.LivingEntityMixin",
"rule.playerNoNetherPortalCrossing.NetherPortalBlockMixin",
"rule.pointedDripstoneCollisionBoxDisabled.AbstractBlockStateMixin",
"rule.preventAdministratorCheat.AdvancementCommandMixin",
Expand Down Expand Up @@ -108,6 +110,8 @@
"rule.scheduledRandomTick.CactusBlockMixin",
"rule.scheduledRandomTick.ChorusFlowerBlockMixin",
"rule.scheduledRandomTick.SugarCaneBlockMixin",
"rule.sendPlayerDeathLocation.ServerPlayerEntityInvoker",
"rule.sendPlayerDeathLocation.ServerPlayerEntityMixin",
"rule.sensibleEnderman_endermanPickUpDisabled.PickUpBlockGoalMixin",
"rule.sharedVillagerDiscounts.GetValueForInvoker",
"rule.sharedVillagerDiscounts.VillagerGossipsMixin",
Expand Down
Loading

0 comments on commit ae12aea

Please sign in to comment.