mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
add support for doors
This commit is contained in:
parent
cf4cd611cd
commit
b31104e07f
4
pom.xml
4
pom.xml
@ -26,8 +26,8 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>11</source>
|
<source>14</source>
|
||||||
<target>11</target>
|
<target>14</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.render.blockModels;
|
package de.bixilon.minosoft.render.blockModels;
|
||||||
|
|
||||||
|
import com.google.common.collect.BiMap;
|
||||||
|
import com.google.common.collect.HashBiMap;
|
||||||
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;
|
import de.bixilon.minosoft.Config;
|
||||||
@ -32,6 +34,13 @@ import java.util.Map;
|
|||||||
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
|
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
|
||||||
|
|
||||||
public class BlockModel {
|
public class BlockModel {
|
||||||
|
public static final HashBiMap<BlockRotation, BlockRotation> rotationAdjust = HashBiMap.create(Map.of(
|
||||||
|
BlockRotation.EAST, BlockRotation.SOUTH,
|
||||||
|
BlockRotation.SOUTH, BlockRotation.WEST,
|
||||||
|
BlockRotation.WEST, BlockRotation.NORTH,
|
||||||
|
BlockRotation.NORTH, BlockRotation.EAST
|
||||||
|
));
|
||||||
|
|
||||||
HashMap<BlockConfiguration, HashSet<SubBlock>> blockConfigurationStates;
|
HashMap<BlockConfiguration, HashSet<SubBlock>> blockConfigurationStates;
|
||||||
boolean isFull;
|
boolean isFull;
|
||||||
|
|
||||||
|
@ -21,10 +21,7 @@ import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
|||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.render.blockModels.Face.Face;
|
import de.bixilon.minosoft.render.blockModels.Face.Face;
|
||||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||||
import de.bixilon.minosoft.render.blockModels.specialModels.CropModel;
|
import de.bixilon.minosoft.render.blockModels.specialModels.*;
|
||||||
import de.bixilon.minosoft.render.blockModels.specialModels.FireModel;
|
|
||||||
import de.bixilon.minosoft.render.blockModels.specialModels.WireModel;
|
|
||||||
import de.bixilon.minosoft.render.blockModels.specialModels.StairsModel;
|
|
||||||
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;
|
||||||
|
|
||||||
@ -102,27 +99,19 @@ public class BlockModelLoader {
|
|||||||
private HashSet<String> loadModel(String mod, String identifier, JsonObject block) {
|
private HashSet<String> loadModel(String mod, String identifier, JsonObject block) {
|
||||||
HashSet<String> result = new HashSet<>();
|
HashSet<String> result = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
BlockModel model = null;
|
String type = "";
|
||||||
|
|
||||||
if (block.has("type")) {
|
if (block.has("type")) {
|
||||||
String type = block.get("type").getAsString();
|
type = block.get("type").getAsString();
|
||||||
switch (type) {
|
|
||||||
case "fire":
|
|
||||||
model = new FireModel(block, mod);
|
|
||||||
break;
|
|
||||||
case "stairs":
|
|
||||||
model = new StairsModel(block, mod);
|
|
||||||
break;
|
|
||||||
case "wire":
|
|
||||||
model = new WireModel(block, mod);
|
|
||||||
break;
|
|
||||||
case "crop":
|
|
||||||
model = new CropModel(block, mod);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (model == null) {
|
|
||||||
model = new BlockModel(block, mod);
|
|
||||||
}
|
}
|
||||||
|
BlockModel model = switch (type) {
|
||||||
|
case "fire" -> new FireModel(block, mod);
|
||||||
|
case "stairs" -> new StairsModel(block, mod);
|
||||||
|
case "wire" -> new WireModel(block, mod);
|
||||||
|
case "crop" -> new CropModel(block, mod);
|
||||||
|
case "door" -> new DoorModel(block, mod);
|
||||||
|
default -> new BlockModel(block, mod);
|
||||||
|
};
|
||||||
result.addAll(model.getAllTextures());
|
result.addAll(model.getAllTextures());
|
||||||
HashMap<String, BlockModel> modMap = blockDescriptionMap.get(mod);
|
HashMap<String, BlockModel> modMap = blockDescriptionMap.get(mod);
|
||||||
modMap.put(identifier, model);
|
modMap.put(identifier, model);
|
||||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.render.blockModels.specialModels;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockProperties;
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockProperties;
|
||||||
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.render.blockModels.BlockModel;
|
import de.bixilon.minosoft.render.blockModels.BlockModel;
|
||||||
import de.bixilon.minosoft.render.blockModels.Face.Face;
|
import de.bixilon.minosoft.render.blockModels.Face.Face;
|
||||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||||
@ -44,6 +45,7 @@ public class CropModel extends BlockModel {
|
|||||||
return prepareBlockState(modelMap.get(property.name()), adjacentBlocks, block);
|
return prepareBlockState(modelMap.get(property.name()), adjacentBlocks, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log.warn("failed to prepare block: " + block.toString());
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Codename Minosoft
|
||||||
|
* Copyright (C) 2020 Lukas Eisenhauer
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.render.blockModels.specialModels;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockProperties;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockRotation;
|
||||||
|
import de.bixilon.minosoft.logging.Log;
|
||||||
|
import de.bixilon.minosoft.render.blockModels.BlockModel;
|
||||||
|
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.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class DoorModel extends BlockModel {
|
||||||
|
HashSet<SubBlock> bottom;
|
||||||
|
HashSet<SubBlock> bottom_hinge;
|
||||||
|
|
||||||
|
HashSet<SubBlock> top;
|
||||||
|
HashSet<SubBlock> top_hinge;
|
||||||
|
|
||||||
|
public DoorModel(JsonObject block, String mod) {
|
||||||
|
bottom = super.load(mod, block.get("bottom").getAsString());
|
||||||
|
bottom_hinge = super.load(mod, block.get("bottom_hinge").getAsString());
|
||||||
|
|
||||||
|
top = super.load(mod, block.get("top").getAsString());
|
||||||
|
top_hinge = super.load(mod, block.get("top_hinge").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashSet<Face> prepare(Block block, HashMap<FaceOrientation, Boolean> adjacentBlocks) {
|
||||||
|
if (block.getProperties().contains(BlockProperties.HINGE_LEFT)) {
|
||||||
|
return prepareHinge(bottom, top, block, adjacentBlocks);
|
||||||
|
}
|
||||||
|
return prepareHinge(bottom_hinge, top_hinge, block, adjacentBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HashSet<Face> prepareHinge(HashSet<SubBlock> bottom, HashSet<SubBlock> top, Block block,
|
||||||
|
HashMap<FaceOrientation, Boolean> adjacentBlocks) {
|
||||||
|
if (block.getProperties().contains(BlockProperties.OPEN)) {
|
||||||
|
return prepareHalf(bottom, top, block, adjacentBlocks,
|
||||||
|
rotationAdjust.inverse().get(block.getRotation()));
|
||||||
|
} else {
|
||||||
|
return prepareHalf(bottom,top, block, adjacentBlocks, block.getRotation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HashSet<Face> prepareHalf(HashSet<SubBlock> bottom, HashSet<SubBlock> top,
|
||||||
|
Block block, HashMap<FaceOrientation, Boolean> adjacentBlocks,
|
||||||
|
BlockRotation rotation) {
|
||||||
|
if (block.getProperties().contains(BlockProperties.HALF_LOWER)) {
|
||||||
|
return prepareBlockState(bottom, adjacentBlocks, new Block("", "",
|
||||||
|
rotation));
|
||||||
|
}
|
||||||
|
else if (block.getProperties().contains(BlockProperties.HALF_UPPER)) {
|
||||||
|
return prepareBlockState(top, adjacentBlocks, new Block("", "",
|
||||||
|
rotation));
|
||||||
|
}
|
||||||
|
Log.warn("now");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFull() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashSet<String> getAllTextures() {
|
||||||
|
HashSet<String> result = new HashSet<>();
|
||||||
|
result.addAll(getTextures(bottom));
|
||||||
|
result.addAll(getTextures(bottom_hinge));
|
||||||
|
result.addAll(getTextures(top));
|
||||||
|
result.addAll(getTextures(top_hinge));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyTextures(String mod, TextureLoader loader) {
|
||||||
|
applyConfigurationTextures(bottom, mod, loader);
|
||||||
|
applyConfigurationTextures(bottom_hinge, mod, loader);
|
||||||
|
applyConfigurationTextures(top, mod, loader);
|
||||||
|
applyConfigurationTextures(top_hinge, mod, loader);
|
||||||
|
}
|
||||||
|
}
|
@ -25,20 +25,12 @@ import de.bixilon.minosoft.render.texture.TextureLoader;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class StairsModel extends BlockModel {
|
public class StairsModel extends BlockModel {
|
||||||
HashSet<SubBlock> straight;
|
HashSet<SubBlock> straight;
|
||||||
HashSet<SubBlock> inner;
|
HashSet<SubBlock> inner;
|
||||||
HashSet<SubBlock> outer;
|
HashSet<SubBlock> outer;
|
||||||
|
|
||||||
public static final Map<BlockRotation, BlockRotation> rotationAdjust = Map.of(
|
|
||||||
BlockRotation.EAST, BlockRotation.SOUTH,
|
|
||||||
BlockRotation.SOUTH, BlockRotation.WEST,
|
|
||||||
BlockRotation.WEST, BlockRotation.NORTH,
|
|
||||||
BlockRotation.NORTH, BlockRotation.EAST
|
|
||||||
);
|
|
||||||
|
|
||||||
public StairsModel(JsonObject block, String mod) {
|
public StairsModel(JsonObject block, String mod) {
|
||||||
straight = super.load(mod, block.get("straight").getAsString());
|
straight = super.load(mod, block.get("straight").getAsString());
|
||||||
inner = super.load(mod, block.get("inner").getAsString());
|
inner = super.load(mod, block.get("inner").getAsString());
|
||||||
|
@ -75,6 +75,9 @@ public class SubBlockPosition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SubBlockPosition rotated(Block block) {
|
public SubBlockPosition rotated(Block block) {
|
||||||
|
if (block.getRotation() == null) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
switch (block.getRotation()) {
|
switch (block.getRotation()) {
|
||||||
case EAST:
|
case EAST:
|
||||||
return eastRotator.apply(this);
|
return eastRotator.apply(this);
|
||||||
|
@ -699,7 +699,97 @@
|
|||||||
"base_name": "wheat_stage"
|
"base_name": "wheat_stage"
|
||||||
},
|
},
|
||||||
"farmland": {
|
"farmland": {
|
||||||
|
"states": [
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"moisture": "0"
|
||||||
|
},
|
||||||
"blockModel": "farmland"
|
"blockModel": "farmland"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"moisture": "1"
|
||||||
|
},
|
||||||
|
"blockModel": "farmland"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"moisture": "2"
|
||||||
|
},
|
||||||
|
"blockModel": "farmland"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"moisture": "3"
|
||||||
|
},
|
||||||
|
"blockModel": "farmland"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"moisture": "4"
|
||||||
|
},
|
||||||
|
"blockModel": "farmland"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"moisture": "5"
|
||||||
|
},
|
||||||
|
"blockModel": "farmland"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"moisture": "6"
|
||||||
|
},
|
||||||
|
"blockModel": "farmland"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"moisture": "7"
|
||||||
|
},
|
||||||
|
"blockModel": "farmland_moist"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"furnace": {
|
||||||
|
"states": [
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"lit": "false"
|
||||||
|
},
|
||||||
|
"blockModel": "furnace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"lit": "true"
|
||||||
|
},
|
||||||
|
"blockModel": "furnace_on"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"oak_sign": {
|
||||||
|
"blockModel": "oak_sign"
|
||||||
|
},
|
||||||
|
"spruce_sign": {
|
||||||
|
"blockModel": "spruce_sign"
|
||||||
|
},
|
||||||
|
"birch_sign": {
|
||||||
|
"blockModel": "birch_sign"
|
||||||
|
},
|
||||||
|
"acacia_sign": {
|
||||||
|
"blockModel": "acacia_sign"
|
||||||
|
},
|
||||||
|
"jungle_sign": {
|
||||||
|
"blockModel": "jungle_sign"
|
||||||
|
},
|
||||||
|
"dark_oak_sign": {
|
||||||
|
"blockModel": "dark_oak_sign"
|
||||||
|
},
|
||||||
|
"oak_door": {
|
||||||
|
"type": "door",
|
||||||
|
"bottom": "oak_door_bottom",
|
||||||
|
"bottom_hinge": "oak_door_bottom_hinge",
|
||||||
|
"top": "oak_door_top",
|
||||||
|
"top_hinge": "oak_door_top_hinge"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tinted_textures": {
|
"tinted_textures": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user