Skip to content

Commit

Permalink
fix: SubSystemBlockEntity now properly saves id
Browse files Browse the repository at this point in the history
  • Loading branch information
Duzos committed Nov 20, 2024
1 parent 2cfd196 commit 3508494
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -84,16 +84,16 @@ public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);

if (this.id != null) {
nbt.putString("id", this.id.toString());
nbt.putString("SystemId", this.id.name());
}
}

@Override
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"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected StructureHolder getHolder() {
}
protected void onChangeId() {
this.processStructure();
this.markDirty();
}

@Override
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/loqor/ait/core/tardis/dim/TardisDimension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()))
Expand Down Expand Up @@ -70,6 +73,18 @@ public static Optional<Tardis> get(World world) {

return Optional.ofNullable(TardisManager.with(world, ((o, manager) -> manager.demandTardis(o, uuid))));
}
public static void withTardis(ServerWorld world, Consumer<ServerTardis> 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> world) {
Identifier value = world.getValue();

Expand Down

0 comments on commit 3508494

Please sign in to comment.