migrate to mojmap

This commit is contained in:
wagyourtail 2021-06-23 11:24:32 -06:00
parent f0130c7199
commit e6d8b268c7
No known key found for this signature in database
GPG Key ID: E6E3EB7DCD4EB017
159 changed files with 1453 additions and 1447 deletions

View File

@ -21,10 +21,9 @@ import baritone.api.cache.IWorldScanner;
import baritone.api.command.ICommand;
import baritone.api.command.ICommandSystem;
import baritone.api.schematic.ISchematicSystem;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import java.util.List;
import java.util.Objects;
import net.minecraft.client.player.LocalPlayer;
/**
* Provides the present {@link IBaritone} instances, as well as non-baritone instance related APIs.
@ -47,19 +46,19 @@ public interface IBaritoneProvider {
* returned by {@link #getPrimaryBaritone()}.
*
* @return All active {@link IBaritone} instances.
* @see #getBaritoneForPlayer(ClientPlayerEntity)
* @see #getBaritoneForPlayer(LocalPlayer)
*/
List<IBaritone> getAllBaritones();
/**
* Provides the {@link IBaritone} instance for a given {@link ClientPlayerEntity}. This will likely be
* Provides the {@link IBaritone} instance for a given {@link LocalPlayer}. This will likely be
* replaced with or be overloaded in addition to {@code #getBaritoneForUser(IBaritoneUser)} when
* {@code bot-system} is merged into {@code master}.
*
* @param player The player
* @return The {@link IBaritone} instance.
*/
default IBaritone getBaritoneForPlayer(ClientPlayerEntity player) {
default IBaritone getBaritoneForPlayer(LocalPlayer player) {
for (IBaritone baritone : getAllBaritones()) {
if (Objects.equals(player, baritone.getPlayerContext().player())) {
return baritone;

View File

@ -19,18 +19,16 @@ package baritone.api;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.TypeUtils;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.util.math.vector.Vector3i;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.core.Vec3i;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import java.awt.*;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.*;
import java.util.function.Consumer;
@ -824,7 +822,7 @@ public final class Settings {
/**
* How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely
*/
public final Setting<Vector3i> buildRepeat = new Setting<>(new Vector3i(0, 0, 0));
public final Setting<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0));
/**
* How many times to buildrepeat. -1 for infinite.
@ -1023,7 +1021,7 @@ public final class Settings {
* via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting
* {@link Setting#value};
*/
public final Setting<Consumer<ITextComponent>> logger = new Setting<>(Minecraft.getInstance().ingameGUI.getChatGUI()::printChatMessage);
public final Setting<Consumer<Component>> logger = new Setting<>(Minecraft.getInstance().gui.getChat()::addMessage);
/**
* Print out ALL command exceptions as a stack trace to stdout, even simple syntax errors

View File

@ -17,8 +17,8 @@
package baritone.api.cache;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
/**
* @author Brady

View File

@ -17,10 +17,9 @@
package baritone.api.cache;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.Chunk;
import java.util.ArrayList;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.chunk.LevelChunk;
/**
* @author Brady
@ -44,7 +43,7 @@ public interface ICachedWorld {
*
* @param chunk The chunk to pack and store
*/
void queueForPacking(Chunk chunk);
void queueForPacking(LevelChunk chunk);
/**
* Returns whether or not the block at the specified X and Z coordinates

View File

@ -17,9 +17,8 @@
package baritone.api.cache;
import net.minecraft.util.math.BlockPos;
import java.util.Map;
import net.minecraft.core.BlockPos;
/**
* @author Brady

View File

@ -17,9 +17,8 @@
package baritone.api.cache;
import net.minecraft.item.ItemStack;
import java.util.List;
import net.minecraft.world.item.ItemStack;
/**
* @author Brady

View File

@ -19,11 +19,10 @@ package baritone.api.cache;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.api.utils.IPlayerContext;
import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import java.util.List;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.Block;
/**
* @author Brady

View File

@ -27,11 +27,10 @@ import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.exception.CommandNotEnoughArgumentsException;
import baritone.api.command.exception.CommandTooManyArgumentsException;
import baritone.api.utils.Helper;
import net.minecraft.util.Direction;
import java.util.Deque;
import java.util.LinkedList;
import java.util.stream.Stream;
import net.minecraft.core.Direction;
/**
* The {@link IArgConsumer} is how {@link ICommand}s read the arguments passed to them. This class has many benefits:

View File

@ -19,7 +19,7 @@ package baritone.api.command.argument;
import baritone.api.command.argparser.IArgParser;
import baritone.api.command.exception.CommandInvalidTypeException;
import net.minecraft.util.Direction;
import net.minecraft.core.Direction;
/**
* A {@link ICommandArgument} is an immutable object representing one command argument. It contains data on the index of

View File

@ -19,11 +19,10 @@ package baritone.api.command.datatypes;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.block.Block;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import java.util.stream.Stream;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
public enum BlockById implements IDatatypeFor<Block> {
INSTANCE;

View File

@ -19,11 +19,10 @@ package baritone.api.command.datatypes;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import java.util.stream.Stream;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
public enum EntityClassById implements IDatatypeFor<EntityType> {
INSTANCE;

View File

@ -19,10 +19,9 @@ package baritone.api.command.datatypes;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.util.Direction;
import java.util.Locale;
import java.util.stream.Stream;
import net.minecraft.core.Direction;
public enum ForDirection implements IDatatypeFor<Direction> {
INSTANCE;
@ -36,7 +35,7 @@ public enum ForDirection implements IDatatypeFor<Direction> {
public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException {
return new TabCompleteHelper()
.append(Stream.of(Direction.values())
.map(Direction::getName2).map(String::toLowerCase))
.map(Direction::getName).map(String::toLowerCase))
.filterPrefix(ctx.getConsumer().getString())
.stream();
}

View File

@ -20,21 +20,20 @@ package baritone.api.command.datatypes;
import baritone.api.IBaritone;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.text.ITextComponent;
import java.util.List;
import java.util.stream.Stream;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
/**
* An {@link IDatatype} used to resolve nearby players, those within
* render distance of the target {@link IBaritone} instance.
*/
public enum NearbyPlayer implements IDatatypeFor<PlayerEntity> {
public enum NearbyPlayer implements IDatatypeFor<Player> {
INSTANCE;
@Override
public PlayerEntity get(IDatatypeContext ctx) throws CommandException {
public Player get(IDatatypeContext ctx) throws CommandException {
final String username = ctx.getConsumer().getString();
return getPlayers(ctx).stream()
.filter(s -> s.getName().getString().equalsIgnoreCase(username))
@ -44,13 +43,13 @@ public enum NearbyPlayer implements IDatatypeFor<PlayerEntity> {
@Override
public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException {
return new TabCompleteHelper()
.append(getPlayers(ctx).stream().map(PlayerEntity::getName).map(ITextComponent::getString))
.append(getPlayers(ctx).stream().map(Player::getName).map(Component::getString))
.filterPrefix(ctx.getConsumer().getString())
.sortAlphabetically()
.stream();
}
private static List<? extends PlayerEntity> getPlayers(IDatatypeContext ctx) {
return ctx.getBaritone().getPlayerContext().world().getPlayers();
private static List<? extends Player> getPlayers(IDatatypeContext ctx) {
return ctx.getBaritone().getPlayerContext().world().players();
}
}

View File

@ -94,7 +94,7 @@ public enum RelativeFile implements IDatatypePost<File, File> {
}
public static File gameDir() {
File gameDir = HELPER.mc.gameDir.getAbsoluteFile();
File gameDir = HELPER.mc.gameDirectory.getAbsoluteFile();
if (gameDir.getName().equals(".")) {
return gameDir.getParentFile();
}

View File

@ -21,9 +21,8 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.util.math.MathHelper;
import java.util.stream.Stream;
import net.minecraft.util.Mth;
public enum RelativeGoalBlock implements IDatatypePost<GoalBlock, BetterBlockPos> {
INSTANCE;
@ -36,9 +35,9 @@ public enum RelativeGoalBlock implements IDatatypePost<GoalBlock, BetterBlockPos
final IArgConsumer consumer = ctx.getConsumer();
return new GoalBlock(
MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.x)),
MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.y)),
MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.z))
Mth.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.x)),
Mth.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.y)),
Mth.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.z))
);
}

View File

@ -21,9 +21,8 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.util.math.MathHelper;
import java.util.stream.Stream;
import net.minecraft.util.Mth;
public enum RelativeGoalXZ implements IDatatypePost<GoalXZ, BetterBlockPos> {
INSTANCE;
@ -36,8 +35,8 @@ public enum RelativeGoalXZ implements IDatatypePost<GoalXZ, BetterBlockPos> {
final IArgConsumer consumer = ctx.getConsumer();
return new GoalXZ(
MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.x)),
MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.z))
Mth.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.x)),
Mth.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.z))
);
}

View File

@ -21,9 +21,8 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.pathing.goals.GoalYLevel;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.util.math.MathHelper;
import java.util.stream.Stream;
import net.minecraft.util.Mth;
public enum RelativeGoalYLevel implements IDatatypePost<GoalYLevel, BetterBlockPos> {
INSTANCE;
@ -35,7 +34,7 @@ public enum RelativeGoalYLevel implements IDatatypePost<GoalYLevel, BetterBlockP
}
return new GoalYLevel(
MathHelper.floor(ctx.getConsumer().getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.y))
Mth.floor(ctx.getConsumer().getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.y))
);
}

View File

@ -19,9 +19,8 @@ package baritone.api.command.exception;
import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting;
import java.util.List;
import net.minecraft.ChatFormatting;
import static baritone.api.utils.Helper.HELPER;
@ -39,7 +38,7 @@ public class CommandUnhandledException extends RuntimeException implements IComm
public void handle(ICommand command, List<ICommandArgument> args) {
HELPER.logDirect("An unhandled exception occurred. " +
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
TextFormatting.RED);
ChatFormatting.RED);
this.printStackTrace();
}

View File

@ -19,9 +19,8 @@ package baritone.api.command.exception;
import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting;
import java.util.List;
import net.minecraft.ChatFormatting;
import static baritone.api.utils.Helper.HELPER;
@ -50,6 +49,6 @@ public interface ICommandException {
* @param args The arguments the command was called with.
*/
default void handle(ICommand command, List<ICommandArgument> args) {
HELPER.logDirect(this.getMessage(), TextFormatting.RED);
HELPER.logDirect(this.getMessage(), ChatFormatting.RED);
}
}

View File

