diff --git a/build.gradle b/build.gradle index a03a89631..d116a81d9 100755 --- a/build.gradle +++ b/build.gradle @@ -20,20 +20,15 @@ version '1.2.1' buildscript { repositories { + jcenter() maven { name = 'forge' url = 'http://files.minecraftforge.net/maven' } - maven { - name = 'SpongePowered' - url = 'http://repo.spongepowered.org/maven' - } - jcenter() } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true } } @@ -42,8 +37,9 @@ import baritone.gradle.task.CreateDistTask import baritone.gradle.task.ProguardTask apply plugin: 'java' -apply plugin: 'net.minecraftforge.gradle.tweaker-client' -apply plugin: 'org.spongepowered.mixin' +//apply plugin: 'net.minecraftforge.gradle.tweaker-client' +//apply plugin: 'org.spongepowered.mixin' +apply plugin: 'net.minecraftforge.gradle' sourceCompatibility = targetCompatibility = '1.8' compileJava { @@ -52,11 +48,21 @@ compileJava { } sourceSets { + api { + compileClasspath += main.compileClasspath + } + main { + compileClasspath += api.output + } + test { + compileClasspath += api.output + } launch { compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output } } +/* minecraft { version = '1.12.2' mappings = 'stable_39' @@ -66,6 +72,18 @@ minecraft { // The sources jar should use SRG names not MCP to ensure compatibility with all mappings makeObfSourceJar = true } +*/ + +minecraft { + mappings channel: 'snapshot', version: '20190307-1.13.1' + + runs { + client { + workingDirectory project.file('run') + source sourceSets.main + } + } +} repositories { mavenCentral() @@ -82,6 +100,9 @@ repositories { } dependencies { + minecraft 'com.github.ImpactDevelopment:Vanilla:1.13.2' + + runtime launchCompile('net.minecraft:launchwrapper:1.12') runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') { // Mixin includes a lot of dependencies that are too up-to-date @@ -91,13 +112,16 @@ dependencies { exclude module: 'commons-io' exclude module: 'log4j-core' } + testImplementation 'junit:junit:4.12' } +/* mixin { defaultObfuscationEnv searge add sourceSets.launch, 'mixins.baritone.refmap.json' } +*/ javadoc { options.addStringOption('Xwerror', '-quiet') // makes the build fail on travis when there is a javadoc error diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 7b47a2a6f..f49166461 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -647,7 +647,7 @@ public final class Settings { * via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting * {@link Setting#value}; */ - public final Setting> logger = new Setting<>(Minecraft.getMinecraft().ingameGUI.getChatGUI()::printChatMessage); + public final Setting> logger = new Setting<>(Minecraft.getInstance().ingameGUI.getChatGUI()::printChatMessage); /** * The color of the current path diff --git a/src/api/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java index dc471e5fb..8d39d6422 100644 --- a/src/api/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/IGameEventListener.java @@ -18,12 +18,12 @@ package baritone.api.event.listener; import baritone.api.event.events.*; -import io.netty.util.concurrent.GenericFutureListener; +import net.minecraft.client.GameSettings; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiGameOver; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.settings.GameSettings; import net.minecraft.entity.Entity; import net.minecraft.network.Packet; @@ -45,7 +45,7 @@ public interface IGameEventListener { * Run once per game tick from before and after the player rotation is sent to the server. * * @param event The event - * @see EntityPlayerSP#onUpdate() + * @see EntityPlayerSP#tick() */ void onPlayerUpdate(PlayerUpdateEvent event); @@ -66,9 +66,7 @@ public interface IGameEventListener { void onChunkEvent(ChunkEvent event); /** - * Runs once per world render pass. Two passes are made when {@link GameSettings#anaglyph} is on. - *

