diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 52a233052..2f036c08c 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -25,6 +25,6 @@ "depends": { "fabricloader": ">=0.14.22", - "minecraft": ["1.20.5", "1.20.6"] + "minecraft": "1.21" } } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 8103cfdcf..535190f9e 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -35,6 +35,6 @@ A Minecraft pathfinder bot. modId="minecraft" mandatory=true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="[1.20.5, 1.20.6]" +versionRange="[1.21]" ordering="NONE" side="BOTH" diff --git a/gradle.properties b/gradle.properties index e25c8b569..9a7b5417c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,15 +2,15 @@ org.gradle.jvmargs=-Xmx4G available_loaders=fabric,forge,neoforge,tweaker -mod_version=1.10.2 +mod_version=1.11.0 maven_group=baritone archives_base_name=baritone -minecraft_version=1.20.6 +minecraft_version=1.21 -forge_version=50.0.8 +forge_version=51.0.16 -neoforge_version=43-beta +neoforge_version=20-beta fabric_version=0.15.11 diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 6b97406fd..818999bf5 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -128,4 +128,4 @@ publishing { repositories { // Add repositories to publish to here. } -} \ No newline at end of file +} diff --git a/neoforge/src/main/java/baritone/launch/BaritoneForgeModXD.java b/neoforge/src/main/java/baritone/launch/BaritoneForgeModXD.java index de097320d..1d6b87996 100644 --- a/neoforge/src/main/java/baritone/launch/BaritoneForgeModXD.java +++ b/neoforge/src/main/java/baritone/launch/BaritoneForgeModXD.java @@ -17,8 +17,9 @@ package baritone.launch; +import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.common.Mod; -@Mod("baritoe") +@Mod(value = "baritoe", dist = Dist.CLIENT) public class BaritoneForgeModXD { } diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 307e5ca1a..fa1b75122 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -35,6 +35,6 @@ A Minecraft pathfinder bot. modId="minecraft" type="required" # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="[1.20.5, 1.20.6]" +versionRange="[1.21]" ordering="NONE" side="BOTH" diff --git a/src/api/java/baritone/api/command/datatypes/BlockById.java b/src/api/java/baritone/api/command/datatypes/BlockById.java index f92c968a2..67c04ebb0 100644 --- a/src/api/java/baritone/api/command/datatypes/BlockById.java +++ b/src/api/java/baritone/api/command/datatypes/BlockById.java @@ -36,7 +36,7 @@ public enum BlockById implements IDatatypeFor { @Override public Block get(IDatatypeContext ctx) throws CommandException { - ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString()); + ResourceLocation id = ResourceLocation.parse(ctx.getConsumer().getString()); Block block; if ((block = BuiltInRegistries.BLOCK.getOptional(id).orElse(null)) == null) { throw new IllegalArgumentException("no block found by that id"); diff --git a/src/api/java/baritone/api/command/datatypes/EntityClassById.java b/src/api/java/baritone/api/command/datatypes/EntityClassById.java index d7cb75734..322586d00 100644 --- a/src/api/java/baritone/api/command/datatypes/EntityClassById.java +++ b/src/api/java/baritone/api/command/datatypes/EntityClassById.java @@ -30,7 +30,7 @@ public enum EntityClassById implements IDatatypeFor { @Override public EntityType get(IDatatypeContext ctx) throws CommandException { - ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString()); + ResourceLocation id = ResourceLocation.parse(ctx.getConsumer().getString()); EntityType entity; if ((entity = BuiltInRegistries.ENTITY_TYPE.getOptional(id).orElse(null)) == null) { throw new IllegalArgumentException("no entity found by that id"); diff --git a/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java b/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java index 5b949cd63..db57271fb 100644 --- a/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java +++ b/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java @@ -77,7 +77,7 @@ public Stream tabComplete(IDatatypeContext ctx) throws CommandException properties = parts[1]; } - Block block = BuiltInRegistries.BLOCK.getOptional(new ResourceLocation(blockId)).orElse(null); + Block block = BuiltInRegistries.BLOCK.getOptional(ResourceLocation.parse(blockId)).orElse(null); if (block == null) { // This block doesn't exist so there's no properties to complete. return Stream.empty(); diff --git a/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java index 4f822352a..e11c7dd82 100644 --- a/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java +++ b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java @@ -212,7 +212,7 @@ public TabCompleteHelper filterPrefix(String prefix) { * @return This {@link TabCompleteHelper} */ public TabCompleteHelper filterPrefixNamespaced(String prefix) { - return filterPrefix(new ResourceLocation(prefix).toString()); + return filterPrefix(ResourceLocation.parse(prefix).toString()); } /** diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 53283cd33..444af26c3 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -251,7 +251,7 @@ private enum Parser implements ISettingParser { ), ITEM( Item.class, - str -> BuiltInRegistries.ITEM.get(new ResourceLocation(str.trim())), // TODO this now returns AIR on failure instead of null, is that an issue? + str -> BuiltInRegistries.ITEM.get(ResourceLocation.parse(str.trim())), // TODO this now returns AIR on failure instead of null, is that an issue? item -> BuiltInRegistries.ITEM.getKey(item).toString() ), LIST() { diff --git a/src/api/java/baritone/api/utils/gui/BaritoneToast.java b/src/api/java/baritone/api/utils/gui/BaritoneToast.java index 6cdc57cc0..e8a24bc6e 100644 --- a/src/api/java/baritone/api/utils/gui/BaritoneToast.java +++ b/src/api/java/baritone/api/utils/gui/BaritoneToast.java @@ -47,7 +47,7 @@ public Visibility render(GuiGraphics gui, ToastComponent toastGui, long delta) { //TODO: check - gui.blit(new ResourceLocation("textures/gui/toasts.png"), 0, 0, 0, 32, 160, 32); + gui.blit(ResourceLocation.parse("textures/gui/toasts.png"), 0, 0, 0, 32, 160, 32); if (this.subtitle == null) { gui.drawString(toastGui.getMinecraft().font, this.title, 18, 12, -11534256); diff --git a/src/launch/java/baritone/launch/mixins/MixinScreen.java b/src/launch/java/baritone/launch/mixins/MixinScreen.java index c99c7776c..e87fef061 100644 --- a/src/launch/java/baritone/launch/mixins/MixinScreen.java +++ b/src/launch/java/baritone/launch/mixins/MixinScreen.java @@ -35,11 +35,6 @@ @Mixin(Screen.class) public abstract class MixinScreen implements IGuiScreen { - @Override - @Invoker("openLink") - public abstract void openLinkInvoker(URI url); - - //TODO: switch to enum extention with mixin 9.0 or whenever Mumfrey gets around to it @Inject(at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;)V", remap = false, ordinal = 1), method = "handleComponentClicked", cancellable = true) public void handleCustomClickEvent(Style style, CallbackInfoReturnable cir) { diff --git a/src/launch/java/baritone/launch/mixins/MixinWorldRenderer.java b/src/launch/java/baritone/launch/mixins/MixinWorldRenderer.java index 1a1ae74e2..fd4dd1b96 100644 --- a/src/launch/java/baritone/launch/mixins/MixinWorldRenderer.java +++ b/src/launch/java/baritone/launch/mixins/MixinWorldRenderer.java @@ -22,6 +22,7 @@ import baritone.api.event.events.RenderEvent; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.LightTexture; @@ -41,14 +42,13 @@ public class MixinWorldRenderer { @Inject( method = "renderLevel", - at = @At("RETURN"), - locals = LocalCapture.CAPTURE_FAILSOFT + at = @At("RETURN") ) - private void onStartHand(float f, long l, boolean bl, Camera arg, GameRenderer arg2, LightTexture arg3, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { + private void onStartHand(final DeltaTracker deltaTracker, final boolean bl, final Camera camera, final GameRenderer gameRenderer, final LightTexture lightTexture, final Matrix4f matrix4f, final Matrix4f matrix4f2, final CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { PoseStack poseStack = new PoseStack(); poseStack.mulPose(matrix4f); - ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(f, poseStack, matrix4f2)); + ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(deltaTracker.getGameTimeDeltaPartialTick(false), poseStack, matrix4f2)); } } -} \ No newline at end of file +} diff --git a/src/main/java/baritone/command/ExampleBaritoneControl.java b/src/main/java/baritone/command/ExampleBaritoneControl.java index 943b8afa6..173610185 100644 --- a/src/main/java/baritone/command/ExampleBaritoneControl.java +++ b/src/main/java/baritone/command/ExampleBaritoneControl.java @@ -35,6 +35,7 @@ import baritone.command.manager.CommandManager; import baritone.utils.accessor.IGuiScreen; import net.minecraft.ChatFormatting; +import net.minecraft.Util; import net.minecraft.network.chat.*; import net.minecraft.network.chat.MutableComponent; import net.minecraft.util.Tuple; @@ -97,8 +98,8 @@ public boolean runCommand(String msg) { return false; } else if (msg.trim().equalsIgnoreCase("orderpizza")) { try { - ((IGuiScreen) ctx.minecraft().screen).openLinkInvoker(new URI("https://www.dominos.com/en/pages/order/")); - } catch (NullPointerException | URISyntaxException ignored) {} + Util.getPlatform().openUri("https://www.dominos.com/en/pages/order/"); + } catch (Exception ignored) {} return false; } if (msg.isEmpty()) { diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index a374e92e8..233f118f2 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -42,6 +42,7 @@ import baritone.utils.BlockStateInterface; import baritone.utils.IRenderer; import baritone.utils.schematic.StaticSchematic; +import com.mojang.blaze3d.vertex.BufferBuilder; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Vec3i; @@ -75,9 +76,9 @@ public void onRenderPass(RenderEvent event) { float opacity = Baritone.settings().selectionOpacity.value; float lineWidth = Baritone.settings().selectionLineWidth.value; boolean ignoreDepth = Baritone.settings().renderSelectionIgnoreDepth.value; - IRenderer.startLines(color, opacity, lineWidth, ignoreDepth); - IRenderer.emitAABB(event.getModelViewStack(), new AABB(pos1)); - IRenderer.endLines(ignoreDepth); + BufferBuilder bufferBuilder = IRenderer.startLines(color, opacity, lineWidth, ignoreDepth); + IRenderer.emitAABB(bufferBuilder, event.getModelViewStack(), new AABB(pos1)); + IRenderer.endLines(bufferBuilder, ignoreDepth); } }); } diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 64aca2ceb..0d6ec1640 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -27,11 +27,14 @@ import baritone.utils.pathing.BetterWorldBorder; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.item.enchantment.*; +import net.minecraft.world.item.enchantment.effects.EnchantmentAttributeEffect; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; @@ -108,19 +111,44 @@ public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) { this.allowParkourAscend = Baritone.settings().allowParkourAscend.value; this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.value; this.allowFallIntoLava = false; // Super secret internal setting for ElytraBehavior - this.frostWalker = EnchantmentHelper.getEnchantmentLevel(Enchantments.FROST_WALKER, baritone.getPlayerContext().player()); + // todo: technically there can now be datapack enchants that replace blocks with any other at any range + int frostWalkerLevel = 0; + for (EquipmentSlot slot : EquipmentSlot.values()) { + ItemEnchantments itemEnchantments = baritone.getPlayerContext() + .player() + .getItemBySlot(slot) + .getEnchantments(); + for (Holder enchant : itemEnchantments.keySet()) { + if (enchant.is(Enchantments.FROST_WALKER)) { + frostWalkerLevel = itemEnchantments.getLevel(enchant); + } + } + } + this.frostWalker = frostWalkerLevel; this.allowDiagonalDescend = Baritone.settings().allowDiagonalDescend.value; this.allowDiagonalAscend = Baritone.settings().allowDiagonalAscend.value; this.allowDownward = Baritone.settings().allowDownward.value; this.minFallHeight = 3; // Minimum fall height used by MovementFall this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.value; this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.value; - int depth = EnchantmentHelper.getDepthStrider(player); - if (depth > 3) { - depth = 3; + float waterSpeedMultiplier = 1.0f; + OUTER: for (EquipmentSlot slot : EquipmentSlot.values()) { + ItemEnchantments itemEnchantments = baritone.getPlayerContext() + .player() + .getItemBySlot(slot) + .getEnchantments(); + for (Holder enchant : itemEnchantments.keySet()) { + List effects = enchant.value() + .getEffects(EnchantmentEffectComponents.ATTRIBUTES); + for (EnchantmentAttributeEffect effect : effects) { + if (effect.attribute().is(Attributes.WATER_MOVEMENT_EFFICIENCY.unwrapKey().get())) { + waterSpeedMultiplier = effect.amount().calculate(itemEnchantments.getLevel(enchant)); + break OUTER; + } + } + } } - float mult = depth / 3.0F; - this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - mult) + ActionCosts.WALK_ONE_BLOCK_COST * mult; + this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - waterSpeedMultiplier) + ActionCosts.WALK_ONE_BLOCK_COST * waterSpeedMultiplier; this.breakBlockAdditionalCost = Baritone.settings().blockBreakAdditionalPenalty.value; this.backtrackCostFavoringCoefficient = Baritone.settings().backtrackCostFavoringCoefficient.value; this.jumpPenalty = Baritone.settings().jumpPenalty.value; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 16119bb07..66d497d9e 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -31,7 +31,11 @@ import baritone.utils.ToolSet; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.core.Holder; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.item.enchantment.ItemEnchantments; import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.piston.MovingPistonBlock; import net.minecraft.world.level.block.state.BlockState; @@ -500,14 +504,27 @@ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z) { static boolean canUseFrostWalker(CalculationContext context, BlockState state) { return context.frostWalker != 0 && state == FrostedIceBlock.meltsInto() - && ((Integer) state.getValue(LiquidBlock.LEVEL)) == 0; + && state.getValue(LiquidBlock.LEVEL) == 0; } static boolean canUseFrostWalker(IPlayerContext ctx, BlockPos pos) { + boolean hasFrostWalker = false; + OUTER: for (EquipmentSlot slot : EquipmentSlot.values()) { + ItemEnchantments itemEnchantments = ctx + .player() + .getItemBySlot(slot) + .getEnchantments(); + for (Holder enchant : itemEnchantments.keySet()) { + if (enchant.is(Enchantments.FROST_WALKER)) { + hasFrostWalker = true; + break OUTER; + } + } + } BlockState state = BlockStateInterface.get(ctx, pos); - return EnchantmentHelper.hasFrostWalker(ctx.player()) + return hasFrostWalker && state == FrostedIceBlock.meltsInto() - && ((Integer) state.getValue(LiquidBlock.LEVEL)) == 0; + && state.getValue(LiquidBlock.LEVEL) == 0; } /** diff --git a/src/main/java/baritone/process/elytra/ElytraBehavior.java b/src/main/java/baritone/process/elytra/ElytraBehavior.java index 8ace420e9..5d2dba7b2 100644 --- a/src/main/java/baritone/process/elytra/ElytraBehavior.java +++ b/src/main/java/baritone/process/elytra/ElytraBehavior.java @@ -31,6 +31,7 @@ import baritone.utils.IRenderer; import baritone.utils.PathRenderer; import baritone.utils.accessor.IFireworkRocketEntity; +import com.mojang.blaze3d.vertex.BufferBuilder; import it.unimi.dsi.fastutil.floats.FloatArrayList; import it.unimi.dsi.fastutil.floats.FloatIterator; import net.minecraft.core.BlockPos; @@ -424,28 +425,28 @@ public void onRenderPass(RenderEvent event) { PathRenderer.drawGoal(event.getModelViewStack(), ctx, new GoalBlock(this.aimPos), event.getPartialTicks(), Color.GREEN); } if (!this.clearLines.isEmpty() && settings.elytraRenderRaytraces.value) { - IRenderer.startLines(Color.GREEN, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value); + BufferBuilder bufferBuilder = IRenderer.startLines(Color.GREEN, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value); for (Pair line : this.clearLines) { - IRenderer.emitLine(event.getModelViewStack(), line.first(), line.second()); + IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), line.first(), line.second()); } - IRenderer.endLines(settings.renderPathIgnoreDepth.value); + IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value); } if (!this.blockedLines.isEmpty() && Baritone.settings().elytraRenderRaytraces.value) { - IRenderer.startLines(Color.BLUE, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value); + BufferBuilder bufferBuilder = IRenderer.startLines(Color.BLUE, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value); for (Pair line : this.blockedLines) { - IRenderer.emitLine(event.getModelViewStack(), line.first(), line.second()); + IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), line.first(), line.second()); } - IRenderer.endLines(settings.renderPathIgnoreDepth.value); + IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value); } if (this.simulationLine != null && Baritone.settings().elytraRenderSimulation.value) { - IRenderer.startLines(new Color(0x36CCDC), settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value); + BufferBuilder bufferBuilder = IRenderer.startLines(new Color(0x36CCDC), settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value); final Vec3 offset = ctx.player().getPosition(event.getPartialTicks()); for (int i = 0; i < this.simulationLine.size() - 1; i++) { final Vec3 src = this.simulationLine.get(i).add(offset); final Vec3 dst = this.simulationLine.get(i + 1).add(offset); - IRenderer.emitLine(event.getModelViewStack(), src, dst); + IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), src, dst); } - IRenderer.endLines(settings.renderPathIgnoreDepth.value); + IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value); } } diff --git a/src/main/java/baritone/selection/SelectionRenderer.java b/src/main/java/baritone/selection/SelectionRenderer.java index 4250f4085..a5a8a4462 100644 --- a/src/main/java/baritone/selection/SelectionRenderer.java +++ b/src/main/java/baritone/selection/SelectionRenderer.java @@ -5,6 +5,7 @@ import baritone.api.event.listener.AbstractGameEventListener; import baritone.api.selection.ISelection; import baritone.utils.IRenderer; +import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.world.phys.AABB; @@ -28,27 +29,27 @@ public static void renderSelections(PoseStack stack, ISelection[] selections) { return; } - IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth, ignoreDepth); + BufferBuilder bufferBuilder = IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth, ignoreDepth); for (ISelection selection : selections) { - IRenderer.emitAABB(stack, selection.aabb(), SELECTION_BOX_EXPANSION); + IRenderer.emitAABB(bufferBuilder, stack, selection.aabb(), SELECTION_BOX_EXPANSION); } if (settings.renderSelectionCorners.value) { IRenderer.glColor(settings.colorSelectionPos1.value, opacity); for (ISelection selection : selections) { - IRenderer.emitAABB(stack, new AABB(selection.pos1())); + IRenderer.emitAABB(bufferBuilder, stack, new AABB(selection.pos1())); } IRenderer.glColor(settings.colorSelectionPos2.value, opacity); for (ISelection selection : selections) { - IRenderer.emitAABB(stack, new AABB(selection.pos2())); + IRenderer.emitAABB(bufferBuilder, stack, new AABB(selection.pos2())); } } - IRenderer.endLines(ignoreDepth); + IRenderer.endLines(bufferBuilder, ignoreDepth); } @Override diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java index 113450d1c..37259278b 100644 --- a/src/main/java/baritone/utils/GuiClick.java +++ b/src/main/java/baritone/utils/GuiClick.java @@ -22,6 +22,7 @@ import baritone.api.pathing.goals.GoalBlock; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.Helper; +import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.GuiGraphics; @@ -128,11 +129,11 @@ public void onRender(PoseStack modelViewStack, Matrix4f projectionMatrix) { // drawSingleSelectionBox WHEN? PathRenderer.drawManySelectionBoxes(modelViewStack, e, Collections.singletonList(currentMouseOver), Color.CYAN); if (clickStart != null && !clickStart.equals(currentMouseOver)) { - IRenderer.startLines(Color.RED, Baritone.settings().pathRenderLineWidthPixels.value, true); + BufferBuilder bufferBuilder = IRenderer.startLines(Color.RED, Baritone.settings().pathRenderLineWidthPixels.value, true); BetterBlockPos a = new BetterBlockPos(currentMouseOver); BetterBlockPos b = new BetterBlockPos(clickStart); - IRenderer.emitAABB(modelViewStack, new AABB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1)); - IRenderer.endLines(true); + IRenderer.emitAABB(bufferBuilder, modelViewStack, new AABB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1)); + IRenderer.endLines(bufferBuilder, true); } } } diff --git a/src/main/java/baritone/utils/IRenderer.java b/src/main/java/baritone/utils/IRenderer.java index 86db4c87f..2989a8377 100644 --- a/src/main/java/baritone/utils/IRenderer.java +++ b/src/main/java/baritone/utils/IRenderer.java @@ -28,15 +28,12 @@ import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -import org.joml.Matrix3f; -import org.joml.Matrix4f; import java.awt.*; public interface IRenderer { Tesselator tessellator = Tesselator.getInstance(); - BufferBuilder buffer = tessellator.getBuilder(); IEntityRenderManager renderManager = (IEntityRenderManager) Minecraft.getInstance().getEntityRenderDispatcher(); TextureManager textureManager = Minecraft.getInstance().getTextureManager(); Settings settings = BaritoneAPI.getSettings(); @@ -51,7 +48,7 @@ static void glColor(Color color, float alpha) { IRenderer.color[3] = alpha; } - static void startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) { + static BufferBuilder startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) { RenderSystem.enableBlend(); RenderSystem.setShader(GameRenderer::getPositionColorShader); RenderSystem.blendFuncSeparate( @@ -69,15 +66,19 @@ static void startLines(Color color, float alpha, float lineWidth, boolean ignore RenderSystem.disableDepthTest(); } RenderSystem.setShader(GameRenderer::getRendertypeLinesShader); - buffer.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL); + return tessellator.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL); } - static void startLines(Color color, float lineWidth, boolean ignoreDepth) { - startLines(color, .4f, lineWidth, ignoreDepth); + static BufferBuilder startLines(Color color, float lineWidth, boolean ignoreDepth) { + return startLines(color, .4f, lineWidth, ignoreDepth); } - static void endLines(boolean ignoredDepth) { - tessellator.end(); + static void endLines(BufferBuilder bufferBuilder, boolean ignoredDepth) { + MeshData meshData = bufferBuilder.build(); + if (meshData != null) { + BufferUploader.drawWithShader(meshData); + } + if (ignoredDepth) { RenderSystem.enableDepthTest(); } @@ -87,7 +88,7 @@ static void endLines(boolean ignoredDepth) { RenderSystem.disableBlend(); } - static void emitLine(PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) { + static void emitLine(BufferBuilder bufferBuilder, PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) { final double dx = x2 - x1; final double dy = y2 - y1; final double dz = z2 - z1; @@ -97,59 +98,59 @@ static void emitLine(PoseStack stack, double x1, double y1, double z1, double x2 final float ny = (float) (dy * invMag); final float nz = (float) (dz * invMag); - emitLine(stack, x1, y1, z1, x2, y2, z2, nx, ny, nz); + emitLine(bufferBuilder, stack, x1, y1, z1, x2, y2, z2, nx, ny, nz); } - static void emitLine(PoseStack stack, + static void emitLine(BufferBuilder bufferBuilder, PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2, double nx, double ny, double nz) { - emitLine(stack, + emitLine(bufferBuilder, stack, (float) x1, (float) y1, (float) z1, (float) x2, (float) y2, (float) z2, (float) nx, (float) ny, (float) nz ); } - static void emitLine(PoseStack stack, + static void emitLine(BufferBuilder bufferBuilder, PoseStack stack, float x1, float y1, float z1, float x2, float y2, float z2, float nx, float ny, float nz) { PoseStack.Pose pose = stack.last(); - buffer.vertex(pose, x1, y1, z1).color(color[0], color[1], color[2], color[3]).normal(pose, nx, ny, nz).endVertex(); - buffer.vertex(pose, x2, y2, z2).color(color[0], color[1], color[2], color[3]).normal(pose, nx, ny, nz).endVertex(); + bufferBuilder.addVertex(pose, x1, y1, z1).setColor(color[0], color[1], color[2], color[3]).setNormal(pose, nx, ny, nz); + bufferBuilder.addVertex(pose, x2, y2, z2).setColor(color[0], color[1], color[2], color[3]).setNormal(pose, nx, ny, nz); } - static void emitAABB(PoseStack stack, AABB aabb) { + static void emitAABB(BufferBuilder bufferBuilder, PoseStack stack, AABB aabb) { AABB toDraw = aabb.move(-renderManager.renderPosX(), -renderManager.renderPosY(), -renderManager.renderPosZ()); // bottom - emitLine(stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.minZ, 1.0, 0.0, 0.0); - emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.maxZ, 0.0, 0.0, 1.0); - emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.maxZ, -1.0, 0.0, 0.0); - emitLine(stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.minZ, 0.0, 0.0, -1.0); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.minZ, 1.0, 0.0, 0.0); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.maxZ, 0.0, 0.0, 1.0); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.maxZ, -1.0, 0.0, 0.0); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.minZ, 0.0, 0.0, -1.0); // top - emitLine(stack, toDraw.minX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 1.0, 0.0, 0.0); - emitLine(stack, toDraw.maxX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 0.0, 1.0); - emitLine(stack, toDraw.maxX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, -1.0, 0.0, 0.0); - emitLine(stack, toDraw.minX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 0.0, -1.0); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 1.0, 0.0, 0.0); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 0.0, 1.0); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, -1.0, 0.0, 0.0); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 0.0, -1.0); // corners - emitLine(stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0); - emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0); - emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0); - emitLine(stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0); } - static void emitAABB(PoseStack stack, AABB aabb, double expand) { - emitAABB(stack, aabb.inflate(expand, expand, expand)); + static void emitAABB(BufferBuilder bufferBuilder, PoseStack stack, AABB aabb, double expand) { + emitAABB(bufferBuilder, stack, aabb.inflate(expand, expand, expand)); } - static void emitLine(PoseStack stack, Vec3 start, Vec3 end) { + static void emitLine(BufferBuilder bufferBuilder, PoseStack stack, Vec3 start, Vec3 end) { double vpX = renderManager.renderPosX(); double vpY = renderManager.renderPosY(); double vpZ = renderManager.renderPosZ(); - emitLine(stack, start.x - vpX, start.y - vpY, start.z - vpZ, end.x - vpX, end.y - vpY, end.z - vpZ); + emitLine(bufferBuilder, stack, start.x - vpX, start.y - vpY, start.z - vpZ, end.x - vpX, end.y - vpY, end.z - vpZ); } } diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index d22a0058a..f8a60130b 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -26,6 +26,7 @@ import baritone.behavior.PathingBehavior; import baritone.pathing.path.PathExecutor; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.blockentity.BeaconRenderer; import net.minecraft.core.BlockPos; @@ -37,6 +38,7 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; import java.awt.*; import java.util.Arrays; @@ -50,7 +52,7 @@ */ public final class PathRenderer implements IRenderer { - private static final ResourceLocation TEXTURE_BEACON_BEAM = new ResourceLocation("textures/entity/beacon_beam.png"); + private static final ResourceLocation TEXTURE_BEACON_BEAM = ResourceLocation.parse("textures/entity/beacon_beam.png"); private PathRenderer() {} @@ -133,7 +135,7 @@ public static void drawPath(PoseStack stack, List positions, int } public static void drawPath(PoseStack stack, List positions, int startIndex, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0, double offset) { - IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value); + BufferBuilder bufferBuilder = IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value); int fadeStart = fadeStart0 + startIndex; int fadeEnd = fadeEnd0 + startIndex; @@ -167,13 +169,13 @@ public static void drawPath(PoseStack stack, List positions, int IRenderer.glColor(color, alpha); } - emitPathLine(stack, start.x, start.y, start.z, end.x, end.y, end.z, offset); + emitPathLine(bufferBuilder, stack, start.x, start.y, start.z, end.x, end.y, end.z, offset); } - IRenderer.endLines(settings.renderPathIgnoreDepth.value); + IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value); } - private static void emitPathLine(PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2, double offset) { + private static void emitPathLine(BufferBuilder bufferBuilder, PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2, double offset) { final double extraOffset = offset + 0.03D; double vpX = posX(); @@ -181,20 +183,20 @@ private static void emitPathLine(PoseStack stack, double x1, double y1, double z double vpZ = posZ(); boolean renderPathAsFrickinThingy = !settings.renderPathAsLine.value; - IRenderer.emitLine(stack, + IRenderer.emitLine(bufferBuilder, stack, x1 + offset - vpX, y1 + offset - vpY, z1 + offset - vpZ, x2 + offset - vpX, y2 + offset - vpY, z2 + offset - vpZ ); if (renderPathAsFrickinThingy) { - IRenderer.emitLine(stack, + IRenderer.emitLine(bufferBuilder, stack, x2 + offset - vpX, y2 + offset - vpY, z2 + offset - vpZ, x2 + offset - vpX, y2 + extraOffset - vpY, z2 + offset - vpZ ); - IRenderer.emitLine(stack, + IRenderer.emitLine(bufferBuilder, stack, x2 + offset - vpX, y2 + extraOffset - vpY, z2 + offset - vpZ, x1 + offset - vpX, y1 + extraOffset - vpY, z1 + offset - vpZ ); - IRenderer.emitLine(stack, + IRenderer.emitLine(bufferBuilder, stack, x1 + offset - vpX, y1 + extraOffset - vpY, z1 + offset - vpZ, x1 + offset - vpX, y1 + offset - vpY, z1 + offset - vpZ ); @@ -202,7 +204,7 @@ private static void emitPathLine(PoseStack stack, double x1, double y1, double z } public static void drawManySelectionBoxes(PoseStack stack, Entity player, Collection positions, Color color) { - IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value, settings.renderSelectionBoxesIgnoreDepth.value); + BufferBuilder bufferBuilder = IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value, settings.renderSelectionBoxesIgnoreDepth.value); //BlockPos blockpos = movingObjectPositionIn.getBlockPos(); BlockStateInterface bsi = new BlockStateInterface(BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext()); // TODO this assumes same dimension between primary baritone and render view? is this safe? @@ -212,17 +214,20 @@ public static void drawManySelectionBoxes(PoseStack stack, Entity player, Collec VoxelShape shape = state.getShape(player.level(), pos); AABB toDraw = shape.isEmpty() ? Shapes.block().bounds() : shape.bounds(); toDraw = toDraw.move(pos); - IRenderer.emitAABB(stack, toDraw, .002D); + IRenderer.emitAABB(bufferBuilder, stack, toDraw, .002D); }); - IRenderer.endLines(settings.renderSelectionBoxesIgnoreDepth.value); + IRenderer.endLines(bufferBuilder, settings.renderSelectionBoxesIgnoreDepth.value); } public static void drawGoal(PoseStack stack, IPlayerContext ctx, Goal goal, float partialTicks, Color color) { - drawGoal(stack, ctx, goal, partialTicks, color, true); + drawGoal(null, stack, ctx, goal, partialTicks, color, true); } - private static void drawGoal(PoseStack stack, IPlayerContext ctx, Goal goal, float partialTicks, Color color, boolean setupRender) { + private static void drawGoal(@Nullable BufferBuilder bufferBuilder, PoseStack stack, IPlayerContext ctx, Goal goal, float partialTicks, Color color, boolean setupRender) { + if (!setupRender && bufferBuilder == null) { + throw new RuntimeException("BufferBuilder must not be null if setupRender is false"); + } double renderPosX = posX(); double renderPosY = posY(); double renderPosZ = posZ(); @@ -254,7 +259,7 @@ private static void drawGoal(PoseStack stack, IPlayerContext ctx, Goal goal, flo y2 -= 0.5; maxY--; } - drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); + drawDankLitGoalBox(bufferBuilder, stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); } else if (goal instanceof GoalXZ) { GoalXZ goalPos = (GoalXZ) goal; minY = ctx.world().getMinBuildHeight(); @@ -280,7 +285,7 @@ private static void drawGoal(PoseStack stack, IPlayerContext ctx, Goal goal, flo settings.renderGoalAnimated.value ? ctx.world().getGameTime() : 0, (int) minY, (int) maxY, - color.getColorComponents(null), + color.getRGB(), // Arguments filled by the private method lol 0.2F, @@ -304,19 +309,19 @@ private static void drawGoal(PoseStack stack, IPlayerContext ctx, Goal goal, flo y2 = 0; minY -= renderPosY; maxY -= renderPosY; - drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); + drawDankLitGoalBox(bufferBuilder, stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); } else if (goal instanceof GoalComposite) { // Simple way to determine if goals can be batched, without having some sort of GoalRenderer boolean batch = Arrays.stream(((GoalComposite) goal).goals()).allMatch(IGoalRenderPos.class::isInstance); - + BufferBuilder buf = bufferBuilder; if (batch) { - IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); + buf = IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); } for (Goal g : ((GoalComposite) goal).goals()) { - drawGoal(stack, ctx, g, partialTicks, color, !batch); + drawGoal(buf, stack, ctx, g, partialTicks, color, !batch); } if (batch) { - IRenderer.endLines(settings.renderGoalIgnoreDepth.value); + IRenderer.endLines(buf, settings.renderGoalIgnoreDepth.value); } } else if (goal instanceof GoalInverted) { drawGoal(stack, ctx, ((GoalInverted) goal).origin, partialTicks, settings.colorInvertedGoalBox.value); @@ -330,37 +335,37 @@ private static void drawGoal(PoseStack stack, IPlayerContext ctx, Goal goal, flo maxY = minY + 2; y1 = 1 + y + goalpos.level - renderPosY; y2 = 1 - y + goalpos.level - renderPosY; - drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); + drawDankLitGoalBox(bufferBuilder, stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); } } - private static void drawDankLitGoalBox(PoseStack stack, Color colorIn, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) { + private static void drawDankLitGoalBox(BufferBuilder bufferBuilder, PoseStack stack, Color colorIn, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) { if (setupRender) { - IRenderer.startLines(colorIn, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); + bufferBuilder = IRenderer.startLines(colorIn, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); } - renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y1); - renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y2); + renderHorizontalQuad(bufferBuilder, stack, minX, maxX, minZ, maxZ, y1); + renderHorizontalQuad(bufferBuilder, stack, minX, maxX, minZ, maxZ, y2); for (double y = minY; y < maxY; y += 16) { double max = Math.min(maxY, y + 16); - IRenderer.emitLine(stack, minX, y, minZ, minX, max, minZ, 0.0, 1.0, 0.0); - IRenderer.emitLine(stack, maxX, y, minZ, maxX, max, minZ, 0.0, 1.0, 0.0); - IRenderer.emitLine(stack, maxX, y, maxZ, maxX, max, maxZ, 0.0, 1.0, 0.0); - IRenderer.emitLine(stack, minX, y, maxZ, minX, max, maxZ, 0.0, 1.0, 0.0); + IRenderer.emitLine(bufferBuilder, stack, minX, y, minZ, minX, max, minZ, 0.0, 1.0, 0.0); + IRenderer.emitLine(bufferBuilder, stack, maxX, y, minZ, maxX, max, minZ, 0.0, 1.0, 0.0); + IRenderer.emitLine(bufferBuilder, stack, maxX, y, maxZ, maxX, max, maxZ, 0.0, 1.0, 0.0); + IRenderer.emitLine(bufferBuilder, stack, minX, y, maxZ, minX, max, maxZ, 0.0, 1.0, 0.0); } if (setupRender) { - IRenderer.endLines(settings.renderGoalIgnoreDepth.value); + IRenderer.endLines(bufferBuilder, settings.renderGoalIgnoreDepth.value); } } - private static void renderHorizontalQuad(PoseStack stack, double minX, double maxX, double minZ, double maxZ, double y) { + private static void renderHorizontalQuad(BufferBuilder bufferBuilder, PoseStack stack, double minX, double maxX, double minZ, double maxZ, double y) { if (y != 0) { - IRenderer.emitLine(stack, minX, y, minZ, maxX, y, minZ, 1.0, 0.0, 0.0); - IRenderer.emitLine(stack, maxX, y, minZ, maxX, y, maxZ, 0.0, 0.0, 1.0); - IRenderer.emitLine(stack, maxX, y, maxZ, minX, y, maxZ, -1.0, 0.0, 0.0); - IRenderer.emitLine(stack, minX, y, maxZ, minX, y, minZ, 0.0, 0.0, -1.0); + IRenderer.emitLine(bufferBuilder, stack, minX, y, minZ, maxX, y, minZ, 1.0, 0.0, 0.0); + IRenderer.emitLine(bufferBuilder, stack, maxX, y, minZ, maxX, y, maxZ, 0.0, 0.0, 1.0); + IRenderer.emitLine(bufferBuilder, stack, maxX, y, maxZ, minX, y, maxZ, -1.0, 0.0, 0.0); + IRenderer.emitLine(bufferBuilder, stack, minX, y, maxZ, minX, y, minZ, 0.0, 0.0, -1.0); } } } diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index ef83a2db1..4579a5b45 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -19,16 +19,19 @@ import baritone.Baritone; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.Holder; import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.SwordItem; import net.minecraft.world.item.TieredItem; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.item.enchantment.*; +import net.minecraft.world.item.enchantment.effects.EnchantmentAttributeEffect; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Function; @@ -93,7 +96,15 @@ private int getMaterialCost(ItemStack itemStack) { } public boolean hasSilkTouch(ItemStack stack) { - return EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0; + ItemEnchantments enchantments = stack.getEnchantments(); + for (Holder enchant : enchantments.keySet()) { + // silk touch enchantment is still special cased as affecting block drops + // not possible to add custom attribute via datapack + if (enchant.is(Enchantments.SILK_TOUCH) && enchantments.getLevel(enchant) > 0) { + return true; + } + } + return false; } /** @@ -184,9 +195,15 @@ public static double calculateSpeedVsBlock(ItemStack item, BlockState state) { float speed = item.getDestroySpeed(state); if (speed > 1) { - int effLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.EFFICIENCY, item); - if (effLevel > 0 && !item.isEmpty()) { - speed += effLevel * effLevel + 1; + final ItemEnchantments itemEnchantments = item.getEnchantments(); + OUTER: for (Holder enchant : itemEnchantments.keySet()) { + List effects = enchant.value().getEffects(EnchantmentEffectComponents.ATTRIBUTES); + for (EnchantmentAttributeEffect e : effects) { + if (e.attribute().is(Attributes.MINING_EFFICIENCY.unwrapKey().get())) { + speed += e.amount().calculate(itemEnchantments.getLevel(enchant)); + break OUTER; + } + } } } diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 94a01a157..d30867ab8 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -81,7 +81,9 @@ public IStaticSchematic parse(InputStream input) throws IOException { case 4: //1.12 case 5: //1.13-1.17 throw new UnsupportedOperationException("This litematic Version is too old."); - case 6: //1.18+ + case 6: //1.18-1.20 + throw new UnsupportedOperationException("This litematic Version is too old."); + case 7: //1.21+ return new LitematicaSchematic(nbt, false); default: throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 65cdec058..92e8a39df 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -94,7 +94,7 @@ private static BlockState[] getBlockList(ListTag blockStatePalette) { BlockState[] blockList = new BlockState[blockStatePalette.size()]; for (int i = 0; i < blockStatePalette.size(); i++) { - Block block = BuiltInRegistries.BLOCK.get(new ResourceLocation((((CompoundTag) blockStatePalette.get(i)).getString("Name")))); + Block block = BuiltInRegistries.BLOCK.get(ResourceLocation.parse((((CompoundTag) blockStatePalette.get(i)).getString("Name")))); CompoundTag properties = ((CompoundTag) blockStatePalette.get(i)).getCompound("Properties"); blockList[i] = getBlockState(block, properties); @@ -345,4 +345,4 @@ public long size() { return this.arraySize; } } -} \ No newline at end of file +} diff --git a/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java index 12163cbff..9e6178c0d 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java @@ -130,7 +130,7 @@ private static SerializedBlockState getFromString(String s) { String location = m.group("location"); String properties = m.group("properties"); - ResourceLocation resourceLocation = new ResourceLocation(location); + ResourceLocation resourceLocation = ResourceLocation.parse(location); Map propertiesMap = new HashMap<>(); if (properties != null) { for (String property : properties.split(",")) {