From 1962587f21b4161982aa40ee5455b333245b3c57 Mon Sep 17 00:00:00 2001 From: jellylab Date: Mon, 8 Aug 2022 20:34:09 +0800 Subject: [PATCH] tons of shit --- .../com/jelly/MightyMiner/MightyMiner.java | 11 ++- .../baritone/automine/AutoMineBaritone.java | 98 +++++++++---------- .../automine/config/MineBehaviour.java | 19 ++++ .../automine/pathing/AStarPathFinder.java | 93 ++++++++---------- .../pathing/config/PathBehaviour.java | 35 +++++++ .../com/jelly/MightyMiner/config/Config.java | 73 ++++++++++++++ .../MightyMiner/handlers/KeybindHandler.java | 28 +++--- .../macros/macros/GemstoneMacro.java | 27 +++-- .../MightyMiner/mixins/MixinMinecraft.java | 16 +++ .../jelly/MightyMiner/player/Rotation.java | 7 +- .../jelly/MightyMiner/utils/BlockUtils.java | 1 + .../jelly/MightyMiner/utils/PlayerUtils.java | 18 ++++ src/main/resources/mixins.mightyminer.json | 5 +- 13 files changed, 295 insertions(+), 136 deletions(-) create mode 100644 src/main/java/com/jelly/MightyMiner/baritone/automine/config/MineBehaviour.java create mode 100644 src/main/java/com/jelly/MightyMiner/baritone/automine/pathing/config/PathBehaviour.java create mode 100644 src/main/java/com/jelly/MightyMiner/config/Config.java create mode 100644 src/main/java/com/jelly/MightyMiner/mixins/MixinMinecraft.java diff --git a/src/main/java/com/jelly/MightyMiner/MightyMiner.java b/src/main/java/com/jelly/MightyMiner/MightyMiner.java index b658f7c0..48c60965 100644 --- a/src/main/java/com/jelly/MightyMiner/MightyMiner.java +++ b/src/main/java/com/jelly/MightyMiner/MightyMiner.java @@ -1,5 +1,6 @@ package com.jelly.MightyMiner; +import com.jelly.MightyMiner.config.Config; import com.jelly.MightyMiner.handlers.KeybindHandler; import com.jelly.MightyMiner.handlers.MacroHandler; import com.jelly.MightyMiner.macros.macros.GemstoneMacro; @@ -14,11 +15,17 @@ public class MightyMiner { public static final String MODID = "mightyminer"; public static final String VERSION = "1.0"; + public static Config config; + + //thx pizza for fixing this + public static void onStartGame(){ + config = new Config(); + } + + @Mod.EventHandler public void init(FMLInitializationEvent event) { - - MinecraftForge.EVENT_BUS.register(new MacroHandler()); MinecraftForge.EVENT_BUS.register(new KeybindHandler()); MinecraftForge.EVENT_BUS.register(new GemstoneMacro()); diff --git a/src/main/java/com/jelly/MightyMiner/baritone/automine/AutoMineBaritone.java b/src/main/java/com/jelly/MightyMiner/baritone/automine/AutoMineBaritone.java index d5e4f9c3..3ee758d4 100644 --- a/src/main/java/com/jelly/MightyMiner/baritone/automine/AutoMineBaritone.java +++ b/src/main/java/com/jelly/MightyMiner/baritone/automine/AutoMineBaritone.java @@ -1,5 +1,8 @@ package com.jelly.MightyMiner.baritone.automine; +import com.jelly.MightyMiner.MightyMiner; +import com.jelly.MightyMiner.baritone.automine.config.MineBehaviour; +import com.jelly.MightyMiner.baritone.automine.pathing.config.PathBehaviour; import com.jelly.MightyMiner.baritone.logging.Logger; import com.jelly.MightyMiner.baritone.automine.pathing.AStarPathFinder; import com.jelly.MightyMiner.baritone.structures.BlockNode; @@ -10,6 +13,7 @@ import com.jelly.MightyMiner.utils.*; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraftforge.client.event.RenderGameOverlayEvent; @@ -17,12 +21,11 @@ import java.awt.*; import java.util.LinkedList; -import java.util.List; public class AutoMineBaritone{ Minecraft mc = Minecraft.getMinecraft(); - + MineBehaviour mineBehaviour; LinkedList blocksToMine = new LinkedList<>(); LinkedList minedBlocks = new LinkedList<>(); @@ -32,10 +35,6 @@ public class AutoMineBaritone{ int deltaJumpTick = 0; - List forbiddenMiningBlocks; - List allowedMiningBlocks; - boolean shiftWhenMine; - enum PlayerState { WALKING, MINING, @@ -46,28 +45,12 @@ enum PlayerState { AStarPathFinder pathFinder; - public AutoMineBaritone(){} - - public AutoMineBaritone(List forbiddenMiningBlocks){ - pathFinder = new AStarPathFinder(null, null); - this.forbiddenMiningBlocks = forbiddenMiningBlocks; - } - - public AutoMineBaritone(List forbiddenMiningBlocks, List allowedMiningBlocks){ - this.forbiddenMiningBlocks = forbiddenMiningBlocks; - this.allowedMiningBlocks = allowedMiningBlocks; - pathFinder = new AStarPathFinder(forbiddenMiningBlocks, allowedMiningBlocks); - } - - public AutoMineBaritone(List forbiddenMiningBlocks, List allowedMiningBlocks, boolean shiftWhenMine){ - this.forbiddenMiningBlocks = forbiddenMiningBlocks; - this.allowedMiningBlocks = allowedMiningBlocks; - this.shiftWhenMine = shiftWhenMine; - pathFinder = new AStarPathFinder(forbiddenMiningBlocks, allowedMiningBlocks); + public AutoMineBaritone(PathBehaviour pathBehaviour, MineBehaviour mineBehaviour){ + pathFinder = new AStarPathFinder(pathBehaviour); + this.mineBehaviour = mineBehaviour; } - public void clearBlocksToWalk(){ blocksToMine.clear(); BlockRenderer.renderMap.clear(); @@ -75,11 +58,7 @@ public void clearBlocksToWalk(){ } - - - public void enableBaritone(Block... blockType){ - enabled = true; mc.thePlayer.addChatMessage(new ChatComponentText("Starting automine")); @@ -107,12 +86,16 @@ public void enableBaritone(Block... blockType){ inAction = true; currentState = PlayerState.NONE; + stuckTickCount = 0; }).start(); } public void disableBaritone() { + pauseMacro(); enabled = false; + } + private void pauseMacro() { inAction = false; currentState = PlayerState.NONE; KeybindHandler.resetKeybindState(); @@ -137,43 +120,42 @@ public void onOverlayRenderEvent(RenderGameOverlayEvent event){ } } - public void onTickEvent(TickEvent.Phase phase){ - - if(phase != TickEvent.Phase.START) - return; - if(!inAction) - return; + int stuckTickCount = 0; + public void onTickEvent(TickEvent.Phase phase){ - if(blocksToMine.isEmpty()) + if(phase != TickEvent.Phase.START || !inAction || blocksToMine.isEmpty()) return; - if ( (blocksToMine.getLast().getBlockType() == BlockType.MINE && BlockUtils.isPassable(blocksToMine.getLast().getBlockPos())) - || (blocksToMine.getLast().getBlockType() == BlockType.WALK && + if ( (blocksToMine.getLast().getBlockType() == BlockType.MINE && BlockUtils.isPassable(blocksToMine.getLast().getBlockPos())) || + (blocksToMine.getLast().getBlockType() == BlockType.WALK && (BlockUtils.onTheSameXZ(blocksToMine.getLast().getBlockPos(), BlockUtils.getPlayerLoc()) || !BlockUtils.fitsPlayer(blocksToMine.getLast().getBlockPos().down())) ) ){ - + stuckTickCount = 0; minedBlocks.add(blocksToMine.getLast()); BlockRenderer.renderMap.remove(blocksToMine.getLast().getBlockPos()); blocksToMine.removeLast(); + } else { + //stuck handling + stuckTickCount++; + if(stuckTickCount > 20 * MightyMiner.config.gemRestartTimeThreshold){ + new Thread(restartBaritone).start(); + return; + } } + if(blocksToMine.isEmpty() || BlockUtils.isPassable(blocksToMine.getFirst().getBlockPos())){ mc.thePlayer.addChatMessage(new ChatComponentText("Finished baritone")); - inAction = false; - KeybindHandler.resetKeybindState(); disableBaritone(); return; } - - updateState(); BlockPos lastMinedBlockPos = minedBlocks.isEmpty() ? null : minedBlocks.getLast().getBlockPos(); BlockPos targetMineBlock = blocksToMine.getLast().getBlockPos(); switch (currentState){ - case WALKING: KeybindHandler.updateKeys( (lastMinedBlockPos != null || BlockUtils.isPassable(targetMineBlock)), @@ -185,11 +167,10 @@ public void onTickEvent(TickEvent.Phase phase){ false, deltaJumpTick > 0); - if(BlockUtils.isPassable(targetMineBlock)) - rotation.intLockAngle(AngleUtils.getRequiredYaw(targetMineBlock), mc.thePlayer.rotationPitch, 350); + rotation.intLockAngle(AngleUtils.getRequiredYaw(targetMineBlock), mc.thePlayer.rotationPitch, mineBehaviour.getRotationTime()); else if(lastMinedBlockPos != null) - rotation.intLockAngle(AngleUtils.getRequiredYaw(lastMinedBlockPos), mc.thePlayer.rotationPitch, 350); + rotation.intLockAngle(AngleUtils.getRequiredYaw(lastMinedBlockPos), mc.thePlayer.rotationPitch, mineBehaviour.getRotationTime()); if(lastMinedBlockPos != null){ @@ -211,25 +192,24 @@ else if(lastMinedBlockPos != null) break; case MINING: + mc.thePlayer.inventory.currentItem = PlayerUtils.getItemInHotbar("Pick", "Drill"); KeybindHandler.updateKeys( false, false, false, false, mc.objectMouseOver != null && mc.objectMouseOver.getBlockPos() != null && - mc.objectMouseOver.getBlockPos().equals(targetMineBlock) && PlayerUtils.hasStoppedMoving(), + mc.objectMouseOver.getBlockPos().equals(targetMineBlock), false, - shiftWhenMine, + mineBehaviour.isShiftWhenMine(), false); - if(mc.objectMouseOver != null && mc.objectMouseOver.getBlockPos() != null && !mc.objectMouseOver.getBlockPos().equals(targetMineBlock)) { + if(mc.objectMouseOver != null && mc.objectMouseOver.getBlockPos() != null){ if (!BlockUtils.isPassable(targetMineBlock) && !rotation.rotating) - rotation.intLockAngle(AngleUtils.getRequiredYaw(targetMineBlock), AngleUtils.getRequiredPitch(targetMineBlock), 350); + rotation.intLockAngle(AngleUtils.getRequiredYaw(targetMineBlock), AngleUtils.getRequiredPitch(targetMineBlock), mineBehaviour.getRotationTime()); } break; - - } if (deltaJumpTick > 0) @@ -266,7 +246,6 @@ private void updateState(){ } } else if(currentState == PlayerState.MINING){ - if (blocksToMine.getLast().getBlockType() == BlockType.MINE) { if( (BlockUtils.fitsPlayer(minedBlocks.getLast().getBlockPos().down()) || BlockUtils.fitsPlayer(minedBlocks.getLast().getBlockPos().down(2))) && !BlockUtils.onTheSameXZ(minedBlocks.getLast().getBlockPos(), BlockUtils.getPlayerLoc())) { @@ -279,5 +258,16 @@ private void updateState(){ } } + private final Runnable restartBaritone = () -> { + try { + pauseMacro(); + mc.thePlayer.addChatMessage(new ChatComponentText("Restarting baritone")); + Thread.sleep(200); + KeybindHandler.setKeyBindState(KeybindHandler.keybindS, true); + Thread.sleep(100); + enableBaritone(Blocks.stained_glass, Blocks.stained_glass_pane); + } catch (InterruptedException ignored) {} + }; + } diff --git a/src/main/java/com/jelly/MightyMiner/baritone/automine/config/MineBehaviour.java b/src/main/java/com/jelly/MightyMiner/baritone/automine/config/MineBehaviour.java new file mode 100644 index 00000000..e9dc6a54 --- /dev/null +++ b/src/main/java/com/jelly/MightyMiner/baritone/automine/config/MineBehaviour.java @@ -0,0 +1,19 @@ +package com.jelly.MightyMiner.baritone.automine.config; + +public class MineBehaviour { + boolean shiftWhenMine; + int rotationTime; + + public MineBehaviour(boolean shiftWhenMine, int rotationTime) { + this.shiftWhenMine = shiftWhenMine; + this.rotationTime = rotationTime; + } + + public boolean isShiftWhenMine() { + return shiftWhenMine; + } + + public int getRotationTime() { + return rotationTime; + } +} diff --git a/src/main/java/com/jelly/MightyMiner/baritone/automine/pathing/AStarPathFinder.java b/src/main/java/com/jelly/MightyMiner/baritone/automine/pathing/AStarPathFinder.java index fea5d52e..73a1ab12 100644 --- a/src/main/java/com/jelly/MightyMiner/baritone/automine/pathing/AStarPathFinder.java +++ b/src/main/java/com/jelly/MightyMiner/baritone/automine/pathing/AStarPathFinder.java @@ -1,5 +1,6 @@ package com.jelly.MightyMiner.baritone.automine.pathing; +import com.jelly.MightyMiner.baritone.automine.pathing.config.PathBehaviour; import com.jelly.MightyMiner.baritone.logging.Logger; import com.jelly.MightyMiner.baritone.automine.pathing.exceptions.NoBlockException; import com.jelly.MightyMiner.baritone.automine.pathing.exceptions.NoPathException; @@ -25,17 +26,15 @@ public class AStarPathFinder { GridEnvironment gridEnvironment = new GridEnvironment<>(); int step; - - List forbiddenMiningBlocks; - List allowedMiningBlocks; + PathBehaviour pathBehaviour; List checkedNodes = new ArrayList<>(); PriorityQueue openNodes = new PriorityQueue<>(Comparator.comparingDouble(n -> n.fValue)); - public AStarPathFinder(List forbiddenMiningBlocks, List allowedMiningBlocks){ - this.forbiddenMiningBlocks = forbiddenMiningBlocks; - this.allowedMiningBlocks = allowedMiningBlocks; + + public AStarPathFinder(PathBehaviour options){ + this.pathBehaviour = options; } public LinkedList getPath(Block... blockType) throws NoBlockException, NoPathException { @@ -110,45 +109,42 @@ private LinkedList calculatePath(BlockPos startingPos, BlockPos endin instantiateNode(currentGridX + 1, currentGridY, currentGridZ, startNode); checkNode(gridEnvironment.get(currentGridX + 1, currentGridY, currentGridZ), currentNode, endingBlock); - instantiateNode(currentGridX, currentGridY, currentGridZ - 1, startNode); checkNode(gridEnvironment.get(currentGridX, currentGridY, currentGridZ - 1), currentNode, endingBlock); instantiateNode(currentGridX, currentGridY, currentGridZ + 1, startNode); checkNode(gridEnvironment.get(currentGridX, currentGridY, currentGridZ + 1), currentNode, endingBlock); + if(currentGridY > pathBehaviour.getMinY()) { + instantiateNode(currentGridX - 1, currentGridY - 1, currentGridZ, startNode); + checkNode(gridEnvironment.get(currentGridX - 1, currentGridY - 1, currentGridZ), currentNode, endingBlock); - instantiateNode(currentGridX - 1, currentGridY - 1, currentGridZ, startNode); - checkNode(gridEnvironment.get(currentGridX - 1, currentGridY - 1, currentGridZ), currentNode, endingBlock); - - - instantiateNode(currentGridX + 1, currentGridY - 1, currentGridZ, startNode); - checkNode(gridEnvironment.get(currentGridX + 1, currentGridY - 1, currentGridZ), currentNode, endingBlock); - - - instantiateNode(currentGridX, currentGridY - 1, currentGridZ - 1, startNode); - checkNode(gridEnvironment.get(currentGridX, currentGridY - 1, currentGridZ - 1), currentNode, endingBlock); + instantiateNode(currentGridX + 1, currentGridY - 1, currentGridZ, startNode); + checkNode(gridEnvironment.get(currentGridX + 1, currentGridY - 1, currentGridZ), currentNode, endingBlock); + instantiateNode(currentGridX, currentGridY - 1, currentGridZ - 1, startNode); + checkNode(gridEnvironment.get(currentGridX, currentGridY - 1, currentGridZ - 1), currentNode, endingBlock); - instantiateNode(currentGridX, currentGridY - 1, currentGridZ + 1, startNode); - checkNode(gridEnvironment.get(currentGridX, currentGridY - 1, currentGridZ + 1), currentNode, endingBlock); + instantiateNode(currentGridX, currentGridY - 1, currentGridZ + 1, startNode); + checkNode(gridEnvironment.get(currentGridX, currentGridY - 1, currentGridZ + 1), currentNode, endingBlock); - instantiateNode(currentGridX - 1, currentGridY + 1, currentGridZ, startNode); - checkNode(gridEnvironment.get(currentGridX - 1, currentGridY + 1, currentGridZ), currentNode, endingBlock); - - instantiateNode(currentGridX + 1, currentGridY + 1, currentGridZ, startNode); - checkNode(gridEnvironment.get(currentGridX + 1, currentGridY + 1, currentGridZ), currentNode, endingBlock); - - instantiateNode(currentGridX, currentGridY + 1, currentGridZ - 1, startNode); - checkNode(gridEnvironment.get(currentGridX, currentGridY + 1, currentGridZ - 1), currentNode, endingBlock); + instantiateNode(currentGridX, currentGridY - 1, currentGridZ, startNode); + checkNode(gridEnvironment.get(currentGridX, currentGridY - 1, currentGridZ), currentNode, endingBlock); + } - instantiateNode(currentGridX, currentGridY + 1, currentGridZ + 1, startNode); - checkNode(gridEnvironment.get(currentGridX, currentGridY + 1, currentGridZ + 1), currentNode, endingBlock); + if(currentGridY < pathBehaviour.getMaxY()) { + instantiateNode(currentGridX - 1, currentGridY + 1, currentGridZ, startNode); + checkNode(gridEnvironment.get(currentGridX - 1, currentGridY + 1, currentGridZ), currentNode, endingBlock); - instantiateNode(currentGridX, currentGridY - 1, currentGridZ, startNode); - checkNode(gridEnvironment.get(currentGridX, currentGridY - 1, currentGridZ), currentNode, endingBlock); + instantiateNode(currentGridX + 1, currentGridY + 1, currentGridZ, startNode); + checkNode(gridEnvironment.get(currentGridX + 1, currentGridY + 1, currentGridZ), currentNode, endingBlock); + instantiateNode(currentGridX, currentGridY + 1, currentGridZ - 1, startNode); + checkNode(gridEnvironment.get(currentGridX, currentGridY + 1, currentGridZ - 1), currentNode, endingBlock); + instantiateNode(currentGridX, currentGridY + 1, currentGridZ + 1, startNode); + checkNode(gridEnvironment.get(currentGridX, currentGridY + 1, currentGridZ + 1), currentNode, endingBlock); + } if(currentNode.blockPos.equals(endingBlock)) { return trackBackPath(currentNode, startNode); @@ -164,17 +160,21 @@ private void checkNode(Node searchNode, Node currentNode, BlockPos endingBlockPo if (!checkedNodes.contains(searchNode) && BlockUtils.canWalkOn(searchNode.blockPos.down())){ if(!searchNode.blockPos.equals(endingBlockPos)) { - if (forbiddenMiningBlocks != null && forbiddenMiningBlocks.contains(BlockUtils.getBlock(searchNode.blockPos)) && !BlockUtils.getBlock(searchNode.blockPos).equals(Blocks.air)) - return; - - if (allowedMiningBlocks != null && !allowedMiningBlocks.contains(BlockUtils.getBlock(searchNode.blockPos)) && !BlockUtils.getBlock(searchNode.blockPos).equals(Blocks.air)) - return; + if(pathBehaviour.getForbiddenMiningBlocks() != null){ + if ((pathBehaviour.getForbiddenMiningBlocks().contains(BlockUtils.getBlock(searchNode.blockPos)) && !BlockUtils.getBlock(searchNode.blockPos).equals(Blocks.air)) || + (pathBehaviour.getForbiddenMiningBlocks().contains(BlockUtils.getBlock(searchNode.blockPos.up())) && !BlockUtils.getBlock(searchNode.blockPos.up()).equals(Blocks.air))) + return; + } + if(pathBehaviour.getAllowedMiningBlocks() != null){ + if((!pathBehaviour.getAllowedMiningBlocks().contains(BlockUtils.getBlock(searchNode.blockPos)) && !BlockUtils.getBlock(searchNode.blockPos).equals(Blocks.air)) || + (!pathBehaviour.getAllowedMiningBlocks().contains(BlockUtils.getBlock(searchNode.blockPos.up())) && !BlockUtils.getBlock(searchNode.blockPos.up()).equals(Blocks.air))) + return; + } } if(!openNodes.contains(searchNode)){ calculateCost(searchNode, endingBlockPos); searchNode.lastNode = currentNode; openNodes.add(searchNode); - } else { if(currentNode.gValue + (Math.abs(searchNode.blockPos.getY() - currentNode.blockPos.getY()) > 0 ? 2 : 1) < searchNode.gValue){ Logger.log("Found better path"); @@ -242,23 +242,10 @@ private LinkedList trackBackPath(Node goalNode, Node startNode){ blocksToMine.add(new BlockNode(currentTrackNode.blockPos, getBlockType(currentTrackNode.blockPos))); } else { + blocksToMine.add(new BlockNode(currentTrackNode.blockPos, getBlockType(currentTrackNode.blockPos))); + if (!BlockUtils.isPassable(currentTrackNode.blockPos.up())) + blocksToMine.add(new BlockNode(currentTrackNode.blockPos.up(), getBlockType(currentTrackNode.blockPos.up()))); - if((AngleUtils.shouldLookAtCenter(currentTrackNode.blockPos.up()) && !AngleUtils.shouldLookAtCenter(currentTrackNode.blockPos))) { - - - if (!BlockUtils.isPassable(currentTrackNode.blockPos.up())) - blocksToMine.add(new BlockNode(currentTrackNode.blockPos.up(), getBlockType(currentTrackNode.blockPos.up()))); - - blocksToMine.add(new BlockNode(currentTrackNode.blockPos, getBlockType(currentTrackNode.blockPos))); - - } else { - - blocksToMine.add(new BlockNode(currentTrackNode.blockPos, getBlockType(currentTrackNode.blockPos))); - - if (!BlockUtils.isPassable(currentTrackNode.blockPos.up())) - blocksToMine.add(new BlockNode(currentTrackNode.blockPos.up(), getBlockType(currentTrackNode.blockPos.up()))); - - } } formerNode = currentTrackNode; currentTrackNode = currentTrackNode.lastNode; diff --git a/src/main/java/com/jelly/MightyMiner/baritone/automine/pathing/config/PathBehaviour.java b/src/main/java/com/jelly/MightyMiner/baritone/automine/pathing/config/PathBehaviour.java new file mode 100644 index 00000000..4eb5c507 --- /dev/null +++ b/src/main/java/com/jelly/MightyMiner/baritone/automine/pathing/config/PathBehaviour.java @@ -0,0 +1,35 @@ +package com.jelly.MightyMiner.baritone.automine.pathing.config; + +import net.minecraft.block.Block; + +import java.util.List; + +public class PathBehaviour { + List forbiddenMiningBlocks; + List allowedMiningBlocks; + int maxY; + int minY; + + public PathBehaviour(List forbiddenMiningBlocks, List allowedMiningBlocks, int maxY, int minY) { + this.forbiddenMiningBlocks = forbiddenMiningBlocks; + this.allowedMiningBlocks = allowedMiningBlocks; + this.maxY = maxY; + this.minY = minY; + } + + public List getForbiddenMiningBlocks() { + return forbiddenMiningBlocks; + } + + public List getAllowedMiningBlocks() { + return allowedMiningBlocks; + } + + public int getMaxY() { + return maxY; + } + + public int getMinY() { + return minY; + } +} diff --git a/src/main/java/com/jelly/MightyMiner/config/Config.java b/src/main/java/com/jelly/MightyMiner/config/Config.java new file mode 100644 index 00000000..e5fdb5c4 --- /dev/null +++ b/src/main/java/com/jelly/MightyMiner/config/Config.java @@ -0,0 +1,73 @@ +package com.jelly.MightyMiner.config; + +import gg.essential.vigilance.Vigilant; +import gg.essential.vigilance.data.*; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public class Config extends Vigilant { + + @Property( + type = PropertyType.SELECTOR, + name = "Macro", category = "Core", + subcategory = "Macro", + options = { "Gemstone macro"} + ) + public int macroType = 0; + + @Property( + type = PropertyType.SLIDER, + name = "Stuck time threshold (seconds)", + description = "restarts macro when stuck time > threshold", + category = "Gemstone macro", + subcategory = "Miscellaneous", + max = 20, + min = 3 + ) + public int gemRestartTimeThreshold = 8; + + @Property(type = PropertyType.SLIDER, + name = "Max y level", + category = "Gemstone macro", + subcategory = "Miscellaneous", + max = 256 + ) + public int gemMaxY = 256; + + @Property(type = PropertyType.SLIDER, + name = "Min y level", + category = "Gemstone macro", + subcategory = "Miscellaneous", + max = 256 + ) + public int gemMinY = 0; + + @Property(type = PropertyType.SLIDER, + name = "Rotation time (milliseconds)", + description = "Time the macro takes for each rotation", + category = "Gemstone macro", + subcategory = "Miscellaneous", + max = 500, + min = 50 + ) + public int gemRotationTime = 300; + + + + + + public Config() { + super(new File("./config/mightyminer.toml"), "Mighty Miner", new JVMAnnotationPropertyCollector()); + init(); + } + + private void init() { + this.initialize(); + this.markDirty(); + this.preload(); + } + + + +} diff --git a/src/main/java/com/jelly/MightyMiner/handlers/KeybindHandler.java b/src/main/java/com/jelly/MightyMiner/handlers/KeybindHandler.java index 4d7e616f..95e6bb99 100644 --- a/src/main/java/com/jelly/MightyMiner/handlers/KeybindHandler.java +++ b/src/main/java/com/jelly/MightyMiner/handlers/KeybindHandler.java @@ -1,5 +1,7 @@ package com.jelly.MightyMiner.handlers; +import com.jelly.MightyMiner.MightyMiner; +import com.jelly.MightyMiner.config.Config; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -22,37 +24,33 @@ public class KeybindHandler { - static KeyBinding[] macroKeybinds = new KeyBinding[1]; - static KeyBinding[] otherKeybinds = new KeyBinding[2]; + static KeyBinding[] macroKeybinds = new KeyBinding[4]; public static void initializeCustomKeybindings() { - macroKeybinds[0] = new KeyBinding("Gemstone macro", Keyboard.KEY_F, "MightyMiner"); - otherKeybinds[0] = new KeyBinding("Disable script", Keyboard.KEY_Z, "MightyMiner"); - otherKeybinds[1] = new KeyBinding("Debug", Keyboard.KEY_H, "MightyMiner"); + macroKeybinds[0] = new KeyBinding("Start macro", Keyboard.KEY_F, "MightyMiner"); + macroKeybinds[1] = new KeyBinding("Disable macro", Keyboard.KEY_Z, "MightyMiner"); + macroKeybinds[2] = new KeyBinding("Debug", Keyboard.KEY_H, "MightyMiner"); + macroKeybinds[3] = new KeyBinding("Open GUI", Keyboard.KEY_RSHIFT, "MightyMiner"); for (KeyBinding customKeyBind : macroKeybinds) { ClientRegistry.registerKeyBinding(customKeyBind); } - for (KeyBinding customKeyBind : otherKeybinds) { - ClientRegistry.registerKeyBinding(customKeyBind); - } } @SubscribeEvent public void onKeyPress(InputEvent.KeyInputEvent event) { - for(int i = 0; i < macroKeybinds.length; i++){ - if(macroKeybinds[i].isKeyDown()){ - MacroHandler.startScript(i); - } + if(macroKeybinds[0].isKeyDown()){ + MacroHandler.startScript(MightyMiner.config.macroType); } - if(otherKeybinds[0].isKeyDown()){ + if(macroKeybinds[1].isKeyDown()){ MacroHandler.disableScript(); } + if(macroKeybinds[3].isKeyDown()){ + mc.displayGuiScreen(MightyMiner.config.gui()); + } } - - public static void setKeyBindState(int keyCode, boolean pressed) { if (pressed) { if (mc.currentScreen != null) { diff --git a/src/main/java/com/jelly/MightyMiner/macros/macros/GemstoneMacro.java b/src/main/java/com/jelly/MightyMiner/macros/macros/GemstoneMacro.java index fade3b5b..126fcdf5 100644 --- a/src/main/java/com/jelly/MightyMiner/macros/macros/GemstoneMacro.java +++ b/src/main/java/com/jelly/MightyMiner/macros/macros/GemstoneMacro.java @@ -1,15 +1,13 @@ package com.jelly.MightyMiner.macros.macros; +import com.jelly.MightyMiner.MightyMiner; import com.jelly.MightyMiner.baritone.automine.AutoMineBaritone; -import com.jelly.MightyMiner.handlers.MacroHandler; +import com.jelly.MightyMiner.baritone.automine.config.MineBehaviour; +import com.jelly.MightyMiner.baritone.automine.pathing.config.PathBehaviour; import com.jelly.MightyMiner.macros.Macro; -import com.jelly.MightyMiner.utils.BlockUtils; -import com.jelly.MightyMiner.utils.LogUtils; import com.jelly.MightyMiner.utils.PlayerUtils; import net.minecraft.block.Block; import net.minecraft.init.Blocks; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -38,12 +36,14 @@ public class GemstoneMacro extends Macro { } }; - AutoMineBaritone baritone = new AutoMineBaritone(blocksForbiddenToMine, blocksAllowedToMine); + + AutoMineBaritone baritone; boolean minedNearbyGemstones; @Override public void onEnable() { + baritone = new AutoMineBaritone(getPathBehaviour(), getMineBehaviour()); minedNearbyGemstones = false; } @@ -74,6 +74,21 @@ public void onOverlayRenderEvent(RenderGameOverlayEvent event){ baritone.onOverlayRenderEvent(event); } + private PathBehaviour getPathBehaviour(){ + return new PathBehaviour( + blocksForbiddenToMine, + blocksAllowedToMine, + MightyMiner.config.gemMaxY, + MightyMiner.config.gemMinY + ); + } + private MineBehaviour getMineBehaviour(){ + return new MineBehaviour( + false, + MightyMiner.config.gemRotationTime + ); + } + } diff --git a/src/main/java/com/jelly/MightyMiner/mixins/MixinMinecraft.java b/src/main/java/com/jelly/MightyMiner/mixins/MixinMinecraft.java new file mode 100644 index 00000000..32e5f759 --- /dev/null +++ b/src/main/java/com/jelly/MightyMiner/mixins/MixinMinecraft.java @@ -0,0 +1,16 @@ +package com.jelly.MightyMiner.mixins; + +import com.jelly.MightyMiner.MightyMiner; +import net.minecraft.client.Minecraft; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Minecraft.class) +public class MixinMinecraft { + @Inject(method = { "startGame" }, at = { @At(value = "INVOKE", target = "Lnet/minecraft/client/shader/Framebuffer;setFramebufferColor(FFFF)V", shift = At.Shift.AFTER) }) + private void onInit(final CallbackInfo ci) { + MightyMiner.onStartGame(); + } +} diff --git a/src/main/java/com/jelly/MightyMiner/player/Rotation.java b/src/main/java/com/jelly/MightyMiner/player/Rotation.java index 523b7d8e..a12027e0 100644 --- a/src/main/java/com/jelly/MightyMiner/player/Rotation.java +++ b/src/main/java/com/jelly/MightyMiner/player/Rotation.java @@ -28,12 +28,9 @@ public void easeTo(float yaw, float pitch, long time) { getDifference(); } - public void lockAngle(float yaw, float pitch) { - if (mc.thePlayer.rotationYaw != yaw || mc.thePlayer.rotationPitch != pitch && !rotating) - easeTo(yaw, pitch, 1000); - } public void intLockAngle(float yaw, float pitch, int time) { - if (Math.floor(mc.thePlayer.rotationYaw) != Math.floor(yaw) || Math.floor(mc.thePlayer.rotationPitch) != Math.floor(pitch) && !rotating) + if ((AngleUtils.get360RotationYaw((float) Math.floor(mc.thePlayer.rotationYaw)) != AngleUtils.get360RotationYaw((float) Math.floor(yaw)) + ||AngleUtils.get360RotationYaw((float) Math.floor(mc.thePlayer.rotationPitch)) != AngleUtils.get360RotationYaw((float) Math.floor(pitch))) && !rotating) easeTo(yaw, pitch, time); } diff --git a/src/main/java/com/jelly/MightyMiner/utils/BlockUtils.java b/src/main/java/com/jelly/MightyMiner/utils/BlockUtils.java index 223a1324..075ee714 100644 --- a/src/main/java/com/jelly/MightyMiner/utils/BlockUtils.java +++ b/src/main/java/com/jelly/MightyMiner/utils/BlockUtils.java @@ -89,6 +89,7 @@ public static List findBlock(int range, ArrayList forbiddenB List requiredBlocks = Arrays.asList(requiredBlock); List foundBlocks = new ArrayList<>(); + for (int i = 0; i < range; i++) { for (int j = 0; j < range; j++) { for (int k = 0; k < range; k++) { diff --git a/src/main/java/com/jelly/MightyMiner/utils/PlayerUtils.java b/src/main/java/com/jelly/MightyMiner/utils/PlayerUtils.java index 6fed6378..a21b2519 100644 --- a/src/main/java/com/jelly/MightyMiner/utils/PlayerUtils.java +++ b/src/main/java/com/jelly/MightyMiner/utils/PlayerUtils.java @@ -1,12 +1,30 @@ package com.jelly.MightyMiner.utils; import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StringUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public class PlayerUtils { + private static Minecraft mc = Minecraft.getMinecraft(); public static boolean hasStoppedMoving(){ return mc.thePlayer.posX - mc.thePlayer.lastTickPosX == 0 && mc.thePlayer.posY - mc.thePlayer.lastTickPosY == 0 && mc.thePlayer.posZ - mc.thePlayer.lastTickPosZ == 0; } + public static int getItemInHotbar(final String... itemName) { + for (int i = 0; i < 8; ++i) { + final ItemStack is = mc.thePlayer.inventory.getStackInSlot(i); + for(String s : itemName) { + if (is != null && StringUtils.stripControlCodes(is.getDisplayName()).contains(s)) { + return i; + } + } + } + return 0; + } } diff --git a/src/main/resources/mixins.mightyminer.json b/src/main/resources/mixins.mightyminer.json index 48de717a..9144f4e5 100644 --- a/src/main/resources/mixins.mightyminer.json +++ b/src/main/resources/mixins.mightyminer.json @@ -3,5 +3,8 @@ "compatibilityLevel": "JAVA_8", "package": "com.jelly.MightyMiner.mixins", "refmap": "mixins.mightyminer.refmap.json", - "mixins": [] + "mixins": [], + "client": [ + "MixinMinecraft" + ] } \ No newline at end of file