improve render code

This commit is contained in:
Bixilon 2020-12-11 13:31:15 +01:00
parent 35671ab606
commit 6de799ad9d
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
24 changed files with 132 additions and 126 deletions

View File

@ -17,6 +17,7 @@ import com.google.common.collect.HashBiMap;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
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.StaticConfiguration;
import de.bixilon.minosoft.data.EntityClassMappings; import de.bixilon.minosoft.data.EntityClassMappings;
import de.bixilon.minosoft.data.Mappings; import de.bixilon.minosoft.data.Mappings;
import de.bixilon.minosoft.data.entities.EntityInformation; import de.bixilon.minosoft.data.entities.EntityInformation;
@ -32,7 +33,7 @@ import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition; import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
import de.bixilon.minosoft.render.blockModels.BlockModelInterface; import de.bixilon.minosoft.render.blockModels.BlockModelInterface;
import de.bixilon.minosoft.render.blockModels.BlockModelLoader; import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
import de.bixilon.minosoft.util.Pair; import de.bixilon.minosoft.util.Pair;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;
@ -294,7 +295,7 @@ public class VersionMapping {
} }
} }
BlockModelInterface model = modelMap.get(block.getMod()).get(block.getIdentifier()); BlockModelInterface model = modelMap.get(block.getMod()).get(block.getIdentifier());
if (model == null) { if (StaticConfiguration.DEBUG_MODE && model == null) {
Log.warn(String.format("The block model for the following block could not be found: %s", block)); Log.warn(String.format("The block model for the following block could not be found: %s", block));
return BlockModelInterface.EMPTY; return BlockModelInterface.EMPTY;
} }

View File

