diff --git a/build.gradle b/build.gradle index 3cfba863b..4fcfd1636 100755 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,9 @@ allprojects { } repositories { + maven { + url = "https://files.minecraftforge.net/maven/" + } maven { name = 'spongepowered-repo' url = 'https://repo.spongepowered.org/repository/maven-public/' diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 05fce6ad6..63c52e11b 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -25,7 +25,7 @@ ], "depends": { "fabricloader": ">=0.14.22", - "minecraft": ["1.21.9", "1.21.10"] + "minecraft": ["1.21.11"] }, "custom": { "modmenu": { diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 48e073837..1792bd3dc 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.21.9, 1.21.10]" +versionRange="[1.21.11]" ordering="NONE" side="BOTH" diff --git a/gradle.properties b/gradle.properties index f6b9f1cfc..437263942 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,24 +1,24 @@ org.gradle.jvmargs=-Xmx4G -available_loaders=fabric,neoforge,forge,tweaker +available_loaders=fabric,forge,tweaker -mod_version=1.16.0 +mod_version=1.17.0 maven_group=baritone archives_base_name=baritone java_version=21 -minecraft_version=1.21.10 +minecraft_version=1.21.11 -forge_version=60.0.0 +forge_version=61.0.0 -neoforge_version=1-beta +neoforge_version=0-beta -fabric_version=0.17.2 +fabric_version=0.18.1 nether_pathfinder_version=1.4.1 // These dependencies are used for common and tweaker // while mod loaders usually ship their own version -mixin_version=0.8.5 +mixin_version=0.8.7 asm_version=9.7 diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 48674943d..ddb9dee52 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -35,7 +35,7 @@ A Minecraft pathfinder bot. modId="minecraft" type="required" # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="[1.21.9, 1.21.10]" +versionRange="[1.21.11]" 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 c0f05eed4..22b8699e7 100644 --- a/src/api/java/baritone/api/command/datatypes/BlockById.java +++ b/src/api/java/baritone/api/command/datatypes/BlockById.java @@ -20,7 +20,7 @@ import baritone.api.command.exception.CommandException; import baritone.api.command.helpers.TabCompleteHelper; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.level.block.Block; import java.util.stream.Stream; @@ -30,7 +30,7 @@ public enum BlockById implements IDatatypeFor { @Override public Block get(IDatatypeContext ctx) throws CommandException { - ResourceLocation id = ResourceLocation.parse(ctx.getConsumer().getString()); + Identifier id = Identifier.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 322586d00..7ef092138 100644 --- a/src/api/java/baritone/api/command/datatypes/EntityClassById.java +++ b/src/api/java/baritone/api/command/datatypes/EntityClassById.java @@ -20,7 +20,7 @@ import baritone.api.command.exception.CommandException; import baritone.api.command.helpers.TabCompleteHelper; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.entity.EntityType; import java.util.stream.Stream; @@ -30,7 +30,7 @@ public enum EntityClassById implements IDatatypeFor { @Override public EntityType get(IDatatypeContext ctx) throws CommandException { - ResourceLocation id = ResourceLocation.parse(ctx.getConsumer().getString()); + Identifier id = Identifier.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 db57271fb..6b5cc5d35 100644 --- a/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java +++ b/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java @@ -21,7 +21,7 @@ import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.utils.BlockOptionalMeta; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.properties.Property; @@ -77,7 +77,7 @@ public Stream tabComplete(IDatatypeContext ctx) throws CommandException properties = parts[1]; } - Block block = BuiltInRegistries.BLOCK.getOptional(ResourceLocation.parse(blockId)).orElse(null); + Block block = BuiltInRegistries.BLOCK.getOptional(Identifier.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/datatypes/ItemById.java b/src/api/java/baritone/api/command/datatypes/ItemById.java index 2c238f495..791f06c93 100644 --- a/src/api/java/baritone/api/command/datatypes/ItemById.java +++ b/src/api/java/baritone/api/command/datatypes/ItemById.java @@ -20,7 +20,7 @@ import baritone.api.command.exception.CommandException; import baritone.api.command.helpers.TabCompleteHelper; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.item.Item; import java.util.stream.Stream; @@ -30,7 +30,7 @@ public enum ItemById implements IDatatypeFor { @Override public Item get(IDatatypeContext ctx) throws CommandException { - ResourceLocation id = ResourceLocation.parse(ctx.getConsumer().getString()); + Identifier id = Identifier.parse(ctx.getConsumer().getString()); Item item; if ((item = BuiltInRegistries.ITEM.getOptional(id).orElse(null)) == null) { throw new IllegalArgumentException("No item found by that id"); @@ -44,7 +44,7 @@ public Stream tabComplete(IDatatypeContext ctx) throws CommandException .append( BuiltInRegistries.BLOCK.keySet() .stream() - .map(ResourceLocation::toString) + .map(Identifier::toString) ) .filterPrefixNamespaced(ctx.getConsumer().getString()) .sortAlphabetically() diff --git a/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java index 88f603205..fcd7d67f9 100644 --- a/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java +++ b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java @@ -23,13 +23,14 @@ import baritone.api.command.manager.ICommandManager; import baritone.api.event.events.TabCompleteEvent; import baritone.api.utils.SettingsUtil; +import net.minecraft.resources.Identifier; + import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Stream; -import net.minecraft.resources.ResourceLocation; /** * The {@link TabCompleteHelper} is a single-use object that helps you handle tab completion. It includes helper @@ -206,13 +207,13 @@ public TabCompleteHelper filterPrefix(String prefix) { /** * Filter out any element that doesn't start with {@code prefix} and return this object for chaining *

- * Assumes every element in this {@link TabCompleteHelper} is a {@link ResourceLocation} + * Assumes every element in this {@link TabCompleteHelper} is a {@link Identifier} * * @param prefix The prefix to filter for * @return This {@link TabCompleteHelper} */ public TabCompleteHelper filterPrefixNamespaced(String prefix) { - ResourceLocation loc = ResourceLocation.tryParse(prefix); + Identifier loc = Identifier.tryParse(prefix); if (loc == null) { stream = Stream.empty(); return this; diff --git a/src/api/java/baritone/api/utils/BlockOptionalMeta.java b/src/api/java/baritone/api/utils/BlockOptionalMeta.java index c73e2e8e2..b57b1a725 100644 --- a/src/api/java/baritone/api/utils/BlockOptionalMeta.java +++ b/src/api/java/baritone/api/utils/BlockOptionalMeta.java @@ -66,6 +66,7 @@ import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; +import java.util.concurrent.ForkJoinPool; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -324,7 +325,7 @@ public static CompletableFuture load() { layeredRegistryAccess, pendingTags, closeableResourceManager, - Minecraft.getInstance() + ForkJoinPool.commonPool() ).thenApply(r -> r.layers().compositeAccess()); } } diff --git a/src/api/java/baritone/api/utils/BlockUtils.java b/src/api/java/baritone/api/utils/BlockUtils.java index a43d78e87..000646f33 100644 --- a/src/api/java/baritone/api/utils/BlockUtils.java +++ b/src/api/java/baritone/api/utils/BlockUtils.java @@ -17,19 +17,19 @@ package baritone.api.utils; -import java.util.HashMap; -import java.util.Map; -import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.level.block.Block; +import java.util.HashMap; +import java.util.Map; + public class BlockUtils { private static transient Map resourceCache = new HashMap<>(); public static String blockToString(Block block) { - ResourceLocation loc = BuiltInRegistries.BLOCK.getKey(block); + Identifier loc = BuiltInRegistries.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? @@ -57,7 +57,7 @@ public static Block stringToBlockNullable(String name) { if (resourceCache.containsKey(name)) { return null; // cached as null } - block = BuiltInRegistries.BLOCK.getOptional(ResourceLocation.tryParse(name.contains(":") ? name : "minecraft:" + name)).orElse(null); + block = BuiltInRegistries.BLOCK.getOptional(Identifier.tryParse(name.contains(":") ? name : "minecraft:" + name)).orElse(null); Map copy = new HashMap<>(resourceCache); // read only copy is safe, wont throw concurrentmodification copy.put(name, block); resourceCache = copy; diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index beb287a94..8b9f6a74f 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -20,12 +20,10 @@ import baritone.api.BaritoneAPI; import baritone.api.Settings; import net.minecraft.client.Minecraft; -import net.minecraft.core.Direction; import net.minecraft.core.Holder; -import net.minecraft.core.Registry; import net.minecraft.core.Vec3i; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Mirror; @@ -247,7 +245,7 @@ private enum Parser implements ISettingParser { ), ITEM( Item.class, - str -> BuiltInRegistries.ITEM.get(ResourceLocation.parse(str.trim())).map(Holder.Reference::value).orElse(null), + str -> BuiltInRegistries.ITEM.get(Identifier.parse(str.trim())).map(Holder.Reference::value).orElse(null), item -> BuiltInRegistries.ITEM.getKey(item).toString() ), LIST() { diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityRenderManager.java b/src/launch/java/baritone/launch/mixins/MixinEntityRenderManager.java index 32f85593e..29780ab94 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityRenderManager.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityRenderManager.java @@ -27,16 +27,16 @@ public class MixinEntityRenderManager implements IEntityRenderManager { @Override public double renderPosX() { - return ((EntityRenderDispatcher) (Object) this).camera.getPosition().x; + return ((EntityRenderDispatcher) (Object) this).camera.position().x; } @Override public double renderPosY() { - return ((EntityRenderDispatcher) (Object) this).camera.getPosition().y; + return ((EntityRenderDispatcher) (Object) this).camera.position().y; } @Override public double renderPosZ() { - return ((EntityRenderDispatcher) (Object) this).camera.getPosition().z; + return ((EntityRenderDispatcher) (Object) this).camera.position().z; } } diff --git a/src/launch/java/baritone/launch/mixins/MixinRenderType.java b/src/launch/java/baritone/launch/mixins/MixinRenderType.java new file mode 100644 index 000000000..39102ad37 --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinRenderType.java @@ -0,0 +1,38 @@ +/* + * 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.utils.accessor.IRenderType; +import net.minecraft.client.renderer.rendertype.RenderSetup; +import net.minecraft.client.renderer.rendertype.RenderType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(RenderType.class) +public abstract class MixinRenderType implements IRenderType { + + @Shadow + static RenderType create(final String string, final RenderSetup renderSetup) { + return null; + } + + @Override + public RenderType createRenderType(final String name, final RenderSetup renderSetup) { + return create(name, renderSetup); + } +} diff --git a/src/launch/java/baritone/launch/mixins/MixinScreen.java b/src/launch/java/baritone/launch/mixins/MixinScreen.java index 247e751d1..f5842249a 100644 --- a/src/launch/java/baritone/launch/mixins/MixinScreen.java +++ b/src/launch/java/baritone/launch/mixins/MixinScreen.java @@ -35,8 +35,8 @@ public abstract class MixinScreen implements IGuiScreen { //TODO: switch to enum extention with mixin 9.0 or whenever Mumfrey gets around to it - @Inject(method = "handleClickEvent", at = @At(value = "HEAD"), cancellable = true) - public void handleCustomClickEvent(final Minecraft minecraft, final ClickEvent clickEvent, final CallbackInfo ci) { + @Inject(method = "defaultHandleGameClickEvent", at = @At(value = "HEAD"), cancellable = true) + private static void handleCustomClickEvent(final ClickEvent clickEvent, final Minecraft minecraft, final Screen screen, final CallbackInfo ci) { if (clickEvent == null) { return; } diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index 0b845f3a0..8a71428f3 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -26,6 +26,7 @@ "MixinPalettedContainer$Data", "MixinPlayerController", "MixinRenderPipelines", + "MixinRenderType", "MixinScreen", "MixinWorldRenderer" ], diff --git a/src/main/java/baritone/cache/CachedChunk.java b/src/main/java/baritone/cache/CachedChunk.java index 2659c4feb..86a849e5a 100644 --- a/src/main/java/baritone/cache/CachedChunk.java +++ b/src/main/java/baritone/cache/CachedChunk.java @@ -22,6 +22,8 @@ import com.google.common.collect.ImmutableSet; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; @@ -192,7 +194,7 @@ private final void setSpecial() { } } - public final BlockState getBlock(int x, int y, int z, DimensionType dimension) { + public final BlockState getBlock(int x, int y, int z, DimensionType dimension, ResourceKey dimensionId) { int index = getPositionIndex(x, y, z); PathingBlockType type = getType(index); int internalPos = z << 4 | x; @@ -218,14 +220,15 @@ public final BlockState getBlock(int x, int y, int z, DimensionType dimension) { // nether roof is always unbreakable return Blocks.BEDROCK.defaultBlockState(); } - if (y < -59 && dimension.natural()) { + + if ((dimensionId == Level.OVERWORLD || dimensionId == Level.NETHER) && y < dimension.minY() + 5) { // solid blocks below 5 are commonly bedrock // however, returning bedrock always would be a little yikes // discourage paths that include breaking blocks below 5 a little more heavily just so that it takes paths breaking what's known to be stone (at 5 or above) instead of what could maybe be bedrock (below 5) return Blocks.OBSIDIAN.defaultBlockState(); } } - return ChunkPacker.pathingTypeToBlock(type, dimension); + return ChunkPacker.pathingTypeToBlock(type, dimension, dimensionId); } private PathingBlockType getType(int index) { diff --git a/src/main/java/baritone/cache/CachedRegion.java b/src/main/java/baritone/cache/CachedRegion.java index 8aa992d79..38b549010 100644 --- a/src/main/java/baritone/cache/CachedRegion.java +++ b/src/main/java/baritone/cache/CachedRegion.java @@ -21,6 +21,8 @@ import baritone.api.cache.ICachedRegion; import baritone.api.utils.BlockUtils; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.dimension.DimensionType; @@ -63,16 +65,19 @@ public final class CachedRegion implements ICachedRegion { private final DimensionType dimension; + private final ResourceKey dimensionId; + /** * Has this region been modified since its most recent load or save */ private boolean hasUnsavedChanges; - CachedRegion(int x, int z, DimensionType dimension) { + CachedRegion(int x, int z, DimensionType dimension, ResourceKey dimensionId) { this.x = x; this.z = z; this.hasUnsavedChanges = false; this.dimension = dimension; + this.dimensionId = dimensionId; } @Override @@ -80,7 +85,7 @@ public final BlockState getBlock(int x, int y, int z) { int adjY = y - dimension.minY(); CachedChunk chunk = chunks[x >> 4][z >> 4]; if (chunk != null) { - return chunk.getBlock(x & 15, adjY, z & 15, dimension); + return chunk.getBlock(x & 15, adjY, z & 15, dimension, dimensionId); } return null; } diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index aed1faeb5..037cc35f4 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -27,7 +27,9 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.Level; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.dimension.DimensionType; @@ -74,7 +76,9 @@ public final class CachedWorld implements ICachedWorld, Helper { private final DimensionType dimension; - CachedWorld(Path directory, DimensionType dimension) { + private final ResourceKey dimensionId; + + CachedWorld(Path directory, DimensionType dimension, ResourceKey dimensionId) { if (!Files.exists(directory)) { try { Files.createDirectories(directory); @@ -83,6 +87,7 @@ public final class CachedWorld implements ICachedWorld, Helper { } this.directory = directory.toString(); this.dimension = dimension; + this.dimensionId = dimensionId; System.out.println("Cached world directory: " + directory); Baritone.getExecutor().execute(new PackerThread()); Baritone.getExecutor().execute(() -> { @@ -262,7 +267,7 @@ public final synchronized CachedRegion getRegion(int regionX, int regionZ) { */ private synchronized CachedRegion getOrCreateRegion(int regionX, int regionZ) { return cachedRegions.computeIfAbsent(getRegionID(regionX, regionZ), id -> { - CachedRegion newRegion = new CachedRegion(regionX, regionZ, dimension); + CachedRegion newRegion = new CachedRegion(regionX, regionZ, dimension, dimensionId); newRegion.load(this.directory); return newRegion; }); diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index 5c8580187..c52b73205 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -21,17 +21,13 @@ import baritone.pathing.movement.MovementHelper; import baritone.utils.pathing.PathingBlockType; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.AirBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.DoublePlantBlock; -import net.minecraft.world.level.block.FlowerBlock; -import net.minecraft.world.level.block.TallGrassBlock; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.chunk.PalettedContainer; -import net.minecraft.world.level.dimension.BuiltinDimensionTypes; import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.phys.Vec3; @@ -157,7 +153,7 @@ private static PathingBlockType getPathingBlockType(BlockState state, LevelChunk return PathingBlockType.SOLID; } - public static BlockState pathingTypeToBlock(PathingBlockType type, DimensionType dimension) { + public static BlockState pathingTypeToBlock(PathingBlockType type, DimensionType dimension, ResourceKey dimensionId) { switch (type) { case AIR: return Blocks.AIR.defaultBlockState(); @@ -167,14 +163,12 @@ public static BlockState pathingTypeToBlock(PathingBlockType type, DimensionType return Blocks.LAVA.defaultBlockState(); case SOLID: // Dimension solid types - if (dimension.natural()) { - return Blocks.STONE.defaultBlockState(); - } - if (dimension.ultraWarm()) { + if (dimensionId == Level.NETHER) { return Blocks.NETHERRACK.defaultBlockState(); - } - if (dimension.effectsLocation().equals(BuiltinDimensionTypes.END_EFFECTS)) { + } else if (dimensionId == Level.END) { return Blocks.END_STONE.defaultBlockState(); + } else { // overworld, or some custom dimension + return Blocks.STONE.defaultBlockState(); } default: return null; diff --git a/src/main/java/baritone/cache/WorldData.java b/src/main/java/baritone/cache/WorldData.java index b8efb5e1c..5ea9739f9 100644 --- a/src/main/java/baritone/cache/WorldData.java +++ b/src/main/java/baritone/cache/WorldData.java @@ -21,6 +21,8 @@ import baritone.api.cache.ICachedWorld; import baritone.api.cache.IWaypointCollection; import baritone.api.cache.IWorldData; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import net.minecraft.world.level.dimension.DimensionType; import java.nio.file.Path; @@ -38,9 +40,9 @@ public class WorldData implements IWorldData { public final Path directory; public final DimensionType dimension; - WorldData(Path directory, DimensionType dimension) { + WorldData(Path directory, DimensionType dimension, ResourceKey dimensionId) { this.directory = directory; - this.cache = new CachedWorld(directory.resolve("cache"), dimension); + this.cache = new CachedWorld(directory.resolve("cache"), dimension, dimensionId); this.waypoints = new WaypointCollection(directory.resolve("waypoints")); this.dimension = dimension; } diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index 38202e65b..f503a0799 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -21,10 +21,9 @@ import baritone.api.cache.IWorldProvider; import baritone.api.utils.IPlayerContext; import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.util.Tuple; import net.minecraft.world.level.Level; -import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.storage.LevelResource; import org.apache.commons.lang3.SystemUtils; @@ -93,7 +92,7 @@ public final void initWorld(Level world) { System.out.println("Baritone world data dir: " + worldDataDir); synchronized (worldCache) { - this.currentWorld = worldCache.computeIfAbsent(worldDataDir, d -> new WorldData(d, world.dimensionType())); + this.currentWorld = worldCache.computeIfAbsent(worldDataDir, d -> new WorldData(d, world.dimensionType(), world.dimension())); } this.mcWorld = ctx.world(); }); @@ -110,7 +109,7 @@ public final void closeWorld() { } private Path getWorldDataDirectory(Path parent, Level world) { - ResourceLocation dimId = world.dimension().location(); + Identifier dimId = world.dimension().identifier(); int height = world.dimensionType().logicalHeight(); return parent.resolve(dimId.getNamespace()).resolve(dimId.getPath() + "_" + height); } diff --git a/src/main/java/baritone/command/ExampleBaritoneControl.java b/src/main/java/baritone/command/ExampleBaritoneControl.java index ffc53cb0b..bb9681e97 100644 --- a/src/main/java/baritone/command/ExampleBaritoneControl.java +++ b/src/main/java/baritone/command/ExampleBaritoneControl.java @@ -34,12 +34,12 @@ import baritone.command.argument.CommandArguments; import baritone.command.manager.CommandManager; import net.minecraft.ChatFormatting; -import net.minecraft.Util; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.MutableComponent; import net.minecraft.util.Tuple; +import net.minecraft.util.Util; import java.util.List; import java.util.Locale; diff --git a/src/main/java/baritone/command/defaults/FollowCommand.java b/src/main/java/baritone/command/defaults/FollowCommand.java index b7e708377..a680bdc4a 100644 --- a/src/main/java/baritone/command/defaults/FollowCommand.java +++ b/src/main/java/baritone/command/defaults/FollowCommand.java @@ -27,17 +27,17 @@ import baritone.api.command.exception.CommandErrorMessageException; import baritone.api.command.exception.CommandException; import baritone.api.command.helpers.TabCompleteHelper; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Stream; -import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; +import java.util.*; +import java.util.function.Predicate; +import java.util.stream.Stream; + public class FollowCommand extends Command { public FollowCommand(IBaritone baritone) { @@ -87,7 +87,7 @@ public void execute(String label, IArgConsumer args) throws CommandException { classes.stream() .map(BuiltInRegistries.ENTITY_TYPE::getKey) .map(Objects::requireNonNull) - .map(ResourceLocation::toString) + .map(Identifier::toString) .forEach(this::logDirect); } } diff --git a/src/main/java/baritone/command/defaults/PickupCommand.java b/src/main/java/baritone/command/defaults/PickupCommand.java index 7967dd023..a032ec823 100644 --- a/src/main/java/baritone/command/defaults/PickupCommand.java +++ b/src/main/java/baritone/command/defaults/PickupCommand.java @@ -23,7 +23,7 @@ import baritone.api.command.datatypes.ItemById; import baritone.api.command.exception.CommandException; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.item.Item; import java.util.Arrays; @@ -51,7 +51,7 @@ public void execute(String label, IArgConsumer args) throws CommandException { } else { baritone.getFollowProcess().pickup(stack -> collecting.contains(stack.getItem())); logDirect("Picking up these items:"); - collecting.stream().map(BuiltInRegistries.ITEM::getKey).map(ResourceLocation::toString).forEach(this::logDirect); + collecting.stream().map(BuiltInRegistries.ITEM::getKey).map(Identifier::toString).forEach(this::logDirect); } } diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 22e4d4d08..c9225f3ea 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -75,8 +75,8 @@ public void onRenderPass(RenderEvent event) { float opacity = Baritone.settings().selectionOpacity.value; float lineWidth = Baritone.settings().selectionLineWidth.value; boolean ignoreDepth = Baritone.settings().renderSelectionIgnoreDepth.value; - BufferBuilder bufferBuilder = IRenderer.startLines(color, opacity, lineWidth); - IRenderer.emitAABB(bufferBuilder, event.getModelViewStack(), new AABB(pos1)); + BufferBuilder bufferBuilder = IRenderer.startLines(color, opacity); + IRenderer.emitAABB(bufferBuilder, event.getModelViewStack(), new AABB(pos1), lineWidth); IRenderer.endLines(bufferBuilder, ignoreDepth); } }); diff --git a/src/main/java/baritone/process/elytra/ElytraBehavior.java b/src/main/java/baritone/process/elytra/ElytraBehavior.java index ae32cfddb..1c9dbe185 100644 --- a/src/main/java/baritone/process/elytra/ElytraBehavior.java +++ b/src/main/java/baritone/process/elytra/ElytraBehavior.java @@ -424,26 +424,26 @@ 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) { - BufferBuilder bufferBuilder = IRenderer.startLines(Color.GREEN, settings.pathRenderLineWidthPixels.value); + BufferBuilder bufferBuilder = IRenderer.startLines(Color.GREEN); for (Pair line : this.clearLines) { - IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), line.first(), line.second()); + IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), line.first(), line.second(), settings.pathRenderLineWidthPixels.value); } IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value); } if (!this.blockedLines.isEmpty() && Baritone.settings().elytraRenderRaytraces.value) { - BufferBuilder bufferBuilder = IRenderer.startLines(Color.BLUE, settings.pathRenderLineWidthPixels.value); + BufferBuilder bufferBuilder = IRenderer.startLines(Color.BLUE); for (Pair line : this.blockedLines) { - IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), line.first(), line.second()); + IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), line.first(), line.second(), settings.pathRenderLineWidthPixels.value); } IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value); } if (this.simulationLine != null && Baritone.settings().elytraRenderSimulation.value) { - BufferBuilder bufferBuilder = IRenderer.startLines(new Color(0x36CCDC), settings.pathRenderLineWidthPixels.value); + BufferBuilder bufferBuilder = IRenderer.startLines(new Color(0x36CCDC)); 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(bufferBuilder, event.getModelViewStack(), src, dst); + IRenderer.emitLine(bufferBuilder, event.getModelViewStack(), src, dst, settings.pathRenderLineWidthPixels.value); } IRenderer.endLines(bufferBuilder, settings.renderPathIgnoreDepth.value); } diff --git a/src/main/java/baritone/process/elytra/NetherPathfinderContext.java b/src/main/java/baritone/process/elytra/NetherPathfinderContext.java index 56c8fec38..475590251 100644 --- a/src/main/java/baritone/process/elytra/NetherPathfinderContext.java +++ b/src/main/java/baritone/process/elytra/NetherPathfinderContext.java @@ -196,9 +196,13 @@ private static void writeChunkData(LevelChunk chunk, long ptr) { continue; } final PalettedContainer bsc = extendedblockstorage.getStates(); - final int airId = ((IPalettedContainer) bsc).getPalette().idFor(AIR_BLOCK_STATE, PaletteResize.noResizeExpected()); + IPalettedContainer iPalettedContainer = (IPalettedContainer) bsc; + int airId = -1; + if (iPalettedContainer.getPalette().maybeHas(state -> state.equals(AIR_BLOCK_STATE))) { + airId = iPalettedContainer.getPalette().idFor(AIR_BLOCK_STATE, PaletteResize.noResizeExpected()); + } // pasted from FasterWorldScanner - final BitStorage array = ((IPalettedContainer) bsc).getStorage(); + final BitStorage array = iPalettedContainer.getStorage(); if (array == null) continue; final long[] longArray = array.getRaw(); final int arraySize = array.getSize(); diff --git a/src/main/java/baritone/selection/SelectionRenderer.java b/src/main/java/baritone/selection/SelectionRenderer.java index aca1d376c..58f817882 100644 --- a/src/main/java/baritone/selection/SelectionRenderer.java +++ b/src/main/java/baritone/selection/SelectionRenderer.java @@ -29,23 +29,23 @@ public static void renderSelections(PoseStack stack, ISelection[] selections) { return; } - BufferBuilder bufferBuilder = IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth); + BufferBuilder bufferBuilder = IRenderer.startLines(settings.colorSelection.value, opacity); for (ISelection selection : selections) { - IRenderer.emitAABB(bufferBuilder, stack, selection.aabb(), SELECTION_BOX_EXPANSION); + IRenderer.emitAABB(bufferBuilder, stack, selection.aabb(), SELECTION_BOX_EXPANSION, lineWidth); } if (settings.renderSelectionCorners.value) { IRenderer.glColor(settings.colorSelectionPos1.value, opacity); for (ISelection selection : selections) { - IRenderer.emitAABB(bufferBuilder, stack, new AABB(selection.pos1())); + IRenderer.emitAABB(bufferBuilder, stack, new AABB(selection.pos1()), lineWidth); } IRenderer.glColor(settings.colorSelectionPos2.value, opacity); for (ISelection selection : selections) { - IRenderer.emitAABB(bufferBuilder, stack, new AABB(selection.pos2())); + IRenderer.emitAABB(bufferBuilder, stack, new AABB(selection.pos2()), lineWidth); } } diff --git a/src/main/java/baritone/utils/BaritoneRenderType.java b/src/main/java/baritone/utils/BaritoneRenderType.java deleted file mode 100644 index ca57eb3e1..000000000 --- a/src/main/java/baritone/utils/BaritoneRenderType.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.utils; - -import com.mojang.blaze3d.buffers.GpuBuffer; -import com.mojang.blaze3d.buffers.GpuBufferSlice; -import com.mojang.blaze3d.pipeline.RenderPipeline; -import com.mojang.blaze3d.pipeline.RenderTarget; -import com.mojang.blaze3d.systems.RenderPass; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.systems.ScissorState; -import com.mojang.blaze3d.textures.GpuTextureView; -import com.mojang.blaze3d.vertex.MeshData; -import com.mojang.blaze3d.vertex.VertexFormat; -import net.minecraft.client.renderer.RenderStateShard; -import net.minecraft.client.renderer.RenderType; -import org.joml.Vector3f; -import org.joml.Vector4f; - -import java.util.OptionalDouble; -import java.util.OptionalInt; - -public class BaritoneRenderType extends RenderType { - private final RenderPipeline renderPipeline; - - public BaritoneRenderType(String name, int bufferSize, boolean affectsCrumbling, boolean sortOnUpload, RenderPipeline renderPipeline) { - super(name, bufferSize, affectsCrumbling, sortOnUpload, () -> {}, () -> {}); - this.renderPipeline = renderPipeline; - } - - public static BaritoneRenderType create(String name, int bufferSize, RenderPipeline renderPipeline) { - return new BaritoneRenderType(name, bufferSize, false, false, renderPipeline); - } - - @Override - public VertexFormat format() { - return this.renderPipeline.getVertexFormat(); - } - - @Override - public VertexFormat.Mode mode() { - return this.renderPipeline.getVertexFormatMode(); - } - - @Override - public RenderPipeline pipeline() { - return this.renderPipeline; - } - - @Override - public void draw(final MeshData meshData) { - this.setupRenderState(); - try { - GpuBuffer vertexBuffer = this.renderPipeline.getVertexFormat().uploadImmediateVertexBuffer(meshData.vertexBuffer()); - GpuBuffer indexBuffer; - VertexFormat.IndexType indexType; - if (meshData.indexBuffer() == null) { - RenderSystem.AutoStorageIndexBuffer autoStorageIndexBuffer = RenderSystem.getSequentialBuffer(meshData.drawState().mode()); - indexBuffer = autoStorageIndexBuffer.getBuffer(meshData.drawState().indexCount()); - indexType = autoStorageIndexBuffer.type(); - } else { - indexBuffer = this.renderPipeline.getVertexFormat().uploadImmediateIndexBuffer(meshData.indexBuffer()); - indexType = meshData.drawState().indexType(); - } - - RenderTarget renderTarget = RenderStateShard.MAIN_TARGET.getRenderTarget(); - GpuTextureView colorTextureTarget = RenderSystem.outputColorTextureOverride != null - ? RenderSystem.outputColorTextureOverride - : renderTarget.getColorTextureView(); - GpuTextureView depthTextureTarget = renderTarget.useDepth - ? (RenderSystem.outputDepthTextureOverride != null ? RenderSystem.outputDepthTextureOverride : renderTarget.getDepthTextureView()) - : null; - - GpuBufferSlice dynamicTransformsUbo = RenderSystem.getDynamicUniforms() - .writeTransform( - RenderSystem.getModelViewMatrix(), - new Vector4f(1.0F, 1.0F, 1.0F, 1.0F), - new Vector3f(), - RenderSystem.getTextureMatrix(), - RenderSystem.getShaderLineWidth() - ); - - try (RenderPass renderPass = RenderSystem.getDevice() - .createCommandEncoder() - .createRenderPass(() -> "Immediate draw for " + this.getName(), colorTextureTarget, OptionalInt.empty(), depthTextureTarget, OptionalDouble.empty())) { - renderPass.setPipeline(this.renderPipeline); - ScissorState scissorState = RenderSystem.getScissorStateForRenderTypeDraws(); - if (scissorState.enabled()) { - renderPass.enableScissor(scissorState.x(), scissorState.y(), scissorState.width(), scissorState.height()); - } - - RenderSystem.bindDefaultUniforms(renderPass); - renderPass.setUniform("DynamicTransforms", dynamicTransformsUbo); - renderPass.setVertexBuffer(0, vertexBuffer); - - for (int i = 0; i < 12; i++) { - GpuTextureView texture = RenderSystem.getShaderTexture(i); - if (texture != null) { - renderPass.bindSampler("Sampler" + i, texture); - } - } - - renderPass.setIndexBuffer(indexBuffer, indexType); - renderPass.drawIndexed(0, 0, meshData.drawState().indexCount(), 1); - } - } catch (Throwable e) { - try { - meshData.close(); - } catch (Throwable e2) { - e.addSuppressed(e2); - } - throw e; - } - - meshData.close(); - - this.clearRenderState(); - } -} diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java index 55746c0af..41aa1be74 100644 --- a/src/main/java/baritone/utils/GuiClick.java +++ b/src/main/java/baritone/utils/GuiClick.java @@ -126,10 +126,10 @@ public void onRender(PoseStack modelViewStack, Matrix4f projectionMatrix) { // drawSingleSelectionBox WHEN? PathRenderer.drawManySelectionBoxes(modelViewStack, e, Collections.singletonList(currentMouseOver), Color.CYAN); if (clickStart != null && !clickStart.equals(currentMouseOver)) { - BufferBuilder bufferBuilder = IRenderer.startLines(Color.RED, Baritone.settings().pathRenderLineWidthPixels.value); + BufferBuilder bufferBuilder = IRenderer.startLines(Color.RED); BetterBlockPos a = new BetterBlockPos(currentMouseOver); BetterBlockPos b = new BetterBlockPos(clickStart); - IRenderer.emitAABB(bufferBuilder, modelViewStack, new AABB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1)); + 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), Baritone.settings().pathRenderLineWidthPixels.value); IRenderer.endLines(bufferBuilder, true); } } diff --git a/src/main/java/baritone/utils/IRenderer.java b/src/main/java/baritone/utils/IRenderer.java index c37505ad6..2a43a13eb 100644 --- a/src/main/java/baritone/utils/IRenderer.java +++ b/src/main/java/baritone/utils/IRenderer.java @@ -21,16 +21,18 @@ import baritone.api.Settings; import baritone.utils.accessor.IEntityRenderManager; import baritone.utils.accessor.IRenderPipelines; +import baritone.utils.accessor.IRenderType; import com.mojang.blaze3d.pipeline.BlendFunction; import com.mojang.blaze3d.pipeline.RenderPipeline; import com.mojang.blaze3d.platform.DepthTestFunction; import com.mojang.blaze3d.platform.DestFactor; import com.mojang.blaze3d.platform.SourceFactor; -import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderPipelines; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.rendertype.RenderSetup; +import net.minecraft.client.renderer.rendertype.RenderType; +import net.minecraft.client.renderer.rendertype.RenderTypes; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; @@ -51,21 +53,24 @@ public interface IRenderer { .withDepthWrite(false) .withCull(false) .buildSnippet(); - RenderType linesWithDepthRenderType = BaritoneRenderType.create( + + RenderType linesWithDepthRenderType = ((IRenderType) RenderTypes.lines()).createRenderType( "renderType/baritone_lines_with_depth", - 256, - RenderPipeline.builder(BARITONE_LINES_SNIPPET) + RenderSetup.builder(RenderPipeline.builder(BARITONE_LINES_SNIPPET) .withLocation("pipelines/baritone_lines_with_depth") .withDepthTestFunction(DepthTestFunction.LEQUAL_DEPTH_TEST) - .build() + .build()) + .bufferSize(256) + .createRenderSetup() ); - RenderType linesNoDepthRenderType = BaritoneRenderType.create( + RenderType linesNoDepthRenderType = ((IRenderType) RenderTypes.lines()).createRenderType( "renderType/baritone_lines_no_depth", - 256, - RenderPipeline.builder(BARITONE_LINES_SNIPPET) - .withLocation("pipelines/baritone_lines_no_depth") - .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) - .build() + RenderSetup.builder(RenderPipeline.builder(BARITONE_LINES_SNIPPET) + .withLocation("pipelines/baritone_lines_no_depth") + .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) + .build()) + .bufferSize(256) + .createRenderSetup() ); float[] color = new float[]{1.0F, 1.0F, 1.0F, 255.0F}; @@ -78,14 +83,13 @@ static void glColor(Color color, float alpha) { IRenderer.color[3] = alpha; } - static BufferBuilder startLines(Color color, float alpha, float lineWidth) { + static BufferBuilder startLines(Color color, float alpha) { glColor(color, alpha); - RenderSystem.lineWidth(lineWidth); - return tessellator.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL); + return tessellator.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL_LINE_WIDTH); } - static BufferBuilder startLines(Color color, float lineWidth) { - return startLines(color, .4f, lineWidth); + static BufferBuilder startLines(Color color) { + return startLines(color, .4f); } static void endLines(BufferBuilder bufferBuilder, boolean ignoredDepth) { @@ -99,7 +103,7 @@ static void endLines(BufferBuilder bufferBuilder, boolean ignoredDepth) { } } - static void emitLine(BufferBuilder bufferBuilder, 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, float lineWidth) { final double dx = x2 - x1; final double dy = y2 - y1; final double dz = z2 - z1; @@ -109,59 +113,64 @@ static void emitLine(BufferBuilder bufferBuilder, PoseStack stack, double x1, do final float ny = (float) (dy * invMag); final float nz = (float) (dz * invMag); - emitLine(bufferBuilder, stack, x1, y1, z1, x2, y2, z2, nx, ny, nz); + emitLine(bufferBuilder, stack, x1, y1, z1, x2, y2, z2, nx, ny, nz, lineWidth); } 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) { + double nx, double ny, double nz, + float lineWidth + ) { emitLine(bufferBuilder, stack, (float) x1, (float) y1, (float) z1, (float) x2, (float) y2, (float) z2, - (float) nx, (float) ny, (float) nz + (float) nx, (float) ny, (float) nz, + lineWidth ); } 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) { + float nx, float ny, float nz, + float lineWidth + ) { PoseStack.Pose pose = stack.last(); - 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); + bufferBuilder.addVertex(pose, x1, y1, z1).setColor(color[0], color[1], color[2], color[3]).setNormal(pose, nx, ny, nz).setLineWidth(lineWidth); + bufferBuilder.addVertex(pose, x2, y2, z2).setColor(color[0], color[1], color[2], color[3]).setNormal(pose, nx, ny, nz).setLineWidth(lineWidth); } - static void emitAABB(BufferBuilder bufferBuilder, PoseStack stack, AABB aabb) { + static void emitAABB(BufferBuilder bufferBuilder, PoseStack stack, AABB aabb, float lineWidth) { AABB toDraw = aabb.move(-renderManager.renderPosX(), -renderManager.renderPosY(), -renderManager.renderPosZ()); // bottom - 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); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.minZ, 1.0, 0.0, 0.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.maxZ, 0.0, 0.0, 1.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.maxZ, -1.0, 0.0, 0.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.minZ, 0.0, 0.0, -1.0, lineWidth); // top - 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); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 1.0, 0.0, 0.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 0.0, 1.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, -1.0, 0.0, 0.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 0.0, -1.0, lineWidth); // corners - 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); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0, lineWidth); + emitLine(bufferBuilder, stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0, lineWidth); } - static void emitAABB(BufferBuilder bufferBuilder, PoseStack stack, AABB aabb, double expand) { - emitAABB(bufferBuilder, stack, aabb.inflate(expand, expand, expand)); + static void emitAABB(BufferBuilder bufferBuilder, PoseStack stack, AABB aabb, double expand, float lineWidth) { + emitAABB(bufferBuilder, stack, aabb.inflate(expand, expand, expand), lineWidth); } - static void emitLine(BufferBuilder bufferBuilder, PoseStack stack, Vec3 start, Vec3 end) { + static void emitLine(BufferBuilder bufferBuilder, PoseStack stack, Vec3 start, Vec3 end, float lineWidth) { double vpX = renderManager.renderPosX(); double vpY = renderManager.renderPosY(); double vpZ = renderManager.renderPosZ(); - emitLine(bufferBuilder, 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, lineWidth); } } diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 58e7019d0..4883df69e 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -129,7 +129,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) { - BufferBuilder bufferBuilder = IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value); + BufferBuilder bufferBuilder = IRenderer.startLines(color); int fadeStart = fadeStart0 + startIndex; int fadeEnd = fadeEnd0 + startIndex; @@ -179,26 +179,30 @@ private static void emitPathLine(BufferBuilder bufferBuilder, PoseStack stack, d IRenderer.emitLine(bufferBuilder, stack, x1 + offset - vpX, y1 + offset - vpY, z1 + offset - vpZ, - x2 + offset - vpX, y2 + offset - vpY, z2 + offset - vpZ + x2 + offset - vpX, y2 + offset - vpY, z2 + offset - vpZ, + settings.pathRenderLineWidthPixels.value ); if (renderPathAsFrickinThingy) { IRenderer.emitLine(bufferBuilder, stack, x2 + offset - vpX, y2 + offset - vpY, z2 + offset - vpZ, - x2 + offset - vpX, y2 + extraOffset - vpY, z2 + offset - vpZ + x2 + offset - vpX, y2 + extraOffset - vpY, z2 + offset - vpZ, + settings.pathRenderLineWidthPixels.value ); IRenderer.emitLine(bufferBuilder, stack, x2 + offset - vpX, y2 + extraOffset - vpY, z2 + offset - vpZ, - x1 + offset - vpX, y1 + extraOffset - vpY, z1 + offset - vpZ + x1 + offset - vpX, y1 + extraOffset - vpY, z1 + offset - vpZ, + settings.pathRenderLineWidthPixels.value ); IRenderer.emitLine(bufferBuilder, stack, x1 + offset - vpX, y1 + extraOffset - vpY, z1 + offset - vpZ, - x1 + offset - vpX, y1 + offset - vpY, z1 + offset - vpZ + x1 + offset - vpX, y1 + offset - vpY, z1 + offset - vpZ, + settings.pathRenderLineWidthPixels.value ); } } public static void drawManySelectionBoxes(PoseStack stack, Entity player, Collection positions, Color color) { - BufferBuilder bufferBuilder = IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value); + BufferBuilder bufferBuilder = IRenderer.startLines(color); //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? @@ -208,7 +212,7 @@ 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(bufferBuilder, stack, toDraw, .002D); + IRenderer.emitAABB(bufferBuilder, stack, toDraw, .002D, settings.pathRenderLineWidthPixels.value); }); IRenderer.endLines(bufferBuilder, settings.renderSelectionBoxesIgnoreDepth.value); @@ -310,18 +314,18 @@ private static void drawGoal(@Nullable BufferBuilder bufferBuilder, PoseStack st private static void drawDankLitGoalBox(BufferBuilder bufferBuilder, PoseStack stack, Color colorIn, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) { if (setupRender) { - bufferBuilder = IRenderer.startLines(colorIn, settings.goalRenderLineWidthPixels.value); + bufferBuilder = IRenderer.startLines(colorIn); } - renderHorizontalQuad(bufferBuilder, stack, minX, maxX, minZ, maxZ, y1); - renderHorizontalQuad(bufferBuilder, stack, minX, maxX, minZ, maxZ, y2); + renderHorizontalQuad(bufferBuilder, stack, minX, maxX, minZ, maxZ, y1, settings.goalRenderLineWidthPixels.value); + renderHorizontalQuad(bufferBuilder, stack, minX, maxX, minZ, maxZ, y2, settings.goalRenderLineWidthPixels.value); for (double y = minY; y < maxY; y += 16) { double max = Math.min(maxY, y + 16); - 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); + IRenderer.emitLine(bufferBuilder, stack, minX, y, minZ, minX, max, minZ, 0.0, 1.0, 0.0, settings.goalRenderLineWidthPixels.value); + IRenderer.emitLine(bufferBuilder, stack, maxX, y, minZ, maxX, max, minZ, 0.0, 1.0, 0.0, settings.goalRenderLineWidthPixels.value); + IRenderer.emitLine(bufferBuilder, stack, maxX, y, maxZ, maxX, max, maxZ, 0.0, 1.0, 0.0, settings.goalRenderLineWidthPixels.value); + IRenderer.emitLine(bufferBuilder, stack, minX, y, maxZ, minX, max, maxZ, 0.0, 1.0, 0.0, settings.goalRenderLineWidthPixels.value); } if (setupRender) { @@ -329,12 +333,12 @@ private static void drawDankLitGoalBox(BufferBuilder bufferBuilder, PoseStack st } } - private static void renderHorizontalQuad(BufferBuilder bufferBuilder, 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, float lineWidth) { if (y != 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); + IRenderer.emitLine(bufferBuilder, stack, minX, y, minZ, maxX, y, minZ, 1.0, 0.0, 0.0, lineWidth); + IRenderer.emitLine(bufferBuilder, stack, maxX, y, minZ, maxX, y, maxZ, 0.0, 0.0, 1.0, lineWidth); + IRenderer.emitLine(bufferBuilder, stack, maxX, y, maxZ, minX, y, maxZ, -1.0, 0.0, 0.0, lineWidth); + IRenderer.emitLine(bufferBuilder, stack, minX, y, maxZ, minX, y, minZ, 0.0, 0.0, -1.0, lineWidth); } } } diff --git a/src/main/java/baritone/utils/accessor/IRenderType.java b/src/main/java/baritone/utils/accessor/IRenderType.java new file mode 100644 index 000000000..3fb853262 --- /dev/null +++ b/src/main/java/baritone/utils/accessor/IRenderType.java @@ -0,0 +1,25 @@ +/* + * 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.utils.accessor; + +import net.minecraft.client.renderer.rendertype.RenderSetup; +import net.minecraft.client.renderer.rendertype.RenderType; + +public interface IRenderType { + RenderType createRenderType(String name, RenderSetup renderSetup); +} diff --git a/src/main/java/baritone/utils/pathing/Avoidance.java b/src/main/java/baritone/utils/pathing/Avoidance.java index 0b4b95843..dcaf6e8a5 100644 --- a/src/main/java/baritone/utils/pathing/Avoidance.java +++ b/src/main/java/baritone/utils/pathing/Avoidance.java @@ -21,14 +21,15 @@ import baritone.api.utils.BetterBlockPos; import baritone.api.utils.IPlayerContext; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.monster.EnderMan; -import net.minecraft.world.entity.monster.Spider; -import net.minecraft.world.entity.monster.ZombifiedPiglin; +import net.minecraft.world.entity.monster.spider.Spider; +import net.minecraft.world.entity.monster.zombie.ZombifiedPiglin; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; public class Avoidance { 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 56952762f..c3496c016 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -25,7 +25,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; @@ -88,7 +88,7 @@ private static BlockState[] getBlockList(ListTag blockStatePalette) { for (int i = 0; i < blockStatePalette.size(); i++) { CompoundTag tag = (CompoundTag) blockStatePalette.get(i); - ResourceLocation blockKey = ResourceLocation.tryParse(tag.getString("Name").orElse("")); + Identifier blockKey = Identifier.tryParse(tag.getString("Name").orElse("")); Block block = blockKey == null ? Blocks.AIR : BuiltInRegistries.BLOCK.get(blockKey) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java index a5239c2ca..353802966 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java @@ -21,7 +21,7 @@ import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.util.datafix.fixes.ItemIdFix; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -64,7 +64,7 @@ public MCEditSchematic(CompoundTag schematic) { // additional is 0 through 15 inclusive since it's & 0xF above blockID |= additional[blockInd] << 8; } - ResourceLocation blockKey = ResourceLocation.tryParse(ItemIdFix.getItem(blockID)); + Identifier blockKey = Identifier.tryParse(ItemIdFix.getItem(blockID)); Block block = blockKey == null ? Blocks.AIR : BuiltInRegistries.BLOCK.get(blockKey) 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 35c84cb9a..d73242133 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java @@ -23,7 +23,7 @@ import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; @@ -98,18 +98,18 @@ private static final class SerializedBlockState { private static final Pattern REGEX = Pattern.compile("(?(\\w+:)?\\w+)(\\[(?(\\w+=\\w+,?)+)])?"); - private final ResourceLocation resourceLocation; + private final Identifier identifier; private final Map properties; private BlockState blockState; - private SerializedBlockState(ResourceLocation resourceLocation, Map properties) { - this.resourceLocation = resourceLocation; + private SerializedBlockState(Identifier identifier, Map properties) { + this.identifier = identifier; this.properties = properties; } private BlockState deserialize() { if (this.blockState == null) { - Block block = BuiltInRegistries.BLOCK.get(this.resourceLocation) + Block block = BuiltInRegistries.BLOCK.get(this.identifier) .map(Holder.Reference::value) .orElse(Blocks.AIR); this.blockState = block.defaultBlockState(); @@ -134,7 +134,7 @@ private static SerializedBlockState getFromString(String s) { String location = m.group("location"); String properties = m.group("properties"); - ResourceLocation resourceLocation = ResourceLocation.parse(location); + Identifier identifier = Identifier.parse(location); Map propertiesMap = new HashMap<>(); if (properties != null) { for (String property : properties.split(",")) { @@ -143,7 +143,7 @@ private static SerializedBlockState getFromString(String s) { } } - return new SerializedBlockState(resourceLocation, propertiesMap); + return new SerializedBlockState(identifier, propertiesMap); } catch (Exception e) { e.printStackTrace(); return null;