mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 02:45:13 -04:00
added support for different block models depending on the block state
This commit is contained in:
parent
10b8d602a5
commit
54cfc33eca
@ -1,67 +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.Face;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
|
||||
import static de.bixilon.minosoft.render.Face.RenderConstants.UV;
|
||||
|
||||
public class FullFacePosition {
|
||||
private final BlockPosition blockPosition;
|
||||
private final FaceOrientation faceOrientation;
|
||||
|
||||
public FullFacePosition(BlockPosition blockPosition, FaceOrientation faceOrientation) {
|
||||
this.blockPosition = blockPosition;
|
||||
this.faceOrientation = faceOrientation;
|
||||
}
|
||||
|
||||
public BlockPosition getBlockPosition() {
|
||||
return blockPosition;
|
||||
}
|
||||
|
||||
public FaceOrientation getFaceOrientation() {
|
||||
return faceOrientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return blockPosition.hashCode() * faceOrientation.hashCode();
|
||||
}
|
||||
|
||||
public void addVertices(ArrayFloatList vertPos, ArrayFloatList textPos, Pair<Float, Float> texture) {
|
||||
float[][] vertPositions = RenderConstants.FACE_VERTEX[faceOrientation.getId()];
|
||||
for (int vert = 0; vert < 4; vert++) {
|
||||
vertPos.add(vertPositions[vert][0] + this.getBlockPosition().getX());
|
||||
vertPos.add(vertPositions[vert][1] + this.getBlockPosition().getY());
|
||||
vertPos.add(vertPositions[vert][2] + this.getBlockPosition().getZ());
|
||||
|
||||
float u;
|
||||
switch (UV[vert][0]) {
|
||||
case 0:
|
||||
u = texture.getKey();
|
||||
break;
|
||||
case 1:
|
||||
u = texture.getValue();
|
||||
break;
|
||||
default:
|
||||
u = 0;
|
||||
}
|
||||
|
||||
textPos.add(u);
|
||||
textPos.add(UV[vert][1]);
|
||||
}
|
||||
}
|
||||
}
|
@ -17,15 +17,15 @@ import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
||||
import de.bixilon.minosoft.game.datatypes.world.*;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.render.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
|
||||
import de.bixilon.minosoft.render.blockModels.Face;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Face;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.bixilon.minosoft.render.Face.RenderConstants.faceDir;
|
||||
import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.faceDir;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class WorldRenderer {
|
||||
|
@ -20,30 +20,25 @@ import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockRotation;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class BlockConfiguration {
|
||||
HashSet<BlockRotation> rotations;
|
||||
BlockRotation rotation;
|
||||
HashSet<BlockProperties> blockProperties;
|
||||
|
||||
public BlockConfiguration(String config) {
|
||||
rotations = new HashSet<>();
|
||||
blockProperties = new HashSet<>();
|
||||
for (String configuration : config.split(",")) {
|
||||
switch (configuration) {
|
||||
case "orientation:vertical":
|
||||
rotations.add(BlockRotation.UP);
|
||||
rotations.add(BlockRotation.DOWN);
|
||||
break;
|
||||
case "orientation:up":
|
||||
rotations.add(BlockRotation.UP);
|
||||
rotation = BlockRotation.UP;
|
||||
break;
|
||||
case "orientation:down":
|
||||
rotations.add(BlockRotation.DOWN);
|
||||
rotation = BlockRotation.DOWN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<BlockRotation> getRotations() {
|
||||
return rotations;
|
||||
public BlockRotation getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public HashSet<BlockProperties> getBlockProperties() {
|
||||
@ -51,15 +46,20 @@ public class BlockConfiguration {
|
||||
}
|
||||
|
||||
public boolean equals(BlockConfiguration blockConfiguration) {
|
||||
return rotations.equals(blockConfiguration.getRotations()) &&
|
||||
return rotation.equals(blockConfiguration.getRotation()) &&
|
||||
blockProperties.equals(blockConfiguration.getBlockProperties());
|
||||
}
|
||||
|
||||
public boolean contains(Block block) {
|
||||
if (!rotations.contains(block.getRotation()) && block.getRotation() != BlockRotation.NONE) {
|
||||
if (block.getRotation().equals(BlockRotation.NONE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!block.getRotation().equals(rotation)) {
|
||||
return false;
|
||||
}
|
||||
if (blockProperties.size() == 0 && block.getProperties().size() == 0) {
|
||||
return true;
|
||||
}
|
||||
for (BlockProperties property : blockProperties) {
|
||||
if (!block.getProperties().contains(property)) {
|
||||
return false;
|
||||
|
@ -17,13 +17,15 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.Config;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||
import de.bixilon.minosoft.render.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Face;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
|
||||
import de.bixilon.minosoft.render.texture.TextureLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
|
||||
|
||||
@ -104,9 +106,19 @@ public class BlockDescription {
|
||||
}
|
||||
|
||||
public HashSet<Face> prepare(Block block, HashMap<FaceOrientation, Boolean> adjacentBlocks) {
|
||||
for (Map.Entry<BlockConfiguration, HashSet<SubBlock>> entry : blockConfigurationStates.entrySet()) {
|
||||
if (entry.getKey().contains(block)) {
|
||||
return prepareBlockState(entry.getValue(), adjacentBlocks, block);
|
||||
}
|
||||
}
|
||||
return prepareBlockState(defaultState, adjacentBlocks, block);
|
||||
}
|
||||
|
||||
private HashSet<Face> prepareBlockState(HashSet<SubBlock> subBlocks,
|
||||
HashMap<FaceOrientation, Boolean> adjacentBlocks, Block block) {
|
||||
HashSet<Face> result = new HashSet<>();
|
||||
for (SubBlock subBlock : defaultState) {
|
||||
result.addAll(subBlock.getFaces(adjacentBlocks));
|
||||
for (SubBlock subBlock : subBlocks) {
|
||||
result.addAll(subBlock.getFaces(block, adjacentBlocks));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -116,11 +128,23 @@ public class BlockDescription {
|
||||
for (SubBlock subBlock : defaultState) {
|
||||
result.addAll(subBlock.getTextures());
|
||||
}
|
||||
for (HashSet<SubBlock> subBlocks : blockConfigurationStates.values()) {
|
||||
for (SubBlock subBlock : subBlocks) {
|
||||
result.addAll(subBlock.getTextures());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void applyTextures(String mod, TextureLoader loader) {
|
||||
for (SubBlock subBlock : defaultState) {
|
||||
applyConfigurationTextures(defaultState, mod, loader);
|
||||
for (HashSet<SubBlock> subBlocks : blockConfigurationStates.values()) {
|
||||
applyConfigurationTextures(subBlocks, mod, loader);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyConfigurationTextures(HashSet<SubBlock> subBlocks, String mod, TextureLoader loader) {
|
||||
for (SubBlock subBlock : subBlocks) {
|
||||
subBlock.applyTextures(mod, loader);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ import de.bixilon.minosoft.Config;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.render.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Face;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.texture.TextureLoader;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.render.Face;
|
||||
package de.bixilon.minosoft.render.blockModels.Face;
|
||||
|
||||
public enum Axis {
|
||||
X, Y, Z
|
@ -11,10 +11,9 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.render.blockModels;
|
||||
package de.bixilon.minosoft.render.blockModels.Face;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
|
||||
import de.bixilon.minosoft.render.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.subBlocks.Cuboid;
|
||||
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlockPosition;
|
||||
import de.bixilon.minosoft.render.texture.InFaceUV;
|
@ -11,7 +11,7 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.render.Face;
|
||||
package de.bixilon.minosoft.render.blockModels.Face;
|
||||
|
||||
public enum FaceOrientation {
|
||||
EAST(0), WEST(1), UP(2), DOWN(3), SOUTH(4), NORTH(5);
|
@ -11,7 +11,7 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.render.Face;
|
||||
package de.bixilon.minosoft.render.blockModels.Face;
|
||||
|
||||
public class RenderConstants {
|
||||
public static final int texturePackRes = 16;
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.render.blockModels.subBlocks;
|
||||
|
||||
// some 3d object with 8 corners, 6 faces and 12 edges (example: cube, but can be deformed)
|
||||
|
||||
import de.bixilon.minosoft.render.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -25,7 +25,7 @@ public class Cuboid {
|
||||
FaceOrientation.EAST, new int[]{7, 5, 1, 3},
|
||||
FaceOrientation.WEST, new int[]{4, 6, 2, 0},
|
||||
FaceOrientation.UP, new int[]{7, 6, 4, 5},
|
||||
FaceOrientation.DOWN, new int[]{0, 1, 3, 2},
|
||||
FaceOrientation.DOWN, new int[]{2, 3, 1, 0},
|
||||
FaceOrientation.SOUTH, new int[]{6, 7, 3, 2},
|
||||
FaceOrientation.NORTH, new int[]{5, 4, 0, 1}
|
||||
);
|
||||
|
@ -14,8 +14,9 @@
|
||||
package de.bixilon.minosoft.render.blockModels.subBlocks;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.render.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.Face;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Face;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.texture.InFaceUV;
|
||||
import de.bixilon.minosoft.render.texture.TextureLoader;
|
||||
import javafx.util.Pair;
|
||||
@ -103,7 +104,7 @@ public class SubBlock {
|
||||
cullFaceTextures.put(orientation, faceJson.has("cullface"));
|
||||
}
|
||||
|
||||
public HashSet<Face> getFaces(HashMap<FaceOrientation, Boolean> adjacentBlocks) {
|
||||
public HashSet<Face> getFaces(Block block, HashMap<FaceOrientation, Boolean> adjacentBlocks) {
|
||||
HashSet<Face> result = new HashSet<>();
|
||||
for (FaceOrientation orientation : FaceOrientation.values()) {
|
||||
if (!textureCoordinates.containsKey(orientation)) {
|
||||
|
@ -16,7 +16,7 @@ package de.bixilon.minosoft.render.blockModels.subBlocks;
|
||||
import com.google.gson.JsonArray;
|
||||
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
|
||||
|
||||
import static de.bixilon.minosoft.render.Face.RenderConstants.blockRes;
|
||||
import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.blockRes;
|
||||
import static org.lwjgl.opengl.GL11.glVertex3f;
|
||||
|
||||
public class SubBlockPosition {
|
||||
|
@ -14,7 +14,7 @@
|
||||
package de.bixilon.minosoft.render.blockModels.subBlocks;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.render.Face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Axis;
|
||||
import javafx.util.Pair;
|
||||
|
||||
import static java.lang.StrictMath.cos;
|
||||
|
@ -23,7 +23,7 @@ import static org.lwjgl.opengl.GL11.glTranslatef;
|
||||
|
||||
public class PlayerController {
|
||||
private final float playerHeight = 1.8f;
|
||||
private final float playerWidth = 0.5f;
|
||||
private final float playerWidth = 0.25f;
|
||||
CameraMovement cameraMovement;
|
||||
PlayerMovement playerMovement;
|
||||
Vec3 playerPos = new Vec3(); // the feet position of the player
|
||||
|
@ -17,7 +17,7 @@ import com.google.gson.JsonArray;
|
||||
import de.bixilon.minosoft.render.MainWindow;
|
||||
import javafx.util.Pair;
|
||||
|
||||
import static de.bixilon.minosoft.render.Face.RenderConstants.texturePackRes;
|
||||
import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.texturePackRes;
|
||||
import static org.lwjgl.opengl.GL11.glTexCoord2f;
|
||||
|
||||
public class InFaceUV {
|
||||
|
@ -46,7 +46,8 @@
|
||||
"lapis_ore": "regular",
|
||||
"lapis_block": "regular",
|
||||
"dispenser": {
|
||||
"orientation:vertical": "dispenser_vertical",
|
||||
"orientation:up": "dispenser_vertical",
|
||||
"orientation:down": "dispenser_vertical",
|
||||
"else": "dispenser"
|
||||
},
|
||||
"sandstone": "regular",
|
||||
@ -111,16 +112,8 @@
|
||||
"azure_bluet": "regular"
|
||||
},
|
||||
"tinted_textures": {
|
||||
"block/grass_block_top": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
],
|
||||
"block/grass": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
]
|
||||
"block/grass_block_top": [0,1,0],
|
||||
"block/grass": [0,1,0]
|
||||
},
|
||||
"ignored_textures": [
|
||||
"block/grass_block_side_overlay"
|
||||
|
Loading…
x
Reference in New Issue
Block a user