Skip to content

Commit

Permalink
Add fishingManipulation config
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Nov 27, 2024
1 parent 8daca5b commit 31837d4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 17 deletions.
17 changes: 16 additions & 1 deletion src/main/java/net/earthcomputer/clientcommands/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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<FabricClientCommandSource> dispatcher, CommandBuildContext context) {
dispatcher.register(literal("cvillager")
Expand Down Expand Up @@ -92,8 +97,6 @@ public static void register(CommandDispatcher<FabricClientCommandSource> 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")
Expand All @@ -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);
Expand Down Expand Up @@ -148,7 +155,11 @@ private static void checkStackSize(WithStringArgument.Result<ClientItemPredicate
}
}

private static int listGoals(FabricClientCommandSource source) {
private static int listGoals(FabricClientCommandSource source) throws CommandSyntaxException {
if (!Configs.getVillagerManipulation()) {
throw NEED_VILLAGER_MANIPULATION_EXCEPTION.create();
}

if (VillagerCracker.goals.isEmpty()) {
source.sendFeedback(Component.translatable("commands.cvillager.listGoals.noGoals").withStyle(style -> style.withColor(ChatFormatting.RED)));
} else {
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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<Level> dimension = ctx.getWorld().dimension();
VillagerCracker.setClockPos(pos == null ? null : new GlobalPos(dimension, pos));
if (pos == null) {
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -225,9 +226,7 @@ private static void onDisconnect() {
});
}

clockPos = null;
villagerUuid = null;
VillagerCracker.stopRunning();
reset();
}

private static int[] possibleTicksAhead(Offer[] actualOffers, VillagerRngSimulator.SurroundingOffers surroundingOffers) {
Expand Down Expand Up @@ -316,6 +315,13 @@ public static void onGuiOpened(List<Offer> actualOffersList) {
}
}

public static void reset() {
simulator.reset();
clockPos = null;
villagerUuid = null;
stopRunning();
}

public static boolean isRunning() {
return targetOffer != null;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/clientcommands/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 31837d4

Please sign in to comment.