- * Note: {@link GameSettings#anaglyph} has been removed in Minecraft 1.13 + * Runs once per world render pass. * * @param event The event */ @@ -78,7 +76,7 @@ public interface IGameEventListener { * Runs before and after whenever a new world is loaded * * @param event The event - * @see Minecraft#loadWorld(WorldClient, String) + * @see Minecraft#loadWorld(WorldClient, GuiScreen) */ void onWorldEvent(WorldEvent event); @@ -87,7 +85,6 @@ public interface IGameEventListener { * * @param event The event * @see Packet - * @see GenericFutureListener */ void onSendPacket(PacketEvent event); @@ -96,7 +93,6 @@ public interface IGameEventListener { * * @param event The event * @see Packet - * @see GenericFutureListener */ void onReceivePacket(PacketEvent event); @@ -110,10 +106,10 @@ public interface IGameEventListener { void onPlayerRotationMove(RotationMoveEvent event); /** - * Called whenever the sprint keybind state is checked in {@link EntityPlayerSP#onLivingUpdate} + * Called whenever the sprint keybind state is checked in {@link EntityPlayerSP#livingTick} * * @param event The event - * @see EntityPlayerSP#onLivingUpdate() + * @see EntityPlayerSP#livingTick() */ void onPlayerSprintState(SprintStateEvent event); diff --git a/src/api/java/baritone/api/utils/IPlayerContext.java b/src/api/java/baritone/api/utils/IPlayerContext.java index 83040ab52..7abfee802 100644 --- a/src/api/java/baritone/api/utils/IPlayerContext.java +++ b/src/api/java/baritone/api/utils/IPlayerContext.java @@ -71,7 +71,7 @@ public interface IPlayerContext { * @return The position of the highlighted block */ default Optional getSelectedBlock() { - if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK) { + if (objectMouseOver() != null && objectMouseOver().type == RayTraceResult.Type.BLOCK) { return Optional.of(objectMouseOver().getBlockPos()); } return Optional.empty(); @@ -83,8 +83,8 @@ public interface IPlayerContext { * @return The entity */ default Optional getSelectedEntity() { - if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.ENTITY) { - return Optional.of(objectMouseOver().entityHit); + if (objectMouseOver() != null && objectMouseOver().type == RayTraceResult.Type.ENTITY) { + return Optional.of(objectMouseOver().entity); } return Optional.empty(); } diff --git a/src/api/java/baritone/api/utils/RayTraceUtils.java b/src/api/java/baritone/api/utils/RayTraceUtils.java index 0fd1e4e01..872cadbd9 100644 --- a/src/api/java/baritone/api/utils/RayTraceUtils.java +++ b/src/api/java/baritone/api/utils/RayTraceUtils.java @@ -18,6 +18,7 @@ package baritone.api.utils; import net.minecraft.entity.Entity; +import net.minecraft.util.math.RayTraceFluidMode; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; @@ -40,13 +41,13 @@ public final class RayTraceUtils { * @return The calculated raytrace result */ public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) { - Vec3d start = entity.getPositionEyes(1.0F); + Vec3d start = entity.getEyePosition(1.0F); Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation); Vec3d end = start.add( direction.x * blockReachDistance, direction.y * blockReachDistance, direction.z * blockReachDistance ); - return entity.world.rayTraceBlocks(start, end, false, false, true); + return entity.world.rayTraceBlocks(start, end, RayTraceFluidMode.NEVER, false, true); } } diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index 3010d2832..9e810e187 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -23,7 +23,9 @@ import net.minecraft.block.BlockFire; import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.Entity; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.*; +import net.minecraft.util.math.shapes.VoxelShape; import java.util.Optional; @@ -174,11 +176,11 @@ public final class RotationUtils { } IBlockState state = entity.world.getBlockState(pos); - AxisAlignedBB aabb = state.getBoundingBox(entity.world, pos); + VoxelShape shape = state.getCollisionShape(entity.world, pos); for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) { - double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x); - double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y); - double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z); + double xDiff = shape.getStart(EnumFacing.Axis.X) * sideOffset.x + shape.getEnd(EnumFacing.Axis.X) * (1 - sideOffset.x); + double yDiff = shape.getStart(EnumFacing.Axis.Y) * sideOffset.y + shape.getEnd(EnumFacing.Axis.Y) * (1 - sideOffset.y); + double zDiff = shape.getStart(EnumFacing.Axis.Z) * sideOffset.z + shape.getEnd(EnumFacing.Axis.Z) * (1 - sideOffset.z); possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance); if (possibleRotation.isPresent()) { return possibleRotation; @@ -199,10 +201,10 @@ public final class RotationUtils { * @return The optional rotation */ public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance) { - Rotation rotation = calcRotationFromVec3d(entity.getPositionEyes(1.0F), offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); + Rotation rotation = calcRotationFromVec3d(entity.getEyePosition(1.0F), offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance); //System.out.println(result); - if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { + if (result != null && result.type == RayTraceResult.Type.BLOCK) { if (result.getBlockPos().equals(pos)) { return Optional.of(rotation); } diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 84e9af689..73517c405 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -18,8 +18,10 @@ package baritone.api.utils; import baritone.api.Settings; +import net.minecraft.client.Minecraft; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; import java.awt.*; import java.io.BufferedReader; @@ -36,11 +38,9 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import static net.minecraft.client.Minecraft.getMinecraft; - public class SettingsUtil { - private static final Path SETTINGS_PATH = getMinecraft().gameDir.toPath().resolve("baritone").resolve("settings.txt"); + private static final Path SETTINGS_PATH = Minecraft.getInstance().gameDir.toPath().resolve("baritone").resolve("settings.txt"); private static final Pattern SETTING_PATTERN = Pattern.compile("^(?[^ ]+) +(?[^ ]+)"); // 2 words separated by spaces private static final Map, SettingsIO> map; @@ -146,7 +146,7 @@ public class SettingsUtil { FLOAT(Float.class, Float::parseFloat), LONG(Long.class, Long::parseLong), - ITEM_LIST(ArrayList.class, str -> Stream.of(str.split(",")).map(Item::getByNameOrId).collect(Collectors.toCollection(ArrayList::new)), list -> ((ArrayList) list).stream().map(Item.REGISTRY::getNameForObject).map(ResourceLocation::toString).collect(Collectors.joining(","))), + ITEM_LIST(ArrayList.class, str -> Stream.of(str.split(",")).map(ResourceLocation::new).map(IRegistry.ITEM::get).collect(Collectors.toCollection(ArrayList::new)), list -> ((ArrayList) list).stream().map(IRegistry.ITEM::getKey).map(ResourceLocation::toString).collect(Collectors.joining(","))), COLOR(Color.class, str -> new Color(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])), color -> color.getRed() + "," + color.getGreen() + "," + color.getBlue()); diff --git a/src/api/java/baritone/api/utils/VecUtils.java b/src/api/java/baritone/api/utils/VecUtils.java index 4c35c05e8..b268c914a 100644 --- a/src/api/java/baritone/api/utils/VecUtils.java +++ b/src/api/java/baritone/api/utils/VecUtils.java @@ -20,9 +20,11 @@ package baritone.api.utils; import net.minecraft.block.BlockFire; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.World; /** @@ -43,10 +45,10 @@ public final class VecUtils { */ public static Vec3d calculateBlockCenter(World world, BlockPos pos) { IBlockState b = world.getBlockState(pos); - AxisAlignedBB bbox = b.getBoundingBox(world, pos); - double xDiff = (bbox.minX + bbox.maxX) / 2; - double yDiff = (bbox.minY + bbox.maxY) / 2; - double zDiff = (bbox.minZ + bbox.maxZ) / 2; + VoxelShape shape = b.getCollisionShape(world, pos); + double xDiff = (shape.getStart(EnumFacing.Axis.X) + shape.getEnd(EnumFacing.Axis.X)) / 2; + double yDiff = (shape.getStart(EnumFacing.Axis.Y) + shape.getEnd(EnumFacing.Axis.Y)) / 2; + double zDiff = (shape.getStart(EnumFacing.Axis.Z) + shape.getEnd(EnumFacing.Axis.Z)) / 2; if (b.getBlock() instanceof BlockFire) {//look at bottom of fire when putting it out yDiff = 0; } diff --git a/src/api/java/baritone/api/utils/input/Input.java b/src/api/java/baritone/api/utils/input/Input.java index 1e8d44b50..c7143db96 100644 --- a/src/api/java/baritone/api/utils/input/Input.java +++ b/src/api/java/baritone/api/utils/input/Input.java @@ -17,8 +17,8 @@ package baritone.api.utils.input; +import net.minecraft.client.GameSettings; import net.minecraft.client.Minecraft; -import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.KeyBinding; import java.util.Arrays; @@ -97,7 +97,7 @@ public enum Input { an interface with a game instance field just to not have to do this. */ - this.keyBinding = keyBindingMapper.apply(Minecraft.getMinecraft().gameSettings); + this.keyBinding = keyBindingMapper.apply(Minecraft.getInstance().gameSettings); } /** diff --git a/src/launch/java/baritone/launch/BaritoneTweaker.java b/src/launch/java/baritone/launch/BaritoneTweaker.java index b9db9b6a5..8201d60fd 100644 --- a/src/launch/java/baritone/launch/BaritoneTweaker.java +++ b/src/launch/java/baritone/launch/BaritoneTweaker.java @@ -31,6 +31,7 @@ import java.util.List; * @author Brady * @since 7/31/2018 */ +@Deprecated public class BaritoneTweaker extends SimpleTweaker { @Override diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java index 0fc814874..1548057d8 100644 --- a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java +++ b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java @@ -29,6 +29,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL14.*; @Mixin(ChunkRenderContainer.class) public class MixinChunkRenderContainer { @@ -41,11 +42,11 @@ public class MixinChunkRenderContainer { ) ) private BlockPos getPosition(RenderChunk renderChunkIn) { - if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null && Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) { - GlStateManager.enableAlpha(); + if (Baritone.settings().renderCachedChunks.get() && Minecraft.getInstance().getIntegratedServer() == null && Minecraft.getInstance().world.getChunk(renderChunkIn.getPosition()).isEmpty()) { + GlStateManager.enableAlphaTest(); GlStateManager.enableBlend(); GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.get()); - GlStateManager.tryBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO); + GlStateManager.blendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO); } return renderChunkIn.getPosition(); } diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkRenderWorker.java b/src/launch/java/baritone/launch/mixins/MixinChunkRenderWorker.java index 2bd1521c7..4b87260db 100644 --- a/src/launch/java/baritone/launch/mixins/MixinChunkRenderWorker.java +++ b/src/launch/java/baritone/launch/mixins/MixinChunkRenderWorker.java @@ -43,7 +43,7 @@ public abstract class MixinChunkRenderWorker { ) ) private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) { - if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) { + if (Baritone.settings().renderCachedChunks.get() && Minecraft.getInstance().getIntegratedServer() == null) { Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); IPlayerContext ctx = baritone.getPlayerContext(); if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java index 0fd2436c9..c3d3cb1fb 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java @@ -23,6 +23,7 @@ import baritone.api.event.events.RotationMoveEvent; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.EntityType; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -44,9 +45,8 @@ public abstract class MixinEntityLivingBase extends Entity { */ private RotationMoveEvent jumpRotationEvent; - public MixinEntityLivingBase(World worldIn, RotationMoveEvent jumpRotationEvent) { - super(worldIn); - this.jumpRotationEvent = jumpRotationEvent; + public MixinEntityLivingBase(EntityType entityTypeIn, World worldIn) { + super(entityTypeIn, worldIn); } @Inject( diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 7c1225b9b..16ca15b07 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -58,10 +58,10 @@ public class MixinEntityPlayerSP { } @Inject( - method = "onUpdate", + method = "tick", at = @At( value = "INVOKE", - target = "net/minecraft/client/entity/EntityPlayerSP.isRiding()Z", + target = "net/minecraft/client/entity/EntityPlayerSP.isPassenger()Z", shift = At.Shift.BY, by = -3 ) @@ -74,7 +74,7 @@ public class MixinEntityPlayerSP { } @Inject( - method = "onUpdate", + method = "tick", at = @At( value = "INVOKE", target = "net/minecraft/client/entity/EntityPlayerSP.onUpdateWalkingPlayer()V", @@ -90,7 +90,7 @@ public class MixinEntityPlayerSP { } @Redirect( - method = "onLivingUpdate", + method = "livingTick", at = @At( value = "FIELD", target = "net/minecraft/entity/player/PlayerCapabilities.allowFlying:Z" @@ -105,7 +105,7 @@ public class MixinEntityPlayerSP { } @Redirect( - method = "onLivingUpdate", + method = "livingTick", at = @At( value = "INVOKE", target = "net/minecraft/client/settings/KeyBinding.isKeyDown()Z" diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java b/src/launch/java/baritone/launch/mixins/MixinGameRenderer.java similarity index 85% rename from src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java rename to src/launch/java/baritone/launch/mixins/MixinGameRenderer.java index dfd01e46e..57de55c7d 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java +++ b/src/launch/java/baritone/launch/mixins/MixinGameRenderer.java @@ -20,24 +20,24 @@ package baritone.launch.mixins; import baritone.api.BaritoneAPI; import baritone.api.IBaritone; import baritone.api.event.events.RenderEvent; -import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.GameRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(EntityRenderer.class) -public class MixinEntityRenderer { +@Mixin(GameRenderer.class) +public class MixinGameRenderer { @Inject( - method = "renderWorldPass", + method = "updateCameraAndRender(FJ)V", at = @At( value = "INVOKE_STRING", target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V", args = {"ldc=hand"} ) ) - private void renderWorldPass(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + private void renderWorldPass(float partialTicks, long finishTimeNano, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks)); } diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 6ee1a79be..6c065049a 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -97,10 +97,10 @@ public class MixinMinecraft { } @Inject( - method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", + method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/client/gui/GuiScreen;)V", at = @At("HEAD") ) - private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { + private void preLoadWorld(WorldClient world, GuiScreen loadingScreen, CallbackInfo ci) { // If we're unloading the world but one doesn't exist, ignore it if (this.world == null && world == null) { return; @@ -117,10 +117,10 @@ public class MixinMinecraft { } @Inject( - method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", + method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/client/gui/GuiScreen;)V", at = @At("RETURN") ) - private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { + private void postLoadWorld(WorldClient world, GuiScreen loadingScreen, CallbackInfo ci) { // still fire event for both null, as that means we've just finished exiting a world // mc.world changing is only the primary baritone diff --git a/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java index e2cc98427..013c38a13 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java +++ b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java @@ -24,6 +24,7 @@ import baritone.api.event.events.type.EventState; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.play.server.SPacketChunkData; import net.minecraft.network.play.server.SPacketCombatEvent; +import net.minecraft.network.play.server.SPacketUnloadChunk; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -40,7 +41,7 @@ public class MixinNetHandlerPlayClient { method = "handleChunkData", at = @At( value = "INVOKE", - target = "net/minecraft/world/chunk/Chunk.read(Lnet/minecraft/network/PacketBuffer;IZ)V" + target = "net/minecraft/client/multiplayer/ChunkProviderClient.func_212474_a(IILnet/minecraft/network/PacketBuffer;IZ)Lnet/minecraft/world/chunk/Chunk;" ) ) private void preRead(SPacketChunkData packetIn, CallbackInfo ci) { @@ -77,6 +78,34 @@ public class MixinNetHandlerPlayClient { } } + @Inject( + method = "processChunkUnload", + at = @At("HEAD") + ) + private void preChunkUnload(SPacketUnloadChunk packet, CallbackInfo ci) { + for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { + if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) { + ibaritone.getGameEventHandler().onChunkEvent( + new ChunkEvent(EventState.PRE, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ()) + ); + } + } + } + + @Inject( + method = "processChunkUnload", + at = @At("RETURN") + ) + private void postChunkUnload(SPacketUnloadChunk packet, CallbackInfo ci) { + for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { + if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) { + ibaritone.getGameEventHandler().onChunkEvent( + new ChunkEvent(EventState.POST, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ()) + ); + } + } + } + @Inject( method = "handleCombatEvent", at = @At( diff --git a/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java b/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java index 577be96dc..895d2df7e 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java +++ b/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java @@ -53,7 +53,7 @@ public class MixinNetworkManager { method = "dispatchPacket", at = @At("HEAD") ) - private void preDispatchPacket(Packet inPacket, final GenericFutureListener>[] futureListeners, CallbackInfo ci) { + private void preDispatchPacket(Packet inPacket, final GenericFutureListener> futureListeners, CallbackInfo ci) { if (this.direction != EnumPacketDirection.CLIENTBOUND) { return; } @@ -69,7 +69,7 @@ public class MixinNetworkManager { method = "dispatchPacket", at = @At("RETURN") ) - private void postDispatchPacket(Packet inPacket, final GenericFutureListener>[] futureListeners, CallbackInfo ci) { + private void postDispatchPacket(Packet inPacket, final GenericFutureListener> futureListeners, CallbackInfo ci) { if (this.direction != EnumPacketDirection.CLIENTBOUND) { return; } @@ -85,7 +85,7 @@ public class MixinNetworkManager { method = "channelRead0", at = @At( value = "INVOKE", - target = "net/minecraft/network/Packet.processPacket(Lnet/minecraft/network/INetHandler;)V" + target = "net/minecraft/network/NetworkManager.processPacket(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;)V" ) ) private void preProcessPacket(ChannelHandlerContext context, Packet packet, CallbackInfo ci) { diff --git a/src/launch/java/baritone/launch/mixins/MixinRenderChunk.java b/src/launch/java/baritone/launch/mixins/MixinRenderChunk.java index 754f523f2..792b7a8fd 100644 --- a/src/launch/java/baritone/launch/mixins/MixinRenderChunk.java +++ b/src/launch/java/baritone/launch/mixins/MixinRenderChunk.java @@ -23,8 +23,8 @@ import baritone.api.utils.IPlayerContext; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.chunk.RenderChunk; +import net.minecraft.client.renderer.chunk.RenderChunkCache; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.ChunkCache; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -36,6 +36,9 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(RenderChunk.class) public class MixinRenderChunk { + // TODO: Resolve this issue + // Looks like generateCache will return null if the chunk is empty, so we're probably going to want to hook that method + /* @Redirect( method = "rebuildChunk", at = @At( @@ -47,7 +50,7 @@ public class MixinRenderChunk { if (!chunkCache.isEmpty()) { return false; } - if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) { + if (Baritone.settings().renderCachedChunks.get() && Minecraft.getInstance().getIntegratedServer() == null) { Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); IPlayerContext ctx = baritone.getPlayerContext(); if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { @@ -67,16 +70,17 @@ public class MixinRenderChunk { return true; } + */ @Redirect( method = "rebuildChunk", at = @At( value = "INVOKE", - target = "net/minecraft/world/ChunkCache.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;" + target = "net/minecraft/client/renderer/chunk/RenderChunkCache.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;" ) ) - private IBlockState getBlockState(ChunkCache chunkCache, BlockPos pos) { - if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) { + private IBlockState getBlockState(RenderChunkCache chunkCache, BlockPos pos) { + if (Baritone.settings().renderCachedChunks.get() && Minecraft.getInstance().getIntegratedServer() == null) { Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); IPlayerContext ctx = baritone.getPlayerContext(); if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { diff --git a/src/launch/java/baritone/launch/mixins/MixinRenderList.java b/src/launch/java/baritone/launch/mixins/MixinRenderList.java index e2f0ae902..651760ec1 100644 --- a/src/launch/java/baritone/launch/mixins/MixinRenderList.java +++ b/src/launch/java/baritone/launch/mixins/MixinRenderList.java @@ -38,9 +38,9 @@ public class MixinRenderList { ) ) private void popMatrix() { - if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) { + if (Baritone.settings().renderCachedChunks.get() && Minecraft.getInstance().getIntegratedServer() == null) { // reset the blend func to normal (not dependent on constant alpha) - GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); } GlStateManager.popMatrix(); } diff --git a/src/launch/java/baritone/launch/mixins/MixinVboRenderList.java b/src/launch/java/baritone/launch/mixins/MixinVboRenderList.java index f51d22341..6ea02a0a1 100644 --- a/src/launch/java/baritone/launch/mixins/MixinVboRenderList.java +++ b/src/launch/java/baritone/launch/mixins/MixinVboRenderList.java @@ -38,9 +38,9 @@ public class MixinVboRenderList { ) ) private void popMatrix() { - if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().getIntegratedServer() == null) { + if (Baritone.settings().renderCachedChunks.get() && Minecraft.getInstance().getIntegratedServer() == null) { // reset the blend func to normal (not dependent on constant alpha) - GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); } GlStateManager.popMatrix(); } diff --git a/src/launch/java/baritone/launch/mixins/MixinWorldClient.java b/src/launch/java/baritone/launch/mixins/MixinWorldClient.java deleted file mode 100644 index 7c1561631..000000000 --- a/src/launch/java/baritone/launch/mixins/MixinWorldClient.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.launch.mixins; - -import baritone.api.BaritoneAPI; -import baritone.api.IBaritone; -import baritone.api.event.events.ChunkEvent; -import baritone.api.event.events.type.EventState; -import net.minecraft.client.multiplayer.WorldClient; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * @author Brady - * @since 8/2/2018 - */ -@Mixin(WorldClient.class) -public class MixinWorldClient { - - @Inject( - method = "doPreChunk", - at = @At("HEAD") - ) - private void preDoPreChunk(int chunkX, int chunkZ, boolean loadChunk, CallbackInfo ci) { - for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().world() == (WorldClient) (Object) this) { - ibaritone.getGameEventHandler().onChunkEvent( - new ChunkEvent( - EventState.PRE, - loadChunk ? ChunkEvent.Type.LOAD : ChunkEvent.Type.UNLOAD, - chunkX, - chunkZ - ) - ); - } - } - - } - - @Inject( - method = "doPreChunk", - at = @At("RETURN") - ) - private void postDoPreChunk(int chunkX, int chunkZ, boolean loadChunk, CallbackInfo ci) { - for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().world() == (WorldClient) (Object) this) { - ibaritone.getGameEventHandler().onChunkEvent( - new ChunkEvent( - EventState.POST, - loadChunk ? ChunkEvent.Type.LOAD : ChunkEvent.Type.UNLOAD, - chunkX, - chunkZ - ) - ); - } - } - } -} diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index 3b5fa70cc..858cb71e9 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -16,13 +16,12 @@ "MixinChunkRenderWorker", "MixinEntityLivingBase", "MixinEntityPlayerSP", - "MixinEntityRenderer", + "MixinGameRenderer", "MixinMinecraft", "MixinNetHandlerPlayClient", "MixinNetworkManager", "MixinRenderChunk", "MixinRenderList", - "MixinVboRenderList", - "MixinWorldClient" + "MixinVboRenderList" ] } \ No newline at end of file diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 51a6ff699..d9a9b2f64 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -55,7 +55,7 @@ public class Baritone implements IBaritone { static { threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); - dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); + dir = new File(Minecraft.getInstance().gameDir, "baritone"); if (!Files.exists(dir.toPath())) { try { Files.createDirectories(dir.toPath()); diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index df0921cf4..345416d37 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -28,9 +28,6 @@ public final class LookBehavior extends Behavior implements ILookBehavior { /** * Target's values are as follows: - *

- * getFirst() -> yaw - * getSecond() -> pitch */ private Rotation target; diff --git a/src/main/java/baritone/cache/CachedChunk.java b/src/main/java/baritone/cache/CachedChunk.java index d2737190f..1a34b2aef 100644 --- a/src/main/java/baritone/cache/CachedChunk.java +++ b/src/main/java/baritone/cache/CachedChunk.java @@ -52,9 +52,10 @@ public final class CachedChunk { temp.add(Blocks.TRAPPED_CHEST); temp.add(Blocks.END_PORTAL); temp.add(Blocks.END_PORTAL_FRAME); - temp.add(Blocks.MOB_SPAWNER); + temp.add(Blocks.SPAWNER); temp.add(Blocks.BARRIER); temp.add(Blocks.OBSERVER); + temp.add(Blocks.WHITE_SHULKER_BOX); temp.add(Blocks.ORANGE_SHULKER_BOX); temp.add(Blocks.MAGENTA_SHULKER_BOX); @@ -63,7 +64,7 @@ public final class CachedChunk { temp.add(Blocks.LIME_SHULKER_BOX); temp.add(Blocks.PINK_SHULKER_BOX); temp.add(Blocks.GRAY_SHULKER_BOX); - temp.add(Blocks.SILVER_SHULKER_BOX); + temp.add(Blocks.LIGHT_GRAY_SHULKER_BOX); temp.add(Blocks.CYAN_SHULKER_BOX); temp.add(Blocks.PURPLE_SHULKER_BOX); temp.add(Blocks.BLUE_SHULKER_BOX); @@ -71,22 +72,56 @@ public final class CachedChunk { temp.add(Blocks.GREEN_SHULKER_BOX); temp.add(Blocks.RED_SHULKER_BOX); temp.add(Blocks.BLACK_SHULKER_BOX); - temp.add(Blocks.PORTAL); + + temp.add(Blocks.NETHER_PORTAL); temp.add(Blocks.HOPPER); temp.add(Blocks.BEACON); temp.add(Blocks.BREWING_STAND); - temp.add(Blocks.SKULL); + + // TODO: Maybe add a predicate for blocks to keep track of? + // This should really not need to happen + temp.add(Blocks.CREEPER_HEAD); + temp.add(Blocks.CREEPER_WALL_HEAD); + temp.add(Blocks.DRAGON_HEAD); + temp.add(Blocks.DRAGON_WALL_HEAD); + temp.add(Blocks.PLAYER_HEAD); + temp.add(Blocks.PLAYER_WALL_HEAD); + temp.add(Blocks.ZOMBIE_HEAD); + temp.add(Blocks.ZOMBIE_WALL_HEAD); + temp.add(Blocks.SKELETON_SKULL); + temp.add(Blocks.SKELETON_WALL_SKULL); + temp.add(Blocks.WITHER_SKELETON_SKULL); + temp.add(Blocks.WITHER_SKELETON_WALL_SKULL); + temp.add(Blocks.ENCHANTING_TABLE); temp.add(Blocks.ANVIL); - temp.add(Blocks.LIT_FURNACE); - temp.add(Blocks.BED); + + temp.add(Blocks.WHITE_BED); + temp.add(Blocks.ORANGE_BED); + temp.add(Blocks.MAGENTA_BED); + temp.add(Blocks.LIGHT_BLUE_BED); + temp.add(Blocks.YELLOW_BED); + temp.add(Blocks.LIME_BED); + temp.add(Blocks.PINK_BED); + temp.add(Blocks.GRAY_BED); + temp.add(Blocks.LIGHT_GRAY_BED); + temp.add(Blocks.CYAN_BED); + temp.add(Blocks.PURPLE_BED); + temp.add(Blocks.BLUE_BED); + temp.add(Blocks.BROWN_BED); + temp.add(Blocks.GREEN_BED); + temp.add(Blocks.RED_BED); + temp.add(Blocks.BLACK_BED); + temp.add(Blocks.DRAGON_EGG); temp.add(Blocks.JUKEBOX); temp.add(Blocks.END_GATEWAY); - temp.add(Blocks.WEB); + temp.add(Blocks.COBWEB); temp.add(Blocks.NETHER_WART); temp.add(Blocks.LADDER); BLOCKS_TO_KEEP_TRACK_OF = Collections.unmodifiableSet(temp); + + // TODO: Lit Furnaces } /** @@ -147,8 +182,8 @@ public final class CachedChunk { if (heightMap[internalPos] == y) { // we have this exact block, it's a surface block /*System.out.println("Saying that " + x + "," + y + "," + z + " is " + state); - if (!Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock().equals(state.getBlock())) { - throw new IllegalStateException("failed " + Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock() + " " + state.getBlock() + " " + (x + this.x * 16) + " " + y + " " + (z + this.z * 16)); + if (!Minecraft.getInstance().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock().equals(state.getBlock())) { + throw new IllegalStateException("failed " + Minecraft.getInstance().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock() + " " + state.getBlock() + " " + (x + this.x * 16) + " " + y + " " + (z + this.z * 16)); }*/ return overview[internalPos]; } diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index 892369d5b..90aec3f4a 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -24,9 +24,11 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.registry.IRegistry; import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import net.minecraft.world.chunk.ChunkSection; import java.util.*; @@ -46,9 +48,9 @@ public final class ChunkPacker { Map> specialBlocks = new HashMap<>(); BitSet bitSet = new BitSet(CachedChunk.SIZE); try { - ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); + ChunkSection[] chunkInternalStorageArray = chunk.getSections(); for (int y0 = 0; y0 < 16; y0++) { - ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0]; + ChunkSection extendedblockstorage = chunkInternalStorageArray[y0]; if (extendedblockstorage == null) { // any 16x16x16 area that's all air will have null storage // for example, in an ocean biome, with air from y=64 to y=256 @@ -60,7 +62,7 @@ public final class ChunkPacker { // since a bitset is initialized to all zero, and air is saved as zeros continue; } - BlockStateContainer bsc = extendedblockstorage.getData(); + BlockStateContainer bsc = extendedblockstorage.getData(); int yReal = y0 << 4; // the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x; // for better cache locality, iterate in that order @@ -106,7 +108,7 @@ public final class ChunkPacker { } public static String blockToString(Block block) { - ResourceLocation loc = Block.REGISTRY.getNameForObject(block); + ResourceLocation loc = IRegistry.BLOCK.getKey(block); String name = loc.getPath(); // normally, only write the part after the minecraft: if (!loc.getNamespace().equals("minecraft")) { // Baritone is running on top of forge with mods installed, perhaps? @@ -116,24 +118,25 @@ public final class ChunkPacker { } public static Block stringToBlock(String name) { - return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n)); + return resourceCache.computeIfAbsent(name, n -> IRegistry.BLOCK.get(new ResourceLocation(n.contains(":") ? n : "minecraft:" + n))); } private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) { Block block = state.getBlock(); - if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) { + if (MovementHelper.isWater(state)) { // only water source blocks are plausibly usable, flowing water should be avoid // FLOWING_WATER is a waterfall, it doesn't really matter and caching it as AVOID just makes it look wrong if (!MovementHelper.possiblyFlowing(state)) { return PathingBlockType.WATER; } - if (BlockLiquid.getSlopeAngle(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4), state.getMaterial(), state) != -1000.0F) { + Vec3d flow = state.getFluidState().getFlow(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4)); + if (flow.x != 0.0 || flow.z != 0.0) { return PathingBlockType.AVOID; } return PathingBlockType.WATER; } - if (MovementHelper.avoidWalkingInto(block) || MovementHelper.isBottomSlab(state)) { + if (MovementHelper.avoidWalkingInto(state) || MovementHelper.isBottomSlab(state)) { return PathingBlockType.AVOID; } // We used to do an AABB check here diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index fe2efa4eb..3e8c03a82 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -24,6 +24,7 @@ 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.dimension.DimensionType; import org.apache.commons.lang3.SystemUtils; import java.io.File; @@ -55,7 +56,7 @@ public class WorldProvider implements IWorldProvider, Helper { * * @param dimension The ID of the world's dimension */ - public final void initWorld(int dimension) { + public final void initWorld(DimensionType dimension) { File directory; File readme; @@ -101,7 +102,7 @@ public class WorldProvider implements IWorldProvider, Helper { System.out.println("Baritone world data dir: " + dir); synchronized (worldCache) { - this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension)); + this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension.getId())); } } diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java index 463dd22f7..6f81201b1 100644 --- a/src/main/java/baritone/cache/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -26,7 +26,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import net.minecraft.world.chunk.ChunkSection; import java.util.ArrayList; import java.util.Collection; @@ -67,7 +67,7 @@ public enum WorldScanner implements IWorldScanner { foundChunks = true; int chunkX = xoff + playerChunkX; int chunkZ = zoff + playerChunkZ; - Chunk chunk = chunkProvider.getLoadedChunk(chunkX, chunkZ); + Chunk chunk = chunkProvider.getChunk(chunkX, chunkZ, false, false); if (chunk == null) { continue; } @@ -92,7 +92,7 @@ public enum WorldScanner implements IWorldScanner { } ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider(); - Chunk chunk = chunkProvider.getLoadedChunk(pos.x, pos.z); + Chunk chunk = chunkProvider.getChunk(pos.x, pos.z, false, false); int playerY = ctx.playerFeet().getY(); if (chunk == null || chunk.isEmpty()) { @@ -105,14 +105,14 @@ public enum WorldScanner implements IWorldScanner { } public void scanChunkInto(int chunkX, int chunkZ, Chunk chunk, List search, Collection result, int max, int yLevelThreshold, int playerY) { - ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); + ChunkSection[] chunkInternalStorageArray = chunk.getSections(); for (int y0 = 0; y0 < 16; y0++) { - ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0]; + ChunkSection extendedblockstorage = chunkInternalStorageArray[y0]; if (extendedblockstorage == null) { continue; } int yReal = y0 << 4; - BlockStateContainer bsc = extendedblockstorage.getData(); + BlockStateContainer bsc = extendedblockstorage.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++) { diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index b1bb1182d..6d947a9a8 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -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().isChunkGeneratedAt(event.getX(), event.getZ()); + && world.getChunkProvider().getChunk(event.getX(), event.getZ(), false, false) != null; if (isPostPopulate || isPreUnload) { baritone.getWorldProvider().ifWorldLoaded(worldData -> { @@ -109,7 +109,7 @@ public final class GameEventHandler implements IEventBus, Helper { if (event.getState() == EventState.POST) { cache.closeWorld(); if (event.getWorld() != null) { - cache.initWorld(event.getWorld().provider.getDimensionType().getId()); + cache.initWorld(event.getWorld().getDimension().getType()); } } diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 4c3b299d2..23d9d8e1c 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -77,7 +77,7 @@ public class CalculationContext { this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread); // TODO TODO TODO this.toolSet = new ToolSet(player); this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(baritone.getPlayerContext(), false); - this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.provider.isNether(); + this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.getDimension().isNether(); this.canSprint = Baritone.settings().allowSprint.get() && player.getFoodStats().getFoodLevel() > 6; this.placeBlockCost = Baritone.settings().blockPlacementPenalty.get(); this.allowBreak = Baritone.settings().allowBreak.get(); diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 15f4fa24b..6eec9285c 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -23,7 +23,7 @@ import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.*; import baritone.api.utils.input.Input; import baritone.utils.BlockStateInterface; -import net.minecraft.block.BlockLiquid; +import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -109,7 +109,7 @@ public abstract class Movement implements IMovement, MovementHelper { */ @Override public MovementStatus update() { - ctx.player().capabilities.isFlying = false; + ctx.player().abilities.isFlying = false; currentState = updateState(currentState); if (MovementHelper.isLiquid(ctx, ctx.playerFeet())) { currentState.setInput(Input.JUMP, true); @@ -143,7 +143,7 @@ public abstract class Movement implements IMovement, MovementHelper { } boolean somethingInTheWay = false; for (BetterBlockPos blockPos : positionsToBreak) { - if (!MovementHelper.canWalkThrough(ctx, blockPos) && !(BlockStateInterface.getBlock(ctx, blockPos) instanceof BlockLiquid)) { // can't break liquid, so don't try + if (!MovementHelper.canWalkThrough(ctx, blockPos) && BlockStateInterface.getBlock(ctx, blockPos) != Blocks.AIR) { // can't break air, so don't try somethingInTheWay = true; Optional reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance()); if (reachable.isPresent()) { @@ -159,7 +159,7 @@ public abstract class Movement implements IMovement, MovementHelper { //i'm doing it anyway //i dont care if theres snow in the way!!!!!!! //you dont own me!!!! - state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F), + state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.player().getEyePosition(1.0F), VecUtils.getBlockPosCenter(blockPos), ctx.playerRotations()), true) ); // don't check selectedblock on this one, this is a fallback when we can't see any face directly, it's intended to be breaking the "incorrect" block diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 592aecd0e..5782ee253 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -28,12 +28,19 @@ import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.ToolSet; import net.minecraft.block.*; -import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; +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.item.ItemPickaxe; import net.minecraft.item.ItemStack; +import net.minecraft.pathfinding.PathType; +import net.minecraft.state.BooleanProperty; +import net.minecraft.state.properties.SlabType; import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; @@ -56,11 +63,11 @@ public interface MovementHelper extends ActionCosts, Helper { return b == Blocks.ICE // ice becomes water, and water can mess up the path || b instanceof BlockSilverfish // obvious reasons // call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason - || bsi.get0(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side - || bsi.get0(x + 1, y, z).getBlock() instanceof BlockLiquid - || bsi.get0(x - 1, y, z).getBlock() instanceof BlockLiquid - || bsi.get0(x, y, z + 1).getBlock() instanceof BlockLiquid - || bsi.get0(x, y, z - 1).getBlock() instanceof BlockLiquid; + || !bsi.get0(x, y + 1, z).getFluidState().isEmpty()//don't break anything touching liquid on any side + || !bsi.get0(x + 1, y, z).getFluidState().isEmpty() + || !bsi.get0(x - 1, y, z).getFluidState().isEmpty() + || !bsi.get0(x, y, z + 1).getFluidState().isEmpty() + || !bsi.get0(x, y, z - 1).getFluidState().isEmpty(); } static boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) { @@ -76,7 +83,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.AIR) { // early return for most common case return true; } - if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull) { + if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull) { return false; } if (block instanceof BlockDoor || block instanceof BlockFenceGate) { @@ -85,7 +92,7 @@ public interface MovementHelper extends ActionCosts, Helper { // be opened by just interacting. return block != Blocks.IRON_DOOR; } - boolean snow = block instanceof BlockSnow; + boolean snow = block instanceof BlockSnowLayer; boolean trapdoor = block instanceof BlockTrapDoor; if (snow || trapdoor) { // we've already checked doors and fence gates @@ -98,34 +105,36 @@ public interface MovementHelper extends ActionCosts, Helper { if (snow) { // 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.getValue(BlockSnow.LAYERS) >= 3) { + if (state.get(BlockSnowLayer.LAYERS) >= 3) { return false; } // ok, it's low enough we could walk through it, but is it supported? return canWalkOn(bsi, x, y - 1, z); } if (trapdoor) { - return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable + return !state.get(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable } + // The previous condition should always be true, so this exception will never be thrown throw new IllegalStateException(); } if (isFlowing(x, y, z, state, bsi)) { return false; // Don't walk through flowing liquids } - if (block instanceof BlockLiquid) { + IFluidState fluidState = state.getFluidState(); + if (fluidState.getFluid() instanceof WaterFluid) { if (Baritone.settings().assumeWalkOnWater.get()) { return false; } IBlockState up = bsi.get0(x, y + 1, z); - if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { + if (!up.getFluidState().isEmpty() || up.getBlock() instanceof BlockLilyPad) { return false; } - return block == Blocks.WATER || block == Blocks.FLOWING_WATER; + return true; } // every block that overrides isPassable with anything more complicated than a "return true;" or "return false;" // has already been accounted for above // therefore it's safe to not construct a blockpos from our x, y, z ints and instead just pass null - return block.isPassable(null, null); + return state.allowsMovement(null, null, PathType.LAND); } /** @@ -150,21 +159,21 @@ public interface MovementHelper extends ActionCosts, Helper { // exceptions - blocks that are isPassable true, but we can't actually jump through if (block == Blocks.FIRE || block == Blocks.TRIPWIRE - || block == Blocks.WEB + || block == Blocks.COBWEB || block == Blocks.VINE || block == Blocks.LADDER || block == Blocks.COCOA || block instanceof BlockDoor || block instanceof BlockFenceGate || block instanceof BlockSnow - || block instanceof BlockLiquid + || !state.getFluidState().isEmpty() || block instanceof BlockTrapDoor || block instanceof BlockEndPortal || block instanceof BlockSkull) { return false; } // door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters - return block.isPassable(null, null); + return state.allowsMovement(null, null, PathType.LAND); } static boolean isReplacable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) { @@ -179,20 +188,19 @@ public interface MovementHelper extends ActionCosts, Helper { * } */ Block block = state.getBlock(); - if (block == Blocks.AIR || isWater(block)) { + if (block == Blocks.AIR || isWater(state)) { // early return for common cases hehe return true; } - if (block instanceof BlockSnow) { + if (block instanceof BlockSnowLayer) { // 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.getValue(BlockSnow.LAYERS) == 1; + return state.get(BlockSnowLayer.LAYERS) == 1; } - if (block instanceof BlockDoublePlant) { - BlockDoublePlant.EnumPlantType kek = state.getValue(BlockDoublePlant.VARIANT); - return kek == BlockDoublePlant.EnumPlantType.FERN || kek == BlockDoublePlant.EnumPlantType.GRASS; + if (block == Blocks.LARGE_FERN || block == Blocks.TALL_GRASS) { + return true; } return state.getMaterial().isReplaceable(); } @@ -220,16 +228,16 @@ public interface MovementHelper extends ActionCosts, Helper { return true; } - return state.getValue(BlockFenceGate.OPEN); + return state.get(BlockFenceGate.OPEN); } - static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) { + static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, BooleanProperty propertyOpen) { if (playerPos.equals(blockPos)) { return false; } - EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis(); - boolean open = blockState.getValue(propertyOpen); + EnumFacing.Axis facing = blockState.get(BlockHorizontal.HORIZONTAL_FACING).getAxis(); + boolean open = blockState.get(propertyOpen); EnumFacing.Axis playerFacing; if (playerPos.north().equals(blockPos) || playerPos.south().equals(blockPos)) { @@ -243,14 +251,14 @@ public interface MovementHelper extends ActionCosts, Helper { return (facing == playerFacing) == open; } - static boolean avoidWalkingInto(Block block) { - return block instanceof BlockLiquid - || block instanceof BlockDynamicLiquid - || block == Blocks.MAGMA + static boolean avoidWalkingInto(IBlockState state) { + Block block = state.getBlock(); + return !state.getFluidState().isEmpty() + || block == Blocks.MAGMA_BLOCK || block == Blocks.CACTUS || block == Blocks.FIRE || block == Blocks.END_PORTAL - || block == Blocks.WEB; + || block == Blocks.COBWEB; } /** @@ -267,7 +275,7 @@ public interface MovementHelper extends ActionCosts, Helper { */ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { Block block = state.getBlock(); - if (block == Blocks.AIR || block == Blocks.MAGMA) { + if (block == Blocks.AIR || block == Blocks.MAGMA_BLOCK) { // early return for most common case (air) // plus magma, which is a normal cube but it hurts you return false; @@ -284,30 +292,28 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST) { return true; } - if (isWater(block)) { + if (isWater(state)) { // since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()" // BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability - Block up = bsi.get0(x, y + 1, z).getBlock(); - if (up == Blocks.WATERLILY || up == Blocks.CARPET) { + IBlockState upState = bsi.get0(x, y + 1, z); + Block up = upState.getBlock(); + if (up == Blocks.LILY_PAD || up instanceof BlockCarpet) { return true; } - if (isFlowing(x, y, z, state, bsi) || block == Blocks.FLOWING_WATER) { + if (isFlowing(x, y, z, state, bsi) || upState.getFluidState().getFluid() == Fluids.FLOWING_WATER) { // the only scenario in which we can walk on flowing water is if it's under still water with jesus off - return isWater(up) && !Baritone.settings().assumeWalkOnWater.get(); + return isWater(upState) && !Baritone.settings().assumeWalkOnWater.get(); } // if assumeWalkOnWater is on, we can only walk on water if there isn't water above it // if assumeWalkOnWater is off, we can only walk on water if there is water above it - return isWater(up) ^ Baritone.settings().assumeWalkOnWater.get(); + return isWater(upState) ^ Baritone.settings().assumeWalkOnWater.get(); } - if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) { + if (block == Blocks.GLASS || block instanceof BlockStainedGlass) { return true; } if (block instanceof BlockSlab) { if (!Baritone.settings().allowWalkOnBottomSlab.get()) { - if (((BlockSlab) block).isDouble()) { - return true; - } - return state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM; + return state.isTopSolid(); } return true; } @@ -356,7 +362,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (avoidBreaking(context.bsi, x, y, z, state)) { return COST_INF; } - if (block instanceof BlockLiquid) { + if (!state.getFluidState().isEmpty()) { return COST_INF; } double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table @@ -380,8 +386,7 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean isBottomSlab(IBlockState state) { return state.getBlock() instanceof BlockSlab - && !((BlockSlab) state.getBlock()).isDouble() - && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM; + && state.get(BlockSlab.TYPE) == SlabType.BOTTOM; } /** @@ -454,11 +459,12 @@ public interface MovementHelper extends ActionCosts, Helper { * Returns whether or not the specified block is * water, regardless of whether or not it is flowing. * - * @param b The block + * @param state The block state * @return Whether or not the block is water */ - static boolean isWater(Block b) { - return b == Blocks.FLOWING_WATER || b == Blocks.WATER; + static boolean isWater(IBlockState state) { + Fluid f = state.getFluidState().getFluid(); + return f == Fluids.WATER || f == Fluids.FLOWING_WATER; } /** @@ -470,11 +476,12 @@ public interface MovementHelper extends ActionCosts, Helper { * @return Whether or not the block is water */ static boolean isWater(IPlayerContext ctx, BlockPos bp) { - return isWater(BlockStateInterface.getBlock(ctx, bp)); + return isWater(BlockStateInterface.get(ctx, bp)); } - static boolean isLava(Block b) { - return b == Blocks.FLOWING_LAVA || b == Blocks.LAVA; + static boolean isLava(IBlockState state) { + Fluid f = state.getFluidState().getFluid(); + return f == Fluids.LAVA || f == Fluids.FLOWING_LAVA; } /** @@ -485,20 +492,25 @@ public interface MovementHelper extends ActionCosts, Helper { * @return Whether or not the block is a liquid */ static boolean isLiquid(IPlayerContext ctx, BlockPos p) { - return BlockStateInterface.getBlock(ctx, p) instanceof BlockLiquid; + return isLiquid(BlockStateInterface.get(ctx, p)); + } + + static boolean isLiquid(IBlockState blockState) { + return !blockState.getFluidState().isEmpty(); } static boolean possiblyFlowing(IBlockState state) { - // Will be IFluidState in 1.13 - return state.getBlock() instanceof BlockLiquid - && state.getValue(BlockLiquid.LEVEL) != 0; + IFluidState fluidState = state.getFluidState(); + return fluidState.getFluid() instanceof FlowingFluid + && state.get(FlowingFluid.LEVEL_1_8) != 0; } static boolean isFlowing(int x, int y, int z, IBlockState state, BlockStateInterface bsi) { - if (!(state.getBlock() instanceof BlockLiquid)) { + IFluidState fluidState = state.getFluidState(); + if (!(fluidState.getFluid() instanceof FlowingFluid)) { return false; } - if (state.getValue(BlockLiquid.LEVEL) != 0) { + if (fluidState.get(FlowingFluid.LEVEL_1_8) != 0) { return true; } return possiblyFlowing(bsi.get0(x + 1, y, z)) @@ -530,7 +542,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.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) { + if (res != null && res.type == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) { state.setTarget(new MovementState.MovementTarget(place, true)); found = true; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 3a8ed913e..84a89bcb7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -137,7 +137,7 @@ public class MovementDescend extends Movement { IBlockState ontoBlock = context.get(destX, newY, destZ); int unprotectedFallHeight = fallHeight - (y - effectiveStartHeight); // equal to fallHeight - y + effectiveFallHeight, which is equal to -newY + effectiveFallHeight, which is equal to effectiveFallHeight - newY double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[unprotectedFallHeight] + frontBreak + costSoFar; - if ((ontoBlock.getBlock() == Blocks.WATER || ontoBlock.getBlock() == Blocks.FLOWING_WATER) && context.getBlock(destX, newY + 1, destZ) != Blocks.WATERLILY) { + if (MovementHelper.isWater(ontoBlock) && context.getBlock(destX, newY + 1, destZ) != Blocks.LILY_PAD) { // lilypads are canWalkThrough, but we can't end a fall that should be broken by water if it's covered by a lilypad // however, don't return impossible in the lilypad scenario, because we could still jump right on it (water that's below a lilypad is canWalkOn so it works) if (context.assumeWalkOnWater) { @@ -214,7 +214,7 @@ public class MovementDescend extends Movement { double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83; EntityPlayerSP player = ctx.player(); state.setTarget(new MovementState.MovementTarget( - new Rotation(RotationUtils.calcRotationFromVec3d(player.getPositionEyes(1.0F), + new Rotation(RotationUtils.calcRotationFromVec3d(player.getEyePosition(1.0F), new Vec3d(destX, dest.getY(), destZ), new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch), false @@ -250,7 +250,7 @@ public class MovementDescend extends Movement { return true; } for (int y = 0; y <= 2; y++) { // we could hit any of the three blocks - if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(ctx, into.up(y)))) { + if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, into.up(y)))) { return true; } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index f156ff1b4..a360ba450 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -91,12 +91,12 @@ public class MovementDiagonal extends Movement { if (fromDown == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } - Block cuttingOver1 = context.get(x, y - 1, destZ).getBlock(); - if (cuttingOver1 == Blocks.MAGMA || MovementHelper.isLava(cuttingOver1)) { + IBlockState cuttingOver1 = context.get(x, y - 1, destZ); + if (cuttingOver1.getBlock() == Blocks.MAGMA_BLOCK || MovementHelper.isLava(cuttingOver1)) { return; } - Block cuttingOver2 = context.get(destX, y - 1, z).getBlock(); - if (cuttingOver2 == Blocks.MAGMA || MovementHelper.isLava(cuttingOver2)) { + IBlockState cuttingOver2 = context.get(destX, y - 1, z); + if (cuttingOver2.getBlock() == Blocks.MAGMA_BLOCK || MovementHelper.isLava(cuttingOver2)) { return; } IBlockState pb0 = context.get(x, y, destZ); @@ -115,7 +115,7 @@ public class MovementDiagonal extends Movement { return; } IBlockState pb3 = context.get(destX, y + 1, z); - if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2.getBlock()) && pb2.getBlock() != Blocks.WATER) || MovementHelper.avoidWalkingInto(pb3.getBlock()))) { + if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2) && pb2.getBlock() != Blocks.WATER) || MovementHelper.avoidWalkingInto(pb3))) { // at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction return; } @@ -124,13 +124,14 @@ public class MovementDiagonal extends Movement { // and finally, if the cost is nonzero for both ways to approach this diagonal, it's not possible return; } - if (optionB == 0 && ((MovementHelper.avoidWalkingInto(pb0.getBlock()) && pb0.getBlock() != Blocks.WATER) || MovementHelper.avoidWalkingInto(pb1.getBlock()))) { + if (optionB == 0 && ((MovementHelper.avoidWalkingInto(pb0) && pb0.getBlock() != Blocks.WATER) || MovementHelper.avoidWalkingInto(pb1))) { // and now that option B is fully calculated, see if we can edge around that way return; } boolean water = false; - Block startIn = context.getBlock(x, y, z); - if (MovementHelper.isWater(startIn) || MovementHelper.isWater(destInto.getBlock())) { + IBlockState startState = context.get(x, y, z); + Block startIn = startState.getBlock(); + if (MovementHelper.isWater(startState) || MovementHelper.isWater(destInto)) { // Ignore previous multiplier // Whatever we were walking on (possibly soul sand) doesn't matter as we're actually floating on water // Not even touching the blocks below diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 93f60f5d1..5aeb73e47 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -34,6 +34,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockLadder; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.fluid.WaterFluid; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -80,10 +81,11 @@ public class MovementFall extends Movement { BlockPos playerFeet = ctx.playerFeet(); Rotation toDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()); Rotation targetRotation = null; - Block destBlock = ctx.world().getBlockState(dest).getBlock(); - boolean isWater = destBlock == Blocks.WATER || destBlock == Blocks.FLOWING_WATER; + IBlockState destState = ctx.world().getBlockState(dest); + 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().provider.isNether()) { + if (!InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().getDimension().isNether()) { return state.setStatus(MovementStatus.UNREACHABLE); } @@ -93,7 +95,7 @@ public class MovementFall extends Movement { targetRotation = new Rotation(toDest.getYaw(), 90.0F); RayTraceResult trace = ctx.objectMouseOver(); - if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK && (trace.getBlockPos().equals(dest) || trace.getBlockPos().equals(dest.down()))) { + if (trace != null && trace.type == RayTraceResult.Type.BLOCK && (trace.getBlockPos().equals(dest) || trace.getBlockPos().equals(dest.down()))) { state.setInput(Input.CLICK_RIGHT, true); } } @@ -150,7 +152,7 @@ public class MovementFall extends Movement { for (int i = 0; i < 15; i++) { IBlockState state = ctx.world().getBlockState(ctx.playerFeet().down(i)); if (state.getBlock() == Blocks.LADDER) { - return state.getValue(BlockLadder.FACING); + return state.get(BlockLadder.FACING); } } return null; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 185167c69..de143e8d4 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -28,10 +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.BlockLiquid; import net.minecraft.block.BlockStairs; import net.minecraft.block.state.IBlockState; +import net.minecraft.fluid.WaterFluid; import net.minecraft.init.Blocks; +import net.minecraft.init.Fluids; import net.minecraft.util.EnumFacing; public class MovementParkour extends Movement { @@ -73,7 +74,7 @@ public class MovementParkour extends Movement { // second most common case -- we could just traverse not parkour return; } - if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks + if (MovementHelper.avoidWalkingInto(adj) && !(adj.getFluidState().getFluid() instanceof WaterFluid)) { // magma sucks return; } if (!MovementHelper.fullyPassable(context, x + xDiff, y + 1, z + zDiff)) { @@ -86,7 +87,7 @@ public class MovementParkour extends Movement { return; } IBlockState standingOn = context.get(x, y - 1, z); - if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn) || standingOn.getBlock() instanceof BlockLiquid) { + if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn) || standingOn.getFluidState().getFluid() != Fluids.EMPTY) { return; } int maxJump; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 1bbfa6f91..a873c254d 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -49,14 +49,15 @@ public class MovementPillar extends Movement { } public static double cost(CalculationContext context, int x, int y, int z) { - Block from = context.get(x, y, z).getBlock(); + IBlockState fromState = context.get(x, y, z); + Block from = fromState.getBlock(); boolean ladder = from == Blocks.LADDER || from == Blocks.VINE; IBlockState fromDown = context.get(x, y - 1, z); if (!ladder) { 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 && !((BlockSlab) fromDown.getBlock()).isDouble() && fromDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + if (fromDown.getBlock() instanceof BlockSlab && !fromDown.isTopSolid()) { return COST_INF; // can't pillar up from a bottom slab onto a non ladder } } @@ -68,9 +69,9 @@ public class MovementPillar extends Movement { if (toBreakBlock instanceof BlockFenceGate) { // see issue #172 return COST_INF; } - Block srcUp = null; - if (MovementHelper.isWater(toBreakBlock) && MovementHelper.isWater(from)) { // TODO should this also be allowed if toBreakBlock is air? - srcUp = context.get(x, y + 1, z).getBlock(); + IBlockState srcUp = null; + if (MovementHelper.isWater(toBreak) && MovementHelper.isWater(fromState)) { // TODO should this also be allowed if toBreakBlock is air? + srcUp = context.get(x, y + 1, z); if (MovementHelper.isWater(srcUp)) { return LADDER_UP_ONE_COST; // allow ascending pillars of water, but only if we're already in one } @@ -78,7 +79,7 @@ public class MovementPillar extends Movement { if (!ladder && !context.canPlaceThrowawayAt(x, y, z)) { // we need to place a block where we started to jump on it return COST_INF; } - if (from instanceof BlockLiquid || (fromDown.getBlock() instanceof BlockLiquid && context.assumeWalkOnWater)) { + if (MovementHelper.isLiquid(fromState) || (MovementHelper.isLiquid(fromDown) && context.assumeWalkOnWater)) { // otherwise, if we're standing in water, we cannot pillar // if we're standing on water and assumeWalkOnWater is true, we cannot pillar // if we're standing on water and assumeWalkOnWater is false, we must have ascended to here, or sneak backplaced, so it is possible to pillar again @@ -96,9 +97,9 @@ public class MovementPillar extends Movement { if (check.getBlock() instanceof BlockFalling) { // see MovementAscend's identical check for breaking a falling block above our head if (srcUp == null) { - srcUp = context.get(x, y + 1, z).getBlock(); + srcUp = context.get(x, y + 1, z); } - if (!(toBreakBlock instanceof BlockFalling) || !(srcUp instanceof BlockFalling)) { + if (!(toBreakBlock instanceof BlockFalling) || !(srcUp.getBlock() instanceof BlockFalling)) { return COST_INF; } } @@ -149,7 +150,7 @@ public class MovementPillar extends Movement { } IBlockState fromDown = BlockStateInterface.get(ctx, src); - if (MovementHelper.isWater(fromDown.getBlock()) && MovementHelper.isWater(ctx, dest)) { + if (MovementHelper.isWater(fromDown) && MovementHelper.isWater(ctx, dest)) { // stay centered while swimming up a water column state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()), false)); Vec3d destCenter = VecUtils.getBlockPosCenter(dest); @@ -163,7 +164,7 @@ public class MovementPillar extends Movement { } boolean ladder = fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE; boolean vine = fromDown.getBlock() == Blocks.VINE; - Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F), + Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.player().getEyePosition(1.0F), VecUtils.getBlockPosCenter(positionToPlace), new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch)); if (!ladder) { @@ -172,7 +173,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.getValue(BlockLadder.FACING).getOpposite()); + BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.get(BlockLadder.FACING).getOpposite()); if (against == null) { logDebug("Unable to climb vines"); return state.setStatus(MovementStatus.UNREACHABLE); @@ -222,8 +223,10 @@ public class MovementPillar extends Movement { if (!blockIsThere) { - Block fr = BlockStateInterface.get(ctx, src).getBlock(); - if (!(fr instanceof BlockAir || fr.isReplaceable(ctx.world(), src))) { + IBlockState frState = BlockStateInterface.get(ctx, src); + Block fr = frState.getBlock(); + // TODO: Evaluate usage of getMaterial().isReplaceable() + if (!(fr instanceof BlockAir || frState.getMaterial().isReplaceable())) { 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) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index d618cf1a0..3203b0880 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -35,7 +35,9 @@ import net.minecraft.block.BlockDoor; import net.minecraft.block.BlockFenceGate; import net.minecraft.block.BlockSlab; import net.minecraft.block.state.IBlockState; +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; @@ -67,11 +69,12 @@ public class MovementTraverse extends Movement { IBlockState pb0 = context.get(destX, y + 1, destZ); IBlockState pb1 = context.get(destX, y, destZ); IBlockState destOn = context.get(destX, y - 1, destZ); - Block srcDown = context.getBlock(x, y - 1, z); + IBlockState down = context.get(x, y - 1, z); + Block srcDown = down.getBlock(); if (MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; boolean water = false; - if (MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock())) { + if (MovementHelper.isWater(pb0) || MovementHelper.isWater(pb1)) { WC = context.waterWalkSpeed; water = true; } else { @@ -108,8 +111,8 @@ public class MovementTraverse extends Movement { return COST_INF; } if (MovementHelper.isReplacable(destX, y - 1, destZ, destOn, context.bsi)) { - boolean throughWater = MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock()); - if (MovementHelper.isWater(destOn.getBlock()) && throughWater) { + boolean throughWater = MovementHelper.isWater(pb0) || MovementHelper.isWater(pb1); + if (MovementHelper.isWater(destOn) && throughWater) { // this happens when assume walk on water is true and this is a traverse in water, which isn't allowed return COST_INF; } @@ -134,10 +137,10 @@ 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 && !((BlockSlab) srcDown).isDouble())) { + if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof BlockSlab && down.get(BlockSlab.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 (srcDown == Blocks.FLOWING_WATER || srcDown == Blocks.WATER) { + if (down.getFluidState() instanceof WaterFluid) { return COST_INF; // this is obviously impossible } WC = WC * (SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST);//since we are sneak backplacing, we are sneaking lol @@ -160,10 +163,10 @@ public class MovementTraverse extends Movement { return state; } // and if it's fine to walk into the blocks in front - if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[0]).getBlock())) { + if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[0]))) { return state; } - if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[1]).getBlock())) { + if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[1]))) { return state; } // and we aren't already pressed up against the block @@ -232,8 +235,8 @@ public class MovementTraverse extends Movement { return state.setStatus(MovementStatus.SUCCESS); } BlockPos into = dest.subtract(src).add(dest); - Block intoBelow = BlockStateInterface.get(ctx, into).getBlock(); - Block intoAbove = BlockStateInterface.get(ctx, into.up()).getBlock(); + IBlockState intoBelow = BlockStateInterface.get(ctx, into); + IBlockState intoAbove = BlockStateInterface.get(ctx, into.up()); if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, ctx.playerFeet()) || Baritone.settings().sprintInWater.get()) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) { state.setInput(Input.SPRINT, true); } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index b025f6899..1d4baa86a 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -36,8 +36,8 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.movements.*; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; -import net.minecraft.block.BlockLiquid; import net.minecraft.init.Blocks; +import net.minecraft.init.Fluids; import net.minecraft.util.Tuple; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -137,7 +137,7 @@ public class PathExecutor implements IPathExecutor, Helper { Tuple status = closestPathPos(path); if (possiblyOffPath(status, MAX_DIST_FROM_PATH)) { ticksAway++; - System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + status.getFirst() + ". Threshold: " + MAX_DIST_FROM_PATH); + System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + status.getA() + ". Threshold: " + MAX_DIST_FROM_PATH); if (ticksAway > MAX_TICKS_AWAY) { logDebug("Too far away from path for too long, cancelling path"); cancel(); @@ -333,7 +333,7 @@ public class PathExecutor implements IPathExecutor, Helper { } private boolean possiblyOffPath(Tuple status, double leniency) { - double distanceFromPath = status.getFirst(); + double distanceFromPath = status.getA(); if (distanceFromPath > leniency) { // when we're midair in the middle of a fall, we're very far from both the beginning and the end, but we aren't actually off path if (path.movements().get(pathPosition) instanceof MovementFall) { @@ -353,7 +353,7 @@ public class PathExecutor implements IPathExecutor, Helper { * @return Whether or not it was possible to snap to the current player feet */ public boolean snipsnapifpossible() { - if (!ctx.player().onGround && !(ctx.world().getBlockState(ctx.playerFeet()).getBlock() instanceof BlockLiquid)) { + if (!ctx.player().onGround && ctx.world().getFluidState(ctx.playerFeet()).isEmpty()) { // if we're falling in the air, and not in water, don't splice return false; } else { @@ -453,7 +453,7 @@ public class PathExecutor implements IPathExecutor, Helper { if (current instanceof MovementFall) { Tuple data = overrideFall((MovementFall) current); if (data != null) { - BlockPos fallDest = data.getSecond(); + BlockPos fallDest = data.getB(); if (!path.positions().contains(fallDest)) { throw new IllegalStateException(); } @@ -464,7 +464,7 @@ public class PathExecutor implements IPathExecutor, Helper { return true; } clearKeys(); - behavior.baritone.getLookBehavior().updateTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), data.getFirst(), ctx.playerRotations()), false); + behavior.baritone.getLookBehavior().updateTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), data.getA(), ctx.playerRotations()), false); behavior.baritone.getInputOverrideHandler().setInputForceState(Input.MOVE_FORWARD, true); return true; } @@ -556,10 +556,10 @@ public class PathExecutor implements IPathExecutor, Helper { } } } - if (MovementHelper.avoidWalkingInto(ctx.world().getBlockState(current.getSrc().up(3)).getBlock())) { + if (MovementHelper.avoidWalkingInto(ctx.world().getBlockState(current.getSrc().up(3)))) { return false; } - return !MovementHelper.avoidWalkingInto(ctx.world().getBlockState(next.getDest().up(2)).getBlock()); // codacy smh my head + return !MovementHelper.avoidWalkingInto(ctx.world().getBlockState(next.getDest().up(2))); // codacy smh my head } private static boolean canSprintFromDescendInto(IPlayerContext ctx, IMovement current, IMovement next) { diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index 3d25c0765..013f1ffa9 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -72,7 +72,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo if (entity == null) { return false; } - if (entity.isDead) { + if (!entity.isAlive()) { return false; } if (entity.equals(ctx.player())) { diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index cb80926b1..db3769c68 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -203,7 +203,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl if (!Baritone.settings().enterPortal.get()) { return false; } - return block == Blocks.PORTAL; + return block == Blocks.NETHER_PORTAL; } private boolean rightClickOnArrival(Block block) { diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index a299bf314..2347424cd 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -37,6 +37,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.IItemProvider; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -71,11 +72,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro @Override public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { if (desiredQuantity > 0) { - Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), new Random(), 0); + Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), ctx.world(), null, 0).asItem(); int curr = ctx.player().inventory.mainInventory.stream().filter(stack -> item.equals(stack.getItem())).mapToInt(ItemStack::getCount).sum(); System.out.println("Currently have " + curr + " " + item); if (curr >= desiredQuantity) { - logDirect("Have " + curr + " " + item.getItemStackDisplayName(new ItemStack(item, 1))); + logDirect("Have " + curr + " " + item.getDisplayName(new ItemStack(item, 1))); cancel(); return null; } @@ -187,7 +188,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } Set searchingFor = new HashSet<>(); for (Block block : mining) { - Item drop = block.getItemDropped(block.getDefaultState(), new Random(), 0); + Item drop = block.getItemDropped(block.getDefaultState(), world, null, 0).asItem(); Item ore = Item.getItemFromBlock(block); searchingFor.add(drop); searchingFor.add(ore); diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index c798c563f..a006e8e7c 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -23,14 +23,17 @@ import baritone.api.event.listener.AbstractGameEventListener; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalBlock; 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.settings.GameSettings; import net.minecraft.client.tutorial.TutorialSteps; +import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.util.HttpUtil; import net.minecraft.util.math.BlockPos; import net.minecraft.world.GameType; import net.minecraft.world.WorldSettings; import net.minecraft.world.WorldType; +import net.minecraft.world.dimension.DimensionType; /** * Responsible for automatically testing Baritone's pathing algorithm by automatically creating a world with a specific @@ -88,11 +91,13 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { mc.launchIntegratedServer("BaritoneAutoTest", "BaritoneAutoTest", worldsettings); } + IntegratedServer server = mc.getIntegratedServer(); + // If the integrated server is launched and the world has initialized, set the spawn point // to our defined starting position - if (mc.getIntegratedServer() != null && mc.getIntegratedServer().worlds[0] != null) { - mc.getIntegratedServer().worlds[0].setSpawnPoint(STARTING_POSITION); - mc.getIntegratedServer().worlds[0].getGameRules().setOrCreateGameRule("spawnRadius", "0"); + if (server != null && server.getWorld(DimensionType.OVERWORLD) != null) { + server.getWorld(DimensionType.OVERWORLD).setSpawnPoint(STARTING_POSITION); + server.getWorld(DimensionType.OVERWORLD).getGameRules().setOrCreateGameRule("spawnRadius", "0", server); } if (event.getType() == TickEvent.Type.IN) { // If we're in-game @@ -100,7 +105,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); + mc.getIntegratedServer().shareToLAN(GameType.getByName("survival"), false, HttpUtil.getSuitableLanPort()); } // For the first 200 ticks, wait for the world to generate diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index db56b91f7..b5b7c7757 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -53,7 +53,7 @@ public final class BlockBreakHelper implements Helper { public void tick(boolean isLeftClick) { RayTraceResult trace = playerContext.objectMouseOver(); - boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK; + boolean isBlockTrace = trace != null && trace.type == RayTraceResult.Type.BLOCK; if (isLeftClick && isBlockTrace) { tryBreakBlock(trace.getBlockPos(), trace.sideHit); diff --git a/src/main/java/baritone/utils/BlockPlaceHelper.java b/src/main/java/baritone/utils/BlockPlaceHelper.java index e0c782bb4..904417413 100644 --- a/src/main/java/baritone/utils/BlockPlaceHelper.java +++ b/src/main/java/baritone/utils/BlockPlaceHelper.java @@ -39,7 +39,7 @@ public class BlockPlaceHelper implements Helper { } RayTraceResult mouseOver = ctx.objectMouseOver(); BlockPos pos = mouseOver.getBlockPos(); - if (!rightClickRequested || ctx.player().isRowingBoat() || pos == null || mouseOver.typeOfHit != RayTraceResult.Type.BLOCK) { + if (!rightClickRequested || ctx.player().isRowingBoat() || pos == null || mouseOver.type != RayTraceResult.Type.BLOCK) { return; } rightClickTimer = Baritone.settings().rightClickSpeed.get(); diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 5f8cac6ad..e49cff757 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -67,7 +67,7 @@ public class BlockStateInterface { this.loadedChunks = worldLoaded; // this will only be used on the main thread } this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.get(); - if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) { + if (!Minecraft.getInstance().isCallingFromMinecraftThread()) { throw new IllegalStateException(); } } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 31ee8ff1f..6986cca13 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -241,7 +241,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { int count = 0; for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) { for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) { - Chunk chunk = cli.getLoadedChunk(x, z); + Chunk chunk = cli.getChunk(x, z, false, false); if (chunk != null) { count++; baritone.getWorldProvider().getCurrentWorld().getCachedWorld().queueForPacking(chunk); @@ -306,7 +306,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } if (msg.equals("render")) { BetterBlockPos pf = ctx.playerFeet(); - Minecraft.getMinecraft().renderGlobal.markBlockRangeForRenderUpdate(pf.x - 500, pf.y - 500, pf.z - 500, pf.x + 500, pf.y + 500, pf.z + 500); + Minecraft.getInstance().worldRenderer.markBlockRangeForRenderUpdate(pf.x - 500, pf.y - 500, pf.z - 500, pf.x + 500, pf.y + 500, pf.z + 500); logDirect("okay"); return true; } @@ -349,8 +349,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper { toFollow = ctx.getSelectedEntity(); } else { for (EntityPlayer pl : ctx.world().playerEntities) { - String theirName = pl.getName().trim().toLowerCase(); - if (!theirName.equals(ctx.player().getName().trim().toLowerCase()) && (theirName.contains(name) || name.contains(theirName))) { // don't follow ourselves lol + String theirName = pl.getName().getString().trim().toLowerCase(); + if (!theirName.equals(ctx.player().getName().getString().trim().toLowerCase()) && (theirName.contains(name) || name.contains(theirName))) { // don't follow ourselves lol toFollow = Optional.of(pl); } } @@ -554,7 +554,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { private void log(List stacks) { for (ItemStack stack : stacks) { if (!stack.isEmpty()) { - logDirect(stack.getCount() + "x " + stack.getDisplayName() + "@" + stack.getItemDamage()); + logDirect(stack.getCount() + "x " + stack.getDisplayName() + "@" + stack.getDamage()); } } } diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index f85f240cc..d960fb629 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -42,7 +42,7 @@ public interface Helper { TextFormatting.GRAY )); - Minecraft mc = Minecraft.getMinecraft(); + Minecraft mc = Minecraft.getInstance(); /** * Send a message to chat only if chatDebug is on @@ -64,9 +64,9 @@ public interface Helper { * @param message The message to display in chat */ default void logDirect(String message) { - ITextComponent component = MESSAGE_PREFIX.createCopy(); + ITextComponent component = MESSAGE_PREFIX.shallowCopy(); component.getStyle().setColor(TextFormatting.GRAY); component.appendSibling(new TextComponentString(" " + message)); - Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.get().accept(component)); + Minecraft.getInstance().addScheduledTask(() -> Baritone.settings().logger.get().accept(component)); } } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 47a068546..5f393059f 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -100,7 +100,7 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri } } else { if (ctx.player().movementInput.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam - ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings); + ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getInstance().gameSettings); } } // only set it if it was previously incorrect diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 06e298be3..a66d3b4d2 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -34,6 +34,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityBeaconRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; @@ -51,6 +52,7 @@ import static org.lwjgl.opengl.GL11.*; */ public final class PathRenderer implements Helper { + private static final ResourceLocation TEXTURE_BEACON_BEAM = new ResourceLocation("textures/entity/beacon_beam.png"); private static final Tessellator TESSELLATOR = Tessellator.getInstance(); private static final BufferBuilder BUFFER = TESSELLATOR.getBuffer(); @@ -60,8 +62,8 @@ public final class PathRenderer implements Helper { float partialTicks = event.getPartialTicks(); Goal goal = behavior.getGoal(); - int thisPlayerDimension = behavior.baritone.getPlayerContext().world().provider.getDimensionType().getId(); - int currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().provider.getDimensionType().getId(); + int thisPlayerDimension = behavior.baritone.getPlayerContext().world().getDimension().getType().getId(); + int currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().getDimension().getType().getId(); if (thisPlayerDimension != currentRenderViewDimension) { // this is a path for a bot in a different dimension, don't render it @@ -127,13 +129,13 @@ public final class PathRenderer implements Helper { public static void drawPath(IPath path, int startIndex, Entity player, float partialTicks, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0) { GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); - GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F); - GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get()); + 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.get()); GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); if (Baritone.settings().renderPathIgnoreDepth.get()) { - GlStateManager.disableDepth(); + GlStateManager.disableDepthTest(); } List positions = path.positions(); int next; @@ -170,13 +172,13 @@ public final class PathRenderer implements Helper { } alpha = 0.4F * (1.0F - (float) (i - fadeStart) / (float) (fadeEnd - fadeStart)); } - GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], alpha); + GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], alpha); } drawLine(player, x1, y1, z1, x2, y2, z2, partialTicks); tessellator.draw(); } if (Baritone.settings().renderPathIgnoreDepth.get()) { - GlStateManager.enableDepth(); + GlStateManager.enableDepthTest(); } //GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f); GlStateManager.depthMask(true); @@ -198,14 +200,14 @@ public final class PathRenderer implements Helper { public static void drawManySelectionBoxes(Entity player, Collection positions, float partialTicks, Color color) { GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F); - GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get()); + GlStateManager.blendFuncSeparate(770, 771, 1, 0); + GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F); + GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.get()); GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); if (Baritone.settings().renderSelectionBoxesIgnoreDepth.get()) { - GlStateManager.disableDepth(); + GlStateManager.disableDepthTest(); } float expand = 0.002F; @@ -219,9 +221,9 @@ public final class PathRenderer implements Helper { IBlockState state = bsi.get0(pos); AxisAlignedBB toDraw; if (state.getBlock().equals(Blocks.AIR)) { - toDraw = Blocks.DIRT.getDefaultState().getSelectedBoundingBox(player.world, pos); + toDraw = Blocks.DIRT.getDefaultState().getShape(player.world, pos).getBoundingBox(); } else { - toDraw = state.getSelectedBoundingBox(player.world, pos); + toDraw = state.getShape(player.world, pos).getBoundingBox(); } toDraw = toDraw.expand(expand, expand, expand).offset(-renderPosX, -renderPosY, -renderPosZ); BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); @@ -251,7 +253,7 @@ public final class PathRenderer implements Helper { }); if (Baritone.settings().renderSelectionBoxesIgnoreDepth.get()) { - GlStateManager.enableDepth(); + GlStateManager.enableDepthTest(); } GlStateManager.depthMask(true); @@ -297,10 +299,10 @@ public final class PathRenderer implements Helper { if (Baritone.settings().renderGoalXZBeacon.get()) { glPushAttrib(GL_LIGHTING_BIT); - mc.getTextureManager().bindTexture(TileEntityBeaconRenderer.TEXTURE_BEACON_BEAM); + mc.getTextureManager().bindTexture(TEXTURE_BEACON_BEAM); if (Baritone.settings().renderGoalIgnoreDepth.get()) { - GlStateManager.disableDepth(); + GlStateManager.disableDepthTest(); } TileEntityBeaconRenderer.renderBeamSegment( @@ -309,14 +311,18 @@ public final class PathRenderer implements Helper { goalPos.getZ() - renderPosZ, partialTicks, 1.0, - player.world.getTotalWorldTime(), + player.world.getGameTime(), 0, 256, - color.getColorComponents(null) + color.getColorComponents(null), + + // Arguments filled by the private method lol + 0.2D, + 0.25D ); if (Baritone.settings().renderGoalIgnoreDepth.get()) { - GlStateManager.enableDepth(); + GlStateManager.enableDepthTest(); } glPopAttrib(); @@ -342,13 +348,13 @@ public final class PathRenderer implements Helper { } GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.6F); - GlStateManager.glLineWidth(Baritone.settings().goalRenderLineWidthPixels.get()); + GlStateManager.blendFuncSeparate(770, 771, 1, 0); + GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.6F); + GlStateManager.lineWidth(Baritone.settings().goalRenderLineWidthPixels.get()); GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); if (Baritone.settings().renderGoalIgnoreDepth.get()) { - GlStateManager.disableDepth(); + GlStateManager.disableDepthTest(); } renderHorizontalQuad(minX, maxX, minZ, maxZ, y1); @@ -366,7 +372,7 @@ public final class PathRenderer implements Helper { TESSELLATOR.draw(); if (Baritone.settings().renderGoalIgnoreDepth.get()) { - GlStateManager.enableDepth(); + GlStateManager.enableDepthTest(); } GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index bfa4e2513..9566f2a64 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -24,7 +24,6 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.init.Enchantments; import net.minecraft.init.MobEffects; -import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemTool; @@ -75,19 +74,13 @@ public class ToolSet { } /** - * Evaluate the material cost of a possible tool. The priority matches the - * listed order in the Item.ToolMaterial enum. + * Evaluate the material cost of a possible tool. Will return 1 for tools, -1 for other * * @param itemStack a possibly empty ItemStack - * @return values range from -1 to 4 + * @return Either 1 or -1 */ private int getMaterialCost(ItemStack itemStack) { - if (itemStack.getItem() instanceof ItemTool) { - ItemTool tool = (ItemTool) itemStack.getItem(); - return ToolMaterial.valueOf(tool.getToolMaterialName()).ordinal(); - } else { - return -1; - } + return itemStack.getItem() instanceof ItemTool ? 1 : -1; } /** diff --git a/src/main/java/baritone/utils/accessor/IChunkProviderServer.java b/src/main/java/baritone/utils/accessor/IChunkProviderServer.java index e3e412b58..e527cb508 100644 --- a/src/main/java/baritone/utils/accessor/IChunkProviderServer.java +++ b/src/main/java/baritone/utils/accessor/IChunkProviderServer.java @@ -17,12 +17,10 @@ package baritone.utils.accessor; -import net.minecraft.world.WorldProvider; import net.minecraft.world.chunk.storage.IChunkLoader; /** * @author Brady - * @see WorldProvider * @since 8/4/2018 */ public interface IChunkProviderServer {