Skip to content

Commit 7ae8f5c

Browse files
committed
Fix compile errors
1 parent 6676f88 commit 7ae8f5c

7 files changed

Lines changed: 58 additions & 42 deletions

File tree

modules/core-xplat/src/main/java/com/kneelawk/graphlib/api/util/SidedPos.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.kneelawk.graphlib.api.util;
22

3+
import java.util.Optional;
4+
35
import org.jetbrains.annotations.Contract;
46
import org.jetbrains.annotations.NotNull;
57

@@ -79,8 +81,13 @@ public void toPacket(@NotNull FriendlyByteBuf buf) {
7981
*/
8082
@Contract("_ -> new")
8183
public static @NotNull SidedPos fromNbt(@NotNull CompoundTag nbt) {
82-
int[] pos = nbt.getIntArray("pos");
83-
return new SidedPos(new BlockPos(pos[0], pos[1], pos[2]), Direction.from3DDataValue(nbt.getByte("side")));
84+
Optional<int[]> posOpt = nbt.getIntArray("pos");
85+
if (posOpt.isEmpty())
86+
throw new IllegalArgumentException("Attempted to decode a SidedPos that has no block-pos");
87+
88+
int[] pos = posOpt.get();
89+
return new SidedPos(new BlockPos(pos[0], pos[1], pos[2]),
90+
Direction.from3DDataValue(nbt.getByteOr("side", (byte) 0)));
8491
}
8592

8693
/**

modules/core-xplat/src/main/java/com/kneelawk/graphlib/api/wire/WireConnectionDiscoverers.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static boolean sidedWireCanConnect(@NotNull SidedWireBlockNode self, @Not
151151
BlockNode other = link.other().getNode();
152152

153153
BlockPos posDiff = otherPos.subtract(pos);
154-
Direction posDiffDir = Direction.fromDelta(posDiff.getX(), posDiff.getY(), posDiff.getZ());
154+
Direction posDiffDir = Direction.getNearest(posDiff.getX(), posDiff.getY(), posDiff.getZ(), null);
155155

156156
if (other instanceof SidedWireBlockNode otherSidedNode) {
157157
Direction otherSide = otherSidedNode.getSide();
@@ -175,7 +175,7 @@ public static boolean sidedWireCanConnect(@NotNull SidedWireBlockNode self, @Not
175175
BlockPos under = pos.relative(side);
176176
BlockPos underPosDiff = otherPos.subtract(under);
177177
Direction underPosDiffDir =
178-
Direction.fromDelta(underPosDiff.getX(), underPosDiff.getY(), underPosDiff.getZ());
178+
Direction.getNearest(underPosDiff.getX(), underPosDiff.getY(), underPosDiff.getZ(), null);
179179

180180
if (underPosDiffDir != null) {
181181
return !underPosDiffDir.getAxis().equals(side.getAxis()) &&
@@ -289,7 +289,7 @@ public static boolean fullBlockCanConnect(@NotNull FullWireBlockNode self, @NotN
289289
BlockNode other = link.other().getNode();
290290

291291
BlockPos posDiff = otherPos.subtract(pos);
292-
Direction posDiffDir = Direction.fromDelta(posDiff.getX(), posDiff.getY(), posDiff.getZ());
292+
Direction posDiffDir = Direction.getNearest(posDiff.getX(), posDiff.getY(), posDiff.getZ(), null);
293293

294294
if (posDiffDir == null) {
295295
return false;
@@ -404,7 +404,7 @@ public static boolean centerWireCanConnect(@NotNull CenterWireBlockNode self, @N
404404
BlockNode other = link.other().getNode();
405405

406406
BlockPos posDiff = otherPos.subtract(pos);
407-
Direction posDiffDir = Direction.fromDelta(posDiff.getX(), posDiff.getY(), posDiff.getZ());
407+
Direction posDiffDir = Direction.getNearest(posDiff.getX(), posDiff.getY(), posDiff.getZ(), null);
408408

409409
if (other instanceof CenterWireBlockNode || other instanceof FullWireBlockNode) {
410410
return posDiffDir != null && (filter == null || filter.canConnect(self, holder, posDiffDir, link)) &&

modules/core-xplat/src/main/java/com/kneelawk/graphlib/api/world/UnloadingRegionBasedStorage.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,25 +218,32 @@ private CompletableFuture<Void> loadChunkPillar(@NotNull ChunkPos chunkPos) {
218218
private void loadChunkPillar(@NotNull ChunkPos chunkPos, @NotNull Int2ObjectMap<R> pillar,
219219
@NotNull CompoundTag root) {
220220
// TODO: move this over to dynamics and DFU fix it
221-
CompoundTag sectionsTag = root.getCompound("Sections");
222-
for (int sectionY = world.getMinSection(); sectionY < world.getMaxSection(); sectionY++) {
223-
if (sectionsTag.contains(String.valueOf(sectionY), Tag.TAG_COMPOUND)) {
224-
CompoundTag sectionTag = sectionsTag.getCompound(String.valueOf(sectionY));
225-
try {
226-
DynamicOps<Tag> ops = createOps(SectionPos.of(chunkPos, sectionY), () -> markDirty(chunkPos));
227-
DataResult<R> res = sectionCodec.parse(ops, sectionTag);
228-
final int y = sectionY;
229-
Optional<R> opt = res.resultOrPartial(
230-
err -> GLLog.error("Error loading chunk {}, section {}: {}", chunkPos, y, err));
231-
232-
if (opt.isPresent()) {
233-
R section = opt.get();
234-
pillar.put(sectionY, section);
235-
} else {
236-
GLLog.error("Unable to load chunk {}, section {} due to previous errors.", chunkPos, sectionY);
221+
222+
Optional<CompoundTag> sectionsOpt = root.getCompound("Sections");
223+
if (sectionsOpt.isPresent()) {
224+
CompoundTag sectionsTag = sectionsOpt.get();
225+
for (int sectionY = world.getMinSectionY(); sectionY < world.getMaxSectionY(); sectionY++) {
226+
Optional<CompoundTag> sectionOpt = sectionsTag.getCompound(String.valueOf(sectionY));
227+
if (sectionOpt.isPresent()) {
228+
CompoundTag sectionTag = sectionOpt.get();
229+
try {
230+
DynamicOps<Tag> ops = createOps(SectionPos.of(chunkPos, sectionY), () -> markDirty(chunkPos));
231+
DataResult<R> res = sectionCodec.parse(ops, sectionTag);
232+
final int y = sectionY;
233+
Optional<R> opt = res.resultOrPartial(
234+
err -> GLLog.error("Error loading chunk {}, section {}: {}", chunkPos, y, err));
235+
236+
if (opt.isPresent()) {
237+
R section = opt.get();
238+
pillar.put(sectionY, section);
239+
} else {
240+
GLLog.error("Unable to load chunk {}, section {} due to previous errors.", chunkPos,
241+
sectionY);
242+
}
243+
} catch (Exception e) {
244+
GLLog.error("Error loading chunk {} section {}. Discarding chunk section.", chunkPos, sectionY,
245+
e);
237246
}
238-
} catch (Exception e) {
239-
GLLog.error("Error loading chunk {} section {}. Discarding chunk section.", chunkPos, sectionY, e);
240247
}
241248
}
242249
}
@@ -293,7 +300,7 @@ public void saveChunk(@NotNull ChunkPos pos) {
293300
CompoundTag root = new CompoundTag();
294301

295302
CompoundTag sectionsTag = new CompoundTag();
296-
for (int sectionY = world.getMinSection(); sectionY < world.getMaxSection(); sectionY++) {
303+
for (int sectionY = world.getMinSectionY(); sectionY < world.getMaxSectionY(); sectionY++) {
297304
R section = sections.get(sectionY);
298305
if (section != null) {
299306
try {
@@ -317,7 +324,7 @@ public void saveChunk(@NotNull ChunkPos pos) {
317324

318325
worker.store(pos, root);
319326
} else {
320-
worker.store(pos, null);
327+
worker.store(pos, (CompoundTag) null);
321328
}
322329
}
323330

modules/core-xplat/src/main/java/com/kneelawk/graphlib/impl/command/GraphLibCommand.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static int listUniverses(CommandSourceStack source) {
8888
for (ResourceLocation key : GraphLibImpl.UNIVERSE.keySet()) {
8989
msg.append("\n");
9090
msg.append(Component.literal(key.toString()).withStyle(style -> style.withColor(ChatFormatting.AQUA)
91-
.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, key.toString()))));
91+
.withClickEvent(new ClickEvent.CopyToClipboard(key.toString()))));
9292
}
9393

9494
source.sendSuccess(() -> msg, false);
@@ -183,10 +183,9 @@ private static MutableComponent blockPosText(BlockPos pos) {
183183
Component.translatable("chat.coordinates", pos.getX(), pos.getY(), pos.getZ()))
184184
.withStyle(
185185
style -> style.withColor(ChatFormatting.GREEN)
186-
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND,
187-
"/tp @s " + pos.getX() + " " + pos.getY() + " " + pos.getZ()))
188-
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
189-
Component.translatable("chat.coordinates.tooltip")))
186+
.withClickEvent(
187+
new ClickEvent.SuggestCommand("/tp @s " + pos.getX() + " " + pos.getY() + " " + pos.getZ()))
188+
.withHoverEvent(new HoverEvent.ShowText(Component.translatable("chat.coordinates.tooltip")))
190189
);
191190
}
192191
}

modules/core-xplat/src/main/java/com/kneelawk/graphlib/impl/graph/simple/SimpleBlockGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,8 @@ public void unloadInChunk(int chunkX, int chunkZ) {
10681068
Set<BlockPos> removedPoses = new LinkedHashSet<>();
10691069
LongSet removedChunks = new LongLinkedOpenHashSet();
10701070

1071-
for (int sectionY = world.getWorld().getMinSection();
1072-
sectionY < world.getWorld().getMaxSection(); sectionY++) {
1071+
for (int sectionY = world.getWorld().getMinSectionY();
1072+
sectionY < world.getWorld().getMaxSectionY(); sectionY++) {
10731073
long longPos = SectionPos.asLong(chunkX, sectionY, chunkZ);
10741074
Set<NodeHolder<BlockNode>> inRemovedChunk = nodesInChunk.get(longPos);
10751075
if (inRemovedChunk != null) {

modules/core-xplat/src/main/java/com/kneelawk/graphlib/impl/graph/simple/SimpleBlockGraphPillar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class SimpleBlockGraphPillar {
3838
public final int bottomSectionCoord;
3939

4040
public SimpleBlockGraphPillar(int x, int z, Level world) {
41-
this(x, z, new SimpleBlockGraphChunk[world.getMaxSection() - world.getMinSection()],
42-
world.getMinSection());
41+
this(x, z, new SimpleBlockGraphChunk[world.getMaxSectionY() - world.getMinSectionY()],
42+
world.getMinSectionY());
4343
}
4444

4545
public SimpleBlockGraphPillar(int x, int z, @Nullable SimpleBlockGraphChunk @NotNull [] pillar,

modules/core-xplat/src/main/java/com/kneelawk/graphlib/impl/graph/simple/SimpleServerGraphWorld.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public SimpleServerGraphWorld(SimpleGraphUniverse universe, @NotNull LevelStorag
146146
this.saveMode = universe.saveMode;
147147
graphsDir = path.resolve(Constants.GRAPHS_DIRNAME);
148148
stateFile = path.resolve(Constants.STATE_FILENAME);
149-
timer = new ChunkSectionUnloadTimer(world.getMinSection(), world.getMaxSection(), MAX_AGE);
149+
timer = new ChunkSectionUnloadTimer(world.getMinSectionY(), world.getMaxSectionY(), MAX_AGE);
150150

151151
try {
152152
Files.createDirectories(graphsDir);
@@ -696,7 +696,7 @@ public SimpleBlockGraph getGraph(long id) {
696696
*/
697697
@Override
698698
public @NotNull LongStream getAllGraphIdsInChunk(@NotNull ChunkPos pos) {
699-
return LongStream.range(world.getMinSection(), world.getMaxSection())
699+
return LongStream.range(world.getMinSectionY(), world.getMaxSectionY())
700700
.flatMap(y -> getAllGraphIdsInChunkSection(SectionPos.of(pos, (int) y))).distinct();
701701
}
702702

@@ -1236,7 +1236,7 @@ private void tickGraphs() {
12361236
}
12371237

12381238
private void loadGraphs(@NotNull ChunkPos pos) {
1239-
for (int y = world.getMinSection(); y < world.getMaxSection(); y++) {
1239+
for (int y = world.getMinSectionY(); y < world.getMaxSectionY(); y++) {
12401240
SimpleBlockGraphChunk chunk = chunks.getIfExists(SectionPos.of(pos.x, y, pos.z));
12411241
if (chunk != null) {
12421242
for (long id : chunk.getGraphs()) {
@@ -1247,8 +1247,8 @@ private void loadGraphs(@NotNull ChunkPos pos) {
12471247
}
12481248

12491249
private void saveGraphs(@NotNull ChunkPos pos) {
1250-
LongSet chunkSectionPillar = new LongOpenHashSet(world.getMaxSection() - world.getMinSection());
1251-
for (int y = world.getMinSection(); y < world.getMaxSection(); y++) {
1250+
LongSet chunkSectionPillar = new LongOpenHashSet(world.getMaxSectionY() - world.getMinSectionY());
1251+
for (int y = world.getMinSectionY(); y < world.getMaxSectionY(); y++) {
12521252
chunkSectionPillar.add(SectionPos.asLong(pos.x, y, pos.z));
12531253
}
12541254

@@ -1494,8 +1494,11 @@ private void loadState() {
14941494
if (Files.exists(stateFile)) {
14951495
try (InputStream is = Files.newInputStream(stateFile)) {
14961496
CompoundTag root = NbtIo.readCompressed(is, NbtAccounter.unlimitedHeap());
1497-
CompoundTag data = root.getCompound("data");
1498-
prevGraphId = data.getLong("prevGraphId");
1497+
Optional<CompoundTag> dataOpt = root.getCompound("data");
1498+
if (dataOpt.isEmpty())
1499+
throw new IllegalStateException("graph controller state file missing data root compound");
1500+
CompoundTag data = dataOpt.get();
1501+
prevGraphId = data.getLongOr("prevGraphId", 0);
14991502
} catch (Exception e) {
15001503
GLLog.error("Error loading graph controller state file.", e);
15011504
}

0 commit comments

Comments
 (0)