diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f4aeb9e..3b3795b 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -16,10 +16,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 21 + - name: Set up JDK 25 uses: actions/setup-java@v4 with: - java-version: 21 + java-version: 25 distribution: 'temurin' - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e876d69..57f7103 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,11 +11,11 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 21 + - name: Set up JDK 25 uses: actions/setup-java@v3 with: distribution: temurin - java-version: 21 + java-version: 25 - name: Make gradlew executable run: chmod +x ./gradlew diff --git a/build.gradle b/build.gradle index 85d7c5a..7105cbb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.14-SNAPSHOT' + id 'net.fabricmc.fabric-loom' version '1.15-SNAPSHOT' id 'maven-publish' } @@ -38,16 +38,15 @@ base { dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + implementation "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. - modImplementation include("eu.pb4:sgui:${project.sgui_version}") - modImplementation include("me.lucko:fabric-permissions-api:${project.permission_api_version}") + implementation include("eu.pb4:sgui:${project.sgui_version}") + implementation include("me.lucko:fabric-permissions-api:${project.permission_api_version}") // modImplementation "dev.emi:trinkets:${project.trinkets_version}" // modImplementation "com.github.apace100:apoli:${project.apoli_version}" @@ -74,8 +73,8 @@ tasks.withType(JavaCompile) { } java { - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 } jar { diff --git a/gradle.properties b/gradle.properties index a3a4331..ed0325a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,17 +2,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop/ -minecraft_version=1.21.11 -yarn_mappings=1.21.11+build.3 -loader_version=0.18.3 +minecraft_version=26.1 +loader_version=0.18.5 # Mod Properties -mod_version=1.4.19 +mod_version=1.4.20 maven_group=us.potatoboy archives_base_name=InvView # Dependencies # check this on https://fabricmc.net/develop/ -fabric_version=0.140.0+1.21.11 +fabric_version=0.144.3+26.1 # trinkets_version=3.10.0 # apoli_version=2.12.0 -sgui_version=1.11.0+1.21.9 -permission_api_version=0.6.1 +sgui_version=2.0.0+26.1 +permission_api_version=0.7.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 8bdaf60..f8e1ee3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 23449a2..c61a118 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-9.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/us/potatoboy/invview/InvView.java b/src/main/java/us/potatoboy/invview/InvView.java index 21f5425..a5ee235 100644 --- a/src/main/java/us/potatoboy/invview/InvView.java +++ b/src/main/java/us/potatoboy/invview/InvView.java @@ -8,18 +8,17 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.nbt.NbtCompound; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.storage.NbtWriteView; -import net.minecraft.util.ErrorReporter; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.ProblemReporter; import net.minecraft.util.Util; -import net.minecraft.util.WorldSavePath; - +import net.minecraft.world.level.storage.LevelResource; +import net.minecraft.world.level.storage.TagValueOutput; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; @@ -38,22 +37,22 @@ public void onInitialize() { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - LiteralCommandNode viewNode = CommandManager + LiteralCommandNode viewNode = Commands .literal("view") .requires(Permissions.require("invview.command.root", 2)) .build(); - LiteralCommandNode invNode = CommandManager + LiteralCommandNode invNode = Commands .literal("inv") .requires(Permissions.require("invview.command.inv", 2)) - .then(CommandManager.argument("target", GameProfileArgumentType.gameProfile()) + .then(Commands.argument("target", GameProfileArgument.gameProfile()) .executes(ViewCommand::inv)) .build(); - LiteralCommandNode echestNode = CommandManager + LiteralCommandNode echestNode = Commands .literal("echest") .requires(Permissions.require("invview.command.echest", 2)) - .then(CommandManager.argument("target", GameProfileArgumentType.gameProfile()) + .then(Commands.argument("target", GameProfileArgument.gameProfile()) .executes(ViewCommand::eChest)) .build(); @@ -95,18 +94,18 @@ public static MinecraftServer getMinecraftServer() { } // Taken from net.minecraft.world.PlayerSaveHandler.savePlayerData(), which is a protected method - public static void savePlayerData(ServerPlayerEntity player) { - File playerDataDir = minecraftServer.getSavePath(WorldSavePath.PLAYERDATA).toFile(); - try (ErrorReporter.Logging logging = new ErrorReporter.Logging(player.getErrorReporterContext(), LogUtils.getLogger())) { - NbtWriteView nbtWriteView = NbtWriteView.create(logging, player.getRegistryManager()); - player.writeData(nbtWriteView); + public static void savePlayerData(ServerPlayer player) { + File playerDataDir = minecraftServer.getWorldPath(LevelResource.PLAYER_DATA_DIR).toFile(); + try (ProblemReporter.ScopedCollector logging = new ProblemReporter.ScopedCollector(player.problemPath(), LogUtils.getLogger())) { + TagValueOutput nbtWriteView = TagValueOutput.createWithContext(logging, player.registryAccess()); + player.saveWithoutId(nbtWriteView); Path path = playerDataDir.toPath(); - Path path2 = Files.createTempFile(path, player.getUuidAsString() + "-", ".dat"); - NbtCompound nbtCompound = nbtWriteView.getNbt(); + Path path2 = Files.createTempFile(path, player.getStringUUID() + "-", ".dat"); + CompoundTag nbtCompound = nbtWriteView.buildResult(); NbtIo.writeCompressed(nbtCompound, path2); - Path path3 = path.resolve(player.getUuidAsString() + ".dat"); - Path path4 = path.resolve(player.getUuidAsString() + ".dat_old"); - Util.backupAndReplace(path3, path2, path4); + Path path3 = path.resolve(player.getStringUUID() + ".dat"); + Path path4 = path.resolve(player.getStringUUID() + ".dat_old"); + Util.safeReplaceFile(path3, path2, path4); } catch (Exception var11) { LogUtils.getLogger().warn("Failed to save player data for {}", player.getName().getString()); } diff --git a/src/main/java/us/potatoboy/invview/ViewCommand.java b/src/main/java/us/potatoboy/invview/ViewCommand.java index fab749a..be19456 100644 --- a/src/main/java/us/potatoboy/invview/ViewCommand.java +++ b/src/main/java/us/potatoboy/invview/ViewCommand.java @@ -7,24 +7,24 @@ import eu.pb4.sgui.api.elements.GuiElementBuilder; import eu.pb4.sgui.api.gui.SimpleGui; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.inventory.EnderChestInventory; -import net.minecraft.item.Items; -import net.minecraft.network.packet.c2s.common.SyncedClientOptions; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.screen.slot.Slot; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerConfigEntry; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.storage.NbtReadView; -import net.minecraft.storage.ReadView; -import net.minecraft.text.Text; -import net.minecraft.util.ErrorReporter; -import net.minecraft.util.Identifier; +import net.minecraft.server.level.ClientInformation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.players.NameAndId; +import net.minecraft.util.ProblemReporter; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.PlayerEnderChestContainer; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.storage.TagValueInput; +import net.minecraft.world.level.storage.ValueInput; import us.potatoboy.invview.gui.SavingPlayerDataGui; import us.potatoboy.invview.gui.UnmodifiableSlot; import us.potatoboy.invview.mixin.EntityAccessor; @@ -38,21 +38,21 @@ public class ViewCommand { private static final String permModify = "invview.can_modify"; private static final String msgProtected = "Requested inventory is protected"; - public static int inv(CommandContext context) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); - ServerPlayerEntity requestedPlayer = getRequestedPlayer(context); + public static int inv(CommandContext context) throws CommandSyntaxException { + ServerPlayer player = context.getSource().getPlayer(); + ServerPlayer requestedPlayer = getRequestedPlayer(context); boolean canModify = Permissions.check(context.getSource(), permModify, true); - Permissions.check(requestedPlayer.getUuid(), permProtected, false).thenAcceptAsync(isProtected -> { + Permissions.check(requestedPlayer.getUUID(), permProtected, false).thenAcceptAsync(isProtected -> { if (isProtected) { - context.getSource().sendError(Text.literal(msgProtected)); + context.getSource().sendFailure(Component.literal(msgProtected)); } else { - SimpleGui gui = new SavingPlayerDataGui(ScreenHandlerType.GENERIC_9X5, player, requestedPlayer); + SimpleGui gui = new SavingPlayerDataGui(MenuType.GENERIC_9x5, player, requestedPlayer); gui.setTitle(requestedPlayer.getName()); addBackground(gui); - for (int i = 0; i < requestedPlayer.getInventory().size(); i++) { - gui.setSlotRedirect(i, canModify ? new Slot(requestedPlayer.getInventory(), i, 0, 0) + for (int i = 0; i < requestedPlayer.getInventory().getContainerSize(); i++) { + gui.setSlot(i, canModify ? new Slot(requestedPlayer.getInventory(), i, 0, 0) : new UnmodifiableSlot(requestedPlayer.getInventory(), i)); } @@ -63,30 +63,30 @@ public static int inv(CommandContext context) throws Comman return 1; } - public static int eChest(CommandContext context) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); - ServerPlayerEntity requestedPlayer = getRequestedPlayer(context); - EnderChestInventory requestedEchest = requestedPlayer.getEnderChestInventory(); + public static int eChest(CommandContext context) throws CommandSyntaxException { + ServerPlayer player = context.getSource().getPlayer(); + ServerPlayer requestedPlayer = getRequestedPlayer(context); + PlayerEnderChestContainer requestedEchest = requestedPlayer.getEnderChestInventory(); boolean canModify = Permissions.check(context.getSource(), permModify, true); - Permissions.check(requestedPlayer.getUuid(), permProtected, false).thenAcceptAsync(isProtected -> { + Permissions.check(requestedPlayer.getUUID(), permProtected, false).thenAcceptAsync(isProtected -> { if (isProtected) { - context.getSource().sendError(Text.literal(msgProtected)); + context.getSource().sendFailure(Component.literal(msgProtected)); } else { - ScreenHandlerType screenHandlerType = switch (requestedEchest.size()) { - case 9 -> ScreenHandlerType.GENERIC_9X1; - case 18 -> ScreenHandlerType.GENERIC_9X2; - case 36 -> ScreenHandlerType.GENERIC_9X4; - case 45 -> ScreenHandlerType.GENERIC_9X5; - case 54 -> ScreenHandlerType.GENERIC_9X6; - default -> ScreenHandlerType.GENERIC_9X3; + MenuType screenHandlerType = switch (requestedEchest.getContainerSize()) { + case 9 -> MenuType.GENERIC_9x1; + case 18 -> MenuType.GENERIC_9x2; + case 36 -> MenuType.GENERIC_9x4; + case 45 -> MenuType.GENERIC_9x5; + case 54 -> MenuType.GENERIC_9x6; + default -> MenuType.GENERIC_9x3; }; SimpleGui gui = new SavingPlayerDataGui(screenHandlerType, player, requestedPlayer); gui.setTitle(requestedPlayer.getName()); addBackground(gui); - for (int i = 0; i < requestedEchest.size(); i++) { - gui.setSlotRedirect(i, + for (int i = 0; i < requestedEchest.getContainerSize(); i++) { + gui.setSlot(i, canModify ? new Slot(requestedEchest, i, 0, 0) : new UnmodifiableSlot(requestedEchest, i)); } @@ -162,30 +162,30 @@ public static int eChest(CommandContext context) throws Com // return 1; // } - private static ServerPlayerEntity getRequestedPlayer(CommandContext context) + private static ServerPlayer getRequestedPlayer(CommandContext context) throws CommandSyntaxException { - PlayerConfigEntry playerConfigEntry = GameProfileArgumentType.getProfileArgument(context, "target").iterator().next(); - ServerPlayerEntity requestedPlayer = minecraftServer.getPlayerManager().getPlayer(playerConfigEntry.name()); + NameAndId playerConfigEntry = GameProfileArgument.getGameProfiles(context, "target").iterator().next(); + ServerPlayer requestedPlayer = minecraftServer.getPlayerList().getPlayerByName(playerConfigEntry.name()); // If player is not currently online if (requestedPlayer == null) { - requestedPlayer = new ServerPlayerEntity(minecraftServer, minecraftServer.getOverworld(), new GameProfile(playerConfigEntry.id(), playerConfigEntry.name()), - SyncedClientOptions.createDefault()); - Optional readViewOpt = minecraftServer.getPlayerManager() - .loadPlayerData(playerConfigEntry).map(playerData -> NbtReadView.create(new ErrorReporter.Logging(LogUtils.getLogger()), minecraftServer.getRegistryManager(), playerData)); - readViewOpt.ifPresent(requestedPlayer::readData); + requestedPlayer = new ServerPlayer(minecraftServer, minecraftServer.overworld(), new GameProfile(playerConfigEntry.id(), playerConfigEntry.name()), + ClientInformation.createDefault()); + Optional readViewOpt = minecraftServer.getPlayerList() + .loadPlayerData(playerConfigEntry).map(playerData -> TagValueInput.create(new ProblemReporter.ScopedCollector(LogUtils.getLogger()), minecraftServer.registryAccess(), playerData)); + readViewOpt.ifPresent(requestedPlayer::load); // Avoids player's dimension being reset to the overworld if (readViewOpt.isPresent()) { - ReadView readView = readViewOpt.get(); - Optional dimension = readView.getOptionalString("Dimension"); + ValueInput readView = readViewOpt.get(); + Optional dimension = readView.getString("Dimension"); if (dimension.isPresent()) { - ServerWorld world = minecraftServer.getWorld( - RegistryKey.of(RegistryKeys.WORLD, Identifier.tryParse(dimension.get()))); + ServerLevel world = minecraftServer.getLevel( + ResourceKey.create(Registries.DIMENSION, Identifier.tryParse(dimension.get()))); if (world != null) { - ((EntityAccessor) requestedPlayer).callSetWorld(world); + ((EntityAccessor) requestedPlayer).callSetLevel(world); } } } @@ -196,7 +196,7 @@ private static ServerPlayerEntity getRequestedPlayer(CommandContext type, ServerPlayerEntity player, ServerPlayerEntity savedPlayer) { + public SavingPlayerDataGui(MenuType type, ServerPlayer player, ServerPlayer savedPlayer) { super(type, player, false); this.savedPlayer = savedPlayer; } @Override - public void onClose() { + public void onRemoved() { InvView.savePlayerData(savedPlayer); } } diff --git a/src/main/java/us/potatoboy/invview/gui/UnmodifiableSlot.java b/src/main/java/us/potatoboy/invview/gui/UnmodifiableSlot.java index ea0f58a..9ba30c1 100644 --- a/src/main/java/us/potatoboy/invview/gui/UnmodifiableSlot.java +++ b/src/main/java/us/potatoboy/invview/gui/UnmodifiableSlot.java @@ -1,47 +1,47 @@ package us.potatoboy.invview.gui; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.slot.Slot; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; public class UnmodifiableSlot extends Slot { - public UnmodifiableSlot(Inventory inventory, int index) { + public UnmodifiableSlot(Container inventory, int index) { super(inventory, index, 0, 0); } @Override - public boolean canInsert(ItemStack stack) { + public boolean mayPlace(ItemStack stack) { return false; } @Override - public boolean canTakeItems(PlayerEntity playerEntity) { + public boolean mayPickup(Player playerEntity) { return false; } @Override - public boolean canTakePartial(PlayerEntity player) { + public boolean allowModification(Player player) { return false; } @Override - public ItemStack takeStack(int amount) { + public ItemStack remove(int amount) { return ItemStack.EMPTY; } @Override - public ItemStack insertStack(ItemStack stack, int count) { + public ItemStack safeInsert(ItemStack stack, int count) { return stack; } @Override - public void setStack(ItemStack stack) { + public void setByPlayer(ItemStack stack) { } @Override - public void setStackNoCallbacks(ItemStack stack) { + public void set(ItemStack stack) { } } diff --git a/src/main/java/us/potatoboy/invview/mixin/EntityAccessor.java b/src/main/java/us/potatoboy/invview/mixin/EntityAccessor.java index f395a5a..e9d5249 100644 --- a/src/main/java/us/potatoboy/invview/mixin/EntityAccessor.java +++ b/src/main/java/us/potatoboy/invview/mixin/EntityAccessor.java @@ -1,12 +1,12 @@ package us.potatoboy.invview.mixin; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -import net.minecraft.entity.Entity; -import net.minecraft.world.World; @Mixin(Entity.class) public interface EntityAccessor { @Invoker - public void callSetWorld(World world); + public void callSetLevel(Level world); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 42e78fc..3aa9e19 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,7 +33,7 @@ ], "depends": { "fabricloader": ">=0.17.0", - "fabric": "*", - "minecraft": ">=1.21.11" + "fabric-api": "*", + "minecraft": ">=26.1" } } diff --git a/src/main/resources/invview.mixins.json b/src/main/resources/invview.mixins.json index 109cc66..f5cd253 100644 --- a/src/main/resources/invview.mixins.json +++ b/src/main/resources/invview.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "us.potatoboy.invview.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_25", "mixins": [ "EntityAccessor" ],