diff --git a/.github/workflows/gradle_build.yml b/.github/workflows/gradle_build.yml index 56c11e193..d16242f2f 100644 --- a/.github/workflows/gradle_build.yml +++ b/.github/workflows/gradle_build.yml @@ -17,10 +17,10 @@ jobs: with: fetch-depth: 0 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' cache: gradle diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 04b26b422..bba23333a 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -12,10 +12,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Grant execute permission for gradlew diff --git a/build.gradle b/build.gradle index 52c8ec0cc..d802ac566 100755 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,13 @@ allprojects { } group = rootProject.maven_group - sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21 + + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(21)) + } + } repositories { maven { @@ -72,8 +78,8 @@ allprojects { } dependencies { - implementation "org.spongepowered:mixin:0.8.5" - implementation "org.ow2.asm:asm:9.3" + compileOnly "org.spongepowered:mixin:0.8" + compileOnly "org.ow2.asm:asm:9.7" // The following line declares the yarn mappings you may select this one as well. // mappings "net.fabricmc:yarn:1.17.1+build.32:v2" //launchImplementation('dev.babbaj:nether-pathfinder:1.3.0') @@ -88,7 +94,9 @@ allprojects { mappings { intermediary() mojmap() - parchment("1.20.2", "2023.10.22") + parchment("1.20.6", "2024.05.01") + + devFallbackNamespace "official" } } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index a58fe6089..b613c5d6b 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -40,5 +40,5 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0' implementation group: 'commons-io', name: 'commons-io', version: '2.7' - implementation group: 'xyz.wagyourtail.unimined', name: 'xyz.wagyourtail.unimined.gradle.plugin', version: '1.1.0' + implementation group: 'xyz.wagyourtail.unimined', name: 'xyz.wagyourtail.unimined.gradle.plugin', version: '1.2.3' } \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle index e0d5d8442..bf3e6c38d 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -78,8 +78,8 @@ components.java { } task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' + url 'https://github.com/Guardsquare/proguard/releases/download/v7.4.2/proguard-7.4.2.zip' + extract 'proguard-7.4.2/lib/proguard.jar' compType "fabric" } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index c1512a6cc..52a233052 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.3", "1.20.4"] + "minecraft": ["1.20.5", "1.20.6"] } } diff --git a/forge/build.gradle b/forge/build.gradle index 334bd968c..46c941a62 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -25,11 +25,7 @@ plugins { archivesBaseName = archivesBaseName + "-forge" unimined.minecraft { - mappings { - devFallbackNamespace "intermediary" - } - - forge { + minecraftForge { loader project.forge_version mixinConfig ["mixins.baritone.json"] } @@ -99,8 +95,8 @@ components.java { } task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' + url 'https://github.com/Guardsquare/proguard/releases/download/v7.4.2/proguard-7.4.2.zip' + extract 'proguard-7.4.2/lib/proguard.jar' compType "forge" } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index dd309314c..8103cfdcf 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.3, 1.20.4]" +versionRange="[1.20.5, 1.20.6]" ordering="NONE" side="BOTH" diff --git a/gradle.properties b/gradle.properties index 18a9f77e0..e25c8b569 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,12 @@ mod_version=1.10.2 maven_group=baritone archives_base_name=baritone -minecraft_version=1.20.4 +minecraft_version=1.20.6 -forge_version=49.0.3 -neoforge_version=0-beta +forge_version=50.0.8 -fabric_version=0.14.22 +neoforge_version=43-beta + +fabric_version=0.15.11 nether_pathfinder_version=1.4.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15de90249..48c0a02ca 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/neoforge/build.gradle b/neoforge/build.gradle index c60cc81be..c6c3d5c5c 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -25,9 +25,6 @@ plugins { archivesBaseName = archivesBaseName + "-neoforge" unimined.minecraft { - mappings { - devFallbackNamespace "intermediary" - } neoForged { loader project.neoforge_version @@ -108,8 +105,8 @@ components.java { } task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' + url 'https://github.com/Guardsquare/proguard/releases/download/v7.4.2/proguard-7.4.2.zip' + extract 'proguard-7.4.2/lib/proguard.jar' compType "neoforge" } diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml similarity index 92% rename from neoforge/src/main/resources/META-INF/mods.toml rename to neoforge/src/main/resources/META-INF/neoforge.mods.toml index 4ad41a286..307e5ca1a 100644 --- a/neoforge/src/main/resources/META-INF/mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -1,4 +1,4 @@ -# This is an example mods.toml file. It contains the data relating to the loading mods. +# This is an example neoforge.mods.toml file. It contains the data relating to the loading mods. # There are several mandatory fields (#mandatory), and many more that are optional (#optional). # The overall format is standard TOML format, v0.5.0. # Note that there are a couple of TOML lists in this file. @@ -33,8 +33,8 @@ A Minecraft pathfinder bot. [[dependencies.baritoe]] modId="minecraft" -mandatory=true +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.3, 1.20.4]" +versionRange="[1.20.5, 1.20.6]" ordering="NONE" side="BOTH" diff --git a/src/api/java/baritone/api/utils/BlockOptionalMeta.java b/src/api/java/baritone/api/utils/BlockOptionalMeta.java index ac14d0187..bca2875c3 100644 --- a/src/api/java/baritone/api/utils/BlockOptionalMeta.java +++ b/src/api/java/baritone/api/utils/BlockOptionalMeta.java @@ -18,28 +18,38 @@ package baritone.api.utils; import baritone.api.utils.accessor.IItemStack; +import baritone.api.utils.accessor.ILootTable; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import io.netty.util.concurrent.ThreadPerTaskExecutor; +import net.minecraft.Util; import net.minecraft.client.Minecraft; -import net.minecraft.core.BlockPos; +import net.minecraft.commands.Commands; +import net.minecraft.core.LayeredRegistryAccess; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.RegistryDataLoader; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.RegistryLayer; +import net.minecraft.server.ReloadableServerRegistries; +import net.minecraft.server.ReloadableServerResources; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.progress.ChunkProgressListener; import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.VanillaPackResources; +import net.minecraft.server.packs.repository.PackRepository; import net.minecraft.server.packs.repository.ServerPacksSource; +import net.minecraft.server.packs.resources.CloseableResourceManager; import net.minecraft.server.packs.resources.MultiPackResourceManager; -import net.minecraft.server.packs.resources.ReloadableResourceManager; -import net.minecraft.util.Unit; +import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.world.RandomSequences; import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.CustomSpawner; import net.minecraft.world.level.Level; +import net.minecraft.world.level.WorldDataConfiguration; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Property; @@ -48,8 +58,8 @@ import net.minecraft.world.level.storage.ServerLevelData; import net.minecraft.world.level.storage.loot.BuiltInLootTables; import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.LootDataManager; import net.minecraft.world.level.storage.loot.LootParams; +import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.Vec3; @@ -75,7 +85,6 @@ public final class BlockOptionalMeta { private final Set blockstates; private final ImmutableSet stateHashes; private final ImmutableSet stackHashes; - private static LootDataManager lootTables; private static Map> drops = new HashMap<>(); public BlockOptionalMeta(@Nonnull Block block) { @@ -218,43 +227,21 @@ private static VanillaPackResources getVanillaServerPack() { return null; } - public static LootDataManager getManager() { - if (lootTables == null) { - MultiPackResourceManager resources = new MultiPackResourceManager(PackType.SERVER_DATA, List.of(getVanillaServerPack())); - ReloadableResourceManager resourceManager = new ReloadableResourceManager(PackType.SERVER_DATA); - lootTables = new LootDataManager(); - resourceManager.registerReloadListener(lootTables); - try { - resourceManager.createReload(new ThreadPerTaskExecutor(Thread::new), new ThreadPerTaskExecutor(Thread::new), CompletableFuture.completedFuture(Unit.INSTANCE), resources.listPacks().toList()).done().get(); - } catch (Exception exception) { - throw new RuntimeException(exception); - } - - } - return lootTables; - } - private static synchronized List drops(Block b) { return drops.computeIfAbsent(b, block -> { - ResourceLocation lootTableLocation = block.getLootTable(); - if (lootTableLocation == BuiltInLootTables.EMPTY) { + ResourceLocation lootTableLocation = block.getLootTable().location(); + if (lootTableLocation.equals(BuiltInLootTables.EMPTY.location())) { return Collections.emptyList(); } else { List items = new ArrayList<>(); try { + ServerLevel lv2 = ServerLevelStub.fastCreate(); - getManager().getLootTable(lootTableLocation).getRandomItemsRaw( - new LootContext.Builder( - new LootParams.Builder(ServerLevelStub.fastCreate()) - .withParameter(LootContextParams.ORIGIN, Vec3.atLowerCornerOf(BlockPos.ZERO)) - .withParameter(LootContextParams.TOOL, ItemStack.EMPTY) - .withOptionalParameter(LootContextParams.BLOCK_ENTITY, null) - .withParameter(LootContextParams.BLOCK_STATE, block.defaultBlockState()) - .create(LootContextParamSets.BLOCK) - ).withOptionalRandomSeed(1L) - .create(null), - stack -> items.add(stack.getItem()) - ); + LootParams.Builder lv5 = new LootParams.Builder(lv2) + .withParameter(LootContextParams.ORIGIN, Vec3.ZERO) + .withParameter(LootContextParams.BLOCK_STATE, b.defaultBlockState()) + .withParameter(LootContextParams.TOOL, new ItemStack(Items.NETHERITE_PICKAXE, 1)); + getDrops(block, lv5).stream().map(ItemStack::getItem).forEach(items::add); } catch (Exception e) { e.printStackTrace(); } @@ -263,9 +250,22 @@ private static synchronized List drops(Block b) { }); } - private static class ServerLevelStub extends ServerLevel { + private static List getDrops(Block state, LootParams.Builder params) { + ResourceKey lv = state.getLootTable(); + if (lv == BuiltInLootTables.EMPTY) { + return Collections.emptyList(); + } else { + LootParams lv2 = params.withParameter(LootContextParams.BLOCK_STATE, state.defaultBlockState()).create(LootContextParamSets.BLOCK); + ServerLevelStub lv3 = (ServerLevelStub) lv2.getLevel(); + LootTable lv4 = lv3.holder().getLootTable(lv); + return((ILootTable) lv4).invokeGetRandomItems(new LootContext.Builder(lv2).withOptionalRandomSeed(1).create(null)); + } + } + + public static class ServerLevelStub extends ServerLevel { private static Minecraft client = Minecraft.getInstance(); private static Unsafe unsafe = getUnsafe(); + private static CompletableFuture registryAccess = load(); public ServerLevelStub(MinecraftServer $$0, Executor $$1, LevelStorageSource.LevelStorageAccess $$2, ServerLevelData $$3, ResourceKey $$4, LevelStem $$5, ChunkProgressListener $$6, boolean $$7, long $$8, List $$9, boolean $$10, @Nullable RandomSequences $$11) { super($$0, $$1, $$2, $$3, $$4, $$5, $$6, $$7, $$8, $$9, $$10, $$11); @@ -285,6 +285,15 @@ public static ServerLevelStub fastCreate() { } } + @Override + public RegistryAccess registryAccess() { + return registryAccess.join(); + } + + public ReloadableServerRegistries.Holder holder() { + return new ReloadableServerRegistries.Holder(registryAccess().freeze()); + } + public static Unsafe getUnsafe() { try { Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); @@ -295,5 +304,42 @@ public static Unsafe getUnsafe() { } } + public static CompletableFuture load() { + PackRepository packRepository = Minecraft.getInstance().getResourcePackRepository(); + CloseableResourceManager closeableResourceManager = new MultiPackResourceManager(PackType.SERVER_DATA, packRepository.openAllSelected()); + LayeredRegistryAccess layeredRegistryAccess = loadAndReplaceLayer( + closeableResourceManager, RegistryLayer.createRegistryAccess(), RegistryLayer.WORLDGEN, RegistryDataLoader.WORLDGEN_REGISTRIES + ); + return ReloadableServerResources.loadResources( + closeableResourceManager, + layeredRegistryAccess, + WorldDataConfiguration.DEFAULT.enabledFeatures(), + Commands.CommandSelection.INTEGRATED, + 2, + Runnable::run, + Minecraft.getInstance() + ).thenApply(reloadableServerResources -> reloadableServerResources.fullRegistries().get()); + } + + private static LayeredRegistryAccess loadAndReplaceLayer( + ResourceManager resourceManager, + LayeredRegistryAccess registryAccess, + RegistryLayer registryLayer, + List> registryData + ) { + RegistryAccess.Frozen frozen = loadLayer(resourceManager, registryAccess, registryLayer, registryData); + return registryAccess.replaceFrom(registryLayer, frozen); + } + + private static RegistryAccess.Frozen loadLayer( + ResourceManager resourceManager, + LayeredRegistryAccess registryAccess, + RegistryLayer registryLayer, + List> registryData + ) { + RegistryAccess.Frozen frozen = registryAccess.getAccessForLoading(registryLayer); + return RegistryDataLoader.load(resourceManager, frozen, registryData); + } + } } diff --git a/src/api/java/baritone/api/utils/accessor/ILootTable.java b/src/api/java/baritone/api/utils/accessor/ILootTable.java new file mode 100644 index 000000000..c032fc6cd --- /dev/null +++ b/src/api/java/baritone/api/utils/accessor/ILootTable.java @@ -0,0 +1,28 @@ +/* + * 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.api.utils.accessor; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.LootContext; + +public interface ILootTable { + + ObjectArrayList invokeGetRandomItems(LootContext context); + +} diff --git a/src/launch/java/baritone/launch/mixins/MixinLootContext.java b/src/launch/java/baritone/launch/mixins/MixinLootContextBuilder.java similarity index 54% rename from src/launch/java/baritone/launch/mixins/MixinLootContext.java rename to src/launch/java/baritone/launch/mixins/MixinLootContextBuilder.java index 223444e12..707a4c317 100644 --- a/src/launch/java/baritone/launch/mixins/MixinLootContext.java +++ b/src/launch/java/baritone/launch/mixins/MixinLootContextBuilder.java @@ -19,41 +19,28 @@ import baritone.api.utils.BlockOptionalMeta; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ReloadableServerRegistries; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.LootDataManager; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(LootContext.Builder.class) -public class MixinLootContext { +public abstract class MixinLootContextBuilder { - @Redirect( - method = "create", - at = @At( - value = "INVOKE", - target = "net/minecraft/server/level/ServerLevel.getServer()Lnet/minecraft/server/MinecraftServer;" - ) - ) - private MinecraftServer getServer(ServerLevel world) { - if (world == null) { - return null; - } - return world.getServer(); - } + @Shadow public abstract ServerLevel getLevel(); - @Redirect( - method = "create", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/server/MinecraftServer;getLootData()Lnet/minecraft/world/level/storage/loot/LootDataManager;" - ) - ) - private LootDataManager getLootTableManager(MinecraftServer server) { - if (server == null) { - return BlockOptionalMeta.getManager(); + @Redirect(method = "create", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;reloadableRegistries()Lnet/minecraft/server/ReloadableServerRegistries$Holder;")) + private ReloadableServerRegistries.Holder create(MinecraftServer instance) { + if (instance != null) { + return instance.reloadableRegistries(); } - return server.getLootData(); + if (getLevel() instanceof BlockOptionalMeta.ServerLevelStub sls) { + return sls.holder(); + } + return null; } + } diff --git a/src/launch/java/baritone/launch/mixins/MixinLootTable.java b/src/launch/java/baritone/launch/mixins/MixinLootTable.java new file mode 100644 index 000000000..f3f2e3600 --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinLootTable.java @@ -0,0 +1,34 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.launch.mixins; + +import baritone.api.utils.accessor.ILootTable; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.LootTable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(LootTable.class) +public abstract class MixinLootTable implements ILootTable { + + @Invoker + public abstract ObjectArrayList invokeGetRandomItems(LootContext context); + +} diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index e615a822a..de78501ef 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -24,6 +24,7 @@ import baritone.api.event.events.WorldEvent; import baritone.api.event.events.type.EventState; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.ReceivingLevelScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; @@ -130,7 +131,7 @@ private void postUpdateEntities(CallbackInfo ci) { method = "setLevel", at = @At("HEAD") ) - private void preLoadWorld(ClientLevel world, CallbackInfo ci) { + private void preLoadWorld(ClientLevel world, ReceivingLevelScreen.Reason arg2, CallbackInfo ci) { // If we're unloading the world but one doesn't exist, ignore it if (this.level == null && world == null) { return; @@ -150,7 +151,7 @@ private void preLoadWorld(ClientLevel world, CallbackInfo ci) { method = "setLevel", at = @At("RETURN") ) - private void postLoadWorld(ClientLevel world, CallbackInfo ci) { + private void postLoadWorld(ClientLevel world, ReceivingLevelScreen.Reason arg2, CallbackInfo ci) { // still fire event for both null, as that means we've just finished exiting a world // mc.world changing is only the primary baritone diff --git a/src/launch/java/baritone/launch/mixins/MixinWorldRenderer.java b/src/launch/java/baritone/launch/mixins/MixinWorldRenderer.java index a6cf48899..1a1ae74e2 100644 --- a/src/launch/java/baritone/launch/mixins/MixinWorldRenderer.java +++ b/src/launch/java/baritone/launch/mixins/MixinWorldRenderer.java @@ -44,9 +44,11 @@ public class MixinWorldRenderer { at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILSOFT ) - private void onStartHand(PoseStack matrixStackIn, float partialTicks, long finishTimeNano, boolean drawBlockOutline, Camera activeRenderInfoIn, GameRenderer gameRendererIn, LightTexture lightmapIn, Matrix4f projectionIn, CallbackInfo ci) { + private void onStartHand(float f, long l, boolean bl, Camera arg, GameRenderer arg2, LightTexture arg3, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks, matrixStackIn, projectionIn)); + PoseStack poseStack = new PoseStack(); + poseStack.mulPose(matrix4f); + ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(f, poseStack, matrix4f2)); } } } \ No newline at end of file diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index 35d5ae0d6..9d526addc 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -18,7 +18,8 @@ "MixinFireworkRocketEntity", "MixinItemStack", "MixinLivingEntity", - "MixinLootContext", + "MixinLootContextBuilder", + "MixinLootTable", "MixinMinecraft", "MixinNetworkManager", "MixinPalettedContainer", @@ -26,5 +27,7 @@ "MixinPlayerController", "MixinScreen", "MixinWorldRenderer" + ], + "mixins": [ ] } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index f5c928cd4..16119bb07 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -177,15 +177,10 @@ static Ternary canWalkThroughBlockState(BlockState state) { if (block instanceof CauldronBlock) { return NO; } - try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information - if (state.isPathfindable(null, null, PathComputationType.LAND)) { - return YES; - } else { - return NO; - } - } catch (Throwable exception) { - System.out.println("The block " + state.getBlock().getName().getString() + " requires a special case due to the exception " + exception.getMessage()); - return MAYBE; + if (state.isPathfindable(PathComputationType.LAND)) { + return YES; + } else { + return NO; } } @@ -228,10 +223,7 @@ static boolean canWalkThroughPosition(BlockStateInterface bsi, int x, int y, int return fluidState.getType() instanceof WaterFluid; } - // every block that overrides isPassable with anything more complicated than a "return true;" or "return false;" - // has already been accounted for above - // therefore it's safe to not construct a blockpos from our x, y, z ints and instead just pass null - return state.isPathfindable(bsi.access, BlockPos.ZERO, PathComputationType.LAND); // workaround for future compatibility =P + return state.isPathfindable(PathComputationType.LAND); } static Ternary fullyPassableBlockState(BlockState state) { @@ -259,16 +251,10 @@ static Ternary fullyPassableBlockState(BlockState state) { } // door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters // at least in 1.12.2 vanilla, that is..... - try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information - if (state.isPathfindable(null, null, PathComputationType.LAND)) { - return YES; - } else { - return NO; - } - } catch (Throwable exception) { - // see PR #1087 for why - System.out.println("The block " + state.getBlock().getName().getString() + " requires a special case due to the exception " + exception.getMessage()); - return MAYBE; + if (state.isPathfindable(PathComputationType.LAND)) { + return YES; + } else { + return NO; } } @@ -293,11 +279,14 @@ static boolean fullyPassable(IPlayerContext ctx, BlockPos pos) { if (fullyPassable == NO) { return false; } - return fullyPassablePosition(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ(), state); // meh + return state.isPathfindable(PathComputationType.LAND); } + /** + * params retained for backwards compatibility + */ static boolean fullyPassablePosition(BlockStateInterface bsi, int x, int y, int z, BlockState state) { - return state.isPathfindable(bsi.access, bsi.isPassableBlockPos.set(x, y, z), PathComputationType.LAND); + return state.isPathfindable(PathComputationType.LAND); } static boolean isReplaceable(int x, int y, int z, BlockState state, BlockStateInterface bsi) { diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 3d0d0d4b7..301019275 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -1028,8 +1028,8 @@ private static boolean sameBlockstate(BlockState first, BlockState second) { if (!ignoreDirection && ignoredProps.isEmpty()) { return first.equals(second); // early return if no properties are being ignored } - ImmutableMap, Comparable> map1 = first.getValues(); - ImmutableMap, Comparable> map2 = second.getValues(); + Map, Comparable> map1 = first.getValues(); + Map, Comparable> map2 = second.getValues(); for (Property prop : map1.keySet()) { if (map1.get(prop) != map2.get(prop) && !(ignoreDirection && ORIENTATION_PROPS.contains(prop)) diff --git a/src/main/java/baritone/process/ElytraProcess.java b/src/main/java/baritone/process/ElytraProcess.java index fcd6c4b34..466969071 100644 --- a/src/main/java/baritone/process/ElytraProcess.java +++ b/src/main/java/baritone/process/ElytraProcess.java @@ -360,7 +360,7 @@ public void pathTo(Goal iGoal) { private boolean shouldLandForSafety() { ItemStack chest = ctx.player().getItemBySlot(EquipmentSlot.CHEST); - if (chest.getItem() != Items.ELYTRA || chest.getItem().getMaxDamage() - chest.getDamageValue() < Baritone.settings().elytraMinimumDurability.value) { + if (chest.getItem() != Items.ELYTRA || chest.getMaxDamage() - chest.getDamageValue() < Baritone.settings().elytraMinimumDurability.value) { // elytrabehavior replaces when durability <= minimumDurability, so if durability < minimumDurability then we can reasonably assume that the elytra will soon be broken without replacement return true; } diff --git a/src/main/java/baritone/process/elytra/ElytraBehavior.java b/src/main/java/baritone/process/elytra/ElytraBehavior.java index 8cdfd0e39..8ace420e9 100644 --- a/src/main/java/baritone/process/elytra/ElytraBehavior.java +++ b/src/main/java/baritone/process/elytra/ElytraBehavior.java @@ -35,6 +35,7 @@ import it.unimi.dsi.fastutil.floats.FloatIterator; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; import net.minecraft.util.Mth; @@ -44,6 +45,7 @@ import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.Fireworks; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.block.AirBlock; @@ -922,9 +924,8 @@ public static boolean isFireworks(final ItemStack itemStack) { if (itemStack.getItem() != Items.FIREWORK_ROCKET) { return false; } - // If it has NBT data, make sure it won't cause us to explode. - final CompoundTag compound = itemStack.getTagElement("Fireworks"); - return compound == null || !compound.getAllKeys().contains("Explosions"); + Fireworks fw = itemStack.get(DataComponents.FIREWORKS); + return fw != null && fw.explosions().isEmpty(); } private static boolean isBoostingFireworks(final ItemStack itemStack) { @@ -932,11 +933,9 @@ private static boolean isBoostingFireworks(final ItemStack itemStack) { } private static OptionalInt getFireworkBoost(final ItemStack itemStack) { - if (isFireworks(itemStack)) { - final CompoundTag compound = itemStack.getTagElement("Fireworks"); - if (compound != null && compound.getAllKeys().contains("Flight")) { - return OptionalInt.of(compound.getByte("Flight")); - } + Fireworks fw = itemStack.get(DataComponents.FIREWORKS); + if (fw != null && fw.explosions().isEmpty()) { + return OptionalInt.of(fw.flightDuration()); } return OptionalInt.empty(); } @@ -1292,7 +1291,7 @@ private int findGoodElytra() { NonNullList invy = ctx.player().getInventory().items; for (int i = 0; i < invy.size(); i++) { ItemStack slot = invy.get(i); - if (slot.getItem() == Items.ELYTRA && (slot.getItem().getMaxDamage() - slot.getDamageValue()) > Baritone.settings().elytraMinimumDurability.value) { + if (slot.getItem() == Items.ELYTRA && (slot.getMaxDamage() - slot.getDamageValue()) > Baritone.settings().elytraMinimumDurability.value) { return i; } } @@ -1306,7 +1305,7 @@ private void trySwapElytra() { ItemStack chest = ctx.player().getItemBySlot(EquipmentSlot.CHEST); if (chest.getItem() != Items.ELYTRA - || chest.getItem().getMaxDamage() - chest.getDamageValue() > Baritone.settings().elytraMinimumDurability.value) { + || chest.getMaxDamage() - chest.getDamageValue() > Baritone.settings().elytraMinimumDurability.value) { return; } diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 095694db9..9708f40bc 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -30,9 +30,9 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunkSection; +import net.minecraft.world.level.chunk.status.ChunkStatus; /** * Wraps get for chuck caching capability diff --git a/src/main/java/baritone/utils/IRenderer.java b/src/main/java/baritone/utils/IRenderer.java index 7f6065b72..86db4c87f 100644 --- a/src/main/java/baritone/utils/IRenderer.java +++ b/src/main/java/baritone/utils/IRenderer.java @@ -115,11 +115,10 @@ static void emitLine(PoseStack stack, float x1, float y1, float z1, float x2, float y2, float z2, float nx, float ny, float nz) { - final Matrix4f matrix4f = stack.last().pose(); - final Matrix3f normal = stack.last().normal(); + PoseStack.Pose pose = stack.last(); - buffer.vertex(matrix4f, x1, y1, z1).color(color[0], color[1], color[2], color[3]).normal(normal, nx, ny, nz).endVertex(); - buffer.vertex(matrix4f, x2, y2, z2).color(color[0], color[1], color[2], color[3]).normal(normal, nx, ny, nz).endVertex(); + 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(); } static void emitAABB(PoseStack stack, AABB aabb) { diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 38b1fafdd..ef83a2db1 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -86,7 +86,7 @@ public double getStrVsBlock(BlockState state) { private int getMaterialCost(ItemStack itemStack) { if (itemStack.getItem() instanceof TieredItem) { TieredItem tool = (TieredItem) itemStack.getItem(); - return tool.getTier().getLevel(); + return (int) tool.getTier().getAttackDamageBonus(); } else { return -1; } @@ -184,7 +184,7 @@ public static double calculateSpeedVsBlock(ItemStack item, BlockState state) { float speed = item.getDestroySpeed(state); if (speed > 1) { - int effLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY, item); + int effLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.EFFICIENCY, item); if (effLevel > 0 && !item.isEmpty()) { speed += effLevel * effLevel + 1; } diff --git a/tweaker/build.gradle b/tweaker/build.gradle index 9f053fb88..71a025ca8 100644 --- a/tweaker/build.gradle +++ b/tweaker/build.gradle @@ -94,8 +94,8 @@ jar { } task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' + url 'https://github.com/Guardsquare/proguard/releases/download/v7.4.2/proguard-7.4.2.zip' + extract 'proguard-7.4.2/lib/proguard.jar' } task createDist(type: CreateDistTask, dependsOn: proguard)