most of the way there

This commit is contained in:
Leijurv
2019-06-10 18:25:20 -07:00
parent dba496471e
commit 8758c77ac0
60 changed files with 505 additions and 941 deletions

View File

@@ -218,7 +218,7 @@ public class Baritone implements IBaritone {
new Thread(() -> {
try {
Thread.sleep(100);
Helper.mc.addScheduledTask(() -> Helper.mc.displayScreen(new GuiClick()));
Helper.mc.execute(() -> Helper.mc.displayGuiScreen(new GuiClick()));
} catch (Exception ignored) {}
}).start();
}

View File

@@ -21,10 +21,10 @@ import baritone.Baritone;
import baritone.api.event.events.TickEvent;
import baritone.utils.ToolSet;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockState;
import net.minecraft.client.entity.ClientPlayerEntity;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ClickType;
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.item.*;
import net.minecraft.util.NonNullList;
@@ -46,14 +46,14 @@ public final class InventoryBehavior extends Behavior {
if (event.getType() == TickEvent.Type.OUT) {
return;
}
if (ctx.player().openContainer != ctx.player().inventoryContainer) {
if (ctx.player().openContainer != ctx.player().container) {
// we have a crafting table or a chest or something open
return;
}
if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory
swapWithHotBar(firstValidThrowaway(), 8);
}
int pick = bestToolAgainst(Blocks.STONE, ItemPickaxe.class);
int pick = bestToolAgainst(Blocks.STONE, PickaxeItem.class);
if (pick >= 9) {
swapWithHotBar(pick, 0);
}
@@ -88,7 +88,7 @@ public final class InventoryBehavior extends Behavior {
}
private void swapWithHotBar(int inInventory, int inHotbar) {
ctx.playerController().windowClick(ctx.player().inventoryContainer.windowId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player());
ctx.playerController().windowClick(ctx.player().container.windowId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player());
}
private int firstValidThrowaway() { // TODO offhand idk
@@ -101,7 +101,7 @@ public final class InventoryBehavior extends Behavior {
return -1;
}
private int bestToolAgainst(Block against, Class<? extends ItemTool> klass) {
private int bestToolAgainst(Block against, Class<? extends ToolItem> klass) {
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
int bestInd = -1;
double bestSpeed = -1;
@@ -132,7 +132,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);
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof BlockItem && ((BlockItem) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
return true; // gotem
}
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
@@ -168,7 +168,7 @@ public final class InventoryBehavior extends Behavior {
// so not a shovel, not a hoe, not a block, etc
for (byte i = 0; i < 9; i++) {
ItemStack item = inv.get(i);
if (item.isEmpty() || item.getItem() instanceof ItemPickaxe) {
if (item.isEmpty() || item.getItem() instanceof PickaxeItem) {
if (select) {
p.inventory.currentItem = i;
}

View File

@@ -20,26 +20,10 @@ package baritone.behavior;
import baritone.Baritone;
import baritone.api.cache.Waypoint;
import baritone.api.event.events.BlockInteractEvent;
import baritone.api.event.events.PacketEvent;
import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.TickEvent;
import baritone.api.event.events.type.EventState;
import baritone.cache.ContainerMemory;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBed;
import net.minecraft.init.Blocks;
import net.minecraft.block.BedBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketCloseWindow;
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
import net.minecraft.network.play.server.SPacketCloseWindow;
import net.minecraft.network.play.server.SPacketOpenWindow;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityLockable;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import java.io.IOException;
import java.nio.file.Files;
@@ -54,111 +38,13 @@ import java.util.*;
*/
public final class MemoryBehavior extends Behavior {
private final List<FutureInventory> futureInventories = new ArrayList<>(); // this is per-bot
private Integer enderChestWindowId; // nae nae
public MemoryBehavior(Baritone baritone) {
super(baritone);
}
@Override
public synchronized void onTick(TickEvent event) {
if (!Baritone.settings().containerMemory.value) {
return;
}
if (event.getType() == TickEvent.Type.OUT) {
enderChestWindowId = null;
futureInventories.clear();
}
}
@Override
public synchronized void onPlayerUpdate(PlayerUpdateEvent event) {
if (event.getState() == EventState.PRE) {
updateInventory();
}
}
@Override
public synchronized void onSendPacket(PacketEvent event) {
if (!Baritone.settings().containerMemory.value) {
return;
}
Packet p = event.getPacket();
if (event.getState() == EventState.PRE) {
if (p instanceof CPacketPlayerTryUseItemOnBlock) {
CPacketPlayerTryUseItemOnBlock packet = event.cast();
TileEntity tileEntity = ctx.world().getTileEntity(packet.getPos());
// if tileEntity is an ender chest, we don't need to do anything. ender chests are treated the same regardless of what coordinate right clicked
// Ensure the TileEntity is a container of some sort
if (tileEntity instanceof TileEntityLockable) {
TileEntityLockable lockable = (TileEntityLockable) tileEntity;
int size = lockable.getSizeInventory();
BlockPos position = tileEntity.getPos();
BlockPos adj = neighboringConnectedBlock(position);
System.out.println(position + " " + adj);
if (adj != null) {
size *= 2; // double chest or double trapped chest
if (adj.getX() < position.getX() || adj.getZ() < position.getZ()) {
position = adj; // standardize on the lower coordinate, regardless of which side of the large chest we right clicked
}
}
this.futureInventories.add(new FutureInventory(System.nanoTime() / 1000000L, size, lockable.getGuiID(), position));
}
}
if (p instanceof CPacketCloseWindow) {
getCurrent().save();
}
}
}
@Override
public synchronized void onReceivePacket(PacketEvent event) {
if (!Baritone.settings().containerMemory.value) {
return;
}
Packet p = event.getPacket();
if (event.getState() == EventState.PRE) {
if (p instanceof SPacketOpenWindow) {
SPacketOpenWindow packet = event.cast();
// Remove any entries that were created over a second ago, this should make up for INSANE latency
futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000);
System.out.println("Received packet " + packet.getGuiId() + " " + packet.getEntityId() + " " + packet.getSlotCount() + " " + packet.getWindowId());
System.out.println(packet.getWindowTitle());
if (packet.getWindowTitle() instanceof TextComponentTranslation && ((TextComponentTranslation) packet.getWindowTitle()).getKey().equals("container.enderchest")) {
// title is not customized (i.e. this isn't just a renamed shulker)
enderChestWindowId = packet.getWindowId();
return;
}
futureInventories.stream()
.filter(i -> i.getType().equals(packet.getGuiId()) && i.slots == packet.getSlotCount())
.findFirst().ifPresent(matched -> {
// Remove the future inventory
futureInventories.remove(matched);
// Setup the remembered inventory
getCurrentContainer().setup(matched.pos, packet.getWindowId(), packet.getSlotCount());
});
}
if (p instanceof SPacketCloseWindow) {
getCurrent().save();
}
}
}
@Override
public void onBlockInteract(BlockInteractEvent event) {
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BlockBed) {
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BedBlock) {
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, event.getPos()));
}
}
@@ -168,85 +54,6 @@ public final class MemoryBehavior extends Behavior {
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("death", Waypoint.Tag.DEATH, ctx.playerFeet()));
}
private void updateInventory() {
if (!Baritone.settings().containerMemory.value) {
return;
}
int windowId = ctx.player().openContainer.windowId;
if (enderChestWindowId != null) {
if (windowId == enderChestWindowId) {
getCurrent().contents = ctx.player().openContainer.getInventory().subList(0, 27);
} else {
getCurrent().save();
enderChestWindowId = null;
}
}
if (getCurrentContainer() != null) {
getCurrentContainer().getInventoryFromWindow(windowId).ifPresent(inventory -> inventory.updateFromOpenWindow(ctx));
}
}
private ContainerMemory getCurrentContainer() {
if (baritone.getWorldProvider().getCurrentWorld() == null) {
return null;
}
return (ContainerMemory) baritone.getWorldProvider().getCurrentWorld().getContainerMemory();
}
private BlockPos neighboringConnectedBlock(BlockPos in) {
BlockStateInterface bsi = baritone.bsi;
Block block = bsi.get0(in).getBlock();
if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) {
return null; // other things that have contents, but can be placed adjacent without combining
}
for (int i = 0; i < 4; i++) {
BlockPos adj = in.offset(Direction.byHorizontalIndex(i));
if (bsi.get0(adj).getBlock() == block) {
return adj;
}
}
return null;
}
/**
* An inventory that we are not yet fully aware of, but are expecting to exist at some point in the future.
*/
private static final class FutureInventory {
/**
* The time that we initially expected the inventory to be provided, in milliseconds
*/
private final long time;
/**
* The amount of slots in the inventory
*/
private final int slots;
/**
* The type of inventory
*/
private final String type;
/**
* The position of the inventory container
*/
private final BlockPos pos;
private FutureInventory(long time, int slots, String type, BlockPos pos) {
this.time = time;
this.slots = slots;
this.type = type;
this.pos = pos;
System.out.println("Future inventory created " + time + " " + slots + " " + type + " " + pos);
}
}
public Optional<List<ItemStack>> echest() {
return Optional.ofNullable(getCurrent().contents).map(Collections::unmodifiableList);
}
public EnderChestMemory getCurrent() {
Path path = baritone.getWorldProvider().getCurrentWorld().directory;
return EnderChestMemory.getByServerAndPlayer(path.getParent(), ctx.player().getUniqueID());

View File

@@ -22,8 +22,8 @@ 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.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;

View File

@@ -20,7 +20,7 @@ package baritone.cache;
import baritone.Baritone;
import baritone.api.cache.ICachedRegion;
import baritone.api.utils.BlockUtils;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import java.io.*;

View File

@@ -21,8 +21,6 @@ import baritone.api.utils.BlockUtils;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.pathing.PathingBlockType;
import net.minecraft.block.*;
import net.minecraft.block.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.chunk.BlockStateContainer;
@@ -31,6 +29,8 @@ import net.minecraft.world.chunk.ChunkSection;
import java.util.*;
import static baritone.utils.BlockStateInterface.getFromChunk;
/**
* @author Brady
* @since 8/3/2018
@@ -89,19 +89,20 @@ public final class ChunkPacker {
BlockState[] blocks = new BlockState[256];
for (int z = 0; z < 16; z++) {
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
https:
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
for (int x = 0; x < 16; x++) {
for (int y = 255; y >= 0; y--) {
int index = CachedChunk.getPositionIndex(x, y, z);
if (bitSet.get(index) || bitSet.get(index + 1)) {
blocks[z << 4 | x] = chunk.getBlockState(x, y, z);
blocks[z << 4 | x] = getFromChunk(chunk, x, y, z);
continue https;
}
}
blocks[z << 4 | x] = Blocks.AIR.getDefaultState();
}
}
return new CachedChunk(chunk.x, chunk.z, bitSet, blocks, specialBlocks, System.currentTimeMillis());
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) {
@@ -113,15 +114,15 @@ public final class ChunkPacker {
return PathingBlockType.AVOID;
}
if (
(x != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z)))
|| (x != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z)))
|| (z != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1)))
|| (z != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1)))
(x != 15 && MovementHelper.possiblyFlowing(getFromChunk(chunk, x + 1, y, z)))
|| (x != 0 && MovementHelper.possiblyFlowing(getFromChunk(chunk, x - 1, y, z)))
|| (z != 15 && MovementHelper.possiblyFlowing(getFromChunk(chunk, x, y, z + 1)))
|| (z != 0 && MovementHelper.possiblyFlowing(getFromChunk(chunk, x, y, z - 1)))
) {
return PathingBlockType.AVOID;
}
if (x == 0 || x == 15 || z == 0 || z == 15) {
Vec3d flow = state.getFluidState().getFlow(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4));
Vec3d flow = state.getFluidState().getFlow(chunk.getWorld(), 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;
}
@@ -137,7 +138,7 @@ public final class ChunkPacker {
// however, this failed in the nether when you were near a nether fortress
// because fences check their adjacent blocks in the world for their fence connection status to determine AABB shape
// this caused a nullpointerexception when we saved chunks on unload, because they were unable to check their neighbors
if (block instanceof BlockAir || block instanceof BlockTallGrass || block instanceof BlockDoublePlant || block instanceof BlockFlower) {
if (block instanceof AirBlock || block instanceof TallGrassBlock || block instanceof DoublePlantBlock || block instanceof FlowerBlock) {
return PathingBlockType.AIR;
}

View File

@@ -23,7 +23,7 @@ import baritone.api.utils.Helper;
import baritone.utils.accessor.IAnvilChunkLoader;
import baritone.utils.accessor.IChunkProviderServer;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.world.WorldServer;
import net.minecraft.world.ServerWorld;
import net.minecraft.world.dimension.DimensionType;
import org.apache.commons.lang3.SystemUtils;
@@ -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()) {
WorldServer localServerWorld = integratedServer.getWorld(dimension);
ServerWorld localServerWorld = integratedServer.getWorld(dimension);
IChunkProviderServer provider = (IChunkProviderServer) localServerWorld.getChunkProvider();
IAnvilChunkLoader loader = (IAnvilChunkLoader) provider.getChunkLoader();
directory = loader.getChunkSaveLocation();

View File

@@ -20,8 +20,8 @@ package baritone.cache;
import baritone.api.cache.IWorldScanner;
import baritone.api.utils.IPlayerContext;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockState;
import net.minecraft.client.multiplayer.ChunkProviderClient;
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.world.chunk.BlockStateContainer;
@@ -46,7 +46,7 @@ public enum WorldScanner implements IWorldScanner {
if (blocks.isEmpty()) {
return res;
}
ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider();
ClientChunkProvider chunkProvider = (ClientChunkProvider) ctx.world().getChunkProvider();
int maxSearchRadiusSq = maxSearchRadius * maxSearchRadius;
int playerChunkX = ctx.playerFeet().getX() >> 4;
@@ -70,7 +70,7 @@ public enum WorldScanner implements IWorldScanner {
foundChunks = true;
int chunkX = xoff + playerChunkX;
int chunkZ = zoff + playerChunkZ;
Chunk chunk = chunkProvider.getChunk(chunkX, chunkZ, false, false);
Chunk chunk = chunkProvider.getChunk(chunkX, chunkZ, null, false);
if (chunk == null) {
continue;
}
@@ -96,8 +96,8 @@ public enum WorldScanner implements IWorldScanner {
return Collections.emptyList();
}
ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider();
Chunk chunk = chunkProvider.getChunk(pos.x, pos.z, false, false);
ClientChunkProvider chunkProvider = (ClientChunkProvider) ctx.world().getChunkProvider();
Chunk chunk = chunkProvider.getChunk(pos.x, pos.z, null, false);
int playerY = ctx.playerFeet().getY();
if (chunk == null || chunk.isEmpty()) {
@@ -114,12 +114,12 @@ public enum WorldScanner implements IWorldScanner {
boolean foundWithinY = false;
for (int yIndex = 0; yIndex < 16; yIndex++) {
int y0 = coordinateIterationOrder[yIndex];
ChunkSection extendedblockstorage = chunkInternalStorageArray[y0];
if (extendedblockstorage == null) {
ChunkSection section = chunkInternalStorageArray[y0];
if (section == null || ChunkSection.isEmpty(section)) {
continue;
}
int yReal = y0 << 4;
BlockStateContainer<BlockState> bsc = extendedblockstorage.getData();
BlockStateContainer<BlockState> bsc = section.getData();
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
// for better cache locality, iterate in that order
for (int y = 0; y < 16; y++) {

View File

@@ -84,7 +84,7 @@ public final class GameEventHandler implements IEventBus, Helper {
// to make sure the chunk being unloaded is already loaded.
boolean isPreUnload = state == EventState.PRE
&& type == ChunkEvent.Type.UNLOAD
&& world.getChunkProvider().getChunk(event.getX(), event.getZ(), false, false) != null;
&& world.getChunkProvider().getChunk(event.getX(), event.getZ(), null, false) != null;
if (isPostPopulate || isPreUnload) {
baritone.getWorldProvider().ifWorldLoaded(worldData -> {

View File

@@ -25,12 +25,12 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.ToolSet;
import baritone.utils.pathing.BetterWorldBorder;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockState;
import net.minecraft.client.entity.ClientPlayerEntity;
import net.minecraft.block.BlockState;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -83,7 +83,7 @@ public class CalculationContext {
this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread);
this.toolSet = new ToolSet(player);
this.hasThrowaway = Baritone.settings().allowPlace.value && ((Baritone) baritone).getInventoryBehavior().hasGenericThrowaway();
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.value && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.getDimension().isNether();
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.value && PlayerInventory.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.getDimension().isNether();
this.canSprint = Baritone.settings().allowSprint.value && player.getFoodStats().getFoodLevel() > 6;
this.placeBlockCost = Baritone.settings().blockPlacementPenalty.value;
this.allowBreak = Baritone.settings().allowBreak.value;

View File

@@ -24,7 +24,7 @@ import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.*;
import baritone.api.utils.input.Input;
import baritone.utils.BlockStateInterface;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.item.FallingBlockEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
@@ -107,7 +107,7 @@ public abstract class Movement implements IMovement, MovementHelper {
*/
@Override
public MovementStatus update() {
ctx.player().abilities.isFlying = false;
ctx.player().playerAbilities.isFlying = false;
currentState = updateState(currentState);
if (MovementHelper.isLiquid(ctx, ctx.playerFeet())) {
currentState.setInput(Input.JUMP, true);
@@ -142,7 +142,7 @@ public abstract class Movement implements IMovement, MovementHelper {
}
boolean somethingInTheWay = false;
for (BetterBlockPos blockPos : positionsToBreak) {
if (!ctx.world().getEntitiesWithinAABB(EntityFallingBlock.class, new AxisAlignedBB(0, 0, 0, 1, 1.1, 1).offset(blockPos)).isEmpty() && Baritone.settings().pauseMiningForFallingBlocks.value) {
if (!ctx.world().getEntitiesWithinAABB(FallingBlockEntity.class, new AxisAlignedBB(0, 0, 0, 1, 1.1, 1).offset(blockPos)).isEmpty() && Baritone.settings().pauseMiningForFallingBlocks.value) {
return false;
}
if (!MovementHelper.canWalkThrough(ctx, blockPos)) { // can't break air, so don't try

View File

@@ -27,18 +27,13 @@ import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.BlockStateInterface;
import baritone.utils.ToolSet;
import net.minecraft.block.*;
import net.minecraft.block.state.BlockState;
import net.minecraft.fluid.FlowingFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.IFluidState;
import net.minecraft.fluid.WaterFluid;
import net.minecraft.init.Blocks;
import net.minecraft.init.Fluids;
import net.minecraft.fluid.*;
import net.minecraft.pathfinding.PathType;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.properties.SlabType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
@@ -56,7 +51,7 @@ public interface MovementHelper extends ActionCosts, Helper {
static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, BlockState state) {
Block b = state.getBlock();
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|| b instanceof BlockSilverfish // obvious reasons
|| b instanceof SilverfishBlock // obvious reasons
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|| avoidAdjacentBreaking(bsi, x, y + 1, z, true)
|| avoidAdjacentBreaking(bsi, x + 1, y, z, false)
@@ -73,9 +68,9 @@ public interface MovementHelper extends ActionCosts, Helper {
Block block = state.getBlock();
if (!directlyAbove // it is fine to mine a block that has a falling block directly above, this (the cost of breaking the stacked fallings) is included in cost calculations
// therefore if directlyAbove is true, we will actually ignore if this is falling
&& block instanceof BlockFalling // obviously, this check is only valid for falling blocks
&& block instanceof FallingBlock // obviously, this check is only valid for falling blocks
&& Baritone.settings().avoidUpdatingFallingBlocks.value // and if the setting is enabled
&& BlockFalling.canFallThrough(bsi.get0(x, y - 1, z))) { // and if it would fall (i.e. it's unsupported)
&& FallingBlock.canFallThrough(bsi.get0(x, y - 1, z))) { // and if it would fall (i.e. it's unsupported)
return true; // dont break a block that is adjacent to unsupported gravel because it can cause really weird stuff
}
return !state.getFluidState().isEmpty();
@@ -91,25 +86,25 @@ public interface MovementHelper extends ActionCosts, Helper {
static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, BlockState state) {
Block block = state.getBlock();
if (block instanceof BlockAir) { // early return for most common case
if (block instanceof AirBlock) { // early return for most common case
return true;
}
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block == Blocks.BUBBLE_COLUMN || block instanceof BlockShulkerBox || block instanceof BlockSlab || block instanceof BlockTrapDoor) {
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof SkullBlock || block == Blocks.BUBBLE_COLUMN || block instanceof ShulkerBoxBlock || block instanceof SlabBlock || block instanceof TrapDoorBlock) {
return false;
}
if (Baritone.settings().blocksToAvoid.value.contains(block)) {
return false;
}
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
if (block instanceof DoorBlock || block instanceof FenceGateBlock) {
// Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume
// that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't
// be opened by just interacting.
return block != Blocks.IRON_DOOR;
}
if (block instanceof BlockCarpet) {
if (block instanceof CarpetBlock) {
return canWalkOn(bsi, x, y - 1, z);
}
if (block instanceof BlockSnowLayer) {
if (block instanceof SnowBlock) {
// we've already checked doors and fence gates
// so the only remaining dynamic isPassables are snow and trapdoor
// if they're cached as a top block, we don't know their metadata
@@ -119,7 +114,7 @@ public interface MovementHelper extends ActionCosts, Helper {
}
// the check in BlockSnow.isPassable is layers < 5
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
if (state.get(BlockSnowLayer.LAYERS) >= 3) {
if (state.get(SnowBlock.LAYERS) >= 3) {
return false;
}
// ok, it's low enough we could walk through it, but is it supported?
@@ -134,7 +129,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return false;
}
BlockState up = bsi.get0(x, y + 1, z);
if (!up.getFluidState().isEmpty() || up.getBlock() instanceof BlockLilyPad) {
if (!up.getFluidState().isEmpty() || up.getBlock() instanceof LilyPadBlock) {
return false;
}
return true;
@@ -161,7 +156,7 @@ public interface MovementHelper extends ActionCosts, Helper {
static boolean fullyPassable(BlockState state) {
Block block = state.getBlock();
if (block instanceof BlockAir) { // early return for most common case
if (block instanceof AirBlock) { // early return for most common case
return true;
}
// exceptions - blocks that are isPassable true, but we can't actually jump through
@@ -171,14 +166,14 @@ public interface MovementHelper extends ActionCosts, Helper {
|| block == Blocks.VINE
|| block == Blocks.LADDER
|| block == Blocks.COCOA
|| block instanceof BlockDoor
|| block instanceof BlockFenceGate
|| block instanceof BlockSnow
|| block instanceof DoorBlock
|| block instanceof FenceGateBlock
|| block instanceof SnowBlock
|| !state.getFluidState().isEmpty()
|| block instanceof BlockTrapDoor
|| block instanceof BlockEndPortal
|| block instanceof BlockSkull
|| block instanceof BlockShulkerBox) {
|| block instanceof TrapDoorBlock
|| block instanceof EndPortalBlock
|| block instanceof SkullBlock
|| block instanceof ShulkerBoxBlock) {
return false;
}
// door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
@@ -197,16 +192,16 @@ public interface MovementHelper extends ActionCosts, Helper {
* }
*/
Block block = state.getBlock();
if (block instanceof BlockAir) {
if (block instanceof AirBlock) {
// early return for common cases hehe
return true;
}
if (block instanceof BlockSnowLayer) {
if (block instanceof SnowBlock) {
// as before, default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible)
if (!bsi.worldContainsLoadedChunk(x, z)) {
return true;
}
return state.get(BlockSnowLayer.LAYERS) == 1;
return state.get(SnowBlock.LAYERS) == 1;
}
if (block == Blocks.LARGE_FERN || block == Blocks.TALL_GRASS) {
return true;
@@ -220,11 +215,11 @@ public interface MovementHelper extends ActionCosts, Helper {
}
BlockState state = BlockStateInterface.get(ctx, doorPos);
if (!(state.getBlock() instanceof BlockDoor)) {
if (!(state.getBlock() instanceof DoorBlock)) {
return true;
}
return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN);
return isHorizontalBlockPassable(doorPos, state, playerPos, DoorBlock.OPEN);
}
static boolean isGatePassable(IPlayerContext ctx, BlockPos gatePos, BlockPos playerPos) {
@@ -233,11 +228,11 @@ public interface MovementHelper extends ActionCosts, Helper {
}
BlockState state = BlockStateInterface.get(ctx, gatePos);
if (!(state.getBlock() instanceof BlockFenceGate)) {
if (!(state.getBlock() instanceof FenceGateBlock)) {
return true;
}
return state.get(BlockFenceGate.OPEN);
return state.get(FenceGateBlock.OPEN);
}
static boolean isHorizontalBlockPassable(BlockPos blockPos, BlockState blockState, BlockPos playerPos, BooleanProperty propertyOpen) {
@@ -245,7 +240,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return false;
}
Direction.Axis facing = blockState.get(BlockHorizontal.HORIZONTAL_FACING).getAxis();
Direction.Axis facing = blockState.get(HorizontalBlock.HORIZONTAL_FACING).getAxis();
boolean open = blockState.get(propertyOpen);
Direction.Axis playerFacing;
@@ -285,12 +280,12 @@ public interface MovementHelper extends ActionCosts, Helper {
*/
static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, BlockState state) {
Block block = state.getBlock();
if (block instanceof BlockAir || block == Blocks.MAGMA_BLOCK || block == Blocks.BUBBLE_COLUMN) {
if (block instanceof AirBlock || block == Blocks.MAGMA_BLOCK || block == Blocks.BUBBLE_COLUMN) {
// early return for most common case (air)
// plus magma, which is a normal cube but it hurts you
return false;
}
if (state.isBlockNormalCube()) {
if (isBlockNormalCube(state)) {
return true;
}
if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this
@@ -307,7 +302,7 @@ public interface MovementHelper extends ActionCosts, Helper {
// BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability
BlockState upState = bsi.get0(x, y + 1, z);
Block up = upState.getBlock();
if (up == Blocks.LILY_PAD || up instanceof BlockCarpet) {
if (up == Blocks.LILY_PAD || up instanceof CarpetBlock) {
return true;
}
if (isFlowing(x, y, z, state, bsi) || upState.getFluidState().getFluid() == Fluids.FLOWING_WATER) {
@@ -321,16 +316,16 @@ public interface MovementHelper extends ActionCosts, Helper {
if (Baritone.settings().assumeWalkOnLava.value && isLava(state) && !isFlowing(x, y, z, state, bsi)) {
return true;
}
if (block == Blocks.GLASS || block instanceof BlockStainedGlass) {
if (block == Blocks.GLASS || block instanceof StainedGlassBlock) {
return true;
}
if (block instanceof BlockSlab) {
if (block instanceof SlabBlock) {
if (!Baritone.settings().allowWalkOnBottomSlab.value) {
return state.isTopSolid();
return state.get(SlabBlock.TYPE) != SlabType.BOTTOM;
}
return true;
}
return block instanceof BlockStairs;
return block instanceof StairsBlock;
}
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos, BlockState state) {
@@ -365,7 +360,7 @@ public interface MovementHelper extends ActionCosts, Helper {
// can we look at the center of a side face of this block and likely be able to place?
// (thats how this check is used)
// therefore dont include weird things that we technically could place against (like carpet) but practically can't
return state.isBlockNormalCube() || state.isFullCube() || state.getBlock() == Blocks.GLASS || state.getBlock() instanceof BlockStainedGlass;
return isBlockNormalCube(state) || isFullCube(state) || state.getBlock() == Blocks.GLASS || state.getBlock() instanceof StainedGlassBlock;
}
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, boolean includeFalling) {
@@ -394,7 +389,7 @@ public interface MovementHelper extends ActionCosts, Helper {
result *= mult;
if (includeFalling) {
BlockState above = context.get(x, y + 1, z);
if (above.getBlock() instanceof BlockFalling) {
if (above.getBlock() instanceof FallingBlock) {
result += getMiningDurationTicks(context, x, y + 1, z, above, true);
}
}
@@ -404,8 +399,8 @@ public interface MovementHelper extends ActionCosts, Helper {
}
static boolean isBottomSlab(BlockState state) {
return state.getBlock() instanceof BlockSlab
&& state.get(BlockSlab.TYPE) == SlabType.BOTTOM;
return state.getBlock() instanceof SlabBlock
&& state.get(SlabBlock.TYPE) == SlabType.BOTTOM;
}
/**
@@ -502,6 +497,13 @@ public interface MovementHelper extends ActionCosts, Helper {
|| possiblyFlowing(bsi.get0(x, y, z - 1));
}
static boolean isBlockNormalCube(BlockState state) {
return state.isBlockNormalCube();
}
static boolean isFullCube(BlockState state){
return state.isFullCube();
}
static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) {
IPlayerContext ctx = baritone.getPlayerContext();
@@ -524,7 +526,7 @@ public interface MovementHelper extends ActionCosts, Helper {
double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
Rotation place = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations());
RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance());
if (res != null && res.getType() == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) {
if (res != null && res.getType() == RayTraceResult.Type.BLOCK && ((BlockRayTraceResult) res).getPos().equals(against1) && ((BlockRayTraceResult) res).getPos().offset(((BlockRayTraceResult) res).getFace()).equals(placeAt)) {
state.setTarget(new MovementState.MovementTarget(place, true));
found = true;
@@ -538,7 +540,7 @@ public interface MovementHelper extends ActionCosts, Helper {
}
if (ctx.getSelectedBlock().isPresent()) {
BlockPos selectedBlock = ctx.getSelectedBlock().get();
Direction side = ctx.objectMouseOver().sideHit;
Direction side = ((BlockRayTraceResult) ctx.objectMouseOver()).getFace();
// only way for selectedBlock.equals(placeAt) to be true is if it's replacable
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) {
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());

View File

@@ -27,9 +27,9 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.util.Direction;
public class MovementAscend extends Movement {
@@ -80,18 +80,18 @@ public class MovementAscend extends Movement {
}
}
BlockState srcUp2 = context.get(x, y + 2, z); // used lower down anyway
if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context.bsi, x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us
if (context.get(x, y + 3, z).getBlock() instanceof FallingBlock && (MovementHelper.canWalkThrough(context.bsi, x, y + 1, z) || !(srcUp2.getBlock() instanceof FallingBlock))) {//it would fall on us and possibly suffocate us
// HOWEVER, we assume that we're standing in the start position
// that means that src and src.up(1) are both air
// maybe they aren't now, but they will be by the time this starts
// if the lower one is can't walk through and the upper one is falling, that means that by standing on src
// (the presupposition of this Movement)
// we have necessarily already cleared the entire BlockFalling stack
// we have necessarily already cleared the entire FallingBlock stack
// on top of our head
// as in, if we have a block, then two BlockFallings on top of it
// as in, if we have a block, then two FallingBlocks on top of it
// and that block is x, y+1, z, and we'd have to clear it to even start this movement
// we don't need to worry about those BlockFallings because we've already cleared them
// we don't need to worry about those FallingBlocks because we've already cleared them
return COST_INF;
// you may think we only need to check srcUp2, not srcUp
// however, in the scenario where glitchy world gen where unsupported sand / gravel generates
@@ -189,7 +189,7 @@ public class MovementAscend extends Movement {
double flatDistToNext = xAxis * Math.abs((dest.getX() + 0.5D) - ctx.player().posX) + zAxis * Math.abs((dest.getZ() + 0.5D) - ctx.player().posZ);
double sideDist = zAxis * Math.abs((dest.getX() + 0.5D) - ctx.player().posX) + xAxis * Math.abs((dest.getZ() + 0.5D) - ctx.player().posZ);
double lateralMotion = xAxis * ctx.player().motionZ + zAxis * ctx.player().motionX;
double lateralMotion = xAxis * ctx.player().getMotion().z + zAxis * ctx.player().getMotion().x;
if (Math.abs(lateralMotion) > 0.1) {
return state;
}

View File

@@ -30,10 +30,10 @@ import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.BlockState;
import net.minecraft.client.entity.ClientPlayerEntity;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@@ -116,7 +116,7 @@ public class MovementDescend extends Movement {
}
public static boolean dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, BlockState below, MutableMoveResult res) {
if (frontBreak != 0 && context.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) {
if (frontBreak != 0 && context.get(destX, y + 2, destZ).getBlock() instanceof FallingBlock) {
// if frontBreak is 0 we can actually get through this without updating the falling block and making it actually fall
// but if frontBreak is nonzero, we're breaking blocks in front, so don't let anything fall through this column,
// and potentially replace the water we're going to fall into

View File

@@ -29,8 +29,8 @@ import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;

View File

@@ -25,8 +25,8 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
public class MovementDownward extends Movement {

View File

@@ -31,13 +31,13 @@ import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.state.BlockState;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.LadderBlock;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.fluid.WaterFluid;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@@ -84,7 +84,7 @@ public class MovementFall extends Movement {
Block destBlock = destState.getBlock();
boolean isWater = destState.getFluidState().getFluid() instanceof WaterFluid;
if (!isWater && willPlaceBucket() && !playerFeet.equals(dest)) {
if (!InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().getDimension().isNether()) {
if (!PlayerInventory.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().getDimension().isNether()) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
@@ -105,15 +105,15 @@ public class MovementFall extends Movement {
}
if (playerFeet.equals(dest) && (ctx.player().posY - playerFeet.getY() < 0.094 || isWater)) { // 0.094 because lilypads
if (isWater) { // only match water, not flowing water (which we cannot pick up with a bucket)
if (InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
if (PlayerInventory.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
if (ctx.player().motionY >= 0) {
if (ctx.player().getMotion().y >= 0) {
return state.setInput(Input.CLICK_RIGHT, true);
} else {
return state;
}
} else {
if (ctx.player().motionY >= 0) {
if (ctx.player().getMotion().y >= 0) {
return state.setStatus(MovementStatus.SUCCESS);
} // don't else return state; we need to stay centered because this water might be flowing under the surface
}
@@ -122,8 +122,8 @@ public class MovementFall extends Movement {
}
}
Vec3d destCenter = VecUtils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
if (Math.abs(ctx.player().posX + ctx.player().motionX - destCenter.x) > 0.1 || Math.abs(ctx.player().posZ + ctx.player().motionZ - destCenter.z) > 0.1) {
if (!ctx.player().onGround && Math.abs(ctx.player().motionY) > 0.4) {
if (Math.abs(ctx.player().posX + ctx.player().getMotion().x - destCenter.x) > 0.1 || Math.abs(ctx.player().posZ + ctx.player().getMotion().z - destCenter.z) > 0.1) {
if (!ctx.player().onGround && Math.abs(ctx.player().getMotion().y) > 0.4) {
state.setInput(Input.SNEAK, true);
}
state.setInput(Input.MOVE_FORWARD, true);
@@ -150,7 +150,7 @@ public class MovementFall extends Movement {
for (int i = 0; i < 15; i++) {
BlockState state = ctx.world().getBlockState(ctx.playerFeet().down(i));
if (state.getBlock() == Blocks.LADDER) {
return state.get(BlockLadder.FACING);
return state.get(LadderBlock.FACING);
}
}
return null;

View File

@@ -28,11 +28,11 @@ import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.StairsBlock;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.WaterFluid;
import net.minecraft.init.Blocks;
import net.minecraft.init.Fluids;
import net.minecraft.util.Direction;
public class MovementParkour extends Movement {
@@ -87,7 +87,7 @@ public class MovementParkour extends Movement {
return;
}
BlockState standingOn = context.get(x, y - 1, z);
if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn) || standingOn.getFluidState().getFluid() != Fluids.EMPTY) {
if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof StairsBlock || MovementHelper.isBottomSlab(standingOn) || standingOn.getFluidState().getFluid() != Fluids.EMPTY) {
return;
}
int maxJump;

View File

@@ -31,13 +31,10 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.*;
import net.minecraft.block.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.state.properties.SlabType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import java.util.Objects;
public class MovementPillar extends Movement {
public MovementPillar(IBaritone baritone, BetterBlockPos start, BetterBlockPos end) {
@@ -58,7 +55,7 @@ public class MovementPillar extends Movement {
if (fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE) {
return COST_INF; // can't pillar from a ladder or vine onto something that isn't also climbable
}
if (fromDown.getBlock() instanceof BlockSlab && !fromDown.isTopSolid()) {
if (fromDown.getBlock() instanceof SlabBlock && fromDown.get(SlabBlock.TYPE) == SlabType.BOTTOM) {
return COST_INF; // can't pillar up from a bottom slab onto a non ladder
}
}
@@ -67,7 +64,7 @@ public class MovementPillar extends Movement {
}
BlockState toBreak = context.get(x, y + 2, z);
Block toBreakBlock = toBreak.getBlock();
if (toBreakBlock instanceof BlockFenceGate) { // see issue #172
if (toBreakBlock instanceof FenceGateBlock) { // see issue #172
return COST_INF;
}
BlockState srcUp = null;
@@ -84,7 +81,7 @@ public class MovementPillar extends Movement {
if (placeCost >= COST_INF) {
return COST_INF;
}
if (fromDown.getBlock() instanceof BlockAir) {
if (fromDown.getBlock() instanceof AirBlock) {
placeCost += 0.1; // slightly (1/200th of a second) penalize pillaring on what's currently air
}
}
@@ -103,19 +100,19 @@ public class MovementPillar extends Movement {
hardness = 0; // we won't actually need to break the ladder / vine because we're going to use it
} else {
BlockState check = context.get(x, y + 3, z); // the block on top of the one we're going to break, could it fall on us?
if (check.getBlock() instanceof BlockFalling) {
if (check.getBlock() instanceof FallingBlock) {
// see MovementAscend's identical check for breaking a falling block above our head
if (srcUp == null) {
srcUp = context.get(x, y + 1, z);
}
if (!(toBreakBlock instanceof BlockFalling) || !(srcUp.getBlock() instanceof BlockFalling)) {
if (!(toBreakBlock instanceof FallingBlock) || !(srcUp.getBlock() instanceof FallingBlock)) {
return COST_INF;
}
}
// this is commented because it may have had a purpose, but it's very unclear what it was. it's from the minebot era.
//if (!MovementHelper.canWalkOn(chkPos, check) || MovementHelper.canWalkThrough(chkPos, check)) {//if the block above where we want to break is not a full block, don't do it
// TODO why does canWalkThrough mean this action is COST_INF?
// BlockFalling makes sense, and !canWalkOn deals with weird cases like if it were lava
// FallingBlock makes sense, and !canWalkOn deals with weird cases like if it were lava
// but I don't understand why canWalkThrough makes it impossible
// return COST_INF;
//}
@@ -129,23 +126,23 @@ public class MovementPillar extends Movement {
}
public static boolean hasAgainst(CalculationContext context, int x, int y, int z) {
return context.get(x + 1, y, z).isBlockNormalCube() ||
context.get(x - 1, y, z).isBlockNormalCube() ||
context.get(x, y, z + 1).isBlockNormalCube() ||
context.get(x, y, z - 1).isBlockNormalCube();
return MovementHelper.isBlockNormalCube(context.get(x + 1, y, z)) ||
MovementHelper.isBlockNormalCube(context.get(x - 1, y, z)) ||
MovementHelper.isBlockNormalCube(context.get(x, y, z + 1)) ||
MovementHelper.isBlockNormalCube(context.get(x, y, z - 1));
}
public static BlockPos getAgainst(CalculationContext context, BetterBlockPos vine) {
if (context.get(vine.north()).isBlockNormalCube()) {
if (MovementHelper.isBlockNormalCube(context.get(vine.north()))) {
return vine.north();
}
if (context.get(vine.south()).isBlockNormalCube()) {
if (MovementHelper.isBlockNormalCube(context.get(vine.south()))) {
return vine.south();
}
if (context.get(vine.east()).isBlockNormalCube()) {
if (MovementHelper.isBlockNormalCube(context.get(vine.east()))) {
return vine.east();
}
if (context.get(vine.west()).isBlockNormalCube()) {
if (MovementHelper.isBlockNormalCube(context.get(vine.west()))) {
return vine.west();
}
return null;
@@ -186,7 +183,7 @@ public class MovementPillar extends Movement {
boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder;
if (ladder) {
BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.get(BlockLadder.FACING).getOpposite());
BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.get(LadderBlock.FACING).getOpposite());
if (against == null) {
logDebug("Unable to climb vines");
return state.setStatus(MovementStatus.UNREACHABLE);
@@ -219,7 +216,7 @@ public class MovementPillar extends Movement {
double diffX = ctx.player().posX - (dest.getX() + 0.5);
double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
double flatMotion = Math.sqrt(ctx.player().motionX * ctx.player().motionX + ctx.player().motionZ * ctx.player().motionZ);
double flatMotion = Math.sqrt(ctx.player().getMotion().x * ctx.player().getMotion().x + ctx.player().getMotion().z * ctx.player().getMotion().z);
if (dist > 0.17) {//why 0.17? because it seemed like a good number, that's why
//[explanation added after baritone port lol] also because it needs to be less than 0.2 because of the 0.3 sneak limit
//and 0.17 is reasonably less than 0.2
@@ -239,14 +236,14 @@ public class MovementPillar extends Movement {
BlockState frState = BlockStateInterface.get(ctx, src);
Block fr = frState.getBlock();
// TODO: Evaluate usage of getMaterial().isReplaceable()
if (!(fr instanceof BlockAir || frState.getMaterial().isReplaceable())) {
if (!(fr instanceof AirBlock || frState.getMaterial().isReplaceable())) {
RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance())
.map(rot -> new MovementState.MovementTarget(rot, true))
.ifPresent(state::setTarget);
state.setInput(Input.JUMP, false); // breaking is like 5x slower when you're jumping
state.setInput(Input.CLICK_LEFT, true);
blockIsThere = false;
} else if (ctx.player().isSneaking() && (Objects.equals(src.down(), ctx.objectMouseOver().getBlockPos()) || Objects.equals(src, ctx.objectMouseOver().getBlockPos())) && ctx.player().posY > dest.getY() + 0.1) {
} else if (ctx.player().isSneaking() && (ctx.isLookingAt(src.down()) || ctx.isLookingAt(src)) && ctx.player().posY > dest.getY() + 0.1) {
state.setInput(Input.CLICK_RIGHT, true);
}
}

View File

@@ -31,9 +31,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.*;
import net.minecraft.block.state.BlockState;
import net.minecraft.fluid.WaterFluid;
import net.minecraft.init.Blocks;
import net.minecraft.state.properties.SlabType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@@ -133,7 +131,7 @@ public class MovementTraverse extends Movement {
}
}
// now that we've checked all possible directions to side place, we actually need to backplace
if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof BlockSlab && down.get(BlockSlab.TYPE) != SlabType.DOUBLE)) {
if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof SlabBlock && down.get(SlabBlock.TYPE) != SlabType.DOUBLE)) {
return COST_INF; // can't sneak and backplace against soul sand or half slabs (regardless of whether it's top half or bottom half) =/
}
if (down.getFluidState() instanceof WaterFluid) {
@@ -181,7 +179,7 @@ public class MovementTraverse extends Movement {
// it's safe to do this since the two blocks we break (in a traverse) are right on top of each other and so will have the same yaw
float yawToDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), dest), ctx.playerRotations()).getYaw();
float pitchToBreak = state.getTarget().getRotation().get().getPitch();
if ((pb0.isFullCube() || pb0.getBlock() instanceof BlockAir && (pb1.isFullCube() || pb1.getBlock() instanceof BlockAir))) {
if ((MovementHelper.isFullCube(pb0) || pb0.getBlock() instanceof AirBlock && (MovementHelper.isFullCube(pb1) || pb1.getBlock() instanceof AirBlock))) {
// in the meantime, before we're right up against the block, we can break efficiently at this angle
pitchToBreak = 26;
}
@@ -197,16 +195,16 @@ public class MovementTraverse extends Movement {
Block fd = BlockStateInterface.get(ctx, src.down()).getBlock();
boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE;
if (pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor) {
if ((pb0.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, src, dest)
|| pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, dest, src))
if (pb0.getBlock() instanceof DoorBlock || pb1.getBlock() instanceof DoorBlock) {
if ((pb0.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, src, dest)
|| pb1.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, dest, src))
&& !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) {
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), positionsToBreak[0]), ctx.playerRotations()), true))
.setInput(Input.CLICK_RIGHT, true);
}
}
if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) {
if (pb0.getBlock() instanceof FenceGateBlock || pb1.getBlock() instanceof FenceGateBlock) {
BlockPos blocked = !MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up()) ? positionsToBreak[0]
: !MovementHelper.isGatePassable(ctx, positionsToBreak[1], src) ? positionsToBreak[1]
: null;
@@ -250,14 +248,14 @@ public class MovementTraverse extends Movement {
BlockState destDown = BlockStateInterface.get(ctx, dest.down());
BlockPos against = positionsToBreak[0];
if (feet.getY() != dest.getY() && ladder && (destDown.getBlock() == Blocks.VINE || destDown.getBlock() == Blocks.LADDER)) {
against = destDown.getBlock() == Blocks.VINE ? MovementPillar.getAgainst(new CalculationContext(baritone), dest.down()) : dest.offset(destDown.get(BlockLadder.FACING).getOpposite());
against = destDown.getBlock() == Blocks.VINE ? MovementPillar.getAgainst(new CalculationContext(baritone), dest.down()) : dest.offset(destDown.get(LadderBlock.FACING).getOpposite());
}
MovementHelper.moveTowards(ctx, state, against);
return state;
} else {
wasTheBridgeBlockAlwaysThere = false;
Block standingOn = BlockStateInterface.get(ctx, feet.down()).getBlock();
if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) { // see issue #118
if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof SlabBlock) { // see issue #118
double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().posX), Math.abs(dest.getZ() + 0.5 - ctx.player().posZ));
if (dist < 0.85) { // 0.5 + 0.3 + epsilon
MovementHelper.moveTowards(ctx, state, dest);

View File

@@ -32,7 +32,7 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.movements.*;
import baritone.utils.BlockStateInterface;
import net.minecraft.init.Blocks;
import net.minecraft.block.Blocks;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@@ -353,7 +353,7 @@ public class PathExecutor implements IPathExecutor, Helper {
return false;
} else {
// we are either onGround or in liquid
if (ctx.player().motionY < -0.1) {
if (ctx.player().getMotion().y < -0.1) {
// if we are strictly moving downwards (not stationary)
// we could be falling through water, which could be unsafe to splice
return false; // so don't

View File

@@ -26,8 +26,8 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.pathing.path.PathExecutor;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.block.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk;
@@ -103,7 +103,7 @@ public final class BackfillProcess extends BaritoneProcessHelper {
.filter(pos -> ctx.world().getBlockState(pos).getBlock() == Blocks.AIR)
.filter(pos -> baritone.getBuilderProcess().placementPlausible(pos, Blocks.DIRT.getDefaultState()))
.filter(pos -> !partOfCurrentMovement(pos))
.sorted(Comparator.<BlockPos>comparingDouble(ctx.player()::getDistanceSq).reversed())
.sorted(Comparator.<BlockPos>comparingDouble(ctx.playerFeet()::distanceSq).reversed())
.collect(Collectors.toList());
}

View File

@@ -36,17 +36,18 @@ import baritone.utils.PathingCommandContext;
import baritone.utils.schematic.AirSchematic;
import baritone.utils.schematic.Schematic;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockFlowingFluid;
import net.minecraft.block.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.AirBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.*;
import net.minecraft.util.math.shapes.VoxelShape;
@@ -95,7 +96,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
@Override
public boolean build(String name, File schematic, Vec3i origin) {
NBTTagCompound tag;
CompoundNBT tag;
try (FileInputStream fileIn = new FileInputStream(schematic)) {
tag = CompressedStreamTools.readCompressed(fileIn);
} catch (IOException e) {
@@ -117,7 +118,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
build("clear area", new AirSchematic(widthX, heightY, lengthZ), origin);
}
private static ISchematic parse(NBTTagCompound schematic) {
private static ISchematic parse(CompoundNBT schematic) {
return new Schematic(schematic);
}
@@ -134,7 +135,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
return null;
}
BlockState state = schematic.desiredState(x - origin.getX(), y - origin.getY(), z - origin.getZ());
if (state.getBlock() instanceof BlockAir) {
if (state.getBlock() instanceof AirBlock) {
return null;
}
return state;
@@ -157,7 +158,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
continue; // irrelevant
}
BlockState curr = bcc.bsi.get0(x, y, z);
if (!(curr.getBlock() instanceof BlockAir) && !valid(curr, desired)) {
if (!(curr.getBlock() instanceof AirBlock) && !valid(curr, desired)) {
BetterBlockPos pos = new BetterBlockPos(x, y, z);
Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
if (rot.isPresent()) {
@@ -198,7 +199,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
BlockState curr = bcc.bsi.get0(x, y, z);
if (MovementHelper.isReplacable(x, y, z, curr, bcc.bsi) && !valid(curr, desired)) {
if (dy == 1 && bcc.bsi.get0(x, y + 1, z).getBlock() instanceof BlockAir) {
if (dy == 1 && bcc.bsi.get0(x, y + 1, z).getBlock() instanceof AirBlock) {
continue;
}
desirableOnHotbar.add(desired);
@@ -238,7 +239,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);
Rotation rot = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations());
RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance());
if (result != null && result.getType() == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(placeAgainstPos) && result.sideHit == against.getOpposite()) {
if (result != null && result.getType() == RayTraceResult.Type.BLOCK && ((BlockRayTraceResult) result).getPos().equals(placeAgainstPos) && ((BlockRayTraceResult) result).getFace() == against.getOpposite()) {
OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot);
if (hotbar.isPresent()) {
return Optional.of(new Placement(hotbar.getAsInt(), placeAgainstPos, against.getOpposite(), rot));
@@ -252,7 +253,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private OptionalInt hasAnyItemThatWouldPlace(BlockState desired, RayTraceResult result, Rotation rot) {
for (int i = 0; i < 9; i++) {
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
if (stack.isEmpty() || !(stack.getItem() instanceof ItemBlock)) {
if (stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) {
continue;
}
float originalYaw = ctx.player().rotationYaw;
@@ -261,15 +262,13 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
ctx.player().rotationYaw = rot.getYaw();
ctx.player().rotationPitch = rot.getPitch();
BlockItemUseContext meme = new BlockItemUseContext(new ItemUseContext(
ctx.world(),
ctx.player(),
Hand.MAIN_HAND,
stack,
result.getBlockPos().offset(result.sideHit),
result.sideHit,
(float) result.hitVec.x - result.getBlockPos().getX(),
(float) result.hitVec.y - result.getBlockPos().getY(),
(float) result.hitVec.z - result.getBlockPos().getZ()
));
BlockState wouldBePlaced = ((ItemBlock) stack.getItem()).getBlock().getStateForPlacement(meme);
(BlockRayTraceResult) result
) {}); // that {} gives us access to a protected constructor lmfao
BlockState wouldBePlaced = ((BlockItem) stack.getItem()).getBlock().getStateForPlacement(meme);
ctx.player().rotationYaw = originalYaw;
ctx.player().rotationPitch = originalPitch;
if (wouldBePlaced == null) {
@@ -404,7 +403,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
baritone.getLookBehavior().updateTarget(rot, true);
ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ((BlockRayTraceResult) ctx.objectMouseOver()).getFace().equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
}
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
@@ -466,7 +465,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private void trim() {
HashSet<BetterBlockPos> copy = new HashSet<>(incorrectPositions);
copy.removeIf(pos -> pos.distanceSq(ctx.player().posX, ctx.player().posY, ctx.player().posZ) > 200);
copy.removeIf(pos -> pos.distanceSq(new BlockPos(ctx.player())) > 200);
if (!copy.isEmpty()) {
incorrectPositions = copy;
}
@@ -535,12 +534,12 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
List<BetterBlockPos> sourceLiquids = new ArrayList<>();
incorrectPositions.forEach(pos -> {
BlockState state = bcc.bsi.get0(pos);
if (state.getBlock() instanceof BlockAir) {
if (state.getBlock() instanceof AirBlock) {
if (approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z))) {
placable.add(pos);
}
} else {
if (state.getBlock() instanceof BlockFlowingFluid) {
if (state.getBlock() instanceof FlowingFluidBlock) {
// if the block itself is JUST a liquid (i.e. not just a waterlogged block), we CANNOT break it
// TODO for 1.13 make sure that this only matches pure water, not waterlogged blocks
if (!MovementHelper.possiblyFlowing(state)) {
@@ -615,10 +614,10 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
private Goal placementGoal(BlockPos pos, BuilderCalculationContext bcc) {
if (!(ctx.world().getBlockState(pos).getBlock() instanceof BlockAir)) { // TODO can this even happen?
if (!(ctx.world().getBlockState(pos).getBlock() instanceof AirBlock)) { // TODO can this even happen?
return new GoalPlace(pos);
}
boolean allowSameLevel = !(ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir);
boolean allowSameLevel = !(ctx.world().getBlockState(pos.up()).getBlock() instanceof AirBlock);
for (Direction facing : Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP) {
if (MovementHelper.canPlaceAgainst(ctx, pos.offset(facing)) && placementPlausible(pos, bcc.getSchematic(pos.getX(), pos.getY(), pos.getZ()))) {
return new GoalAdjacent(pos, allowSameLevel);
@@ -628,7 +627,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
private Goal breakGoal(BlockPos pos, BuilderCalculationContext bcc) {
if (Baritone.settings().goalBreakFromAbove.value && bcc.bsi.get0(pos.up()).getBlock() instanceof BlockAir && bcc.bsi.get0(pos.up(2)).getBlock() instanceof BlockAir) { // TODO maybe possible without the up(2) check?
if (Baritone.settings().goalBreakFromAbove.value && bcc.bsi.get0(pos.up()).getBlock() instanceof AirBlock && bcc.bsi.get0(pos.up(2)).getBlock() instanceof AirBlock) { // TODO maybe possible without the up(2) check?
return new JankyGoalComposite(new GoalBreak(pos), new GoalGetToBlock(pos.up()) {
@Override
public boolean isInGoal(int x, int y, int z) {
@@ -700,12 +699,12 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
List<BlockState> result = new ArrayList<>();
for (int i = 0; i < size; i++) {
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
if (stack.isEmpty() || !(stack.getItem() instanceof ItemBlock)) {
if (stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) {
result.add(Blocks.AIR.getDefaultState());
continue;
}
// <toxic cloud>
result.add(((ItemBlock) stack.getItem()).getBlock().getStateForPlacement(new BlockItemUseContext(new ItemUseContext(ctx.player(), stack, ctx.playerFeet(), Direction.UP, (float) ctx.player().posX, (float) ctx.player().posY, (float) ctx.player().posZ))));
result.add(((BlockItem) stack.getItem()).getBlock().getStateForPlacement(new BlockItemUseContext(new ItemUseContext(ctx.world(), ctx.player(), Hand.MAIN_HAND, stack, new BlockRayTraceResult(new Vec3d(ctx.player().posX, ctx.player().posY, ctx.player().posZ), Direction.UP, ctx.playerFeet(), false)) {})));
// </toxic cloud>
}
return result;
@@ -715,7 +714,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
if (desired == null) {
return true;
}
if (current.getBlock() instanceof BlockAir && desired.getBlock() instanceof BlockAir) {
if (current.getBlock() instanceof AirBlock && desired.getBlock() instanceof AirBlock) {
return true;
}
// TODO more complicated comparison logic I guess
@@ -757,7 +756,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
BlockState sch = getSchematic(x, y, z);
if (sch != null) {
// TODO this can return true even when allowPlace is off.... is that an issue?
if (sch.getBlock() instanceof BlockAir) {
if (sch.getBlock() instanceof AirBlock) {
// we want this to be air, but they're asking if they can place here
// this won't be a schematic block, this will be a throwaway
return placeBlockCost * 2; // we're going to have to break it eventually
@@ -790,7 +789,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
BlockState sch = getSchematic(x, y, z);
if (sch != null) {
if (sch.getBlock() instanceof BlockAir) {
if (sch.getBlock() instanceof AirBlock) {
// it should be air
// regardless of current contents, we can break it
return 1;

View File

@@ -31,13 +31,11 @@ import baritone.cache.WorldScanner;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.block.*;
import net.minecraft.block.state.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@@ -94,29 +92,29 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
}
private enum Harvest {
WHEAT((BlockCrops) Blocks.WHEAT),
CARROTS((BlockCrops) Blocks.CARROTS),
POTATOES((BlockCrops) Blocks.POTATOES),
BEETROOT((BlockCrops) Blocks.BEETROOTS),
WHEAT((CropsBlock) Blocks.WHEAT),
CARROTS((CropsBlock) Blocks.CARROTS),
POTATOES((CropsBlock) Blocks.POTATOES),
BEETROOT((CropsBlock) Blocks.BEETROOTS),
PUMPKIN(Blocks.PUMPKIN, state -> true),
MELON(Blocks.MELON, state -> true),
NETHERWART(Blocks.NETHER_WART, state -> state.get(BlockNetherWart.AGE) >= 3),
NETHERWART(Blocks.NETHER_WART, state -> state.get(NetherWartBlock.AGE) >= 3),
SUGARCANE(Blocks.SUGAR_CANE, null) {
@Override
public boolean readyToHarvest(World world, BlockPos pos, BlockState state) {
return world.getBlockState(pos.down()).getBlock() instanceof BlockReed;
return world.getBlockState(pos.down()).getBlock() instanceof SugarCaneBlock;
}
},
CACTUS(Blocks.CACTUS, null) {
@Override
public boolean readyToHarvest(World world, BlockPos pos, BlockState state) {
return world.getBlockState(pos.down()).getBlock() instanceof BlockCactus;
return world.getBlockState(pos.down()).getBlock() instanceof CactusBlock;
}
};
public final Block block;
public final Predicate<BlockState> readyToHarvest;
Harvest(BlockCrops blockCrops) {
Harvest(CropsBlock blockCrops) {
this(blockCrops, blockCrops::isMaxAge);
// max age is 7 for wheat, carrots, and potatoes, but 3 for beetroot
}
@@ -171,7 +169,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
List<BlockPos> openSoulsand = new ArrayList<>();
for (BlockPos pos : locations) {
BlockState state = ctx.world().getBlockState(pos);
boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir;
boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof AirBlock;
if (state.getBlock() == Blocks.FARMLAND) {
if (airAbove) {
openFarmland.add(pos);
@@ -258,8 +256,8 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
}
}
for (Entity entity : ctx.world().loadedEntityList) {
if (entity instanceof EntityItem && entity.onGround) {
EntityItem ei = (EntityItem) entity;
if (entity instanceof ItemEntity && entity.onGround) {
ItemEntity ei = (ItemEntity) entity;
if (PICKUP_DROPPED.contains(ei.getItem().getItem())) {
// +0.1 because of farmland's 0.9375 dummy height lol
goalz.add(new GoalBlock(new BlockPos(entity.posX, entity.posY + 0.1, entity.posZ)));

View File

@@ -82,7 +82,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
}
private void scanWorld() {
cache = Stream.of(ctx.world().loadedEntityList, ctx.world().playerEntities).flatMap(List::stream).filter(this::followable).filter(this.filter).distinct().collect(Collectors.toCollection(ArrayList::new));
cache = Stream.of(ctx.world().loadedEntityList, ctx.world().getPlayers()).flatMap(List::stream).filter(this::followable).filter(this.filter).distinct().collect(Collectors.toCollection(ArrayList::new));
}
@Override

View File

@@ -26,10 +26,11 @@ import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.input.Input;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.block.Blocks;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.util.math.BlockPos;
import java.util.*;
@@ -121,7 +122,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
// blacklist the closest block and its adjacent blocks
public synchronized boolean blacklistClosest() {
List<BlockPos> newBlacklist = new ArrayList<>();
knownLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(newBlacklist::add);
knownLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(newBlacklist::add);
outer:
while (true) {
for (BlockPos known : knownLocations) {
@@ -180,7 +181,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
if (walkIntoInsteadOfAdjacent(gettingTo)) {
return new GoalTwoBlocks(pos);
}
if (blockOnTopMustBeRemoved(gettingTo) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) {
if (blockOnTopMustBeRemoved(gettingTo) && MovementHelper.isBlockNormalCube(baritone.bsi.get0(pos.up()))) { // TODO this should be the check for chest openability
return new GoalBlock(pos.up());
}
return new GoalGetToBlock(pos);
@@ -194,7 +195,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
if (knownLocations.contains(ctx.getSelectedBlock().orElse(null))) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); // TODO find some way to right click even if we're in an ESC menu
System.out.println(ctx.player().openContainer);
if (!(ctx.player().openContainer instanceof ContainerPlayer)) {
if (!(ctx.player().openContainer instanceof PlayerContainer)) {
return true;
}
}

View File

@@ -33,13 +33,9 @@ import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@@ -91,7 +87,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
if (calcFailed) {
if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) {
logDirect("Unable to find any path to " + mining + ", blacklisting presumably unreachable closest instance...");
knownOreLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(blacklist::add);
knownOreLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(blacklist::add);
knownOreLocations.removeIf(blacklist::contains);
} else {
logDirect("Unable to find any path to " + mining + ", canceling Mine");
@@ -111,8 +107,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
Optional<BlockPos> shaft = curr.stream()
.filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ())
.filter(pos -> pos.getY() >= ctx.playerFeet().getY())
.filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof BlockAir)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =(
.min(Comparator.comparingDouble(ctx.player()::getDistanceSq));
.filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof AirBlock)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =(
.min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq));
baritone.getInputOverrideHandler().clearAllKeys();
if (shaft.isPresent()) {
BlockPos pos = shaft.get();
@@ -211,14 +207,14 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return true;
}
Block block = BlockStateInterface.getBlock(ctx, pos);
if (Baritone.settings().internalMiningAirException.value && block instanceof BlockAir) {
if (Baritone.settings().internalMiningAirException.value && block instanceof AirBlock) {
return true;
}
return mining.contains(block);
}
private Goal coalesce(BlockPos loc, List<BlockPos> locs) {
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof BlockFalling);
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof FallingBlock);
if (!Baritone.settings().forceInternalMining.value) {
if (assumeVerticalShaftMine) {
// we can get directly below the block
@@ -292,8 +288,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
List<BlockPos> ret = new ArrayList<>();
for (Entity entity : world.loadedEntityList) {
if (entity instanceof EntityItem) {
EntityItem ei = (EntityItem) entity;
if (entity instanceof ItemEntity) {
ItemEntity ei = (ItemEntity) entity;
if (searchingFor.contains(ei.getItem().getItem())) {
ret.add(new BlockPos(entity));
}
@@ -369,7 +365,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
.filter(pos -> !blacklist.contains(pos))
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().player()::getDistanceSq))
.sorted(Comparator.comparingDouble(new BlockPos(ctx.getBaritone().getPlayerContext().player())::distanceSq))
.collect(Collectors.toList());
if (locs.size() > max) {

View File

@@ -26,10 +26,13 @@ import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import net.minecraft.client.GameSettings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.settings.AmbientOcclusionStatus;
import net.minecraft.client.settings.CloudOption;
import net.minecraft.client.settings.ParticleStatus;
import net.minecraft.client.tutorial.TutorialSteps;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.HttpUtil;
import net.minecraft.util.HTTPUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameType;
import net.minecraft.world.WorldSettings;
@@ -71,14 +74,14 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
GameSettings s = mc.gameSettings;
s.limitFramerate = 20;
s.mipmapLevels = 0;
s.particleSetting = 2;
s.field_74362_aa = ParticleStatus.MINIMAL;
s.overrideWidth = 128;
s.overrideHeight = 128;
s.heldItemTooltips = false;
s.entityShadows = false;
s.chatScale = 0.0F;
s.ambientOcclusion = 0;
s.clouds = 0;
s.ambientOcclusionStatus = AmbientOcclusionStatus.OFF;
s.field_74345_l = CloudOption.OFF;
s.fancyGraphics = false;
s.tutorialStep = TutorialSteps.NONE;
s.hideGUI = true;
@@ -89,9 +92,9 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
public void onTick(TickEvent event) {
IPlayerContext ctx = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext();
// If we're on the main menu then create the test world and launch the integrated server
if (mc.currentScreen instanceof GuiMainMenu) {
if (mc.field_71462_r instanceof MainMenuScreen) {
System.out.println("Beginning Baritone automatic test routine");
mc.displayScreen(null);
mc.displayGuiScreen(null);
WorldSettings worldsettings = new WorldSettings(TEST_SEED, GameType.getByName("survival"), true, false, WorldType.DEFAULT);
mc.launchIntegratedServer("BaritoneAutoTest", "BaritoneAutoTest", worldsettings);
}
@@ -110,7 +113,7 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
// Force the integrated server to share the world to LAN so that
// the ingame pause menu gui doesn't actually pause our game
if (mc.isSingleplayer() && !mc.getIntegratedServer().getPublic()) {
mc.getIntegratedServer().shareToLAN(GameType.getByName("survival"), false, HttpUtil.getSuitableLanPort());
mc.getIntegratedServer().shareToLAN(GameType.getByName("survival"), false, HTTPUtil.getSuitableLanPort());
}
// For the first 200 ticks, wait for the world to generate

View File

@@ -20,8 +20,9 @@ package baritone.utils;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import net.minecraft.util.Direction;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
/**
@@ -40,7 +41,7 @@ public final class BlockBreakHelper implements Helper {
public void tryBreakBlock(BlockPos pos, Direction side) {
if (playerContext.playerController().onPlayerDamageBlock(pos, side)) {
playerContext.player().swingArm(EnumHand.MAIN_HAND);
playerContext.player().swingArm(Hand.MAIN_HAND);
}
}
@@ -57,7 +58,7 @@ public final class BlockBreakHelper implements Helper {
boolean isBlockTrace = trace != null && trace.getType() == RayTraceResult.Type.BLOCK;
if (isLeftClick && isBlockTrace) {
tryBreakBlock(trace.getBlockPos(), trace.sideHit);
tryBreakBlock(((BlockRayTraceResult) trace).getPos(), ((BlockRayTraceResult) trace).getFace());
didBreakLastTick = true;
} else if (didBreakLastTick) {
stopBreakingBlock();

View File

@@ -20,8 +20,9 @@ package baritone.utils;
import baritone.Baritone;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
public class BlockPlaceHelper implements Helper {
@@ -38,16 +39,16 @@ public class BlockPlaceHelper implements Helper {
return;
}
RayTraceResult mouseOver = ctx.objectMouseOver();
if (!rightClickRequested || ctx.player().isRowingBoat() || mouseOver == null || mouseOver.getBlockPos() == null || mouseOver.getType() != RayTraceResult.Type.BLOCK) {
if (!rightClickRequested || ctx.player().isRowingBoat() || mouseOver == null || mouseOver.getType() != RayTraceResult.Type.BLOCK) {
return;
}
rightClickTimer = Baritone.settings().rightClickSpeed.value;
for (EnumHand hand : EnumHand.values()) {
if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), mouseOver.getBlockPos(), mouseOver.sideHit, mouseOver.hitVec, hand) == EnumActionResult.SUCCESS) {
for (Hand hand : Hand.values()) {
if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), hand, (BlockRayTraceResult) mouseOver) == ActionResultType.SUCCESS) {
ctx.player().swingArm(hand);
return;
}
if (!ctx.player().getHeldItem(hand).isEmpty() && ctx.playerController().processRightClick(ctx.player(), ctx.world(), hand) == EnumActionResult.SUCCESS) {
if (!ctx.player().getHeldItem(hand).isEmpty() && ctx.playerController().processRightClick(ctx.player(), ctx.world(), hand) == ActionResultType.SUCCESS) {
return;
}
}

View File

@@ -25,13 +25,14 @@ import baritone.utils.accessor.IChunkProviderClient;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
/**
* Wraps get for chuck caching capability
@@ -67,7 +68,7 @@ public class BlockStateInterface {
this.loadedChunks = worldLoaded; // this will only be used on the main thread
}
this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.value;
if (!Minecraft.getInstance().isCallingFromMinecraftThread()) {
if (!Minecraft.getInstance().isOnExecutionThread()) {
throw new IllegalStateException();
}
}
@@ -105,14 +106,14 @@ public class BlockStateInterface {
// we can just skip the mc.world.getChunk lookup
// which is a Long2ObjectOpenHashMap.get
// see issue #113
if (cached != null && cached.x == x >> 4 && cached.z == z >> 4) {
return cached.getBlockState(x, y, z);
if (cached != null && cached.getPos().x == x >> 4 && cached.getPos().z == z >> 4) {
return getFromChunk(cached, x, y, z);
}
Chunk chunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4));
if (chunk != null && chunk.isLoaded()) {
if (chunk != null && !chunk.isEmpty()) {
prev = chunk;
return chunk.getBlockState(x, y, z);
return getFromChunk(chunk, x, y, z);
}
}
// same idea here, skip the Long2ObjectOpenHashMap.get if at all possible
@@ -138,11 +139,11 @@ public class BlockStateInterface {
public boolean isLoaded(int x, int z) {
Chunk prevChunk = prev;
if (prevChunk != null && prevChunk.x == x >> 4 && prevChunk.z == z >> 4) {
if (prevChunk != null && prevChunk.getPos().x == x >> 4 && prevChunk.getPos().z == z >> 4) {
return true;
}
prevChunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4));
if (prevChunk != null && prevChunk.isLoaded()) {
if (prevChunk != null && !prevChunk.isEmpty()) {
prev = prevChunk;
return true;
}
@@ -160,4 +161,13 @@ public class BlockStateInterface {
prevCached = prevRegion;
return prevRegion.isCached(x & 511, z & 511);
}
// get the block at x,y,z from this chunk WITHOUT creating a single blockpos object
public static BlockState getFromChunk(Chunk chunk, int x, int y, int z) {
ChunkSection section = chunk.getSections()[y >> 4];
if (ChunkSection.isEmpty(section)) {
return AIR;
}
return section.get(x & 15, y & 15, z & 15);
}
}

View File

@@ -22,10 +22,13 @@ import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalTwoBlocks;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.client.gui.Screen;
import net.minecraft.client.renderer.GlStateManager;
import baritone.api.utils.Helper;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.*;
import net.minecraft.util.text.StringTextComponent;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
@@ -36,7 +39,7 @@ import java.util.Collections;
import static org.lwjgl.opengl.GL11.*;
public class GuiClick extends Screen {
public class GuiClick extends Screen implements Helper {
// My name is Brady and I grant leijurv permission to use this pasted code
private final FloatBuffer MODELVIEW = BufferUtils.createFloatBuffer(16);
@@ -47,8 +50,12 @@ public class GuiClick extends Screen {
private BlockPos clickStart;
private BlockPos currentMouseOver;
public GuiClick() {
super(new StringTextComponent("CLICK"));
}
@Override
public boolean doesGuiPauseGame() {
public boolean isPauseScreen() {
return false;
}
@@ -62,10 +69,12 @@ public class GuiClick extends Screen {
Vec3d near = toWorld(mx, my, 0);
Vec3d far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - leijurv
if (near != null && far != null) {
Vec3d viewerPos = new Vec3d(mc.getRenderManager().viewerPosX, mc.getRenderManager().viewerPosY, mc.getRenderManager().viewerPosZ);
RayTraceResult result = mc.world.rayTraceBlocks(near.add(viewerPos), far.add(viewerPos), RayTraceFluidMode.NEVER, false, true);
///
Vec3d viewerPos = new Vec3d(PathRenderer.posX(), PathRenderer.posY(), PathRenderer.posZ());
ClientPlayerEntity player = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().player();
RayTraceResult result = player.world.func_217299_a(new RayTraceContext(near.add(viewerPos), far.add(viewerPos), RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, player));
if (result != null && result.getType() == RayTraceResult.Type.BLOCK) {
currentMouseOver = result.getBlockPos();
currentMouseOver = ((BlockRayTraceResult) result).getPos();
}
}
@@ -94,8 +103,8 @@ public class GuiClick extends Screen {
}
public void onRender() {
GlStateManager.getFloatv(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear());
GlStateManager.getFloatv(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear());
GlStateManager.getMatrix(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear());
GlStateManager.getMatrix(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear());
GL11.glGetIntegerv(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear());
if (currentMouseOver != null) {
@@ -107,7 +116,7 @@ public class GuiClick extends Screen {
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
GlStateManager.color4f(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F);
GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
GlStateManager.depthMask(false);
GlStateManager.disableDepthTest();
BetterBlockPos a = new BetterBlockPos(currentMouseOver);
@@ -116,7 +125,7 @@ public class GuiClick extends Screen {
GlStateManager.enableDepthTest();
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.disableBlend();
}
}

View File

@@ -27,11 +27,11 @@ import baritone.api.utils.Helper;
import baritone.api.utils.interfaces.IGoalRenderPos;
import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor;
import net.minecraft.block.state.BlockState;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntityBeaconRenderer;
import net.minecraft.client.renderer.tileentity.BeaconTileEntityRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
@@ -60,11 +60,23 @@ public final class PathRenderer implements Helper {
private PathRenderer() {}
public static double posX() {
return mc.getRenderManager().viewerPosX;
}
public static double posY() {
return mc.getRenderManager().viewerPosY;
}
public static double posZ() {
return mc.getRenderManager().viewerPosZ;
}
public static void render(RenderEvent event, PathingBehavior behavior) {
float partialTicks = event.getPartialTicks();
Goal goal = behavior.getGoal();
if (mc.currentScreen instanceof GuiClick) {
((GuiClick) mc.currentScreen).onRender();
if (mc.field_71462_r instanceof GuiClick) {
((GuiClick) mc.field_71462_r).onRender();
}
int thisPlayerDimension = behavior.baritone.getPlayerContext().world().getDimension().getType().getId();
@@ -137,7 +149,7 @@ public final class PathRenderer implements Helper {
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
GlStateManager.depthMask(false);
if (Baritone.settings().renderPathIgnoreDepth.value) {
GlStateManager.disableDepthTest();
@@ -187,14 +199,14 @@ public final class PathRenderer implements Helper {
}
//GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.disableBlend();
}
public static void drawLine(double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z) {
double d0 = mc.getRenderManager().viewerPosX;
double d1 = mc.getRenderManager().viewerPosY;
double d2 = mc.getRenderManager().viewerPosZ;
double d0 = posX();
double d1 = posY();
double d2 = posZ();
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
BUFFER.pos(bp1x + 0.5D - d0, bp1y + 0.5D - d1, bp1z + 0.5D - d2).endVertex();
BUFFER.pos(bp2x + 0.5D - d0, bp2y + 0.5D - d1, bp2z + 0.5D - d2).endVertex();
@@ -208,7 +220,7 @@ public final class PathRenderer implements Helper {
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
GlStateManager.depthMask(false);
if (Baritone.settings().renderSelectionBoxesIgnoreDepth.value) {
@@ -231,13 +243,13 @@ public final class PathRenderer implements Helper {
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.disableBlend();
}
public static void drawAABB(AxisAlignedBB aabb) {
float expand = 0.002F;
AxisAlignedBB toDraw = aabb.expand(expand, expand, expand).offset(-mc.getRenderManager().viewerPosX, -mc.getRenderManager().viewerPosY, -mc.getRenderManager().viewerPosZ);
AxisAlignedBB toDraw = aabb.expand(expand, expand, expand).offset(-posX(), -posY(), -posZ());
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
@@ -265,9 +277,9 @@ public final class PathRenderer implements Helper {
}
public static void drawDankLitGoalBox(Entity player, Goal goal, float partialTicks, Color color) {
double renderPosX = mc.getRenderManager().viewerPosX;
double renderPosY = mc.getRenderManager().viewerPosY;
double renderPosZ = mc.getRenderManager().viewerPosZ;
double renderPosX = posX();
double renderPosY = posY();
double renderPosZ = posZ();
double minX;
double maxX;
double minZ;
@@ -307,7 +319,7 @@ public final class PathRenderer implements Helper {
GlStateManager.disableDepthTest();
}
TileEntityBeaconRenderer.renderBeamSegment(
BeaconTileEntityRenderer.renderBeamSegment(
goalPos.getX() - renderPosX,
-renderPosY,
goalPos.getZ() - renderPosZ,
@@ -363,7 +375,7 @@ public final class PathRenderer implements Helper {
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.6F);
GlStateManager.lineWidth(Baritone.settings().goalRenderLineWidthPixels.value);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
GlStateManager.depthMask(false);
if (Baritone.settings().renderGoalIgnoreDepth.value) {
GlStateManager.disableDepthTest();
@@ -387,7 +399,7 @@ public final class PathRenderer implements Helper {
GlStateManager.enableDepthTest();
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.disableBlend();
}

View File

@@ -19,13 +19,13 @@ package baritone.utils;
import baritone.Baritone;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockState;
import net.minecraft.client.entity.ClientPlayerEntity;
import net.minecraft.block.BlockState;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Enchantments;
import net.minecraft.init.MobEffects;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.item.ToolItem;
import net.minecraft.potion.Effects;
import java.util.HashMap;
import java.util.Map;
@@ -80,7 +80,7 @@ public class ToolSet {
* @return Either 1 or -1
*/
private int getMaterialCost(ItemStack itemStack) {
return itemStack.getItem() instanceof ItemTool ? 1 : -1;
return itemStack.getItem() instanceof ToolItem ? 1 : -1;
}
/**
@@ -165,11 +165,11 @@ public class ToolSet {
*/
private double potionAmplifier() {
double speed = 1;
if (player.isPotionActive(MobEffects.HASTE)) {
speed *= 1 + (player.getActivePotionEffect(MobEffects.HASTE).getAmplifier() + 1) * 0.2;
if (player.isPotionActive(Effects.field_76422_e)) {
speed *= 1 + (player.getActivePotionEffect(Effects.field_76422_e).getAmplifier() + 1) * 0.2;
}
if (player.isPotionActive(MobEffects.MINING_FATIGUE)) {
switch (player.getActivePotionEffect(MobEffects.MINING_FATIGUE).getAmplifier()) {
if (player.isPotionActive(Effects.field_76419_f)) {
switch (player.getActivePotionEffect(Effects.field_76419_f).getAmplifier()) {
case 0:
speed *= 0.3;
break;

View File

@@ -17,7 +17,7 @@
package baritone.utils.accessor;
import net.minecraft.world.chunk.storage.IChunkLoader;
import net.minecraft.world.chunk.storage.ChunkLoader;
/**
* @author Brady
@@ -25,5 +25,5 @@ import net.minecraft.world.chunk.storage.IChunkLoader;
*/
public interface IChunkProviderServer {
IChunkLoader getChunkLoader();
ChunkLoader getChunkLoader();
}

View File

@@ -21,7 +21,7 @@ import baritone.Baritone;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.IPlayerContext;
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.MobEntity;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
@@ -69,7 +69,7 @@ public class Avoidance {
}
if (mobCoeff != 1.0D) {
ctx.world().loadedEntityList.stream()
.filter(entity -> entity instanceof EntityMob)
.filter(entity -> entity instanceof MobEntity)
.forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.value)));
}
return res;

View File

@@ -23,7 +23,7 @@ import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import baritone.api.utils.IPlayerController;
import baritone.api.utils.RayTraceUtils;
import net.minecraft.client.entity.ClientPlayerEntity;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

View File

@@ -19,16 +19,16 @@ package baritone.utils.player;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerController;
import net.minecraft.client.entity.ClientPlayerEntity;
import net.minecraft.client.multiplayer.ClientWorld;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.GameType;
import net.minecraft.world.World;
@@ -44,37 +44,38 @@ public enum PrimaryPlayerController implements IPlayerController, Helper {
@Override
public boolean onPlayerDamageBlock(BlockPos pos, Direction side) {
return mc.playerController.onPlayerDamageBlock(pos, side);
return mc.field_71442_b.onPlayerDamageBlock(pos, side);
}
@Override
public void resetBlockRemoving() {
mc.playerController.resetBlockRemoving();
mc.field_71442_b.resetBlockRemoving();
}
@Override
public ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, PlayerEntity player) {
return mc.playerController.windowClick(windowId, slotId, mouseButton, type, player);
return mc.field_71442_b.windowClick(windowId, slotId, mouseButton, type, player);
}
@Override
public void setGameType(GameType type) {
mc.playerController.setGameType(type);
mc.field_71442_b.setGameType(type);
}
@Override
public GameType getGameType() {
return mc.playerController.getCurrentGameType();
return mc.field_71442_b.getCurrentGameType();
}
@Override
public EnumActionResult processRightClickBlock(ClientPlayerEntity player, World world, BlockPos pos, Direction direction, Vec3d vec, EnumHand hand) {
public ActionResultType processRightClickBlock(ClientPlayerEntity player, World world, Hand hand, BlockRayTraceResult result) {
// primaryplayercontroller is always in a ClientWorld so this is ok
return mc.playerController.processRightClickBlock(player, (ClientWorld) world, pos, direction, vec, hand);
return mc.field_71442_b.func_217292_a(player, (ClientWorld) world, hand, result);
}
@Override
public EnumActionResult processRightClick(ClientPlayerEntity player, World world, EnumHand hand) {
return mc.playerController.processRightClick(player, world, hand);
public ActionResultType processRightClick(ClientPlayerEntity player, World world, Hand hand) {
return mc.field_71442_b.processRightClick(player, world, hand);
}
}

View File

@@ -18,8 +18,8 @@
package baritone.utils.schematic;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.BlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
public class AirSchematic implements ISchematic {

View File

@@ -17,9 +17,9 @@
package baritone.utils.schematic;
import net.minecraft.block.BlockAir;
import net.minecraft.block.state.BlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.block.AirBlock;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
import java.util.OptionalInt;
import java.util.function.Predicate;
@@ -28,7 +28,7 @@ public class MapArtSchematic extends Schematic {
private final int[][] heightMap;
public MapArtSchematic(NBTTagCompound schematic) {
public MapArtSchematic(CompoundNBT schematic) {
super(schematic);
heightMap = new int[widthX][lengthZ];
@@ -36,7 +36,7 @@ public class MapArtSchematic extends Schematic {
for (int z = 0; z < lengthZ; z++) {
BlockState[] column = states[x][z];
OptionalInt lowestBlockY = lastIndexMatching(column, block -> !(block instanceof BlockAir));
OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof AirBlock));
if (lowestBlockY.isPresent()) {
heightMap[x][z] = lowestBlockY.getAsInt();
} else {

View File

@@ -18,8 +18,8 @@
package baritone.utils.schematic;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.BlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
public class Schematic implements ISchematic {
public final int widthX;
@@ -27,7 +27,7 @@ public class Schematic implements ISchematic {
public final int lengthZ;
protected final BlockState[][][] states;
public Schematic(NBTTagCompound schematic) {
public Schematic(CompoundNBT schematic) {
/*String type = schematic.getString("Materials");
if (!type.equals("Alpha")) {
throw new IllegalStateException("bad schematic " + type);