wip implementing of new block system

This commit is contained in:
Lukas 2020-07-25 17:27:29 +02:00
parent 0d38f8d7e8
commit ea47b0d89d
7 changed files with 29 additions and 38 deletions

13
pom.xml
View File

@ -41,6 +41,11 @@
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
@ -56,14 +61,6 @@
<artifactId>commons-primitives</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>

View File

@ -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<BlockProperties> 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<BlockProperties> one, ArrayList<BlockProperties> two) {
if (one.size() != two.size()) {
return false;
}
for (BlockProperties property : one) {
if (!containsElement(two, property)) {
if (!two.contains(property)) {
return false;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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<String, DrawDescription> 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);
}

View File

@ -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<FaceOrientation, Pair<Float, Float>> 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<String> 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<Float, Float> texture;
Pair<Float, Float> 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;

View File

@ -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;