Compare commits

..

1 Commits

Author SHA1 Message Date
ZacSharp
a99e25eb8d v1.13.1 2025-08-27 00:33:00 +02:00
48 changed files with 328 additions and 465 deletions

View File

@@ -56,7 +56,7 @@ The recommended Java versions by Minecraft version are
| 1.12.2 - 1.16.5 | 8 |
| 1.17.1 | 16 |
| 1.18.2 - 1.20.4 | 17 |
| 1.20.5 - 1.21.5 | 21 |
| 1.20.5 - 1.21.4 | 21 |
Download java: https://adoptium.net/

View File

@@ -92,7 +92,7 @@ allprojects {
mappings {
intermediary()
mojmap()
parchment("1.21.4", "2025.03.23")
parchment("1.20.6", "2024.05.01")
devFallbackNamespace "official"
}

View File

@@ -11,7 +11,7 @@
"contact": {
"homepage": "https://github.com/cabaletta/baritone",
"sources": "https://github.com/cabaletta/baritone",
"issues": "https://github.com/cabaletta/baritone/issues"
"issues": "https://github.com/cabaletta/baritone/issues"
},
"license": "LGPL-3.0",
@@ -23,9 +23,10 @@
"mixins": [
"mixins.baritone.json"
],
"depends": {
"fabricloader": ">=0.14.22",
"minecraft": ["1.21.9", "1.21.10"]
"minecraft": ["1.21.4"]
},
"custom": {
"modmenu": {

View File

@@ -35,6 +35,6 @@ A Minecraft pathfinder bot.
modId="minecraft"
mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.21.9, 1.21.10]"
versionRange="[1.21.4]"
ordering="NONE"
side="BOTH"

View File

@@ -1,20 +1,20 @@
org.gradle.jvmargs=-Xmx4G
available_loaders=fabric,neoforge,forge,tweaker
available_loaders=fabric,forge,neoforge,tweaker
mod_version=1.16.0
mod_version=1.13.1
maven_group=baritone
archives_base_name=baritone
java_version=21
minecraft_version=1.21.10
minecraft_version=1.21.4
forge_version=60.0.0
forge_version=54.0.5
neoforge_version=1-beta
neoforge_version=9-beta
fabric_version=0.17.2
fabric_version=0.16.9
nether_pathfinder_version=1.4.1

View File

@@ -35,9 +35,6 @@ A Minecraft pathfinder bot.
modId="minecraft"
type="required"
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.21.9, 1.21.10]"
versionRange="[1.21.4]"
ordering="NONE"
side="BOTH"
[[mixins]]
config = "mixins.baritone.json"

View File

@@ -41,7 +41,7 @@
# setting names are reflected from field names, so keep field names
-keepclassmembers class baritone.api.Settings {
public <fields>;
public <fields>;
}
# need to keep mixin names
@@ -346,4 +346,4 @@
public int length();
public java.lang.String substring(int);
public java.lang.String substring(int,int);
}
}

View File

