Skip to content

Commit

Permalink
tons of shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelly298 committed Aug 8, 2022
1 parent 457acf7 commit 1962587
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 136 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/jelly/MightyMiner/MightyMiner.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,19 +13,19 @@
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;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.awt.*;
import java.util.LinkedList;
import java.util.List;

public class AutoMineBaritone{

Minecraft mc = Minecraft.getMinecraft();

MineBehaviour mineBehaviour;

LinkedList<BlockNode> blocksToMine = new LinkedList<>();
LinkedList<BlockNode> minedBlocks = new LinkedList<>();
Expand All @@ -32,10 +35,6 @@ public class AutoMineBaritone{

int deltaJumpTick = 0;

List<Block> forbiddenMiningBlocks;
List<Block> allowedMiningBlocks;
boolean shiftWhenMine;

enum PlayerState {
WALKING,
MINING,
Expand All @@ -46,40 +45,20 @@ enum PlayerState {

AStarPathFinder pathFinder;

public AutoMineBaritone(){}

public AutoMineBaritone(List<Block> forbiddenMiningBlocks){
pathFinder = new AStarPathFinder(null, null);
this.forbiddenMiningBlocks = forbiddenMiningBlocks;
}

public AutoMineBaritone(List<Block> forbiddenMiningBlocks, List<Block> allowedMiningBlocks){
this.forbiddenMiningBlocks = forbiddenMiningBlocks;
this.allowedMiningBlocks = allowedMiningBlocks;
pathFinder = new AStarPathFinder(forbiddenMiningBlocks, allowedMiningBlocks);
}

public AutoMineBaritone(List<Block> forbiddenMiningBlocks, List<Block> 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();
minedBlocks.clear();
}





public void enableBaritone(Block... blockType){

enabled = true;
mc.thePlayer.addChatMessage(new ChatComponentText("Starting automine"));

Expand Down Expand Up @@ -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();
Expand All @@ -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)),
Expand All @@ -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){
Expand All @@ -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)
Expand Down Expand Up @@ -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())) {
Expand All @@ -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) {}
};


}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 1962587

Please sign in to comment.