diff --git a/build.gradle b/build.gradle index 3f0891d..9444521 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.6-SNAPSHOT' + id 'fabric-loom' version '1.8-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 2a86932..d48164e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,13 +4,13 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.1 -loader_version=0.16.5 +minecraft_version=1.21.2-pre3 +loader_version=0.16.7 # Mod Properties -mod_version=1.8.0 +mod_version=1.9.0-beta1 maven_group=io.github.misode archives_base_name=packtest # Dependencies -fabric_version=0.105.0+1.21.1 +fabric_version=0.105.4+1.21.2 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23..9355b41 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 1aa94a4..f5feea6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -84,7 +86,8 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/gradlew.bat b/gradlew.bat index 7101f8e..9b42019 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## diff --git a/src/main/java/io/github/misode/packtest/PackTestFunction.java b/src/main/java/io/github/misode/packtest/PackTestFunction.java index f8f1e5c..bb09b33 100644 --- a/src/main/java/io/github/misode/packtest/PackTestFunction.java +++ b/src/main/java/io/github/misode/packtest/PackTestFunction.java @@ -138,7 +138,7 @@ public TestFunction toTestFunction(int permissionLevel) { private Consumer createTestBody(int permissionLevel) { return (helper) -> { CommandSourceStack source = helper.getLevel().getServer().createCommandSourceStack() - .withPosition(helper.absoluteVec(Vec3.ZERO).add(0, 1, 0)) + .withPosition(helper.absoluteVec(Vec3.ZERO)) .withPermission(permissionLevel) .withSuppressedOutput(); ((PackTestSourceStack) source).packtest$setHelper(helper); diff --git a/src/main/java/io/github/misode/packtest/PackTestLibrary.java b/src/main/java/io/github/misode/packtest/PackTestLibrary.java index 34223f6..666d293 100644 --- a/src/main/java/io/github/misode/packtest/PackTestLibrary.java +++ b/src/main/java/io/github/misode/packtest/PackTestLibrary.java @@ -10,7 +10,6 @@ import net.minecraft.server.packs.resources.PreparableReloadListener; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.util.profiling.ProfilerFiller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,7 +49,7 @@ public void setDispatcher(CommandDispatcher dispatcher) { } @Override - public @NotNull CompletableFuture reload(PreparableReloadListener.PreparationBarrier barrier, ResourceManager resources, ProfilerFiller profiler1, ProfilerFiller profiler2, Executor executor1, Executor executor2) { + public @NotNull CompletableFuture reload(PreparableReloadListener.PreparationBarrier barrier, ResourceManager resources, Executor executor1, Executor executor2) { CompletableFuture>> prep = CompletableFuture.supplyAsync( () -> LISTER.listMatchingResources(resources), executor1 ).thenComposeAsync(map -> { diff --git a/src/main/java/io/github/misode/packtest/commands/DummyCommand.java b/src/main/java/io/github/misode/packtest/commands/DummyCommand.java index 9cceb51..2ca75cf 100644 --- a/src/main/java/io/github/misode/packtest/commands/DummyCommand.java +++ b/src/main/java/io/github/misode/packtest/commands/DummyCommand.java @@ -250,7 +250,7 @@ private static int useBlock(CommandContext ctx, Direction hi BlockHitResult blockHit = new BlockHitResult(pos, hitDirection, BlockPos.containing(pos), false); InteractionResult result = dummy.gameMode.useItemOn(dummy, dummy.serverLevel(), handItem, hand, blockHit); if (result.consumesAction()) { - if (result.shouldSwing()) dummy.swing(hand); + dummy.swing(hand); return 1; } } diff --git a/src/main/java/io/github/misode/packtest/dummy/Dummy.java b/src/main/java/io/github/misode/packtest/dummy/Dummy.java index 36b3a6e..6ecc42c 100644 --- a/src/main/java/io/github/misode/packtest/dummy/Dummy.java +++ b/src/main/java/io/github/misode/packtest/dummy/Dummy.java @@ -6,8 +6,8 @@ import net.minecraft.network.DisconnectionDetails; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.PacketFlow; +import net.minecraft.network.protocol.game.ClientboundEntityPositionSyncPacket; import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; import net.minecraft.network.protocol.game.ServerboundClientCommandPacket; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; @@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; +import java.util.Set; /** * Heavily inspired by Carpet @@ -68,12 +69,12 @@ public static Dummy create(String username, MinecraftServer server, ResourceKey< new DummyClientConnection(PacketFlow.SERVERBOUND), dummy, new CommonListenerCookie(profile, 0, dummy.clientInformation(), false)); - dummy.teleportTo(level, originalSpawn.x, originalSpawn.y, originalSpawn.z, 0, 0); + dummy.teleportTo(level, originalSpawn.x, originalSpawn.y, originalSpawn.z, Set.of(), 0, 0, true); dummy.setHealth(20); dummy.unsetRemoved(); dummy.gameMode.changeGameModeForPlayer(GameType.SURVIVAL); server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(dummy, (byte) (dummy.yHeadRot * 256 / 360)), dimensionId); - server.getPlayerList().broadcastAll(new ClientboundTeleportEntityPacket(dummy), dimensionId); + server.getPlayerList().broadcastAll(ClientboundEntityPositionSyncPacket.of(dummy), dimensionId); dummy.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); return dummy; } @@ -96,6 +97,7 @@ public void respawn() { server.getPlayerList().respawn(this, false, Entity.RemovalReason.KILLED); } + @SuppressWarnings("resource") @Override public void tick() { if (Objects.requireNonNull(this.getServer()).getTickCount() % 10 == 0) { @@ -108,11 +110,12 @@ public void tick() { } catch (NullPointerException ignored) {} } + @SuppressWarnings("resource") @Override public void die(DamageSource cause) { super.die(cause); if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN)) { - this.server.tell(new TickTask(this.server.getTickCount(), + this.server.schedule(new TickTask(this.server.getTickCount(), () -> this.connection.handleClientCommand(new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN)) )); } diff --git a/src/main/java/io/github/misode/packtest/mixin/LootDataTypeMixin.java b/src/main/java/io/github/misode/packtest/mixin/LootDataTypeMixin.java deleted file mode 100644 index de25063..0000000 --- a/src/main/java/io/github/misode/packtest/mixin/LootDataTypeMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.misode.packtest.mixin; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import io.github.misode.packtest.LoadDiagnostics; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.storage.loot.LootDataType; -import org.slf4j.Logger; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; - -/** - * Catches loot table, predicate and item modifier errors. - * Improves error message. - */ -@Mixin(LootDataType.class) -public class LootDataTypeMixin { - @Shadow - @Final - private static Logger LOGGER; - - @WrapOperation(method = "method_53267", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;[Ljava/lang/Object;)V", remap = false)) - private void deserialize(Logger logger, String message, Object[] args, Operation original) { - String type = ((ResourceLocation)args[0]).getPath().replaceAll("_", " ").replaceFirst("s$", ""); - LoadDiagnostics.error(LOGGER, type, ((ResourceLocation)args[1]).toString(), (String)args[2]); - } -} diff --git a/src/main/java/io/github/misode/packtest/mixin/PlayerListMixin.java b/src/main/java/io/github/misode/packtest/mixin/PlayerListMixin.java index 52b3f81..f66944f 100644 --- a/src/main/java/io/github/misode/packtest/mixin/PlayerListMixin.java +++ b/src/main/java/io/github/misode/packtest/mixin/PlayerListMixin.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Optional; +import java.util.Set; /** * Fixes starting position of dummies when they load in. @@ -55,7 +56,7 @@ private void skipSaveDummy(ServerPlayer player, CallbackInfo ci) { } @WrapOperation(method = "getPlayerAdvancements", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object getPlayerAdvancements(Map map, Object key, Operation original, @Local(ordinal = 0) ServerPlayer player) { + private Object getPlayerAdvancements(Map map, Object key, Operation original, @Local(ordinal = 0, argsOnly = true) ServerPlayer player) { if (player instanceof Dummy) { return null; } else { @@ -64,7 +65,7 @@ private Object getPlayerAdvancements(Map map, Object key, Operat } @WrapOperation(method = "respawn", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/level/ServerLevel;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/server/level/ClientInformation;)Lnet/minecraft/server/level/ServerPlayer;")) - private ServerPlayer createDummy(MinecraftServer server, ServerLevel level, GameProfile profile, ClientInformation cli, Operation original, @Local(ordinal = 0) ServerPlayer player) { + private ServerPlayer createDummy(MinecraftServer server, ServerLevel level, GameProfile profile, ClientInformation cli, Operation original, @Local(ordinal = 0, argsOnly = true) ServerPlayer player) { if (player instanceof Dummy dummy) { return new Dummy(server, level, profile, cli, dummy.originalSpawn); } else { @@ -77,7 +78,7 @@ private void teleportDummy(ServerPlayer serverPlayer, boolean bl, Entity.Removal if (player instanceof Dummy dummy) { Vec3 pos = dummy.originalSpawn; dummy.moveTo(pos.x, pos.y, pos.z, 0, 0); - dummy.teleportTo(dummy.serverLevel(), pos.x, pos.y, pos.z, 0, 0); + dummy.teleportTo(dummy.serverLevel(), pos.x, pos.y, pos.z, Set.of(), 0, 0, true); } } } diff --git a/src/main/java/io/github/misode/packtest/mixin/RecipeManagerMixin.java b/src/main/java/io/github/misode/packtest/mixin/RecipeManagerMixin.java deleted file mode 100644 index 34e1f21..0000000 --- a/src/main/java/io/github/misode/packtest/mixin/RecipeManagerMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.misode.packtest.mixin; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import io.github.misode.packtest.LoadDiagnostics; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.crafting.RecipeManager; -import org.slf4j.Logger; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; - -/** - * Catch recipe errors and removes stacktrace. - */ -@Mixin(RecipeManager.class) -public class RecipeManagerMixin { - @Shadow - @Final - private static Logger LOGGER; - - @WrapOperation(method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", remap = false)) - private void apply(Logger logger, String message, Object id, Object e, Operation original) { - String error = ((Exception)e).getMessage(); - LoadDiagnostics.error(LOGGER, "recipe", ((ResourceLocation)id).toString(), error); - } -} diff --git a/src/main/java/io/github/misode/packtest/mixin/ReloadableServerResourcesMixin.java b/src/main/java/io/github/misode/packtest/mixin/ReloadableServerResourcesMixin.java index 7bfc5b7..7cda263 100644 --- a/src/main/java/io/github/misode/packtest/mixin/ReloadableServerResourcesMixin.java +++ b/src/main/java/io/github/misode/packtest/mixin/ReloadableServerResourcesMixin.java @@ -3,7 +3,10 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import io.github.misode.packtest.PackTestLibrary; import net.minecraft.commands.Commands; -import net.minecraft.core.RegistryAccess; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.LayeredRegistryAccess; +import net.minecraft.core.Registry; +import net.minecraft.server.RegistryLayer; import net.minecraft.server.ReloadableServerResources; import net.minecraft.server.packs.resources.PreparableReloadListener; import net.minecraft.world.flag.FeatureFlagSet; @@ -28,7 +31,7 @@ public class ReloadableServerResourcesMixin { private Commands commands; @Inject(method = "", at = @At("RETURN")) - private void init(RegistryAccess.Frozen frozen, FeatureFlagSet featureFlagSet, Commands.CommandSelection commandSelection, int permissionLevel, CallbackInfo ci) { + private void init(LayeredRegistryAccess layeredRegistryAccess, HolderLookup.Provider provider, FeatureFlagSet featureFlagSet, Commands.CommandSelection commandSelection, List> list, int permissionLevel, CallbackInfo ci) { PackTestLibrary.INSTANCE.setPermissionLevel(permissionLevel); PackTestLibrary.INSTANCE.setDispatcher(commands.getDispatcher()); } diff --git a/src/main/java/io/github/misode/packtest/mixin/ReportGameListenerMixin.java b/src/main/java/io/github/misode/packtest/mixin/ReportGameListenerMixin.java index 963f461..7868a89 100644 --- a/src/main/java/io/github/misode/packtest/mixin/ReportGameListenerMixin.java +++ b/src/main/java/io/github/misode/packtest/mixin/ReportGameListenerMixin.java @@ -14,7 +14,7 @@ public class ReportGameListenerMixin { @ModifyArg(method = "visualizeFailedTest", at = @At(value = "INVOKE", target = "Lnet/minecraft/gametest/framework/ReportGameListener;say(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/ChatFormatting;Ljava/lang/String;)V"), index = 2) - private static String visualizeFailedTest(String message, @Local(ordinal = 0) Throwable error) { + private static String visualizeFailedTest(String message, @Local(ordinal = 0, argsOnly = true) Throwable error) { if (error instanceof LineNumberException e) { return message.replaceFirst(" failed!", " failed on line " + e.getLineNumber() + "!"); } else { diff --git a/src/main/java/io/github/misode/packtest/mixin/ServerAdvancementsManagerMixin.java b/src/main/java/io/github/misode/packtest/mixin/ServerAdvancementsManagerMixin.java deleted file mode 100644 index a07e29e..0000000 --- a/src/main/java/io/github/misode/packtest/mixin/ServerAdvancementsManagerMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.github.misode.packtest.mixin; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import io.github.misode.packtest.LoadDiagnostics; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.ServerAdvancementManager; -import org.slf4j.Logger; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; - -/** - * Catch advancement errors. - */ -@Mixin(ServerAdvancementManager.class) -public class ServerAdvancementsManagerMixin { - @Shadow - @Final - private static Logger LOGGER; - - @WrapOperation(method = "method_20723", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", remap = false)) - private void apply(Logger logger, String message, Object id, Object error, Operation original) { - LoadDiagnostics.error(LOGGER, "advancement", ((ResourceLocation)id).toString(), (String)error); - } -} diff --git a/src/main/java/io/github/misode/packtest/mixin/SimpleJsonResourceReloadListenerMixin.java b/src/main/java/io/github/misode/packtest/mixin/SimpleJsonResourceReloadListenerMixin.java index f60a1dc..44f6114 100644 --- a/src/main/java/io/github/misode/packtest/mixin/SimpleJsonResourceReloadListenerMixin.java +++ b/src/main/java/io/github/misode/packtest/mixin/SimpleJsonResourceReloadListenerMixin.java @@ -2,6 +2,8 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.serialization.DataResult; import io.github.misode.packtest.LoadDiagnostics; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; @@ -11,17 +13,26 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +/** + * Catches loot table, predicate, item modifier, advancement, and recipe errors. + * Improves error message. + */ @Mixin(SimpleJsonResourceReloadListener.class) public class SimpleJsonResourceReloadListenerMixin { @Shadow @Final private static Logger LOGGER; + @WrapOperation(method = "method_63567", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;[Ljava/lang/Object;)V", remap = false)) + private static void resourceParseError(Logger logger, String message, Object[] args, Operation original) { + String resourcePath = ((ResourceLocation)args[1]).getPath(); + String type = resourcePath.substring(0, resourcePath.indexOf('/')).replace("_", " ").replace("/", " "); + LoadDiagnostics.error(LOGGER, type, ((ResourceLocation)args[0]).toString(), ((DataResult.Error)args[2]).message()); + } + @WrapOperation(method = "scanDirectory", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;[Ljava/lang/Object;)V", remap = false)) - private static void catchTagReferenceError(Logger logger, String message, Object[] args, Operation original) { - String path = ((ResourceLocation)args[1]).getPath(); - String type = path.substring(0, path.indexOf("/")).replaceAll("_", " ").replaceFirst("s$", ""); - String error = ((Exception)args[2]).getMessage().replaceFirst("^[A-Za-z0-9.]+Exception: ", ""); - LoadDiagnostics.error(LOGGER, type, ((ResourceLocation)args[0]).toString(), error); + private static void resourceException(Logger logger, String message, Object[] args, Operation original, @Local(ordinal = 0, argsOnly = true) String directory) { + String type = directory.replace("_", " ").replace("/", " "); + LoadDiagnostics.error(LOGGER, type, ((ResourceLocation)args[0]).toString(), (args[2]).toString()); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f80aea4..2d83224 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -24,7 +24,7 @@ "accessWidener": "packtest.accesswidener", "depends": { "fabricloader": ">=0.15.10", - "minecraft": ">=1.21.1", + "minecraft": ">=1.21.2-beta.3", "java": ">=21", "fabric-api": "*" } diff --git a/src/main/resources/packtest.mixins.json b/src/main/resources/packtest.mixins.json index 6e1963d..80beba5 100644 --- a/src/main/resources/packtest.mixins.json +++ b/src/main/resources/packtest.mixins.json @@ -22,13 +22,10 @@ "GameTestServerMixin", "ItemPredicateArgumentMixin", "LogTestReporterMixin", - "LootDataTypeMixin", "MinecraftServerMixin", "PlayerListMixin", - "RecipeManagerMixin", "ReloadableServerResourcesMixin", "ReportGameListenerMixin", - "ServerAdvancementsManagerMixin", "ServerFunctionLibraryMixin", "ServerPlayerMixin", "SimpleJsonResourceReloadListenerMixin",