some cleaning & fixes

This commit is contained in:
CreepyCre 2021-02-04 14:13:57 +01:00
parent 0df83c8c0d
commit bd030ec374
3 changed files with 10 additions and 27 deletions

View file

@ -42,7 +42,7 @@ public class SchematicV2Handler {
try { try {
Path path = Paths.get(SchematicV2Handler.class.getResource("/data/dimdoors/pockets/generators").toURI()); 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); LOGGER.info("Loaded pockets in {} seconds", System.currentTimeMillis() - startTime);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
LOGGER.error(e); LOGGER.error(e);
@ -51,14 +51,14 @@ public class SchematicV2Handler {
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
try { try {
Path path = Paths.get(SchematicV2Handler.class.getResource("/data/dimdoors/pockets/groups").toURI()); 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); LOGGER.info("Loaded pocket groups in {} seconds", System.currentTimeMillis() - startTime);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
LOGGER.error(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)) { if (Files.isDirectory(path)) {
try { try {
for (Path directoryPath : Files.newDirectoryStream(path)) { for (Path directoryPath : Files.newDirectoryStream(path)) {
@ -66,7 +66,7 @@ public class SchematicV2Handler {
String fileName = directoryPath.getFileName().toString(); String fileName = directoryPath.getFileName().toString();
if (Files.isRegularFile(directoryPath)) fileName = fileName.substring(0, fileName.lastIndexOf('.')); // cut extension if (Files.isRegularFile(directoryPath)) fileName = fileName.substring(0, fileName.lastIndexOf('.')); // cut extension
directoryIdParts[directoryIdParts.length - 1] = fileName; directoryIdParts[directoryIdParts.length - 1] = fileName;
loadCompound(directoryPath, directoryIdParts, loader); loadJson(directoryPath, directoryIdParts, loader);
} }
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("could not load pocket data in path " + path.toString() + " due to malformed json.", 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); String id = String.join(".", idParts);
try { try {
JsonElement json = GSON.fromJson(String.join("", Files.readAllLines(path)), JsonElement.class); 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) { } catch (IOException e) {
LOGGER.error("could not load pocket data in path " + path.toString() + " due to malformed json.", 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) { private void loadPocketGroup(String id, Tag tag) {
VirtualPocket group = VirtualPocket.deserialize(tag); VirtualPocket group = VirtualPocket.deserialize(tag);
LOGGER.info(VirtualPocket.serialize(group).toString()); LOGGER.info(VirtualPocket.serialize(group).toString());

View file

@ -80,8 +80,8 @@ public class ChunkGenerator extends PocketGenerator {
ServerWorld world = parameters.getWorld(); ServerWorld world = parameters.getWorld();
VirtualLocation sourceVirtualLocation = parameters.getSourceVirtualLocation(); VirtualLocation sourceVirtualLocation = parameters.getSourceVirtualLocation();
int ChunkSizeX = ((this.size.getX() >> 4) + (this.size.getX() % 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)); int chunkSizeZ = ((this.size.getZ() >> 4) + (this.size.getZ() % 16 == 0 ? 0 : 1));
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket(); Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket();
pocket.setSize(size); pocket.setSize(size);
@ -93,8 +93,8 @@ public class ChunkGenerator extends PocketGenerator {
net.minecraft.world.gen.chunk.ChunkGenerator genWorldChunkGenerator = genWorld.getChunkManager().getChunkGenerator(); net.minecraft.world.gen.chunk.ChunkGenerator genWorldChunkGenerator = genWorld.getChunkManager().getChunkGenerator();
ArrayList<Chunk> protoChunks = new ArrayList<>(); ArrayList<Chunk> protoChunks = new ArrayList<>();
for (int z = 0; z < ChunkSizeZ; z++) { for (int z = 0; z < chunkSizeZ; z++) {
for (int x = 0; x < ChunkSizeX; x++) { 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 protoChunk = new ProtoChunk(new ChunkPos(pocket.getOrigin().add(x * 16, 0, z * 16)), UpgradeData.NO_UPGRADE_DATA);
protoChunk.setLightingProvider(genWorld.getLightingProvider()); protoChunk.setLightingProvider(genWorld.getLightingProvider());
protoChunks.add(protoChunk); protoChunks.add(protoChunk);

View file

@ -51,7 +51,7 @@ public final class ModDimensions {
} }
public static boolean isPersonalPocketDimension(World world) { public static boolean isPersonalPocketDimension(World world) {
return isPocketDimension(world.getRegistryKey()); return world != null && world == PERSONAL_POCKET_DIMENSION;
} }
public static boolean isPocketDimension(RegistryKey<World> type) { public static boolean isPocketDimension(RegistryKey<World> type) {