From 31837d427d88b2731ee6e402701e50c61952c0da Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 27 Nov 2024 23:03:48 +0000 Subject: [PATCH] Add fishingManipulation config --- .../earthcomputer/clientcommands/Configs.java | 17 ++++++- .../command/VillagerCommand.java | 48 ++++++++++++++----- .../features/VillagerCracker.java | 14 ++++-- .../assets/clientcommands/lang/en_us.json | 1 + 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/Configs.java b/src/main/java/net/earthcomputer/clientcommands/Configs.java index e31d84f7..c99d8c77 100644 --- a/src/main/java/net/earthcomputer/clientcommands/Configs.java +++ b/src/main/java/net/earthcomputer/clientcommands/Configs.java @@ -6,6 +6,7 @@ import net.earthcomputer.clientcommands.features.FishingCracker; import net.earthcomputer.clientcommands.features.PlayerRandCracker; import net.earthcomputer.clientcommands.features.ServerBrandManager; +import net.earthcomputer.clientcommands.features.VillagerCracker; import net.earthcomputer.clientcommands.util.MultiVersionCompat; import net.minecraft.util.Mth; import net.minecraft.util.StringRepresentable; @@ -174,7 +175,21 @@ public enum PacketDumpMethod { @Config public static int maximumPacketFieldDepth = 10; - @Config(temporary = true, setter = @Config.Setter("setMaxVillagerBruteForceSimulationTicks")) + @Config(setter = @Config.Setter("setVillagerManipulation"), temporary = true) + private static boolean villagerManipulation = false; + public static boolean getVillagerManipulation() { + return villagerManipulation; + } + public static void setVillagerManipulation(boolean villagerManipulation) { + Configs.villagerManipulation = villagerManipulation; + if (villagerManipulation) { + ServerBrandManager.rngWarning(); + } else { + VillagerCracker.reset(); + } + } + + @Config(setter = @Config.Setter("setMaxVillagerBruteForceSimulationTicks"), temporary = true) public static int maxVillagerBruteForceSimulationTicks = 12000; public static void setMaxVillagerBruteForceSimulationTicks(int maxVillagerBruteForceSimulationTicks) { Configs.maxVillagerBruteForceSimulationTicks = Mth.clamp(maxVillagerBruteForceSimulationTicks, 0, 1_000_000); diff --git a/src/main/java/net/earthcomputer/clientcommands/command/VillagerCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/VillagerCommand.java index cdbac1e4..9d80a128 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/VillagerCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/VillagerCommand.java @@ -38,6 +38,7 @@ import static dev.xpple.clientarguments.arguments.CBlockPosArgument.*; import static dev.xpple.clientarguments.arguments.CEntityArgument.*; import static dev.xpple.clientarguments.arguments.CRangeArgument.*; +import static net.earthcomputer.clientcommands.command.ClientCommandHelper.*; import static net.earthcomputer.clientcommands.command.arguments.ClientItemPredicateArgument.*; import static net.earthcomputer.clientcommands.command.arguments.ItemAndEnchantmentsPredicateArgument.*; import static net.earthcomputer.clientcommands.command.arguments.WithStringArgument.*; @@ -52,6 +53,10 @@ public class VillagerCommand { private static final SimpleCommandExceptionType ALREADY_RUNNING_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.cvillager.alreadyRunning")); private static final Dynamic2CommandExceptionType INVALID_GOAL_INDEX_EXCEPTION = new Dynamic2CommandExceptionType((index, length) -> Component.translatable("commands.cvillager.removeGoal.invalidIndex", index, length)); private static final Dynamic2CommandExceptionType ITEM_OVERSTACKED_EXCEPTION = new Dynamic2CommandExceptionType((item, stackSize) -> Component.translatable("arguments.item.overstacked", item, stackSize)); + private static final SimpleCommandExceptionType NEED_VILLAGER_MANIPULATION_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.cvillager.needVillagerManipulation") + .withStyle(ChatFormatting.RED) + .append(" ") + .append(getCommandTextComponent("commands.client.enable", "/cconfig clientcommands villagerManipulation set true"))); public static void register(CommandDispatcher dispatcher, CommandBuildContext context) { dispatcher.register(literal("cvillager") @@ -92,8 +97,6 @@ public static void register(CommandDispatcher dispatc .executes(ctx -> getClockPos()) .then(argument("pos", blockPos()) .executes(ctx -> setClockPos(ctx.getSource(), getBlockPos(ctx, "pos"))))) - .then(literal("reset-cracker") - .executes(ctx -> resetCracker())) .then(literal("start") .executes(ctx -> start(false)) .then(literal("first-level") @@ -119,6 +122,10 @@ private static int addGoal( checkStackSize(second, secondCount); } + if (!Configs.getVillagerManipulation()) { + throw NEED_VILLAGER_MANIPULATION_EXCEPTION.create(); + } + String firstString = first == null ? null : first.string() + " " + CUtil.boundsToString(firstCount); String secondString = second == null ? null : second.string() + " " + CUtil.boundsToString(secondCount); String resultString = result.string() + " " + CUtil.boundsToString(resultCount); @@ -148,7 +155,11 @@ private static void checkStackSize(WithStringArgument.Result style.withColor(ChatFormatting.RED))); } else { @@ -162,6 +173,10 @@ private static int listGoals(FabricClientCommandSource source) { } private static int removeGoal(FabricClientCommandSource source, int index) throws CommandSyntaxException { + if (!Configs.getVillagerManipulation()) { + throw NEED_VILLAGER_MANIPULATION_EXCEPTION.create(); + } + index = index - 1; if (index < VillagerCracker.goals.size()) { VillagerCracker.Goal goal = VillagerCracker.goals.remove(index); @@ -173,6 +188,10 @@ private static int removeGoal(FabricClientCommandSource source, int index) throw } private static int setVillagerTarget(@Nullable Entity target) throws CommandSyntaxException { + if (!Configs.getVillagerManipulation()) { + throw NEED_VILLAGER_MANIPULATION_EXCEPTION.create(); + } + if (target instanceof Villager villager) { VillagerCracker.setTargetVillager(villager); ClientCommandHelper.sendFeedback("commands.cvillager.target.set"); @@ -186,7 +205,11 @@ private static int setVillagerTarget(@Nullable Entity target) throws CommandSynt return Command.SINGLE_SUCCESS; } - private static int getClockPos() { + private static int getClockPos() throws CommandSyntaxException { + if (!Configs.getVillagerManipulation()) { + throw NEED_VILLAGER_MANIPULATION_EXCEPTION.create(); + } + GlobalPos pos = VillagerCracker.getClockPos(); if (pos == null) { ClientCommandHelper.sendFeedback("commands.cvillager.clock.cleared"); @@ -196,7 +219,11 @@ private static int getClockPos() { return Command.SINGLE_SUCCESS; } - private static int setClockPos(FabricClientCommandSource ctx, BlockPos pos) { + private static int setClockPos(FabricClientCommandSource ctx, BlockPos pos) throws CommandSyntaxException { + if (!Configs.getVillagerManipulation()) { + throw NEED_VILLAGER_MANIPULATION_EXCEPTION.create(); + } + ResourceKey dimension = ctx.getWorld().dimension(); VillagerCracker.setClockPos(pos == null ? null : new GlobalPos(dimension, pos)); if (pos == null) { @@ -207,14 +234,11 @@ private static int setClockPos(FabricClientCommandSource ctx, BlockPos pos) { return Command.SINGLE_SUCCESS; } - private static int resetCracker() { - VillagerCracker.simulator.reset(); - ClientCommandHelper.sendFeedback("commands.cvillager.resetCracker"); - - return Command.SINGLE_SUCCESS; - } - private static int start(boolean levelUp) throws CommandSyntaxException { + if (!Configs.getVillagerManipulation()) { + throw NEED_VILLAGER_MANIPULATION_EXCEPTION.create(); + } + Villager targetVillager = VillagerCracker.getVillager(); if (VillagerCracker.goals.isEmpty()) { diff --git a/src/main/java/net/earthcomputer/clientcommands/features/VillagerCracker.java b/src/main/java/net/earthcomputer/clientcommands/features/VillagerCracker.java index 79cb833d..ae9effaa 100644 --- a/src/main/java/net/earthcomputer/clientcommands/features/VillagerCracker.java +++ b/src/main/java/net/earthcomputer/clientcommands/features/VillagerCracker.java @@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.doubles.DoubleList; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; +import net.earthcomputer.clientcommands.Configs; import net.earthcomputer.clientcommands.command.ClientCommandHelper; import net.earthcomputer.clientcommands.command.PingCommand; import net.earthcomputer.clientcommands.command.VillagerCommand; @@ -163,7 +164,7 @@ public static void onXpOrbSpawned(ClientboundAddExperienceOrbPacket packet) { private static void onTimeSync() { long now = System.nanoTime(); - if (getVillager() != null && clockPos != null && !isNewClock && clockTicksSinceLastTimeSync != 20) { + if (Configs.getVillagerManipulation() && clockPos != null && !isNewClock && clockTicksSinceLastTimeSync != 20) { if (now - lastClockRateWarning >= 60_000_000_000L) { if (clockTicksSinceLastTimeSync < 20) { ClientCommandHelper.sendHelp(Component.translatable("commands.cvillager.help.tooSlow")); @@ -225,9 +226,7 @@ private static void onDisconnect() { }); } - clockPos = null; - villagerUuid = null; - VillagerCracker.stopRunning(); + reset(); } private static int[] possibleTicksAhead(Offer[] actualOffers, VillagerRngSimulator.SurroundingOffers surroundingOffers) { @@ -316,6 +315,13 @@ public static void onGuiOpened(List actualOffersList) { } } + public static void reset() { + simulator.reset(); + clockPos = null; + villagerUuid = null; + stopRunning(); + } + public static boolean isRunning() { return targetOffer != null; } diff --git a/src/main/resources/assets/clientcommands/lang/en_us.json b/src/main/resources/assets/clientcommands/lang/en_us.json index f275bca1..f7c93511 100644 --- a/src/main/resources/assets/clientcommands/lang/en_us.json +++ b/src/main/resources/assets/clientcommands/lang/en_us.json @@ -260,6 +260,7 @@ "commands.cvillager.inSync": "Your villager's RNG is cracked", "commands.cvillager.listGoals.noGoals": "There are no villager goals", "commands.cvillager.listGoals.success": "There are %s villager goals:", + "commands.cvillager.needVillagerManipulation": "Villager manipulation is not enabled", "commands.cvillager.noCrackedVillagerPresent": "There was no cracked villager available to use", "commands.cvillager.noProfession": "The targeted villager has no profession", "commands.cvillager.notAVillager": "Target was not a villager",