Skip to content

Commit

Permalink
Use change listeners rather than setters where applicable in Configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Dec 3, 2024
1 parent 68987dd commit 5a1e635
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 34 deletions.
30 changes: 9 additions & 21 deletions src/main/java/net/earthcomputer/clientcommands/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ public class Configs {
@Config(readOnly = true, temporary = true)
public static PlayerRandCracker.CrackState playerCrackState = PlayerRandCracker.CrackState.UNCRACKED;

@Config(setter = @Config.Setter("setEnchantingPrediction"), temporary = true)
private static boolean enchantingPrediction = false;
public static boolean getEnchantingPrediction() {
return enchantingPrediction;
}
public static void setEnchantingPrediction(boolean enchantingPrediction) {
Configs.enchantingPrediction = enchantingPrediction;
@Config(onChange = "onChangeEnchantingPrediction", temporary = true)
public static boolean enchantingPrediction = false;
private static void onChangeEnchantingPrediction(boolean oldEnchantingPrediction, boolean enchantingPrediction) {
if (enchantingPrediction) {
ServerBrandManager.rngWarning();
} else {
Expand All @@ -53,13 +49,9 @@ public boolean isEnabled() {
}
}

@Config(setter = @Config.Setter("setFishingManipulation"), temporary = true, condition = "conditionLessThan1_20")
private static FishingManipulation fishingManipulation = FishingManipulation.OFF;
public static FishingManipulation getFishingManipulation() {
return fishingManipulation;
}
public static void setFishingManipulation(FishingManipulation fishingManipulation) {
Configs.fishingManipulation = fishingManipulation;
@Config(onChange = "onChangeFishingManipulation", temporary = true, condition = "conditionLessThan1_20")
public static FishingManipulation fishingManipulation = FishingManipulation.OFF;
private static void onChangeFishingManipulation(FishingManipulation oldFishingManipulation, FishingManipulation fishingManipulation) {
if (fishingManipulation.isEnabled()) {
ServerBrandManager.rngWarning();
} else {
Expand Down Expand Up @@ -122,13 +114,9 @@ public static void setMaxEnchantLevels(int maxEnchantLevels) {
Configs.minEnchantLevels = Math.min(Configs.minEnchantLevels, Configs.maxEnchantLevels);
}

@Config(setter = @Config.Setter("setChorusManipulation"), temporary = true)
private static boolean chorusManipulation = false;
public static boolean getChorusManipulation() {
return chorusManipulation;
}
public static void setChorusManipulation(boolean chorusManipulation) {
Configs.chorusManipulation = chorusManipulation;
@Config(onChange = "onChangeChorusManipulation", temporary = true)
public static boolean chorusManipulation = false;
public static void onChangeChorusManipulation(boolean oldChorusManipulation, boolean chorusManipulation) {
if (chorusManipulation) {
ServerBrandManager.rngWarning();
ChorusManipulation.onChorusManipEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static boolean enchantmentPredicate(Item item, Holder<Enchantment> ench)
}

private static int cenchant(FabricClientCommandSource source, ItemAndEnchantmentsPredicate itemAndEnchantmentsPredicate) throws CommandSyntaxException {
if (!Configs.getEnchantingPrediction()) {
if (!Configs.enchantingPrediction) {
Component component = Component.translatable("commands.cenchant.needEnchantingPrediction")
.withStyle(ChatFormatting.RED)
.append(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
}

private static int listGoals(FabricClientCommandSource source) throws CommandSyntaxException {
if (!Configs.getFishingManipulation().isEnabled()) {
if (!Configs.fishingManipulation.isEnabled()) {
throw NEED_FISHING_MANIPULATION_EXCEPTION.create();
}

Expand All @@ -73,7 +73,7 @@ private static int listGoals(FabricClientCommandSource source) throws CommandSyn
}

private static int addGoal(FabricClientCommandSource source, WithStringArgument.Result<ClientItemPredicateArgument.ClientItemPredicate> goal) throws CommandSyntaxException {
if (!Configs.getFishingManipulation().isEnabled()) {
if (!Configs.fishingManipulation.isEnabled()) {
throw NEED_FISHING_MANIPULATION_EXCEPTION.create();
}

Expand All @@ -85,7 +85,7 @@ private static int addGoal(FabricClientCommandSource source, WithStringArgument.
}

private static int addEnchantedGoal(FabricClientCommandSource source, WithStringArgument.Result<ItemAndEnchantmentsPredicate> stringAndItemAndEnchantments) throws CommandSyntaxException {
if (!Configs.getFishingManipulation().isEnabled()) {
if (!Configs.fishingManipulation.isEnabled()) {
throw NEED_FISHING_MANIPULATION_EXCEPTION.create();
}

Expand All @@ -102,7 +102,7 @@ private static int addEnchantedGoal(FabricClientCommandSource source, WithString
}

private static int removeGoal(FabricClientCommandSource source, int index) throws CommandSyntaxException {
if (!Configs.getFishingManipulation().isEnabled()) {
if (!Configs.fishingManipulation.isEnabled()) {
throw NEED_FISHING_MANIPULATION_EXCEPTION.create();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void onChorusManipEnabled() {
TaskManager.addNonConflictingTask("chorusManipRenderer", new SimpleTask() {
@Override
public boolean condition() {
return Configs.getChorusManipulation() && Minecraft.getInstance().player != null;
return Configs.chorusManipulation && Minecraft.getInstance().player != null;
}

@Override
Expand All @@ -48,7 +48,7 @@ protected void onTick() {
}

public static int setGoal(Vec3 v1, Vec3 v2, boolean relative) {
if (!Configs.getChorusManipulation()) {
if (!Configs.chorusManipulation) {
Component component = Component.translatable("chorusManip.needChorusManipulation")
.withStyle(ChatFormatting.RED)
.append(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public String toString() {
// MISCELLANEOUS HELPER METHODS & ENCHANTING SIMULATION

public static boolean isEnchantingPredictionEnabled() {
return Configs.getEnchantingPrediction();
return Configs.enchantingPrediction;
}

private static int getEnchantPower(Level level, BlockPos tablePos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static boolean throwFishingBobber() {
}

public static boolean canManipulateFishing() {
return Configs.getFishingManipulation().isEnabled() && !goals.isEmpty();
return Configs.fishingManipulation.isEnabled() && !goals.isEmpty();
}

private static void handleFishingRodThrow(ItemStack stack) {
Expand All @@ -267,7 +267,7 @@ public static void reset() {
synchronized (STATE_LOCK) {
state = State.NOT_MANIPULATING;

if (canManipulateFishing() && Configs.getFishingManipulation() == Configs.FishingManipulation.AFK) {
if (canManipulateFishing() && Configs.fishingManipulation == Configs.FishingManipulation.AFK) {
state = State.WAITING_FOR_RETRHOW;
TaskManager.addNonConflictingTask("cfishRethrow", new LongTask() {
private int counter;
Expand Down Expand Up @@ -340,7 +340,7 @@ public static void registerEvents() {
}
});
MoreClientEvents.TIME_SYNC_ON_NETWORK_THREAD.register(packet -> {
if (Configs.getFishingManipulation().isEnabled()) {
if (Configs.fishingManipulation.isEnabled()) {
onTimeSync();
}
});
Expand Down Expand Up @@ -590,7 +590,7 @@ private static void onTimeSync() {
int delay = (totalTicksToWait - estimatedTicksElapsed) * serverMspt - magicMillisecondsCorrection - PingCommand.getLocalPing() - timeToStartOfTick + serverMspt / 2;
long targetTime = (delay) * 1000000L + System.nanoTime();
DELAY_EXECUTOR.schedule(() -> {
if (!Configs.getFishingManipulation().isEnabled() || state != State.ASYNC_WAITING_FOR_FISH) {
if (!Configs.fishingManipulation.isEnabled() || state != State.ASYNC_WAITING_FOR_FISH) {
return;
}
LocalPlayer oldPlayer = Minecraft.getInstance().player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static void onConsume(ItemStack stack, Vec3 pos, int particleCount, int i
}
}

if (Configs.getChorusManipulation() && stack.getItem() == Items.CHORUS_FRUIT) {
if (Configs.chorusManipulation && stack.getItem() == Items.CHORUS_FRUIT) {
ChorusManipulation.onEat(pos, particleCount, itemUseTimeLeft);
if (particleCount == 16) {
//Consumption randoms
Expand Down

0 comments on commit 5a1e635

Please sign in to comment.