@@ -21,16 +21,17 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.utils.Helper;
import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
public class Paginator<E> implements Helper {
public final List<E> entries;
@@ -77,10 +78,12 @@ public class Paginator<E> implements Helper {
MutableComponent prevPageComponent = Component.literal("<<");
if (hasPrevPage) {
prevPageComponent.setStyle(prevPageComponent.getStyle()
.withClickEvent(new ClickEvent.RunCommand(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format("%s %d", commandPrefix, page - 1)
))
.withHoverEvent(new HoverEvent.ShowText(
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Component.literal("Click to view previous page")
)));
} else {
@@ -89,8 +92,9 @@ public class Paginator<E> implements Helper {
MutableComponent nextPageComponent = Component.literal(">>");
if (hasNextPage) {
nextPageComponent.setStyle(nextPageComponent.getStyle()
.withClickEvent(new ClickEvent.RunCommand(String.format("%s %d", commandPrefix, page + 1)))
.withHoverEvent(new HoverEvent.ShowText(
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s %d", commandPrefix, page + 1)))
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Component.literal("Click to view next page")
)));
} else {

View File

@@ -32,6 +32,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.RegistryLayer;
import net.minecraft.server.ReloadableServerRegistries;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.progress.ChunkProgressListener;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.VanillaPackResources;
import net.minecraft.server.packs.repository.ServerPacksSource;
@@ -261,8 +262,8 @@ public final class BlockOptionalMeta {
private static Unsafe unsafe = getUnsafe();
private static CompletableFuture<RegistryAccess> registryAccess = load();
public ServerLevelStub(MinecraftServer $$0, Executor $$1, LevelStorageSource.LevelStorageAccess $$2, ServerLevelData $$3, ResourceKey<Level> $$4, LevelStem $$5, boolean $$6, long $$7, List<CustomSpawner> $$8, boolean $$9, @Nullable RandomSequences $$10) {
super($$0, $$1, $$2, $$3, $$4, $$5, $$6, $$7, $$8, $$9, $$10);
public ServerLevelStub(MinecraftServer $$0, Executor $$1, LevelStorageSource.LevelStorageAccess $$2, ServerLevelData $$3, ResourceKey<Level> $$4, LevelStem $$5, ChunkProgressListener $$6, boolean $$7, long $$8, List<CustomSpawner> $$9, boolean $$10, @Nullable RandomSequences $$11) {
super($$0, $$1, $$2, $$3, $$4, $$5, $$6, $$7, $$8, $$9, $$10, $$11);
}
@Override

View File

@@ -23,9 +23,9 @@ import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.SprintStateEvent;
import baritone.api.event.events.type.EventState;
import baritone.behavior.LookBehavior;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.world.entity.player.Input;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
@@ -110,13 +110,13 @@ public class MixinClientPlayerEntity {
method = "aiStep",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/player/Input;sprint()Z"
target = "net/minecraft/client/KeyMapping.isDown()Z"
)
)
private boolean redirectSprintInput(final Input instance) {
private boolean isKeyDown(KeyMapping keyBinding) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
if (baritone == null) {
return instance.sprint();
return keyBinding.isDown();
}
SprintStateEvent event = new SprintStateEvent();
baritone.getGameEventHandler().onPlayerSprintState(event);
@@ -127,7 +127,7 @@ public class MixinClientPlayerEntity {
// hitting control shouldn't make all bots sprint
return false;
}
return instance.sprint();
return keyBinding.isDown();
}
@Inject(

View File

@@ -101,7 +101,7 @@ public abstract class MixinLivingEntity extends Entity {
method = "travelFallFlying",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/LivingEntity;move(Lnet/minecraft/world/entity/MoverType;Lnet/minecraft/world/phys/Vec3;)V",
target = "net/minecraft/world/entity/LivingEntity.move(Lnet/minecraft/world/entity/MoverType;Lnet/minecraft/world/phys/Vec3;)V",
shift = At.Shift.AFTER
)
)

View File

@@ -24,6 +24,7 @@ import baritone.api.event.events.TickEvent;
import baritone.api.event.events.WorldEvent;
import baritone.api.event.events.type.EventState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
@@ -130,7 +131,7 @@ public class MixinMinecraft {
method = "setLevel",
at = @At("HEAD")
)
private void preLoadWorld(final ClientLevel world, final CallbackInfo ci) {
private void preLoadWorld(ClientLevel world, ReceivingLevelScreen.Reason arg2, CallbackInfo ci) {
// If we're unloading the world but one doesn't exist, ignore it
if (this.level == null && world == null) {
return;
@@ -150,7 +151,7 @@ public class MixinMinecraft {
method = "setLevel",
at = @At("RETURN")
)
private void postLoadWorld(final ClientLevel world, final CallbackInfo ci) {
private void postLoadWorld(ClientLevel world, ReceivingLevelScreen.Reason arg2, CallbackInfo ci) {
// still fire event for both null, as that means we've just finished exiting a world
// mc.world changing is only the primary baritone

View File

@@ -22,9 +22,9 @@ import baritone.api.IBaritone;
import baritone.api.event.events.PacketEvent;
import baritone.api.event.events.type.EventState;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.network.Connection;
import net.minecraft.network.PacketSendListener;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
import org.spongepowered.asm.mixin.Final;
@@ -52,7 +52,7 @@ public class MixinNetworkManager {
method = "sendPacket",
at = @At("HEAD")
)
private void preDispatchPacket(final Packet<?> packet, final ChannelFutureListener channelFutureListener, final boolean flush, final CallbackInfo ci) {
private void preDispatchPacket(Packet<?> packet, PacketSendListener packetSendListener, boolean flush, CallbackInfo ci) {
if (this.receiving != PacketFlow.CLIENTBOUND) {
return;
}
@@ -68,7 +68,7 @@ public class MixinNetworkManager {
method = "sendPacket",
at = @At("RETURN")
)
private void postDispatchPacket(Packet<?> packet, ChannelFutureListener packetSendListener, boolean flush, CallbackInfo ci) {
private void postDispatchPacket(Packet<?> packet, PacketSendListener packetSendListener, boolean flush, CallbackInfo ci) {
if (this.receiving != PacketFlow.CLIENTBOUND) {
return;
}

View File

@@ -1,35 +0,0 @@
/*
* 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.IRenderPipelines;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import net.minecraft.client.renderer.RenderPipelines;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(RenderPipelines.class)
public class MixinRenderPipelines implements IRenderPipelines {
@Final @Shadow
private static RenderPipeline.Snippet LINES_SNIPPET;
public RenderPipeline.Snippet getLinesSnippet() {
return LINES_SNIPPET;
}
}

View File

@@ -21,13 +21,16 @@ import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.ChatEvent;
import baritone.utils.accessor.IGuiScreen;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Style;
import org.spongepowered.asm.mixin.Mixin;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.net.URI;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
@@ -35,19 +38,21 @@ import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public abstract class MixinScreen implements IGuiScreen {
//TODO: switch to enum extention with mixin 9.0 or whenever Mumfrey gets around to it
@Inject(method = "handleClickEvent", at = @At(value = "HEAD"), cancellable = true)
public void handleCustomClickEvent(final Minecraft minecraft, final ClickEvent clickEvent, final CallbackInfo ci) {
@Inject(at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;)V", remap = false, ordinal = 1), method = "handleComponentClicked", cancellable = true)
public void handleCustomClickEvent(Style style, CallbackInfoReturnable<Boolean> cir) {
ClickEvent clickEvent = style.getClickEvent();
if (clickEvent == null) {
return;
}
if (!(clickEvent instanceof ClickEvent.RunCommand(String command))) return;
if (!command.startsWith(FORCE_COMMAND_PREFIX)) {
String command = clickEvent.getValue();
if (command == null || !command.startsWith(FORCE_COMMAND_PREFIX)) {
return;
}
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
if (baritone != null) {
baritone.getGameEventHandler().onSendChatMessage(new ChatEvent(command));
}
ci.cancel();
cir.setReturnValue(true);
cir.cancel();
}
}

View File

@@ -20,14 +20,13 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.RenderEvent;
import com.mojang.blaze3d.buffers.GpuBufferSlice;
import com.mojang.blaze3d.resource.GraphicsResourceAllocator;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import org.joml.Matrix4f;
import org.joml.Vector4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -44,7 +43,7 @@ public class MixinWorldRenderer {
method = "renderLevel",
at = @At("RETURN")
)
private void onStartHand(final GraphicsResourceAllocator graphicsResourceAllocator, final DeltaTracker deltaTracker, final boolean bl, final Camera camera, final Matrix4f matrix4f, final Matrix4f matrix4f2, final Matrix4f matrix4f3, final GpuBufferSlice gpuBufferSlice, final Vector4f vector4f, final boolean bl2, final CallbackInfo ci) {
private void onStartHand(final GraphicsResourceAllocator graphicsResourceAllocator, final DeltaTracker deltaTracker, final boolean bl, final Camera camera, final GameRenderer gameRenderer, final Matrix4f matrix4f, final Matrix4f matrix4f2, final CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
PoseStack poseStack = new PoseStack();
poseStack.mulPose(matrix4f);

View File

@@ -25,7 +25,6 @@
"MixinPalettedContainer",
"MixinPalettedContainer$Data",
"MixinPlayerController",
"MixinRenderPipelines",
"MixinScreen",
"MixinWorldRenderer"
],

View File

@@ -24,13 +24,13 @@ import baritone.utils.ToolSet;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.Block;
@@ -38,7 +38,6 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import java.util.ArrayList;
import java.util.OptionalInt;
import java.util.Random;
@@ -69,7 +68,7 @@ public final class InventoryBehavior extends Behavior implements Helper {
if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory
requestSwapWithHotBar(firstValidThrowaway(), 8);
}
int pick = bestToolAgainst(Blocks.STONE);
int pick = bestToolAgainst(Blocks.STONE, PickaxeItem.class);
if (pick >= 9) {
requestSwapWithHotBar(pick, 0);
}
@@ -93,7 +92,7 @@ public final class InventoryBehavior extends Behavior implements Helper {
// we're using 0 and 8 for pickaxe and throwaway
ArrayList<Integer> candidates = new ArrayList<>();
for (int i = 1; i < 8; i++) {
if (ctx.player().getInventory().getNonEquipmentItems().get(i).isEmpty() && !disallowedHotbar.test(i)) {
if (ctx.player().getInventory().items.get(i).isEmpty() && !disallowedHotbar.test(i)) {
candidates.add(i);
}
}
@@ -127,7 +126,7 @@ public final class InventoryBehavior extends Behavior implements Helper {
}
private int firstValidThrowaway() { // TODO offhand idk
NonNullList<ItemStack> invy = ctx.player().getInventory().getNonEquipmentItems();
NonNullList<ItemStack> invy = ctx.player().getInventory().items;
for (int i = 0; i < invy.size(); i++) {
if (Baritone.settings().acceptableThrowawayItems.value.contains(invy.get(i).getItem())) {
return i;
@@ -136,8 +135,8 @@ public final class InventoryBehavior extends Behavior implements Helper {
return -1;
}
private int bestToolAgainst(Block against) {
NonNullList<ItemStack> invy = ctx.player().getInventory().getNonEquipmentItems();
private int bestToolAgainst(Block against, Class<? extends DiggerItem> cla$$) {
NonNullList<ItemStack> invy = ctx.player().getInventory().items;
int bestInd = -1;
double bestSpeed = -1;
for (int i = 0; i < invy.size(); i++) {
@@ -148,7 +147,7 @@ public final class InventoryBehavior extends Behavior implements Helper {
if (Baritone.settings().itemSaver.value && (stack.getDamageValue() + Baritone.settings().itemSaverThreshold.value) >= stack.getMaxDamage() && stack.getMaxDamage() > 1) {
continue;
}
if (stack.getItem().components().has(DataComponents.TOOL)) {
if (cla$$.isInstance(stack.getItem())) {
double speed = ToolSet.calculateSpeedVsBlock(stack, against.defaultBlockState()); // takes into account enchants
if (speed > bestSpeed) {
bestSpeed = speed;
@@ -190,7 +189,7 @@ public final class InventoryBehavior extends Behavior implements Helper {
public boolean throwaway(boolean select, Predicate<? super ItemStack> desired, boolean allowInventory) {
LocalPlayer p = ctx.player();
NonNullList<ItemStack> inv = p.getInventory().getNonEquipmentItems();
NonNullList<ItemStack> inv = p.getInventory().items;
for (int i = 0; i < 9; i++) {
ItemStack item = inv.get(i);
// this usage of settings() is okay because it's only called once during pathing
@@ -200,12 +199,12 @@ public final class InventoryBehavior extends Behavior implements Helper {
// acceptableThrowawayItems to the CalculationContext
if (desired.test(item)) {
if (select) {
p.getInventory().setSelectedSlot(i);
p.getInventory().selected = i;
}
return true;
}
}
if (desired.test(p.getItemBySlot(EquipmentSlot.OFFHAND))) {
if (desired.test(p.getInventory().offhand.get(0))) {
// main hand takes precedence over off hand
// that means that if we have block A selected in main hand and block B in off hand, right clicking places block B
// we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem
@@ -213,9 +212,9 @@ public final class InventoryBehavior extends Behavior implements Helper {
// so not a shovel, not a hoe, not a block, etc
for (int i = 0; i < 9; i++) {
ItemStack item = inv.get(i);
if (item.isEmpty() || item.getItem().components().has(DataComponents.TOOL)) {
if (item.isEmpty() || item.getItem() instanceof PickaxeItem) {
if (select) {
p.getInventory().setSelectedSlot(i);
p.getInventory().selected = i;
}
return true;
}
@@ -227,7 +226,7 @@ public final class InventoryBehavior extends Behavior implements Helper {
if (desired.test(inv.get(i))) {
if (select) {
requestSwapWithHotBar(i, 7);
p.getInventory().setSelectedSlot(7);
p.getInventory().selected = 7;
}
return true;
}

View File

@@ -33,18 +33,16 @@ import baritone.pathing.calc.AbstractNodeCostSearch;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.path.PathExecutor;
import baritone.process.ElytraProcess;
import baritone.utils.PathRenderer;
import baritone.utils.PathingCommandContext;
import baritone.utils.pathing.Favoring;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.LinkedBlockingQueue;
import net.minecraft.core.BlockPos;
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
@@ -160,9 +158,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
queuePathEvent(PathEvent.AT_GOAL);
next = null;
if (Baritone.settings().disconnectOnArrival.value) {
if (ctx.world() instanceof ClientLevel clientLevel) {
clientLevel.disconnect(Component.literal("[Baritone] Arrived at goal!"));
}
ctx.world().disconnect();
}
return;
}

View File

@@ -73,10 +73,12 @@ public class WaypointBehavior extends Behavior {
MutableComponent component = Component.literal("Death position saved.");
component.setStyle(component.getStyle()
.withColor(ChatFormatting.WHITE)
.withHoverEvent(new HoverEvent.ShowText(
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Component.literal("Click to goto death")
))
.withClickEvent(new ClickEvent.RunCommand(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format(
"%s%s goto %s @ %d",
FORCE_COMMAND_PREFIX,

View File

@@ -26,12 +26,19 @@ import baritone.api.utils.IPlayerContext;
import baritone.utils.accessor.IPalettedContainer;
import io.netty.buffer.Unpooled;
import net.minecraft.core.BlockPos;
import net.minecraft.core.IdMapper;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.BitStorage;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.chunk.GlobalPalette;
import net.minecraft.world.level.chunk.ChunkSource;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.Palette;
import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.SingleValuePalette;
import java.util.ArrayList;
import java.util.List;
@@ -282,7 +289,7 @@ public enum FasterWorldScanner implements IWorldScanner {
return PALETTE_REGISTRY_SENTINEL;
} else {
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
palette.write(buf, Block.BLOCK_STATE_REGISTRY);
palette.write(buf);
int size = buf.readVarInt();
BlockState[] states = new BlockState[size];
for (int i = 0; i < size; i++) {

View File

@@ -33,14 +33,14 @@ import baritone.behavior.Behavior;
import baritone.command.argument.ArgConsumer;
import baritone.command.argument.CommandArguments;
import baritone.command.manager.CommandManager;
import baritone.utils.accessor.IGuiScreen;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.*;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.Tuple;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
@@ -80,10 +80,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
MutableComponent component = Component.literal(String.format("> %s", toDisplay));
component.setStyle(component.getStyle()
.withColor(ChatFormatting.WHITE)
.withHoverEvent(new HoverEvent.ShowText(
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Component.literal("Click to rerun command")
))
.withClickEvent(new ClickEvent.RunCommand(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + msg
)));
logDirect(component);

View File

@@ -115,11 +115,11 @@ public class ElytraCommand extends Command {
clippy.append("Within a few hundred blocks of spawn/axis/highways/etc, the terrain is too fragmented to be predictable. Baritone Elytra will still work, just with backtracking. ");
clippy.append("However, once you get more than a few thousand blocks out, you should try ");
MutableComponent olderSeed = Component.literal("the older seed (click here)");
olderSeed.setStyle(olderSeed.getStyle().withUnderlined(true).withBold(true).withHoverEvent(new HoverEvent.ShowText(Component.literal(Baritone.settings().prefix.value + "set elytraNetherSeed " + OLD_2B2T_SEED))).withClickEvent(new ClickEvent.RunCommand(FORCE_COMMAND_PREFIX + "set elytraNetherSeed " + OLD_2B2T_SEED)));
olderSeed.setStyle(olderSeed.getStyle().withUnderlined(true).withBold(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(Baritone.settings().prefix.value + "set elytraNetherSeed " + OLD_2B2T_SEED))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, FORCE_COMMAND_PREFIX + "set elytraNetherSeed " + OLD_2B2T_SEED)));
clippy.append(olderSeed);
clippy.append(". Once you're further out into newer terrain generation (this includes everything up through 1.12), you should try ");
MutableComponent newerSeed = Component.literal("the newer seed (click here)");
newerSeed.setStyle(newerSeed.getStyle().withUnderlined(true).withBold(true).withHoverEvent(new HoverEvent.ShowText(Component.literal(Baritone.settings().prefix.value + "set elytraNetherSeed " + NEW_2B2T_SEED))).withClickEvent(new ClickEvent.RunCommand(FORCE_COMMAND_PREFIX + "set elytraNetherSeed " + NEW_2B2T_SEED)));
newerSeed.setStyle(newerSeed.getStyle().withUnderlined(true).withBold(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(Baritone.settings().prefix.value + "set elytraNetherSeed " + NEW_2B2T_SEED))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, FORCE_COMMAND_PREFIX + "set elytraNetherSeed " + NEW_2B2T_SEED)));
clippy.append(newerSeed);
clippy.append(". Once you get into 1.19 terrain, the terrain becomes unpredictable again, due to custom non-vanilla generation, and you should set #elytraPredictTerrain to false. ");
return clippy;
@@ -130,10 +130,10 @@ public class ElytraCommand extends Command {
gatekeep.append("To disable this message, enable the setting elytraTermsAccepted\n");
gatekeep.append("Baritone Elytra is an experimental feature. It is only intended for long distance travel in the Nether using fireworks for vanilla boost. It will not work with any other mods (\"hacks\") for non-vanilla boost. ");
MutableComponent gatekeep2 = Component.literal("If you want Baritone to attempt to take off from the ground for you, you can enable the elytraAutoJump setting (not advisable on laggy servers!). ");
gatekeep2.setStyle(gatekeep2.getStyle().withHoverEvent(new HoverEvent.ShowText(Component.literal(Baritone.settings().prefix.value + "set elytraAutoJump true"))));
gatekeep2.setStyle(gatekeep2.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(Baritone.settings().prefix.value + "set elytraAutoJump true"))));
gatekeep.append(gatekeep2);
MutableComponent gatekeep3 = Component.literal("If you want Baritone to go slower, enable the elytraConserveFireworks setting and/or decrease the elytraFireworkSpeed setting. ");
gatekeep3.setStyle(gatekeep3.getStyle().withHoverEvent(new HoverEvent.ShowText(Component.literal(Baritone.settings().prefix.value + "set elytraConserveFireworks true\n" + Baritone.settings().prefix.value + "set elytraFireworkSpeed 0.6\n(the 0.6 number is just an example, tweak to your liking)"))));
gatekeep3.setStyle(gatekeep3.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(Baritone.settings().prefix.value + "set elytraConserveFireworks true\n" + Baritone.settings().prefix.value + "set elytraFireworkSpeed 0.6\n(the 0.6 number is just an example, tweak to your liking)"))));
gatekeep.append(gatekeep3);
MutableComponent gatekeep4 = Component.literal("Baritone Elytra ");
MutableComponent red = Component.literal("wants to know the seed");

View File

@@ -25,6 +25,7 @@ import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.utils.BetterBlockPos;
import baritone.cache.CachedChunk;
import net.minecraft.core.Registry;
import net.minecraft.ChatFormatting;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.ClickEvent;
@@ -82,8 +83,8 @@ public class FindCommand extends Command {
baseComponent.setStyle(baseComponent.getStyle()
.withColor(ChatFormatting.GRAY)
.withInsertion(positionText)
.withClickEvent(new ClickEvent.RunCommand(command))
.withHoverEvent(new HoverEvent.ShowText(hoverComponent)));
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)));
return baseComponent;
}

View File

@@ -25,17 +25,19 @@ import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandNotFoundException;
import baritone.api.command.helpers.Paginator;
import baritone.api.command.helpers.TabCompleteHelper;
import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public class HelpCommand extends Command {
@@ -72,8 +74,8 @@ public class HelpCommand extends Command {
component.setStyle(component.getStyle().withColor(ChatFormatting.GRAY));
component.append(shortDescComponent);
component.setStyle(component.getStyle()
.withHoverEvent(new HoverEvent.ShowText(hoverComponent))
.withClickEvent(new ClickEvent.RunCommand(clickCommand)));
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent))
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, clickCommand)));
return component;
},
FORCE_COMMAND_PREFIX + label
@@ -89,7 +91,8 @@ public class HelpCommand extends Command {
command.getLongDesc().forEach(this::logDirect);
logDirect("");
MutableComponent returnComponent = Component.literal("Click to return to the help menu");
returnComponent.setStyle(returnComponent.getStyle().withClickEvent(new ClickEvent.RunCommand(
returnComponent.setStyle(returnComponent.getStyle().withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + label
)));
logDirect(returnComponent);

View File

@@ -43,6 +43,7 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.IRenderer;
import baritone.utils.schematic.StaticSchematic;
import com.mojang.blaze3d.vertex.BufferBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.world.level.block.Blocks;
@@ -75,7 +76,7 @@ public class SelCommand extends Command {
float opacity = Baritone.settings().selectionOpacity.value;
float lineWidth = Baritone.settings().selectionLineWidth.value;
boolean ignoreDepth = Baritone.settings().renderSelectionIgnoreDepth.value;
BufferBuilder bufferBuilder = IRenderer.startLines(color, opacity, lineWidth);
BufferBuilder bufferBuilder = IRenderer.startLines(color, opacity, lineWidth, ignoreDepth);
IRenderer.emitAABB(bufferBuilder, event.getModelViewStack(), new AABB(pos1));
IRenderer.endLines(bufferBuilder, ignoreDepth);
}

View File

@@ -31,8 +31,8 @@ import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.utils.SettingsUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
@@ -108,8 +108,8 @@ public class SetCommand extends Command {
component.setStyle(component.getStyle().withColor(ChatFormatting.GRAY));
component.append(typeComponent);
component.setStyle(component.getStyle()
.withHoverEvent(new HoverEvent.ShowText(hoverComponent))
.withClickEvent(new ClickEvent.SuggestCommand(commandSuggestion)));
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent))
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, commandSuggestion)));
return component;
},
FORCE_COMMAND_PREFIX + "set " + arg + " " + search
@@ -188,10 +188,12 @@ public class SetCommand extends Command {
MutableComponent oldValueComponent = Component.literal(String.format("Old value: %s", oldValue));
oldValueComponent.setStyle(oldValueComponent.getStyle()
.withColor(ChatFormatting.GRAY)
.withHoverEvent(new HoverEvent.ShowText(
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Component.literal("Click to set the setting back to this value")
))
.withClickEvent(new ClickEvent.RunCommand(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + String.format("set %s %s", setting.getName(), oldValue)
)));
logDirect(oldValueComponent);

View File

@@ -34,17 +34,17 @@ import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
@@ -75,10 +75,12 @@ public class WaypointsCommand extends Command {
component.append(nameComponent);
component.append(timestamp);
component.setStyle(component.getStyle()
.withHoverEvent(new HoverEvent.ShowText(
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Component.literal("Click to select")
))
.withClickEvent(new ClickEvent.RunCommand(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format(
"%s%s %s %s @ %d",
FORCE_COMMAND_PREFIX,
@@ -158,7 +160,8 @@ public class WaypointsCommand extends Command {
}
deletedWaypoints.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), k -> new ArrayList<>()).addAll(Arrays.<IWaypoint>asList(waypoints));
MutableComponent textComponent = Component.literal(String.format("Cleared %d waypoints, click to restore them", waypoints.length));
textComponent.setStyle(textComponent.getStyle().withClickEvent(new ClickEvent.RunCommand(
textComponent.setStyle(textComponent.getStyle().withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format(
"%s%s restore @ %s",
FORCE_COMMAND_PREFIX,
@@ -238,7 +241,8 @@ public class WaypointsCommand extends Command {
logDirect(transform.apply(waypoint));
logDirect(String.format("Position: %s", waypoint.getLocation()));
MutableComponent deleteComponent = Component.literal("Click to delete this waypoint");
deleteComponent.setStyle(deleteComponent.getStyle().withClickEvent(new ClickEvent.RunCommand(
deleteComponent.setStyle(deleteComponent.getStyle().withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format(
"%s%s delete %s @ %d",
FORCE_COMMAND_PREFIX,
@@ -248,7 +252,8 @@ public class WaypointsCommand extends Command {
)
)));
MutableComponent goalComponent = Component.literal("Click to set goal to this waypoint");
goalComponent.setStyle(goalComponent.getStyle().withClickEvent(new ClickEvent.RunCommand(
goalComponent.setStyle(goalComponent.getStyle().withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format(
"%s%s goal %s @ %d",
FORCE_COMMAND_PREFIX,
@@ -258,7 +263,8 @@ public class WaypointsCommand extends Command {
)
)));
MutableComponent recreateComponent = Component.literal("Click to show a command to recreate this waypoint");
recreateComponent.setStyle(recreateComponent.getStyle().withClickEvent(new ClickEvent.SuggestCommand(
recreateComponent.setStyle(recreateComponent.getStyle().withClickEvent(new ClickEvent(
ClickEvent.Action.SUGGEST_COMMAND,
String.format(
"%s%s save %s %s %s %s %s",
Baritone.settings().prefix.value, // This uses the normal prefix because it is run by the user.
@@ -271,7 +277,8 @@ public class WaypointsCommand extends Command {
)
)));
MutableComponent backComponent = Component.literal("Click to return to the waypoints list");
backComponent.setStyle(backComponent.getStyle().withClickEvent(new ClickEvent.RunCommand(
backComponent.setStyle(backComponent.getStyle().withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format(
"%s%s list",
FORCE_COMMAND_PREFIX,
@@ -286,7 +293,8 @@ public class WaypointsCommand extends Command {
ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
deletedWaypoints.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), k -> new ArrayList<>()).add(waypoint);
MutableComponent textComponent = Component.literal("That waypoint has successfully been deleted, click to restore it");
textComponent.setStyle(textComponent.getStyle().withClickEvent(new ClickEvent.RunCommand(
textComponent.setStyle(textComponent.getStyle().withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format(
"%s%s restore @ %s",
FORCE_COMMAND_PREFIX,

View File

@@ -43,12 +43,17 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.block.state.properties.StairsShape;
import net.minecraft.world.level.material.*;
import net.minecraft.world.level.material.FlowingFluid;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.WaterFluid;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import java.util.List;
import java.util.Optional;
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP;
@@ -645,7 +650,7 @@ public interface MovementHelper extends ActionCosts, Helper {
*/
static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts, boolean preferSilkTouch) {
if (Baritone.settings().autoTool.value && !Baritone.settings().assumeExternalAutoTool.value) {
ctx.player().getInventory().setSelectedSlot(ts.getBestSlot(b.getBlock(), preferSilkTouch));
ctx.player().getInventory().selected = ts.getBestSlot(b.getBlock(), preferSilkTouch);
}
}

View File

@@ -30,6 +30,9 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.pathing.MutableMoveResult;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
@@ -44,10 +47,6 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.WaterFluid;
import net.minecraft.world.phys.Vec3;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class MovementFall extends Movement {
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
@@ -102,7 +101,7 @@ public class MovementFall extends Movement {
}
if (ctx.player().position().y - dest.getY() < ctx.playerController().getBlockReachDistance() && !ctx.player().onGround()) {
ctx.player().getInventory().setSelectedSlot(ctx.player().getInventory().findSlotMatchingItem(STACK_BUCKET_WATER));
ctx.player().getInventory().selected = ctx.player().getInventory().findSlotMatchingItem(STACK_BUCKET_WATER);
targetRotation = new Rotation(toDest.getYaw(), 90.0F);
@@ -119,7 +118,7 @@ public class MovementFall extends Movement {
if (playerFeet.equals(dest) && (ctx.player().position().y - playerFeet.getY() < 0.094 || isWater)) { // 0.094 because lilypads
if (isWater) { // only match water, not flowing water (which we cannot pick up with a bucket)
if (Inventory.isHotbarSlot(ctx.player().getInventory().findSlotMatchingItem(STACK_BUCKET_EMPTY))) {
ctx.player().getInventory().setSelectedSlot(ctx.player().getInventory().findSlotMatchingItem(STACK_BUCKET_EMPTY));
ctx.player().getInventory().selected = ctx.player().getInventory().findSlotMatchingItem(STACK_BUCKET_EMPTY);
if (ctx.player().getDeltaMovement().y >= 0) {
return state.setInput(Input.CLICK_RIGHT, true);
} else {

View File

@@ -25,10 +25,15 @@ import baritone.api.pathing.goals.GoalGetToBlock;
import baritone.api.process.IBuilderProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.api.schematic.*;
import baritone.api.schematic.FillSchematic;
import baritone.api.schematic.ISchematic;
import baritone.api.schematic.IStaticSchematic;
import baritone.api.schematic.MaskSchematic;
import baritone.api.schematic.SubstituteSchematic;
import baritone.api.schematic.RotatedSchematic;
import baritone.api.schematic.MirroredSchematic;
import baritone.api.schematic.format.ISchematicFormat;
import baritone.api.utils.*;
import baritone.api.utils.Rotation;
import baritone.api.utils.input.Input;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
@@ -37,8 +42,8 @@ import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
import baritone.utils.PathingCommandContext;
import baritone.utils.schematic.MapArtSchematic;
import baritone.utils.schematic.SchematicSystem;
import baritone.utils.schematic.SelectionSchematic;
import baritone.utils.schematic.SchematicSystem;
import baritone.utils.schematic.litematica.LitematicaHelper;
import baritone.utils.schematic.schematica.SchematicaHelper;
import com.google.common.collect.ImmutableSet;
@@ -52,7 +57,14 @@ import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.AirBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.PipeBlock;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.phys.AABB;
@@ -383,7 +395,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private OptionalInt hasAnyItemThatWouldPlace(BlockState desired, HitResult result, Rotation rot) {
for (int i = 0; i < 9; i++) {
ItemStack stack = ctx.player().getInventory().getNonEquipmentItems().get(i);
ItemStack stack = ctx.player().getInventory().items.get(i);
if (stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) {
continue;
}
@@ -555,7 +567,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround() && ticks <= 0) {
Rotation rot = toPlace.get().rot;
baritone.getLookBehavior().updateTarget(rot, true);
ctx.player().getInventory().setSelectedSlot(toPlace.get().hotbarSelection);
ctx.player().getInventory().selected = toPlace.get().hotbarSelection;
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ((BlockHitResult) ctx.objectMouseOver()).getDirection().equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
@@ -1005,7 +1017,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private List<BlockState> approxPlaceable(int size) {
List<BlockState> result = new ArrayList<>();
for (int i = 0; i < size; i++) {
ItemStack stack = ctx.player().getInventory().getNonEquipmentItems().get(i);
ItemStack stack = ctx.player().getInventory().items.get(i);
if (stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) {
result.add(Blocks.AIR.defaultBlockState());
continue;

View File

@@ -23,8 +23,6 @@ import baritone.api.process.ICustomGoalProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.chat.Component;
/**
* As set by ExampleBaritoneControl or something idk
@@ -107,9 +105,7 @@ public final class CustomGoalProcess extends BaritoneProcessHelper implements IC
if (this.goal == null || (this.goal.isInGoal(ctx.playerFeet()) && this.goal.isInGoal(baritone.getPathingBehavior().pathStart()))) {
onLostControl(); // we're there xd
if (Baritone.settings().disconnectOnArrival.value) {
if (ctx.world() instanceof ClientLevel clientLevel) {
clientLevel.disconnect(Component.literal("[Baritone] Arrived at goal!"));
}
ctx.world().disconnect();
}
if (Baritone.settings().notificationOnPathComplete.value) {
logNotification("Pathing complete", false);

View File

@@ -44,10 +44,8 @@ import baritone.process.elytra.NullElytraProcess;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.PathingCommandContext;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
@@ -159,9 +157,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
if (Baritone.settings().disconnectOnArrival.value && !reachedGoal) {
// don't be active when the user logs back in
this.onLostControl();
if (ctx.world() instanceof ClientLevel clientLevel) {
clientLevel.disconnect(Component.literal("[Baritone] Arrived at goal!"));
}
ctx.world().disconnect();
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
reachedGoal = true;
@@ -371,7 +367,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
return true;
}
NonNullList<ItemStack> inv = ctx.player().getInventory().getNonEquipmentItems();
NonNullList<ItemStack> inv = ctx.player().getInventory().items;
int qty = 0;
for (int i = 0; i < 36; i++) {
if (ElytraBehavior.isFireworks(inv.get(i))) {

View File

@@ -74,7 +74,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (desiredQuantity > 0) {
int curr = ctx.player().getInventory().getNonEquipmentItems().stream()
int curr = ctx.player().getInventory().items.stream()
.filter(stack -> filter.has(stack))
.mapToInt(ItemStack::getCount).sum();
if (curr >= desiredQuantity) {

View File

@@ -37,6 +37,7 @@ import it.unimi.dsi.fastutil.floats.FloatIterator;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
@@ -57,9 +58,9 @@ import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.Queue;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.UnaryOperator;
@@ -424,21 +425,21 @@ public final class ElytraBehavior implements Helper {
PathRenderer.drawGoal(event.getModelViewStack(), ctx, new GoalBlock(this.aimPos), event.getPartialTicks(), Color.GREEN);
}
if (!this.clearLines.isEmpty() && settings.elytraRenderRaytraces.value) {
BufferBuilder bufferBuilder = IRenderer.startLines(Color.GREEN, settings.pathRenderLineWidthPixels.value);
BufferBuilder bufferBuilder = IRenderer.startLines(Color.GREEN, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value);
for (Pair<Vec3, Vec3> line : this.clearLines) {
IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), line.first(), line.second());
}
IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value);
}
if (!this.blockedLines.isEmpty() && Baritone.settings().elytraRenderRaytraces.value) {
BufferBuilder bufferBuilder = IRenderer.startLines(Color.BLUE, settings.pathRenderLineWidthPixels.value);
BufferBuilder bufferBuilder = IRenderer.startLines(Color.BLUE, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value);
for (Pair<Vec3, Vec3> line : this.blockedLines) {
IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), line.first(), line.second());
}
IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value);
}
if (this.simulationLine != null && Baritone.settings().elytraRenderSimulation.value) {
BufferBuilder bufferBuilder = IRenderer.startLines(new Color(0x36CCDC), settings.pathRenderLineWidthPixels.value);
BufferBuilder bufferBuilder = IRenderer.startLines(new Color(0x36CCDC), settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value);
final Vec3 offset = ctx.player().getPosition(event.getPartialTicks());
for (int i = 0; i < this.simulationLine.size() - 1; i++) {
final Vec3 src = this.simulationLine.get(i).add(offset);
@@ -1288,7 +1289,7 @@ public final class ElytraBehavior implements Helper {
}
private int findGoodElytra() {
NonNullList<ItemStack> invy = ctx.player().getInventory().getNonEquipmentItems();
NonNullList<ItemStack> invy = ctx.player().getInventory().items;
for (int i = 0; i < invy.size(); i++) {
ItemStack slot = invy.get(i);
if (slot.getItem() == Items.ELYTRA && (slot.getMaxDamage() - slot.getDamageValue()) > Baritone.settings().elytraMinimumDurability.value) {

View File

@@ -30,7 +30,6 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.PaletteResize;
import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.phys.Vec3;
@@ -196,7 +195,7 @@ public final class NetherPathfinderContext {
continue;
}
final PalettedContainer<BlockState> bsc = extendedblockstorage.getStates();
final int airId = ((IPalettedContainer<BlockState>) bsc).getPalette().idFor(AIR_BLOCK_STATE, PaletteResize.noResizeExpected());
final int airId = ((IPalettedContainer<BlockState>) bsc).getPalette().idFor(AIR_BLOCK_STATE);
// pasted from FasterWorldScanner
final BitStorage array = ((IPalettedContainer<BlockState>) bsc).getStorage();
if (array == null) continue;

View File

@@ -29,7 +29,7 @@ public class SelectionRenderer implements IRenderer, AbstractGameEventListener {
return;
}
BufferBuilder bufferBuilder = IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth);
BufferBuilder bufferBuilder = IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth, ignoreDepth);
for (ISelection selection : selections) {
IRenderer.emitAABB(bufferBuilder, stack, selection.aabb(), SELECTION_BOX_EXPANSION);

View File

@@ -1,134 +0,0 @@
/*
* 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;
import com.mojang.blaze3d.buffers.GpuBuffer;
import com.mojang.blaze3d.buffers.GpuBufferSlice;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.systems.RenderPass;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.systems.ScissorState;
import com.mojang.blaze3d.textures.GpuTextureView;
import com.mojang.blaze3d.vertex.MeshData;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import org.joml.Vector3f;
import org.joml.Vector4f;
import java.util.OptionalDouble;
import java.util.OptionalInt;
public class BaritoneRenderType extends RenderType {
private final RenderPipeline renderPipeline;
public BaritoneRenderType(String name, int bufferSize, boolean affectsCrumbling, boolean sortOnUpload, RenderPipeline renderPipeline) {
super(name, bufferSize, affectsCrumbling, sortOnUpload, () -> {}, () -> {});
this.renderPipeline = renderPipeline;
}
public static BaritoneRenderType create(String name, int bufferSize, RenderPipeline renderPipeline) {
return new BaritoneRenderType(name, bufferSize, false, false, renderPipeline);
}
@Override
public VertexFormat format() {
return this.renderPipeline.getVertexFormat();
}
@Override
public VertexFormat.Mode mode() {
return this.renderPipeline.getVertexFormatMode();
}
@Override
public RenderPipeline pipeline() {
return this.renderPipeline;
}
@Override
public void draw(final MeshData meshData) {
this.setupRenderState();
try {
GpuBuffer vertexBuffer = this.renderPipeline.getVertexFormat().uploadImmediateVertexBuffer(meshData.vertexBuffer());
GpuBuffer indexBuffer;
VertexFormat.IndexType indexType;
if (meshData.indexBuffer() == null) {
RenderSystem.AutoStorageIndexBuffer autoStorageIndexBuffer = RenderSystem.getSequentialBuffer(meshData.drawState().mode());
indexBuffer = autoStorageIndexBuffer.getBuffer(meshData.drawState().indexCount());
indexType = autoStorageIndexBuffer.type();
} else {
indexBuffer = this.renderPipeline.getVertexFormat().uploadImmediateIndexBuffer(meshData.indexBuffer());
indexType = meshData.drawState().indexType();
}
RenderTarget renderTarget = RenderStateShard.MAIN_TARGET.getRenderTarget();
GpuTextureView colorTextureTarget = RenderSystem.outputColorTextureOverride != null
? RenderSystem.outputColorTextureOverride
: renderTarget.getColorTextureView();
GpuTextureView depthTextureTarget = renderTarget.useDepth
? (RenderSystem.outputDepthTextureOverride != null ? RenderSystem.outputDepthTextureOverride : renderTarget.getDepthTextureView())
: null;
GpuBufferSlice dynamicTransformsUbo = RenderSystem.getDynamicUniforms()
.writeTransform(
RenderSystem.getModelViewMatrix(),
new Vector4f(1.0F, 1.0F, 1.0F, 1.0F),
new Vector3f(),
RenderSystem.getTextureMatrix(),
RenderSystem.getShaderLineWidth()
);
try (RenderPass renderPass = RenderSystem.getDevice()
.createCommandEncoder()
.createRenderPass(() -> "Immediate draw for " + this.getName(), colorTextureTarget, OptionalInt.empty(), depthTextureTarget, OptionalDouble.empty())) {
renderPass.setPipeline(this.renderPipeline);
ScissorState scissorState = RenderSystem.getScissorStateForRenderTypeDraws();
if (scissorState.enabled()) {
renderPass.enableScissor(scissorState.x(), scissorState.y(), scissorState.width(), scissorState.height());
}
RenderSystem.bindDefaultUniforms(renderPass);
renderPass.setUniform("DynamicTransforms", dynamicTransformsUbo);
renderPass.setVertexBuffer(0, vertexBuffer);
for (int i = 0; i < 12; i++) {
GpuTextureView texture = RenderSystem.getShaderTexture(i);
if (texture != null) {
renderPass.bindSampler("Sampler" + i, texture);
}
}
renderPass.setIndexBuffer(indexBuffer, indexType);
renderPass.drawIndexed(0, 0, meshData.drawState().indexCount(), 1);
}
} catch (Throwable e) {
try {
meshData.close();
} catch (Throwable e2) {
e.addSuppressed(e2);
}
throw e;
}
meshData.close();
this.clearRenderState();
}
}

View File

@@ -27,12 +27,12 @@ import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.AABB;
@@ -85,16 +85,17 @@ public class GuiClick extends Screen implements Helper {
}
@Override
public boolean mouseReleased(MouseButtonEvent event) {
public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) {
if (currentMouseOver != null) { //Catch this, or else a click into void will result in a crash
if (event.button() == 0) {
if (mouseButton == 0) {
if (clickStart != null && !clickStart.equals(currentMouseOver)) {
BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().removeAllSelections();
BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().addSelection(BetterBlockPos.from(clickStart), BetterBlockPos.from(currentMouseOver));
MutableComponent component = Component.literal("Selection made! For usage: " + Baritone.settings().prefix.value + "help sel");
component.setStyle(component.getStyle()
.withColor(ChatFormatting.WHITE)
.withClickEvent(new ClickEvent.RunCommand(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + "help sel"
)));
Helper.HELPER.logDirect(component);
@@ -102,18 +103,18 @@ public class GuiClick extends Screen implements Helper {
} else {
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(currentMouseOver));
}
} else if (event.button() == 1) {
} else if (mouseButton == 1) {
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(currentMouseOver.above()));
}
}
clickStart = null;
return super.mouseReleased(event);
return super.mouseReleased(mouseX, mouseY, mouseButton);
}
@Override
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
clickStart = currentMouseOver;
return super.mouseClicked(event, doubleClick);
return super.mouseClicked(mouseX, mouseY, mouseButton);
}
public void onRender(PoseStack modelViewStack, Matrix4f projectionMatrix) {
@@ -126,7 +127,7 @@ public class GuiClick extends Screen implements Helper {
// drawSingleSelectionBox WHEN?
PathRenderer.drawManySelectionBoxes(modelViewStack, e, Collections.singletonList(currentMouseOver), Color.CYAN);
if (clickStart != null && !clickStart.equals(currentMouseOver)) {
BufferBuilder bufferBuilder = IRenderer.startLines(Color.RED, Baritone.settings().pathRenderLineWidthPixels.value);
BufferBuilder bufferBuilder = IRenderer.startLines(Color.RED, Baritone.settings().pathRenderLineWidthPixels.value, true);
BetterBlockPos a = new BetterBlockPos(currentMouseOver);
BetterBlockPos b = new BetterBlockPos(clickStart);
IRenderer.emitAABB(bufferBuilder, modelViewStack, new AABB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1));

View File

@@ -20,17 +20,15 @@ package baritone.utils;
import baritone.api.BaritoneAPI;
import baritone.api.Settings;
import baritone.utils.accessor.IEntityRenderManager;
import baritone.utils.accessor.IRenderPipelines;
import com.mojang.blaze3d.pipeline.BlendFunction;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.platform.DepthTestFunction;
import com.mojang.blaze3d.platform.DestFactor;
import com.mojang.blaze3d.platform.SourceFactor;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.client.renderer.CoreShaders;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.ShaderProgram;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
@@ -40,33 +38,8 @@ public interface IRenderer {
Tesselator tessellator = Tesselator.getInstance();
IEntityRenderManager renderManager = (IEntityRenderManager) Minecraft.getInstance().getEntityRenderDispatcher();
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
Settings settings = BaritoneAPI.getSettings();
RenderPipeline.Snippet BARITONE_LINES_SNIPPET = RenderPipeline.builder(((IRenderPipelines) new RenderPipelines()).getLinesSnippet())
.withBlend(new BlendFunction(
SourceFactor.SRC_ALPHA,
DestFactor.ONE_MINUS_SRC_ALPHA,
SourceFactor.ONE,
DestFactor.ZERO
))
.withDepthWrite(false)
.withCull(false)
.buildSnippet();
RenderType linesWithDepthRenderType = BaritoneRenderType.create(
"renderType/baritone_lines_with_depth",
256,
RenderPipeline.builder(BARITONE_LINES_SNIPPET)
.withLocation("pipelines/baritone_lines_with_depth")
.withDepthTestFunction(DepthTestFunction.LEQUAL_DEPTH_TEST)
.build()
);
RenderType linesNoDepthRenderType = BaritoneRenderType.create(
"renderType/baritone_lines_no_depth",
256,
RenderPipeline.builder(BARITONE_LINES_SNIPPET)
.withLocation("pipelines/baritone_lines_no_depth")
.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST)
.build()
);
float[] color = new float[]{1.0F, 1.0F, 1.0F, 255.0F};
@@ -78,25 +51,44 @@ public interface IRenderer {
IRenderer.color[3] = alpha;
}
static BufferBuilder startLines(Color color, float alpha, float lineWidth) {
static BufferBuilder startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) {
RenderSystem.enableBlend();
RenderSystem.setShader(CoreShaders.POSITION_COLOR);
RenderSystem.blendFuncSeparate(
GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
GlStateManager.SourceFactor.ONE,
GlStateManager.DestFactor.ZERO
);
glColor(color, alpha);
RenderSystem.lineWidth(lineWidth);
RenderSystem.depthMask(false);
RenderSystem.disableCull();
if (ignoreDepth) {
RenderSystem.disableDepthTest();
}
RenderSystem.setShader(CoreShaders.RENDERTYPE_LINES);
return tessellator.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
}
static BufferBuilder startLines(Color color, float lineWidth) {
return startLines(color, .4f, lineWidth);
static BufferBuilder startLines(Color color, float lineWidth, boolean ignoreDepth) {
return startLines(color, .4f, lineWidth, ignoreDepth);
}
static void endLines(BufferBuilder bufferBuilder, boolean ignoredDepth) {
MeshData meshData = bufferBuilder.build();
if (meshData != null) {
if (ignoredDepth) {
linesNoDepthRenderType.draw(meshData);
} else {
linesWithDepthRenderType.draw(meshData);
}
BufferUploader.drawWithShader(meshData);
}
if (ignoredDepth) {
RenderSystem.enableDepthTest();
}
RenderSystem.enableCull();
RenderSystem.depthMask(true);
RenderSystem.disableBlend();
}
static void emitLine(BufferBuilder bufferBuilder, PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {

View File

@@ -25,9 +25,12 @@ import baritone.api.utils.IPlayerContext;
import baritone.api.utils.interfaces.IGoalRenderPos;
import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.blockentity.BeaconRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.state.BlockState;
@@ -49,6 +52,9 @@ import java.util.List;
*/
public final class PathRenderer implements IRenderer {
private static final ResourceLocation TEXTURE_BEACON_BEAM = ResourceLocation.parse("textures/entity/beacon_beam.png");
private PathRenderer() {}
public static double posX() {
@@ -129,7 +135,7 @@ public final class PathRenderer implements IRenderer {
}
public static void drawPath(PoseStack stack, List<BetterBlockPos> positions, int startIndex, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0, double offset) {
BufferBuilder bufferBuilder = IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value);
BufferBuilder bufferBuilder = IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value);
int fadeStart = fadeStart0 + startIndex;
int fadeEnd = fadeEnd0 + startIndex;
@@ -198,7 +204,7 @@ public final class PathRenderer implements IRenderer {
}
public static void drawManySelectionBoxes(PoseStack stack, Entity player, Collection<BlockPos> positions, Color color) {
BufferBuilder bufferBuilder = IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value);
BufferBuilder bufferBuilder = IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value, settings.renderSelectionBoxesIgnoreDepth.value);
//BlockPos blockpos = movingObjectPositionIn.getBlockPos();
BlockStateInterface bsi = new BlockStateInterface(BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext()); // TODO this assumes same dimension between primary baritone and render view? is this safe?
@@ -260,13 +266,38 @@ public final class PathRenderer implements IRenderer {
maxY = ctx.world().getMaxY();
if (settings.renderGoalXZBeacon.value) {
// todo: fix beacon renderer (has been broken since at least 1.20.4)
// issue with outer beam rendering, probably related to matrix transforms state not matching vanilla
// possible solutions:
// inject hook into LevelRenderer#renderBlockEntities where the matrices have already been set up correctly
// copy out and modify the vanilla beacon render code
// also another issue on 1.21.5 is we don't have a simple method call for editing the beacon's depth test
// return;
//TODO: check
textureManager.getTexture(TEXTURE_BEACON_BEAM).bind();
if (settings.renderGoalIgnoreDepth.value) {
RenderSystem.disableDepthTest();
}
stack.pushPose(); // push
stack.translate(goalPos.getX() - renderPosX, -renderPosY, goalPos.getZ() - renderPosZ); // translate
//TODO: check
BeaconRenderer.renderBeaconBeam(
stack,
ctx.minecraft().renderBuffers().bufferSource(),
TEXTURE_BEACON_BEAM,
settings.renderGoalAnimated.value ? partialTicks : 0,
1.0F,
settings.renderGoalAnimated.value ? ctx.world().getGameTime() : 0,
(int) minY,
(int) maxY,
color.getRGB(),
// Arguments filled by the private method lol
0.2F,
0.25F
);
stack.popPose(); // pop
if (settings.renderGoalIgnoreDepth.value) {
RenderSystem.enableDepthTest();
}
return;
}
minX = goalPos.getX() + 0.002 - renderPosX;
@@ -284,7 +315,7 @@ public final class PathRenderer implements IRenderer {
boolean batch = Arrays.stream(((GoalComposite) goal).goals()).allMatch(IGoalRenderPos.class::isInstance);
BufferBuilder buf = bufferBuilder;
if (batch) {
buf = IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value);
buf = IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value);
}
for (Goal g : ((GoalComposite) goal).goals()) {
drawGoal(buf, stack, ctx, g, partialTicks, color, !batch);
@@ -310,7 +341,7 @@ public final class PathRenderer implements IRenderer {
private static void drawDankLitGoalBox(BufferBuilder bufferBuilder, PoseStack stack, Color colorIn, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) {
if (setupRender) {
bufferBuilder = IRenderer.startLines(colorIn, settings.goalRenderLineWidthPixels.value);
bufferBuilder = IRenderer.startLines(colorIn, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value);
}
renderHorizontalQuad(bufferBuilder, stack, minX, maxX, minZ, maxZ, y1);

View File

@@ -19,7 +19,6 @@ package baritone.utils;
import baritone.api.utils.input.Input;
import net.minecraft.client.player.ClientInput;
import net.minecraft.world.phys.Vec2;
public class PlayerMovementInput extends ClientInput {
@@ -31,36 +30,35 @@ public class PlayerMovementInput extends ClientInput {
@Override
public void tick() {
float leftImpulse = 0.0F;
float forwardImpulse = 0.0F;
this.leftImpulse = 0.0F;
this.forwardImpulse = 0.0F;
boolean jumping = handler.isInputForcedDown(Input.JUMP); // oppa gangnam style
boolean up = handler.isInputForcedDown(Input.MOVE_FORWARD);
if (up) {
forwardImpulse++;
this.forwardImpulse++;
}
boolean down = handler.isInputForcedDown(Input.MOVE_BACK);
if (down) {
forwardImpulse--;
this.forwardImpulse--;
}
boolean left = handler.isInputForcedDown(Input.MOVE_LEFT);
if (left) {
leftImpulse++;
this.leftImpulse++;
}
boolean right = handler.isInputForcedDown(Input.MOVE_RIGHT);
if (right) {
leftImpulse--;
this.leftImpulse--;
}
boolean sneaking = handler.isInputForcedDown(Input.SNEAK);
if (sneaking) {
leftImpulse *= 0.3D;
forwardImpulse *= 0.3D;
this.leftImpulse *= 0.3D;
this.forwardImpulse *= 0.3D;
}
this.moveVector = new Vec2(leftImpulse, forwardImpulse);
boolean sprinting = handler.isInputForcedDown(Input.SPRINT);

View File

@@ -20,13 +20,13 @@ package baritone.utils;
import baritone.Baritone;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
import net.minecraft.world.item.enchantment.Enchantments;
@@ -143,7 +143,7 @@ public class ToolSet {
possible, this lets us make pathing depend on the actual tool to be used (if auto tool is disabled)
*/
if (!Baritone.settings().autoTool.value && pathingCalculation) {
return player.getInventory().getSelectedSlot();
return player.getInventory().selected;
}
int best = 0;
@@ -153,7 +153,7 @@ public class ToolSet {
BlockState blockState = b.defaultBlockState();
for (int i = 0; i < 9; i++) {
ItemStack itemStack = player.getInventory().getItem(i);
if (!Baritone.settings().useSwordToMine.value && itemStack.getItem().components().has(DataComponents.WEAPON)) {
if (!Baritone.settings().useSwordToMine.value && itemStack.getItem() instanceof SwordItem) {
continue;
}
@@ -245,11 +245,11 @@ public class ToolSet {
*/
private double potionAmplifier() {
double speed = 1;
if (player.hasEffect(MobEffects.HASTE)) {
speed *= 1 + (player.getEffect(MobEffects.HASTE).getAmplifier() + 1) * 0.2;
if (player.hasEffect(MobEffects.DIG_SPEED)) {
speed *= 1 + (player.getEffect(MobEffects.DIG_SPEED).getAmplifier() + 1) * 0.2;
}
if (player.hasEffect(MobEffects.MINING_FATIGUE)) {
switch (player.getEffect(MobEffects.MINING_FATIGUE).getAmplifier()) {
if (player.hasEffect(MobEffects.DIG_SLOWDOWN)) {
switch (player.getEffect(MobEffects.DIG_SLOWDOWN).getAmplifier()) {
case 0:
speed *= 0.3;
break;

View File

@@ -1,24 +0,0 @@
/*
* 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;
import com.mojang.blaze3d.pipeline.RenderPipeline;
public interface IRenderPipelines {
RenderPipeline.Snippet getLinesSnippet();
}

View File

@@ -60,7 +60,7 @@ public enum DefaultSchematicFormats implements ISchematicFormat {
@Override
public IStaticSchematic parse(InputStream input) throws IOException {
CompoundTag nbt = NbtIo.readCompressed(input, NbtAccounter.unlimitedHeap());
int version = nbt.getInt("Version").orElse(-1);
int version = nbt.getInt("Version");
switch (version) {
case 1:
case 2:
@@ -78,7 +78,7 @@ public enum DefaultSchematicFormats implements ISchematicFormat {
@Override
public IStaticSchematic parse(InputStream input) throws IOException {
CompoundTag nbt = NbtIo.readCompressed(input, NbtAccounter.unlimitedHeap());
int version = nbt.getInt("Version").orElse(-1);
int version = nbt.getInt("Version");
switch (version) {
case 4: //1.12
case 5: //1.13-1.17

View File

@@ -58,13 +58,9 @@ public final class LitematicaSchematic extends CompositeSchematic implements ISt
* @return Array of subregion tags.
*/
private static CompoundTag[] getRegions(CompoundTag nbt) {
return nbt.getCompound("Regions")
.map(CompoundTag::values)
.map(r -> r.stream()
.filter(v -> v instanceof CompoundTag)
.map(CompoundTag.class::cast)
.toArray(CompoundTag[]::new)
).orElse(new CompoundTag[0]);
return nbt.getCompound("Regions").getAllKeys().stream()
.map(nbt.getCompound("Regions")::getCompound)
.toArray(CompoundTag[]::new);
}
/**
@@ -74,8 +70,8 @@ public final class LitematicaSchematic extends CompositeSchematic implements ISt
* @return the lower coord of the requested axis.
*/
private static int getMinOfSubregion(CompoundTag subReg, String s) {
int a = subReg.getCompound("Position").flatMap(position -> position.getInt(s)).orElse(0);
int b = subReg.getCompound("Size").flatMap(size -> size.getInt(s)).orElse(0);
int a = subReg.getCompound("Position").getInt(s);
int b = subReg.getCompound("Size").getInt(s);
return Math.min(a, a + b + 1);
}
@@ -88,13 +84,13 @@ public final class LitematicaSchematic extends CompositeSchematic implements ISt
for (int i = 0; i < blockStatePalette.size(); i++) {
CompoundTag tag = (CompoundTag) blockStatePalette.get(i);
ResourceLocation blockKey = ResourceLocation.tryParse(tag.getString("Name").orElse(""));
ResourceLocation blockKey = ResourceLocation.tryParse(tag.getString("Name"));
Block block = blockKey == null
? Blocks.AIR
: BuiltInRegistries.BLOCK.get(blockKey)
.map(Holder.Reference::value)
.orElse(Blocks.AIR);
CompoundTag properties = tag.getCompound("Properties").orElse(new CompoundTag());
CompoundTag properties = tag.getCompound("Properties");
blockList[i] = getBlockState(block, properties);
}
@@ -109,9 +105,9 @@ public final class LitematicaSchematic extends CompositeSchematic implements ISt
private static BlockState getBlockState(Block block, CompoundTag properties) {
BlockState blockState = block.defaultBlockState();
for (String key : properties.keySet()) {
Property<?> property = block.getStateDefinition().getProperty(key);
String propertyValue = properties.getString(key).orElse(null);
for (Object key : properties.getAllKeys()) {
Property<?> property = block.getStateDefinition().getProperty((String) key);
String propertyValue = properties.getString((String) key);
if (property != null) {
blockState = setPropertyValue(blockState, property, propertyValue);
}
@@ -146,8 +142,8 @@ public final class LitematicaSchematic extends CompositeSchematic implements ISt
* @return the volume of the subregion.
*/
private static long getVolume(CompoundTag subReg) {
CompoundTag size = subReg.getCompound("Size").orElse(new CompoundTag());
return Math.abs(size.getInt("x").orElse(0) * size.getInt("y").orElse(0) * size.getInt("z").orElse(0));
CompoundTag size = subReg.getCompound("Size");
return Math.abs(size.getInt("x") * size.getInt("y") * size.getInt("z"));
}
/**
@@ -168,12 +164,12 @@ public final class LitematicaSchematic extends CompositeSchematic implements ISt
private void fillInSchematic(CompoundTag nbt) {
Vec3i offsetMinCorner = new Vec3i(getMinOfSchematic(nbt, "x"), getMinOfSchematic(nbt, "y"), getMinOfSchematic(nbt, "z"));
for (CompoundTag subReg : getRegions(nbt)) {
ListTag usedBlockTypes = subReg.getListOrEmpty("BlockStatePalette");
ListTag usedBlockTypes = subReg.getList("BlockStatePalette", 10);
BlockState[] blockList = getBlockList(usedBlockTypes);
int bitsPerBlock = getBitsPerBlock(usedBlockTypes.size());
long regionVolume = getVolume(subReg);
long[] blockStateArray = subReg.getLongArray("BlockStates").orElse(new long[0]);
long[] blockStateArray = subReg.getLongArray("BlockStates");
LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray);
writeSubregionIntoSchematic(subReg, offsetMinCorner, blockList, bitArray);
@@ -190,10 +186,10 @@ public final class LitematicaSchematic extends CompositeSchematic implements ISt
int offsetX = getMinOfSubregion(subReg, "x") - offsetMinCorner.getX();
int offsetY = getMinOfSubregion(subReg, "y") - offsetMinCorner.getY();
int offsetZ = getMinOfSubregion(subReg, "z") - offsetMinCorner.getZ();
CompoundTag size = subReg.getCompound("Size").orElse(new CompoundTag());
int sizeX = Math.abs(size.getInt("x").orElse(0));
int sizeY = Math.abs(size.getInt("y").orElse(0));
int sizeZ = Math.abs(size.getInt("z").orElse(0));
CompoundTag size = subReg.getCompound("Size");
int sizeX = Math.abs(size.getInt("x"));
int sizeY = Math.abs(size.getInt("y"));
int sizeZ = Math.abs(size.getInt("z"));
BlockState[][][] states = new BlockState[sizeX][sizeZ][sizeY];
int index = 0;
for (int y = 0; y < sizeY; y++) {

View File

@@ -19,6 +19,7 @@ package baritone.utils.schematic.format.defaults;
import baritone.utils.schematic.StaticSchematic;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
@@ -34,19 +35,19 @@ import net.minecraft.world.level.block.state.BlockState;
public final class MCEditSchematic extends StaticSchematic {
public MCEditSchematic(CompoundTag schematic) {
String type = schematic.getString("Materials").orElseThrow();
String type = schematic.getString("Materials");
if (!type.equals("Alpha")) {
throw new IllegalStateException("bad schematic " + type);
}
this.x = schematic.getInt("Width").orElse(0);
this.y = schematic.getInt("Height").orElse(0);
this.z = schematic.getInt("Length").orElse(0);
byte[] blocks = schematic.getByteArray("Blocks").orElseThrow();
this.x = schematic.getInt("Width");
this.y = schematic.getInt("Height");
this.z = schematic.getInt("Length");
byte[] blocks = schematic.getByteArray("Blocks");
// byte[] metadata = schematic.getByteArray("Data");
byte[] additional = null;
if (schematic.contains("AddBlocks")) {
byte[] addBlocks = schematic.getByteArray("AddBlocks").orElseThrow();
byte[] addBlocks = schematic.getByteArray("AddBlocks");
additional = new byte[addBlocks.length * 2];
for (int i = 0; i < addBlocks.length; i++) {
additional[i * 2 + 0] = (byte) ((addBlocks[i] >> 4) & 0xF); // lower nibble

View File

@@ -20,7 +20,14 @@ package baritone.utils.schematic.format.defaults;
import baritone.utils.schematic.StaticSchematic;
import baritone.utils.type.VarInt;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
@@ -29,12 +36,6 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Brady
* @since 12/27/2019
@@ -42,15 +43,15 @@ import java.util.regex.Pattern;
public final class SpongeSchematic extends StaticSchematic {
public SpongeSchematic(CompoundTag nbt) {
this.x = nbt.getInt("Width").orElse(0);
this.y = nbt.getInt("Height").orElse(0);
this.z = nbt.getInt("Length").orElse(0);
this.x = nbt.getInt("Width");
this.y = nbt.getInt("Height");
this.z = nbt.getInt("Length");
this.states = new BlockState[this.x][this.z][this.y];
Int2ObjectArrayMap<BlockState> palette = new Int2ObjectArrayMap<>();
CompoundTag paletteTag = nbt.getCompound("Palette").orElse(new CompoundTag());
for (String tag : paletteTag.keySet()) {
int index = paletteTag.getInt(tag).orElse(0);
CompoundTag paletteTag = nbt.getCompound("Palette");
for (String tag : paletteTag.getAllKeys()) {
int index = paletteTag.getInt(tag);
SerializedBlockState serializedState = SerializedBlockState.getFromString(tag);
if (serializedState == null) {
@@ -66,7 +67,7 @@ public final class SpongeSchematic extends StaticSchematic {
}
// BlockData is stored as an NBT byte[], however, the actual data that is represented is a varint[]
byte[] rawBlockData = nbt.getByteArray("BlockData").orElseThrow();
byte[] rawBlockData = nbt.getByteArray("BlockData");
int[] blockData = new int[this.x * this.y * this.z];
int offset = 0;
for (int i = 0; i < blockData.length; i++) {