Skip to content

Commit 48dea1c

Browse files
committed
fix a couple of template frame NBT loading/saving bugs
1 parent f7c5481 commit 48dea1c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/me/desht/modularrouters/block/tile/TemplateFrameBlockEntity.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import me.desht.modularrouters.util.Scheduler;
66
import net.minecraft.core.BlockPos;
77
import net.minecraft.core.Direction;
8+
import net.minecraft.core.registries.BuiltInRegistries;
89
import net.minecraft.core.registries.Registries;
910
import net.minecraft.nbt.CompoundTag;
1011
import net.minecraft.nbt.NbtUtils;
@@ -72,7 +73,9 @@ public void load(CompoundTag compound) {
7273
public void saveAdditional(CompoundTag compound) {
7374
super.saveAdditional(compound);
7475
compound.putBoolean(NBT_MIMIC, extendedMimic);
75-
compound.put(NBT_CAMO_NAME, NbtUtils.writeBlockState(camouflage));
76+
if (camouflage != null) {
77+
compound.put(NBT_CAMO_NAME, NbtUtils.writeBlockState(camouflage));
78+
}
7679
}
7780

7881
@Override
@@ -117,8 +120,10 @@ public CompoundTag getUpdateTag() {
117120
}
118121

119122
private BlockState getCamoStateFromNBT(CompoundTag tag) {
123+
// level isn't necessarily available here
124+
var lookup = level == null ? BuiltInRegistries.BLOCK.asLookup() : level.holderLookup(Registries.BLOCK);
120125
if (tag.contains(NBT_CAMO_NAME)) {
121-
return NbtUtils.readBlockState(level.holderLookup(Registries.BLOCK), tag.getCompound(NBT_CAMO_NAME));
126+
return NbtUtils.readBlockState(lookup, tag.getCompound(NBT_CAMO_NAME));
122127
}
123128
return null;
124129
}

0 commit comments

Comments
 (0)