diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index de61ec1..8bf84c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,10 +18,10 @@ jobs: uses: actions/checkout@v2 - name: validate gradle wrapper uses: gradle/wrapper-validation-action@v1 - - name: setup jdk 17 + - name: setup jdk 21 uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: make gradle wrapper executable if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 56d98e3..f49258e 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 17 + - name: Set up JDK 21 uses: actions/setup-java@v3 with: distribution: temurin - java-version: 17 + java-version: 21 - name: Make gradlew executable run: chmod +x ./gradlew @@ -24,7 +24,7 @@ jobs: run: ./gradlew clean build - name: Upload assets to GitHub, Modrinth and CurseForge - uses: Kir-Antipov/mc-publish@v3.2 + uses: Kir-Antipov/mc-publish@v3.3 with: modrinth-id: IEPAK5x6 modrinth-token: ${{ secrets.MODRINTH_TOKEN }} @@ -32,4 +32,4 @@ jobs: curseforge-id: 462534 curseforge-token: ${{ secrets.CF_API_TOKEN }} - github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.gradle b/build.gradle index ab82a9c..63343e0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.4.+' + id 'fabric-loom' version '1.6.+' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 03e6436..b320601 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,14 +2,14 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.3 -loader_version=0.15.3 +minecraft_version=1.20.5 +yarn_mappings=1.20.5+build.1 +loader_version=0.15.10 # Mod Properties -mod_version=1.1.11 +mod_version=1.1.12 maven_group=us.potatoboy archives_base_name=htm # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.91.3+1.20.4 -translation_version=2.2.0+1.20.3-rc1 +fabric_version=0.97.6+1.20.5 +translation_version=2.3.0+1.20.5-rc2 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a595206..48c0a02 100644 --- 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.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/github/fabricservertools/htm/HTMContainerLock.java b/src/main/java/com/github/fabricservertools/htm/HTMContainerLock.java index 14dc3cd..9c4a23a 100644 --- a/src/main/java/com/github/fabricservertools/htm/HTMContainerLock.java +++ b/src/main/java/com/github/fabricservertools/htm/HTMContainerLock.java @@ -2,13 +2,12 @@ import com.github.fabricservertools.htm.api.Lock; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtHelper; import net.minecraft.nbt.NbtList; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; @@ -41,10 +40,10 @@ private void initFlags() { flags = hashMap; } - public void toTag(NbtCompound tag) { + public void toTag(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { if (type != null) { tag.putString("Type", HTMRegistry.getLockId(type.getType())); - tag.put("TypeData", type.toTag()); + tag.put("TypeData", type.toTag(registryLookup)); tag.putUuid("Owner", owner); NbtList trustedTag = new NbtList(); @@ -74,7 +73,7 @@ public void toTag(NbtCompound tag) { } - public void fromTag(NbtCompound tag) { + public void fromTag(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { if (tag.contains("Type")) { try { type = HTMRegistry.getLock(tag.getString("Type")).orElseThrow(RuntimeException::new); @@ -83,22 +82,22 @@ public void fromTag(NbtCompound tag) { type = null; return; } - type.fromTag(tag.getCompound("TypeData")); + type.fromTag(tag.getCompound("TypeData"), registryLookup); owner = tag.getUuid("Owner"); - NbtList trustedTag = tag.getList("Trusted", NbtType.INT_ARRAY); + NbtList trustedTag = tag.getList("Trusted", NbtElement.INT_ARRAY_TYPE); for (NbtElement value : trustedTag) { trusted.add(NbtHelper.toUuid(value)); } - NbtList managersTag = tag.getList("Managers", NbtType.INT_ARRAY); + NbtList managersTag = tag.getList("Managers", NbtElement.INT_ARRAY_TYPE); for (NbtElement value : managersTag) { managers.add(NbtHelper.toUuid(value)); } - NbtList flagTags = tag.getList("Flags", NbtType.COMPOUND); + NbtList flagTags = tag.getList("Flags", NbtElement.COMPOUND_TYPE); for (NbtElement flagTag : flagTags) { NbtCompound compoundTag = (NbtCompound) flagTag; flags.put(compoundTag.getString("type"), compoundTag.getBoolean("value")); @@ -114,7 +113,7 @@ public boolean canOpen(ServerPlayerEntity player) { if (isOwner(player)) return true; player.sendMessage(Text.translatable("text.htm.locked"), true); - player.playSound(SoundEvents.BLOCK_CHEST_LOCKED, SoundCategory.BLOCKS, 1.0F, 1.0F); + player.playSound(SoundEvents.BLOCK_CHEST_LOCKED, 1.0F, 1.0F); return false; } diff --git a/src/main/java/com/github/fabricservertools/htm/api/Lock.java b/src/main/java/com/github/fabricservertools/htm/api/Lock.java index ea5589f..6c9fcb4 100644 --- a/src/main/java/com/github/fabricservertools/htm/api/Lock.java +++ b/src/main/java/com/github/fabricservertools/htm/api/Lock.java @@ -2,6 +2,7 @@ import com.github.fabricservertools.htm.HTMContainerLock; import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; public interface Lock { @@ -11,9 +12,9 @@ public interface Lock { void onInfo(ServerPlayerEntity player, HTMContainerLock lock); - NbtCompound toTag(); + NbtCompound toTag(RegistryWrapper.WrapperLookup registryLookup); - void fromTag(NbtCompound tag); + void fromTag(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup); LockType getType(); } diff --git a/src/main/java/com/github/fabricservertools/htm/locks/KeyLock.java b/src/main/java/com/github/fabricservertools/htm/locks/KeyLock.java index 6d74fc6..ed7d8bf 100644 --- a/src/main/java/com/github/fabricservertools/htm/locks/KeyLock.java +++ b/src/main/java/com/github/fabricservertools/htm/locks/KeyLock.java @@ -4,12 +4,21 @@ import com.github.fabricservertools.htm.Utility; import com.github.fabricservertools.htm.api.Lock; import com.github.fabricservertools.htm.api.LockType; +import com.mojang.serialization.Dynamic; +import net.minecraft.MinecraftVersion; +import net.minecraft.SharedConstants; +import net.minecraft.datafixer.Schemas; +import net.minecraft.datafixer.TypeReferences; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtOps; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; public class KeyLock implements Lock { + private static final String ITEM_TAG = "Item"; private ItemStack key; @Override @@ -20,7 +29,7 @@ public boolean canOpen(ServerPlayerEntity player, HTMContainerLock lock) { return true; ItemStack itemStack = player.getMainHandStack(); - return ItemStack.canCombine(itemStack, key); + return ItemStack.areItemsAndComponentsEqual(itemStack, key); } @Override @@ -35,15 +44,30 @@ public void onInfo(ServerPlayerEntity player, HTMContainerLock lock) { } @Override - public NbtCompound toTag() { - NbtCompound tag = new NbtCompound(); - key.writeNbt(tag); - return tag; + public NbtCompound toTag(RegistryWrapper.WrapperLookup registryLookup) { + NbtCompound saveTag = new NbtCompound(); + saveTag.putInt(SharedConstants.DATA_VERSION_KEY, MinecraftVersion.CURRENT.getSaveVersion().getId()); + saveTag.put(ITEM_TAG, key.encodeAllowEmpty(registryLookup)); + return saveTag; } @Override - public void fromTag(NbtCompound tag) { - key = ItemStack.fromNbt(tag); + public void fromTag(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { + NbtCompound itemTag; + int dataVersion; + if (!tag.contains(SharedConstants.DATA_VERSION_KEY, NbtElement.INT_TYPE)) { + // 1.20.4 or older, assuming 1.20.4 data version + itemTag = tag; + dataVersion = 3700; + } else { + dataVersion = tag.getInt(SharedConstants.DATA_VERSION_KEY); + itemTag = tag.getCompound(ITEM_TAG); + } + + itemTag = (NbtCompound) Schemas.getFixer().update(TypeReferences.ITEM_STACK, + new Dynamic<>(NbtOps.INSTANCE, itemTag), dataVersion, + MinecraftVersion.CURRENT.getSaveVersion().getId()).cast(NbtOps.INSTANCE); + key = ItemStack.fromNbtOrEmpty(registryLookup, itemTag); } @Override diff --git a/src/main/java/com/github/fabricservertools/htm/locks/PrivateLock.java b/src/main/java/com/github/fabricservertools/htm/locks/PrivateLock.java index 9652fbc..5f5d82b 100644 --- a/src/main/java/com/github/fabricservertools/htm/locks/PrivateLock.java +++ b/src/main/java/com/github/fabricservertools/htm/locks/PrivateLock.java @@ -5,6 +5,7 @@ import com.github.fabricservertools.htm.api.Lock; import com.github.fabricservertools.htm.api.LockType; import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; public class PrivateLock implements Lock { @@ -25,12 +26,12 @@ public void onInfo(ServerPlayerEntity player, HTMContainerLock lock) { } @Override - public NbtCompound toTag() { + public NbtCompound toTag(RegistryWrapper.WrapperLookup registryLookup) { return new NbtCompound(); } @Override - public void fromTag(NbtCompound tag) { + public void fromTag(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { } diff --git a/src/main/java/com/github/fabricservertools/htm/locks/PublicLock.java b/src/main/java/com/github/fabricservertools/htm/locks/PublicLock.java index 83f00dc..c0ffdba 100644 --- a/src/main/java/com/github/fabricservertools/htm/locks/PublicLock.java +++ b/src/main/java/com/github/fabricservertools/htm/locks/PublicLock.java @@ -4,6 +4,7 @@ import com.github.fabricservertools.htm.api.Lock; import com.github.fabricservertools.htm.api.LockType; import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; public class PublicLock implements Lock { @@ -22,12 +23,12 @@ public void onInfo(ServerPlayerEntity player, HTMContainerLock lock) { } @Override - public NbtCompound toTag() { + public NbtCompound toTag(RegistryWrapper.WrapperLookup registryLookup) { return new NbtCompound(); } @Override - public void fromTag(NbtCompound tag) { + public void fromTag(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { } diff --git a/src/main/java/com/github/fabricservertools/htm/mixin/LockableContainerMixin.java b/src/main/java/com/github/fabricservertools/htm/mixin/LockableContainerMixin.java index fedd92f..c8416f7 100644 --- a/src/main/java/com/github/fabricservertools/htm/mixin/LockableContainerMixin.java +++ b/src/main/java/com/github/fabricservertools/htm/mixin/LockableContainerMixin.java @@ -7,6 +7,7 @@ import net.minecraft.block.entity.LockableContainerBlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Mixin; @@ -25,13 +26,14 @@ private void init(BlockEntityType blockEntityType, BlockPos blockPos, BlockSt } @Inject(method = "writeNbt", at = @At("HEAD")) - private void toTag(NbtCompound nbt, CallbackInfo ci) { - htmContainerLock.toTag(nbt); + private void toTag(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup, CallbackInfo ci) { + htmContainerLock.toTag(nbt, registryLookup); } @Inject(method = "readNbt", at = @At("HEAD")) - private void fromTag(NbtCompound nbt, CallbackInfo ci) { - htmContainerLock.fromTag(nbt); + private void fromTag(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup, + CallbackInfo ci) { + htmContainerLock.fromTag(nbt, registryLookup); } @Inject(method = "checkUnlocked(Lnet/minecraft/entity/player/PlayerEntity;)Z", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/com/github/fabricservertools/htm/world/data/GlobalTrustState.java b/src/main/java/com/github/fabricservertools/htm/world/data/GlobalTrustState.java index e762061..e9c6f1a 100644 --- a/src/main/java/com/github/fabricservertools/htm/world/data/GlobalTrustState.java +++ b/src/main/java/com/github/fabricservertools/htm/world/data/GlobalTrustState.java @@ -7,6 +7,7 @@ import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtHelper; import net.minecraft.nbt.NbtList; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.world.PersistentState; import java.util.UUID; @@ -18,7 +19,8 @@ public GlobalTrustState() { globalTrust = HashMultimap.create(); } - public static GlobalTrustState fromNbt(NbtCompound tag) { + public static GlobalTrustState fromNbt(NbtCompound tag, + RegistryWrapper.WrapperLookup registryLookup) { GlobalTrustState trustState = new GlobalTrustState(); NbtList trustList = tag.getList("GlobalTrusts", NbtType.COMPOUND); @@ -37,7 +39,7 @@ public static GlobalTrustState fromNbt(NbtCompound tag) { } @Override - public NbtCompound writeNbt(NbtCompound tag) { + public NbtCompound writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { NbtList trustList = new NbtList(); for (UUID trusterID : globalTrust.keySet()) {