diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/CustomMapping.java b/src/main/java/de/bixilon/minosoft/data/mappings/CustomMapping.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java b/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java index 9a9467bd8..71ae6e003 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java @@ -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; } diff --git a/src/main/java/de/bixilon/minosoft/data/world/BlockPosition.java b/src/main/java/de/bixilon/minosoft/data/world/BlockPosition.java index c56302c49..d4f8dbe93 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/BlockPosition.java +++ b/src/main/java/de/bixilon/minosoft/data/world/BlockPosition.java @@ -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) { diff --git a/src/main/java/de/bixilon/minosoft/data/world/Chunk.java b/src/main/java/de/bixilon/minosoft/data/world/Chunk.java index a521c99c8..decab9820 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/Chunk.java +++ b/src/main/java/de/bixilon/minosoft/data/world/Chunk.java @@ -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; diff --git a/src/main/java/de/bixilon/minosoft/data/world/InChunkLocation.java b/src/main/java/de/bixilon/minosoft/data/world/InChunkLocation.java index 3d5e2f8f4..d8924776a 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/InChunkLocation.java +++ b/src/main/java/de/bixilon/minosoft/data/world/InChunkLocation.java @@ -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) diff --git a/src/main/java/de/bixilon/minosoft/data/world/InChunkSectionLocation.java b/src/main/java/de/bixilon/minosoft/data/world/InChunkSectionLocation.java index 7469a1e83..9635b0d41 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/InChunkSectionLocation.java +++ b/src/main/java/de/bixilon/minosoft/data/world/InChunkSectionLocation.java @@ -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) diff --git a/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java b/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java index 2b19dc2d3..0e2d03191 100644 --- a/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java +++ b/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java @@ -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; diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockCondition.java b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockCondition.java index 746369fb4..a3d6b7da2 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockCondition.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockCondition.java @@ -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 properties; - BlockRotations rotation; + private HashSet 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()); } } diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModel.java b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModel.java index d367db4ef..9ec0bdfd9 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModel.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModel.java @@ -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; diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelInterface.java b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelInterface.java index f3e90e140..656c188c0 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelInterface.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelInterface.java @@ -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; diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java index 979780109..f26209412 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java @@ -29,6 +29,17 @@ import java.util.HashSet; import java.util.Map; public class BlockModelLoader { + public static final HashMap 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, Integer> load(String modName, JsonObject data) { HashMap 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> blockModels = loadModels(data); diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/ConditionalModel.java b/src/main/java/de/bixilon/minosoft/render/blockModels/ConditionalModel.java index c30306206..0106074c9 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/ConditionalModel.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/ConditionalModel.java @@ -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> conditionMap; public ConditionalModel(HashMap> 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 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 facesToDraw, BlockPosition position, Block block) { - ArrayFloatList result = new ArrayFloatList(); + ArrayFloatList result = new ArrayFloatList(5 * conditionMap.size()); for (Map.Entry> 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; diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/Face/FullPositions.java b/src/main/java/de/bixilon/minosoft/render/blockModels/Face/FullPositions.java deleted file mode 100644 index 92c6e8db8..000000000 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/Face/FullPositions.java +++ /dev/null @@ -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 . - * - * 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 EAST_POSITIONS = new HashSet<>(Arrays.asList(position1, position3, position5, position7)); - public static final HashSet WEST_POSITIONS = new HashSet<>(Arrays.asList(position2, position4, position6, position8)); - public static final HashSet DOWN_POSITIONS = new HashSet<>(Arrays.asList(position1, position2, position3, position4)); - public static final HashSet UP_POSITIONS = new HashSet<>(Arrays.asList(position5, position6, position7, position8)); - public static final HashSet SOUTH_POSITIONS = new HashSet<>(Arrays.asList(position1, position2, position5, position6)); - public static final HashSet NORTH_POSITIONS = new HashSet<>(Arrays.asList(position3, position4, position7, position8)); -} diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/Face/Axis.java b/src/main/java/de/bixilon/minosoft/render/blockModels/face/Axis.java similarity index 77% rename from src/main/java/de/bixilon/minosoft/render/blockModels/Face/Axis.java rename to src/main/java/de/bixilon/minosoft/render/blockModels/face/Axis.java index bebf7f9f3..44091dda6 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/Face/Axis.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/face/Axis.java @@ -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; + } } diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/Face/FaceOrientation.java b/src/main/java/de/bixilon/minosoft/render/blockModels/face/FaceOrientation.java similarity index 96% rename from src/main/java/de/bixilon/minosoft/render/blockModels/Face/FaceOrientation.java rename to src/main/java/de/bixilon/minosoft/render/blockModels/face/FaceOrientation.java index d5d1c914d..20b12e210 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/Face/FaceOrientation.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/face/FaceOrientation.java @@ -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), diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/face/FullPositions.java b/src/main/java/de/bixilon/minosoft/render/blockModels/face/FullPositions.java new file mode 100644 index 000000000..237fe72fe --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/face/FullPositions.java @@ -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 . + * + * 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 EAST_POSITIONS = new HashSet<>(Arrays.asList(POSITION_1, POSITION_3, POSITION_5, POSITION_7)); + public static final HashSet WEST_POSITIONS = new HashSet<>(Arrays.asList(POSITION_2, POSITION_4, POSITION_6, POSITION_8)); + public static final HashSet DOWN_POSITIONS = new HashSet<>(Arrays.asList(POSITION_1, POSITION_2, POSITION_3, POSITION_4)); + public static final HashSet UP_POSITIONS = new HashSet<>(Arrays.asList(POSITION_5, POSITION_6, POSITION_7, POSITION_8)); + public static final HashSet SOUTH_POSITIONS = new HashSet<>(Arrays.asList(POSITION_1, POSITION_2, POSITION_5, POSITION_6)); + public static final HashSet NORTH_POSITIONS = new HashSet<>(Arrays.asList(POSITION_3, POSITION_4, POSITION_7, POSITION_8)); +} diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/Face/RenderConstants.java b/src/main/java/de/bixilon/minosoft/render/blockModels/face/RenderConstants.java similarity index 96% rename from src/main/java/de/bixilon/minosoft/render/blockModels/Face/RenderConstants.java rename to src/main/java/de/bixilon/minosoft/render/blockModels/face/RenderConstants.java index 2d8aa2e29..712d19d39 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/Face/RenderConstants.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/face/RenderConstants.java @@ -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; diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/Cuboid.java b/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/Cuboid.java index 895866c08..65aa1f2b2 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/Cuboid.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/Cuboid.java @@ -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]]; diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlock.java b/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlock.java index 9159d2aa0..5eb8b4c19 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlock.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlock.java @@ -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 textures; private final HashMap textureRotations; private final boolean[] full; private final HashMap uv; private final Cuboid cuboid; + private HashMap textures; private SubBlockRotation rotation; public SubBlock(JsonObject json, HashMap 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 getTextures() { - HashSet result = new HashSet<>(); - for (Map.Entry texture : textures.entrySet()) { - result.add(texture.getValue()); - } - return result; + return new HashSet<>(textures.values()); } public void rotate(Axis axis, double rotation) { diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlockPosition.java b/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlockPosition.java index 705fae1b6..31c6a4dda 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlockPosition.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlockPosition.java @@ -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; diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlockRotation.java b/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlockRotation.java index 2efb02065..c50033124 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlockRotation.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlockRotation.java @@ -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; diff --git a/src/main/java/de/bixilon/minosoft/render/texture/InFaceUV.java b/src/main/java/de/bixilon/minosoft/render/texture/InFaceUV.java index ee787f3d0..4bea4a939 100644 --- a/src/main/java/de/bixilon/minosoft/render/texture/InFaceUV.java +++ b/src/main/java/de/bixilon/minosoft/render/texture/InFaceUV.java @@ -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); diff --git a/src/main/java/de/bixilon/minosoft/render/texture/TextureLoader.java b/src/main/java/de/bixilon/minosoft/render/texture/TextureLoader.java index 94bedbe74..3b27b27ee 100644 --- a/src/main/java/de/bixilon/minosoft/render/texture/TextureLoader.java +++ b/src/main/java/de/bixilon/minosoft/render/texture/TextureLoader.java @@ -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() { diff --git a/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java b/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java index 43236a00c..0bea13618 100644 --- a/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java +++ b/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java @@ -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;