diff --git a/src/main/java/com/wenxin2/warp_pipes/blocks/entities/WarpPipeBlockEntity.java b/src/main/java/com/wenxin2/warp_pipes/blocks/entities/WarpPipeBlockEntity.java index c257ff7..21d9d92 100644 --- a/src/main/java/com/wenxin2/warp_pipes/blocks/entities/WarpPipeBlockEntity.java +++ b/src/main/java/com/wenxin2/warp_pipes/blocks/entities/WarpPipeBlockEntity.java @@ -8,6 +8,7 @@ import com.wenxin2.warp_pipes.init.ModRegistry; import com.wenxin2.warp_pipes.init.SoundRegistry; import com.wenxin2.warp_pipes.inventory.WarpPipeMenu; +import java.util.Optional; import java.util.UUID; import java.util.function.UnaryOperator; import javax.annotation.Nullable; @@ -15,6 +16,7 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; @@ -72,7 +74,7 @@ public class WarpPipeBlockEntity extends BlockEntity implements MenuProvider, Na public Component name; private LockCode lockKey = LockCode.NO_LOCK; @Nullable - public BlockPos destinationPos; + public Optional destinationPos; public String dimensionTag; public int spoutHeight = 4; public int bubblesDistance = 3; @@ -264,9 +266,9 @@ public boolean hasDestinationPos() { return this.destinationPos != null; } - public void setDestinationPos(@Nullable BlockPos pos) { + public void setDestinationPos(@Nullable Optional pos) { this.destinationPos = pos; - if (this.level != null && pos != null) { + if (this.level != null && pos != null && pos.isPresent()) { BlockState state = this.getBlockState(); this.level.setBlock(this.getBlockPos(), state, 4); } @@ -274,8 +276,8 @@ public void setDestinationPos(@Nullable BlockPos pos) { @Nullable public BlockPos getDestinationPos() { - if (this.destinationPos != null) { - return this.destinationPos; + if (this.destinationPos != null && this.destinationPos.isPresent()) { + return this.destinationPos.get(); } return null; } @@ -359,8 +361,8 @@ private Component loadLine(Component text) { } @Override - public void load(CompoundTag tag) { - super.load(tag); + public void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) { + super.loadAdditional(tag, provider); this.lockKey = LockCode.fromTag(tag); this.spoutHeight = tag.getInt(SPOUT_HEIGHT); this.bubblesDistance = tag.getInt(BUBBLES_DISTANCE); @@ -373,7 +375,7 @@ public void load(CompoundTag tag) { this.displayTextBelow = tag.getBoolean(DISPLAY_TEXT_BELOW); if (tag.contains(CUSTOM_NAME, 8)) { - this.name = Component.Serializer.fromJson(tag.getString(CUSTOM_NAME)); + this.name = Component.Serializer.fromJson(tag.getString(CUSTOM_NAME), provider); } if (tag.contains(PIPE_NAME)) { @@ -383,7 +385,7 @@ public void load(CompoundTag tag) { } if (tag.contains(WARP_POS)) { - this.destinationPos = NbtUtils.readBlockPos(tag.getCompound(WARP_POS)); + this.destinationPos = NbtUtils.readBlockPos(tag.getCompound(WARP_POS), "warp_pos"); this.setDestinationPos(this.destinationPos); } @@ -403,8 +405,8 @@ public void load(CompoundTag tag) { } @Override - public void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); + public void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) { + super.saveAdditional(tag, provider); this.lockKey.addToTag(tag); tag.putInt(BUBBLES_DISTANCE, this.bubblesDistance); tag.putInt(SPOUT_HEIGHT, this.spoutHeight); @@ -418,15 +420,15 @@ public void saveAdditional(CompoundTag tag) { tag.putBoolean(DISPLAY_TEXT_BELOW, this.displayTextBelow); if (this.name != null) { - tag.putString(CUSTOM_NAME, Component.Serializer.toJson(this.name)); + tag.putString(CUSTOM_NAME, Component.Serializer.toJson(this.name, provider)); } PipeText.DIRECT_CODEC.encodeStart(NbtOps.INSTANCE, this.pipeName).resultOrPartial(LOGGER::error).ifPresent((pipeName) -> { tag.put(PIPE_NAME, pipeName); }); - if (this.hasDestinationPos() && this.destinationPos != null) { - tag.put(WARP_POS, NbtUtils.writeBlockPos(this.destinationPos)); + if (this.hasDestinationPos() && this.destinationPos != null && this.destinationPos.isPresent()) { + tag.put(WARP_POS, NbtUtils.writeBlockPos(this.destinationPos.get())); } if (this.dimensionTag != null) { @@ -444,10 +446,10 @@ public void saveAdditional(CompoundTag tag) { @NotNull @Override - public CompoundTag getUpdateTag() { - CompoundTag tag = super.getUpdateTag(); + public CompoundTag getUpdateTag(HolderLookup.Provider provider) { + CompoundTag tag = super.getUpdateTag(provider); - this.saveAdditional(tag); + this.saveAdditional(tag, provider); return tag; } diff --git a/src/main/java/com/wenxin2/warp_pipes/items/LinkerItem.java b/src/main/java/com/wenxin2/warp_pipes/items/LinkerItem.java index de5c25a..a2702f2 100644 --- a/src/main/java/com/wenxin2/warp_pipes/items/LinkerItem.java +++ b/src/main/java/com/wenxin2/warp_pipes/items/LinkerItem.java @@ -242,7 +242,7 @@ public void link(BlockPos pos, Level world, ItemStack stack, WarpPipeBlockEntity UUID uuid = warpPipeBE.getUuid(); UUID uuidGlobal = warpPipeBEGlobal.getUuid(); - warpPipeBE.setDestinationPos(warpPipeBEGlobal.getBlockPos()); + warpPipeBE.setDestinationPos(Optional.of(warpPipeBEGlobal.getBlockPos())); if (uuid != null) warpPipeBE.setWarpUuid(getWarpUUID(stack)); warpPipeBE.setChanged(); @@ -251,7 +251,7 @@ public void link(BlockPos pos, Level world, ItemStack stack, WarpPipeBlockEntity // System.out.println("Global Dimension: " + warpPipeBEGlobal.getLevel().dimension()); } /*else System.out.println("World is null!");*/ - warpPipeBEGlobal.setDestinationPos(pos); + warpPipeBEGlobal.setDestinationPos(Optional.ofNullable(pos)); warpPipeBEGlobal.setDestinationDim(world.dimension()); if (uuidGlobal != null) warpPipeBEGlobal.setWarpUuid(warpPipeBE.getUuid());