From cf4cd611cd26213bd7f4d7cea3a424efd33f6d41 Mon Sep 17 00:00:00 2001 From: Lukas Date: Sun, 13 Sep 2020 13:28:06 +0200 Subject: [PATCH] add support for crops --- .../render/blockModels/BlockModelLoader.java | 27 +++++-- .../blockModels/specialModels/CropModel.java | 72 +++++++++++++++++++ .../blockModels/specialModels/WireModel.java | 65 +++++++++++++++++ .../subBlocks/SubBlockPosition.java | 13 +++- .../assets/mapping/blockModels/minecraft.json | 26 +++++++ 5 files changed, 196 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/render/blockModels/specialModels/CropModel.java create mode 100644 src/main/java/de/bixilon/minosoft/render/blockModels/specialModels/WireModel.java 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 feffcbe65..c6a22c6b3 100644 --- a/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java @@ -21,7 +21,9 @@ import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.render.blockModels.Face.Face; import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; +import de.bixilon.minosoft.render.blockModels.specialModels.CropModel; 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 org.apache.commons.collections.primitives.ArrayFloatList; @@ -100,12 +102,25 @@ public class BlockModelLoader { private HashSet loadModel(String mod, String identifier, JsonObject block) { HashSet result = new HashSet<>(); try { - BlockModel model; - if (identifier.contains("fire")) { - model = new FireModel(block, mod); - } else if (identifier.contains("stairs")) { - model = new StairsModel(block, mod); - } else { + BlockModel model = null; + if (block.has("type")) { + String 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); } result.addAll(model.getAllTextures()); diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/specialModels/CropModel.java b/src/main/java/de/bixilon/minosoft/render/blockModels/specialModels/CropModel.java new file mode 100644 index 000000000..5e80127e0 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/specialModels/CropModel.java @@ -0,0 +1,72 @@ +/* + * 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 . + * + * 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.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 CropModel extends BlockModel { + HashMap> modelMap; + + public CropModel(JsonObject block, String mod) { + int stages = block.get("stages").getAsInt(); + modelMap = new HashMap<>(); + for (int i = 0; i < stages; i++) { + modelMap.put(String.format("%s%d", "AGE_", i), + super.load(mod, String.format("%s%d", block.get("base_name").getAsString(), i))); + } + } + + @Override + public HashSet prepare(Block block, HashMap adjacentBlocks) { + for (BlockProperties property : block.getProperties()) { + if (modelMap.containsKey(property.name())) { + return prepareBlockState(modelMap.get(property.name()), adjacentBlocks, block); + } + } + return new HashSet<>(); + } + + @Override + public boolean isFull() { + return false; + } + + @Override + public HashSet getAllTextures() { + HashSet result = new HashSet<>(); + for (HashSet subBlocks : modelMap.values()) { + for (SubBlock subBlock : subBlocks) { + result.addAll(subBlock.getTextures()); + } + } + return result; + } + + @Override + public void applyTextures(String mod, TextureLoader loader) { + for (HashSet subBlocks : modelMap.values()) { + applyConfigurationTextures(subBlocks, mod, loader); + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/render/blockModels/specialModels/WireModel.java b/src/main/java/de/bixilon/minosoft/render/blockModels/specialModels/WireModel.java new file mode 100644 index 000000000..f477dfbf1 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/render/blockModels/specialModels/WireModel.java @@ -0,0 +1,65 @@ +/* + * 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 . + * + * 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.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 WireModel extends BlockModel { + private final HashSet dot; + private final HashSet side; + private final HashSet up; + + public WireModel(JsonObject block, String mod) { + dot = super.load(mod, block.get("dot").getAsString()); + side = super.load(mod, block.get("side").getAsString()); + up = super.load(mod, block.get("up").getAsString()); + } + + @Override + public HashSet prepare(Block block, HashMap adjacentBlocks) { + // TODO: REDSTONE + return new HashSet<>(); + } + + @Override + public boolean isFull() { + return false; + } + + @Override + public HashSet getAllTextures() { + HashSet result = new HashSet<>(); + result.addAll(getTextures(dot)); + result.addAll(getTextures(side)); + result.addAll(getTextures(up)); + return result; + } + + @Override + public void applyTextures(String mod, TextureLoader loader) { + applyConfigurationTextures(dot, mod, loader); + applyConfigurationTextures(side, mod, loader); + applyConfigurationTextures(up, mod, loader); + } +} \ No newline at end of file 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 5c7ad8717..9d6c06e26 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 @@ -36,7 +36,10 @@ public class SubBlockPosition { public static final SubBlockRotation xAxisRotator = new SubBlockRotation(middlePos, Axis.Z, 90); public static final SubBlockRotation zAxisRotator = new SubBlockRotation(middlePos, Axis.X, 90); - public static final SubBlockRotation downRotator = new SubBlockRotation(middlePos, Axis.X, 180); + public static final SubBlockRotation downRotator = new SubBlockRotation(middlePos, Axis.X, 90); + public static final SubBlockRotation downAltRotator = new SubBlockRotation(middlePos, Axis.X, 180); + public static final SubBlockRotation upRotator = new SubBlockRotation(middlePos, Axis.X, -90); + public SubBlockPosition(JsonArray json) { x = json.get(0).getAsFloat(); @@ -79,7 +82,15 @@ public class SubBlockPosition { return westRotator.apply(this); case SOUTH: return southRotator.apply(this); + case UP: + if (block.getIdentifier().equals("dispenser") || block.getIdentifier().equals("dropper")) { + return this; + } + return upRotator.apply(this); case DOWN: + if (block.getIdentifier().equals("dispenser") || block.getIdentifier().equals("dropper")) { + return downAltRotator.apply(this); + } return downRotator.apply(this); case AXIS_X: return xAxisRotator.apply(this); diff --git a/src/main/resources/assets/mapping/blockModels/minecraft.json b/src/main/resources/assets/mapping/blockModels/minecraft.json index 929111257..5a9c44631 100644 --- a/src/main/resources/assets/mapping/blockModels/minecraft.json +++ b/src/main/resources/assets/mapping/blockModels/minecraft.json @@ -674,6 +674,32 @@ "straight": "oak_stairs", "inner": "oak_stairs_inner", "outer": "oak_stairs_outer" + }, + "chest": { + "blockModel": "chest" + }, + "redstone_wire": { + "type": "wire", + "dot": "redstone_dust_dot", + "side": "redstone_dust_side0", + "up": "redstone_dust_up" + }, + "diamond_ore": { + "blockModel": "diamond_ore" + }, + "diamond_block": { + "blockModel": "diamond_block" + }, + "crafting_table": { + "blockModel": "crafting_table" + }, + "wheat": { + "type": "crop", + "stages": 8, + "base_name": "wheat_stage" + }, + "farmland": { + "blockModel": "farmland" } }, "tinted_textures": {