|
5 | 5 | import me.desht.modularrouters.util.Scheduler;
|
6 | 6 | import net.minecraft.core.BlockPos;
|
7 | 7 | import net.minecraft.core.Direction;
|
| 8 | +import net.minecraft.core.registries.BuiltInRegistries; |
8 | 9 | import net.minecraft.core.registries.Registries;
|
9 | 10 | import net.minecraft.nbt.CompoundTag;
|
10 | 11 | import net.minecraft.nbt.NbtUtils;
|
@@ -72,7 +73,9 @@ public void load(CompoundTag compound) {
|
72 | 73 | public void saveAdditional(CompoundTag compound) {
|
73 | 74 | super.saveAdditional(compound);
|
74 | 75 | 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 | + } |
76 | 79 | }
|
77 | 80 |
|
78 | 81 | @Override
|
@@ -117,8 +120,10 @@ public CompoundTag getUpdateTag() {
|
117 | 120 | }
|
118 | 121 |
|
119 | 122 | private BlockState getCamoStateFromNBT(CompoundTag tag) {
|
| 123 | + // level isn't necessarily available here |
| 124 | + var lookup = level == null ? BuiltInRegistries.BLOCK.asLookup() : level.holderLookup(Registries.BLOCK); |
120 | 125 | 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)); |
122 | 127 | }
|
123 | 128 | return null;
|
124 | 129 | }
|
|
0 commit comments