From 78b9ffa352c846ec06729a288f7b69de837a9f92 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 2 Nov 2023 16:51:55 +0100 Subject: feat: added initial bad impl of HandChanger --- .../java/ftbsc/bscv/modules/self/HandChanger.java | 72 ++++++++++++++++++++++ src/main/resources/META-INF/accesstransformer.cfg | 4 ++ 2 files changed, 76 insertions(+) create mode 100644 src/main/java/ftbsc/bscv/modules/self/HandChanger.java (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/self/HandChanger.java b/src/main/java/ftbsc/bscv/modules/self/HandChanger.java new file mode 100644 index 0000000..c7f8a03 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/self/HandChanger.java @@ -0,0 +1,72 @@ +package ftbsc.bscv.modules.self; + +import com.google.auto.service.AutoService; +import ftbsc.bscv.api.ILoadable; +import ftbsc.bscv.modules.AbstractModule; +import ftbsc.bscv.tools.Setting; +import net.minecraftforge.client.event.RenderHandEvent; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +@AutoService(ILoadable.class) +public class HandChanger extends AbstractModule { + + public final ForgeConfigSpec.ConfigValue main; + public final ForgeConfigSpec.ConfigValue off; + public final ForgeConfigSpec.ConfigValue cancel_main; + public final ForgeConfigSpec.ConfigValue cancel_off; + + public HandChanger() { + super(); + + this.main = Setting.Decimal.builder() + .min(0.) + .max(1.) + .name("main") + .comment("height of main hand") + .fallback(1.) + .build(this); + + this.off = Setting.Decimal.builder() + .min(0.) + .max(1.) + .name("off") + .comment("height of off hand") + .fallback(1.) + .build(this); + + this.cancel_main = Setting.Bool.builder() + .name("cancel-main") + .comment("completely prevent main hand rendering") + .fallback(false) + .build(this); + + this.cancel_off = Setting.Bool.builder() + .name("cancel-off") + .comment("completely prevent off hand rendering") + .fallback(false) + .build(this); + } + + @SubscribeEvent + public void onRenderHands(RenderHandEvent event) { + switch (event.getHand()) { + case MAIN_HAND: + if (this.cancel_main.get()) { + event.setCanceled(true); + } else if (this.main.get() != 1.0) { + MC.gameRenderer.itemInHandRenderer.mainHandHeight = this.main.get().floatValue(); // ACCESSTRANSFORMER public net.minecraft.client.renderer.FirstPersonRenderer field_187469_f + MC.gameRenderer.itemInHandRenderer.oMainHandHeight = this.main.get().floatValue(); // ACCESSTRANSFORMER public net.minecraft.client.renderer.FirstPersonRenderer field_187469_f + } + break; + case OFF_HAND: + if (this.cancel_off.get()) { + event.setCanceled(true); + } else if (this.off.get() != 1.0) { + MC.gameRenderer.itemInHandRenderer.offHandHeight = this.off.get().floatValue(); // ACCESSTRANSFORMER public net.minecraft.client.renderer.FirstPersonRenderer field_187470_g + MC.gameRenderer.itemInHandRenderer.oOffHandHeight = this.off.get().floatValue(); // ACCESSTRANSFORMER public net.minecraft.client.renderer.FirstPersonRenderer field_187470_g + } + break; + } + } +} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 5be5b4b..9e08035 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -5,3 +5,7 @@ public net.minecraft.network.play.client.CPlayerPacket field_149474_g # onGround public net.minecraft.network.play.client.CPlayerPacket field_149477_b # y public net.minecraft.client.multiplayer.PlayerController func_78750_j()V # ensureHasSentCarriedItem() public net.minecraft.client.Minecraft field_71467_ac # rightClickDelay +public net.minecraft.client.renderer.FirstPersonRenderer field_187469_f # mainHandHeight +public net.minecraft.client.renderer.FirstPersonRenderer field_187470_g # oMainHandHeight +public net.minecraft.client.renderer.FirstPersonRenderer field_187471_h # offHandHeight +public net.minecraft.client.renderer.FirstPersonRenderer field_187472_i # oOffHandHeight -- cgit v1.2.3-56-ga3b1 From 6201f66c85550b56cd462617a1d46e1bdba99e08 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 2 Nov 2023 16:52:21 +0100 Subject: feat: added ruler --- src/main/java/ftbsc/bscv/Boscovicino.java | 6 ++ src/main/java/ftbsc/bscv/modules/QuickModule.java | 11 +-- src/main/java/ftbsc/bscv/system/Ruler.java | 85 +++++++++++++++++++++++ src/main/java/ftbsc/bscv/tools/Keybind.java | 13 ++++ 4 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 src/main/java/ftbsc/bscv/system/Ruler.java create mode 100644 src/main/java/ftbsc/bscv/tools/Keybind.java (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/Boscovicino.java b/src/main/java/ftbsc/bscv/Boscovicino.java index 65c5830..8d6ab67 100644 --- a/src/main/java/ftbsc/bscv/Boscovicino.java +++ b/src/main/java/ftbsc/bscv/Boscovicino.java @@ -8,6 +8,7 @@ import ftbsc.bscv.api.IModule; import ftbsc.bscv.patches.CommandsPatch.CommandsBuiltEvent; import ftbsc.bscv.system.Friends; import ftbsc.bscv.system.ModManager; +import ftbsc.bscv.system.Ruler; import net.minecraft.client.gui.screen.IngameMenuScreen; import net.minecraft.client.gui.widget.button.Button; import net.minecraft.command.CommandSource; @@ -42,6 +43,9 @@ public class Boscovicino implements ICommons { private static Friends friends; public static Friends friends() { return Boscovicino.friends; } + @SuppressWarnings("unused") // it just needs to exist to be used by player + private static Ruler ruler; + public Boscovicino() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onSetupComplete); @@ -53,6 +57,8 @@ public class Boscovicino implements ICommons { Boscovicino.modManager.finish(); + Boscovicino.ruler = new Ruler(); + Boscovicino.spec = cfg.build(); ForgeConfigSpec.Builder friendSpec = new ForgeConfigSpec.Builder(); diff --git a/src/main/java/ftbsc/bscv/modules/QuickModule.java b/src/main/java/ftbsc/bscv/modules/QuickModule.java index 009a057..648b020 100644 --- a/src/main/java/ftbsc/bscv/modules/QuickModule.java +++ b/src/main/java/ftbsc/bscv/modules/QuickModule.java @@ -1,6 +1,7 @@ package ftbsc.bscv.modules; import ftbsc.bscv.Boscovicino; +import ftbsc.bscv.tools.Keybind; import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.util.InputMappings; import net.minecraftforge.client.event.InputEvent; @@ -51,7 +52,7 @@ public abstract class QuickModule extends AbstractModule { public QuickModule() { super(); - this.keybind = new KeyBinding(key_name(this.getName()), this.getDefaultKey(), key_category()); + this.keybind = new KeyBinding(Keybind.name(this.getName()), this.getDefaultKey(), Keybind.category()); ClientRegistry.registerKeyBinding(this.keybind); // register a separate subclass on the hook, so that it's always listening @@ -76,12 +77,4 @@ public abstract class QuickModule extends AbstractModule { // ); } - private static String key_name(String name) { - return String.format("key.%s.%s", Boscovicino.MOD_ID, name); - } - - private static String key_category() { - return String.format("key.category.%s", Boscovicino.MOD_ID); - } - } diff --git a/src/main/java/ftbsc/bscv/system/Ruler.java b/src/main/java/ftbsc/bscv/system/Ruler.java new file mode 100644 index 0000000..bb4c012 --- /dev/null +++ b/src/main/java/ftbsc/bscv/system/Ruler.java @@ -0,0 +1,85 @@ +package ftbsc.bscv.system; + +import ftbsc.bscv.ICommons; +import ftbsc.bscv.tools.Keybind; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.client.util.InputMappings; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.RayTraceResult.Type; +import net.minecraftforge.client.event.InputEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.client.registry.ClientRegistry; + +import static ftbsc.bscv.Boscovicino.log; + +public class Ruler implements ICommons { + + public final KeyBinding keybind; + + public Ruler() { + super(); + + this.keybind = new KeyBinding(Keybind.name("Ruler"), InputMappings.UNKNOWN.getValue(), Keybind.category()); + ClientRegistry.registerKeyBinding(this.keybind); + + // register a separate subclass on the hook, so that it's always listening + MinecraftForge.EVENT_BUS.register(new ToggleHook(this.keybind)); + + // dispatcher.register( + // Commands.literal(this.name.toLowerCase()) + // .then( + // Commands.literal("bind") + // .then( + // Commands.argument("key", StringArgumentType.word()) + // .executes( ctx -> { + // this.keybind.setKey( + // InputMappings.getKey( // TODO it's not this easy! + // StringArgumentType.getString(ctx, "key") + // ) + // ); + // return 1; + // }) + // ) + // ) + // ); + } + + public static void measure() { + RayTraceResult aim = MC.player.pick(1024, 0, false); // will 1024 be enough? + double distance = Math.sqrt(aim.distanceTo(MC.player)); + if (aim.getType() == Type.BLOCK) { + log("distance: %.1fm", distance); + } + } + + // TODO can this be made an util or a global event listener? + private class ToggleHook { + private final KeyBinding key; + private boolean debounce; + // TODO all examples show isPressed() to get a debounced value + // but it seems to be missing? making my own debounce for now + protected ToggleHook(KeyBinding key) { + this.key = key; + this.debounce = false; + } + + private void onInput() { + if (this.debounce) { + if (!this.key.isDown()) { + this.debounce = false; + } + } else { + if (this.key.isDown()) { + Ruler.measure(); + this.debounce = true; + } + } + } + + @SubscribeEvent + public void onKeyPress(InputEvent.KeyInputEvent event) { this.onInput(); } + @SubscribeEvent + public void onKeyPress(InputEvent.MouseInputEvent event) { this.onInput(); } + } +} diff --git a/src/main/java/ftbsc/bscv/tools/Keybind.java b/src/main/java/ftbsc/bscv/tools/Keybind.java new file mode 100644 index 0000000..64fe1ad --- /dev/null +++ b/src/main/java/ftbsc/bscv/tools/Keybind.java @@ -0,0 +1,13 @@ +package ftbsc.bscv.tools; + +import ftbsc.bscv.Boscovicino; + +public class Keybind { + public static String name(String name) { + return String.format("key.%s.%s", Boscovicino.MOD_ID, name); + } + + public static String category() { + return String.format("key.category.%s", Boscovicino.MOD_ID); + } +} -- cgit v1.2.3-56-ga3b1 From b71dcba7a27942a31ba8802cd607ebf6b4113e50 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 2 Nov 2023 16:52:31 +0100 Subject: feat: updated cursor commands, added block search --- src/main/java/ftbsc/bscv/commands/BlockSearch.java | 57 ++++++++++++++++++++++ src/main/java/ftbsc/bscv/commands/Cursor.java | 10 ++-- 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ftbsc/bscv/commands/BlockSearch.java (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/commands/BlockSearch.java b/src/main/java/ftbsc/bscv/commands/BlockSearch.java new file mode 100644 index 0000000..dd5f663 --- /dev/null +++ b/src/main/java/ftbsc/bscv/commands/BlockSearch.java @@ -0,0 +1,57 @@ +package ftbsc.bscv.commands; + +import com.google.auto.service.AutoService; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import ftbsc.bscv.api.ILoadable; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; + +import static ftbsc.bscv.Boscovicino.log; + +@AutoService(ILoadable.class) +public class BlockSearch extends AbstractCommand { + + @Override + public String getName() { return "block"; } + + public LiteralArgumentBuilder register(LiteralArgumentBuilder builder) { + return builder + .then( + Commands.literal("search") + .then( + Commands.argument("id", IntegerArgumentType.integer(0)) + .executes( ctx -> { + int block_id = ctx.getArgument("id", Integer.class); + int block_number = block_id >> 4; + int block_meta = block_id & 0b1111; + BlockState state = Block.stateById(block_id); + log("block #[%d:%d]::%d >> %s", block_number, block_meta, block_id, state.toString()); + return 1; + }) + ) + .then( + Commands.argument("number", IntegerArgumentType.integer(0)) + .then( + Commands.argument("meta", IntegerArgumentType.integer(0)) + .executes( ctx -> { + int block_number = ctx.getArgument("number", Integer.class); + int block_meta = ctx.getArgument("meta", Integer.class); + int block_id = (block_number << 4) | block_meta; + BlockState state = Block.stateById(block_id); + log("block #[%d:%d]::%d >> %s", block_number, block_meta, block_id, state.toString()); + return 1; + }) + ) + ) + ) + .executes(ctx -> { + log("no block specified"); + return 0; + }); + } + +} diff --git a/src/main/java/ftbsc/bscv/commands/Cursor.java b/src/main/java/ftbsc/bscv/commands/Cursor.java index 49a93aa..a54433d 100644 --- a/src/main/java/ftbsc/bscv/commands/Cursor.java +++ b/src/main/java/ftbsc/bscv/commands/Cursor.java @@ -4,6 +4,7 @@ import com.google.auto.service.AutoService; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import ftbsc.bscv.api.ILoadable; +import net.minecraft.block.BlockState; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; import net.minecraft.util.Direction; @@ -18,17 +19,18 @@ public class Cursor extends AbstractCommand { public LiteralArgumentBuilder register(LiteralArgumentBuilder builder) { return builder .then( - Commands.literal("pos") + Commands.literal("info") .executes(ctx -> { switch (MC.hitResult.getType()) { case BLOCK: BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult; Direction dir = result.getDirection(); - BlockPos pos =result.getBlockPos(); - log("Block @ %s (%s)", pos.toString(), dir.toString()); + BlockPos pos = result.getBlockPos(); + BlockState state = MC.level.getBlockState(pos); + log("Block @ %s (%s): %s", pos.toString(), dir.toString(), state.toString()); return 1; case ENTITY: - log("Entity @ %s", MC.hitResult.getLocation().toString()); + log("Entity @ %s (TODO!)", MC.hitResult.getLocation().toString()); return 1; default: case MISS: -- cgit v1.2.3-56-ga3b1 From 12f1ec92a0c04ac35ad81370c2183ecd2827af02 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 11 Nov 2023 15:29:52 +0100 Subject: feat: allow to select prefer-looting in autoweapon yes i know that *technically* a sharp 5 axe has 3 DPS and a god sword has only 2.9411763880904593 but if a mob dies in 3 attacks, faster attacks means it will die faster, also looting is usually more important, to say nothing about fire aspect which deals DoT and sweeping edge which deals AoE damage. USE THE SWORD!!!!! --- src/main/java/ftbsc/bscv/modules/self/AutoTool.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java index 1474085..c37a8a2 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java @@ -1,11 +1,14 @@ package ftbsc.bscv.modules.self; import com.google.auto.service.AutoService; + +import ftbsc.bscv.Boscovicino; import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.tools.Inventory; import ftbsc.bscv.tools.Setting; import net.minecraft.block.BlockState; +import net.minecraft.enchantment.Enchantments; import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockRayTraceResult; @@ -19,6 +22,7 @@ import java.util.List; public class AutoTool extends AbstractModule { public final ForgeConfigSpec.ConfigValue limit; + public final ForgeConfigSpec.ConfigValue prefer_looting; public AutoTool() { super(); @@ -28,6 +32,12 @@ public class AutoTool extends AbstractModule { .comment("durability limit for tools, set to 0 to destroy them") .fallback(1) .build(this); + + this.prefer_looting = Setting.Bool.builder() + .name("prefer-looting") + .comment("when picking best weapon, prefer looting over slight more DPS") + .fallback(true) + .build(this); } private boolean itemIsTooDamaged(ItemStack item) { @@ -47,6 +57,12 @@ public class AutoTool extends AbstractModule { } double damage = Inventory.itemDPS(item); + + int looting = Inventory.getEnchLevel(item, Enchantments.MOB_LOOTING); + if (this.prefer_looting.get() && looting > 0) { + damage += 0.1 * looting; + } + if (damage > current_damage) { current_slot = i; current_damage = damage; -- cgit v1.2.3-56-ga3b1 From add2ea794516533b80db830eab34bc4e8dfc620b Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 12 Nov 2023 06:03:18 +0100 Subject: feat: add crude regex containercleaner also works on self inventory btw --- .../ftbsc/bscv/modules/self/ContainerCleaner.java | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java new file mode 100644 index 0000000..d08d832 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java @@ -0,0 +1,70 @@ +package ftbsc.bscv.modules.self; + +import java.util.regex.Pattern; +import com.google.auto.service.AutoService; + +import ftbsc.bscv.Boscovicino; +import ftbsc.bscv.api.ILoadable; +import ftbsc.bscv.modules.AbstractModule; +import ftbsc.bscv.tools.Inventory; +import ftbsc.bscv.tools.Setting; +import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.inventory.container.ClickType; +import net.minecraft.inventory.container.Slot; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent.ClientTickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +@AutoService(ILoadable.class) +public class ContainerCleaner extends AbstractModule { + + public final ForgeConfigSpec.ConfigValue query; + public final ForgeConfigSpec.ConfigValue cooldown; + public final ForgeConfigSpec.ConfigValue limit; + private Pattern pattern; + private int counter; + + public ContainerCleaner() { + super(); + + this.pattern = Pattern.compile(""); + this.query = Setting.Str.builder() + .fallback("") + .name("query") + .comment("search query for dropping items") + .callback(to -> this.pattern = Pattern.compile(to)) + .build(this); + + this.counter = 0; + this.cooldown = Setting.Number.builder() + .fallback(0) + .name("cooldown") + .comment("ticks before throwing next item") + .build(this); + + this.limit = Setting.Bool.builder() + .fallback(true) + .name("limit") + .comment("limit to one action per tick") + .build(this); + } + + @SubscribeEvent + public void onTick(ClientTickEvent event) { + if (MC.screen == null) return; + if (!(MC.screen instanceof ContainerScreen)) return; + if (this.counter > 0) { + this.counter -= 1; + return; + } + ContainerScreen screen = (ContainerScreen) MC.screen; + for (Slot slot : screen.getMenu().slots) { + if (Inventory.matchItem(this.pattern, slot.getItem())) { + Boscovicino.log("dropping item %s", slot.getItem().getItem()); + Inventory.clickSLot(screen.getMenu().containerId, slot, ClickType.THROW); + this.counter = this.cooldown.get(); + if (this.limit.get()) return; // only throw one item per tick + } + } + } +} -- cgit v1.2.3-56-ga3b1 From bfc6d4fef6804b0050537228ffdabc63b0f6683b Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:24:49 +0100 Subject: feat: added Many setting for collections still very raw and not super helpful but kind of usable? --- src/main/java/ftbsc/bscv/tools/Setting.java | 196 ++++++++++++++++++++++------ 1 file changed, 153 insertions(+), 43 deletions(-) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/tools/Setting.java b/src/main/java/ftbsc/bscv/tools/Setting.java index 99f5480..427e22e 100644 --- a/src/main/java/ftbsc/bscv/tools/Setting.java +++ b/src/main/java/ftbsc/bscv/tools/Setting.java @@ -1,23 +1,28 @@ package ftbsc.bscv.tools; +import com.google.common.collect.Lists; import com.mojang.brigadier.arguments.*; + import ftbsc.bscv.api.IModule; import net.minecraft.command.Commands; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.server.command.EnumArgument; +import java.io.Serializable; +import java.util.List; import java.util.Optional; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; import static ftbsc.bscv.Boscovicino.log; -public abstract class Setting { +public abstract class Setting { protected Optional name; protected Optional comment; protected Optional fallback; - protected Optional> callback; - + protected Optional> callback; Setting() { this.name = Optional.empty(); @@ -26,68 +31,75 @@ public abstract class Setting { this.callback = Optional.empty(); } - public Setting name(String name) { + public Setting name(String name) { this.name = Optional.of(name); return this; } - public Setting comment(String comment) { + public Setting comment(String comment) { this.comment = Optional.of(comment); return this; } - public Setting fallback(T fallback) { + public Setting fallback(T fallback) { this.fallback = Optional.of(fallback); return this; } - public Setting callback(Consumer callback) { + public Setting callback(Consumer callback) { this.callback = Optional.of(callback); return this; } abstract ForgeConfigSpec.ConfigValue value(ForgeConfigSpec.Builder builder); - abstract ArgumentType argument(); + abstract ArgumentType argument(); + + public abstract ForgeConfigSpec.ConfigValue build(IModule module); + - abstract Class clazz(); - public ForgeConfigSpec.ConfigValue build(IModule module) { - ForgeConfigSpec.ConfigValue conf = this.value(module.getConfigBuilder()); + private static abstract class ValueSetting extends Setting { + + abstract Class clazz(); - String optName = this.name.get(); - Class clazz = this.clazz(); - ArgumentType arg = this.argument(); - Consumer cb = this.callback.isPresent() ? this.callback.get() : null; + public ForgeConfigSpec.ConfigValue build(IModule module) { + ForgeConfigSpec.ConfigValue conf = this.value(module.getConfigBuilder()); - module.getDispatcher().register( - Commands.literal(module.getName().toLowerCase()) - .then( - Commands.literal(optName) + String optName = this.name.get(); + Class clazz = this.clazz(); + ArgumentType arg = this.argument(); + Consumer cb = this.callback.isPresent() ? this.callback.get() : null; + + module.getDispatcher().register( + Commands.literal(module.getName().toLowerCase()) .then( - Commands.argument(optName, arg) - .executes( ctx -> { - T value = ctx.getArgument(optName, clazz); - if (cb != null) { - cb.accept(value); - } - conf.set(value); - conf.save(); - log(String.format("> %s -> %s <", String.join(".", conf.getPath()), conf.get().toString())); - return 1; - })) - .executes(ctx -> { - log(String.format("> %s: %s <", optName, conf.get().toString())); - return 1; - }) - ) - ); - - return conf; + Commands.literal(optName) + .then( + Commands.argument(optName, arg) + .executes( ctx -> { + T value = ctx.getArgument(optName, clazz); + if (cb != null) { + cb.accept(value); + } + conf.set(value); + conf.save(); + log(String.format("> %s -> %s <", String.join(".", conf.getPath()), conf.get().toString())); + return 1; + })) + .executes(ctx -> { + log(String.format("> %s: %s <", optName, conf.get().toString())); + return 1; + }) + ) + ); + + return conf; + } } - public static class Bool extends Setting { + public static class Bool extends ValueSetting { public static Bool builder() { return new Bool(); } public Class clazz() { return Boolean.class; } @@ -101,7 +113,7 @@ public abstract class Setting { } - public static class Decimal extends Setting { + public static class Decimal extends ValueSetting { protected Optional min; protected Optional max; @@ -133,7 +145,7 @@ public abstract class Setting { } - public static class Number extends Setting { + public static class Number extends ValueSetting { protected Optional min; protected Optional max; @@ -165,7 +177,7 @@ public abstract class Setting { } - public static class Str extends Setting { + public static class Str extends ValueSetting { public static Str builder() { return new Str(); } protected boolean greedy = false; @@ -190,7 +202,7 @@ public abstract class Setting { } - public static class Switch> extends Setting { + public static class Switch> extends ValueSetting { private final Class enumClazz; public static> Switch builder(Class type) { return new Switch(type); } @@ -214,4 +226,102 @@ public abstract class Setting { } } + public static class Many extends Setting, T> { + private Predicate validator; + private Function writer; + private final ArgumentType argument_type; + private final Class clazz; + + // TODO can we infer clazz from the argument type without needing the second argument??? + public Many(ArgumentType argument, Class clazz) { + super(); + this.validator = x -> true; + this.writer = x -> (S) x; // TODO this works ootb if it's just the same type but crashes at runtime for everything else + this.argument_type = argument; + this.clazz = clazz; + } + + public static Many builder(ArgumentType argument, Class clazz) { return new Many(argument, clazz); } + + public Many validator(Predicate validator) { + this.validator = validator; + return this; + } + + public Many writer(Function writer) { + this.writer = writer; + return this; + } + + public ArgumentType argument() { + return this.argument_type; + } + + public ForgeConfigSpec.ConfigValue> value(ForgeConfigSpec.Builder builder) { + return builder + .comment(this.comment.get()) + .defineList( + this.name.get(), + this.fallback.get(), + this.validator + ); + } + + public ForgeConfigSpec.ConfigValue> build(IModule module) { + ForgeConfigSpec.ConfigValue> conf = this.value(module.getConfigBuilder()); + + String optName = this.name.get(); + ArgumentType arg = this.argument(); + Consumer cb = this.callback.isPresent() ? this.callback.get() : null; + + module.getDispatcher().register( + Commands.literal(module.getName().toLowerCase()) + .then( + Commands.literal(optName) + .then( + Commands.literal("add") + .then( + Commands.argument(optName, arg) + .executes( ctx -> { + T value = ctx.getArgument(optName, this.clazz); + if (cb != null) { + cb.accept(value); + } + List botch = Lists.newArrayList(conf.get()); + botch.add(this.writer.apply(value)); + conf.set(botch); + conf.save(); + log(String.format("> %s -++> %s <", String.join(".", conf.getPath()), conf.get().toString())); + return 1; + }) + ) + ) + .then( + Commands.literal("remove") + .then( + Commands.argument(optName, arg) + .executes( ctx -> { + T value = ctx.getArgument(optName, clazz); + if (cb != null) { + cb.accept(value); + } + List botch = Lists.newArrayList(conf.get()); + boolean removed = botch.remove(this.writer.apply(value)); + conf.set(botch); + conf.save(); + log(String.format("> %s -%s> %s <", String.join(".", conf.getPath()), removed ? "//" : "--", conf.get().toString())); + return 1; + }) + ) + ) + .executes(ctx -> { + log(String.format("> %s: %s <", optName, conf.get().toString())); + return 1; + }) + ) + ); + + return conf; + } + } } -- cgit v1.2.3-56-ga3b1 From 3638f7f9c15eec46cd9f8639ca9b386a9e03c9c3 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:25:29 +0100 Subject: chore: move regex filters from Highlighter to utils --- .../java/ftbsc/bscv/modules/hud/Highlighter.java | 35 +--------------- src/main/java/ftbsc/bscv/tools/Inventory.java | 46 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 33 deletions(-) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java b/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java index a5fa0e5..f5cc542 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java +++ b/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import ftbsc.bscv.modules.AbstractModule; +import ftbsc.bscv.tools.Inventory; import ftbsc.bscv.tools.Setting; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.inventory.container.Slot; @@ -48,38 +49,6 @@ public class Highlighter extends AbstractModule { this.pattern = Pattern.compile(this.query.get()); } - private List enchantments(ItemStack stack) { - final ListNBT tags; - if (Items.ENCHANTED_BOOK.equals(stack.getItem())) { - tags = EnchantedBookItem.getEnchantments(stack); // special case to also search book enchants - } else { - tags = stack.getEnchantmentTags(); - } - - List out = new ArrayList<>(); - for (int i = 0; i < tags.size(); i++) { - CompoundNBT tag = tags.getCompound(i); - out.add(String.format("%s %s", tag.getString("id"), tag.getInt("lvl"))); - } - - return out; - } - - private boolean matches(ItemStack stack) { - if (stack.isEmpty()) return false; - - String displayName = stack.getDisplayName().getString(); - if (this.pattern.matcher(displayName).find()) return true; - - if (Items.ENCHANTED_BOOK.equals(stack.getItem()) || stack.isEnchanted()) { - for (String ench : this.enchantments(stack)) { - if (this.pattern.matcher(ench).find()) return true; - } - } - - return false; - } - @SubscribeEvent public void onGuiContainerDraw(GuiContainerEvent.DrawBackground event) { MatrixStack matrix = event.getMatrixStack(); @@ -91,7 +60,7 @@ public class Highlighter extends AbstractModule { for (Slot slot : screen.getMenu().slots) { ItemStack stack = slot.getItem(); - if (this.matches(stack)) { + if (Inventory.matchItem(this.pattern, stack)) { GuiUtils.drawGradientRect( matrix.last().pose(), 0, slot.x, slot.y, slot.x + 16, slot.y + 16, diff --git a/src/main/java/ftbsc/bscv/tools/Inventory.java b/src/main/java/ftbsc/bscv/tools/Inventory.java index 8f1e2f5..f044be8 100644 --- a/src/main/java/ftbsc/bscv/tools/Inventory.java +++ b/src/main/java/ftbsc/bscv/tools/Inventory.java @@ -7,13 +7,19 @@ import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.inventory.EquipmentSlotType; +import net.minecraft.inventory.container.ClickType; import net.minecraft.inventory.container.Slot; +import net.minecraft.item.EnchantedBookItem; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; +import net.minecraft.nbt.ListNBT; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.regex.Pattern; public class Inventory implements ICommons { @@ -68,4 +74,44 @@ public class Inventory implements ICommons { return damage / (1. + speed); } + + public static List itemEnchantments(ItemStack stack) { + final ListNBT tags; + if (Items.ENCHANTED_BOOK.equals(stack.getItem())) { + tags = EnchantedBookItem.getEnchantments(stack); // special case to also search book enchants + } else { + tags = stack.getEnchantmentTags(); + } + + List out = new ArrayList<>(); + for (int i = 0; i < tags.size(); i++) { + CompoundNBT tag = tags.getCompound(i); + out.add(String.format("%s %s", tag.getString("id"), tag.getInt("lvl"))); + } + + return out; + } + + public static void clickSLot(Slot slot, ClickType click) { clickSlot(0, slot, 0, click); } + public static void clickSLot(Slot slot, int button, ClickType click) { clickSlot(0, slot, button, click); } + public static void clickSLot(int container, Slot slot, ClickType click) { clickSlot(container, slot, 0, click); } + + public static void clickSlot(int container, Slot slot, int button, ClickType click) { + MC.gameMode.handleInventoryMouseClick(container, slot.index, button, click, MC.player); + } + + public static boolean matchItem(Pattern pattern, ItemStack stack) { + if (stack.isEmpty()) return false; + + String displayName = stack.getDisplayName().getString(); + if (pattern.matcher(displayName).find()) return true; + + if (Items.ENCHANTED_BOOK.equals(stack.getItem()) || stack.isEnchanted()) { + for (String ench : itemEnchantments(stack)) { + if (pattern.matcher(ench).find()) return true; + } + } + + return false; + } } -- cgit v1.2.3-56-ga3b1 From 399af0c12dbab89efdeaa961fcf3000416df4c14 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:25:49 +0100 Subject: chore: better defaults for VanillaFlight --- src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java index df00eda..0d1d736 100644 --- a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java +++ b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java @@ -40,24 +40,24 @@ public class VanillaFlight extends QuickModule { this.force = Setting.Bool.builder() .name("force") .comment("force enable flight on user") - .fallback(false) + .fallback(true) .build(this); this.drift = Setting.Bool.builder() .name("drift") .comment("gradually reduce momentum") - .fallback(true) + .fallback(false) .build(this); this.speed = Setting.Decimal.builder() .min(0.) - .fallback(0.05) + .fallback(0.1) .name("speed") .comment("flight speed to set") .build(this); this.antikick = Setting.Switch.builder(AntikickMode.class) - .fallback(AntikickMode.NONE) + .fallback(AntikickMode.PACKET) .name("antikick") .comment("prevent vanilla flight kick by descending") .build(this); -- cgit v1.2.3-56-ga3b1 From 72333dfd33cfd3be08d8fe54e6eade8c13eba3fc Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:26:06 +0100 Subject: chore: NoOverlay is not really a hud mod --- .../java/ftbsc/bscv/modules/hud/NoOverlay.java | 82 ---------------------- .../java/ftbsc/bscv/modules/self/NoOverlay.java | 82 ++++++++++++++++++++++ 2 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 src/main/java/ftbsc/bscv/modules/hud/NoOverlay.java create mode 100644 src/main/java/ftbsc/bscv/modules/self/NoOverlay.java (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/hud/NoOverlay.java b/src/main/java/ftbsc/bscv/modules/hud/NoOverlay.java deleted file mode 100644 index 474c759..0000000 --- a/src/main/java/ftbsc/bscv/modules/hud/NoOverlay.java +++ /dev/null @@ -1,82 +0,0 @@ -package ftbsc.bscv.modules.hud; - -import com.google.auto.service.AutoService; - -import ftbsc.bscv.api.ILoadable; -import ftbsc.bscv.modules.AbstractModule; -import ftbsc.bscv.tools.Setting; -import net.minecraftforge.client.event.EntityViewRenderEvent; -import net.minecraftforge.client.event.RenderBlockOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -@AutoService(ILoadable.class) -public class NoOverlay extends AbstractModule { - - public final ForgeConfigSpec.ConfigValue liquid; - public final ForgeConfigSpec.ConfigValue block; - public final ForgeConfigSpec.ConfigValue helmet; - public final ForgeConfigSpec.ConfigValue portal; - - public NoOverlay() { - super(); - - this.liquid = Setting.Bool.builder() - .fallback(true) - .name("liquid") - .comment("cancel overlay in water and lava") - .build(this); - - this.block = Setting.Bool.builder() - .fallback(true) - .name("block") - .comment("cancel overlay of blocks on your head") - .build(this); - - this.helmet = Setting.Bool.builder() - .fallback(true) - .name("helmet") - .comment("cancel overlay of pumpkins and helmets") - .build(this); - - this.portal = Setting.Bool.builder() - .fallback(true) - .name("portal") - .comment("cancel overlay in nether portals") - .build(this); - } - - @SubscribeEvent - public void onGameOverlay(RenderGameOverlayEvent event) { - switch (event.getType()) { - case HELMET: - if (event.isCancelable() && this.helmet.get()) - event.setCanceled(true); - break; - case PORTAL: - if (event.isCancelable() && this.portal.get()) - event.setCanceled(true); - break; - default: - break; - } - } - - @SubscribeEvent - public void onRenderBlockOverlay(RenderBlockOverlayEvent event) { - if (this.block.get()) event.setCanceled(true); - } - - @SubscribeEvent - public void onFogRender(EntityViewRenderEvent.FogDensity event) { - if ( - this.liquid.get() && - MC.player != null && - (MC.player.isInLava() || MC.player.isInWater()) - ) { - event.setDensity(0); - event.setCanceled(true); - } - } -} diff --git a/src/main/java/ftbsc/bscv/modules/self/NoOverlay.java b/src/main/java/ftbsc/bscv/modules/self/NoOverlay.java new file mode 100644 index 0000000..d2b02cf --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/self/NoOverlay.java @@ -0,0 +1,82 @@ +package ftbsc.bscv.modules.self; + +import com.google.auto.service.AutoService; + +import ftbsc.bscv.api.ILoadable; +import ftbsc.bscv.modules.AbstractModule; +import ftbsc.bscv.tools.Setting; +import net.minecraftforge.client.event.EntityViewRenderEvent; +import net.minecraftforge.client.event.RenderBlockOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +@AutoService(ILoadable.class) +public class NoOverlay extends AbstractModule { + + public final ForgeConfigSpec.ConfigValue liquid; + public final ForgeConfigSpec.ConfigValue block; + public final ForgeConfigSpec.ConfigValue helmet; + public final ForgeConfigSpec.ConfigValue portal; + + public NoOverlay() { + super(); + + this.liquid = Setting.Bool.builder() + .fallback(true) + .name("liquid") + .comment("cancel overlay in water and lava") + .build(this); + + this.block = Setting.Bool.builder() + .fallback(true) + .name("block") + .comment("cancel overlay of blocks on your head") + .build(this); + + this.helmet = Setting.Bool.builder() + .fallback(true) + .name("helmet") + .comment("cancel overlay of pumpkins and helmets") + .build(this); + + this.portal = Setting.Bool.builder() + .fallback(true) + .name("portal") + .comment("cancel overlay in nether portals") + .build(this); + } + + @SubscribeEvent + public void onGameOverlay(RenderGameOverlayEvent event) { + switch (event.getType()) { + case HELMET: + if (event.isCancelable() && this.helmet.get()) + event.setCanceled(true); + break; + case PORTAL: + if (event.isCancelable() && this.portal.get()) + event.setCanceled(true); + break; + default: + break; + } + } + + @SubscribeEvent + public void onRenderBlockOverlay(RenderBlockOverlayEvent event) { + if (this.block.get()) event.setCanceled(true); + } + + @SubscribeEvent + public void onFogRender(EntityViewRenderEvent.FogDensity event) { + if ( + this.liquid.get() && + MC.player != null && + (MC.player.isInLava() || MC.player.isInWater()) + ) { + event.setDensity(0); + event.setCanceled(true); + } + } +} -- cgit v1.2.3-56-ga3b1 From c2874312d37a258ad88d600b7bf08fe7e58e4e49 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:26:27 +0100 Subject: feat: added item search command also renamed because it clashed with import --- src/main/java/ftbsc/bscv/commands/Item.java | 43 ---------------- src/main/java/ftbsc/bscv/commands/ItemCommand.java | 59 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 43 deletions(-) delete mode 100644 src/main/java/ftbsc/bscv/commands/Item.java create mode 100644 src/main/java/ftbsc/bscv/commands/ItemCommand.java (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/commands/Item.java b/src/main/java/ftbsc/bscv/commands/Item.java deleted file mode 100644 index 2d4bd7f..0000000 --- a/src/main/java/ftbsc/bscv/commands/Item.java +++ /dev/null @@ -1,43 +0,0 @@ -package ftbsc.bscv.commands; - -import com.google.auto.service.AutoService; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; - -import ftbsc.bscv.api.ILoadable; -import ftbsc.bscv.tools.Inventory; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -import net.minecraft.inventory.container.Slot; - -import static ftbsc.bscv.Boscovicino.log; - -@AutoService(ILoadable.class) -public class Item extends AbstractCommand { - - public LiteralArgumentBuilder register(LiteralArgumentBuilder builder) { - return builder - .then( - Commands.literal("damage") - .executes(ctx -> { - Slot slot = Inventory.hotbar(MC.player).get(MC.player.inventory.selected); - if (!slot.hasItem()) return 0; - log( - String.format( - "A %.1f | S %.1f | DPS %.2f", - Inventory.itemAttackDamage(slot.getItem()), - Inventory.itemAttackSpeed(slot.getItem()), - Inventory.itemDPS(slot.getItem()) - ) - ); - return 1; - }) - ) - .executes(ctx -> { - Slot slot = Inventory.hotbar(MC.player).get(MC.player.inventory.selected); - if (!slot.hasItem()) return 0; - log(slot.getItem().toString()); - return 1; - }); - } - -} diff --git a/src/main/java/ftbsc/bscv/commands/ItemCommand.java b/src/main/java/ftbsc/bscv/commands/ItemCommand.java new file mode 100644 index 0000000..e1e1b80 --- /dev/null +++ b/src/main/java/ftbsc/bscv/commands/ItemCommand.java @@ -0,0 +1,59 @@ +package ftbsc.bscv.commands; + +import com.google.auto.service.AutoService; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import ftbsc.bscv.api.ILoadable; +import ftbsc.bscv.tools.Inventory; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.inventory.container.Slot; +import net.minecraft.item.Item; + +import static ftbsc.bscv.Boscovicino.log; + +@AutoService(ILoadable.class) +public class ItemCommand extends AbstractCommand { + + @Override + public String getName() { return "item"; } + + public LiteralArgumentBuilder register(LiteralArgumentBuilder builder) { + return builder + .then( + Commands.literal("damage") + .executes(ctx -> { + Slot slot = Inventory.hotbar(MC.player).get(MC.player.inventory.selected); + if (!slot.hasItem()) return 0; + log( + String.format( + "A %.1f | S %.1f | DPS %.2f", + Inventory.itemAttackDamage(slot.getItem()), + Inventory.itemAttackSpeed(slot.getItem()), + Inventory.itemDPS(slot.getItem()) + ) + ); + return 1; + }) + ) + .then( + Commands.literal("search") + .then( + Commands.argument("id", IntegerArgumentType.integer(0)) + .executes(ctx -> { + int item_id = ctx.getArgument("id", Integer.class); + log("item #[%d] >> %s", item_id, Item.byId(item_id).toString()); + return 1; + }) + ) + ) + .executes(ctx -> { + Slot slot = Inventory.hotbar(MC.player).get(MC.player.inventory.selected); + if (!slot.hasItem()) return 0; + log(slot.getItem().toString()); + return 1; + }); + } + +} -- cgit v1.2.3-56-ga3b1 From 0045af0117debe4f7d70900949888a7ee855169c Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:26:49 +0100 Subject: chore: better default reach for aura --- src/main/java/ftbsc/bscv/modules/defense/Aura.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/defense/Aura.java b/src/main/java/ftbsc/bscv/modules/defense/Aura.java index f031f2c..e38be1e 100644 --- a/src/main/java/ftbsc/bscv/modules/defense/Aura.java +++ b/src/main/java/ftbsc/bscv/modules/defense/Aura.java @@ -52,7 +52,7 @@ public class Aura extends QuickModule { this.reach = Setting.Decimal.builder() .min(0.) - .fallback(5.) + .fallback(4.) .name("reach") .comment("aura attack reach") .build(this); -- cgit v1.2.3-56-ga3b1 From cf6986886390e1aba113fbd3f4a5ce197345cd41 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:27:23 +0100 Subject: feat: use list of integers (ids) for containerclean --- .../ftbsc/bscv/modules/self/ContainerCleaner.java | 37 +++++++++++----------- 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java index d08d832..02af2f2 100644 --- a/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java +++ b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java @@ -1,16 +1,20 @@ package ftbsc.bscv.modules.self; -import java.util.regex.Pattern; +import java.util.ArrayList; +import java.util.List; + import com.google.auto.service.AutoService; -import ftbsc.bscv.Boscovicino; import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.tools.Inventory; import ftbsc.bscv.tools.Setting; import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.command.arguments.ItemArgument; +import net.minecraft.command.arguments.ItemInput; import net.minecraft.inventory.container.ClickType; import net.minecraft.inventory.container.Slot; +import net.minecraft.item.Item; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -18,23 +22,14 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; @AutoService(ILoadable.class) public class ContainerCleaner extends AbstractModule { - public final ForgeConfigSpec.ConfigValue query; public final ForgeConfigSpec.ConfigValue cooldown; public final ForgeConfigSpec.ConfigValue limit; - private Pattern pattern; + public final ForgeConfigSpec.ConfigValue> blacklist; private int counter; public ContainerCleaner() { super(); - this.pattern = Pattern.compile(""); - this.query = Setting.Str.builder() - .fallback("") - .name("query") - .comment("search query for dropping items") - .callback(to -> this.pattern = Pattern.compile(to)) - .build(this); - this.counter = 0; this.cooldown = Setting.Number.builder() .fallback(0) @@ -47,6 +42,13 @@ public class ContainerCleaner extends AbstractModule { .name("limit") .comment("limit to one action per tick") .build(this); + + this.blacklist = new Setting.Many(ItemArgument.item(), ItemInput.class) + .writer(x -> Item.getId(x.getItem())) + .fallback(new ArrayList()) + .name("blacklist") + .comment("items to throw away") + .build(this); } @SubscribeEvent @@ -59,12 +61,11 @@ public class ContainerCleaner extends AbstractModule { } ContainerScreen screen = (ContainerScreen) MC.screen; for (Slot slot : screen.getMenu().slots) { - if (Inventory.matchItem(this.pattern, slot.getItem())) { - Boscovicino.log("dropping item %s", slot.getItem().getItem()); - Inventory.clickSLot(screen.getMenu().containerId, slot, ClickType.THROW); - this.counter = this.cooldown.get(); - if (this.limit.get()) return; // only throw one item per tick - } + if (this.blacklist.get().contains(Item.getId(slot.getItem().getItem()))) { + Inventory.clickSLot(screen.getMenu().containerId, slot, ClickType.THROW); + this.counter = this.cooldown.get(); + if (this.limit.get()) return; // only throw one item per tick + } } } } -- cgit v1.2.3-56-ga3b1 From 939a0f7a40f9c9c4864e7b39a039fbf56c7333ac Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:40:59 +0100 Subject: fix: typo --- src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java | 2 +- src/main/java/ftbsc/bscv/tools/Inventory.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java index 02af2f2..059c4bb 100644 --- a/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java +++ b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java @@ -62,7 +62,7 @@ public class ContainerCleaner extends AbstractModule { ContainerScreen screen = (ContainerScreen) MC.screen; for (Slot slot : screen.getMenu().slots) { if (this.blacklist.get().contains(Item.getId(slot.getItem().getItem()))) { - Inventory.clickSLot(screen.getMenu().containerId, slot, ClickType.THROW); + Inventory.clickSlot(screen.getMenu().containerId, slot.index, ClickType.THROW); this.counter = this.cooldown.get(); if (this.limit.get()) return; // only throw one item per tick } diff --git a/src/main/java/ftbsc/bscv/tools/Inventory.java b/src/main/java/ftbsc/bscv/tools/Inventory.java index f044be8..ec36e89 100644 --- a/src/main/java/ftbsc/bscv/tools/Inventory.java +++ b/src/main/java/ftbsc/bscv/tools/Inventory.java @@ -92,12 +92,12 @@ public class Inventory implements ICommons { return out; } - public static void clickSLot(Slot slot, ClickType click) { clickSlot(0, slot, 0, click); } - public static void clickSLot(Slot slot, int button, ClickType click) { clickSlot(0, slot, button, click); } - public static void clickSLot(int container, Slot slot, ClickType click) { clickSlot(container, slot, 0, click); } + public static void clickSlot(int slot_index, ClickType click) { clickSlot(0, slot_index, 0, click); } + public static void clickSlot(Slot slot, int button, ClickType click) { clickSlot(0, slot.index, button, click); } + public static void clickSlot(int container, int slot_index, ClickType click) { clickSlot(container, slot_index, 0, click); } - public static void clickSlot(int container, Slot slot, int button, ClickType click) { - MC.gameMode.handleInventoryMouseClick(container, slot.index, button, click, MC.player); + public static void clickSlot(int container, int slot_index, int button, ClickType click) { + MC.gameMode.handleInventoryMouseClick(container, slot_index, button, click, MC.player); } public static boolean matchItem(Pattern pattern, ItemStack stack) { -- cgit v1.2.3-56-ga3b1 From 34b96b67d31d032a72a72eb37e3b79809ef9fbbd Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 04:41:06 +0100 Subject: feat: added crude fastcraft --- .../java/ftbsc/bscv/modules/self/FastCraft.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/ftbsc/bscv/modules/self/FastCraft.java (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/self/FastCraft.java b/src/main/java/ftbsc/bscv/modules/self/FastCraft.java new file mode 100644 index 0000000..d4aaa77 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/self/FastCraft.java @@ -0,0 +1,39 @@ +package ftbsc.bscv.modules.self; + +import com.google.auto.service.AutoService; +import ftbsc.bscv.api.ILoadable; +import ftbsc.bscv.modules.AbstractModule; +import ftbsc.bscv.tools.Inventory; +import ftbsc.bscv.tools.Setting; +import net.minecraft.client.gui.screen.inventory.InventoryScreen; +import net.minecraft.inventory.container.ClickType; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent.ClientTickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +@AutoService(ILoadable.class) +public class FastCraft extends AbstractModule { + + public final ForgeConfigSpec.ConfigValue drop; + + public FastCraft() { + super(); + + this.drop = Setting.Bool.builder() + .fallback(false) + .name("drop") + .comment("throw cradted items away instead of moving them back in inventory") + .build(this); + } + + @SubscribeEvent + public void onTick(ClientTickEvent event) { + if (MC.screen == null) return; + if (!(MC.screen instanceof InventoryScreen)) return; + InventoryScreen inventory = (InventoryScreen) MC.screen; + if (inventory.getMenu().slots.get(0).hasItem()) { + // TODO can we throw them all? like this it throws one by one + Inventory.clickSlot(0, this.drop.get() ? ClickType.THROW : ClickType.QUICK_MOVE); + } + } +} -- cgit v1.2.3-56-ga3b1 From aebd63ac13f2e613a6d5a13ee9aff8740bf43c9e Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Nov 2023 05:02:17 +0100 Subject: feat: /mods command lists all mods badly tho: it doesn't fit on screen and must be read from minecraft logs --- src/main/java/ftbsc/bscv/commands/ModCommands.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/commands/ModCommands.java b/src/main/java/ftbsc/bscv/commands/ModCommands.java index 82e8661..57e1887 100644 --- a/src/main/java/ftbsc/bscv/commands/ModCommands.java +++ b/src/main/java/ftbsc/bscv/commands/ModCommands.java @@ -9,7 +9,7 @@ import ftbsc.bscv.api.IModule; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; -import static ftbsc.bscv.Boscovicino.log; +import java.util.stream.Collectors; @AutoService(ILoadable.class) public class ModCommands extends AbstractCommand { @@ -43,8 +43,11 @@ public class ModCommands extends AbstractCommand { }) ) .executes(ctx -> { - log("no args specified"); - return 0; + String mods = Boscovicino.modManager.mods.stream() + .map(x -> x.getName()) + .collect(Collectors.joining(",")); + Boscovicino.log("[ %s ]", mods); + return 1; }); } -- cgit v1.2.3-56-ga3b1 From 63cfbaa56ccf67da7b65cf058a68a4b843af5748 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 26 Nov 2023 00:07:22 +0100 Subject: feat[containercleaner]: throw whole stacks --- src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java index 059c4bb..c53fed0 100644 --- a/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java +++ b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java @@ -24,6 +24,7 @@ public class ContainerCleaner extends AbstractModule { public final ForgeConfigSpec.ConfigValue cooldown; public final ForgeConfigSpec.ConfigValue limit; + public final ForgeConfigSpec.ConfigValue all; public final ForgeConfigSpec.ConfigValue> blacklist; private int counter; @@ -43,6 +44,12 @@ public class ContainerCleaner extends AbstractModule { .comment("limit to one action per tick") .build(this); + this.all = Setting.Bool.builder() + .fallback(true) + .name("all") + .comment("throw whole stacks instead of single items") + .build(this); + this.blacklist = new Setting.Many(ItemArgument.item(), ItemInput.class) .writer(x -> Item.getId(x.getItem())) .fallback(new ArrayList()) @@ -62,7 +69,8 @@ public class ContainerCleaner extends AbstractModule { ContainerScreen screen = (ContainerScreen) MC.screen; for (Slot slot : screen.getMenu().slots) { if (this.blacklist.get().contains(Item.getId(slot.getItem().getItem()))) { - Inventory.clickSlot(screen.getMenu().containerId, slot.index, ClickType.THROW); + int button = this.all.get() ? 1 : 0; + Inventory.clickSlot(screen.getMenu().containerId, slot.index, button, ClickType.THROW); this.counter = this.cooldown.get(); if (this.limit.get()) return; // only throw one item per tick } -- cgit v1.2.3-56-ga3b1