Compare commits

...

68 Commits

Author SHA1 Message Date
Hykilpikonna efa7fec3ae [F] Use json instead of js to store presets 2020-02-21 15:50:48 -05:00
Hykilpikonna a73f2ccbd9 [F] Fix access issue 2020-02-21 15:46:59 -05:00
Hykilpikonna 136f175b12 [+] Create waitfor task 2020-02-21 14:49:56 -05:00
Hykilpikonna 0515a34b63 [+] Create replay task 2020-02-21 14:49:47 -05:00
Hykilpikonna 392ca87a66 [+] Create interaction task 2020-02-21 14:49:37 -05:00
Hykilpikonna c7260580d5 [+] Create delay task 2020-02-21 14:49:27 -05:00
Hykilpikonna f5d49af0a1 [+] Create condition task 2020-02-21 14:49:16 -05:00
Hykilpikonna 5d300244ea [M] Rename package util to utils 2020-02-21 14:41:22 -05:00
Hykilpikonna 2b27d3e03d [+] Create task manager 2020-02-21 14:39:39 -05:00
Hykilpikonna bddc598e88 [+] Create other util methods 2020-02-21 14:39:13 -05:00
Hykilpikonna d3f677d82d [+] Create rotateToBlock() 2020-02-21 14:38:59 -05:00
Hykilpikonna a00255d4b0 [+] Create rotate() 2020-02-21 14:38:33 -05:00
Hykilpikonna b77e7651e7 [+] Create getNeededRotations() 2020-02-21 14:38:15 -05:00
Hykilpikonna 88b8b88474 [+] Create getEyePos() 2020-02-21 14:38:02 -05:00
Hykilpikonna dc010b07a2 [+] Create PlayerUtils 2020-02-21 14:37:46 -05:00
Hykilpikonna bd084ee100 [+] Add lombok dependency 2020-02-21 14:37:19 -05:00
Hykilpikonna 866a704100 [+] Implement mouse mixin 2020-02-21 13:59:44 -05:00
Hykilpikonna 0e228149f6 [+] Create sleep() method 2020-02-21 13:59:22 -05:00
Hykilpikonna ad254f9364 [+] Create duck interface for mouse mixin 2020-02-21 13:59:10 -05:00
Hykilpikonna 94fd115734 [O] Specify username instead of generating random usernames 2020-02-21 13:46:18 -05:00
Hykilpikonna 5d148e56e6 [M] Use proper package names 2020-02-21 13:46:00 -05:00
Hykilpikonna 90a388f04c [O] Reset settings on command stop 2020-02-19 23:08:45 -05:00
Hykilpikonna 2024f31def [F] Fix thread locking 2020-02-19 23:07:42 -05:00
Hykilpikonna ec063cc955 [O] Remove initial delay 2020-02-19 23:07:22 -05:00
Hykilpikonna 12f6f1e846 [O] Actually use the blockToFind var 2020-02-19 23:07:06 -05:00
Hykilpikonna 0f94b958bc [F] Remove air block when pruning 2020-02-19 23:06:45 -05:00
Hykilpikonna 9753b3e3ba [F] Fix mutable pos toString issue 2020-02-19 21:41:33 -05:00
Hykilpikonna c0e4061c45 [O] Send remove block async 2020-02-19 21:28:19 -05:00
Hykilpikonna 386dbf84dd [-] Remove unnecessary debug msg 2020-02-19 21:16:59 -05:00
Hykilpikonna 8df51839d1 [O] Automatically enable mine with seed on command 2020-02-19 21:16:44 -05:00
Hykilpikonna c2671c38b0 [F] Also remove block in map when breaking 2020-02-19 21:16:28 -05:00
Hykilpikonna f553078672 [F] Fix GSON issue on actual client 2020-02-19 21:16:12 -05:00
Hykilpikonna 61aac18212 [F] Replace get block state if mining with seed 2020-02-19 21:15:38 -05:00
Hykilpikonna 78ba6a7aae [O] Only remove block from the server if it is a targeted block 2020-02-19 21:14:25 -05:00
Hykilpikonna 71c0e5c36f [O] Remove block from server on break 2020-02-19 21:12:24 -05:00
Hykilpikonna 4a800dc3ee [O] Prune without removing blocks 2020-02-19 21:10:22 -05:00
Hykilpikonna b38d2c9680 [+] Read seed server cache when scanning 2020-02-19 21:09:47 -05:00
Hykilpikonna 24a3034514 [+] Create block map 2020-02-19 21:08:01 -05:00
Hykilpikonna 90e41977a7 [O] Remove unnecessary outer loop 2020-02-19 21:07:04 -05:00
Hykilpikonna f57899838a [O] Check exited outside the loop 2020-02-19 20:58:01 -05:00
Hykilpikonna 09c8799eb4 [-] Remove loadChunks 2020-02-19 20:55:22 -05:00
Hykilpikonna a776cabb24 [O] Use timeout for updateCache 2020-02-19 20:53:56 -05:00
Hykilpikonna c268e0523f [F] Fix calling onTick when not in game 2020-02-19 20:53:38 -05:00
Hykilpikonna 24a8435c61 [F] Use cacheLocation 2020-02-19 20:53:13 -05:00
Hykilpikonna 0105b5046e [+] Create mine with seed setting 2020-02-19 18:06:19 -05:00
Hykilpikonna ea75b6f0b9 [O] Optimize user response 2020-02-19 18:05:48 -05:00
Hykilpikonna 73b4b09b67 [F] Fix chunk preloading 2020-02-19 18:05:18 -05:00
Hykilpikonna 3973a2eb4e [F] Fix concurrent modification error 2020-02-19 18:05:06 -05:00
Hykilpikonna 5a0f23c150 [+] Add Hyritone message prefix 2020-02-19 18:00:20 -05:00
Hykilpikonna b51760360a [+] Create hyritone field in baritone 2020-02-19 17:39:38 -05:00
Hykilpikonna d4a4de62ba [+] Create hyritone class 2020-02-19 17:39:26 -05:00
Hykilpikonna da0c0fd0d0 [+] Register command 2020-02-19 17:39:05 -05:00
Hykilpikonna 886a60ae61 [O] Optimize render lag 2020-02-19 17:38:44 -05:00
Hykilpikonna fef0182991 [+] Create seed xray command 2020-02-19 17:38:18 -05:00
Hykilpikonna 0309de04ef [+] Create utility to print message 2020-02-19 17:36:38 -05:00
Hykilpikonna 2afd0ddc03 [+] Create class to cache seed server responses 2020-02-19 17:36:15 -05:00
Hykilpikonna eddbb9eba2 [+] Add block destroy listener 2020-02-19 17:35:40 -05:00
Hykilpikonna 05a5d89376 Revert "[+] #2: Add settings for search distances"
This reverts commit 12fa664052.
2020-02-17 11:13:00 -05:00
Hykilpikonna 953414933b Revert "[+] #2 Use search distances for mining"
This reverts commit 5256f2a6a4.
2020-02-17 11:12:38 -05:00
Hykilpikonna 5256f2a6a4 [+] #2 Use search distances for mining 2020-02-17 11:04:22 -05:00
Hykilpikonna 12fa664052 [+] #2: Add settings for search distances 2020-02-17 11:02:39 -05:00
Hykilpikonna d63f8d9f83 [P] Patch #1: Remove allowBreak check for mining 2020-02-17 10:29:22 -05:00
Leijurv 606e9bf97c v1.5.1 2020-02-14 15:28:37 -08:00
Leijurv 47ae75a9d6 Merge branch '1.14.4' into 1.15.2 2020-02-14 15:26:34 -08:00
Leijurv 25587e317a fix link click crash 2020-02-14 15:26:03 -08:00
Leijurv b3ba129fc5 honey is stupid lets just not 2020-02-13 18:59:08 -08:00
Leijurv 746b7b5c88 not unscuffed, just differently scuffed 2020-02-13 18:57:32 -08:00
Brady db2f6ec78d Update mappings to 20200213-1.15.1 2020-02-13 14:44:29 -06:00
38 changed files with 1356 additions and 79 deletions
+5 -2
View File
@@ -16,7 +16,7 @@
*/ */
group 'baritone' group 'baritone'
version '1.5.0' version '1.5.1'
buildscript { buildscript {
repositories { repositories {
@@ -82,7 +82,7 @@ task sourceJar(type: Jar, dependsOn: classes) {
} }
minecraft { minecraft {
mappings channel: 'snapshot', version: '20200205-1.15.1' mappings channel: 'snapshot', version: '20200213-1.15.1'
reobfMappings 'notch' reobfMappings 'notch'
runs { runs {
@@ -155,6 +155,9 @@ dependencies {
} }
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
} }
mixin { mixin {
+7
View File
@@ -830,6 +830,13 @@ public final class Settings {
*/ */
public final Setting<Boolean> mineScanDroppedItems = new Setting<>(true); public final Setting<Boolean> mineScanDroppedItems = new Setting<>(true);
// Hyritone start
/**
* Detect ore locations with a separate world seed.
*/
public final Setting<Boolean> mineWithSeed = new Setting<>(false);
// Hyritone end
/** /**
* While mining, wait this number of milliseconds after mining an ore to see if it will drop an item * While mining, wait this number of milliseconds after mining an ore to see if it will drop an item
* instead of immediately going onto the next one * instead of immediately going onto the next one
@@ -18,6 +18,7 @@
package baritone.api.event.events; package baritone.api.event.events;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.Matrix4f;
/** /**
* @author Brady * @author Brady
@@ -30,12 +31,13 @@ public final class RenderEvent {
*/ */
private final float partialTicks; private final float partialTicks;
private final MatrixStack modelViewStack, projectionStack; private final Matrix4f projectionMatrix;
private final MatrixStack modelViewStack;
public RenderEvent(float partialTicks, MatrixStack modelViewStack, MatrixStack projectionStack) { public RenderEvent(float partialTicks, MatrixStack modelViewStack, Matrix4f projectionMatrix) {
this.partialTicks = partialTicks; this.partialTicks = partialTicks;
this.modelViewStack = modelViewStack; this.modelViewStack = modelViewStack;
this.projectionStack = projectionStack; this.projectionMatrix = projectionMatrix;
} }
/** /**
@@ -45,11 +47,11 @@ public final class RenderEvent {
return this.partialTicks; return this.partialTicks;
} }
public final MatrixStack getModelViewStack() { public MatrixStack getModelViewStack() {
return this.modelViewStack; return this.modelViewStack;
} }
public final MatrixStack getProjectionStack() { public Matrix4f getProjectionMatrix() {
return this.projectionStack; return this.projectionMatrix;
} }
} }
@@ -18,6 +18,7 @@
package baritone.api.event.listener; package baritone.api.event.listener;
import baritone.api.event.events.*; import baritone.api.event.events.*;
import net.minecraft.util.math.BlockPos;
/** /**
* An implementation of {@link IGameEventListener} that has all methods * An implementation of {@link IGameEventListener} that has all methods
@@ -71,4 +72,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
@Override @Override
default void onPathEvent(PathEvent event) {} default void onPathEvent(PathEvent event) {}
@Override
default void onBlockBreak(BlockPos pos) {}
} }
@@ -20,10 +20,10 @@ package baritone.api.event.listener;
import baritone.api.event.events.*; import baritone.api.event.events.*;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.DeathScreen;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
/** /**
* @author Brady * @author Brady
@@ -137,4 +137,11 @@ public interface IGameEventListener {
* @param event The event * @param event The event
*/ */
void onPathEvent(PathEvent event); void onPathEvent(PathEvent event);
/**
* This is called when the player breaks blocks.
*
* @param pos Block position
*/
void onBlockBreak(BlockPos pos);
} }
@@ -57,6 +57,9 @@ public class LaunchTesting {
attemptLogin(arguments, System.getenv("username"), System.getenv("password")); attemptLogin(arguments, System.getenv("username"), System.getenv("password"));
} }
// TODO: Remove
arguments.put("username", "TestUser");
List<String> argsArray = new ArrayList<>(); List<String> argsArray = new ArrayList<>();
arguments.forEach((k, v) -> { arguments.forEach((k, v) -> {
argsArray.add("--" + k); argsArray.add("--" + k);
@@ -0,0 +1,99 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.launch.mixins;
import baritone.utils.accessor.IMouse;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHelper;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static org.hydev.hyritone.utils.MiscUtils.sleep;
/**
* Mixin to control mouse operations
* <p>
* Class created by the HyDEV Team on 2020-02-21!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-02-21 13:54
*/
@Mixin(MouseHelper.class)
public abstract class MixinMouse implements IMouse
{
@Shadow
protected abstract void mouseButtonCallback(long window, int button, int action, int mods);
@Shadow @Final private Minecraft minecraft;
@Inject(method = "mouseButtonCallback", at = @At("HEAD"), cancellable = true)
private void inject(long window, int button, int action, int mods, CallbackInfo info)
{
System.out.println(window + " | " + button + " | " + action + " | " + mods + " | " + System.currentTimeMillis());
}
public void rightClick()
{
new Thread(() ->
{
rightHold();
sleep((long) (70 + Math.random() * 10));
rightRelease();
}).start();
}
public void leftClick()
{
new Thread(() ->
{
leftHold();
sleep((long) (70 + Math.random() * 10));
leftRelease();
}).start();
}
@Override
public void rightHold()
{
mouseButtonCallback(minecraft.getMainWindow().getHandle(), 1, 1, 0);
}
@Override
public void rightRelease()
{
mouseButtonCallback(minecraft.getMainWindow().getHandle(), 1, 0, 0);
}
@Override
public void leftHold()
{
mouseButtonCallback(minecraft.getMainWindow().getHandle(), 0, 1, 0);
}
@Override
public void leftRelease()
{
mouseButtonCallback(minecraft.getMainWindow().getHandle(), 0, 0, 0);
}
}
@@ -17,16 +17,28 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.utils.accessor.IPlayerControllerMP; import baritone.utils.accessor.IPlayerControllerMP;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerController; import net.minecraft.client.multiplayer.PlayerController;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(PlayerController.class) @Mixin(PlayerController.class)
public abstract class MixinPlayerController implements IPlayerControllerMP { public abstract class MixinPlayerController implements IPlayerControllerMP {
@Shadow
@Final
private Minecraft mc;
@Accessor @Accessor
@Override @Override
public abstract void setIsHittingBlock(boolean isHittingBlock); public abstract void setIsHittingBlock(boolean isHittingBlock);
@@ -38,4 +50,20 @@ public abstract class MixinPlayerController implements IPlayerControllerMP {
@Invoker @Invoker
@Override @Override
public abstract void callSyncCurrentPlayItem(); public abstract void callSyncCurrentPlayItem();
@Inject(
method = "onPlayerDestroyBlock",
at = @At(value = "TAIL")
)
public void onPlayerDestroyBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir)
{
// Check if the block is broken
if (!cir.getReturnValue()) return;
// Call event
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(this.mc.player);
if (baritone != null) {
baritone.getGameEventHandler().onBlockBreak(pos);
}
}
} }
@@ -29,5 +29,5 @@ public abstract class MixinScreen implements IGuiScreen {
@Override @Override
@Invoker("openLink") @Invoker("openLink")
public abstract void openLink(URI url); public abstract void openLinkInvoker(URI url);
} }
@@ -21,30 +21,28 @@ import baritone.api.BaritoneAPI;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.event.events.RenderEvent; import baritone.api.event.events.RenderEvent;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.Matrix4f;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(GameRenderer.class) /**
public class MixinGameRenderer { * @author Brady
* @since 2/13/2020
*/
@Mixin(WorldRenderer.class)
public class MixinWorldRenderer {
@Inject( @Inject(
method = "renderWorld", method = "updateCameraAndRender",
at = @At( at = @At("RETURN"),
value = "INVOKE_STRING", locals = LocalCapture.CAPTURE_FAILSOFT
target = "Lnet/minecraft/profiler/IProfiler;endStartSection(Ljava/lang/String;)V",
args = {"ldc=hand"}
),
locals = LocalCapture.CAPTURE_FAILHARD
) )
private void renderWorldPass(float partialTicks, long finishTimeNano, MatrixStack modelViewMatrix, CallbackInfo ci, boolean flag, ActiveRenderInfo activerenderinfo, MatrixStack projectionMatrix, float f, Matrix4f matrix4f) { private void onStartHand(MatrixStack matrixStackIn, float partialTicks, long finishTimeNano, boolean drawBlockOutline, ActiveRenderInfo activeRenderInfoIn, GameRenderer gameRendererIn, LightTexture lightmapIn, Matrix4f projectionIn, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks, modelViewMatrix, projectionMatrix)); ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks, matrixStackIn, projectionIn));
} }
} }
} }
+3 -3
View File
@@ -9,14 +9,13 @@
}, },
"client": [ "client": [
"MixinBitArray", "MixinBitArray",
"MixinCommandSuggestionHelper",
"MixinChunkArray", "MixinChunkArray",
"MixinClientChunkProvider", "MixinClientChunkProvider",
"MixinClientPlayerEntity", "MixinClientPlayerEntity",
"MixinClientPlayNetHandler", "MixinClientPlayNetHandler",
"MixinCommandSuggestionHelper",
"MixinEntity", "MixinEntity",
"MixinEntityRenderManager", "MixinEntityRenderManager",
"MixinGameRenderer",
"MixinItemStack", "MixinItemStack",
"MixinLivingEntity", "MixinLivingEntity",
"MixinLootContext", "MixinLootContext",
@@ -24,6 +23,7 @@
"MixinNetworkManager", "MixinNetworkManager",
"MixinPalettedContainer", "MixinPalettedContainer",
"MixinPlayerController", "MixinPlayerController",
"MixinScreen" "MixinScreen",
"MixinWorldRenderer"
] ]
} }
+6
View File
@@ -32,6 +32,7 @@ import baritone.utils.*;
import baritone.command.manager.CommandManager; import baritone.command.manager.CommandManager;
import baritone.utils.player.PrimaryPlayerContext; import baritone.utils.player.PrimaryPlayerContext;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import org.hydev.hyritone.Hyritone;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -87,6 +88,8 @@ public class Baritone implements IBaritone {
public BlockStateInterface bsi; public BlockStateInterface bsi;
public Hyritone hyritone;
Baritone() { Baritone() {
this.gameEventHandler = new GameEventHandler(this); this.gameEventHandler = new GameEventHandler(this);
@@ -121,6 +124,9 @@ public class Baritone implements IBaritone {
if (BaritoneAutoTest.ENABLE_AUTO_TEST) { if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE); this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE);
} }
// Hyritone
this.hyritone = new Hyritone(this);
} }
@Override @Override
@@ -100,7 +100,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
return false; return false;
} else if (msg.trim().equalsIgnoreCase("orderpizza")) { } else if (msg.trim().equalsIgnoreCase("orderpizza")) {
try { try {
((IGuiScreen) mc.currentScreen).openLink(new URI("https://www.dominos.com/en/pages/order/")); ((IGuiScreen) mc.currentScreen).openLinkInvoker(new URI("https://www.dominos.com/en/pages/order/"));
} catch (NullPointerException | URISyntaxException ignored) {} } catch (NullPointerException | URISyntaxException ignored) {}
return false; return false;
} }
@@ -19,6 +19,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.ICommand; import baritone.api.command.ICommand;
import org.hydev.hyritone.seedxray.SeedXrayCommand;
import java.util.*; import java.util.*;
@@ -64,7 +65,10 @@ public final class DefaultCommands {
new WaypointsCommand(baritone), new WaypointsCommand(baritone),
new CommandAlias(baritone, "sethome", "Sets your home waypoint", "waypoints save home"), new CommandAlias(baritone, "sethome", "Sets your home waypoint", "waypoints save home"),
new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"), new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"),
new SelCommand(baritone) new SelCommand(baritone),
// Hyritone
new SeedXrayCommand(baritone)
)); ));
ExecutionControlCommands prc = new ExecutionControlCommands(baritone); ExecutionControlCommands prc = new ExecutionControlCommands(baritone);
commands.add(prc.pauseCommand); commands.add(prc.pauseCommand);
@@ -25,6 +25,7 @@ import baritone.api.event.listener.IGameEventListener;
import baritone.api.utils.Helper; import baritone.api.utils.Helper;
import baritone.cache.WorldProvider; import baritone.cache.WorldProvider;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
@@ -161,4 +162,9 @@ public final class GameEventHandler implements IEventBus, Helper {
public final void registerEventListener(IGameEventListener listener) { public final void registerEventListener(IGameEventListener listener) {
this.listeners.add(listener); this.listeners.add(listener);
} }
public final void onBlockBreak(BlockPos blockPos)
{
listeners.forEach(l -> l.onBlockBreak(blockPos));
}
} }
@@ -295,7 +295,7 @@ public interface MovementHelper extends ActionCosts, Helper {
*/ */
static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, BlockState state) { static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, BlockState state) {
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof AirBlock || block == Blocks.MAGMA_BLOCK || block == Blocks.BUBBLE_COLUMN) { if (block instanceof AirBlock || block == Blocks.MAGMA_BLOCK || block == Blocks.BUBBLE_COLUMN || block == Blocks.HONEY_BLOCK) {
// early return for most common case (air) // early return for most common case (air)
// plus magma, which is a normal cube but it hurts you // plus magma, which is a normal cube but it hurts you
return false; return false;
+57 -35
View File
@@ -36,11 +36,13 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.hydev.hyritone.Hyritone;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static baritone.Baritone.settings;
import static baritone.api.pathing.movement.ActionCosts.COST_INF; import static baritone.api.pathing.movement.ActionCosts.COST_INF;
import static java.util.stream.Collectors.toList;
/** /**
* Mine blocks of a certain type * Mine blocks of a certain type
@@ -83,7 +85,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
} }
if (calcFailed) { if (calcFailed) {
if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) { if (!knownOreLocations.isEmpty() && settings().blacklistClosestOnFailure.value) {
logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance..."); logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...");
knownOreLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(blacklist::add); knownOreLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(blacklist::add);
knownOreLocations.removeIf(blacklist::contains); knownOreLocations.removeIf(blacklist::contains);
@@ -93,19 +95,19 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return null; return null;
} }
} }
if (!Baritone.settings().allowBreak.value) { if (!settings().allowBreak.value) {
logDirect("Unable to mine when allowBreak is false!"); logDirect("Unable to mine when allowBreak is false!");
cancel(); cancel();
return null; return null;
} }
updateLoucaSystem(); updateLoucaSystem();
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; int mineGoalUpdateInterval = settings().mineGoalUpdateInterval.value;
List<BlockPos> curr = new ArrayList<>(knownOreLocations); List<BlockPos> curr = new ArrayList<>(knownOreLocations);
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
CalculationContext context = new CalculationContext(baritone, true); CalculationContext context = new CalculationContext(baritone, true);
Baritone.getExecutor().execute(() -> rescan(curr, context)); Baritone.getExecutor().execute(() -> rescan(curr, context));
} }
if (Baritone.settings().legitMine.value) { if (settings().legitMine.value) {
addNearby(); addNearby();
} }
Optional<BlockPos> shaft = curr.stream() Optional<BlockPos> shaft = curr.stream()
@@ -144,7 +146,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
Map<BlockPos, Long> copy = new HashMap<>(anticipatedDrops); Map<BlockPos, Long> copy = new HashMap<>(anticipatedDrops);
ctx.getSelectedBlock().ifPresent(pos -> { ctx.getSelectedBlock().ifPresent(pos -> {
if (knownOreLocations.contains(pos)) { if (knownOreLocations.contains(pos)) {
copy.put(pos, System.currentTimeMillis() + Baritone.settings().mineDropLoiterDurationMSThanksLouca.value); copy.put(pos, System.currentTimeMillis() + settings().mineDropLoiterDurationMSThanksLouca.value);
} }
}); });
// elaborate dance to avoid concurrentmodificationexcepption since rescan thread reads this // elaborate dance to avoid concurrentmodificationexcepption since rescan thread reads this
@@ -168,7 +170,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
private PathingCommand updateGoal() { private PathingCommand updateGoal() {
boolean legit = Baritone.settings().legitMine.value; boolean legit = settings().legitMine.value;
List<BlockPos> locs = knownOreLocations; List<BlockPos> locs = knownOreLocations;
if (!locs.isEmpty()) { if (!locs.isEmpty()) {
CalculationContext context = new CalculationContext(baritone); CalculationContext context = new CalculationContext(baritone);
@@ -183,7 +185,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return null; return null;
} }
// only in non-Xray mode (aka legit mode) do we do this // only in non-Xray mode (aka legit mode) do we do this
int y = Baritone.settings().legitMineYLevel.value; int y = settings().legitMineYLevel.value;
if (branchPoint == null) { if (branchPoint == null) {
/*if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) { /*if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) {
// cool, path is over and we are at desired y // cool, path is over and we are at desired y
@@ -211,7 +213,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
if (filter == null) { if (filter == null) {
return; return;
} }
if (Baritone.settings().legitMine.value) { if (settings().legitMine.value) {
return; return;
} }
List<BlockPos> dropped = droppedItemsScan(); List<BlockPos> dropped = droppedItemsScan();
@@ -231,7 +233,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return true; return true;
} }
BlockState state = context.bsi.get0(pos); BlockState state = context.bsi.get0(pos);
if (Baritone.settings().internalMiningAirException.value && state.getBlock() instanceof AirBlock) { if (settings().internalMiningAirException.value && state.getBlock() instanceof AirBlock) {
return true; return true;
} }
return filter.has(state) && plausibleToBreak(context, pos); return filter.has(state) && plausibleToBreak(context, pos);
@@ -239,7 +241,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
private Goal coalesce(BlockPos loc, List<BlockPos> locs, CalculationContext context) { private Goal coalesce(BlockPos loc, List<BlockPos> locs, CalculationContext context) {
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof FallingBlock); boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof FallingBlock);
if (!Baritone.settings().forceInternalMining.value) { if (!settings().forceInternalMining.value) {
if (assumeVerticalShaftMine) { if (assumeVerticalShaftMine) {
// we can get directly below the block // we can get directly below the block
return new GoalThreeBlocks(loc); return new GoalThreeBlocks(loc);
@@ -300,7 +302,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
public List<BlockPos> droppedItemsScan() { public List<BlockPos> droppedItemsScan() {
if (!Baritone.settings().mineScanDroppedItems.value) { if (!settings().mineScanDroppedItems.value) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<BlockPos> ret = new ArrayList<>(); List<BlockPos> ret = new ArrayList<>();
@@ -319,39 +321,52 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
public static List<BlockPos> searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist, List<BlockPos> dropped) { public static List<BlockPos> searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist, List<BlockPos> dropped) {
List<BlockPos> locs = new ArrayList<>(); List<BlockPos> locs = new ArrayList<>();
List<Block> untracked = new ArrayList<>(); List<Block> untracked = new ArrayList<>();
for (BlockOptionalMeta bom : filter.blocks()) {
Block block = bom.getBlock();
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
BetterBlockPos pf = ctx.baritone.getPlayerContext().playerFeet();
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that // Check mine with seed
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf( if (!settings().mineWithSeed.value)
{
// Search the actual world
for (BlockOptionalMeta bom : filter.blocks()) {
Block block = bom.getBlock();
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
BetterBlockPos pf = ctx.baritone.getPlayerContext().playerFeet();
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(
BlockUtils.blockToString(block), BlockUtils.blockToString(block),
Baritone.settings().maxCachedWorldScanCount.value, settings().maxCachedWorldScanCount.value,
pf.x, pf.x,
pf.z, pf.z,
2 2
)); ));
} else { } else {
untracked.add(block); untracked.add(block);
}
} }
}
locs = prune(ctx, locs, filter, max, blacklist, dropped); locs = prune(ctx, locs, filter, max, blacklist, dropped);
if (!untracked.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) { if (!untracked.isEmpty() || (settings().extendCacheOnThreshold.value && locs.size() < max)) {
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius( locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(
ctx.getBaritone().getPlayerContext(), ctx.getBaritone().getPlayerContext(),
filter, filter,
max, max,
10, 10,
32 32
)); // maxSearchRadius is NOT sq )); // maxSearchRadius is NOT sq
}
locs.addAll(alreadyKnown);
locs = prune(ctx, locs, filter, max, blacklist, dropped);
}
else
{
// Add seed ores
locs.addAll(Hyritone.seedServerCache.cacheBlocks);
locs = prune(ctx, locs, filter, max, blacklist, dropped);
} }
locs.addAll(alreadyKnown); return locs;
return prune(ctx, locs, filter, max, blacklist, dropped);
} }
private void addNearby() { private void addNearby() {
@@ -368,7 +383,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
// is an x-ray and it'll get caught // is an x-ray and it'll get caught
if (filter.has(bsi.get0(x, y, z))) { if (filter.has(bsi.get0(x, y, z))) {
BlockPos pos = new BlockPos(x, y, z); BlockPos pos = new BlockPos(x, y, z);
if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) { if ((settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) {
knownOreLocations.add(pos); knownOreLocations.add(pos);
} }
} }
@@ -392,7 +407,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
.distinct() .distinct()
// remove any that are within loaded chunks that aren't actually what we want // remove any that are within loaded chunks that aren't actually what we want
.filter(pos -> !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || filter.has(ctx.get(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) .filter(pos -> settings().mineWithSeed.value || !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || filter.has(ctx.get(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos))
// Hyritone: remove air
.filter(pos -> !settings().mineWithSeed.value || !ctx.get(pos).isAir() || dropped.contains(pos))
// remove any that are implausible to mine (encased in bedrock, or touching lava) // remove any that are implausible to mine (encased in bedrock, or touching lava)
.filter(pos -> MineProcess.plausibleToBreak(ctx, pos)) .filter(pos -> MineProcess.plausibleToBreak(ctx, pos))
@@ -400,7 +418,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
.filter(pos -> !blacklist.contains(pos)) .filter(pos -> !blacklist.contains(pos))
.sorted(Comparator.comparingDouble(new BlockPos(ctx.getBaritone().getPlayerContext().player())::distanceSq)) .sorted(Comparator.comparingDouble(new BlockPos(ctx.getBaritone().getPlayerContext().player())::distanceSq))
.collect(Collectors.toList()); .collect(toList());
if (locs.size() > max) { if (locs.size() > max) {
return locs.subList(0, max); return locs.subList(0, max);
@@ -425,11 +443,15 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
@Override @Override
public void mine(int quantity, BlockOptionalMetaLookup filter) { public void mine(int quantity, BlockOptionalMetaLookup filter) {
this.filter = filter; this.filter = filter;
if (filter != null && !Baritone.settings().allowBreak.value) {
// Hyritone start - #1: Users are not idiots, if they disabled allow break, it's not for mining.
/*if (filter != null && !Baritone.settings().allowBreak.value) {
logDirect("Unable to mine when allowBreak is false!"); logDirect("Unable to mine when allowBreak is false!");
this.mine(quantity, (BlockOptionalMetaLookup) null); this.mine(quantity, (BlockOptionalMetaLookup) null);
return; return;
} }*/
// Hyritone end
this.desiredQuantity = quantity; this.desiredQuantity = quantity;
this.knownOreLocations = new ArrayList<>(); this.knownOreLocations = new ArrayList<>();
this.blacklist = new ArrayList<>(); this.blacklist = new ArrayList<>();
@@ -33,6 +33,9 @@ import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection; import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.ChunkStatus; import net.minecraft.world.chunk.ChunkStatus;
import org.hydev.hyritone.Hyritone;
import static org.hydev.hyritone.utils.MiscUtils.posId;
/** /**
* Wraps get for chuck caching capability * Wraps get for chuck caching capability
@@ -98,6 +101,16 @@ public class BlockStateInterface {
public BlockState get0(int x, int y, int z) { // Mickey resigned public BlockState get0(int x, int y, int z) { // Mickey resigned
// Hyritone: Replace the block with seed block
if (Baritone.settings().mineWithSeed.value)
{
String key = posId(new BlockPos(x, y, z));
if (Hyritone.seedServerCache.blocksMap.containsKey(key))
{
return Hyritone.seedServerCache.blocksMap.get(key);
}
}
// Invalid vertical position // Invalid vertical position
if (y < 0 || y >= 256) { if (y < 0 || y >= 256) {
return AIR; return AIR;
+5 -5
View File
@@ -110,9 +110,9 @@ public class GuiClick extends Screen implements Helper {
return super.mouseClicked(mouseX, mouseY, mouseButton); return super.mouseClicked(mouseX, mouseY, mouseButton);
} }
public void onRender(MatrixStack modelViewStack, MatrixStack projectionStack) { public void onRender(MatrixStack modelViewStack, Matrix4f projectionMatrix) {
this.projectionViewMatrix = projectionStack.getLast().getPositionMatrix().copy(); this.projectionViewMatrix = projectionMatrix.copy();
this.projectionViewMatrix.multiply(modelViewStack.getLast().getPositionMatrix()); this.projectionViewMatrix.mul(modelViewStack.getLast().getMatrix());
this.projectionViewMatrix.invert(); this.projectionViewMatrix.invert();
if (currentMouseOver != null) { if (currentMouseOver != null) {
@@ -144,8 +144,8 @@ public class GuiClick extends Screen implements Helper {
return null; return null;
} }
x /= mc.getMainWindow().getWidth(); x /= mc.getMainWindow().getFramebufferWidth();
y /= mc.getMainWindow().getHeight(); y /= mc.getMainWindow().getFramebufferHeight();
x = x * 2 - 1; x = x * 2 - 1;
y = y * 2 - 1; y = y * 2 - 1;
+1 -1
View File
@@ -77,7 +77,7 @@ public interface IRenderer {
static void drawAABB(MatrixStack stack, AxisAlignedBB aabb) { static void drawAABB(MatrixStack stack, AxisAlignedBB aabb) {
AxisAlignedBB toDraw = aabb.offset(-renderManager.renderPosX(), -renderManager.renderPosY(), -renderManager.renderPosZ()); AxisAlignedBB toDraw = aabb.offset(-renderManager.renderPosX(), -renderManager.renderPosY(), -renderManager.renderPosZ());
Matrix4f matrix4f = stack.getLast().getPositionMatrix(); Matrix4f matrix4f = stack.getLast().getMatrix();
buffer.begin(GL_LINES, DefaultVertexFormats.POSITION); buffer.begin(GL_LINES, DefaultVertexFormats.POSITION);
// bottom // bottom
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).endVertex(); buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).endVertex();
@@ -36,7 +36,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.util.math.shapes.VoxelShapes;
@@ -74,7 +73,7 @@ public final class PathRenderer implements IRenderer, Helper {
float partialTicks = event.getPartialTicks(); float partialTicks = event.getPartialTicks();
Goal goal = behavior.getGoal(); Goal goal = behavior.getGoal();
if (Helper.mc.currentScreen instanceof GuiClick) { if (Helper.mc.currentScreen instanceof GuiClick) {
((GuiClick) Helper.mc.currentScreen).onRender(event.getModelViewStack(), event.getProjectionStack()); ((GuiClick) Helper.mc.currentScreen).onRender(event.getModelViewStack(), event.getProjectionMatrix());
} }
int thisPlayerDimension = behavior.baritone.getPlayerContext().world().getDimension().getType().getId(); int thisPlayerDimension = behavior.baritone.getPlayerContext().world().getDimension().getType().getId();
@@ -181,7 +180,7 @@ public final class PathRenderer implements IRenderer, Helper {
public static void drawLine(MatrixStack stack, double x1, double y1, double z1, double x2, double y2, double z2) { public static void drawLine(MatrixStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
Matrix4f matrix4f = stack.getLast().getPositionMatrix(); Matrix4f matrix4f = stack.getLast().getMatrix();
double vpX = posX(); double vpX = posX();
double vpY = posY(); double vpY = posY();
@@ -224,7 +223,7 @@ public final class PathRenderer implements IRenderer, Helper {
double minZ, maxZ; double minZ, maxZ;
double minY, maxY; double minY, maxY;
double y1, y2; double y1, y2;
double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); double y = 1;
if (goal instanceof IGoalRenderPos) { if (goal instanceof IGoalRenderPos) {
BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos(); BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos();
minX = goalPos.getX() + 0.002 - renderPosX; minX = goalPos.getX() + 0.002 - renderPosX;
@@ -319,7 +318,7 @@ public final class PathRenderer implements IRenderer, Helper {
renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y1); renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y1);
renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y2); renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y2);
Matrix4f matrix4f = stack.getLast().getPositionMatrix(); Matrix4f matrix4f = stack.getLast().getMatrix();
buffer.begin(GL_LINES, DefaultVertexFormats.POSITION); buffer.begin(GL_LINES, DefaultVertexFormats.POSITION);
buffer.pos(matrix4f, (float) minX, (float) minY, (float) minZ).endVertex(); buffer.pos(matrix4f, (float) minX, (float) minY, (float) minZ).endVertex();
buffer.pos(matrix4f, (float) minX, (float) maxY, (float) minZ).endVertex(); buffer.pos(matrix4f, (float) minX, (float) maxY, (float) minZ).endVertex();
@@ -336,7 +335,7 @@ public final class PathRenderer implements IRenderer, Helper {
private static void renderHorizontalQuad(MatrixStack stack, double minX, double maxX, double minZ, double maxZ, double y) { private static void renderHorizontalQuad(MatrixStack stack, double minX, double maxX, double minZ, double maxZ, double y) {
if (y != 0) { if (y != 0) {
Matrix4f matrix4f = stack.getLast().getPositionMatrix(); Matrix4f matrix4f = stack.getLast().getMatrix();
buffer.begin(GL_LINE_LOOP, DefaultVertexFormats.POSITION); buffer.begin(GL_LINE_LOOP, DefaultVertexFormats.POSITION);
buffer.pos(matrix4f, (float) minX, (float) y, (float) minZ).endVertex(); buffer.pos(matrix4f, (float) minX, (float) y, (float) minZ).endVertex();
buffer.pos(matrix4f, (float) maxX, (float) y, (float) minZ).endVertex(); buffer.pos(matrix4f, (float) maxX, (float) y, (float) minZ).endVertex();
@@ -21,5 +21,5 @@ import java.net.URI;
public interface IGuiScreen { public interface IGuiScreen {
void openLink(URI url); void openLinkInvoker(URI url);
} }
@@ -0,0 +1,39 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.accessor;
/**
* Duck interface for the mixin that controls mouse operations.
* <p>
* Class created by the HyDEV Team on 2020-02-21!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-02-21 13:53
*/
public interface IMouse
{
void rightClick();
void rightHold();
void rightRelease();
void leftClick();
void leftHold();
void leftRelease();
}
@@ -0,0 +1,41 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package org.hydev.hyritone;
import baritone.Baritone;
import org.hydev.hyritone.seedxray.SeedServerCache;
/**
* TODO: Write a description for this class!
* <p>
* Class created by the HyDEV Team on 2020-02-19!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-02-19 13:42
*/
public class Hyritone
{
public static SeedServerCache seedServerCache;
public Hyritone(Baritone baritone)
{
seedServerCache = new SeedServerCache(baritone);
}
}
@@ -0,0 +1,195 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package org.hydev.hyritone.seedxray;
import baritone.Baritone;
import baritone.api.event.events.RenderEvent;
import baritone.api.event.events.TickEvent;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Helper;
import baritone.behavior.Behavior;
import baritone.utils.PathRenderer;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static baritone.api.utils.Helper.mc;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.toList;
import static org.hydev.hyritone.utils.MiscUtils.debug;
import static org.hydev.hyritone.utils.MiscUtils.posId;
/**
* TODO: Write a description for this class!
* <p>
* Class created by the HyDEV Team on 2020-02-19!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-02-19 12:35
*/
public class SeedServerCache extends Behavior
{
public static CloseableHttpClient http = HttpClients.createDefault();
public BetterBlockPos cacheLocation;
public List<BlockPos> cacheBlocks = new ArrayList<>();
public Map<String, BlockState> blocksMap = new HashMap<>();
public boolean enabled = false;
public String blockToFind = "diamond_ore";
public boolean updating = false;
public int ticks = 100;
public SeedServerCache(Baritone baritone)
{
super(baritone);
}
/**
* Check for updates every tick
*
* @param event Tick event
*/
@Override
public void onTick(TickEvent event)
{
if (mc.player == null) return;
if (updating || !enabled) return;
// Update cache every 5 seconds (5 * 20 = 100 ticks)
ticks ++;
if (ticks > 100)
{
ticks = 0;
new Thread(this::updateCache).start();
}
}
/**
* Update cached blocks
*/
public void updateCache()
{
// Prevent duplicate calls to update
updating = true;
cacheLocation = new BetterBlockPos(mc.player.getPositionVec().x, mc.player.getPositionVec().y + 0.1251, mc.player.getPositionVec().z);
// Get request
HttpGet get = new HttpGet("http://localhost:12255/api/get-locations-of");
get.setHeader("world", "world");
get.setHeader("block", blockToFind);
get.setHeader("maximum", "64");
get.setHeader("center-x", "" + cacheLocation.getX());
get.setHeader("center-y", "" + cacheLocation.getY());
get.setHeader("center-z", "" + cacheLocation.getZ());
get.setHeader("max-search-rad", "64");
get.setHeader("y-min", "3");
get.setHeader("y-max", "16");
debug("==============================================");
debug("Getting block data from seed exploit server...");
try (CloseableHttpResponse response = http.execute(get))
{
// Exited
if (mc.world == null) return;
ArrayList<BlockPos> blocks = new ArrayList<>();
JsonArray array = new JsonParser().parse(IOUtils.toString(response.getEntity().getContent(), UTF_8)).getAsJsonArray();
array.forEach(j ->
{
JsonObject obj = j.getAsJsonObject();
blocks.add(new BlockPos(obj.get("x").getAsInt(), obj.get("y").getAsInt(), obj.get("z").getAsInt()));
});
// Only add it if it is not air in the client world
cacheBlocks = blocks.stream().filter(b -> !mc.world.getBlockState(b).isAir()).collect(toList());
// Update blocks map
Map<String, BlockState> map = new HashMap<>();
cacheBlocks.forEach(b -> map.put(posId(b), Blocks.DIAMOND_ORE.getDefaultState()));
blocksMap = map;
debug("Found " + cacheBlocks.size() + " valid ores.");
}
catch (IOException e)
{
e.printStackTrace();
}
updating = false;
}
@Override
public void onRenderPass(RenderEvent event)
{
if (!enabled) return;
// Render xray
PathRenderer.drawManySelectionBoxes(event.getModelViewStack(), Helper.mc.getRenderViewEntity(), cacheBlocks, Color.cyan);
}
@Override
public void onBlockBreak(BlockPos pos)
{
// Remove block from list
if (!cacheBlocks.removeIf(b -> posId(b).equals(posId(pos)))) return;
// Remove block from map
blocksMap.remove(posId(pos));
// Remove block from server
HttpGet get = new HttpGet("http://localhost:12255/api/remove-block");
get.setHeader("world", "world");
get.setHeader("x", "" + pos.getX());
get.setHeader("y", "" + pos.getY());
get.setHeader("z", "" + pos.getZ());
new Thread(() ->
{
try (CloseableHttpResponse response = http.execute(get))
{
System.out.println(IOUtils.toString(response.getEntity().getContent(), UTF_8));
}
catch (IOException e)
{
e.printStackTrace();
}
}).start();
}
}
@@ -0,0 +1,91 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package org.hydev.hyritone.seedxray;
import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Stream;
import static org.hydev.hyritone.Hyritone.seedServerCache;
import static org.hydev.hyritone.utils.MiscUtils.print;
/**
* TODO: Write a description for this class!
* <p>
* Class created by the HyDEV Team on 2020-02-19!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-02-19 12:29
*/
public class SeedXrayCommand extends Command
{
public SeedXrayCommand(IBaritone baritone) {
super(baritone, "seedxray");
}
@Override
public void execute(String label, IArgConsumer args) throws CommandException
{
if (Baritone.settings().mineWithSeed.value = seedServerCache.enabled = !seedServerCache.enabled)
{
print("Seed xray enabled");
}
else
{
print("Seed xray disabled");
// Reset status
seedServerCache.ticks = 100;
seedServerCache.enabled = false;
seedServerCache.blocksMap = new HashMap<>();
seedServerCache.cacheLocation = null;
seedServerCache.cacheBlocks = new ArrayList<>();
seedServerCache.updating = false;
}
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Hyritone: Find ores from the seed server";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"This function draws ESP boxes around the ores that exists in the seed server that are not mined.",
"",
"Usage:",
"> seedxray"
);
}
}
@@ -0,0 +1,27 @@
package org.hydev.hyritone.task;
/**
* A task waiting to be executed.
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 18:06
*/
public interface Task
{
/**
* Execute the task
*/
void execute(TaskRunState state);
/**
* Stop the task
*/
default void stop()
{
// Default nothing to do
}
}
@@ -0,0 +1,28 @@
package org.hydev.hyritone.task;
import lombok.AllArgsConstructor;
import java.util.ArrayList;
import java.util.Collections;
/**
* Instances of this class contains lists of tasks to be executed in order.
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 18:05
*/
@AllArgsConstructor
public class TaskList extends ArrayList<Task>
{
public final String name;
public TaskList(String name, Task... tasks)
{
this(name);
Collections.addAll(this, tasks);
}
}
@@ -0,0 +1,76 @@
package org.hydev.hyritone.task;
import lombok.Getter;
/**
* This class is used to manage tasks.
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 19:03
*/
@Getter
public class TaskManager
{
private TaskRunState runState = null;
/**
* Run a task list
*
* @param list Task list
* @return Successfully started or not
*/
public boolean run(TaskList list)
{
// Check already started
if (runState != null) return false;
// Reset values
runState = new TaskRunState(null, list, 0);
// Create thread
runState.thread = new Thread(() ->
{
// Execute step by step
while (runState.step < list.size())
{
list.get(runState.step).execute(runState);
runState.step++;
}
// Finished
stop();
}, "Hyritone Task");
// Start async
runState.thread.start();
// Success
return true;
}
/**
* Stop the task list
*/
public void stop()
{
// Not started
if (runState == null) return;
// Stop thread
runState.thread.interrupt();
// Stop task
if (runState.getStep() < runState.getTaskList().size())
{
runState.getTaskList().get(runState.getStep()).stop();
}
runState = null;
}
// TODO: pause
}
@@ -0,0 +1,95 @@
package org.hydev.hyritone.task;
import com.google.gson.Gson;
import lombok.SneakyThrows;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import static baritone.api.utils.Helper.mc;
/**
* This class contains preset tasks
* TODO: Make a UI for task list!
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 18:23
*/
public class TaskPresets
{
// Map<name.toLowerCase(), taskList>
public static Map<String, TaskList> presets = new HashMap<>();
/**
* Register a task list
*
* @param list Task list
*/
public static void register(TaskList list)
{
presets.put(list.name.toLowerCase(), list);
}
/**
* Get preset by name
*
* @param name Lowercase name
* @return Task list by name, null if not found
*/
public static TaskList getPreset(String name)
{
if (presets.containsKey(name.toLowerCase()))
{
return presets.get(name.toLowerCase());
}
return null;
}
/**
* Load presets from file
*/
@SneakyThrows
public static void reloadPresets()
{
Path filePath = new File(mc.gameDir, "./Hyritone/").toPath();
Files.createDirectories(filePath);
presets.clear();
try
{
Files.walk(filePath, FileVisitOption.FOLLOW_LINKS)
.filter(Files::isRegularFile)
.forEach(path ->
{
try
{
String json = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
TaskList list = new Gson().fromJson(json, TaskList.class);
presets.put(list.name.toLowerCase(), list);
}
catch (IOException e)
{
throw new UncheckedIOException(e);
}
});
}
catch (IOException | UncheckedIOException e)
{
System.err.println("Error when loading hyritone json.");
e.printStackTrace();
}
}
}
@@ -0,0 +1,30 @@
package org.hydev.hyritone.task;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* TODO: Write a description for this class!
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 20:38
*/
@Data
@AllArgsConstructor
public class TaskRunState
{
public Thread thread;
public TaskList taskList;
public int step;
@Override
public String toString()
{
return "Task " + thread.getId() + " is executing step " + step + " of " + taskList.size() + " " +
"| Current Task: " + taskList.get(step).getClass().getSimpleName();
}
}
@@ -0,0 +1,41 @@
package org.hydev.hyritone.task.defaults;
import lombok.AllArgsConstructor;
import org.hydev.hyritone.task.Task;
import org.hydev.hyritone.task.TaskRunState;
import java.util.function.Function;
/**
* Run task if condition is met
* <p>
* Class created by the HyDEV Team on 2020-01-25!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-25 17:44
*/
@AllArgsConstructor
public class TaskCondition implements Task
{
private final Function<TaskRunState, Boolean> condition;
private final Task taskIf;
private final Task taskElse;
@Override
public void execute(TaskRunState state)
{
if (condition.apply(state))
{
if (taskIf != null)
{
taskIf.execute(state);
}
}
else if (taskElse != null)
{
taskElse.execute(state);
}
}
}
@@ -0,0 +1,31 @@
package org.hydev.hyritone.task.defaults;
import lombok.AllArgsConstructor;
import org.hydev.hyritone.task.Task;
import org.hydev.hyritone.task.TaskRunState;
/**
* Task to delay for some seconds
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 18:21
*/
@AllArgsConstructor
public class TaskDelay implements Task
{
private final long delay;
@Override
public void execute(TaskRunState state)
{
try
{
Thread.sleep(delay);
}
catch (InterruptedException ignored) {}
}
}
@@ -0,0 +1,31 @@
package org.hydev.hyritone.task.defaults;
import lombok.AllArgsConstructor;
import net.minecraft.util.math.BlockPos;
import org.hydev.hyritone.task.Task;
import org.hydev.hyritone.task.TaskRunState;
import org.hydev.hyritone.utils.PlayerUtils;
/**
* Interact with blocks (Eg. chests)
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 23:10
*/
@AllArgsConstructor
public class TaskInteract implements Task
{
private final long x;
private final long y;
private final long z;
@Override
public void execute(TaskRunState state)
{
PlayerUtils.interact(new BlockPos(x, y, z));
}
}
@@ -0,0 +1,27 @@
package org.hydev.hyritone.task.defaults;
import lombok.AllArgsConstructor;
import org.hydev.hyritone.task.Task;
import org.hydev.hyritone.task.TaskRunState;
/**
* Replay from some index
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 20:37
*/
@AllArgsConstructor
public class TaskReplay implements Task
{
private final int step;
@Override
public void execute(TaskRunState state)
{
state.step = step - 1;
}
}
@@ -0,0 +1,45 @@
package org.hydev.hyritone.task.defaults;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.hydev.hyritone.task.Task;
import org.hydev.hyritone.task.TaskRunState;
import java.util.function.Function;
import static org.hydev.hyritone.utils.MiscUtils.sleep;
/**
* Wait for a condition to complete
* <p>
* Class created by the HyDEV Team on 2020-01-25!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-25 12:29
*/
@AllArgsConstructor
@RequiredArgsConstructor
public class TaskWaitFor implements Task
{
private final Function<TaskRunState, Boolean> condition;
private long timeout = 10 * 60 * 1000;
private long interval = 100;
@Override
public void execute(TaskRunState state)
{
// Timeout detection
long startTime = System.currentTimeMillis();
// Run
while (true)
{
if (condition.apply(state)) return;
sleep(interval);
if (System.currentTimeMillis() - startTime > timeout) return;
}
}
}
@@ -0,0 +1,77 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package org.hydev.hyritone.utils;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.StringTextComponent;
import static baritone.api.utils.Helper.mc;
/**
* TODO: Write a description for this class!
* <p>
* Class created by the HyDEV Team on 2020-02-19!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-02-19 13:28
*/
public class MiscUtils
{
public static void print(String text)
{
if (mc.player == null) return;
mc.player.sendMessage(new StringTextComponent("§3§l[§bHyritone§3§l] §r" + text));
System.out.println("Log: " + text);
}
public static void debug(String text)
{
print("§8[§7Debug§8]§7 " + text);
}
/**
* Get an identifier for a block pos that's unique for each xyz
*
* @param pos Block position
* @return Stringify
*/
public static String posId(BlockPos pos)
{
return String.format("[%s,%s,%s]", pos.getX(), pos.getY(), pos.getZ());
}
/**
* Sleep without exceptions
*
* @param ms Time in ms
*/
public static void sleep(long ms)
{
try
{
Thread.sleep(ms);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
@@ -0,0 +1,202 @@
package org.hydev.hyritone.utils;
import baritone.api.utils.Helper;
import baritone.api.utils.Rotation;
import baritone.utils.accessor.IMouse;
import net.minecraft.block.BlockState;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.multiplayer.PlayerController;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.network.play.client.CAnimateHandPacket;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
/**
* Utils for controlling the player.
* <p>
* Class created by the HyDEV Team on 2020-01-24!
*
* @author HyDEV Team (https://github.com/HyDevelop)
* @author Hykilpikonna (https://github.com/hykilpikonna)
* @author Vanilla (https://github.com/VergeDX)
* @since 2020-01-24 22:34
*/
public class PlayerUtils
{
public static ClientPlayerEntity player() { return Helper.mc.player; }
public static ClientWorld world() { return Helper.mc.world; }
public static IMouse mouse() { return (IMouse) Helper.mc.mouseHelper; }
public static PlayerController controller() { return Helper.mc.playerController; }
/**
* Get player's eye vector
*
* @return Eye vector
* @author Wurst7 https://github.com/Wurst-Imperium/Wurst7
*/
public static Vec3d getEyesPos()
{
assert player() != null;
return new Vec3d(player().getPosX(),
player().getPosY() + player().getEyeHeight(player().getPose()),
player().getPosZ());
}
/**
* Get what does it take to rotate to a direction
*
* @param vec Final direction
* @return Rotation required
* @author Wurst7 https://github.com/Wurst-Imperium/Wurst7
*/
public static Rotation getNeededRotations(Vec3d vec)
{
Vec3d eyesPos = getEyesPos();
double diffX = vec.x - eyesPos.x;
double diffY = vec.y - eyesPos.y;
double diffZ = vec.z - eyesPos.z;
double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
float yaw = (float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90F;
float pitch = (float)-Math.toDegrees(Math.atan2(diffY, diffXZ));
return new Rotation(yaw, pitch);
}
/**
* Rotate
*
* @param rotation Relative rotation
*/
public static void rotate(Rotation rotation)
{
player().rotationYaw = rotation.getYaw();
player().rotationPitch = rotation.getPitch();
}
/**
* Rotate to face one block
*
* @param pos Block position
* @return Direction
* @author Wurst7 https://github.com/Wurst-Imperium/Wurst7
*/
public static Direction rotateToBlock(BlockPos pos)
{
Direction side = null;
Direction[] sides = Direction.values();
Vec3d eyesPos = getEyesPos();
Vec3d relCenter = world().getBlockState(pos).getShape(world(), pos).getBoundingBox().getCenter();
Vec3d center = new Vec3d(pos).add(relCenter);
Vec3d[] hitVecs = new Vec3d[sides.length];
for (int i = 0; i < sides.length; i++)
{
Vec3i dirVec = sides[i].getDirectionVec();
Vec3d relHitVec = new Vec3d(relCenter.x * dirVec.getX(),
relCenter.y * dirVec.getY(), relCenter.z * dirVec.getZ());
hitVecs[i] = center.add(relHitVec);
}
BlockState state = world().getBlockState(pos);
for (int i = 0; i < sides.length; i++)
{
// check line of sight
if (world().rayTraceBlocks(eyesPos, hitVecs[i], pos, state.getShape(world(), pos), state) != null)
{
continue;
}
side = sides[i];
break;
}
if (side == null)
{
double distanceSqToCenter = eyesPos.squareDistanceTo(center);
for (int i = 0; i < sides.length; i++)
{
// check if side is facing towards player
if (eyesPos.squareDistanceTo(hitVecs[i]) >= distanceSqToCenter)
{
continue;
}
side = sides[i];
break;
}
}
// player is inside of block, side doesn't matter
if (side == null)
{
side = sides[0];
}
// Rotate
rotate(getNeededRotations(hitVecs[side.ordinal()]));
return side;
}
/**
* Interact
*
* @param pos Block
*/
public static void interact(BlockPos pos)
{
rotateToBlock(pos);
mouse().rightClick();
}
/**
* Dig the block at direction
*
* @param pos Block position
* @param side Direction
* @return Dig success or not
* @author Wurst7 https://github.com/Wurst-Imperium/Wurst7
*/
public static boolean dig(BlockPos pos, Direction side)
{
// damage block
if (!controller().onPlayerDamageBlock(pos, side))
{
return false;
}
// swing arm
player().connection.sendPacket(new CAnimateHandPacket(Hand.MAIN_HAND));
return true;
}
/**
* Dig the block at direction
*
* @param pos Block position
* @return Dig success or not
*/
public static boolean dig(BlockPos pos)
{
return dig(pos, rotateToBlock(pos));
}
/**
* Delay between swapping items from inv to chest.
*
* @return Delay between 80 to 120
*/
public static int chestDelay()
{
return (int) (80 + Math.random() * 40);
}
}