added support for ignored textures

This commit is contained in:
Lukas 2020-08-12 21:33:18 +02:00
parent 95ad0f0535
commit 1fc93f067c
6 changed files with 37 additions and 100 deletions

View File

@ -39,15 +39,17 @@ public class BlockModelLoader {
blockDescriptionMap = new HashMap<>();
HashMap<String, HashMap<String, float[]>> tints = new HashMap<>();
HashMap<String, HashSet<String>> textures = new HashMap<>();
HashMap<String, HashSet<String>> ignoredTextures = new HashMap<>();
try {
String folderPath = Config.homeDir + "assets/mapping/blockModels/";
for (File file : new File(folderPath).listFiles()) {
JsonObject json = readJsonFromFile(file.getAbsolutePath());
String mod = file.getName().substring(0, file.getName().lastIndexOf('.'));
tints.put(mod, readTints(json));
ignoredTextures.put(mod, readIgnored(json));
textures.put(mod, loadModels(json.get("blocks").getAsJsonObject(), mod));
}
textureLoader = new TextureLoader(textures, tints);
textureLoader = new TextureLoader(textures, tints, ignoredTextures);
applyTextures();
} catch (IOException e) {
e.printStackTrace();
@ -55,6 +57,17 @@ public class BlockModelLoader {
Log.info("finished loading all blocks");
}
private HashSet<String> readIgnored(JsonObject json) {
if (!json.has("ignored_textures")) {
return new HashSet<>();
}
HashSet<String> result = new HashSet<>();
for (JsonElement texture : json.get("ignored_textures").getAsJsonArray()) {
result.add(texture.getAsString());
}
return result;
}
private void applyTextures() {
for (Map.Entry<String, HashMap<String, BlockDescription>> mod : blockDescriptionMap.entrySet()) {
for (Map.Entry<String, BlockDescription> block : mod.getValue().entrySet()) {

View File

@ -1,94 +0,0 @@
/*
* 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 com.google.gson.JsonObject;
import de.bixilon.minosoft.render.MainWindow;
import de.bixilon.minosoft.render.fullFace.FaceOrientation;
import javafx.util.Pair;
import java.util.*;
public class DrawDescription {
private final FaceOrientation[] sideOrientations = new FaceOrientation[]{
FaceOrientation.EAST,
FaceOrientation.WEST,
FaceOrientation.SOUTH,
FaceOrientation.NORTH
};
private final FaceOrientation[] endOrientations = new FaceOrientation[]{
FaceOrientation.UP,
FaceOrientation.DOWN
};
Map<FaceOrientation, Pair<Float, Float>> faces;
boolean full = false; // is the block a completely filled block?
public DrawDescription(JsonObject json, String mod) {
if (!(json.has("parent") && json.has("textures"))) return;
faces = new HashMap<>();
JsonObject textures = json.getAsJsonObject("textures");
for (String texture : textures.keySet()) {
String textureUse = textures.getAsJsonObject(texture).toString();
Pair<Float, Float> texturePair;
try {
texturePair = MainWindow.getRenderer().getModelLoader().getTextureLoader().getTexture(mod, texture);
} catch (Exception e) {
continue;
}
List<FaceOrientation> faceOrientations = new ArrayList<>();
switch (textureUse) {
case "all":
faceOrientations.addAll(Arrays.asList(FaceOrientation.values()));
case "side":
faceOrientations.addAll(Arrays.asList(sideOrientations));
case "end":
faceOrientations.addAll(Arrays.asList(endOrientations));
case "top":
faceOrientations.add(FaceOrientation.UP);
case "bottom":
faceOrientations.add(FaceOrientation.DOWN);
}
for (FaceOrientation faceOrientation : faceOrientations) {
faces.put(faceOrientation, texturePair);
}
}
full = true;
}
public boolean isFull() {
return full;
}
public Pair<Float, Float> getTexture(FaceOrientation orientation) {
if (!faces.containsKey(orientation))
throw new IllegalArgumentException("face " + orientation + " not covered by: " + this);
return faces.get(orientation);
}
@Override
public String toString() {
return String.format("%s full: %s", faces.toString(), full);
}
}

View File

@ -75,6 +75,9 @@ public class SubBlock {
public void applyTextures(String mod, TextureLoader loader) {
for (Map.Entry<FaceOrientation, String> entry : textures.entrySet()) {
Pair<Float, Float> texture = loader.getTexture(mod, entry.getValue());
if (texture == null) {
continue;
}
textureCoordinates.put(entry.getKey(), texture);
}
// clean up
@ -87,7 +90,6 @@ public class SubBlock {
} catch (Exception e) {
uv.put(orientation, new InFaceUV());
}
String textureName = getRealTextureName(faceJson.get("texture").getAsString(), variables);
textures.put(orientation, textureName);
cullFaceTextures.put(orientation, faceJson.has("cullface"));

View File

@ -41,6 +41,9 @@ public class PlayerController {
}
public void loop(float deltaTime) {
if (!MainWindow.getConnection().getPlayer().isSpawnConfirmed()) {
return;
}
oldPos = playerPos.copy();
GameMode gameMode = MainWindow.getConnection().getPlayer().getGameMode();

View File

@ -34,16 +34,19 @@ import static org.lwjgl.opengl.GL30.glGenerateMipmap;
public class TextureLoader {
private final int TEXTURE_PACK_RES = 16;
private final HashMap<String, HashMap<String, Integer>> textureCoordinates;
private final HashMap<String, HashSet<String>> ignored;
int textureID;
float step;
int totalTextures = 0;
HashMap<String, HashMap<String, BufferedImage>> images;
public TextureLoader(HashMap<String, HashSet<String>> textures, HashMap<String, HashMap<String, float[]>> tints) {
public TextureLoader(HashMap<String, HashSet<String>> textures, HashMap<String, HashMap<String, float[]>> tints,
HashMap<String, HashSet<String>> ignored_textures) {
textureCoordinates = new HashMap<>();
images = new HashMap<>();
this.ignored = ignored_textures;
for (String mod : textures.keySet()) {
loadTextures(mod, textures.get(mod), tints.get(mod));
loadTextures(mod, textures.get(mod), tints.get(mod), ignored_textures.get(mod));
}
combineTextures();
try {
@ -71,9 +74,12 @@ public class TextureLoader {
}
}
private void loadTextures(String mod, HashSet<String> textureNames, HashMap<String, float[]> tint) {
private void loadTextures(String mod, HashSet<String> textureNames, HashMap<String, float[]> tint, HashSet<String> ignored) {
HashMap<String, BufferedImage> modTextureMap = new HashMap<>();
for (String textureName : textureNames) {
if (ignored != null && ignored.contains(textureName)) {
continue;
}
String path = Config.homeDir + "assets/" + mod + "/textures/" + textureName + ".png";
try {
BufferedImage image = ImageIO.read(new File(path));
@ -143,6 +149,10 @@ public class TextureLoader {
public Pair<Float, Float> getTexture(String mod, String textureName) {
// returns the start and end u-coordinate of a specific texture to access it
if (ignored.get(mod) != null && ignored.get(mod).contains(textureName)) {
return null;
}
HashMap<String, Integer> modMap = textureCoordinates.get(mod);
if (modMap == null) {
System.out.println("no mod " + mod + " loaded");

View File

@ -116,5 +116,8 @@
1,
0
]
}
},
"ignored_textures": [
"block/grass_block_side_overlay"
]
}