@ -13,7 +13,7 @@
package de.bixilon.minosoft.data.world; package de.bixilon.minosoft.data.world;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
import de.bixilon.minosoft.render.utility.Vec3; import de.bixilon.minosoft.render.utility.Vec3;
public record BlockPosition(int x, int y, int z) { public record BlockPosition(int x, int y, int z) {

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.world;
import de.bixilon.minosoft.data.entities.block.BlockEntityMetaData; import de.bixilon.minosoft.data.entities.block.BlockEntityMetaData;
import de.bixilon.minosoft.data.mappings.blocks.Block; import de.bixilon.minosoft.data.mappings.blocks.Block;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;

View File

@ -13,7 +13,7 @@
package de.bixilon.minosoft.data.world; package de.bixilon.minosoft.data.world;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
/** /**
* Chunk X, Y and Z location (max 16x255x16) * Chunk X, Y and Z location (max 16x255x16)

View File

@ -13,7 +13,7 @@
package de.bixilon.minosoft.data.world; package de.bixilon.minosoft.data.world;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
/** /**
* Chunk X, Y and Z location (max 16x16x16) * Chunk X, Y and Z location (max 16x16x16)

View File

@ -16,9 +16,8 @@ package de.bixilon.minosoft.render;
import de.bixilon.minosoft.data.mappings.blocks.Block; import de.bixilon.minosoft.data.mappings.blocks.Block;
import de.bixilon.minosoft.data.world.*; import de.bixilon.minosoft.data.world.*;
import de.bixilon.minosoft.protocol.network.Connection; import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.render.blockModels.BlockModelLoader; import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;
import java.util.HashMap; import java.util.HashMap;

View File

@ -23,15 +23,15 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
public class BlockCondition { public class BlockCondition {
public static final BlockCondition trueCondition = new BlockCondition() { public static final BlockCondition TRUE_CONDITION = new BlockCondition() {
@Override @Override
public boolean contains(Block block) { public boolean contains(Block block) {
return true; return true;
} }
}; };
HashSet<BlockProperties> properties; private HashSet<BlockProperties> properties;
BlockRotations rotation; private BlockRotations rotation;
public BlockCondition(JsonObject json) { public BlockCondition(JsonObject json) {
properties = new HashSet<>(); properties = new HashSet<>();
@ -53,11 +53,6 @@ public class BlockCondition {
if (rotation != BlockRotations.NONE && rotation != block.getRotation()) { if (rotation != BlockRotations.NONE && rotation != block.getRotation()) {
return false; return false;
} }
for (BlockProperties property : properties) { return properties.equals(block.getProperties());
if (!block.getProperties().contains(property)) {
return false;
}
}
return true;
} }
} }

View File

@ -21,8 +21,8 @@ import de.bixilon.minosoft.data.mappings.blocks.BlockProperties;
import de.bixilon.minosoft.data.mappings.blocks.BlockRotations; import de.bixilon.minosoft.data.mappings.blocks.BlockRotations;
import de.bixilon.minosoft.data.world.BlockPosition; import de.bixilon.minosoft.data.world.BlockPosition;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.render.blockModels.Face.Axis; import de.bixilon.minosoft.render.blockModels.face.Axis;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock; import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;

View File

@ -17,8 +17,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.bixilon.minosoft.data.mappings.blocks.Block; import de.bixilon.minosoft.data.mappings.blocks.Block;
import de.bixilon.minosoft.data.world.BlockPosition; import de.bixilon.minosoft.data.world.BlockPosition;
import de.bixilon.minosoft.render.blockModels.Face.Axis; import de.bixilon.minosoft.render.blockModels.face.Axis;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock; import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;

View File

@ -29,6 +29,17 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
public class BlockModelLoader { public class BlockModelLoader {
public static final HashMap<String, float[]> TINTS;
static {
try {
TINTS = readTints(Util.readJsonAsset("mapping/tints.json"));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
/** /**
* @param data json file which describes all block models * @param data json file which describes all block models
* @return blockModels, textureID * @return blockModels, textureID
@ -36,11 +47,7 @@ public class BlockModelLoader {
public static Pair<HashMap<String, BlockModelInterface>, Integer> load(String modName, JsonObject data) { public static Pair<HashMap<String, BlockModelInterface>, Integer> load(String modName, JsonObject data) {
HashMap<String, float[]> tints = new HashMap<>(); HashMap<String, float[]> tints = new HashMap<>();
if (modName.equals(ProtocolDefinition.DEFAULT_MOD)) { if (modName.equals(ProtocolDefinition.DEFAULT_MOD)) {
try { tints = TINTS;
tints = readTints(Util.readJsonAsset("mapping/tints.json"));
} catch (IOException e) {
e.printStackTrace();
}
} }
HashMap<String, HashSet<SubBlock>> blockModels = loadModels(data); HashMap<String, HashSet<SubBlock>> blockModels = loadModels(data);

View File

@ -18,8 +18,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.bixilon.minosoft.data.mappings.blocks.Block; import de.bixilon.minosoft.data.mappings.blocks.Block;
import de.bixilon.minosoft.data.world.BlockPosition; import de.bixilon.minosoft.data.world.BlockPosition;
import de.bixilon.minosoft.render.blockModels.Face.Axis; import de.bixilon.minosoft.render.blockModels.face.Axis;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock; import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;
@ -32,20 +32,19 @@ public class ConditionalModel implements BlockModelInterface {
HashMap<BlockCondition, HashSet<SubBlock>> conditionMap; HashMap<BlockCondition, HashSet<SubBlock>> conditionMap;
public ConditionalModel(HashMap<String, HashSet<SubBlock>> blockModels, JsonArray elements) { public ConditionalModel(HashMap<String, HashSet<SubBlock>> blockModels, JsonArray elements) {
conditionMap = new HashMap<>(); this.conditionMap = new HashMap<>();
for (JsonElement element : elements) { for (JsonElement element : elements) {
JsonObject block = element.getAsJsonObject(); JsonObject block = element.getAsJsonObject();
BlockCondition condition; BlockCondition condition;
if (block.has("properties")) { if (block.has("properties")) {
condition = new BlockCondition(block.get("properties").getAsJsonObject()); condition = new BlockCondition(block.get("properties").getAsJsonObject());
} else { } else {
condition = BlockCondition.trueCondition; condition = BlockCondition.TRUE_CONDITION;
} }
HashSet<SubBlock> model = blockModels.get(block.get("model").getAsString()).stream().map(SubBlock::new).collect(Collectors.toCollection(HashSet::new)); HashSet<SubBlock> model = blockModels.get(block.get("model").getAsString()).stream().map(SubBlock::new).collect(Collectors.toCollection(HashSet::new));
for (Axis axis : Axis.values()) { for (Axis axis : Axis.values()) {
String lowercase = axis.name().toLowerCase(); if (block.has(axis.getLowerCase())) {
if (block.has(lowercase)) { BlockModelInterface.rotateModel(model, axis, block.get(axis.getLowerCase()).getAsDouble());
BlockModelInterface.rotateModel(model, axis, block.get(lowercase).getAsDouble());
} }
} }
conditionMap.put(condition, model); conditionMap.put(condition, model);
@ -54,14 +53,15 @@ public class ConditionalModel implements BlockModelInterface {
@Override @Override
public ArrayFloatList prepare(HashSet<FaceOrientation> facesToDraw, BlockPosition position, Block block) { public ArrayFloatList prepare(HashSet<FaceOrientation> facesToDraw, BlockPosition position, Block block) {
ArrayFloatList result = new ArrayFloatList(); ArrayFloatList result = new ArrayFloatList(5 * conditionMap.size());
for (Map.Entry<BlockCondition, HashSet<SubBlock>> entry : conditionMap.entrySet()) { for (Map.Entry<BlockCondition, HashSet<SubBlock>> entry : conditionMap.entrySet()) {
if (entry.getKey().contains(block)) { if (!entry.getKey().contains(block)) {
continue;
}
for (SubBlock subBlock : entry.getValue()) { for (SubBlock subBlock : entry.getValue()) {
result.addAll(subBlock.getFaces(facesToDraw, position)); result.addAll(subBlock.getFaces(facesToDraw, position));
} }
} }
}
return result; return result;
} }

View File

@ -1,40 +0,0 @@
/*
* 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.
*/
package de.bixilon.minosoft.render.blockModels.Face;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlockPosition;
import java.util.Arrays;
import java.util.HashSet;
import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.BLOCK_RESOLUTION;
public class FullPositions {
public static final SubBlockPosition position1 = new SubBlockPosition(0, 0, 0);
public static final SubBlockPosition position2 = new SubBlockPosition(BLOCK_RESOLUTION, 0, 0);
public static final SubBlockPosition position3 = new SubBlockPosition(0, 0, BLOCK_RESOLUTION);
public static final SubBlockPosition position4 = new SubBlockPosition(BLOCK_RESOLUTION, 0, BLOCK_RESOLUTION);
public static final SubBlockPosition position5 = new SubBlockPosition(0, BLOCK_RESOLUTION, 0);
public static final SubBlockPosition position6 = new SubBlockPosition(BLOCK_RESOLUTION, BLOCK_RESOLUTION, 0);
public static final SubBlockPosition position7 = new SubBlockPosition(0, BLOCK_RESOLUTION, BLOCK_RESOLUTION);
public static final SubBlockPosition position8 = new SubBlockPosition(BLOCK_RESOLUTION, BLOCK_RESOLUTION, BLOCK_RESOLUTION);
public static final HashSet<SubBlockPosition> EAST_POSITIONS = new HashSet<>(Arrays.asList(position1, position3, position5, position7));
public static final HashSet<SubBlockPosition> WEST_POSITIONS = new HashSet<>(Arrays.asList(position2, position4, position6, position8));
public static final HashSet<SubBlockPosition> DOWN_POSITIONS = new HashSet<>(Arrays.asList(position1, position2, position3, position4));
public static final HashSet<SubBlockPosition> UP_POSITIONS = new HashSet<>(Arrays.asList(position5, position6, position7, position8));
public static final HashSet<SubBlockPosition> SOUTH_POSITIONS = new HashSet<>(Arrays.asList(position1, position2, position5, position6));
public static final HashSet<SubBlockPosition> NORTH_POSITIONS = new HashSet<>(Arrays.asList(position3, position4, position7, position8));
}

View File

@ -11,10 +11,20 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft. * This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/ */
package de.bixilon.minosoft.render.blockModels.Face; package de.bixilon.minosoft.render.blockModels.face;
public enum Axis { public enum Axis {
X, X,
Y, Y,
Z Z;
private final String lowerCase;
Axis() {
this.lowerCase = name().toLowerCase();
}
public String getLowerCase() {
return lowerCase;
}
} }

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft. * This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/ */
package de.bixilon.minosoft.render.blockModels.Face; package de.bixilon.minosoft.render.blockModels.face;
public enum FaceOrientation { public enum FaceOrientation {
EAST(0), EAST(0),

View File

@ -0,0 +1,40 @@
/*
* 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.
*/
package de.bixilon.minosoft.render.blockModels.face;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlockPosition;
import java.util.Arrays;
import java.util.HashSet;
import static de.bixilon.minosoft.render.blockModels.face.RenderConstants.BLOCK_RESOLUTION;
public class FullPositions {
public static final SubBlockPosition POSITION_1 = new SubBlockPosition(0, 0, 0);
public static final SubBlockPosition POSITION_2 = new SubBlockPosition(BLOCK_RESOLUTION, 0, 0);
public static final SubBlockPosition POSITION_3 = new SubBlockPosition(0, 0, BLOCK_RESOLUTION);
public static final SubBlockPosition POSITION_4 = new SubBlockPosition(BLOCK_RESOLUTION, 0, BLOCK_RESOLUTION);
public static final SubBlockPosition POSITION_5 = new SubBlockPosition(0, BLOCK_RESOLUTION, 0);
public static final SubBlockPosition POSITION_6 = new SubBlockPosition(BLOCK_RESOLUTION, BLOCK_RESOLUTION, 0);
public static final SubBlockPosition POSITION_7 = new SubBlockPosition(0, BLOCK_RESOLUTION, BLOCK_RESOLUTION);
public static final SubBlockPosition POSITION_8 = new SubBlockPosition(BLOCK_RESOLUTION, BLOCK_RESOLUTION, BLOCK_RESOLUTION);
public static final HashSet<SubBlockPosition> EAST_POSITIONS = new HashSet<>(Arrays.asList(POSITION_1, POSITION_3, POSITION_5, POSITION_7));
public static final HashSet<SubBlockPosition> WEST_POSITIONS = new HashSet<>(Arrays.asList(POSITION_2, POSITION_4, POSITION_6, POSITION_8));
public static final HashSet<SubBlockPosition> DOWN_POSITIONS = new HashSet<>(Arrays.asList(POSITION_1, POSITION_2, POSITION_3, POSITION_4));
public static final HashSet<SubBlockPosition> UP_POSITIONS = new HashSet<>(Arrays.asList(POSITION_5, POSITION_6, POSITION_7, POSITION_8));
public static final HashSet<SubBlockPosition> SOUTH_POSITIONS = new HashSet<>(Arrays.asList(POSITION_1, POSITION_2, POSITION_5, POSITION_6));
public static final HashSet<SubBlockPosition> NORTH_POSITIONS = new HashSet<>(Arrays.asList(POSITION_3, POSITION_4, POSITION_7, POSITION_8));
}

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft. * This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/ */
package de.bixilon.minosoft.render.blockModels.Face; package de.bixilon.minosoft.render.blockModels.face;
public class RenderConstants { public class RenderConstants {
public static final int TEXTURE_PACK_RESOLUTION = 16; public static final int TEXTURE_PACK_RESOLUTION = 16;

View File

@ -15,47 +15,46 @@ package de.bixilon.minosoft.render.blockModels.subBlocks;
// a 3d object with 8 corners, 6 faces and 12 edges (cube, but can be deformed) // a 3d object with 8 corners, 6 faces and 12 edges (cube, but can be deformed)
import de.bixilon.minosoft.render.blockModels.Face.Axis; import de.bixilon.minosoft.render.blockModels.face.Axis;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.Face.FullPositions; import de.bixilon.minosoft.render.blockModels.face.FullPositions;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
public class Cuboid { public class Cuboid {
public static final int[][] facePositionMapTemplate = new int[][]{{7, 5, 1, 3}, {4, 6, 2, 0}, {4, 5, 7, 6}, {2, 3, 1, 0}, {6, 7, 3, 2}, {5, 4, 0, 1}}; public static final int[][] FACE_POSITION_MAP_TEMPLATE = new int[][]{{7, 5, 1, 3}, {4, 6, 2, 0}, {4, 5, 7, 6}, {2, 3, 1, 0}, {6, 7, 3, 2}, {5, 4, 0, 1}};
private final SubBlockPosition[] positions; private final SubBlockPosition[] positions;
public Cuboid(SubBlockPosition from, SubBlockPosition to, SubBlockRotation rotation) { public Cuboid(SubBlockPosition from, SubBlockPosition to, SubBlockRotation rotation) {
positions = new SubBlockPosition[8]; positions = new SubBlockPosition[]{
positions[0] = from; from,
positions[1] = new SubBlockPosition(to.getVector().x, from.getVector().y, from.getVector().z); new SubBlockPosition(to.getVector().x, from.getVector().y, from.getVector().z),
positions[2] = new SubBlockPosition(from.getVector().x, from.getVector().y, to.getVector().z); new SubBlockPosition(from.getVector().x, from.getVector().y, to.getVector().z),
positions[3] = new SubBlockPosition(to.getVector().x, from.getVector().y, to.getVector().z); new SubBlockPosition(to.getVector().x, from.getVector().y, to.getVector().z),
positions[4] = new SubBlockPosition(from.getVector().x, to.getVector().y, from.getVector().z); new SubBlockPosition(from.getVector().x, to.getVector().y, from.getVector().z),
positions[5] = new SubBlockPosition(to.getVector().x, to.getVector().y, from.getVector().z); new SubBlockPosition(to.getVector().x, to.getVector().y, from.getVector().z),
positions[6] = new SubBlockPosition(from.getVector().x, to.getVector().y, to.getVector().z); new SubBlockPosition(from.getVector().x, to.getVector().y, to.getVector().z),
positions[7] = to; to
};
if (rotation != null) { if (rotation == null) {
return;
}
for (int i = 0; i < positions.length; i++) { for (int i = 0; i < positions.length; i++) {
positions[i] = rotation.apply(positions[i]); positions[i] = rotation.apply(positions[i]);
} }
} }
}
public Cuboid(Cuboid cuboid) { public Cuboid(Cuboid cuboid) {
positions = new SubBlockPosition[cuboid.positions.length]; this.positions = cuboid.positions.clone();
for (int i = 0; i < positions.length; i++) {
positions[i] = new SubBlockPosition(cuboid.positions[i]);
}
} }
public SubBlockPosition[] getFacePositions(FaceOrientation orientation) { public SubBlockPosition[] getFacePositions(FaceOrientation orientation) {
int[] positionIds = facePositionMapTemplate[orientation.getId()]; int[] positionIds = FACE_POSITION_MAP_TEMPLATE[orientation.getId()];
SubBlockPosition[] result = new SubBlockPosition[positionIds.length]; SubBlockPosition[] result = new SubBlockPosition[positionIds.length];
for (int i = 0; i < positionIds.length; i++) { for (int i = 0; i < positionIds.length; i++) {
result[i] = positions[positionIds[i]]; result[i] = positions[positionIds[i]];

View File

@ -15,8 +15,8 @@ package de.bixilon.minosoft.render.blockModels.subBlocks;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.bixilon.minosoft.data.world.BlockPosition; import de.bixilon.minosoft.data.world.BlockPosition;
import de.bixilon.minosoft.render.blockModels.Face.Axis; import de.bixilon.minosoft.render.blockModels.face.Axis;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
import de.bixilon.minosoft.render.texture.InFaceUV; import de.bixilon.minosoft.render.texture.InFaceUV;
import de.bixilon.minosoft.render.texture.TextureLoader; import de.bixilon.minosoft.render.texture.TextureLoader;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;
@ -26,11 +26,11 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
public class SubBlock { public class SubBlock {
private HashMap<FaceOrientation, String> textures;
private final HashMap<FaceOrientation, Integer> textureRotations; private final HashMap<FaceOrientation, Integer> textureRotations;
private final boolean[] full; private final boolean[] full;
private final HashMap<FaceOrientation, InFaceUV> uv; private final HashMap<FaceOrientation, InFaceUV> uv;
private final Cuboid cuboid; private final Cuboid cuboid;
private HashMap<FaceOrientation, String> textures;
private SubBlockRotation rotation; private SubBlockRotation rotation;
public SubBlock(JsonObject json, HashMap<String, String> variables) { public SubBlock(JsonObject json, HashMap<String, String> variables) {
@ -135,8 +135,8 @@ public class SubBlock {
if (!uv.containsKey(faceDirection) || !uv.get(faceDirection).exists()) { if (!uv.containsKey(faceDirection) || !uv.get(faceDirection).exists()) {
return null; return null;
} }
ArrayFloatList result = new ArrayFloatList();
SubBlockPosition[] positions = cuboid.getFacePositions(faceDirection); SubBlockPosition[] positions = cuboid.getFacePositions(faceDirection);
ArrayFloatList result = new ArrayFloatList(positions.length * 5); // 3 floats for position, 2 for uv faces
InFaceUV inFaceUV = uv.get(faceDirection); InFaceUV inFaceUV = uv.get(faceDirection);
int rotation = textureRotations.get(faceDirection); int rotation = textureRotations.get(faceDirection);
for (int i = 0; i < positions.length; i++) { for (int i = 0; i < positions.length; i++) {
@ -147,11 +147,7 @@ public class SubBlock {
} }
public HashSet<String> getTextures() { public HashSet<String> getTextures() {
HashSet<String> result = new HashSet<>(); return new HashSet<>(textures.values());
for (Map.Entry<FaceOrientation, String> texture : textures.entrySet()) {
result.add(texture.getValue());
}
return result;
} }
public void rotate(Axis axis, double rotation) { public void rotate(Axis axis, double rotation) {

View File

@ -15,11 +15,11 @@ package de.bixilon.minosoft.render.blockModels.subBlocks;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import de.bixilon.minosoft.data.world.BlockPosition; import de.bixilon.minosoft.data.world.BlockPosition;
import de.bixilon.minosoft.render.blockModels.Face.Axis; import de.bixilon.minosoft.render.blockModels.face.Axis;
import de.bixilon.minosoft.render.utility.Vec3; import de.bixilon.minosoft.render.utility.Vec3;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;
import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.BLOCK_RESOLUTION; import static de.bixilon.minosoft.render.blockModels.face.RenderConstants.BLOCK_RESOLUTION;
public class SubBlockPosition { public class SubBlockPosition {
public static final float e = 0.01f; public static final float e = 0.01f;

View File

@ -14,7 +14,7 @@
package de.bixilon.minosoft.render.blockModels.subBlocks; package de.bixilon.minosoft.render.blockModels.subBlocks;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.bixilon.minosoft.render.blockModels.Face.Axis; import de.bixilon.minosoft.render.blockModels.face.Axis;
import de.bixilon.minosoft.render.utility.Vec3; import de.bixilon.minosoft.render.utility.Vec3;
import javafx.util.Pair; import javafx.util.Pair;

View File

@ -14,8 +14,8 @@
package de.bixilon.minosoft.render.texture; package de.bixilon.minosoft.render.texture;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlockPosition; import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlockPosition;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;
@ -66,7 +66,7 @@ public class InFaceUV {
if (i > 3) { if (i > 3) {
i -= 4; i -= 4;
} }
ArrayFloatList result = new ArrayFloatList(); ArrayFloatList result = new ArrayFloatList(2);
switch (i) { switch (i) {
case 0 -> { case 0 -> {
result.add(realU1); result.add(realU1);

View File

@ -16,7 +16,7 @@ package de.bixilon.minosoft.render.texture;
import de.bixilon.minosoft.data.assets.AssetsManager; import de.bixilon.minosoft.data.assets.AssetsManager;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.render.GameWindow; import de.bixilon.minosoft.render.GameWindow;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
@ -96,7 +96,7 @@ public class TextureLoader {
private BufferedImage combineTextures() { private BufferedImage combineTextures() {
// converts all single textures into a very wide image. Improves performance in opengl // converts all single textures into a very wide image. Improves performance in opengl
// TEXTURE_PACK_RESxTEXTURE_PACK_RES textures only // TEXTURE_PACK_RESxTEXTURE_PACK_RES textures only
int imageLength = Integer.highestOneBit(totalTextures * RenderConstants.TEXTURE_PACK_RESOLUTION) * 2; int imageLength = Integer.highestOneBit(totalTextures * RenderConstants.TEXTURE_PACK_RESOLUTION) << 1;
BufferedImage totalImage = new BufferedImage(imageLength, RenderConstants.TEXTURE_PACK_RESOLUTION, BufferedImage.TYPE_INT_ARGB); BufferedImage totalImage = new BufferedImage(imageLength, RenderConstants.TEXTURE_PACK_RESOLUTION, BufferedImage.TYPE_INT_ARGB);
int currentPos = 0; int currentPos = 0;
@ -109,7 +109,7 @@ public class TextureLoader {
} }
textureCoordinates.put(texture.getKey(), currentPos++); textureCoordinates.put(texture.getKey(), currentPos++);
} }
step = (float) 1 / (float) imageLength * RenderConstants.TEXTURE_PACK_RESOLUTION; this.step = 1f / (float) imageLength * RenderConstants.TEXTURE_PACK_RESOLUTION;
return totalImage; return totalImage;
} }
@ -139,8 +139,7 @@ public class TextureLoader {
return -1; return -1;
} }
// returns the start and end u-coordinate of a specific texture to access it // returns the start and end u-coordinate of a specific texture to access it
Integer pos = textureCoordinates.get(textureName); return textureCoordinates.get(textureName) * step;
return pos * step;
} }
public int getTextureID() { public int getTextureID() {

View File

@ -22,7 +22,7 @@ import de.bixilon.minosoft.data.world.palette.Palette;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer; import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition; import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;