Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.

Commit 1c2e9e5

Browse files
committed
chore: cleanup
1 parent a7921c3 commit 1c2e9e5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/main/java/net/crystalgames/scaffolding/schematic/impl/MCEditSchematic.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ public class MCEditSchematic extends AbstractSchematic {
2626
private short width;
2727
private short height;
2828
private short length;
29-
30-
private String materials;
31-
private byte[] addId;
3229
private short[] blocks;
3330

31+
private boolean read = false;
32+
3433
public MCEditSchematic(InputStream inputStream) throws IOException, NBTException {
3534
super(inputStream);
3635
}
@@ -46,6 +45,8 @@ public void read() throws NBTException {
4645
readSizes(nbtTag);
4746
readBlocksData(nbtTag);
4847
readBlocks();
48+
49+
read = true;
4950
}
5051

5152
private void readSizes(@NotNull NBTCompound nbtTag) throws NBTException {
@@ -66,7 +67,6 @@ private void readSizes(@NotNull NBTCompound nbtTag) throws NBTException {
6667
private void readBlocksData(@NotNull NBTCompound nbtTag) throws NBTException {
6768
String materials = nbtTag.getString("Materials");
6869
if (materials == null || !materials.equals("Alpha")) throw new NBTException("Invalid Schematic: Invalid Materials");
69-
this.materials = materials;
7070

7171
ImmutableByteArray blockIdPre = nbtTag.getByteArray("Blocks");
7272
if (blockIdPre == null) throw new NBTException("Invalid Schematic: No Blocks");
@@ -76,15 +76,16 @@ private void readBlocksData(@NotNull NBTCompound nbtTag) throws NBTException {
7676
if (blocksData == null) throw new NBTException("Invalid Schematic: No Block Data");
7777
blocksData.copyArray();
7878

79+
byte[] addId;
7980
if (nbtTag.containsKey("AddBlocks")) addId = Objects.requireNonNull(nbtTag.getByteArray("AddBlocks")).copyArray();
8081
else addId = new byte[0];
8182

8283
blocks = new short[blockId.length];
8384
for (int index = 0; index < blockId.length; index++) {
84-
if ((index >> 1) >= this.addId.length) this.blocks[index] = (short) (blockId[index] & 0xFF);
85+
if ((index >> 1) >= addId.length) this.blocks[index] = (short) (blockId[index] & 0xFF);
8586
else {
86-
if ((index & 1) == 0) this.blocks[index] = (short) (((this.addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
87-
else this.blocks[index] = (short) (((this.addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
87+
if ((index & 1) == 0) this.blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
88+
else this.blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
8889
}
8990
}
9091
}
@@ -108,6 +109,7 @@ public void write(Region region) {
108109

109110
@Override
110111
public CompletableFuture<Region> build(Instance instance, Pos position) {
112+
if (!read) throw new IllegalStateException("Schematic not read");
111113
CompletableFuture<Region> future = new CompletableFuture<>();
112114
CompletableFuture.runAsync(() -> {
113115
AbsoluteBlockBatch blockBatch = new AbsoluteBlockBatch();

src/main/java/net/crystalgames/scaffolding/schematic/impl/SpongeSchematic.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public class SpongeSchematic extends AbstractSchematic {
2525
private short height;
2626
private short length;
2727
private Map<String, Integer> palette = new HashMap<>();
28-
2928
private byte[] blocksData;
3029

30+
private boolean read = false;
31+
3132
public SpongeSchematic(InputStream inputStream) throws IOException, NBTException {
3233
super(inputStream);
3334
}
@@ -41,6 +42,8 @@ public void read() throws NBTException {
4142
readSizes(nbtTag);
4243
readBlockPalette(nbtTag);
4344
readBlocks();
45+
46+
read = true;
4447
}
4548

4649
private void readSizes(@NotNull NBTCompound nbtTag) throws NBTException {
@@ -125,6 +128,7 @@ public void write(Region region) {
125128

126129
@Override
127130
public CompletableFuture<Region> build(Instance instance, Pos position) {
131+
if (!read) throw new IllegalStateException("Schematic not read");
128132
CompletableFuture<Region> future = new CompletableFuture<>();
129133
CompletableFuture.runAsync(() -> {
130134
AbsoluteBlockBatch blockBatch = new AbsoluteBlockBatch();

0 commit comments

Comments
 (0)