diff --git a/src/main/java/loqor/ait/core/engine/block/SubSystemBlockEntity.java b/src/main/java/loqor/ait/core/engine/block/SubSystemBlockEntity.java index b89cd649c..001c78e35 100644 --- a/src/main/java/loqor/ait/core/engine/block/SubSystemBlockEntity.java +++ b/src/main/java/loqor/ait/core/engine/block/SubSystemBlockEntity.java @@ -27,7 +27,7 @@ public SubSystemBlockEntity(BlockEntityType type, BlockPos pos, BlockState st } public SubSystem system() { - if (this.tardis() == null || this.tardis().isEmpty() || this.id() == null) return null; + if (!(this.isLinked()) || this.id() == null) return null; return this.tardis().get().subsystems().get(this.id()); } @@ -84,7 +84,7 @@ public void writeNbt(NbtCompound nbt) { super.writeNbt(nbt); if (this.id != null) { - nbt.putString("id", this.id.toString()); + nbt.putString("SystemId", this.id.name()); } } @@ -92,8 +92,8 @@ public void writeNbt(NbtCompound nbt) { public void readNbt(NbtCompound nbt) { super.readNbt(nbt); - if (nbt.contains("id")) { - this.id = SubSystemRegistry.getInstance().get(nbt.getString("id")); + if (nbt.contains("SystemId")) { + this.id = SubSystemRegistry.getInstance().get(nbt.getString("SystemId")); } } } diff --git a/src/main/java/loqor/ait/core/engine/block/generic/GenericStructureSystemBlockEntity.java b/src/main/java/loqor/ait/core/engine/block/generic/GenericStructureSystemBlockEntity.java index edbc82c80..d72468644 100644 --- a/src/main/java/loqor/ait/core/engine/block/generic/GenericStructureSystemBlockEntity.java +++ b/src/main/java/loqor/ait/core/engine/block/generic/GenericStructureSystemBlockEntity.java @@ -58,6 +58,7 @@ protected StructureHolder getHolder() { } protected void onChangeId() { this.processStructure(); + this.markDirty(); } @Override diff --git a/src/main/java/loqor/ait/core/tardis/dim/TardisDimension.java b/src/main/java/loqor/ait/core/tardis/dim/TardisDimension.java index 70267407a..f92a25945 100644 --- a/src/main/java/loqor/ait/core/tardis/dim/TardisDimension.java +++ b/src/main/java/loqor/ait/core/tardis/dim/TardisDimension.java @@ -2,6 +2,7 @@ import java.util.Optional; import java.util.UUID; +import java.util.function.Consumer; import dev.pavatus.multidim.MultiDim; import dev.pavatus.multidim.api.VoidChunkGenerator; @@ -23,9 +24,11 @@ import loqor.ait.core.tardis.ServerTardis; import loqor.ait.core.tardis.Tardis; import loqor.ait.core.tardis.TardisManager; +import loqor.ait.core.tardis.manager.ServerTardisManager; import loqor.ait.core.util.ServerLifecycleHooks; import loqor.ait.core.util.WorldUtil; + public class TardisDimension { private static WorldBuilder builder(ServerTardis tardis) { return new WorldBuilder(new Identifier(AITMod.MOD_ID, tardis.getUuid().toString())) @@ -70,6 +73,18 @@ public static Optional get(World world) { return Optional.ofNullable(TardisManager.with(world, ((o, manager) -> manager.demandTardis(o, uuid)))); } + public static void withTardis(ServerWorld world, Consumer consumer) { + UUID uuid; + + try { + uuid = UUID.fromString(world.getRegistryKey().getValue().getPath()); + } catch (Exception e) { + consumer.accept(null); + return; + } + + ServerTardisManager.getInstance().getTardis(world.getServer(), uuid, consumer); + } public static boolean isTardisDimension(RegistryKey world) { Identifier value = world.getValue();