@ -21,16 +21,15 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.utils.Helper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.TextComponent;
public class Paginator<E> implements Helper {
@ -64,59 +63,59 @@ public class Paginator<E> implements Helper {
return this;
}
public void display(Function<E, ITextComponent> transform, String commandPrefix) {
public void display(Function<E, Component> transform, String commandPrefix) {
int offset = (page - 1) * pageSize;
for (int i = offset; i < offset + pageSize; i++) {
if (i < entries.size()) {
logDirect(transform.apply(entries.get(i)));
} else {
logDirect("--", TextFormatting.DARK_GRAY);
logDirect("--", ChatFormatting.DARK_GRAY);
}
}
boolean hasPrevPage = commandPrefix != null && validPage(page - 1);
boolean hasNextPage = commandPrefix != null && validPage(page + 1);
TextComponent prevPageComponent = new StringTextComponent("<<");
BaseComponent prevPageComponent = new TextComponent("<<");
if (hasPrevPage) {
prevPageComponent.setStyle(prevPageComponent.getStyle()
.setClickEvent(new ClickEvent(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format("%s %d", commandPrefix, page - 1)
))
.setHoverEvent(new HoverEvent(
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new StringTextComponent("Click to view previous page")
new TextComponent("Click to view previous page")
)));
} else {
prevPageComponent.setStyle(prevPageComponent.getStyle().setFormatting(TextFormatting.DARK_GRAY));
prevPageComponent.setStyle(prevPageComponent.getStyle().withColor(ChatFormatting.DARK_GRAY));
}
TextComponent nextPageComponent = new StringTextComponent(">>");
BaseComponent nextPageComponent = new TextComponent(">>");
if (hasNextPage) {
nextPageComponent.setStyle(nextPageComponent.getStyle()
.setClickEvent(new ClickEvent(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format("%s %d", commandPrefix, page + 1)
))
.setHoverEvent(new HoverEvent(
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new StringTextComponent("Click to view next page")
new TextComponent("Click to view next page")
)));
} else {
nextPageComponent.setStyle(nextPageComponent.getStyle().setFormatting(TextFormatting.DARK_GRAY));
nextPageComponent.setStyle(nextPageComponent.getStyle().withColor(ChatFormatting.DARK_GRAY));
}
TextComponent pagerComponent = new StringTextComponent("");
pagerComponent.setStyle(pagerComponent.getStyle().setFormatting(TextFormatting.GRAY));
BaseComponent pagerComponent = new TextComponent("");
pagerComponent.setStyle(pagerComponent.getStyle().withColor(ChatFormatting.GRAY));
pagerComponent.append(prevPageComponent);
pagerComponent.appendString(" | ");
pagerComponent.append(" | ");
pagerComponent.append(nextPageComponent);
pagerComponent.appendString(String.format(" %d/%d", page, getMaxPage()));
pagerComponent.append(String.format(" %d/%d", page, getMaxPage()));
logDirect(pagerComponent);
}
public void display(Function<E, ITextComponent> transform) {
public void display(Function<E, Component> transform) {
display(transform, null);
}
public static <T> void paginate(IArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, Component> transform, String commandPrefix) throws CommandException {
int page = 1;
consumer.requireMax(1);
if (consumer.hasAny()) {
@ -139,47 +138,47 @@ public class Paginator<E> implements Helper {
pagi.display(transform, commandPrefix);
}
public static <T> void paginate(IArgConsumer consumer, List<T> elems, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, List<T> elems, Runnable pre, Function<T, Component> transform, String commandPrefix) throws CommandException {
paginate(consumer, new Paginator<>(elems), pre, transform, commandPrefix);
}
public static <T> void paginate(IArgConsumer consumer, T[] elems, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, T[] elems, Runnable pre, Function<T, Component> transform, String commandPrefix) throws CommandException {
paginate(consumer, Arrays.asList(elems), pre, transform, commandPrefix);
}
public static <T> void paginate(IArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, Paginator<T> pagi, Function<T, Component> transform, String commandPrefix) throws CommandException {
paginate(consumer, pagi, null, transform, commandPrefix);
}
public static <T> void paginate(IArgConsumer consumer, List<T> elems, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, List<T> elems, Function<T, Component> transform, String commandPrefix) throws CommandException {
paginate(consumer, new Paginator<>(elems), null, transform, commandPrefix);
}
public static <T> void paginate(IArgConsumer consumer, T[] elems, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, T[] elems, Function<T, Component> transform, String commandPrefix) throws CommandException {
paginate(consumer, Arrays.asList(elems), null, transform, commandPrefix);
}
public static <T> void paginate(IArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, Component> transform) throws CommandException {
paginate(consumer, pagi, pre, transform, null);
}
public static <T> void paginate(IArgConsumer consumer, List<T> elems, Runnable pre, Function<T, ITextComponent> transform) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, List<T> elems, Runnable pre, Function<T, Component> transform) throws CommandException {
paginate(consumer, new Paginator<>(elems), pre, transform, null);
}
public static <T> void paginate(IArgConsumer consumer, T[] elems, Runnable pre, Function<T, ITextComponent> transform) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, T[] elems, Runnable pre, Function<T, Component> transform) throws CommandException {
paginate(consumer, Arrays.asList(elems), pre, transform, null);
}
public static <T> void paginate(IArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, Paginator<T> pagi, Function<T, Component> transform) throws CommandException {
paginate(consumer, pagi, null, transform, null);
}
public static <T> void paginate(IArgConsumer consumer, List<T> elems, Function<T, ITextComponent> transform) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, List<T> elems, Function<T, Component> transform) throws CommandException {
paginate(consumer, new Paginator<>(elems), null, transform, null);
}
public static <T> void paginate(IArgConsumer consumer, T[] elems, Function<T, ITextComponent> transform) throws CommandException {
public static <T> void paginate(IArgConsumer consumer, T[] elems, Function<T, Component> transform) throws CommandException {
paginate(consumer, Arrays.asList(elems), null, transform, null);
}
}

View File

@ -23,14 +23,13 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.manager.ICommandManager;
import baritone.api.event.events.TabCompleteEvent;
import baritone.api.utils.SettingsUtil;
import net.minecraft.util.ResourceLocation;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import net.minecraft.resources.ResourceLocation;
/**
* The {@link TabCompleteHelper} is a <b>single-use</b> object that helps you handle tab completion. It includes helper

View File

@ -17,7 +17,7 @@
package baritone.api.event.events;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
/**
* Called when the local player interacts with a block, can be either {@link Type#START_BREAK} or {@link Type#USE}.

View File

@ -18,8 +18,8 @@
package baritone.api.event.events;
import baritone.api.event.events.type.EventState;
import net.minecraft.network.IPacket;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.Packet;
/**
* @author Brady
@ -27,19 +27,19 @@ import net.minecraft.network.NetworkManager;
*/
public final class PacketEvent {
private final NetworkManager networkManager;
private final Connection networkManager;
private final EventState state;
private final IPacket<?> packet;
private final Packet<?> packet;
public PacketEvent(NetworkManager networkManager, EventState state, IPacket<?> packet) {
public PacketEvent(Connection networkManager, EventState state, Packet<?> packet) {
this.networkManager = networkManager;
this.state = state;
this.packet = packet;
}
public final NetworkManager getNetworkManager() {
public final Connection getNetworkManager() {
return this.networkManager;
}
@ -47,12 +47,12 @@ public final class PacketEvent {
return this.state;
}
public final IPacket<?> getPacket() {
public final Packet<?> getPacket() {
return this.packet;
}
@SuppressWarnings("unchecked")
public final <T extends IPacket<?>> T cast() {
public final <T extends Packet<?>> T cast() {
return (T) this.packet;
}
}

View File

@ -17,8 +17,8 @@
package baritone.api.event.events;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.util.math.vector.Matrix4f;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
/**
* @author Brady
@ -32,9 +32,9 @@ public final class RenderEvent {
private final float partialTicks;
private final Matrix4f projectionMatrix;
private final MatrixStack modelViewStack;
private final PoseStack modelViewStack;
public RenderEvent(float partialTicks, MatrixStack modelViewStack, Matrix4f projectionMatrix) {
public RenderEvent(float partialTicks, PoseStack modelViewStack, Matrix4f projectionMatrix) {
this.partialTicks = partialTicks;
this.modelViewStack = modelViewStack;
this.projectionMatrix = projectionMatrix;
@ -47,7 +47,7 @@ public final class RenderEvent {
return this.partialTicks;
}
public MatrixStack getModelViewStack() {
public PoseStack getModelViewStack() {
return this.modelViewStack;
}

View File

@ -17,9 +17,9 @@
package baritone.api.event.events;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
/**
* @author Brady
@ -70,7 +70,7 @@ public final class RotationMoveEvent {
/**
* Called when the player's motion is updated.
*
* @see Entity#moveRelative(float, Vector3d)
* @see Entity#moveRelative(float, Vec3)
*/
MOTION_UPDATE,

View File

@ -18,7 +18,7 @@
package baritone.api.event.events;
import baritone.api.event.events.type.EventState;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.multiplayer.ClientLevel;
/**
* @author Brady
@ -29,14 +29,14 @@ public final class WorldEvent {
/**
* The new world that is being loaded. {@code null} if being unloaded.
*/
private final ClientWorld world;
private final ClientLevel world;
/**
* The state of the event
*/
private final EventState state;
public WorldEvent(ClientWorld world, EventState state) {
public WorldEvent(ClientLevel world, EventState state) {
this.world = world;
this.state = state;
}
@ -44,7 +44,7 @@ public final class WorldEvent {
/**
* @return The new world that is being loaded. {@code null} if being unloaded.
*/
public final ClientWorld getWorld() {
public final ClientLevel getWorld() {
return this.world;
}

View File

@ -19,12 +19,12 @@ package baritone.api.event.listener;
import baritone.api.event.events.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.DeathScreen;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.network.IPacket;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.client.gui.screens.DeathScreen;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.protocol.Packet;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
/**
* @author Brady
@ -36,7 +36,7 @@ public interface IGameEventListener {
* Run once per game tick before screen input is handled.
*
* @param event The event
* @see Minecraft#runTick()
* @see Minecraft#tick()
*/
void onTick(TickEvent event);
@ -44,7 +44,7 @@ public interface IGameEventListener {
* Run once per game tick from before and after the player rotation is sent to the server.
*
* @param event The event
* @see ClientPlayerEntity#tick()
* @see LocalPlayer#tick()
*/
void onPlayerUpdate(PlayerUpdateEvent event);
@ -52,7 +52,7 @@ public interface IGameEventListener {
* Runs whenever the client player sends a message to the server.
*
* @param event The event
* @see ClientPlayerEntity#sendChatMessage(String)
* @see LocalPlayer#chat(String)
*/
void onSendChatMessage(ChatEvent event);
@ -81,7 +81,7 @@ public interface IGameEventListener {
* Runs before and after whenever a new world is loaded
*
* @param event The event
* @see Minecraft#loadWorld(ClientWorld)
* @see Minecraft#setLevel(ClientLevel)
*/
void onWorldEvent(WorldEvent event);
@ -89,7 +89,7 @@ public interface IGameEventListener {
* Runs before a outbound packet is sent
*
* @param event The event
* @see IPacket
* @see Packet
*/
void onSendPacket(PacketEvent event);
@ -97,7 +97,7 @@ public interface IGameEventListener {
* Runs before an inbound packet is processed
*
* @param event The event
* @see IPacket
* @see Packet
*/
void onReceivePacket(PacketEvent event);
@ -106,15 +106,15 @@ public interface IGameEventListener {
* and before and after the player jumps.
*
* @param event The event
* @see Entity#moveRelative(float, Vector3d)
* @see Entity#moveRelative(float, Vec3)
*/
void onPlayerRotationMove(RotationMoveEvent event);
/**
* Called whenever the sprint keybind state is checked in {@link ClientPlayerEntity#livingTick}
* Called whenever the sprint keybind state is checked in {@link LocalPlayer#aiStep}
*
* @param event The event
* @see ClientPlayerEntity#livingTick()
* @see LocalPlayer#aiStep()
*/
void onPlayerSprintState(SprintStateEvent event);

View File

@ -17,7 +17,7 @@
package baritone.api.pathing.goals;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
/**
* An abstract Goal for pathing, can be anything from a specific block to just a Y coordinate.

View File

@ -19,7 +19,7 @@ package baritone.api.pathing.goals;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.interfaces.IGoalRenderPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
/**
* A specific BlockPos goal

View File

@ -19,7 +19,7 @@ package baritone.api.pathing.goals;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.interfaces.IGoalRenderPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
/**

View File

@ -19,7 +19,7 @@ package baritone.api.pathing.goals;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.interfaces.IGoalRenderPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
public class GoalNear implements Goal, IGoalRenderPos {

View File

@ -18,9 +18,8 @@
package baritone.api.pathing.goals;
import baritone.api.utils.SettingsUtil;
import net.minecraft.util.math.BlockPos;
import java.util.Arrays;
import net.minecraft.core.BlockPos;
/**
* Useful for automated combat (retreating specifically)

View File

@ -18,8 +18,8 @@
package baritone.api.pathing.goals;
import baritone.api.utils.SettingsUtil;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
/**
* Dig a tunnel in a certain direction, but if you have to deviate from the path, go back to where you started
@ -36,8 +36,8 @@ public class GoalStrictDirection implements Goal {
x = origin.getX();
y = origin.getY();
z = origin.getZ();
dx = direction.getXOffset();
dz = direction.getZOffset();
dx = direction.getStepX();
dz = direction.getStepZ();
if (dx == 0 && dz == 0) {
throw new IllegalArgumentException(direction + "");
}

View File

@ -19,7 +19,7 @@ package baritone.api.pathing.goals;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.interfaces.IGoalRenderPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
/**
* Useful if the goal is just to mine a block. This goal will be satisfied if the specified

View File

@ -20,8 +20,8 @@ package baritone.api.pathing.goals;
import baritone.api.BaritoneAPI;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.SettingsUtil;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
/**
* Useful for long-range goals that don't have a specific Y level.
@ -94,11 +94,11 @@ public class GoalXZ implements Goal {
return (diagonal + straight) * BaritoneAPI.getSettings().costHeuristic.value; // big TODO tune
}
public static GoalXZ fromDirection(Vector3d origin, float yaw, double distance) {
public static GoalXZ fromDirection(Vec3 origin, float yaw, double distance) {
float theta = (float) Math.toRadians(yaw);
double x = origin.x - MathHelper.sin(theta) * distance;
double z = origin.z + MathHelper.cos(theta) * distance;
return new GoalXZ(MathHelper.floor(x), MathHelper.floor(z));
double x = origin.x - Mth.sin(theta) * distance;
double z = origin.z + Mth.cos(theta) * distance;
return new GoalXZ(Mth.floor(x), Mth.floor(z));
}
public int getX() {

View File

@ -18,7 +18,7 @@
package baritone.api.pathing.movement;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
/**
* @author Brady

View File

@ -18,11 +18,10 @@
package baritone.api.process;
import baritone.api.schematic.ISchematic;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3i;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.world.level.block.state.BlockState;
import java.io.File;
import java.util.List;
@ -39,7 +38,7 @@ public interface IBuilderProcess extends IBaritoneProcess {
* @param schematic The object representation of the schematic
* @param origin The origin position of the schematic being built
*/
void build(String name, ISchematic schematic, Vector3i origin);
void build(String name, ISchematic schematic, Vec3i origin);
/**
* Requests a build for the specified schematic, labeled as specified, with the specified origin.
@ -49,10 +48,10 @@ public interface IBuilderProcess extends IBaritoneProcess {
* @param origin The origin position of the schematic being built
* @return Whether or not the schematic was able to load from file
*/
boolean build(String name, File schematic, Vector3i origin);
boolean build(String name, File schematic, Vec3i origin);
default boolean build(String schematicFile, BlockPos origin) {
File file = new File(new File(Minecraft.getInstance().gameDir, "schematics"), schematicFile);
File file = new File(new File(Minecraft.getInstance().gameDirectory, "schematics"), schematicFile);
return build(schematicFile, file, origin);
}

View File

@ -17,7 +17,7 @@
package baritone.api.process;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
public interface IFarmProcess extends IBaritoneProcess {

View File

@ -17,10 +17,9 @@
package baritone.api.process;
import net.minecraft.entity.Entity;
import java.util.List;
import java.util.function.Predicate;
import net.minecraft.world.entity.Entity;
/**
* @author Brady

View File

@ -18,7 +18,7 @@
package baritone.api.process;
import baritone.api.utils.BlockOptionalMeta;
import net.minecraft.block.Block;
import net.minecraft.world.level.block.Block;
/**
* but it rescans the world every once in a while so it doesn't get fooled by its cache

View File

@ -19,9 +19,8 @@ package baritone.api.process;
import baritone.api.utils.BlockOptionalMeta;
import baritone.api.utils.BlockOptionalMetaLookup;
import net.minecraft.block.Block;
import java.util.stream.Stream;
import net.minecraft.world.level.block.Block;
/**
* @author Brady

View File

@ -17,10 +17,9 @@
package baritone.api.schematic;
import net.minecraft.block.BlockState;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.level.block.state.BlockState;
public class CompositeSchematic extends AbstractSchematic {

View File

@ -18,10 +18,9 @@
package baritone.api.schematic;
import baritone.api.utils.BlockOptionalMeta;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import java.util.List;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
public class FillSchematic extends AbstractSchematic {
@ -45,7 +44,7 @@ public class FillSchematic extends AbstractSchematic {
if (bom.matches(current)) {
return current;
} else if (current.getBlock() != Blocks.AIR) {
return Blocks.AIR.getDefaultState();
return Blocks.AIR.defaultBlockState();
}
for (BlockState placeable : approxPlaceable) {
if (bom.matches(placeable)) {

View File

@ -17,10 +17,9 @@
package baritone.api.schematic;
import net.minecraft.block.BlockState;
import net.minecraft.util.Direction;
import java.util.List;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
/**
* Basic representation of a schematic. Provides the dimensions and the desired state for a given position relative to

View File

@ -17,7 +17,7 @@
package baritone.api.schematic;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.state.BlockState;
/**
* A static schematic is capable of providing the desired state at a given position without

View File

@ -17,9 +17,8 @@
package baritone.api.schematic;
import net.minecraft.block.BlockState;
import java.util.List;
import net.minecraft.world.level.block.state.BlockState;
public abstract class MaskSchematic extends AbstractSchematic {

View File

@ -18,7 +18,7 @@
package baritone.api.schematic;
import baritone.api.utils.BlockOptionalMetaLookup;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.state.BlockState;
public class ReplaceSchematic extends MaskSchematic {

View File

@ -17,7 +17,7 @@
package baritone.api.schematic;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.state.BlockState;
public class ShellSchematic extends MaskSchematic {

View File

@ -17,7 +17,7 @@
package baritone.api.schematic;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.state.BlockState;
public class WallsSchematic extends MaskSchematic {

View File

@ -18,9 +18,9 @@
package baritone.api.selection;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.vector.Vector3i;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.world.phys.AABB;
/**
* A selection is an immutable object representing the current selection. The selection is commonly used for certain
@ -51,12 +51,12 @@ public interface ISelection {
/**
* @return The size of this ISelection.
*/
Vector3i size();
Vec3i size();
/**
* @return An {@link AxisAlignedBB} encompassing all blocks in this selection.
* @return An {@link AABB} encompassing all blocks in this selection.
*/
AxisAlignedBB aabb();
AABB aabb();
/**
* Returns a new {@link ISelection} expanded in the specified direction by the specified number of blocks.

View File

@ -18,7 +18,7 @@
package baritone.api.selection;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.util.Direction;
import net.minecraft.core.Direction;
/**
* The selection manager handles setting Baritone's selections. You can set the selection here, as well as retrieving

View File

@ -17,12 +17,11 @@
package baritone.api.utils;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3i;
import javax.annotation.Nonnull;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.util.Mth;
/**
* A better BlockPos that has fewer hash collisions (and slightly more performant offsets)
@ -49,7 +48,7 @@ public final class BetterBlockPos extends BlockPos {
}
public BetterBlockPos(double x, double y, double z) {
this(MathHelper.floor(x), MathHelper.floor(y), MathHelper.floor(z));
this(Mth.floor(x), Mth.floor(y), Mth.floor(z));
}
public BetterBlockPos(BlockPos pos) {
@ -116,7 +115,7 @@ public final class BetterBlockPos extends BlockPos {
}
@Override
public BetterBlockPos up() {
public BetterBlockPos above() {
// this is unimaginably faster than blockpos.up
// that literally calls
// this.up(1)
@ -130,35 +129,35 @@ public final class BetterBlockPos extends BlockPos {
}
@Override
public BetterBlockPos up(int amt) {
public BetterBlockPos above(int amt) {
// see comment in up()
return amt == 0 ? this : new BetterBlockPos(x, y + amt, z);
}
@Override
public BetterBlockPos down() {
public BetterBlockPos below() {
// see comment in up()
return new BetterBlockPos(x, y - 1, z);
}
@Override
public BetterBlockPos down(int amt) {
public BetterBlockPos below(int amt) {
// see comment in up()
return amt == 0 ? this : new BetterBlockPos(x, y - amt, z);
}
@Override
public BetterBlockPos offset(Direction dir) {
Vector3i vec = dir.getDirectionVec();
public BetterBlockPos relative(Direction dir) {
Vec3i vec = dir.getNormal();
return new BetterBlockPos(x + vec.getX(), y + vec.getY(), z + vec.getZ());
}
@Override
public BetterBlockPos offset(Direction dir, int dist) {
public BetterBlockPos relative(Direction dir, int dist) {
if (dist == 0) {
return this;
}
Vector3i vec = dir.getDirectionVec();
Vec3i vec = dir.getNormal();
return new BetterBlockPos(x + vec.getX() * dist, y + vec.getY() * dist, z + vec.getZ() * dist);
}

View File

@ -20,18 +20,29 @@ package baritone.api.utils;
import baritone.api.utils.accessor.IItemStack;
import com.google.common.collect.ImmutableSet;
import io.netty.util.concurrent.ThreadPerTaskExecutor;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.core.BlockPos;
import net.minecraft.loot.*;
import net.minecraft.resources.*;
import net.minecraft.util.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.server.packs.repository.ServerPacksSource;
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.server.packs.resources.SimpleReloadableResourceManager;
import net.minecraft.util.Unit;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootTables;
import net.minecraft.world.level.storage.loot.PredicateManager;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nonnull;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@ -46,8 +57,8 @@ public final class BlockOptionalMeta {
private final ImmutableSet<Integer> stateHashes;
private final ImmutableSet<Integer> stackHashes;
private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$");
private static LootTableManager manager;
private static LootPredicateManager predicate = new LootPredicateManager();
private static LootTables manager;
private static PredicateManager predicate = new PredicateManager();
private static Map<Block, List<Item>> drops = new HashMap<>();
public BlockOptionalMeta(@Nonnull Block block) {
@ -73,7 +84,7 @@ public final class BlockOptionalMeta {
}
private static Set<BlockState> getStates(@Nonnull Block block) {
return new HashSet<>(block.getStateContainer().getValidStates());
return new HashSet<>(block.getStateDefinition().getPossibleStates());
}
private static ImmutableSet<Integer> getStateHashes(Set<BlockState> blockstates) {
@ -114,7 +125,7 @@ public final class BlockOptionalMeta {
//noinspection ConstantConditions
int hash = ((IItemStack) (Object) stack).getBaritoneHash();
hash -= stack.getDamage();
hash -= stack.getDamageValue();
return stackHashes.contains(hash);
}
@ -132,16 +143,16 @@ public final class BlockOptionalMeta {
return null;
}
public static LootTableManager getManager() {
public static LootTables getManager() {
if (manager == null) {
ResourcePackList rpl = new ResourcePackList(ResourcePackInfo::new, new ServerPackFinder());
rpl.reloadPacksFromFinders();
IResourcePack thePack = rpl.getAllPacks().iterator().next().getResourcePack();
IReloadableResourceManager resourceManager = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA);
manager = new LootTableManager(predicate);
resourceManager.addReloadListener(manager);
PackRepository rpl = new PackRepository(Pack::new, new ServerPacksSource());
rpl.reload();
PackResources thePack = rpl.getAvailablePacks().iterator().next().open();
ReloadableResourceManager resourceManager = new SimpleReloadableResourceManager(PackType.SERVER_DATA);
manager = new LootTables(predicate);
resourceManager.registerReloadListener(manager);
try {
resourceManager.reloadResourcesAndThen(new ThreadPerTaskExecutor(Thread::new), new ThreadPerTaskExecutor(Thread::new), Collections.singletonList(thePack), CompletableFuture.completedFuture(Unit.INSTANCE)).get();
resourceManager.reload(new ThreadPerTaskExecutor(Thread::new), new ThreadPerTaskExecutor(Thread::new), Collections.singletonList(thePack), CompletableFuture.completedFuture(Unit.INSTANCE)).get();
} catch (Exception exception) {
throw new RuntimeException(exception);
}
@ -149,27 +160,27 @@ public final class BlockOptionalMeta {
return manager;
}
public static LootPredicateManager getPredicateManager() {
public static PredicateManager getPredicateManager() {
return predicate;
}
private static synchronized List<Item> drops(Block b) {
return drops.computeIfAbsent(b, block -> {
ResourceLocation lootTableLocation = block.getLootTable();
if (lootTableLocation == LootTables.EMPTY) {
if (lootTableLocation == BuiltInLootTables.EMPTY) {
return Collections.emptyList();
} else {
List<Item> items = new ArrayList<>();
// the other overload for generate doesnt work in forge because forge adds code that requires a non null world
getManager().getLootTableFromLocation(lootTableLocation).generate(
new LootContext.Builder((ServerWorld) null)
getManager().get(lootTableLocation).getRandomItems(
new LootContext.Builder((ServerLevel) null)
.withRandom(new Random())
.withParameter(LootParameters.field_237457_g_, Vector3d.copy(BlockPos.NULL_VECTOR))
.withParameter(LootParameters.TOOL, ItemStack.EMPTY)
.withNullableParameter(LootParameters.BLOCK_ENTITY, null)
.withParameter(LootParameters.BLOCK_STATE, block.getDefaultState())
.build(LootParameterSets.BLOCK),
.withParameter(LootContextParams.ORIGIN, Vec3.atLowerCornerOf(BlockPos.ZERO))
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY)
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, null)
.withParameter(LootContextParams.BLOCK_STATE, block.defaultBlockState())
.create(LootContextParamSets.BLOCK),
stack -> items.add(stack.getItem())
);
return items;

View File

@ -17,13 +17,12 @@
package baritone.api.utils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
public class BlockOptionalMetaLookup {

View File

@ -17,12 +17,11 @@
package baritone.api.utils;
import net.minecraft.block.Block;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
public class BlockUtils {
@ -57,7 +56,7 @@ public class BlockUtils {
if (resourceCache.containsKey(name)) {
return null; // cached as null
}
block = Registry.BLOCK.getOptional(ResourceLocation.tryCreate(name.contains(":") ? name : "minecraft:" + name)).orElse(null);
block = Registry.BLOCK.getOptional(ResourceLocation.tryParse(name.contains(":") ? name : "minecraft:" + name)).orElse(null);
Map<String, Block> copy = new HashMap<>(resourceCache); // read only copy is safe, wont throw concurrentmodification
copy.put(name, block);
resourceCache = copy;

View File

@ -19,12 +19,11 @@ package baritone.api.utils;
import baritone.api.BaritoneAPI;
import baritone.api.utils.gui.BaritoneToast;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import java.util.Arrays;
import java.util.Calendar;
import java.util.stream.Stream;
@ -48,19 +47,19 @@ public interface Helper {
*/
Minecraft mc = Minecraft.getInstance();
static ITextComponent getPrefix() {
static Component getPrefix() {
// Inner text component
final Calendar now = Calendar.getInstance();
final boolean xd = now.get(Calendar.MONTH) == Calendar.APRIL && now.get(Calendar.DAY_OF_MONTH) <= 3;
TextComponent baritone = new StringTextComponent(xd ? "Baritoe" : BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : "Baritone");
baritone.setStyle(baritone.getStyle().setFormatting(TextFormatting.LIGHT_PURPLE));
BaseComponent baritone = new TextComponent(xd ? "Baritoe" : BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : "Baritone");
baritone.setStyle(baritone.getStyle().withColor(ChatFormatting.LIGHT_PURPLE));
// Outer brackets
TextComponent prefix = new StringTextComponent("");
prefix.setStyle(baritone.getStyle().setFormatting(TextFormatting.DARK_PURPLE));
prefix.appendString("[");
BaseComponent prefix = new TextComponent("");
prefix.setStyle(baritone.getStyle().withColor(ChatFormatting.DARK_PURPLE));
prefix.append("[");
prefix.append(baritone);
prefix.appendString("]");
prefix.append("]");
return prefix;
}
@ -71,8 +70,8 @@ public interface Helper {
* @param title The title to display in the popup
* @param message The message to display in the popup
*/
default void logToast(ITextComponent title, ITextComponent message) {
mc.execute(() -> BaritoneToast.addOrUpdate(mc.getToastGui(), title, message, BaritoneAPI.getSettings().toastTimer.value));
default void logToast(Component title, Component message) {
mc.execute(() -> BaritoneToast.addOrUpdate(mc.getToasts(), title, message, BaritoneAPI.getSettings().toastTimer.value));
}
/**
@ -82,7 +81,7 @@ public interface Helper {
* @param message The message to display in the popup
*/
default void logToast(String title, String message) {
logToast(new StringTextComponent(title), new StringTextComponent(message));
logToast(new TextComponent(title), new TextComponent(message));
}
/**
@ -91,7 +90,7 @@ public interface Helper {
* @param message The message to display in the popup
*/
default void logToast(String message) {
logToast(Helper.getPrefix(), new StringTextComponent(message));
logToast(Helper.getPrefix(), new TextComponent(message));
}
/**
@ -116,10 +115,10 @@ public interface Helper {
* @param logAsToast Whether to log as a toast notification
* @param components The components to send
*/
default void logDirect(boolean logAsToast, ITextComponent... components) {
TextComponent component = new StringTextComponent("");
default void logDirect(boolean logAsToast, Component... components) {
BaseComponent component = new TextComponent("");
component.append(getPrefix());
component.append(new StringTextComponent(" "));
component.append(new TextComponent(" "));
Arrays.asList(components).forEach(component::append);
if (logAsToast) {
logToast(getPrefix(), component);
@ -133,7 +132,7 @@ public interface Helper {
*
* @param components The components to send
*/
default void logDirect(ITextComponent... components) {
default void logDirect(Component... components) {
logDirect(BaritoneAPI.getSettings().logAsToast.value, components);
}
@ -145,10 +144,10 @@ public interface Helper {
* @param color The color to print that message in
* @param logAsToast Whether to log as a toast notification
*/
default void logDirect(String message, TextFormatting color, boolean logAsToast) {
default void logDirect(String message, ChatFormatting color, boolean logAsToast) {
Stream.of(message.split("\n")).forEach(line -> {
TextComponent component = new StringTextComponent(line.replace("\t", " "));
component.setStyle(component.getStyle().setFormatting(color));
BaseComponent component = new TextComponent(line.replace("\t", " "));
component.setStyle(component.getStyle().withColor(color));
logDirect(logAsToast, component);
});
}
@ -160,7 +159,7 @@ public interface Helper {
* @param message The message to display in chat
* @param color The color to print that message in
*/
default void logDirect(String message, TextFormatting color) {
default void logDirect(String message, ChatFormatting color) {
logDirect(message, color, BaritoneAPI.getSettings().logAsToast.value);
}
@ -172,7 +171,7 @@ public interface Helper {
* @param logAsToast Whether to log as a toast notification
*/
default void logDirect(String message, boolean logAsToast) {
logDirect(message, TextFormatting.GRAY, logAsToast);
logDirect(message, ChatFormatting.GRAY, logAsToast);
}
/**

View File

@ -18,19 +18,18 @@
package baritone.api.utils;
import baritone.api.cache.IWorldData;
import net.minecraft.block.SlabBlock;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
/**
* @author Brady
@ -38,14 +37,14 @@ import java.util.stream.StreamSupport;
*/
public interface IPlayerContext {
ClientPlayerEntity player();
LocalPlayer player();
IPlayerController playerController();
World world();
Level world();
default Iterable<Entity> entities() {
return ((ClientWorld) world()).getAllEntities();
return ((ClientLevel) world()).entitiesForRendering();
}
default Stream<Entity> entitiesStream() {
@ -55,11 +54,11 @@ public interface IPlayerContext {
IWorldData worldData();
RayTraceResult objectMouseOver();
HitResult objectMouseOver();
default BetterBlockPos playerFeet() {
// TODO find a better way to deal with soul sand!!!!!
BetterBlockPos feet = new BetterBlockPos(player().getPositionVec().x, player().getPositionVec().y + 0.1251, player().getPositionVec().z);
BetterBlockPos feet = new BetterBlockPos(player().position().x, player().position().y + 0.1251, player().position().z);
// sometimes when calling this from another thread or while world is null, it'll throw a NullPointerException
// that causes the game to immediately crash
@ -71,23 +70,23 @@ public interface IPlayerContext {
// if there is an exception, the only overhead is Java generating the exception object... so we can ignore it
try {
if (world().getBlockState(feet).getBlock() instanceof SlabBlock) {
return feet.up();
return feet.above();
}
} catch (NullPointerException ignored) {}
return feet;
}
default Vector3d playerFeetAsVec() {
return new Vector3d(player().getPositionVec().x, player().getPositionVec().y, player().getPositionVec().z);
default Vec3 playerFeetAsVec() {
return new Vec3(player().position().x, player().position().y, player().position().z);
}
default Vector3d playerHead() {
return new Vector3d(player().getPositionVec().x, player().getPositionVec().y + player().getEyeHeight(), player().getPositionVec().z);
default Vec3 playerHead() {
return new Vec3(player().position().x, player().position().y + player().getEyeHeight(), player().position().z);
}
default Rotation playerRotations() {
return new Rotation(player().rotationYaw, player().rotationPitch);
return new Rotation(player().yRot, player().xRot);
}
static double eyeHeight(boolean ifSneaking) {
@ -100,9 +99,9 @@ public interface IPlayerContext {
* @return The position of the highlighted block
*/
default Optional<BlockPos> getSelectedBlock() {
RayTraceResult result = objectMouseOver();
if (result != null && result.getType() == RayTraceResult.Type.BLOCK) {
return Optional.of(((BlockRayTraceResult) result).getPos());
HitResult result = objectMouseOver();
if (result != null && result.getType() == HitResult.Type.BLOCK) {
return Optional.of(((BlockHitResult) result).getBlockPos());
}
return Optional.empty();
}

View File

@ -18,17 +18,17 @@
package baritone.api.utils;
import baritone.api.BaritoneAPI;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.GameType;
import net.minecraft.world.World;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
/**
* @author Brady
@ -44,13 +44,13 @@ public interface IPlayerController {
void resetBlockRemoving();
ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, PlayerEntity player);
ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, Player player);
GameType getGameType();
ActionResultType processRightClickBlock(ClientPlayerEntity player, World world, Hand hand, BlockRayTraceResult result);
InteractionResult processRightClickBlock(LocalPlayer player, Level world, InteractionHand hand, BlockHitResult result);
ActionResultType processRightClick(ClientPlayerEntity player, World world, Hand hand);
InteractionResult processRightClick(LocalPlayer player, Level world, InteractionHand hand);
boolean clickBlock(BlockPos loc, Direction face);

View File

@ -17,10 +17,10 @@
package baritone.api.utils;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
/**
* @author Brady
@ -40,27 +40,27 @@ public final class RayTraceUtils {
* @param blockReachDistance The block reach distance of the entity
* @return The calculated raytrace result
*/
public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) {
public static HitResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) {
return rayTraceTowards(entity, rotation, blockReachDistance, false);
}
public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance, boolean wouldSneak) {
Vector3d start;
public static HitResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance, boolean wouldSneak) {
Vec3 start;
if (wouldSneak) {
start = inferSneakingEyePosition(entity);
} else {
start = entity.getEyePosition(1.0F); // do whatever is correct
}
Vector3d direction = RotationUtils.calcVector3dFromRotation(rotation);
Vector3d end = start.add(
Vec3 direction = RotationUtils.calcVector3dFromRotation(rotation);
Vec3 end = start.add(
direction.x * blockReachDistance,
direction.y * blockReachDistance,
direction.z * blockReachDistance
);
return entity.world.rayTraceBlocks(new RayTraceContext(start, end, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, entity));
return entity.level.clip(new ClipContext(start, end, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity));
}
public static Vector3d inferSneakingEyePosition(Entity entity) {
return new Vector3d(entity.getPosX(), entity.getPosY() + IPlayerContext.eyeHeight(true), entity.getPosZ());
public static Vec3 inferSneakingEyePosition(Entity entity) {
return new Vec3(entity.getX(), entity.getY() + IPlayerContext.eyeHeight(true), entity.getZ());
}
}

View File

@ -19,20 +19,19 @@ package baritone.api.utils;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.block.BlockState;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.util.math.vector.Vector3d;
import java.util.Optional;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
/**
* @author Brady
@ -53,13 +52,13 @@ public final class RotationUtils {
/**
* Offsets from the root block position to the center of each side.
*/
private static final Vector3d[] BLOCK_SIDE_MULTIPLIERS = new Vector3d[]{
new Vector3d(0.5, 0, 0.5), // Down
new Vector3d(0.5, 1, 0.5), // Up
new Vector3d(0.5, 0.5, 0), // North
new Vector3d(0.5, 0.5, 1), // South
new Vector3d(0, 0.5, 0.5), // West
new Vector3d(1, 0.5, 0.5) // East
private static final Vec3[] BLOCK_SIDE_MULTIPLIERS = new Vec3[]{
new Vec3(0.5, 0, 0.5), // Down
new Vec3(0.5, 1, 0.5), // Up
new Vec3(0.5, 0.5, 0), // North
new Vec3(0.5, 0.5, 1), // South
new Vec3(0, 0.5, 0.5), // West
new Vec3(1, 0.5, 0.5) // East
};
private RotationUtils() {}
@ -72,7 +71,7 @@ public final class RotationUtils {
* @return The rotation from the origin to the destination
*/
public static Rotation calcRotationFromCoords(BlockPos orig, BlockPos dest) {
return calcRotationFromVec3d(new Vector3d(orig.getX(), orig.getY(), orig.getZ()), new Vector3d(dest.getX(), dest.getY(), dest.getZ()));
return calcRotationFromVec3d(new Vec3(orig.getX(), orig.getY(), orig.getZ()), new Vec3(dest.getX(), dest.getY(), dest.getZ()));
}
/**
@ -101,7 +100,7 @@ public final class RotationUtils {
* @return The rotation from the origin to the destination
* @see #wrapAnglesToRelative(Rotation, Rotation)
*/
public static Rotation calcRotationFromVec3d(Vector3d orig, Vector3d dest, Rotation current) {
public static Rotation calcRotationFromVec3d(Vec3 orig, Vec3 dest, Rotation current) {
return wrapAnglesToRelative(current, calcRotationFromVec3d(orig, dest));
}
@ -112,11 +111,11 @@ public final class RotationUtils {
* @param dest The destination position
* @return The rotation from the origin to the destination
*/
private static Rotation calcRotationFromVec3d(Vector3d orig, Vector3d dest) {
private static Rotation calcRotationFromVec3d(Vec3 orig, Vec3 dest) {
double[] delta = {orig.x - dest.x, orig.y - dest.y, orig.z - dest.z};
double yaw = MathHelper.atan2(delta[0], -delta[2]);
double yaw = Mth.atan2(delta[0], -delta[2]);
double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]);
double pitch = MathHelper.atan2(delta[1], dist);
double pitch = Mth.atan2(delta[1], dist);
return new Rotation(
(float) (yaw * RAD_TO_DEG),
(float) (pitch * RAD_TO_DEG)
@ -129,19 +128,19 @@ public final class RotationUtils {
* @param rotation The input rotation
* @return Look vector for the rotation
*/
public static Vector3d calcVector3dFromRotation(Rotation rotation) {
float f = MathHelper.cos(-rotation.getYaw() * (float) DEG_TO_RAD - (float) Math.PI);
float f1 = MathHelper.sin(-rotation.getYaw() * (float) DEG_TO_RAD - (float) Math.PI);
float f2 = -MathHelper.cos(-rotation.getPitch() * (float) DEG_TO_RAD);
float f3 = MathHelper.sin(-rotation.getPitch() * (float) DEG_TO_RAD);
return new Vector3d((double) (f1 * f2), (double) f3, (double) (f * f2));
public static Vec3 calcVector3dFromRotation(Rotation rotation) {
float f = Mth.cos(-rotation.getYaw() * (float) DEG_TO_RAD - (float) Math.PI);
float f1 = Mth.sin(-rotation.getYaw() * (float) DEG_TO_RAD - (float) Math.PI);
float f2 = -Mth.cos(-rotation.getPitch() * (float) DEG_TO_RAD);
float f3 = Mth.sin(-rotation.getPitch() * (float) DEG_TO_RAD);
return new Vec3((double) (f1 * f2), (double) f3, (double) (f * f2));
}
/**
* @param ctx Context for the viewing entity
* @param pos The target block position
* @return The optional rotation
* @see #reachable(ClientPlayerEntity, BlockPos, double)
* @see #reachable(LocalPlayer, BlockPos, double)
*/
public static Optional<Rotation> reachable(IPlayerContext ctx, BlockPos pos) {
return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
@ -163,11 +162,11 @@ public final class RotationUtils {
* @param blockReachDistance The block reach distance of the entity
* @return The optional rotation
*/
public static Optional<Rotation> reachable(ClientPlayerEntity entity, BlockPos pos, double blockReachDistance) {
public static Optional<Rotation> reachable(LocalPlayer entity, BlockPos pos, double blockReachDistance) {
return reachable(entity, pos, blockReachDistance, false);
}
public static Optional<Rotation> reachable(ClientPlayerEntity entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
public static Optional<Rotation> reachable(LocalPlayer entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
if (baritone.getPlayerContext().isLookingAt(pos)) {
/*
@ -180,11 +179,11 @@ public final class RotationUtils {
*
* or if you're a normal person literally all this does it ensure that we don't nudge the pitch to a normal level
*/
Rotation hypothetical = new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F);
Rotation hypothetical = new Rotation(entity.yRot, entity.xRot + 0.0001F);
if (wouldSneak) {
// the concern here is: what if we're looking at it now, but as soon as we start sneaking we no longer are
RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true);
if (result != null && result.getType() == RayTraceResult.Type.BLOCK && ((BlockRayTraceResult) result).getPos().equals(pos)) {
HitResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true);
if (result != null && result.getType() == HitResult.Type.BLOCK && ((BlockHitResult) result).getBlockPos().equals(pos)) {
return Optional.of(hypothetical); // yes, if we sneaked we would still be looking at the block
}
} else {
@ -197,16 +196,16 @@ public final class RotationUtils {
return possibleRotation;
}
BlockState state = entity.world.getBlockState(pos);
VoxelShape shape = state.getShape(entity.world, pos);
BlockState state = entity.level.getBlockState(pos);
VoxelShape shape = state.getShape(entity.level, pos);
if (shape.isEmpty()) {
shape = VoxelShapes.fullCube();
shape = Shapes.block();
}
for (Vector3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
double xDiff = shape.getStart(Direction.Axis.X) * sideOffset.x + shape.getEnd(Direction.Axis.X) * (1 - sideOffset.x);
double yDiff = shape.getStart(Direction.Axis.Y) * sideOffset.y + shape.getEnd(Direction.Axis.Y) * (1 - sideOffset.y);
double zDiff = shape.getStart(Direction.Axis.Z) * sideOffset.z + shape.getEnd(Direction.Axis.Z) * (1 - sideOffset.z);
possibleRotation = reachableOffset(entity, pos, new Vector3d(pos.getX(), pos.getY(), pos.getZ()).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak);
for (Vec3 sideOffset : BLOCK_SIDE_MULTIPLIERS) {
double xDiff = shape.min(Direction.Axis.X) * sideOffset.x + shape.max(Direction.Axis.X) * (1 - sideOffset.x);
double yDiff = shape.min(Direction.Axis.Y) * sideOffset.y + shape.max(Direction.Axis.Y) * (1 - sideOffset.y);
double zDiff = shape.min(Direction.Axis.Z) * sideOffset.z + shape.max(Direction.Axis.Z) * (1 - sideOffset.z);
possibleRotation = reachableOffset(entity, pos, new Vec3(pos.getX(), pos.getY(), pos.getZ()).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak);
if (possibleRotation.isPresent()) {
return possibleRotation;
}
@ -225,16 +224,16 @@ public final class RotationUtils {
* @param blockReachDistance The block reach distance of the entity
* @return The optional rotation
*/
public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vector3d offsetPos, double blockReachDistance, boolean wouldSneak) {
Vector3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getEyePosition(1.0F);
Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch));
RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak);
public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3 offsetPos, double blockReachDistance, boolean wouldSneak) {
Vec3 eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getEyePosition(1.0F);
Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.yRot, entity.xRot));
HitResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak);
//System.out.println(result);
if (result != null && result.getType() == RayTraceResult.Type.BLOCK) {
if (((BlockRayTraceResult) result).getPos().equals(pos)) {
if (result != null && result.getType() == HitResult.Type.BLOCK) {
if (((BlockHitResult) result).getBlockPos().equals(pos)) {
return Optional.of(rotation);
}
if (entity.world.getBlockState(pos).getBlock() instanceof AbstractFireBlock && ((BlockRayTraceResult) result).getPos().equals(pos.down())) {
if (entity.level.getBlockState(pos).getBlock() instanceof BaseFireBlock && ((BlockHitResult) result).getBlockPos().equals(pos.below())) {
return Optional.of(rotation);
}
}
@ -251,6 +250,6 @@ public final class RotationUtils {
* @return The optional rotation
*/
public static Optional<Rotation> reachableCenter(Entity entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.world, pos), blockReachDistance, wouldSneak);
return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.level, pos), blockReachDistance, wouldSneak);
}
}

View File

@ -19,14 +19,13 @@ package baritone.api.utils;
import baritone.api.BaritoneAPI;
import baritone.api.Settings;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector3i;
import net.minecraft.util.registry.Registry;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import java.awt.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@ -49,7 +48,7 @@ import java.util.stream.Stream;
public class SettingsUtil {
private static final Path SETTINGS_PATH = Minecraft.getInstance().gameDir.toPath().resolve("baritone").resolve("settings.txt");
private static final Path SETTINGS_PATH = Minecraft.getInstance().gameDirectory.toPath().resolve("baritone").resolve("settings.txt");
private static final Pattern SETTING_PATTERN = Pattern.compile("^(?<setting>[^ ]+) +(?<value>.+)"); // key and value split by the first space
@ -225,8 +224,8 @@ public class SettingsUtil {
color -> color.getRed() + "," + color.getGreen() + "," + color.getBlue()
),
VEC3I(
Vector3i.class,
str -> new Vector3i(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])),
Vec3i.class,
str -> new Vec3i(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])),
vec -> vec.getX() + "," + vec.getY() + "," + vec.getZ()
),
BLOCK(
@ -236,7 +235,7 @@ public class SettingsUtil {
),
ITEM(
Item.class,
str -> Registry.ITEM.getOrDefault(new ResourceLocation(str.trim())), // TODO this now returns AIR on failure instead of null, is that an issue?
str -> Registry.ITEM.get(new ResourceLocation(str.trim())), // TODO this now returns AIR on failure instead of null, is that an issue?
item -> Registry.ITEM.getKey(item).toString()
),
LIST() {

View File

@ -17,14 +17,14 @@
package baritone.api.utils;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
/**
* @author Brady
@ -42,22 +42,22 @@ public final class VecUtils {
* @return The center of the block's bounding box
* @see #getBlockPosCenter(BlockPos)
*/
public static Vector3d calculateBlockCenter(World world, BlockPos pos) {
public static Vec3 calculateBlockCenter(Level world, BlockPos pos) {
BlockState b = world.getBlockState(pos);
VoxelShape shape = b.getCollisionShape(world, pos);
if (shape.isEmpty()) {
return getBlockPosCenter(pos);
}
double xDiff = (shape.getStart(Direction.Axis.X) + shape.getEnd(Direction.Axis.X)) / 2;
double yDiff = (shape.getStart(Direction.Axis.Y) + shape.getEnd(Direction.Axis.Y)) / 2;
double zDiff = (shape.getStart(Direction.Axis.Z) + shape.getEnd(Direction.Axis.Z)) / 2;
double xDiff = (shape.min(Direction.Axis.X) + shape.max(Direction.Axis.X)) / 2;
double yDiff = (shape.min(Direction.Axis.Y) + shape.max(Direction.Axis.Y)) / 2;
double zDiff = (shape.min(Direction.Axis.Z) + shape.max(Direction.Axis.Z)) / 2;
if (Double.isNaN(xDiff) || Double.isNaN(yDiff) || Double.isNaN(zDiff)) {
throw new IllegalStateException(b + " " + pos + " " + shape);
}
if (b.getBlock() instanceof AbstractFireBlock) {//look at bottom of fire when putting it out
if (b.getBlock() instanceof BaseFireBlock) {//look at bottom of fire when putting it out
yDiff = 0;
}
return new Vector3d(
return new Vec3(
pos.getX() + xDiff,
pos.getY() + yDiff,
pos.getZ() + zDiff
@ -72,10 +72,10 @@ public final class VecUtils {
*
* @param pos The block position
* @return The assumed center of the position
* @see #calculateBlockCenter(World, BlockPos)
* @see #calculateBlockCenter(Level, BlockPos)
*/
public static Vector3d getBlockPosCenter(BlockPos pos) {
return new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
public static Vec3 getBlockPosCenter(BlockPos pos) {
return new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
}
/**
@ -105,7 +105,7 @@ public final class VecUtils {
* @see #getBlockPosCenter(BlockPos)
*/
public static double entityDistanceToCenter(Entity entity, BlockPos pos) {
return distanceToCenter(pos, entity.getPositionVec().x, entity.getPositionVec().y, entity.getPositionVec().z);
return distanceToCenter(pos, entity.position().x, entity.position().y, entity.position().z);
}
/**
@ -118,6 +118,6 @@ public final class VecUtils {
* @see #getBlockPosCenter(BlockPos)
*/
public static double entityFlatDistanceToCenter(Entity entity, BlockPos pos) {
return distanceToCenter(pos, entity.getPositionVec().x, pos.getY() + 0.5, entity.getPositionVec().z);
return distanceToCenter(pos, entity.position().x, pos.getY() + 0.5, entity.position().z);
}
}

View File

@ -17,57 +17,57 @@
package baritone.api.utils.gui;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.gui.toasts.IToast;
import net.minecraft.client.gui.toasts.ToastGui;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
public class BaritoneToast implements IToast {
public class BaritoneToast implements Toast {
private String title;
private String subtitle;
private long firstDrawTime;
private boolean newDisplay;
private long totalShowTime;
public BaritoneToast(ITextComponent titleComponent, ITextComponent subtitleComponent, long totalShowTime) {
public BaritoneToast(Component titleComponent, Component subtitleComponent, long totalShowTime) {
this.title = titleComponent.getString();
this.subtitle = subtitleComponent == null ? null : subtitleComponent.getString();
this.totalShowTime = totalShowTime;
}
public Visibility func_230444_a_(MatrixStack matrixStack, ToastGui toastGui, long delta) {
public Visibility render(PoseStack matrixStack, ToastComponent toastGui, long delta) {
if (this.newDisplay) {
this.firstDrawTime = delta;
this.newDisplay = false;
}
toastGui.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/toasts.png"));
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 255.0f);
toastGui.getMinecraft().getTextureManager().bind(new ResourceLocation("textures/gui/toasts.png"));
GlStateManager._color4f(1.0F, 1.0F, 1.0F, 255.0f);
toastGui.blit(matrixStack, 0, 0, 0, 32, 160, 32);
if (this.subtitle == null) {
toastGui.getMinecraft().fontRenderer.drawString(matrixStack, this.title, 18, 12, -11534256);
toastGui.getMinecraft().font.draw(matrixStack, this.title, 18, 12, -11534256);
} else {
toastGui.getMinecraft().fontRenderer.drawString(matrixStack, this.title, 18, 7, -11534256);
toastGui.getMinecraft().fontRenderer.drawString(matrixStack, this.subtitle, 18, 18, -16777216);
toastGui.getMinecraft().font.draw(matrixStack, this.title, 18, 7, -11534256);
toastGui.getMinecraft().font.draw(matrixStack, this.subtitle, 18, 18, -16777216);
}
return delta - this.firstDrawTime < totalShowTime ? Visibility.SHOW : Visibility.HIDE;
}
public void setDisplayedText(ITextComponent titleComponent, ITextComponent subtitleComponent) {
public void setDisplayedText(Component titleComponent, Component subtitleComponent) {
this.title = titleComponent.getString();
this.subtitle = subtitleComponent == null ? null : subtitleComponent.getString();
this.newDisplay = true;
}
public static void addOrUpdate(ToastGui toast, ITextComponent title, ITextComponent subtitle, long totalShowTime) {
public static void addOrUpdate(ToastComponent toast, Component title, Component subtitle, long totalShowTime) {
BaritoneToast baritonetoast = toast.getToast(BaritoneToast.class, new Object());
if (baritonetoast == null) {
toast.add(new BaritoneToast(title, subtitle, totalShowTime));
toast.addToast(new BaritoneToast(title, subtitle, totalShowTime));
} else {
baritonetoast.setDisplayedText(title, subtitle);
}

View File

@ -17,7 +17,7 @@
package baritone.api.utils.interfaces;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
public interface IGoalRenderPos {

View File

@ -18,17 +18,17 @@
package baritone.launch.mixins;
import baritone.utils.accessor.IChunkArray;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.concurrent.atomic.AtomicReferenceArray;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.LevelChunk;
@Mixin(targets = "net.minecraft.client.multiplayer.ClientChunkProvider$ChunkArray")
public abstract class MixinChunkArray implements IChunkArray {
@Shadow
private AtomicReferenceArray<Chunk> chunks;
private AtomicReferenceArray<LevelChunk> chunks;
@Shadow
private int viewDistance;
@Shadow
@ -47,7 +47,7 @@ public abstract class MixinChunkArray implements IChunkArray {
protected abstract int getIndex(int x, int z);
@Shadow
protected abstract void replace(int index, Chunk chunk);
protected abstract void replace(int index, LevelChunk chunk);
@Override
public int centerX() {
@ -65,7 +65,7 @@ public abstract class MixinChunkArray implements IChunkArray {
}
@Override
public AtomicReferenceArray<Chunk> getChunks() {
public AtomicReferenceArray<LevelChunk> getChunks() {
return chunks;
}
@ -74,9 +74,9 @@ public abstract class MixinChunkArray implements IChunkArray {
centerX = other.centerX();
centerZ = other.centerZ();
AtomicReferenceArray<Chunk> copyingFrom = other.getChunks();
AtomicReferenceArray<LevelChunk> copyingFrom = other.getChunks();
for (int k = 0; k < copyingFrom.length(); ++k) {
Chunk chunk = copyingFrom.get(k);
LevelChunk chunk = copyingFrom.get(k);
if (chunk != null) {
ChunkPos chunkpos = chunk.getPos();
if (inView(chunkpos.x, chunkpos.z)) {

View File

@ -19,24 +19,24 @@ package baritone.launch.mixins;
import baritone.utils.accessor.IChunkArray;
import baritone.utils.accessor.IClientChunkProvider;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.lang.reflect.Field;
import java.util.Arrays;
import net.minecraft.client.multiplayer.ClientChunkCache;
import net.minecraft.client.multiplayer.ClientLevel;
@Mixin(ClientChunkProvider.class)
@Mixin(ClientChunkCache.class)
public class MixinClientChunkProvider implements IClientChunkProvider {
@Shadow
private ClientWorld world;
private ClientLevel world;
@Override
public ClientChunkProvider createThreadSafeCopy() {
public ClientChunkCache createThreadSafeCopy() {
IChunkArray arr = extractReferenceArray();
ClientChunkProvider result = new ClientChunkProvider(world, arr.viewDistance() - 3); // -3 because its adds 3 for no reason lmao
ClientChunkCache result = new ClientChunkCache(world, arr.viewDistance() - 3); // -3 because its adds 3 for no reason lmao
IChunkArray copyArr = ((IClientChunkProvider) result).extractReferenceArray();
copyArr.copyFrom(arr);
if (copyArr.viewDistance() != arr.viewDistance()) {
@ -47,7 +47,7 @@ public class MixinClientChunkProvider implements IClientChunkProvider {
@Override
public IChunkArray extractReferenceArray() {
for (Field f : ClientChunkProvider.class.getDeclaredFields()) {
for (Field f : ClientChunkCache.class.getDeclaredFields()) {
if (IChunkArray.class.isAssignableFrom(f.getType())) {
try {
return (IChunkArray) f.get(this);
@ -56,6 +56,6 @@ public class MixinClientChunkProvider implements IClientChunkProvider {
}
}
}
throw new RuntimeException(Arrays.toString(ClientChunkProvider.class.getDeclaredFields()));
throw new RuntimeException(Arrays.toString(ClientChunkCache.class.getDeclaredFields()));
}
}

View File

@ -23,10 +23,15 @@ import baritone.api.IBaritone;
import baritone.api.event.events.ChunkEvent;
import baritone.api.event.events.type.EventState;
import baritone.cache.CachedChunk;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.network.play.ClientPlayNetHandler;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.play.server.*;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundForgetLevelChunkPacket;
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket;
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
import net.minecraft.world.level.ChunkPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -36,7 +41,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* @author Brady
* @since 8/3/2018
*/
@Mixin(ClientPlayNetHandler.class)
@Mixin(ClientPacketListener.class)
public class MixinClientPlayNetHandler {
// unused lol
@ -67,16 +72,16 @@ public class MixinClientPlayNetHandler {
method = "handleChunkData",
at = @At("RETURN")
)
private void postHandleChunkData(SChunkDataPacket packetIn, CallbackInfo ci) {
private void postHandleChunkData(ClientboundLevelChunkPacket packetIn, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ClientPlayerEntity player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) {
LocalPlayer player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPacketListener) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.POST,
packetIn.isFullChunk() ? ChunkEvent.Type.POPULATE_FULL : ChunkEvent.Type.POPULATE_PARTIAL,
packetIn.getChunkX(),
packetIn.getChunkZ()
packetIn.getX(),
packetIn.getZ()
)
);
}
@ -87,10 +92,10 @@ public class MixinClientPlayNetHandler {
method = "processChunkUnload",
at = @At("HEAD")
)
private void preChunkUnload(SUnloadChunkPacket packet, CallbackInfo ci) {
private void preChunkUnload(ClientboundForgetLevelChunkPacket packet, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ClientPlayerEntity player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) {
LocalPlayer player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPacketListener) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(EventState.PRE, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ())
);
@ -102,10 +107,10 @@ public class MixinClientPlayNetHandler {
method = "processChunkUnload",
at = @At("RETURN")
)
private void postChunkUnload(SUnloadChunkPacket packet, CallbackInfo ci) {
private void postChunkUnload(ClientboundForgetLevelChunkPacket packet, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ClientPlayerEntity player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) {
LocalPlayer player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPacketListener) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(EventState.POST, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ())
);
@ -117,16 +122,16 @@ public class MixinClientPlayNetHandler {
method = "handleBlockChange",
at = @At("RETURN")
)
private void postHandleBlockChange(SChangeBlockPacket packetIn, CallbackInfo ci) {
private void postHandleBlockChange(ClientboundBlockUpdatePacket packetIn, CallbackInfo ci) {
if (!Baritone.settings().repackOnAnyBlockChange.value) {
return;
}
if (!CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(packetIn.getState().getBlock())) {
if (!CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(packetIn.getBlockState().getBlock())) {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ClientPlayerEntity player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) {
LocalPlayer player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPacketListener) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.POST,
@ -143,12 +148,12 @@ public class MixinClientPlayNetHandler {
method = "handleMultiBlockChange",
at = @At("RETURN")
)
private void postHandleMultiBlockChange(SMultiBlockChangePacket packetIn, CallbackInfo ci) {
private void postHandleMultiBlockChange(ClientboundSectionBlocksUpdatePacket packetIn, CallbackInfo ci) {
if (!Baritone.settings().repackOnAnyBlockChange.value) {
return;
}
ChunkPos[] chunkPos = new ChunkPos[1];
packetIn.func_244310_a((pos, state) -> {
packetIn.runUpdates((pos, state) -> {
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(state.getBlock())) {
chunkPos[0] = new ChunkPos(pos);
}
@ -157,8 +162,8 @@ public class MixinClientPlayNetHandler {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ClientPlayerEntity player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) {
LocalPlayer player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPacketListener) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.POST,
@ -178,10 +183,10 @@ public class MixinClientPlayNetHandler {
target = "net/minecraft/client/Minecraft.displayGuiScreen(Lnet/minecraft/client/gui/screen/Screen;)V"
)
)
private void onPlayerDeath(SCombatPacket packetIn, CallbackInfo ci) {
private void onPlayerDeath(ClientboundPlayerCombatPacket packetIn, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ClientPlayerEntity player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) {
LocalPlayer player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPacketListener) (Object) this) {
ibaritone.getGameEventHandler().onPlayerDeath();
}
}

View File

@ -24,9 +24,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.entity.player.ClientPlayerEntity;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.player.Abilities;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -37,7 +37,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* @author Brady
* @since 8/1/2018
*/
@Mixin(ClientPlayerEntity.class)
@Mixin(LocalPlayer.class)
public class MixinClientPlayerEntity {
@Inject(
@ -47,7 +47,7 @@ public class MixinClientPlayerEntity {
)
private void sendChatMessage(String msg, CallbackInfo ci) {
ChatEvent event = new ChatEvent(msg);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
if (baritone == null) {
return;
}
@ -67,7 +67,7 @@ public class MixinClientPlayerEntity {
)
)
private void onPreUpdate(CallbackInfo ci) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
if (baritone != null) {
baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE));
}
@ -83,7 +83,7 @@ public class MixinClientPlayerEntity {
)
)
private void onPostUpdate(CallbackInfo ci) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
if (baritone != null) {
baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST));
}
@ -96,12 +96,12 @@ public class MixinClientPlayerEntity {
target = "net/minecraft/entity/player/PlayerAbilities.allowFlying:Z"
)
)
private boolean isAllowFlying(PlayerAbilities capabilities) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
private boolean isAllowFlying(Abilities capabilities) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
if (baritone == null) {
return capabilities.allowFlying;
return capabilities.mayfly;
}
return !baritone.getPathingBehavior().isPathing() && capabilities.allowFlying;
return !baritone.getPathingBehavior().isPathing() && capabilities.mayfly;
}
@Redirect(
@ -111,10 +111,10 @@ public class MixinClientPlayerEntity {
target = "net/minecraft/client/settings/KeyBinding.isKeyDown()Z"
)
)
private boolean isKeyDown(KeyBinding keyBinding) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
private boolean isKeyDown(KeyMapping keyBinding) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
if (baritone == null) {
return keyBinding.isKeyDown();
return keyBinding.isDown();
}
SprintStateEvent event = new SprintStateEvent();
baritone.getGameEventHandler().onPlayerSprintState(event);
@ -125,7 +125,7 @@ public class MixinClientPlayerEntity {
// hitting control shouldn't make all bots sprint
return false;
}
return keyBinding.isKeyDown();
return keyBinding.isDown();
}
@Inject(
@ -135,7 +135,7 @@ public class MixinClientPlayerEntity {
)
)
private void updateRidden(CallbackInfo cb) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
if (baritone != null) {
((LookBehavior) baritone.getLookBehavior()).pig();
}

View File

@ -22,8 +22,6 @@ import baritone.api.event.events.TabCompleteEvent;
import com.mojang.brigadier.context.StringRange;
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
import net.minecraft.client.gui.CommandSuggestionHelper;
import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -35,17 +33,19 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.minecraft.client.gui.components.CommandSuggestions;
import net.minecraft.client.gui.components.EditBox;
/**
* @author Brady
* @since 10/9/2019
*/
@Mixin(CommandSuggestionHelper.class)
@Mixin(CommandSuggestions.class)
public class MixinCommandSuggestionHelper {
@Shadow
@Final
private TextFieldWidget inputField;
private EditBox inputField;
@Shadow
@Final
@ -61,7 +61,7 @@ public class MixinCommandSuggestionHelper {
)
private void preUpdateSuggestion(CallbackInfo ci) {
// Anything that is present in the input text before the cursor position
String prefix = this.inputField.getText().substring(0, Math.min(this.inputField.getText().length(), this.inputField.getCursorPosition()));
String prefix = this.inputField.getValue().substring(0, Math.min(this.inputField.getValue().length(), this.inputField.getCursorPosition()));
TabCompleteEvent event = new TabCompleteEvent(prefix);
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onPreTabComplete(event);
@ -80,9 +80,9 @@ public class MixinCommandSuggestionHelper {
if (event.completions.length == 0) {
this.suggestionsFuture = Suggestions.empty();
} else {
int offset = this.inputField.getText().endsWith(" ")
int offset = this.inputField.getValue().endsWith(" ")
? this.inputField.getCursorPosition()
: this.inputField.getText().lastIndexOf(" ") + 1; // If there is no space this is still 0 haha yes
: this.inputField.getValue().lastIndexOf(" ") + 1; // If there is no space this is still 0 haha yes
List<Suggestion> suggestionList = Stream.of(event.completions)
.map(s -> new Suggestion(StringRange.between(offset, offset + s.length()), s))

View File

@ -19,8 +19,8 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.event.events.RotationMoveEvent;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -42,11 +42,11 @@ public class MixinEntity {
private void moveRelativeHead(CallbackInfo info) {
this.yawRestore = this.rotationYaw;
// noinspection ConstantConditions
if (!ClientPlayerEntity.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this) == null) {
if (!LocalPlayer.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this) == null) {
return;
}
RotationMoveEvent motionUpdateRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.rotationYaw);
BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this).getGameEventHandler().onPlayerRotationMove(motionUpdateRotationEvent);
BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this).getGameEventHandler().onPlayerRotationMove(motionUpdateRotationEvent);
this.rotationYaw = motionUpdateRotationEvent.getYaw();
}

View File

@ -18,25 +18,25 @@
package baritone.launch.mixins;
import baritone.utils.accessor.IEntityRenderManager;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(EntityRendererManager.class)
@Mixin(EntityRenderDispatcher.class)
public class MixinEntityRenderManager implements IEntityRenderManager {
@Override
public double renderPosX() {
return ((EntityRendererManager) (Object) this).info.getProjectedView().x;
return ((EntityRenderDispatcher) (Object) this).camera.getPosition().x;
}
@Override
public double renderPosY() {
return ((EntityRendererManager) (Object) this).info.getProjectedView().y;
return ((EntityRenderDispatcher) (Object) this).camera.getPosition().y;
}
@Override
public double renderPosZ() {
return ((EntityRendererManager) (Object) this).info.getProjectedView().z;
return ((EntityRenderDispatcher) (Object) this).camera.getPosition().z;
}
}

View File

@ -18,8 +18,8 @@
package baritone.launch.mixins;
import baritone.api.utils.accessor.IItemStack;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

View File

@ -20,11 +20,11 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.RotationMoveEvent;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.world.World;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -45,7 +45,7 @@ public abstract class MixinLivingEntity extends Entity {
*/
private RotationMoveEvent jumpRotationEvent;
public MixinLivingEntity(EntityType<?> entityTypeIn, World worldIn) {
public MixinLivingEntity(EntityType<?> entityTypeIn, Level worldIn) {
super(entityTypeIn, worldIn);
}
@ -55,10 +55,10 @@ public abstract class MixinLivingEntity extends Entity {
)
private void preMoveRelative(CallbackInfo ci) {
// noinspection ConstantConditions
if (ClientPlayerEntity.class.isInstance(this)) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
if (LocalPlayer.class.isInstance(this)) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
if (baritone != null) {
this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw);
this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.yRot);
baritone.getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
}
}
@ -73,10 +73,10 @@ public abstract class MixinLivingEntity extends Entity {
)
)
private float overrideYaw(LivingEntity self) {
if (self instanceof ClientPlayerEntity && BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this) != null) {
if (self instanceof LocalPlayer && BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this) != null) {
return this.jumpRotationEvent.getYaw();
}
return self.rotationYaw;
return self.yRot;
}

View File

@ -18,11 +18,11 @@
package baritone.launch.mixins;
import baritone.api.utils.BlockOptionalMeta;
import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootPredicateManager;
import net.minecraft.loot.LootTableManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootTables;
import net.minecraft.world.level.storage.loot.PredicateManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@ -37,7 +37,7 @@ public class MixinLootContext {
target = "net/minecraft/world/server/ServerWorld.getServer()Lnet/minecraft/server/MinecraftServer;"
)
)
private MinecraftServer getServer(ServerWorld world) {
private MinecraftServer getServer(ServerLevel world) {
if (world == null) {
return null;
}
@ -51,11 +51,11 @@ public class MixinLootContext {
target = "net/minecraft/server/MinecraftServer.getLootTableManager()Lnet/minecraft/loot/LootTableManager;"
)
)
private LootTableManager getLootTableManager(MinecraftServer server) {
private LootTables getLootTableManager(MinecraftServer server) {
if (server == null) {
return BlockOptionalMeta.getManager();
}
return server.getLootTableManager();
return server.getLootTables();
}
@Redirect(
@ -65,10 +65,10 @@ public class MixinLootContext {
target = "net/minecraft/server/MinecraftServer.func_229736_aP_()Lnet/minecraft/loot/LootPredicateManager;"
)
)
private LootPredicateManager getLootPredicateManager(MinecraftServer server) {
private PredicateManager getLootPredicateManager(MinecraftServer server) {
if (server == null) {
return BlockOptionalMeta.getPredicateManager();
}
return server.func_229736_aP_();
return server.getPredicateManager();
}
}

View File

@ -23,9 +23,9 @@ 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.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -44,9 +44,9 @@ import java.util.function.BiFunction;
public class MixinMinecraft {
@Shadow
public ClientPlayerEntity player;
public LocalPlayer player;
@Shadow
public ClientWorld world;
public ClientLevel world;
@Inject(
method = "<init>",
@ -86,7 +86,7 @@ public class MixinMinecraft {
method = "loadWorld(Lnet/minecraft/client/world/ClientWorld;)V",
at = @At("HEAD")
)
private void preLoadWorld(ClientWorld world, CallbackInfo ci) {
private void preLoadWorld(ClientLevel world, CallbackInfo ci) {
// If we're unloading the world but one doesn't exist, ignore it
if (this.world == null && world == null) {
return;
@ -106,7 +106,7 @@ public class MixinMinecraft {
method = "loadWorld(Lnet/minecraft/client/world/ClientWorld;)V",
at = @At("RETURN")
)
private void postLoadWorld(ClientWorld world, CallbackInfo ci) {
private void postLoadWorld(ClientLevel world, 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

@ -25,9 +25,9 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.network.IPacket;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.PacketDirection;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -39,7 +39,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* @author Brady
* @since 8/6/2018
*/
@Mixin(NetworkManager.class)
@Mixin(Connection.class)
public class MixinNetworkManager {
@Shadow
@ -47,20 +47,20 @@ public class MixinNetworkManager {
@Shadow
@Final
private PacketDirection direction;
private PacketFlow direction;
@Inject(
method = "dispatchPacket",
at = @At("HEAD")
)
private void preDispatchPacket(IPacket<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) {
if (this.direction != PacketDirection.CLIENTBOUND) {
private void preDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) {
if (this.direction != PacketFlow.CLIENTBOUND) {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (NetworkManager) (Object) this) {
ibaritone.getGameEventHandler().onSendPacket(new PacketEvent((NetworkManager) (Object) this, EventState.PRE, inPacket));
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (Connection) (Object) this) {
ibaritone.getGameEventHandler().onSendPacket(new PacketEvent((Connection) (Object) this, EventState.PRE, inPacket));
}
}
}
@ -69,14 +69,14 @@ public class MixinNetworkManager {
method = "dispatchPacket",
at = @At("RETURN")
)
private void postDispatchPacket(IPacket<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) {
if (this.direction != PacketDirection.CLIENTBOUND) {
private void postDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) {
if (this.direction != PacketFlow.CLIENTBOUND) {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (NetworkManager) (Object) this) {
ibaritone.getGameEventHandler().onSendPacket(new PacketEvent((NetworkManager) (Object) this, EventState.POST, inPacket));
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (Connection) (Object) this) {
ibaritone.getGameEventHandler().onSendPacket(new PacketEvent((Connection) (Object) this, EventState.POST, inPacket));
}
}
}
@ -88,13 +88,13 @@ public class MixinNetworkManager {
target = "net/minecraft/network/NetworkManager.processPacket(Lnet/minecraft/network/IPacket;Lnet/minecraft/network/INetHandler;)V"
)
)
private void preProcessPacket(ChannelHandlerContext context, IPacket<?> packet, CallbackInfo ci) {
if (this.direction != PacketDirection.CLIENTBOUND) {
private void preProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
if (this.direction != PacketFlow.CLIENTBOUND) {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (NetworkManager) (Object) this) {
ibaritone.getGameEventHandler().onReceivePacket(new PacketEvent((NetworkManager) (Object) this, EventState.PRE, packet));
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (Connection) (Object) this) {
ibaritone.getGameEventHandler().onReceivePacket(new PacketEvent((Connection) (Object) this, EventState.PRE, packet));
}
}
}
@ -103,13 +103,13 @@ public class MixinNetworkManager {
method = "channelRead0",
at = @At("RETURN")
)
private void postProcessPacket(ChannelHandlerContext context, IPacket<?> packet, CallbackInfo ci) {
if (!this.channel.isOpen() || this.direction != PacketDirection.CLIENTBOUND) {
private void postProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
if (!this.channel.isOpen() || this.direction != PacketFlow.CLIENTBOUND) {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (NetworkManager) (Object) this) {
ibaritone.getGameEventHandler().onReceivePacket(new PacketEvent((NetworkManager) (Object) this, EventState.POST, packet));
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (Connection) (Object) this) {
ibaritone.getGameEventHandler().onReceivePacket(new PacketEvent((Connection) (Object) this, EventState.POST, packet));
}
}
}

View File

@ -18,13 +18,13 @@
package baritone.launch.mixins;
import baritone.utils.accessor.IPlayerControllerMP;
import net.minecraft.client.multiplayer.PlayerController;
import net.minecraft.util.math.BlockPos;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.core.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(PlayerController.class)
@Mixin(MultiPlayerGameMode.class)
public abstract class MixinPlayerController implements IPlayerControllerMP {
@Accessor

View File

@ -18,11 +18,11 @@
package baritone.launch.mixins;
import baritone.utils.accessor.IGuiScreen;
import net.minecraft.client.gui.screen.Screen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import java.net.URI;
import net.minecraft.client.gui.screens.Screen;
@Mixin(Screen.class)
public abstract class MixinScreen implements IGuiScreen {

View File

@ -20,8 +20,6 @@ package baritone.launch.mixins;
import baritone.utils.accessor.IChunkArray;
import baritone.utils.accessor.IClientChunkProvider;
import baritone.utils.accessor.ISodiumChunkArray;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.*;
import java.lang.reflect.Constructor;
@ -29,6 +27,8 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.concurrent.locks.StampedLock;
import net.minecraft.client.multiplayer.ClientChunkCache;
import net.minecraft.client.multiplayer.ClientLevel;
@Pseudo
@Mixin(targets = "me.jellysquid.mods.sodium.client.world.SodiumChunkManager", remap = false)
@ -40,7 +40,7 @@ public class MixinSodiumChunkProvider implements IClientChunkProvider {
@Shadow
@Final
private ClientWorld world;
private ClientLevel world;
@Shadow
private int radius;
@ -52,16 +52,16 @@ public class MixinSodiumChunkProvider implements IClientChunkProvider {
private static Field chunkArrayField = null;
@Override
public ClientChunkProvider createThreadSafeCopy() {
public ClientChunkCache createThreadSafeCopy() {
// similar operation to https://github.com/jellysquid3/sodium-fabric/blob/d3528521d48a130322c910c6f0725cf365ebae6f/src/main/java/me/jellysquid/mods/sodium/client/world/SodiumChunkManager.java#L139
long stamp = this.lock.writeLock();
try {
ISodiumChunkArray refArray = extractReferenceArray();
if (thisConstructor == null) {
thisConstructor = this.getClass().getConstructor(ClientWorld.class, int.class);
thisConstructor = this.getClass().getConstructor(ClientLevel.class, int.class);
}
ClientChunkProvider result = (ClientChunkProvider) thisConstructor.newInstance(world, radius - 3); // -3 because it adds 3 for no reason here too lmao
ClientChunkCache result = (ClientChunkCache) thisConstructor.newInstance(world, radius - 3); // -3 because it adds 3 for no reason here too lmao
IChunkArray copyArr = ((IClientChunkProvider) result).extractReferenceArray();
copyArr.copyFrom(refArray);
return result;

View File

@ -21,12 +21,12 @@ import baritone.utils.accessor.IChunkArray;
import baritone.utils.accessor.ISodiumChunkArray;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Shadow;
import java.util.concurrent.atomic.AtomicReferenceArray;
import net.minecraft.world.level.chunk.LevelChunk;
@Pseudo
@Mixin(targets = "me.jellysquid.mods.sodium.client.util.collections.FixedLongHashTable", remap = false)
@ -58,7 +58,7 @@ public abstract class MixinSodiumFixedLongHashTable implements ISodiumChunkArray
//these are useless here...
@Override
public AtomicReferenceArray<Chunk> getChunks() {
public AtomicReferenceArray<LevelChunk> getChunks() {
return null;
}

View File

@ -20,12 +20,12 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.RenderEvent;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.ActiveRenderInfo;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.util.math.vector.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -36,7 +36,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
* @author Brady
* @since 2/13/2020
*/
@Mixin(WorldRenderer.class)
@Mixin(LevelRenderer.class)
public class MixinWorldRenderer {
@Inject(
@ -44,7 +44,7 @@ public class MixinWorldRenderer {
at = @At("RETURN"),
locals = LocalCapture.CAPTURE_FAILSOFT
)
private void onStartHand(MatrixStack matrixStackIn, float partialTicks, long finishTimeNano, boolean drawBlockOutline, ActiveRenderInfo activeRenderInfoIn, GameRenderer gameRendererIn, LightTexture lightmapIn, Matrix4f projectionIn, CallbackInfo ci) {
private void onStartHand(PoseStack matrixStackIn, float partialTicks, long finishTimeNano, boolean drawBlockOutline, Camera activeRenderInfoIn, GameRenderer gameRendererIn, LightTexture lightmapIn, Matrix4f projectionIn, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks, matrixStackIn, projectionIn));
}

View File

@ -56,7 +56,7 @@ public class Baritone implements IBaritone {
static {
threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>());
dir = new File(Minecraft.getInstance().gameDir, "baritone");
dir = new File(Minecraft.getInstance().gameDirectory, "baritone");
if (!Files.exists(dir.toPath())) {
try {
Files.createDirectories(dir.toPath());

View File

@ -20,18 +20,24 @@ package baritone.behavior;
import baritone.Baritone;
import baritone.api.event.events.TickEvent;
import baritone.utils.ToolSet;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.item.*;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.InteractionHand;
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;
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;
@ -106,7 +112,7 @@ public final class InventoryBehavior extends Behavior {
return -1;
}
private int bestToolAgainst(Block against, Class<? extends ToolItem> cla$$) {
private int bestToolAgainst(Block against, Class<? extends DiggerItem> cla$$) {
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
int bestInd = -1;
double bestSpeed = -1;
@ -116,7 +122,7 @@ public final class InventoryBehavior extends Behavior {
continue;
}
if (cla$$.isInstance(stack.getItem())) {
double speed = ToolSet.calculateSpeedVsBlock(stack, against.getDefaultState()); // takes into account enchants
double speed = ToolSet.calculateSpeedVsBlock(stack, against.defaultBlockState()); // takes into account enchants
if (speed > bestSpeed) {
bestSpeed = speed;
bestInd = i;
@ -137,7 +143,7 @@ public final class InventoryBehavior extends Behavior {
public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) {
BlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z, baritone.bsi.get0(x, y, z));
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof BlockItem && maybe.equals(((BlockItem) stack.getItem()).getBlock().getStateForPlacement(new BlockItemUseContext(new ItemUseContext(ctx.world(), ctx.player(), Hand.MAIN_HAND, stack, new BlockRayTraceResult(new Vector3d(ctx.player().getPositionVec().x, ctx.player().getPositionVec().y, ctx.player().getPositionVec().z), Direction.UP, ctx.playerFeet(), false)) {}))))) {
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof BlockItem && maybe.equals(((BlockItem) stack.getItem()).getBlock().getStateForPlacement(new BlockPlaceContext(new UseOnContext(ctx.world(), ctx.player(), InteractionHand.MAIN_HAND, stack, new BlockHitResult(new Vec3(ctx.player().getPositionVec().x, ctx.player().getPositionVec().y, ctx.player().getPositionVec().z), Direction.UP, ctx.playerFeet(), false)) {}))))) {
return true; // gotem
}
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof BlockItem && ((BlockItem) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
@ -152,8 +158,8 @@ public final class InventoryBehavior extends Behavior {
}
public boolean throwaway(boolean select, Predicate<? super ItemStack> desired) {
ClientPlayerEntity p = ctx.player();
NonNullList<ItemStack> inv = p.inventory.mainInventory;
LocalPlayer p = ctx.player();
NonNullList<ItemStack> inv = p.inventory.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
@ -163,12 +169,12 @@ public final class InventoryBehavior extends Behavior {
// acceptableThrowawayItems to the CalculationContext
if (desired.test(item)) {
if (select) {
p.inventory.currentItem = i;
p.inventory.selected = i;
}
return true;
}
}
if (desired.test(p.inventory.offHandInventory.get(0))) {
if (desired.test(p.inventory.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
@ -178,7 +184,7 @@ public final class InventoryBehavior extends Behavior {
ItemStack item = inv.get(i);
if (item.isEmpty() || item.getItem() instanceof PickaxeItem) {
if (select) {
p.inventory.currentItem = i;
p.inventory.selected = i;
}
return true;
}

View File

@ -23,9 +23,6 @@ import baritone.api.event.events.BlockInteractEvent;
import baritone.api.utils.BetterBlockPos;
import baritone.cache.ContainerMemory;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.BedBlock;
import net.minecraft.item.ItemStack;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -33,6 +30,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.BedBlock;
/**

View File

@ -36,13 +36,12 @@ import baritone.pathing.path.PathExecutor;
import baritone.utils.PathRenderer;
import baritone.utils.PathingCommandContext;
import baritone.utils.pathing.Favoring;
import net.minecraft.util.math.BlockPos;
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 {

View File

@ -21,17 +21,16 @@ import baritone.api.utils.BlockUtils;
import baritone.utils.pathing.PathingBlockType;
import com.google.common.collect.ImmutableSet;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Map;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
/**
* @author Brady
@ -180,7 +179,7 @@ public final class CachedChunk {
}
}
public final BlockState getBlock(int x, int y, int z, RegistryKey<World> dimension) {
public final BlockState getBlock(int x, int y, int z, ResourceKey<Level> dimension) {
int index = getPositionIndex(x, y, z);
PathingBlockType type = getType(index);
int internalPos = z << 4 | x;
@ -202,15 +201,15 @@ public final class CachedChunk {
}
if (type == PathingBlockType.SOLID) {
if (y == 127 && dimension == World.THE_NETHER) {
if (y == 127 && dimension == Level.NETHER) {
// nether roof is always unbreakable
return Blocks.BEDROCK.getDefaultState();
return Blocks.BEDROCK.defaultBlockState();
}
if (y < 5 && dimension == World.OVERWORLD) {
if (y < 5 && dimension == Level.OVERWORLD) {
// solid blocks below 5 are commonly bedrock
// however, returning bedrock always would be a little yikes
// discourage paths that include breaking blocks below 5 a little more heavily just so that it takes paths breaking what's known to be stone (at 5 or above) instead of what could maybe be bedrock (below 5)
return Blocks.OBSIDIAN.getDefaultState();
return Blocks.OBSIDIAN.defaultBlockState();
}
}
return ChunkPacker.pathingTypeToBlock(type, dimension);

View File

@ -20,11 +20,6 @@ package baritone.cache;
import baritone.Baritone;
import baritone.api.cache.ICachedRegion;
import baritone.api.utils.BlockUtils;
import net.minecraft.block.BlockState;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
@ -32,6 +27,10 @@ import java.nio.file.Paths;
import java.util.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
/**
* @author Brady
@ -62,14 +61,14 @@ public final class CachedRegion implements ICachedRegion {
*/
private final int z;
private final RegistryKey<World> dimension;
private final ResourceKey<Level> dimension;
/**
* Has this region been modified since its most recent load or save
*/
private boolean hasUnsavedChanges;
CachedRegion(int x, int z, RegistryKey<World> dimension) {
CachedRegion(int x, int z, ResourceKey<Level> dimension) {
this.x = x;
this.z = z;
this.hasUnsavedChanges = false;

View File

@ -25,12 +25,6 @@ import baritone.api.cache.IWorldData;
import baritone.api.utils.Helper;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -39,6 +33,11 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
/**
* @author Brady
@ -71,11 +70,11 @@ public final class CachedWorld implements ICachedWorld, Helper {
* All chunk positions pending packing. This map will be updated in-place if a new update to the chunk occurs
* while waiting in the queue for the packer thread to get to it.
*/
private final Map<ChunkPos, Chunk> toPackMap = new ConcurrentHashMap<>();
private final Map<ChunkPos, LevelChunk> toPackMap = new ConcurrentHashMap<>();
private final RegistryKey<World> dimension;
private final ResourceKey<Level> dimension;
CachedWorld(Path directory, RegistryKey<World> dimension) {
CachedWorld(Path directory, ResourceKey<Level> dimension) {
if (!Files.exists(directory)) {
try {
Files.createDirectories(directory);
@ -103,7 +102,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
}
@Override
public final void queueForPacking(Chunk chunk) {
public final void queueForPacking(LevelChunk chunk) {
if (toPackMap.put(chunk.getPos(), chunk) == null) {
toPackQueue.add(chunk.getPos());
}
@ -308,7 +307,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
while (true) {
try {
ChunkPos pos = toPackQueue.take();
Chunk chunk = toPackMap.remove(pos);
LevelChunk chunk = toPackMap.remove(pos);
CachedChunk cached = ChunkPacker.pack(chunk);
CachedWorld.this.updateCachedChunk(cached);
//System.out.println("Processed chunk at " + chunk.x + "," + chunk.z);

View File

@ -21,14 +21,20 @@ import baritone.api.utils.BlockUtils;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.pathing.PathingBlockType;
import net.minecraft.block.*;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.palette.PalettedContainer;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AirBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DoublePlantBlock;
import net.minecraft.world.level.block.FlowerBlock;
import net.minecraft.world.level.block.TallGrassBlock;
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.PalettedContainer;
import net.minecraft.world.phys.Vec3;
import java.util.*;
import static baritone.utils.BlockStateInterface.getFromChunk;
@ -41,15 +47,15 @@ public final class ChunkPacker {
private ChunkPacker() {}
public static CachedChunk pack(Chunk chunk) {
public static CachedChunk pack(LevelChunk chunk) {
//long start = System.nanoTime() / 1000000L;
Map<String, List<BlockPos>> specialBlocks = new HashMap<>();
BitSet bitSet = new BitSet(CachedChunk.SIZE);
try {
ChunkSection[] chunkInternalStorageArray = chunk.getSections();
LevelChunkSection[] chunkInternalStorageArray = chunk.getSections();
for (int y0 = 0; y0 < 16; y0++) {
ChunkSection extendedblockstorage = chunkInternalStorageArray[y0];
LevelChunkSection extendedblockstorage = chunkInternalStorageArray[y0];
if (extendedblockstorage == null) {
// any 16x16x16 area that's all air will have null storage
// for example, in an ocean biome, with air from y=64 to y=256
@ -61,7 +67,7 @@ public final class ChunkPacker {
// since a bitset is initialized to all zero, and air is saved as zeros
continue;
}
PalettedContainer<BlockState> bsc = extendedblockstorage.getData();
PalettedContainer<BlockState> bsc = extendedblockstorage.getStates();
int yReal = y0 << 4;
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
// for better cache locality, iterate in that order
@ -101,14 +107,14 @@ public final class ChunkPacker {
continue https;
}
}
blocks[z << 4 | x] = Blocks.AIR.getDefaultState();
blocks[z << 4 | x] = Blocks.AIR.defaultBlockState();
}
}
// @formatter:on
return new CachedChunk(chunk.getPos().x, chunk.getPos().z, bitSet, blocks, specialBlocks, System.currentTimeMillis());
}
private static PathingBlockType getPathingBlockType(BlockState state, Chunk chunk, int x, int y, int z) {
private static PathingBlockType getPathingBlockType(BlockState state, LevelChunk chunk, int x, int y, int z) {
Block block = state.getBlock();
if (MovementHelper.isWater(state)) {
// only water source blocks are plausibly usable, flowing water should be avoid
@ -125,7 +131,7 @@ public final class ChunkPacker {
return PathingBlockType.AVOID;
}
if (x == 0 || x == 15 || z == 0 || z == 15) {
Vector3d flow = state.getFluidState().getFlow(chunk.getWorld(), new BlockPos(x + chunk.getPos().x << 4, y, z + chunk.getPos().z << 4));
Vec3 flow = state.getFluidState().getFlow(chunk.getLevel(), new BlockPos(x + chunk.getPos().x << 4, y, z + chunk.getPos().z << 4));
if (flow.x != 0.0 || flow.z != 0.0) {
return PathingBlockType.WATER;
}
@ -148,24 +154,24 @@ public final class ChunkPacker {
return PathingBlockType.SOLID;
}
public static BlockState pathingTypeToBlock(PathingBlockType type, RegistryKey<World> dimension) {
public static BlockState pathingTypeToBlock(PathingBlockType type, ResourceKey<Level> dimension) {
switch (type) {
case AIR:
return Blocks.AIR.getDefaultState();
return Blocks.AIR.defaultBlockState();
case WATER:
return Blocks.WATER.getDefaultState();
return Blocks.WATER.defaultBlockState();
case AVOID:
return Blocks.LAVA.getDefaultState();
return Blocks.LAVA.defaultBlockState();
case SOLID:
// Dimension solid types
if (dimension == World.OVERWORLD) {
return Blocks.STONE.getDefaultState();
if (dimension == Level.OVERWORLD) {
return Blocks.STONE.defaultBlockState();
}
if (dimension == World.THE_NETHER) {
return Blocks.NETHERRACK.getDefaultState();
if (dimension == Level.NETHER) {
return Blocks.NETHERRACK.defaultBlockState();
}
if (dimension == World.THE_END) {
return Blocks.END_STONE.getDefaultState();
if (dimension == Level.END) {
return Blocks.END_STONE.defaultBlockState();
}
default:
return null;

View File

@ -23,15 +23,14 @@ import baritone.api.cache.IRememberedInventory;
import baritone.api.utils.IPlayerContext;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.*;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.item.ItemStack;
public class ContainerMemory implements IContainerMemory {
@ -55,7 +54,7 @@ public class ContainerMemory implements IContainerMemory {
}
private void read(byte[] bytes) throws IOException {
PacketBuffer in = new PacketBuffer(Unpooled.wrappedBuffer(bytes));
FriendlyByteBuf in = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes));
int chests = in.readInt();
for (int i = 0; i < chests; i++) {
int x = in.readInt();
@ -77,12 +76,12 @@ public class ContainerMemory implements IContainerMemory {
return;
}
ByteBuf buf = Unpooled.buffer(0, Integer.MAX_VALUE);
PacketBuffer out = new PacketBuffer(buf);
FriendlyByteBuf out = new FriendlyByteBuf(buf);
out.writeInt(inventories.size());
for (Map.Entry<BlockPos, RememberedInventory> entry : inventories.entrySet()) {
out = new PacketBuffer(out.writeInt(entry.getKey().getX()));
out = new PacketBuffer(out.writeInt(entry.getKey().getY()));
out = new PacketBuffer(out.writeInt(entry.getKey().getZ()));
out = new FriendlyByteBuf(out.writeInt(entry.getKey().getX()));
out = new FriendlyByteBuf(out.writeInt(entry.getKey().getY()));
out = new FriendlyByteBuf(out.writeInt(entry.getKey().getZ()));
out = writeItemStacks(entry.getValue().getContents(), out);
}
Files.write(saveTo, out.array());
@ -110,31 +109,31 @@ public class ContainerMemory implements IContainerMemory {
}
public static List<ItemStack> readItemStacks(byte[] bytes) throws IOException {
PacketBuffer in = new PacketBuffer(Unpooled.wrappedBuffer(bytes));
FriendlyByteBuf in = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes));
return readItemStacks(in);
}
public static List<ItemStack> readItemStacks(PacketBuffer in) throws IOException {
public static List<ItemStack> readItemStacks(FriendlyByteBuf in) throws IOException {
int count = in.readInt();
List<ItemStack> result = new ArrayList<>();
for (int i = 0; i < count; i++) {
result.add(in.readItemStack());
result.add(in.readItem());
}
return result;
}
public static byte[] writeItemStacks(List<ItemStack> write) {
ByteBuf buf = Unpooled.buffer(0, Integer.MAX_VALUE);
PacketBuffer out = new PacketBuffer(buf);
FriendlyByteBuf out = new FriendlyByteBuf(buf);
out = writeItemStacks(write, out);
return out.array();
}
public static PacketBuffer writeItemStacks(List<ItemStack> write, PacketBuffer out2) {
PacketBuffer out = out2; // avoid reassigning an argument LOL
out = new PacketBuffer(out.writeInt(write.size()));
public static FriendlyByteBuf writeItemStacks(List<ItemStack> write, FriendlyByteBuf out2) {
FriendlyByteBuf out = out2; // avoid reassigning an argument LOL
out = new FriendlyByteBuf(out.writeInt(write.size()));
for (ItemStack stack : write) {
out = out.writeItemStack(stack);
out = out.writeItem(stack);
}
return out;
}

View File

@ -22,11 +22,10 @@ import baritone.api.cache.ICachedWorld;
import baritone.api.cache.IContainerMemory;
import baritone.api.cache.IWaypointCollection;
import baritone.api.cache.IWorldData;
import net.minecraft.util.RegistryKey;
import net.minecraft.world.World;
import java.io.IOException;
import java.nio.file.Path;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
/**
* Data about a world, from baritone's point of view. Includes cached chunks, waypoints, and map data.
@ -40,9 +39,9 @@ public class WorldData implements IWorldData {
private final ContainerMemory containerMemory;
//public final MapData map;
public final Path directory;
public final RegistryKey<World> dimension;
public final ResourceKey<Level> dimension;
WorldData(Path directory, RegistryKey<World> dimension) {
WorldData(Path directory, ResourceKey<Level> dimension) {
this.directory = directory;
this.cache = new CachedWorld(directory.resolve("cache"), dimension);
this.waypoints = new WaypointCollection(directory.resolve("waypoints"));

View File

@ -20,11 +20,6 @@ package baritone.cache;
import baritone.Baritone;
import baritone.api.cache.IWorldProvider;
import baritone.api.utils.Helper;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.RegistryKey;
import net.minecraft.world.DimensionType;
import net.minecraft.world.World;
import net.minecraft.world.storage.FolderName;
import org.apache.commons.lang3.SystemUtils;
import java.io.File;
@ -35,6 +30,11 @@ import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.storage.LevelResource;
/**
* @author Brady
@ -56,7 +56,7 @@ public class WorldProvider implements IWorldProvider, Helper {
*
* @param world The world's Registry Data
*/
public final void initWorld(RegistryKey<World> world) {
public final void initWorld(ResourceKey<Level> world) {
File directory;
File readme;
@ -64,7 +64,7 @@ public class WorldProvider implements IWorldProvider, Helper {
// If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
if (mc.isSingleplayer()) {
directory = DimensionType.getDimensionFolder(world, integratedServer.func_240776_a_(FolderName.DOT).toFile());
directory = DimensionType.getStorageFolder(world, integratedServer.getWorldPath(LevelResource.ROOT).toFile());
// Gets the "depth" of this directory relative the the game's run directory, 2 is the location of the world
if (directory.toPath().relativize(mc.gameDir.toPath()).getNameCount() != 2) {
@ -90,7 +90,7 @@ public class WorldProvider implements IWorldProvider, Helper {
} catch (IOException ignored) {}
// We will actually store the world data in a subfolder: "DIM<id>"
Path dir = DimensionType.getDimensionFolder(world, directory).toPath();
Path dir = DimensionType.getStorageFolder(world, directory).toPath();
if (!Files.exists(dir)) {
try {
Files.createDirectories(dir);

View File

@ -22,17 +22,16 @@ import baritone.api.cache.IWorldScanner;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.api.utils.IPlayerContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.palette.PalettedContainer;
import net.minecraft.world.chunk.AbstractChunkProvider;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import java.util.*;
import java.util.stream.IntStream;
import net.minecraft.client.multiplayer.ClientChunkCache;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.state.BlockState;
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.PalettedContainer;
public enum WorldScanner implements IWorldScanner {
@ -47,7 +46,7 @@ public enum WorldScanner implements IWorldScanner {
if (filter.blocks().isEmpty()) {
return res;
}
ClientChunkProvider chunkProvider = (ClientChunkProvider) ctx.world().getChunkProvider();
ClientChunkCache chunkProvider = (ClientChunkCache) ctx.world().getChunkProvider();
int maxSearchRadiusSq = maxSearchRadius * maxSearchRadius;
int playerChunkX = ctx.playerFeet().getX() >> 4;
@ -71,7 +70,7 @@ public enum WorldScanner implements IWorldScanner {
foundChunks = true;
int chunkX = xoff + playerChunkX;
int chunkZ = zoff + playerChunkZ;
Chunk chunk = chunkProvider.getChunk(chunkX, chunkZ, null, false);
LevelChunk chunk = chunkProvider.getChunk(chunkX, chunkZ, null, false);
if (chunk == null) {
continue;
}
@ -97,8 +96,8 @@ public enum WorldScanner implements IWorldScanner {
return Collections.emptyList();
}
ClientChunkProvider chunkProvider = (ClientChunkProvider) ctx.world().getChunkProvider();
Chunk chunk = chunkProvider.getChunk(pos.x, pos.z, null, false);
ClientChunkCache chunkProvider = (ClientChunkCache) ctx.world().getChunkProvider();
LevelChunk chunk = chunkProvider.getChunk(pos.x, pos.z, null, false);
int playerY = ctx.playerFeet().getY();
if (chunk == null || chunk.isEmpty()) {
@ -117,7 +116,7 @@ public enum WorldScanner implements IWorldScanner {
@Override
public int repack(IPlayerContext ctx, int range) {
AbstractChunkProvider chunkProvider = ctx.world().getChunkProvider();
ChunkSource chunkProvider = ctx.world().getChunkProvider();
ICachedWorld cachedWorld = ctx.worldData().getCachedWorld();
BetterBlockPos playerPos = ctx.playerFeet();
@ -133,7 +132,7 @@ public enum WorldScanner implements IWorldScanner {
int queued = 0;
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
Chunk chunk = chunkProvider.getChunk(x, z, false);
LevelChunk chunk = chunkProvider.getChunk(x, z, false);
if (chunk != null && !chunk.isEmpty()) {
queued++;
@ -145,17 +144,17 @@ public enum WorldScanner implements IWorldScanner {
return queued;
}
private boolean scanChunkInto(int chunkX, int chunkZ, Chunk chunk, BlockOptionalMetaLookup filter, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) {
ChunkSection[] chunkInternalStorageArray = chunk.getSections();
private boolean scanChunkInto(int chunkX, int chunkZ, LevelChunk chunk, BlockOptionalMetaLookup filter, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) {
LevelChunkSection[] chunkInternalStorageArray = chunk.getSections();
boolean foundWithinY = false;
for (int yIndex = 0; yIndex < 16; yIndex++) {
int y0 = coordinateIterationOrder[yIndex];
ChunkSection section = chunkInternalStorageArray[y0];
if (section == null || ChunkSection.isEmpty(section)) {
LevelChunkSection section = chunkInternalStorageArray[y0];
if (section == null || LevelChunkSection.isEmpty(section)) {
continue;
}
int yReal = y0 << 4;
PalettedContainer<BlockState> bsc = section.getData();
PalettedContainer<BlockState> bsc = section.getStates();
for (int yy = 0; yy < 16; yy++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {

View File

@ -34,13 +34,12 @@ 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.network.chat.BaseComponent;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.util.Tuple;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
@ -79,14 +78,14 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
if (settings.echoCommands.value) {
String msg = command + rest;
String toDisplay = settings.censorRanCommands.value ? command + " ..." : msg;
TextComponent component = new StringTextComponent(String.format("> %s", toDisplay));
BaseComponent component = new TextComponent(String.format("> %s", toDisplay));
component.setStyle(component.getStyle()
.setFormatting(TextFormatting.WHITE)
.setHoverEvent(new HoverEvent(
.withColor(ChatFormatting.WHITE)
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new StringTextComponent("Click to rerun command")
new TextComponent("Click to rerun command")
))
.setClickEvent(new ClickEvent(
.withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + msg
)));

View File

@ -24,15 +24,14 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.IFormattableTextComponent;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.item.ItemStack;
public class ChestsCommand extends Command {
@ -54,8 +53,8 @@ public class ChestsCommand extends Command {
IRememberedInventory inv = entry.getValue();
logDirect(pos.toString());
for (ItemStack item : inv.getContents()) {
IFormattableTextComponent component = (IFormattableTextComponent) item.getTextComponent();
component.appendString(String.format(" x %d", item.getCount()));
MutableComponent component = (MutableComponent) item.getDisplayName();
component.append(String.format(" x %d", item.getCount()));
logDirect(component);
}
}

View File

@ -23,11 +23,10 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.pathing.goals.GoalBlock;
import net.minecraft.entity.Entity;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import net.minecraft.world.entity.Entity;
public class ComeCommand extends Command {
@ -42,7 +41,7 @@ public class ComeCommand extends Command {
if (entity == null) {
throw new CommandInvalidStateException("render view entity is null");
}
baritone.getCustomGoalProcess().setGoalAndPath(new GoalBlock(entity.getPosition()));
baritone.getCustomGoalProcess().setGoalAndPath(new GoalBlock(entity.blockPosition()));
logDirect("Coming");
}

View File

@ -23,13 +23,12 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.datatypes.BlockById;
import baritone.api.command.exception.CommandException;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.block.Block;
import net.minecraft.util.registry.Registry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import net.minecraft.core.Registry;
import net.minecraft.world.level.block.Block;
public class FindCommand extends Command {

View File

@ -26,16 +26,15 @@ import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.NearbyPlayer;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
public class FollowCommand extends Command {
@ -136,7 +135,7 @@ public class FollowCommand extends Command {
@KeepName
private enum FollowGroup {
ENTITIES(LivingEntity.class::isInstance),
PLAYERS(PlayerEntity.class::isInstance); /* ,
PLAYERS(Player.class::isInstance); /* ,
FRIENDLY(entity -> entity.getAttackTarget() != HELPER.mc.player),
HOSTILE(FRIENDLY.filter.negate()); */
final Predicate<Entity> filter;

View File

@ -25,16 +25,13 @@ 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 net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.TextComponent;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
@ -88,8 +85,8 @@ public class HelpCommand extends Command {
logDirect("");
command.getLongDesc().forEach(this::logDirect);
logDirect("");
TextComponent returnComponent = new StringTextComponent("Click to return to the help menu");
returnComponent.setStyle(returnComponent.getStyle().setClickEvent(new ClickEvent(
BaseComponent returnComponent = new TextComponent("Click to return to the help menu");
returnComponent.setStyle(returnComponent.getStyle().withClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + label
)));

View File

@ -37,16 +37,14 @@ import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.utils.IRenderer;
import net.minecraft.block.Blocks;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.vector.Vector3i;
import java.awt.*;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Stream;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.AABB;
public class SelCommand extends Command {
@ -66,7 +64,7 @@ public class SelCommand extends Command {
float lineWidth = Baritone.settings().selectionLineWidth.value;
boolean ignoreDepth = Baritone.settings().renderSelectionIgnoreDepth.value;
IRenderer.startLines(color, opacity, lineWidth, ignoreDepth);
IRenderer.drawAABB(event.getModelViewStack(), new AxisAlignedBB(pos1, pos1.add(1, 1, 1)));
IRenderer.drawAABB(event.getModelViewStack(), new AABB(pos1, pos1.add(1, 1, 1)));
IRenderer.endLines(ignoreDepth);
}
});
@ -143,7 +141,7 @@ public class SelCommand extends Command {
);
}
for (ISelection selection : selections) {
Vector3i size = selection.size();
Vec3i size = selection.size();
BetterBlockPos min = selection.min();
ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type);
if (action == Action.WALLS) {

Some files were not shown because too many files have changed in this diff Show More