mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-11 08:27:29 -04:00
wip blockModelCombiner
This commit is contained in:
parent
7818623c71
commit
43c2c38ec8
@ -15,5 +15,6 @@ package de.bixilon.minosoft.data;
|
||||
|
||||
public enum Mappings {
|
||||
BLOCKS,
|
||||
REGISTRIES
|
||||
REGISTRIES,
|
||||
BLOCK_MODELS
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||
import de.bixilon.minosoft.data.mappings.particle.Particle;
|
||||
import de.bixilon.minosoft.data.mappings.statistics.Statistic;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Version;
|
||||
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -38,6 +39,7 @@ public class CustomMapping {
|
||||
final HashBiMap<Integer, Statistic> statisticIdMap = HashBiMap.create();
|
||||
Version version;
|
||||
HashMap<String, HashBiMap<String, Dimension>> dimensionIdentifierMap = new HashMap<>();
|
||||
BlockModelLoader blockModelLoader;
|
||||
|
||||
public CustomMapping(Version version) {
|
||||
this.version = version;
|
||||
@ -193,6 +195,13 @@ public class CustomMapping {
|
||||
return version.getMapping().getIdByEnchantment(enchantment);
|
||||
}
|
||||
|
||||
public BlockModelLoader getBlockModelLoader() {
|
||||
if (blockModelLoader != null) { // TODO: check models
|
||||
return blockModelLoader;
|
||||
}
|
||||
return version.getMapping().getBlockModelLoader();
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
motiveIdentifierMap.clear();
|
||||
particleIdentifierMap.clear();
|
||||
@ -208,6 +217,7 @@ public class CustomMapping {
|
||||
enchantmentMap.clear();
|
||||
particleIdMap.clear();
|
||||
statisticIdMap.clear();
|
||||
blockModelLoader.clear();
|
||||
}
|
||||
|
||||
public void setDimensions(HashMap<String, HashBiMap<String, Dimension>> dimensions) {
|
||||
|
@ -22,6 +22,7 @@ import de.bixilon.minosoft.data.mappings.blocks.Blocks;
|
||||
import de.bixilon.minosoft.data.mappings.particle.Particle;
|
||||
import de.bixilon.minosoft.data.mappings.statistics.Statistic;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@ -41,6 +42,7 @@ public class VersionMapping {
|
||||
HashBiMap<Integer, Enchantment> enchantmentMap;
|
||||
HashBiMap<Integer, Particle> particleIdMap;
|
||||
HashBiMap<Integer, Statistic> statisticIdMap;
|
||||
BlockModelLoader blockModelLoader;
|
||||
|
||||
public VersionMapping(Version version) {
|
||||
this.version = version;
|
||||
@ -110,6 +112,10 @@ public class VersionMapping {
|
||||
return enchantmentMap.inverse().get(enchantment);
|
||||
}
|
||||
|
||||
public BlockModelLoader getBlockModelLoader() {
|
||||
return blockModelLoader;
|
||||
}
|
||||
|
||||
public void load(Mappings type, JsonObject data) {
|
||||
switch (type) {
|
||||
case REGISTRIES -> {
|
||||
@ -191,6 +197,7 @@ public class VersionMapping {
|
||||
}
|
||||
}
|
||||
case BLOCKS -> blockMap = Blocks.load("minecraft", data, version.getVersionId() < ProtocolDefinition.FLATTING_VERSION_ID);
|
||||
case BLOCK_MODELS -> blockModelLoader = new BlockModelLoader(data);
|
||||
}
|
||||
loaded.add(type);
|
||||
}
|
||||
@ -209,6 +216,7 @@ public class VersionMapping {
|
||||
enchantmentMap.clear();
|
||||
particleIdMap.clear();
|
||||
statisticIdMap.clear();
|
||||
blockModelLoader.clear();
|
||||
}
|
||||
|
||||
public boolean isFullyLoaded() {
|
||||
|
@ -40,6 +40,7 @@ public class Versions {
|
||||
static {
|
||||
mappingsHashMap.put("registries", Mappings.REGISTRIES);
|
||||
mappingsHashMap.put("blocks", Mappings.BLOCKS);
|
||||
mappingsHashMap.put("blockModels", Mappings.BLOCK_MODELS);
|
||||
}
|
||||
|
||||
public static Version getVersionById(int versionId) {
|
||||
|
@ -15,7 +15,6 @@ package de.bixilon.minosoft.render;
|
||||
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@ -35,7 +34,6 @@ public class GameWindow {
|
||||
new Thread(() -> {
|
||||
openGLWindow = new OpenGLWindow();
|
||||
openGLWindow.init();
|
||||
BlockModelLoader.blockModelLoader = new BlockModelLoader();
|
||||
Log.info("Finished loading block models");
|
||||
latch.countDown();
|
||||
mainLoop();
|
||||
|
@ -31,17 +31,16 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockModelLoader {
|
||||
TextureLoader textureLoader;
|
||||
public static BlockModelLoader blockModelLoader;
|
||||
HashMap<String, HashMap<String, BlockModelInterface>> modelMap;
|
||||
private final TextureLoader textureLoader;
|
||||
private final HashMap<String, HashMap<String, BlockModelInterface>> modelMap;
|
||||
|
||||
public BlockModelLoader() {
|
||||
public BlockModelLoader(JsonObject data) {
|
||||
modelMap = new HashMap<>();
|
||||
HashSet<JsonObject> mods = new HashSet<>();
|
||||
HashMap<String, HashMap<String, float[]>> tints = new HashMap<>();
|
||||
mods.add(data);
|
||||
HashMap<String, float[]> tints = null;
|
||||
try {
|
||||
//TODO: modding
|
||||
mods.add(Util.readJsonAsset("mapping/blockModels.json"));
|
||||
tints = readTints(Util.readJsonAsset("mapping/tints.json"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -52,7 +51,6 @@ public class BlockModelLoader {
|
||||
modelMap.put(modName, new HashMap<>());
|
||||
}
|
||||
blockModels.put(modName, loadModels(mod));
|
||||
tints.put(modName, readTints(mod));
|
||||
}
|
||||
textureLoader = new TextureLoader(getTextures(blockModels), tints);
|
||||
applyTextures(blockModels);
|
||||
@ -61,10 +59,6 @@ public class BlockModelLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockModelLoader getInstance() {
|
||||
return blockModelLoader;
|
||||
}
|
||||
|
||||
private void loadBlocks(JsonObject mod, HashMap<String, HashSet<SubBlock>> blockModels) {
|
||||
for (Map.Entry<String, JsonElement> blockEntry : mod.get("blockStates").getAsJsonObject().entrySet()) {
|
||||
JsonObject block = blockEntry.getValue().getAsJsonObject();
|
||||
@ -151,4 +145,8 @@ public class BlockModelLoader {
|
||||
public TextureLoader getTextureLoader() {
|
||||
return textureLoader;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
modelMap.clear();
|
||||
}
|
||||
}
|
||||
|
@ -40,11 +40,11 @@ public class TextureLoader {
|
||||
private float step;
|
||||
private int totalTextures = 0;
|
||||
|
||||
public TextureLoader(HashMap<String, HashSet<String>> textures, HashMap<String, HashMap<String, float[]>> tints) {
|
||||
public TextureLoader(HashMap<String, HashSet<String>> textures, HashMap<String, float[]> tints) {
|
||||
textureCoordinates = new HashMap<>();
|
||||
images = new HashMap<>();
|
||||
for (String mod : textures.keySet()) {
|
||||
loadTextures(mod, textures.get(mod), tints.get(mod));
|
||||
loadTextures(mod, textures.get(mod), tints);
|
||||
}
|
||||
combineTextures();
|
||||
try {
|
||||
|
File diff suppressed because one or more lines are too long
17
src/main/resources/assets/mapping/tints.json
Normal file
17
src/main/resources/assets/mapping/tints.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"block/grass_block_top": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
],
|
||||
"block/grass": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
],
|
||||
"block/water_still": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
]
|
||||
}
|
@ -1,47 +1,85 @@
|
||||
"""
|
||||
* 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.
|
||||
"""
|
||||
# Minosoft
|
||||
# minosoft
|
||||
# Copyright (C) 2020 Moritz Zwerger
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import json
|
||||
import os
|
||||
import \
|
||||
io
|
||||
import \
|
||||
requests
|
||||
import \
|
||||
sys
|
||||
import \
|
||||
ujson
|
||||
import \
|
||||
zipfile
|
||||
|
||||
if len(
|
||||
sys.argv) != 2:
|
||||
print(
|
||||
"useage: %s <jar url>".format(
|
||||
sys.argv[
|
||||
0]))
|
||||
sys.exit()
|
||||
|
||||
blockStates = {}
|
||||
blockModels = {}
|
||||
|
||||
modName = "minecraft"
|
||||
|
||||
blockStatesDir = modName + "/blockstates/"
|
||||
blockModelsDir = modName + "/models/block/"
|
||||
print(
|
||||
"Downloading minecraft jar...")
|
||||
|
||||
print("loading blockstates...")
|
||||
request = requests.get(
|
||||
sys.argv[
|
||||
1],
|
||||
allow_redirects=True)
|
||||
|
||||
print(
|
||||
"Unpacking minecraft jar...")
|
||||
zip = zipfile.ZipFile(
|
||||
io.BytesIO(
|
||||
request.content),
|
||||
"r")
|
||||
|
||||
files = zip.namelist()
|
||||
|
||||
print(
|
||||
"Loading blockstates...")
|
||||
|
||||
|
||||
def readRotations(apply, current):
|
||||
def readRotations(
|
||||
apply,
|
||||
current):
|
||||
if "x" in current:
|
||||
apply["x"] = current["x"]
|
||||
apply[
|
||||
"x"] = \
|
||||
current[
|
||||
"x"]
|
||||
if "y" in current:
|
||||
apply["y"] = current["y"]
|
||||
apply[
|
||||
"y"] = \
|
||||
current[
|
||||
"y"]
|
||||
if "z" in current:
|
||||
apply["z"] = current["z"]
|
||||
apply[
|
||||
"z"] = \
|
||||
current[
|
||||
"z"]
|
||||
|
||||
|
||||
def readPart(part):
|
||||
@ -71,19 +109,38 @@ def readPart(part):
|
||||
return result
|
||||
|
||||
|
||||
for blockStateFile in os.listdir(blockStatesDir):
|
||||
with open(blockStatesDir + blockStateFile, "r") as file:
|
||||
data = json.load(file)
|
||||
for blockStateFile in [
|
||||
f
|
||||
for
|
||||
f
|
||||
in
|
||||
files
|
||||
if
|
||||
f.startswith(
|
||||
'assets/minecraft/blockstates/')]:
|
||||
with zip.open(
|
||||
blockStateFile) as file:
|
||||
data = ujson.load(
|
||||
file)
|
||||
block = {}
|
||||
if "variants" in data:
|
||||
variants = data["variants"]
|
||||
variants = \
|
||||
data[
|
||||
"variants"]
|
||||
states = []
|
||||
for variant in variants:
|
||||
state = {}
|
||||
properties = {}
|
||||
if variant != "":
|
||||
for part in variant.split(","):
|
||||
properties[part.split("=")[0]] = part.split("=")[1]
|
||||
for part in variant.split(
|
||||
","):
|
||||
properties[
|
||||
part.split(
|
||||
"=")[
|
||||
0]] = \
|
||||
part.split(
|
||||
"=")[
|
||||
1]
|
||||
state["properties"] = properties
|
||||
current = variants[variant]
|
||||
if type(current) == type([]):
|
||||
@ -95,36 +152,61 @@ for blockStateFile in os.listdir(blockStatesDir):
|
||||
"states": states
|
||||
}
|
||||
elif "multipart" in data:
|
||||
parts = data["multipart"]
|
||||
parts = \
|
||||
data[
|
||||
"multipart"]
|
||||
conditional = []
|
||||
for part in parts:
|
||||
conditional.extend(readPart(part))
|
||||
conditional.extend(
|
||||
readPart(
|
||||
part))
|
||||
block = {
|
||||
"conditional": conditional
|
||||
}
|
||||
blockStates[blockStateFile.split(".")[0]] = block
|
||||
blockStates[
|
||||
blockStateFile.split(
|
||||
".")[
|
||||
0]] = block
|
||||
|
||||
print("loading models...")
|
||||
for blockModelFile in os.listdir(blockModelsDir):
|
||||
with open(blockModelsDir + blockModelFile, "r") as file:
|
||||
data = json.load(file)
|
||||
print(
|
||||
"Loading models...")
|
||||
for blockModelFile in [
|
||||
f
|
||||
for
|
||||
f
|
||||
in
|
||||
files
|
||||
if
|
||||
f.startswith(
|
||||
'assets/minecraft/models/block/')]:
|
||||
with zip.open(
|
||||
blockModelFile) as file:
|
||||
data = ujson.load(
|
||||
file)
|
||||
blockModels[
|
||||
blockModelFile.split(
|
||||
".")[
|
||||
0]] = data
|
||||
|
||||
blockModels[blockModelFile.split(".")[0]] = data
|
||||
|
||||
print("combining files...")
|
||||
print(
|
||||
"Combining files...")
|
||||
finalJson = {
|
||||
"mod": modName,
|
||||
"blockStates": blockStates,
|
||||
"blockModels": blockModels,
|
||||
"tinted_textures": {
|
||||
"block/grass_block_top": [0, 1, 0],
|
||||
"block/grass": [0, 1, 0],
|
||||
"block/water_still": [0, 0, 1]
|
||||
}
|
||||
}
|
||||
|
||||
print("saving...")
|
||||
with open("blockModels.json", "w+") as file:
|
||||
json.dump(finalJson, file)
|
||||
print(
|
||||
"Saving...")
|
||||
with open(
|
||||
"../../../AppData/Roaming/Minosoft/assets/assets/blockModels.json",
|
||||
"w+") as file:
|
||||
finalJson = ujson.dumps(
|
||||
finalJson)
|
||||
file.write(
|
||||
finalJson.replace(
|
||||
"minecraft:",
|
||||
""))
|
||||
|
||||
print("finished succesfully")
|
||||
print(
|
||||
"Finished succesfully")
|
||||
|
Loading…
x
Reference in New Issue
Block a user