mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
improve render code
This commit is contained in:
parent
35671ab606
commit
6de799ad9d
@ -17,6 +17,7 @@ import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||
import de.bixilon.minosoft.data.EntityClassMappings;
|
||||
import de.bixilon.minosoft.data.Mappings;
|
||||
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.render.blockModels.BlockModelInterface;
|
||||
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 org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
|
||||
@ -294,7 +295,7 @@ public class VersionMapping {
|
||||
}
|
||||
}
|
||||
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));
|
||||
return BlockModelInterface.EMPTY;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
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;
|
||||
|
||||
public record BlockPosition(int x, int y, int z) {
|
||||
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.world;
|
||||
|
||||
import de.bixilon.minosoft.data.entities.block.BlockEntityMetaData;
|
||||
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.concurrent.ConcurrentHashMap;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
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)
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
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)
|
||||
|
@ -16,9 +16,8 @@ package de.bixilon.minosoft.render;
|
||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||
import de.bixilon.minosoft.data.world.*;
|
||||
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.RenderConstants;
|
||||
import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -23,15 +23,15 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockCondition {
|
||||
public static final BlockCondition trueCondition = new BlockCondition() {
|
||||
public static final BlockCondition TRUE_CONDITION = new BlockCondition() {
|
||||
@Override
|
||||
public boolean contains(Block block) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
HashSet<BlockProperties> properties;
|
||||
BlockRotations rotation;
|
||||
private HashSet<BlockProperties> properties;
|
||||
private BlockRotations rotation;
|
||||
|
||||
public BlockCondition(JsonObject json) {
|
||||
properties = new HashSet<>();
|
||||
@ -53,11 +53,6 @@ public class BlockCondition {
|
||||
if (rotation != BlockRotations.NONE && rotation != block.getRotation()) {
|
||||
return false;
|
||||
}
|
||||
for (BlockProperties property : properties) {
|
||||
if (!block.getProperties().contains(property)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return properties.equals(block.getProperties());
|
||||
}
|
||||
}
|
||||
|
@ -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.world.BlockPosition;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
|
||||
|
@ -17,8 +17,8 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||
import de.bixilon.minosoft.data.world.BlockPosition;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
|
||||
|
@ -29,6 +29,17 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
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
|
||||
* @return blockModels, textureID
|
||||
@ -36,11 +47,7 @@ public class BlockModelLoader {
|
||||
public static Pair<HashMap<String, BlockModelInterface>, Integer> load(String modName, JsonObject data) {
|
||||
HashMap<String, float[]> tints = new HashMap<>();
|
||||
if (modName.equals(ProtocolDefinition.DEFAULT_MOD)) {
|
||||
try {
|
||||
tints = readTints(Util.readJsonAsset("mapping/tints.json"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
tints = TINTS;
|
||||
}
|
||||
HashMap<String, HashSet<SubBlock>> blockModels = loadModels(data);
|
||||
|
||||
|
@ -18,8 +18,8 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||
import de.bixilon.minosoft.data.world.BlockPosition;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
|
||||
@ -32,20 +32,19 @@ public class ConditionalModel implements BlockModelInterface {
|
||||
HashMap<BlockCondition, HashSet<SubBlock>> conditionMap;
|
||||
|
||||
public ConditionalModel(HashMap<String, HashSet<SubBlock>> blockModels, JsonArray elements) {
|
||||
conditionMap = new HashMap<>();
|
||||
this.conditionMap = new HashMap<>();
|
||||
for (JsonElement element : elements) {
|
||||
JsonObject block = element.getAsJsonObject();
|
||||
BlockCondition condition;
|
||||
if (block.has("properties")) {
|
||||
condition = new BlockCondition(block.get("properties").getAsJsonObject());
|
||||
} 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));
|
||||
for (Axis axis : Axis.values()) {
|
||||
String lowercase = axis.name().toLowerCase();
|
||||
if (block.has(lowercase)) {
|
||||
BlockModelInterface.rotateModel(model, axis, block.get(lowercase).getAsDouble());
|
||||
if (block.has(axis.getLowerCase())) {
|
||||
BlockModelInterface.rotateModel(model, axis, block.get(axis.getLowerCase()).getAsDouble());
|
||||
}
|
||||
}
|
||||
conditionMap.put(condition, model);
|
||||
@ -54,12 +53,13 @@ public class ConditionalModel implements BlockModelInterface {
|
||||
|
||||
@Override
|
||||
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()) {
|
||||
if (entry.getKey().contains(block)) {
|
||||
for (SubBlock subBlock : entry.getValue()) {
|
||||
result.addAll(subBlock.getFaces(facesToDraw, position));
|
||||
}
|
||||
if (!entry.getKey().contains(block)) {
|
||||
continue;
|
||||
}
|
||||
for (SubBlock subBlock : entry.getValue()) {
|
||||
result.addAll(subBlock.getFaces(facesToDraw, position));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -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));
|
||||
}
|
@ -11,10 +11,20 @@
|
||||
* 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 {
|
||||
X,
|
||||
Y,
|
||||
Z
|
||||
Z;
|
||||
|
||||
private final String lowerCase;
|
||||
|
||||
Axis() {
|
||||
this.lowerCase = name().toLowerCase();
|
||||
}
|
||||
|
||||
public String getLowerCase() {
|
||||
return lowerCase;
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
* 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 {
|
||||
EAST(0),
|
@ -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));
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
* 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 static final int TEXTURE_PACK_RESOLUTION = 16;
|
@ -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)
|
||||
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FullPositions;
|
||||
import de.bixilon.minosoft.render.blockModels.face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.face.FullPositions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
public Cuboid(SubBlockPosition from, SubBlockPosition to, SubBlockRotation rotation) {
|
||||
positions = new SubBlockPosition[8];
|
||||
positions[0] = from;
|
||||
positions[1] = new SubBlockPosition(to.getVector().x, from.getVector().y, from.getVector().z);
|
||||
positions[2] = new SubBlockPosition(from.getVector().x, from.getVector().y, to.getVector().z);
|
||||
positions[3] = new SubBlockPosition(to.getVector().x, from.getVector().y, to.getVector().z);
|
||||
positions = new SubBlockPosition[]{
|
||||
from,
|
||||
new SubBlockPosition(to.getVector().x, from.getVector().y, from.getVector().z),
|
||||
new SubBlockPosition(from.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);
|
||||
positions[5] = new SubBlockPosition(to.getVector().x, to.getVector().y, from.getVector().z);
|
||||
positions[6] = new SubBlockPosition(from.getVector().x, to.getVector().y, to.getVector().z);
|
||||
positions[7] = to;
|
||||
new SubBlockPosition(from.getVector().x, to.getVector().y, from.getVector().z),
|
||||
new SubBlockPosition(to.getVector().x, to.getVector().y, from.getVector().z),
|
||||
new SubBlockPosition(from.getVector().x, to.getVector().y, to.getVector().z),
|
||||
to
|
||||
};
|
||||
|
||||
if (rotation != null) {
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
positions[i] = rotation.apply(positions[i]);
|
||||
}
|
||||
if (rotation == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
positions[i] = rotation.apply(positions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public Cuboid(Cuboid cuboid) {
|
||||
positions = new SubBlockPosition[cuboid.positions.length];
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
positions[i] = new SubBlockPosition(cuboid.positions[i]);
|
||||
}
|
||||
this.positions = cuboid.positions.clone();
|
||||
}
|
||||
|
||||
public SubBlockPosition[] getFacePositions(FaceOrientation orientation) {
|
||||
int[] positionIds = facePositionMapTemplate[orientation.getId()];
|
||||
int[] positionIds = FACE_POSITION_MAP_TEMPLATE[orientation.getId()];
|
||||
SubBlockPosition[] result = new SubBlockPosition[positionIds.length];
|
||||
for (int i = 0; i < positionIds.length; i++) {
|
||||
result[i] = positions[positionIds[i]];
|
||||
|
@ -15,8 +15,8 @@ package de.bixilon.minosoft.render.blockModels.subBlocks;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.data.world.BlockPosition;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.texture.InFaceUV;
|
||||
import de.bixilon.minosoft.render.texture.TextureLoader;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
@ -26,11 +26,11 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class SubBlock {
|
||||
private HashMap<FaceOrientation, String> textures;
|
||||
private final HashMap<FaceOrientation, Integer> textureRotations;
|
||||
private final boolean[] full;
|
||||
private final HashMap<FaceOrientation, InFaceUV> uv;
|
||||
private final Cuboid cuboid;
|
||||
private HashMap<FaceOrientation, String> textures;
|
||||
private SubBlockRotation rotation;
|
||||
|
||||
public SubBlock(JsonObject json, HashMap<String, String> variables) {
|
||||
@ -135,8 +135,8 @@ public class SubBlock {
|
||||
if (!uv.containsKey(faceDirection) || !uv.get(faceDirection).exists()) {
|
||||
return null;
|
||||
}
|
||||
ArrayFloatList result = new ArrayFloatList();
|
||||
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);
|
||||
int rotation = textureRotations.get(faceDirection);
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
@ -147,11 +147,7 @@ public class SubBlock {
|
||||
}
|
||||
|
||||
public HashSet<String> getTextures() {
|
||||
HashSet<String> result = new HashSet<>();
|
||||
for (Map.Entry<FaceOrientation, String> texture : textures.entrySet()) {
|
||||
result.add(texture.getValue());
|
||||
}
|
||||
return result;
|
||||
return new HashSet<>(textures.values());
|
||||
}
|
||||
|
||||
public void rotate(Axis axis, double rotation) {
|
||||
|
@ -15,11 +15,11 @@ package de.bixilon.minosoft.render.blockModels.subBlocks;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
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 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 static final float e = 0.01f;
|
||||
|
@ -14,7 +14,7 @@
|
||||
package de.bixilon.minosoft.render.blockModels.subBlocks;
|
||||
|
||||
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 javafx.util.Pair;
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
package de.bixilon.minosoft.render.texture;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants;
|
||||
import de.bixilon.minosoft.render.blockModels.face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.face.RenderConstants;
|
||||
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlockPosition;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
|
||||
@ -66,7 +66,7 @@ public class InFaceUV {
|
||||
if (i > 3) {
|
||||
i -= 4;
|
||||
}
|
||||
ArrayFloatList result = new ArrayFloatList();
|
||||
ArrayFloatList result = new ArrayFloatList(2);
|
||||
switch (i) {
|
||||
case 0 -> {
|
||||
result.add(realU1);
|
||||
|
@ -16,7 +16,7 @@ package de.bixilon.minosoft.render.texture;
|
||||
import de.bixilon.minosoft.data.assets.AssetsManager;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
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 java.awt.*;
|
||||
@ -96,7 +96,7 @@ public class TextureLoader {
|
||||
private BufferedImage combineTextures() {
|
||||
// converts all single textures into a very wide image. Improves performance in opengl
|
||||
// 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);
|
||||
|
||||
int currentPos = 0;
|
||||
@ -109,7 +109,7 @@ public class TextureLoader {
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -139,8 +139,7 @@ public class TextureLoader {
|
||||
return -1;
|
||||
}
|
||||
// returns the start and end u-coordinate of a specific texture to access it
|
||||
Integer pos = textureCoordinates.get(textureName);
|
||||
return pos * step;
|
||||
return textureCoordinates.get(textureName) * step;
|
||||
}
|
||||
|
||||
public int getTextureID() {
|
||||
|
@ -22,7 +22,7 @@ import de.bixilon.minosoft.data.world.palette.Palette;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||
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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user