Skip to content

Commit

Permalink
- Added a command for setting the Auto Silk target tool setting (/aut…
Browse files Browse the repository at this point in the history
…osilk target <tool>)

- Fixed 'Filter Votes' setting on /economy
- Rewrote Enchant All
- /enchantall (not /unenchantall) can now use the built-in /enchantall command (Change Enchant Mode to 'All')
- Full-inventory enchantment now works on items added to your inventory mid-enchantment
  • Loading branch information
hashalite committed May 2, 2023
1 parent 3e9662a commit 9db9549
Show file tree
Hide file tree
Showing 19 changed files with 370 additions and 308 deletions.
6 changes: 3 additions & 3 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ mc_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.19
# Mod Properties
mod_version=1.1.1
mod_version=1.1.2
maven_group=net.xolt
archives_base_name=sbutils
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.79.0+1.19.4
fabric_version=0.80.0+1.19.4
modmenu_version=6.2.0
yacl_version=2.4.1
exp4j_version = 0.4.8
10 changes: 10 additions & 0 deletions src/main/java/net/xolt/sbutils/config/ConfigGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ private static ConfigCategory buildEnchantAllCategory(ModConfig defaults, ModCon
.name(Text.translatable("text.sbutils.config.category.enchantall"))
.group(OptionGroup.createBuilder()
.name(Text.translatable("text.sbutils.config.group.enchantAll"))
.option(Option.createBuilder(ModConfig.EnchantMode.class)
.name(Text.translatable("text.sbutils.config.option.enchantMode"))
.tooltip(Text.translatable("text.sbutils.config.option.enchantMode.tooltip"))
.binding(
defaults.enchantMode,
() -> config.enchantMode,
(value) -> config.enchantMode = value
)
.controller(EnumController::new)
.build())
.option(Option.createBuilder(double.class)
.name(Text.translatable("text.sbutils.config.option.enchantDelay"))
.tooltip(Text.translatable("text.sbutils.config.option.enchantDelay.tooltip"))
Expand Down
106 changes: 104 additions & 2 deletions src/main/java/net/xolt/sbutils/config/ModConfig.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package net.xolt.sbutils.config;

import com.mojang.brigadier.context.CommandContext;
import dev.isxander.yacl.api.NameableEnum;
import dev.isxander.yacl.config.ConfigEntry;
import dev.isxander.yacl.config.ConfigInstance;
import net.minecraft.command.argument.EnumArgumentType;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -62,6 +65,7 @@ public class ModConfig {

// Enchant All Settings

@ConfigEntry public EnchantMode enchantMode = EnchantMode.ALL;
@ConfigEntry public double enchantDelay = 0.55;
@ConfigEntry public int cooldownFrequency = 12;
@ConfigEntry public double cooldownTime = 6.0;
Expand Down Expand Up @@ -210,9 +214,23 @@ public Text getDisplayName() {
public Formatting getFormatting() {
return formatting;
}

public static class ColorArgumentType extends EnumArgumentType<Color> {
private ColorArgumentType() {
super(StringIdentifiable.createCodec(Color::values), Color::values);
}

public static ColorArgumentType color() {
return new ColorArgumentType();
}

public static Color getColor(CommandContext<?> context, String id) {
return context.getArgument(id, Color.class);
}
}
}

public enum FixMode implements NameableEnum {
public enum FixMode implements NameableEnum, StringIdentifiable {
HAND("text.sbutils.config.option.autoFixMode.hand"),
ALL("text.sbutils.config.option.autoFixMode.all");

Expand All @@ -225,9 +243,60 @@ public enum FixMode implements NameableEnum {
public Text getDisplayName() {
return Text.translatable(name);
}

public String asString() {
return getDisplayName().getString();
}

public static class FixModeArgumentType extends EnumArgumentType<FixMode> {
private FixModeArgumentType() {
super(StringIdentifiable.createCodec(FixMode::values), FixMode::values);
}

public static FixModeArgumentType fixMode() {
return new FixModeArgumentType();
}

public static FixMode getFixMode(CommandContext<?> context, String id) {
return context.getArgument(id, FixMode.class);
}
}
}

public enum EnchantMode implements NameableEnum, StringIdentifiable {
INDIVIDUAL("text.sbutils.config.option.enchantMode.individual"),
ALL("text.sbutils.config.option.enchantMode.all");

private final String name;

EnchantMode(String name) {
this.name = name;
}

public Text getDisplayName() {
return Text.translatable(name);
}

public String asString() {
return getDisplayName().getString();
}

public static class EnchantModeArgumentType extends EnumArgumentType<EnchantMode> {
private EnchantModeArgumentType() {
super(StringIdentifiable.createCodec(EnchantMode::values), EnchantMode::values);
}

public static EnchantModeArgumentType enchantMode() {
return new EnchantModeArgumentType();
}

public static EnchantMode getEnchantMode(CommandContext<?> context, String id) {
return context.getArgument(id, EnchantMode.class);
}
}
}

public enum SilkTarget implements NameableEnum {
public enum SilkTarget implements NameableEnum, StringIdentifiable {
DIAMOND_PICKAXE(Items.DIAMOND_PICKAXE),
DIAMOND_AXE(Items.DIAMOND_AXE),
DIAMOND_SHOVEL(Items.DIAMOND_SHOVEL),
Expand All @@ -247,6 +316,25 @@ public Item getTool() {
public Text getDisplayName() {
return Text.translatable(tool.getTranslationKey());
}

@Override
public String asString() {
return Registries.ITEM.getId(tool).getPath();
}

public static class SilkTargetArgumentType extends EnumArgumentType<SilkTarget> {
private SilkTargetArgumentType() {
super(StringIdentifiable.createCodec(ModConfig.SilkTarget::values), ModConfig.SilkTarget::values);
}

public static SilkTargetArgumentType silkTarget() {
return new SilkTargetArgumentType();
}

public static SilkTarget getSilkTarget(CommandContext<?> context, String id) {
return context.getArgument(id, SilkTarget.class);
}
}
}

public enum NotifSound implements NameableEnum, StringIdentifiable {
Expand Down Expand Up @@ -291,5 +379,19 @@ public Text getDisplayName() {
public SoundEvent getSound() {
return sound;
}

public static class NotifSoundArgumentType extends EnumArgumentType<NotifSound> {
private NotifSoundArgumentType() {
super(StringIdentifiable.createCodec(NotifSound::values), NotifSound::values);
}

public static NotifSoundArgumentType notifSound() {
return new NotifSoundArgumentType();
}

public static NotifSound getNotifSound(CommandContext<?> context, String id) {
return context.getArgument(id, NotifSound.class);
}
}
}
}
19 changes: 8 additions & 11 deletions src/main/java/net/xolt/sbutils/features/AutoFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,11 @@ public static void registerCommand(CommandDispatcher<FabricClientCommandSource>
Messenger.printSetting("text.sbutils.config.option.autoFixMode", ModConfig.INSTANCE.getConfig().autoFixMode);
return Command.SINGLE_SUCCESS;
})
.then(ClientCommandManager.literal("hand")
.then(ClientCommandManager.argument("mode", ModConfig.FixMode.FixModeArgumentType.fixMode())
.executes(context -> {
ModConfig.INSTANCE.getConfig().autoFixMode = ModConfig.FixMode.HAND;
ModConfig.INSTANCE.getConfig().autoFixMode = ModConfig.FixMode.FixModeArgumentType.getFixMode(context, "mode");
ModConfig.INSTANCE.save();
Messenger.printChangedSetting("text.sbutils.config.option.autoFixMode", ModConfig.FixMode.HAND);
return Command.SINGLE_SUCCESS;
}))
.then(ClientCommandManager.literal("all")
.executes(context -> {
ModConfig.INSTANCE.getConfig().autoFixMode = ModConfig.FixMode.ALL;
ModConfig.INSTANCE.save();
Messenger.printChangedSetting("text.sbutils.config.option.autoFixMode", ModConfig.FixMode.ALL);
Messenger.printChangedSetting("text.sbutils.config.option.autoFixMode", ModConfig.INSTANCE.getConfig().autoFixMode);
return Command.SINGLE_SUCCESS;
})))
.then(ClientCommandManager.literal("percent")
Expand Down Expand Up @@ -219,6 +212,10 @@ public static void tick() {
}
}

public static void onDisconnect() {
reset();
}

public static void onUpdateInventory() {
if (!ModConfig.INSTANCE.getConfig().autoFix || fixing) {
return;
Expand Down Expand Up @@ -326,7 +323,7 @@ public static boolean fixing() {
return fixing;
}

public static void reset() {
private static void reset() {
fixing = false;
waitingForResponse = false;
findMostDamaged = true;
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/net/xolt/sbutils/features/AutoSilk.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public static void registerCommand(CommandDispatcher<FabricClientCommandSource>
Messenger.printChangedSetting("text.sbutils.config.category.autosilk", ModConfig.INSTANCE.getConfig().autoSilk);
return Command.SINGLE_SUCCESS;
})
.then(ClientCommandManager.literal("target")
.executes(context -> {
Messenger.printSetting("text.sbutils.config.option.targetTool", ModConfig.INSTANCE.getConfig().targetTool);
return Command.SINGLE_SUCCESS;
})
.then(ClientCommandManager.argument("tool", ModConfig.SilkTarget.SilkTargetArgumentType.silkTarget())
.executes(context -> {
ModConfig.INSTANCE.getConfig().targetTool = ModConfig.SilkTarget.SilkTargetArgumentType.getSilkTarget(context, "tool");
ModConfig.INSTANCE.save();
Messenger.printChangedSetting("text.sbutils.config.option.targetTool", ModConfig.INSTANCE.getConfig().targetTool);
return Command.SINGLE_SUCCESS;
})))
.then(ClientCommandManager.literal("delay")
.executes(context -> {
Messenger.printSetting("text.sbutils.config.option.autoSilkDelay", ModConfig.INSTANCE.getConfig().autoSilkDelay);
Expand All @@ -66,6 +78,10 @@ public static void registerCommand(CommandDispatcher<FabricClientCommandSource>
.redirect(autoSilkNode));
}

public static void onDisconnect() {
reset();
}

public static void onPlayerCloseScreen() {
if (!ModConfig.INSTANCE.getConfig().autoSilk || !(MC.currentScreen instanceof EnchantmentScreen)) {
return;
Expand Down Expand Up @@ -391,7 +407,7 @@ private enum State {
RETURN_ITEM_AND_RESET;
}

public static void reset() {
private static void reset() {
state = State.INSERT_LAPIS;
lastActionPerformedAt = 0;
screenHandler = null;
Expand Down
Loading

0 comments on commit 9db9549

Please sign in to comment.