mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
wip implementing of new block system
This commit is contained in:
parent
0d38f8d7e8
commit
ea47b0d89d
13
pom.xml
13
pom.xml
@ -41,6 +41,11 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.8.6</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
<artifactId>javafx-controls</artifactId>
|
<artifactId>javafx-controls</artifactId>
|
||||||
@ -56,14 +61,6 @@
|
|||||||
<artifactId>commons-primitives</artifactId>
|
<artifactId>commons-primitives</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>org.yaml</groupId>
|
<groupId>org.yaml</groupId>
|
||||||
<artifactId>snakeyaml</artifactId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
@ -471,8 +471,7 @@ public class Blocks {
|
|||||||
rotation = rotationMapping.get(propertiesJSON.get("rotation").getAsString());
|
rotation = rotationMapping.get(propertiesJSON.get("rotation").getAsString());
|
||||||
propertiesJSON.remove("rotation");
|
propertiesJSON.remove("rotation");
|
||||||
}
|
}
|
||||||
BlockProperties[] properties = new BlockProperties[propertiesJSON.size()];
|
ArrayList<BlockProperties> properties = new ArrayList<>();
|
||||||
int ii = 0;
|
|
||||||
for (String propertyName : propertiesJSON.keySet()) {
|
for (String propertyName : propertiesJSON.keySet()) {
|
||||||
if (propertiesMapping.get(propertyName) == null) {
|
if (propertiesMapping.get(propertyName) == null) {
|
||||||
throw new RuntimeException(String.format("Unknown block property: %s (identifier=%s)", propertyName, identifierName));
|
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) {
|
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));
|
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());
|
properties.add(propertiesMapping.get(propertyName).get(propertiesJSON.get(propertyName).getAsString()));
|
||||||
ii++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Block block = new Block(mod, identifierName, properties, rotation);
|
Block block = new Block(mod, identifierName, properties, rotation);
|
||||||
@ -537,12 +535,12 @@ public class Blocks {
|
|||||||
return blockId;
|
return blockId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean propertiesEquals(BlockProperties[] one, BlockProperties[] two) {
|
public static boolean propertiesEquals(ArrayList<BlockProperties> one, ArrayList<BlockProperties> two) {
|
||||||
if (one.length != two.length) {
|
if (one.size() != two.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (BlockProperties property : one) {
|
for (BlockProperties property : one) {
|
||||||
if (!containsElement(two, property)) {
|
if (!two.contains(property)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.game.datatypes.world;
|
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.Block;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.render;
|
package de.bixilon.minosoft.render;
|
||||||
|
|
||||||
import de.bixilon.minosoft.game.datatypes.blocks.Block;
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||||
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
||||||
import de.bixilon.minosoft.game.datatypes.world.*;
|
import de.bixilon.minosoft.game.datatypes.world.*;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
|
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
|
||||||
|
@ -13,17 +13,17 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.render.blockModels;
|
package de.bixilon.minosoft.render.blockModels;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import de.bixilon.minosoft.Config;
|
import de.bixilon.minosoft.Config;
|
||||||
import de.bixilon.minosoft.game.datatypes.blocks.Block;
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||||
import de.bixilon.minosoft.game.datatypes.blocks.BlockProperties;
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockProperties;
|
||||||
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
|
||||||
|
|
||||||
public class BlockModelLoader {
|
public class BlockModelLoader {
|
||||||
final HashMap<String, DrawDescription> drawDescriptionMap;
|
final HashMap<String, DrawDescription> drawDescriptionMap;
|
||||||
|
|
||||||
@ -67,9 +67,7 @@ public class BlockModelLoader {
|
|||||||
|
|
||||||
private void loadModel(String mod, String identifier) throws IOException {
|
private void loadModel(String mod, String identifier) throws IOException {
|
||||||
String path = Config.homeDir + "assets/" + mod + "/models/block/" + identifier + ".json";
|
String path = Config.homeDir + "assets/" + mod + "/models/block/" + identifier + ".json";
|
||||||
|
JsonObject object = readJsonFromFile(path);
|
||||||
String fileContent = new String(Files.readAllBytes(Paths.get(path)));
|
|
||||||
JSONObject object = new JSONObject(fileContent);
|
|
||||||
DrawDescription description = new DrawDescription(object);
|
DrawDescription description = new DrawDescription(object);
|
||||||
drawDescriptionMap.put(mod + ":" + identifier, description);
|
drawDescriptionMap.put(mod + ":" + identifier, description);
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.render.blockModels;
|
package de.bixilon.minosoft.render.blockModels;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import de.bixilon.minosoft.render.MainWindow;
|
import de.bixilon.minosoft.render.MainWindow;
|
||||||
import de.bixilon.minosoft.render.face.FaceOrientation;
|
import de.bixilon.minosoft.render.face.FaceOrientation;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -36,21 +36,20 @@ public class DrawDescription {
|
|||||||
Map<FaceOrientation, Pair<Float, Float>> faces;
|
Map<FaceOrientation, Pair<Float, Float>> faces;
|
||||||
boolean full = false; // is the block a completely filled block?
|
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;
|
if (!(json.has("parent") && json.has("textures"))) return;
|
||||||
|
|
||||||
faces = new HashMap<>();
|
faces = new HashMap<>();
|
||||||
|
|
||||||
JSONObject textures = json.getJSONObject("textures");
|
JsonObject textures = json.getAsJsonObject("textures");
|
||||||
|
|
||||||
for (Iterator<String> textureIterator = textures.keys(); textureIterator.hasNext(); ) {
|
for (String texture : textures.keySet()) {
|
||||||
String textureUse = textureIterator.next();
|
String textureUse = textures.getAsJsonObject(texture).toString();
|
||||||
|
|
||||||
String textureName = textures.getString(textureUse);
|
Pair<Float, Float> texturePair;
|
||||||
Pair<Float, Float> texture;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
texture = MainWindow.getRenderer().getTextureLoader().getTexture(textureName);
|
texturePair = MainWindow.getRenderer().getTextureLoader().getTexture(texture);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -71,7 +70,7 @@ public class DrawDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (FaceOrientation faceOrientation : faceOrientations) {
|
for (FaceOrientation faceOrientation : faceOrientations) {
|
||||||
faces.put(faceOrientation, texture);
|
faces.put(faceOrientation, texturePair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
full = true;
|
full = true;
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.render.utility;
|
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.pow;
|
||||||
import static java.lang.Math.sqrt;
|
import static java.lang.Math.sqrt;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user