some cleaning & fixes
This commit is contained in:
parent
0df83c8c0d
commit
bd030ec374
3 changed files with 10 additions and 27 deletions
|
@ -42,7 +42,7 @@ public class SchematicV2Handler {
|
|||
|
||||
try {
|
||||
Path path = Paths.get(SchematicV2Handler.class.getResource("/data/dimdoors/pockets/generators").toURI());
|
||||
loadCompound(path, new String[0], this::loadPocketGenerator);
|
||||
loadJson(path, new String[0], this::loadPocketGenerator);
|
||||
LOGGER.info("Loaded pockets in {} seconds", System.currentTimeMillis() - startTime);
|
||||
} catch (URISyntaxException e) {
|
||||
LOGGER.error(e);
|
||||
|
@ -51,14 +51,14 @@ public class SchematicV2Handler {
|
|||
startTime = System.currentTimeMillis();
|
||||
try {
|
||||
Path path = Paths.get(SchematicV2Handler.class.getResource("/data/dimdoors/pockets/groups").toURI());
|
||||
loadCompound(path, new String[0], this::loadPocketGroup);
|
||||
loadJson(path, new String[0], this::loadPocketGroup);
|
||||
LOGGER.info("Loaded pocket groups in {} seconds", System.currentTimeMillis() - startTime);
|
||||
} catch (URISyntaxException e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCompound(Path path, String[] idParts, BiConsumer<String, Tag> loader) {
|
||||
private void loadJson(Path path, String[] idParts, BiConsumer<String, Tag> loader) {
|
||||
if (Files.isDirectory(path)) {
|
||||
try {
|
||||
for (Path directoryPath : Files.newDirectoryStream(path)) {
|
||||
|
@ -66,7 +66,7 @@ public class SchematicV2Handler {
|
|||
String fileName = directoryPath.getFileName().toString();
|
||||
if (Files.isRegularFile(directoryPath)) fileName = fileName.substring(0, fileName.lastIndexOf('.')); // cut extension
|
||||
directoryIdParts[directoryIdParts.length - 1] = fileName;
|
||||
loadCompound(directoryPath, directoryIdParts, loader);
|
||||
loadJson(directoryPath, directoryIdParts, loader);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("could not load pocket data in path " + path.toString() + " due to malformed json.", e);
|
||||
|
@ -75,30 +75,13 @@ public class SchematicV2Handler {
|
|||
String id = String.join(".", idParts);
|
||||
try {
|
||||
JsonElement json = GSON.fromJson(String.join("", Files.readAllLines(path)), JsonElement.class);
|
||||
loader.accept(id, jsonToTag(json));
|
||||
loader.accept(id, JsonOps.INSTANCE.convertTo(NbtOps.INSTANCE, json));
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("could not load pocket data in path " + path.toString() + " due to malformed json.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Tag jsonToTag(JsonElement json) {
|
||||
if (json.isJsonArray()) {
|
||||
ListTag listTag = new ListTag();
|
||||
for (JsonElement jsonElement : (JsonArray) json) {
|
||||
Tag tag = jsonToTag(jsonElement);
|
||||
if (tag != null) listTag.add(jsonToTag(jsonElement));
|
||||
}
|
||||
return listTag;
|
||||
}
|
||||
else if (json.isJsonObject()) {
|
||||
return CompoundTag.CODEC.decode(JsonOps.INSTANCE, json).getOrThrow(false, LOGGER::error).getFirst();
|
||||
} else {
|
||||
LOGGER.error("JsonElement was not JsonObject or JsonArray!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadPocketGroup(String id, Tag tag) {
|
||||
VirtualPocket group = VirtualPocket.deserialize(tag);
|
||||
LOGGER.info(VirtualPocket.serialize(group).toString());
|
||||
|
|
|
@ -80,8 +80,8 @@ public class ChunkGenerator extends PocketGenerator {
|
|||
ServerWorld world = parameters.getWorld();
|
||||
VirtualLocation sourceVirtualLocation = parameters.getSourceVirtualLocation();
|
||||
|
||||
int ChunkSizeX = ((this.size.getX() >> 4) + (this.size.getX() % 16 == 0 ? 0 : 1));
|
||||
int ChunkSizeZ = ((this.size.getZ() >> 4) + (this.size.getZ() % 16 == 0 ? 0 : 1));
|
||||
int chunkSizeX = ((this.size.getX() >> 4) + (this.size.getX() % 16 == 0 ? 0 : 1));
|
||||
int chunkSizeZ = ((this.size.getZ() >> 4) + (this.size.getZ() % 16 == 0 ? 0 : 1));
|
||||
|
||||
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket();
|
||||
pocket.setSize(size);
|
||||
|
@ -93,8 +93,8 @@ public class ChunkGenerator extends PocketGenerator {
|
|||
net.minecraft.world.gen.chunk.ChunkGenerator genWorldChunkGenerator = genWorld.getChunkManager().getChunkGenerator();
|
||||
|
||||
ArrayList<Chunk> protoChunks = new ArrayList<>();
|
||||
for (int z = 0; z < ChunkSizeZ; z++) {
|
||||
for (int x = 0; x < ChunkSizeX; x++) {
|
||||
for (int z = 0; z < chunkSizeZ; z++) {
|
||||
for (int x = 0; x < chunkSizeX; x++) {
|
||||
ProtoChunk protoChunk = new ProtoChunk(new ChunkPos(pocket.getOrigin().add(x * 16, 0, z * 16)), UpgradeData.NO_UPGRADE_DATA);
|
||||
protoChunk.setLightingProvider(genWorld.getLightingProvider());
|
||||
protoChunks.add(protoChunk);
|
||||
|
|
|
@ -51,7 +51,7 @@ public final class ModDimensions {
|
|||
}
|
||||
|
||||
public static boolean isPersonalPocketDimension(World world) {
|
||||
return isPocketDimension(world.getRegistryKey());
|
||||
return world != null && world == PERSONAL_POCKET_DIMENSION;
|
||||
}
|
||||
|
||||
public static boolean isPocketDimension(RegistryKey<World> type) {
|
||||
|
|
Loading…
Reference in a new issue