diff --git a/pom.xml b/pom.xml index 809434dbb..b5e28d0cb 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,11 @@ + + com.google.code.gson + gson + 2.8.6 + org.openjfx javafx-controls @@ -56,14 +61,6 @@ commons-primitives 1.0 - - org.json - json - 20180813 - com.google.code.gson - gson - 2.8.6 - org.yaml snakeyaml diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/objectLoader/blocks/Blocks.java b/src/main/java/de/bixilon/minosoft/game/datatypes/objectLoader/blocks/Blocks.java index b2111c628..24e1d8539 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/objectLoader/blocks/Blocks.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/objectLoader/blocks/Blocks.java @@ -471,8 +471,7 @@ public class Blocks { rotation = rotationMapping.get(propertiesJSON.get("rotation").getAsString()); propertiesJSON.remove("rotation"); } - BlockProperties[] properties = new BlockProperties[propertiesJSON.size()]; - int ii = 0; + ArrayList properties = new ArrayList<>(); for (String propertyName : propertiesJSON.keySet()) { if (propertiesMapping.get(propertyName) == null) { throw new RuntimeException(String.format("Unknown block property: %s (identifier=%s)", propertyName, identifierName)); @@ -480,8 +479,7 @@ public class Blocks { if (propertiesMapping.get(propertyName).get(propertiesJSON.get(propertyName).getAsString()) == null) { throw new RuntimeException(String.format("Unknown block property: %s -> %s (identifier=%s)", propertyName, propertiesJSON.get(propertyName).getAsString(), identifierName)); } - properties[ii] = propertiesMapping.get(propertyName).get(propertiesJSON.get(propertyName).getAsString()); - ii++; + properties.add(propertiesMapping.get(propertyName).get(propertiesJSON.get(propertyName).getAsString())); } Block block = new Block(mod, identifierName, properties, rotation); @@ -537,12 +535,12 @@ public class Blocks { return blockId; } - public static boolean propertiesEquals(BlockProperties[] one, BlockProperties[] two) { - if (one.length != two.length) { + public static boolean propertiesEquals(ArrayList one, ArrayList two) { + if (one.size() != two.size()) { return false; } for (BlockProperties property : one) { - if (!containsElement(two, property)) { + if (!two.contains(property)) { return false; } } diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/world/Chunk.java b/src/main/java/de/bixilon/minosoft/game/datatypes/world/Chunk.java index 1c7616f59..b5e636736 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/world/Chunk.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/world/Chunk.java @@ -13,9 +13,8 @@ package de.bixilon.minosoft.game.datatypes.world; -import de.bixilon.minosoft.game.datatypes.blocks.Block; -import de.bixilon.minosoft.game.datatypes.blocks.Blocks; import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block; +import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java b/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java index c9a4da326..aee79f6bd 100644 --- a/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java +++ b/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java @@ -13,8 +13,8 @@ package de.bixilon.minosoft.render; -import de.bixilon.minosoft.game.datatypes.blocks.Block; -import de.bixilon.minosoft.game.datatypes.blocks.Blocks; +import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block; +import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks; import de.bixilon.minosoft.game.datatypes.world.*; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.render.blockModels.BlockModelLoader; diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java index 17595de8f..cd611014f 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java @@ -13,17 +13,17 @@ package de.bixilon.minosoft.render.blockModels; +import com.google.gson.JsonObject; import de.bixilon.minosoft.Config; -import de.bixilon.minosoft.game.datatypes.blocks.Block; -import de.bixilon.minosoft.game.datatypes.blocks.BlockProperties; -import de.bixilon.minosoft.game.datatypes.blocks.Blocks; -import org.json.JSONObject; +import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block; +import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockProperties; +import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.HashMap; +import static de.bixilon.minosoft.util.Util.readJsonFromFile; + public class BlockModelLoader { final HashMap drawDescriptionMap; @@ -67,9 +67,7 @@ public class BlockModelLoader { private void loadModel(String mod, String identifier) throws IOException { String path = Config.homeDir + "assets/" + mod + "/models/block/" + identifier + ".json"; - - String fileContent = new String(Files.readAllBytes(Paths.get(path))); - JSONObject object = new JSONObject(fileContent); + JsonObject object = readJsonFromFile(path); DrawDescription description = new DrawDescription(object); drawDescriptionMap.put(mod + ":" + identifier, description); } diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/DrawDescription.java b/src/main/java/de/bixilon/minosoft/render/blockModels/DrawDescription.java index a34552db1..3eb57e6f0 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/DrawDescription.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/DrawDescription.java @@ -13,10 +13,10 @@ package de.bixilon.minosoft.render.blockModels; +import com.google.gson.JsonObject; import de.bixilon.minosoft.render.MainWindow; import de.bixilon.minosoft.render.face.FaceOrientation; import javafx.util.Pair; -import org.json.JSONObject; import java.util.*; @@ -36,21 +36,20 @@ public class DrawDescription { Map> faces; boolean full = false; // is the block a completely filled block? - public DrawDescription(JSONObject json) { + public DrawDescription(JsonObject json) { if (!(json.has("parent") && json.has("textures"))) return; faces = new HashMap<>(); - JSONObject textures = json.getJSONObject("textures"); + JsonObject textures = json.getAsJsonObject("textures"); - for (Iterator textureIterator = textures.keys(); textureIterator.hasNext(); ) { - String textureUse = textureIterator.next(); + for (String texture : textures.keySet()) { + String textureUse = textures.getAsJsonObject(texture).toString(); - String textureName = textures.getString(textureUse); - Pair texture; + Pair texturePair; try { - texture = MainWindow.getRenderer().getTextureLoader().getTexture(textureName); + texturePair = MainWindow.getRenderer().getTextureLoader().getTexture(texture); } catch (Exception e) { continue; } @@ -71,7 +70,7 @@ public class DrawDescription { } for (FaceOrientation faceOrientation : faceOrientations) { - faces.put(faceOrientation, texture); + faces.put(faceOrientation, texturePair); } } full = true; diff --git a/src/main/java/de/bixilon/minosoft/render/utility/Vec3.java b/src/main/java/de/bixilon/minosoft/render/utility/Vec3.java index c2a78a80a..1d7db8349 100644 --- a/src/main/java/de/bixilon/minosoft/render/utility/Vec3.java +++ b/src/main/java/de/bixilon/minosoft/render/utility/Vec3.java @@ -13,7 +13,7 @@ package de.bixilon.minosoft.render.utility; -import de.bixilon.minosoft.game.datatypes.entities.Location; +import de.bixilon.minosoft.game.datatypes.objectLoader.entities.Location; import static java.lang.Math.pow; import static java.lang.Math.sqrt;