Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxtrek64 committed May 28, 2024
2 parents 3732564 + 4c82877 commit ecf26b6
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,12 +24,12 @@ 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 }}

curseforge-id: 462534
curseforge-token: ${{ secrets.CF_API_TOKEN }}

github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4.+'
id 'fabric-loom' version '1.6.+'
id 'maven-publish'
}

Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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"));
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/github/fabricservertools/htm/api/Lock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
38 changes: 31 additions & 7 deletions src/main/java/com/github/fabricservertools/htm/locks/KeyLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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()) {
Expand Down

0 comments on commit ecf26b6

Please sign in to comment.