mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
new block loading system v2 wip1
This commit is contained in:
parent
76cef9baeb
commit
c4f3c25d2a
@ -100,10 +100,8 @@ public class MainWindow {
|
|||||||
public static void pause() {
|
public static void pause() {
|
||||||
renderMode = MAIN_MENU;
|
renderMode = MAIN_MENU;
|
||||||
glfwSetInputMode(openGLWindow.getWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(openGLWindow.getWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
try {
|
assert connection != null;
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Connection getConnection() {
|
public static Connection getConnection() {
|
||||||
@ -111,7 +109,7 @@ public class MainWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void close() {
|
public static void close() {
|
||||||
System.exit(1);
|
//System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerController getPlayerController() {
|
public static PlayerController getPlayerController() {
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Codename Minosoft
|
||||||
|
* Copyright (C) 2020 Lukas Eisenhauer
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.render.blockModels;
|
||||||
|
|
||||||
|
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.BlockRotation;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class BlockConfiguration {
|
||||||
|
HashSet<BlockRotation> rotations;
|
||||||
|
HashSet<BlockProperties> blockProperties;
|
||||||
|
|
||||||
|
public BlockConfiguration(String config) {
|
||||||
|
rotations = new HashSet<>();
|
||||||
|
blockProperties = new HashSet<>();
|
||||||
|
for (String configuration : config.split(",")) {
|
||||||
|
switch (configuration) {
|
||||||
|
case "orientation:vertical":
|
||||||
|
rotations.add(BlockRotation.UP);
|
||||||
|
rotations.add(BlockRotation.DOWN);
|
||||||
|
break;
|
||||||
|
case "orientation:up":
|
||||||
|
rotations.add(BlockRotation.UP);
|
||||||
|
break;
|
||||||
|
case "orientation:down":
|
||||||
|
rotations.add(BlockRotation.DOWN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<BlockRotation> getRotations() {
|
||||||
|
return rotations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<BlockProperties> getBlockProperties() {
|
||||||
|
return blockProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(BlockConfiguration blockConfiguration) {
|
||||||
|
return rotations.equals(blockConfiguration.getRotations()) &&
|
||||||
|
blockProperties.equals(blockConfiguration.getBlockProperties());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(Block block) {
|
||||||
|
if (!rotations.contains(block.getRotation()) && block.getRotation() != BlockRotation.NONE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BlockProperties property : blockProperties) {
|
||||||
|
if (!block.getProperties().contains(property)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Codename Minosoft
|
* Codename Minosoft
|
||||||
* Copyright (C) 2020 Moritz Zwerger
|
* Copyright (C) 2020 Lukas Eisenhauer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -16,6 +16,7 @@ package de.bixilon.minosoft.render.blockModels;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import de.bixilon.minosoft.Config;
|
import de.bixilon.minosoft.Config;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||||
import de.bixilon.minosoft.render.fullFace.FaceOrientation;
|
import de.bixilon.minosoft.render.fullFace.FaceOrientation;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -25,15 +26,43 @@ import java.util.HashSet;
|
|||||||
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
|
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
|
||||||
|
|
||||||
public class BlockDescription {
|
public class BlockDescription {
|
||||||
HashSet<SubBlock> subBlocks;
|
HashSet<SubBlock> defaultState;
|
||||||
|
HashMap<BlockConfiguration, HashSet<SubBlock>> blockConfigurationStates;
|
||||||
boolean isFull;
|
boolean isFull;
|
||||||
|
|
||||||
public BlockDescription(JsonObject json, HashMap<String, String> variables) {
|
public BlockDescription(JsonElement child, String identifier, String mod) {
|
||||||
subBlocks = new HashSet<>();
|
if (child.getAsString().equals("invisible")) {
|
||||||
if (!json.has("textures")) {
|
return;
|
||||||
//throw new IllegalArgumentException("could not find 'textures' in json");
|
} else if (child.getAsString().equals("regular")) {
|
||||||
|
defaultState = load(mod, identifier, new HashMap<>());
|
||||||
|
} else {
|
||||||
|
JsonObject childJson = child.getAsJsonObject();
|
||||||
|
for (String state : childJson.keySet()) {
|
||||||
|
if (state.equals("else")) {
|
||||||
|
defaultState = load(mod, childJson.get("else").getAsString(), new HashMap<>());
|
||||||
}
|
}
|
||||||
|
blockConfigurationStates.put(new BlockConfiguration(state),
|
||||||
|
load(mod, childJson.get(state).getAsString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (SubBlock subBlock : defaultState) {
|
||||||
|
if (subBlock.isFull()) {
|
||||||
|
isFull = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashSet<SubBlock> load(String mod, String identifier, HashMap<String, String> variables) {
|
||||||
|
String path = Config.homeDir + "assets/" + mod + "/models/block/" + identifier + ".json";
|
||||||
|
JsonObject json = null;
|
||||||
try {
|
try {
|
||||||
|
json = readJsonFromFile(path);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
HashSet<SubBlock> result = new HashSet<>();
|
||||||
|
try {
|
||||||
|
// read the textures into a variable hashmap
|
||||||
JsonObject textures = json.getAsJsonObject("textures");
|
JsonObject textures = json.getAsJsonObject("textures");
|
||||||
for (String texture : textures.keySet()) {
|
for (String texture : textures.keySet()) {
|
||||||
if (texture.contains("#") && variables.containsKey(texture)) {
|
if (texture.contains("#") && variables.containsKey(texture)) {
|
||||||
@ -43,42 +72,32 @@ public class BlockDescription {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (json.has("elements")) {
|
if (json.has("elements")) {
|
||||||
for (JsonElement subBlockJson : json.get("elements").getAsJsonArray()) {
|
for (JsonElement subBlockJson : json.get("elements").getAsJsonArray()) {
|
||||||
subBlocks.add(new SubBlock(subBlockJson.getAsJsonObject(), variables));
|
result.add(new SubBlock(subBlockJson.getAsJsonObject(), variables));
|
||||||
}
|
}
|
||||||
} else if (json.has("parent") && !json.get("parent").getAsString().equals("block/block")) {
|
} else if (json.has("parent") && !json.get("parent").getAsString().equals("block/block")) {
|
||||||
String parent = json.get("parent").getAsString();
|
String parent = json.get("parent").getAsString();
|
||||||
String path = Config.homeDir + "assets/minecraft/models/" + parent + ".json";
|
String parentIdentifier = parent.substring(parent.lastIndexOf("/") + 1);
|
||||||
try {
|
result.addAll(load(mod, parentIdentifier, variables));
|
||||||
subBlocks.addAll(new BlockDescription(readJsonFromFile(path), variables).subBlocks);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("json does not have a parent nor subblocks");
|
throw new IllegalArgumentException("json does not have a parent nor subblocks");
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
for (SubBlock subBlock : subBlocks) {
|
|
||||||
if (subBlock.isFull()) {
|
|
||||||
isFull = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockDescription(JsonObject json) {
|
private HashSet<SubBlock> load(String mod, String identifier) {
|
||||||
this(json, new HashMap<>());
|
return load(mod, identifier, new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFull() {
|
public boolean isFull() {
|
||||||
return isFull;
|
return isFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<Face> prepare(HashMap<FaceOrientation, Boolean> adjacentBlocks) {
|
public HashSet<Face> prepare(Block block, HashMap<FaceOrientation, Boolean> adjacentBlocks) {
|
||||||
HashSet<Face> result = new HashSet<>();
|
HashSet<Face> result = new HashSet<>();
|
||||||
for (SubBlock subBlock : subBlocks) {
|
for (SubBlock subBlock : defaultState) {
|
||||||
result.addAll(subBlock.getFaces(adjacentBlocks));
|
result.addAll(subBlock.getFaces(adjacentBlocks));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -13,366 +13,52 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.render.blockModels;
|
package de.bixilon.minosoft.render.blockModels;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import de.bixilon.minosoft.Config;
|
import de.bixilon.minosoft.Config;
|
||||||
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.BlockProperties;
|
|
||||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.render.fullFace.FaceOrientation;
|
import de.bixilon.minosoft.render.fullFace.FaceOrientation;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
|
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
|
||||||
|
|
||||||
public class BlockModelLoader {
|
public class BlockModelLoader {
|
||||||
// a list of blocks not drawn by the world renderer
|
|
||||||
public static final List<String> ignoredBlocks = new ArrayList<>(Arrays.asList(
|
|
||||||
"air", "cave_air", "void_air", "moving_piston", "shrub", "structure_void", "water", "lava",
|
|
||||||
//TODO
|
|
||||||
"chest", "trapped_chest", "oak_fence"
|
|
||||||
));
|
|
||||||
|
|
||||||
public BlockModelLoader() {
|
public BlockModelLoader() {
|
||||||
blockDescriptionMap = new HashMap<>();
|
blockDescriptionMap = new HashMap<>();
|
||||||
loadModels();
|
try {
|
||||||
}
|
String folderPath = Config.homeDir + "assets/mapping/blockModels/";
|
||||||
|
for (File file : new File(folderPath).listFiles()) {
|
||||||
final HashMap<String, HashMap<String, BlockDescription>> blockDescriptionMap;
|
JsonObject blockList = readJsonFromFile(file.getAbsolutePath());
|
||||||
|
String mod = file.getName().substring(0, file.getName().lastIndexOf('.'));
|
||||||
private void loadModels() {
|
loadModels(blockList, mod);
|
||||||
for (Block block : Blocks.getBlockList()) {
|
}
|
||||||
String mod = block.getMod();
|
} catch (IOException | NullPointerException e) {
|
||||||
String identifier = block.getIdentifier();
|
e.printStackTrace();
|
||||||
|
|
||||||
if (ignoredBlocks.contains(identifier)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!blockDescriptionMap.containsKey(mod)) {
|
|
||||||
blockDescriptionMap.put(mod, new HashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blockDescriptionMap.containsKey(mod + ":" + identifier)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (identifier.equals("silver_glazed_terracotta")) {
|
|
||||||
loadModel(mod, "light_gray_glazed_terracotta");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("flower_upper_block")) {
|
|
||||||
// WHAT EVEN IS THIS BLOCK!?!?!
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("bubble_column")) {
|
|
||||||
// handled with client side "particles"
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("barrier")) {
|
|
||||||
// TODO: display barriers if setting is enabled
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("end_portal") || identifier.equals("end_gateway")) {
|
|
||||||
// TODO: display end portals (the portal itself, not the frames
|
|
||||||
// probably with a shader
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("structure_void")) {
|
|
||||||
// is not displayed
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("infested")) {
|
|
||||||
// same block model as the not infested blocks
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("conduit")) {
|
|
||||||
// shown as entity
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("piston_extension")) {
|
|
||||||
// TODO: handle pistons
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("skull") || identifier.contains("head")) {
|
|
||||||
// TODO: handle skulls
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("water")) {
|
|
||||||
// TODO: handle water
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("lava")) {
|
|
||||||
// TODO: handle lava
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("chest")) {
|
|
||||||
// TODO: handle chests (trapped or not)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("banner")) {
|
|
||||||
// TODO: handle banners
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("shulker_box")) {
|
|
||||||
// TODO: handle shulker_boxes
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("sign")) {
|
|
||||||
// TODO: handle signs
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("fire")) {
|
|
||||||
// TODO: handle fire
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("tripwire_hook")) {
|
|
||||||
loadModel(mod, identifier);
|
|
||||||
loadModel(mod, identifier + "_attached");
|
|
||||||
loadModel(mod, identifier + "_attached_on");
|
|
||||||
loadModel(mod, identifier + "_on");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("brewing_stand")) {
|
|
||||||
loadModel(mod, identifier);
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
loadModel(mod, identifier + "_bottle" + i);
|
|
||||||
loadModel(mod, identifier + "_empty" + i);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("daylight_detector")) {
|
|
||||||
loadModel(mod, identifier);
|
|
||||||
loadModel(mod, identifier + "_inverted");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("lever")) {
|
|
||||||
loadModel(mod, identifier);
|
|
||||||
loadModel(mod, identifier + "_on");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("comparator")) {
|
|
||||||
loadModel(mod, identifier);
|
|
||||||
loadModel(mod, identifier + "_on");
|
|
||||||
loadModel(mod, identifier + "_on_subtract");
|
|
||||||
loadModel(mod, identifier + "_subtract");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("trapdoor")) {
|
|
||||||
loadModel(mod, identifier + "_bottom");
|
|
||||||
loadModel(mod, identifier + "_open");
|
|
||||||
loadModel(mod, identifier + "_top");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("pane")) {
|
|
||||||
loadModel(mod, identifier + "_noside");
|
|
||||||
loadModel(mod, identifier + "_noside_alt");
|
|
||||||
loadModel(mod, identifier + "_Post");
|
|
||||||
loadModel(mod, identifier + "_side");
|
|
||||||
loadModel(mod, identifier + "_side_alt");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("iron_bars")) {
|
|
||||||
loadModel(mod, identifier + "_cap");
|
|
||||||
loadModel(mod, identifier + "_cap_alt");
|
|
||||||
loadModel(mod, identifier + "_post");
|
|
||||||
loadModel(mod, identifier + "_post_ends");
|
|
||||||
loadModel(mod, identifier + "_side");
|
|
||||||
loadModel(mod, identifier + "_side_alt");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.endsWith("bed") && !blockDescriptionMap.containsKey(mod + ":bed")) {
|
|
||||||
// TODO: handle beds
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("vine")) {
|
|
||||||
loadModel(mod, identifier + "_1");
|
|
||||||
loadModel(mod, identifier + "_1u");
|
|
||||||
loadModel(mod, identifier + "_2");
|
|
||||||
loadModel(mod, identifier + "_2u");
|
|
||||||
loadModel(mod, identifier + "_2_opposite");
|
|
||||||
loadModel(mod, identifier + "_2u_opposite");
|
|
||||||
loadModel(mod, identifier + "_3");
|
|
||||||
loadModel(mod, identifier + "_3u");
|
|
||||||
loadModel(mod, identifier + "_4");
|
|
||||||
loadModel(mod, identifier + "_4u");
|
|
||||||
loadModel(mod, identifier + "_u");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("tripwire")) {
|
|
||||||
loadModel(mod, identifier + "_attached_n");
|
|
||||||
loadModel(mod, identifier + "_attached_ne");
|
|
||||||
loadModel(mod, identifier + "_attached_ns");
|
|
||||||
loadModel(mod, identifier + "_attached_nse");
|
|
||||||
loadModel(mod, identifier + "_attached_nsew");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("scaffolding")) {
|
|
||||||
loadModel(mod, identifier + "_stable");
|
|
||||||
loadModel(mod, identifier + "_unstable");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("bell")) {
|
|
||||||
loadModel(mod, identifier + "_between_walls");
|
|
||||||
loadModel(mod, identifier + "_ceiling");
|
|
||||||
loadModel(mod, identifier + "_floor");
|
|
||||||
loadModel(mod, identifier + "_wall");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("frosted_ice")) {
|
|
||||||
loadModel(mod, identifier + "_0");
|
|
||||||
loadModel(mod, identifier + "_1");
|
|
||||||
loadModel(mod, identifier + "_2");
|
|
||||||
loadModel(mod, identifier + "_3");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("redstone_wire")) {
|
|
||||||
loadModel(mod, "redstone_dust_dot");
|
|
||||||
/*
|
|
||||||
loadModel(mod, "redstone_dust_side");
|
|
||||||
loadModel(mod, "redstone_dust_side_alt");
|
|
||||||
loadModel(mod, "redstone_dust_side_alt0");
|
|
||||||
loadModel(mod, "redstone_dust_side_alt1");
|
|
||||||
loadModel(mod, "redstone_dust_side0");
|
|
||||||
loadModel(mod, "redstone_dust_side1");
|
|
||||||
loadModel(mod, "redstone_dust_up");
|
|
||||||
*/ // throws error, can't find variable
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("brown_mushroom_stem")) {
|
|
||||||
loadModel(mod, "brown_mushroom_block");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("red_mushroom_stem")) {
|
|
||||||
loadModel(mod, "red_mushroom_block");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("snow")) {
|
|
||||||
for (int height = 2; height < 16; height += 2) {
|
|
||||||
loadModel(mod, identifier + "_height" + height);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("bamboo")) {
|
|
||||||
loadModel(mod, identifier + "_large_leaves");
|
|
||||||
loadModel(mod, identifier + "_sapling");
|
|
||||||
loadModel(mod, identifier + "_small_leaves");
|
|
||||||
for (int variation = 1; variation < 5; variation++) {
|
|
||||||
for (int age = 0; age < 2; age++) {
|
|
||||||
loadModel(mod, identifier + variation + "_age" + age);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("wheat")) {
|
|
||||||
for (int stage = 0; stage < 8; stage++) {
|
|
||||||
loadModel(mod, identifier + "_stage" + stage);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("potatoes") || identifier.equals("carrots") ||
|
|
||||||
identifier.equals("beetroots") || identifier.equals("sweet_berry_bush")) {
|
|
||||||
for (int stage = 0; stage < 4; stage++) {
|
|
||||||
loadModel(mod, identifier + "_stage" + stage);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("nether_wart")) {
|
|
||||||
for (int stage = 0; stage < 3; stage++) {
|
|
||||||
loadModel(mod, identifier + "_stage" + stage);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("waterlily")) {
|
|
||||||
loadModel(mod, "lily_pad");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("nether_brick")) {
|
|
||||||
loadModel(mod, "nether_bricks");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("quartz_ore")) {
|
|
||||||
loadModel(mod, "nether_" + identifier);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("end_bricks")) {
|
|
||||||
loadModel(mod, "end_stone_bricks");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("cocoa")) {
|
|
||||||
for (int stage = 0; stage < 3; stage++) {
|
|
||||||
loadModel(mod, identifier + "_stage" + stage);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("melon_stem") || identifier.equals("pumpkin_stem")) {
|
|
||||||
for (int stage = 0; stage < 8; stage++) {
|
|
||||||
loadModel(mod, identifier + "_stage" + stage);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("repeater")) {
|
|
||||||
for (int ticks = 1; ticks < 5; ticks++) {
|
|
||||||
loadModel(mod, identifier + "_" + ticks + "tick");
|
|
||||||
loadModel(mod, identifier + "_" + ticks + "tick_locked");
|
|
||||||
loadModel(mod, identifier + "_" + ticks + "tick_on");
|
|
||||||
loadModel(mod, identifier + "_" + ticks + "tick_on_locked");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("door")) {
|
|
||||||
loadModel(mod, identifier + "_bottom");
|
|
||||||
loadModel(mod, identifier + "_bottom_hinge");
|
|
||||||
loadModel(mod, identifier + "_top");
|
|
||||||
loadModel(mod, identifier + "_top_hinge");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.endsWith("wall") || identifier.endsWith("fence")) {
|
|
||||||
loadModel(mod, identifier + "_inventory");
|
|
||||||
loadModel(mod, identifier + "_post");
|
|
||||||
loadModel(mod, identifier + "_side");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.contains("large") || identifier.contains("tall") || identifier.equals("sunflower") ||
|
|
||||||
identifier.equals("rose_bush") || identifier.equals("lilac") || identifier.equals("peony")) {
|
|
||||||
loadModel(mod, identifier + "_bottom");
|
|
||||||
loadModel(mod, identifier + "_top");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("nether_portal")) {
|
|
||||||
loadModel(mod, identifier + "_ew");
|
|
||||||
loadModel(mod, identifier + "_ns");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (identifier.equals("slime")) {
|
|
||||||
loadModel(mod, identifier + "_block");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
loadModel(mod, identifier);
|
|
||||||
}
|
}
|
||||||
Log.info("finished loading all block descriptions");
|
Log.info("finished loading all block descriptions");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleProperties(Block block) {
|
final HashMap<String, HashMap<String, BlockDescription>> blockDescriptionMap;
|
||||||
return !block.getProperties().contains(BlockProperties.NONE) && block.getProperties().size() != 0;
|
|
||||||
|
private void loadModels(JsonObject blockList, String mod) {
|
||||||
|
blockDescriptionMap.put(mod, new HashMap<>());
|
||||||
|
for (String identifier : blockList.keySet()) {
|
||||||
|
JsonElement child = blockList.get(identifier);
|
||||||
|
loadModel(mod, identifier, child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadModel(String mod, String identifier) {
|
private void loadModel(String mod, String identifier, JsonElement child) {
|
||||||
if (blockDescriptionMap.containsKey(mod) && blockDescriptionMap.get(mod).containsKey(identifier)) {
|
|
||||||
// a description for that block already exists. checking because Blocks.getBlockList()
|
|
||||||
// returns all blocks with all possible combinations (rotation, etc.)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
String path = Config.homeDir + "assets/" + mod + "/models/block/" + identifier + ".json";
|
|
||||||
JsonObject json = readJsonFromFile(path);
|
|
||||||
BlockDescription description = new BlockDescription(json);
|
|
||||||
|
|
||||||
HashMap<String, BlockDescription> modList = blockDescriptionMap.get(mod);
|
HashMap<String, BlockDescription> modList = blockDescriptionMap.get(mod);
|
||||||
|
BlockDescription description = new BlockDescription(child, identifier, mod);
|
||||||
modList.put(identifier, description);
|
modList.put(identifier, description);
|
||||||
} catch (IOException e) {
|
|
||||||
Log.debug("could not find block model for block " + mod + ":" + identifier);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println(mod + ":" + identifier);
|
System.out.println(mod + ":" + identifier);
|
||||||
@ -382,9 +68,6 @@ public class BlockModelLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockDescription getBlockDescription(Block block) {
|
public BlockDescription getBlockDescription(Block block) {
|
||||||
if (ignoredBlocks.contains(block.getIdentifier())) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!blockDescriptionMap.containsKey(block.getMod())) {
|
if (!blockDescriptionMap.containsKey(block.getMod())) {
|
||||||
System.out.println(String.format("No mod %s found", block.getMod()));
|
System.out.println(String.format("No mod %s found", block.getMod()));
|
||||||
//System.exit(-1);
|
//System.exit(-1);
|
||||||
@ -413,6 +96,6 @@ public class BlockModelLoader {
|
|||||||
if (description == null) {
|
if (description == null) {
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
return description.prepare(adjacentBlocks);
|
return description.prepare(block, adjacentBlocks);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,6 @@
|
|||||||
package de.bixilon.minosoft.render.texture;
|
package de.bixilon.minosoft.render.texture;
|
||||||
|
|
||||||
import de.bixilon.minosoft.Config;
|
import de.bixilon.minosoft.Config;
|
||||||
import de.bixilon.minosoft.render.utility.Triplet;
|
|
||||||
import de.matthiasmann.twl.utils.PNGDecoder;
|
import de.matthiasmann.twl.utils.PNGDecoder;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
|
|
||||||
@ -47,9 +46,8 @@ public class TextureLoader {
|
|||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
ioException.printStackTrace();
|
ioException.printStackTrace();
|
||||||
}
|
}
|
||||||
PNGDecoder decoder = null;
|
|
||||||
try {
|
try {
|
||||||
decoder = new PNGDecoder(new FileInputStream(
|
PNGDecoder decoder = new PNGDecoder(new FileInputStream(
|
||||||
Config.homeDir + "assets/allTextures.png"));
|
Config.homeDir + "assets/allTextures.png"));
|
||||||
ByteBuffer buf = ByteBuffer.allocateDirect(decoder.getWidth() * decoder.getHeight() * 4);
|
ByteBuffer buf = ByteBuffer.allocateDirect(decoder.getWidth() * decoder.getHeight() * 4);
|
||||||
decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
|
decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
|
||||||
@ -60,39 +58,6 @@ public class TextureLoader {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int makeGreen(int rgb) {
|
|
||||||
// this method has some bugs but it looks cool so let's just say it is an intended mechanic
|
|
||||||
Triplet<Float, Float, Float> rgbValues = getRGBTriplet(rgb);
|
|
||||||
float brightness = getBrightness(rgbValues);
|
|
||||||
rgbValues = multiply(new Triplet<>(94f / 255f, 157f / 255f, 52f / 255f), rgbValues.item1);
|
|
||||||
return getRGBInt(rgbValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Triplet<Float, Float, Float> multiply(Triplet<Float, Float, Float> rgbValues, float value) {
|
|
||||||
rgbValues.item1 *= value;
|
|
||||||
rgbValues.item2 *= value;
|
|
||||||
rgbValues.item3 *= value;
|
|
||||||
return rgbValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getRGBInt(Triplet<Float, Float, Float> rgbValues) {
|
|
||||||
int red = (int) (rgbValues.item1 * 255);
|
|
||||||
int green = (int) (rgbValues.item2 * 255);
|
|
||||||
int blue = (int) (rgbValues.item3 * 255);
|
|
||||||
return ((red << 16) | (green << 8) | blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Triplet<Float, Float, Float> getRGBTriplet(int rgb) {
|
|
||||||
float red = (float) ((rgb >>> 16) & 0xFF) / 16f;
|
|
||||||
float green = (float) ((rgb >> 8) & 0xFF) / 16f;
|
|
||||||
float blue = (float) ((rgb) & 0xFF) / 16f;
|
|
||||||
return new Triplet<>(red, green, blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static float getBrightness(Triplet<Float, Float, Float> rgbValues) {
|
|
||||||
return .2126f * rgbValues.item1 + .7152f * rgbValues.item2 + .0722f * rgbValues.item3;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadTextures(String textureFolder) throws IOException {
|
private void loadTextures(String textureFolder) throws IOException {
|
||||||
// Any animated block will be stationary
|
// Any animated block will be stationary
|
||||||
File[] textureFiles = new File(textureFolder).listFiles();
|
File[] textureFiles = new File(textureFolder).listFiles();
|
||||||
@ -127,9 +92,6 @@ public class TextureLoader {
|
|||||||
for (int y = 0; y < TEXTURE_PACK_RES; y++) {
|
for (int y = 0; y < TEXTURE_PACK_RES; y++) {
|
||||||
for (int xPixel = 0; xPixel < TEXTURE_PACK_RES; xPixel++) {
|
for (int xPixel = 0; xPixel < TEXTURE_PACK_RES; xPixel++) {
|
||||||
int rgb = img.getRGB(xPixel, y);
|
int rgb = img.getRGB(xPixel, y);
|
||||||
if (allTextures.get(xPos).getValue().equals("grass_block_top")) {
|
|
||||||
rgb = makeGreen(rgb);
|
|
||||||
}
|
|
||||||
totalImage.setRGB(xPos * TEXTURE_PACK_RES + xPixel, y, rgb);
|
totalImage.setRGB(xPos * TEXTURE_PACK_RES + xPixel, y, rgb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
59
src/main/resources/assets/mapping/blockModels/minecraft.json
Normal file
59
src/main/resources/assets/mapping/blockModels/minecraft.json
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"stone": "regular",
|
||||||
|
"granite": "regular",
|
||||||
|
"polished_granite": "regular",
|
||||||
|
"diorite": "regular",
|
||||||
|
"polished_diorite": "regular",
|
||||||
|
"andesite": "regular",
|
||||||
|
"polished_andesite": "regular",
|
||||||
|
"grass_block": "regular",
|
||||||
|
"dirt": "regular",
|
||||||
|
"coarse_dirt": "regular",
|
||||||
|
"podzol": "regular",
|
||||||
|
"cobblestone": "regular",
|
||||||
|
"oak_planks": "regular",
|
||||||
|
"spruce_planks": "regular",
|
||||||
|
"birch_planks": "regular",
|
||||||
|
"jungle_planks": "regular",
|
||||||
|
"acacia_planks": "regular",
|
||||||
|
"dark_oak_planks": "regular",
|
||||||
|
"oak_sapling": "regular",
|
||||||
|
"spruce_sapling": "regular",
|
||||||
|
"birch_sapling": "regular",
|
||||||
|
"jungle_sapling": "regular",
|
||||||
|
"acacia_sapling": "regular",
|
||||||
|
"dark_oak_sapling": "regular",
|
||||||
|
"bedrock": "regular",
|
||||||
|
"sand": "regular",
|
||||||
|
"red_sand": "regular",
|
||||||
|
"gravel": "regular",
|
||||||
|
"gold_ore": "regular",
|
||||||
|
"iron_ore": "regular",
|
||||||
|
"coal_ore": "regular",
|
||||||
|
"spruce_log": "regular",
|
||||||
|
"birch_log": "regular",
|
||||||
|
"jungle_log": "regular",
|
||||||
|
"dark_oak_log": "regular",
|
||||||
|
"oak_leaves": "regular",
|
||||||
|
"spruce_leaves": "regular",
|
||||||
|
"jungle_leaves": "regular",
|
||||||
|
"birch_leaves": "regular",
|
||||||
|
"dark_oak_leaves": "regular",
|
||||||
|
"sponge": "regular",
|
||||||
|
"wet_sponge": "regular",
|
||||||
|
"glass": "regular",
|
||||||
|
"lapis_ore": "regular",
|
||||||
|
"lapis_block": "regular",
|
||||||
|
"dispenser": {
|
||||||
|
"orientation:vertical": "dispenser_vertical",
|
||||||
|
"else": "dispenser"
|
||||||
|
},
|
||||||
|
"sandstone": "regular",
|
||||||
|
"chiseled_sandstone": "regular",
|
||||||
|
"smooth_sandstone": "regular",
|
||||||
|
"note_block": "regular",
|
||||||
|
"bed": "regular",
|
||||||
|
"powered_rail": {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user