add support for crops

This commit is contained in:
Lukas 2020-09-13 13:28:06 +02:00
parent 6f2631e42c
commit cf4cd611cd
5 changed files with 196 additions and 7 deletions

View File

@ -21,7 +21,9 @@ 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.FireModel; 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.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;
@ -100,12 +102,25 @@ 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; BlockModel model = null;
if (identifier.contains("fire")) { if (block.has("type")) {
model = new FireModel(block, mod); String type = block.get("type").getAsString();
} else if (identifier.contains("stairs")) { switch (type) {
model = new StairsModel(block, mod); case "fire":
} else { 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); model = new BlockModel(block, mod);
} }
result.addAll(model.getAllTextures()); result.addAll(model.getAllTextures());

View File

@ -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 <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.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<String, HashSet<SubBlock>> 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<Face> prepare(Block block, HashMap<FaceOrientation, Boolean> 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<String> getAllTextures() {
HashSet<String> result = new HashSet<>();
for (HashSet<SubBlock> subBlocks : modelMap.values()) {
for (SubBlock subBlock : subBlocks) {
result.addAll(subBlock.getTextures());
}
}
return result;
}
@Override
public void applyTextures(String mod, TextureLoader loader) {
for (HashSet<SubBlock> subBlocks : modelMap.values()) {
applyConfigurationTextures(subBlocks, mod, loader);
}
}
}

View File

@ -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 <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.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<SubBlock> dot;
private final HashSet<SubBlock> side;
private final HashSet<SubBlock> 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<Face> prepare(Block block, HashMap<FaceOrientation, Boolean> adjacentBlocks) {
// TODO: REDSTONE
return new HashSet<>();
}
@Override
public boolean isFull() {
return false;
}
@Override
public HashSet<String> getAllTextures() {
HashSet<String> 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);
}
}

View File

@ -36,7 +36,10 @@ public class SubBlockPosition {
public static final SubBlockRotation xAxisRotator = new SubBlockRotation(middlePos, Axis.Z, 90); 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 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) { public SubBlockPosition(JsonArray json) {
x = json.get(0).getAsFloat(); x = json.get(0).getAsFloat();
@ -79,7 +82,15 @@ public class SubBlockPosition {
return westRotator.apply(this); return westRotator.apply(this);
case SOUTH: case SOUTH:
return southRotator.apply(this); return southRotator.apply(this);
case UP:
if (block.getIdentifier().equals("dispenser") || block.getIdentifier().equals("dropper")) {
return this;
}
return upRotator.apply(this);
case DOWN: case DOWN:
if (block.getIdentifier().equals("dispenser") || block.getIdentifier().equals("dropper")) {
return downAltRotator.apply(this);
}
return downRotator.apply(this); return downRotator.apply(this);
case AXIS_X: case AXIS_X:
return xAxisRotator.apply(this); return xAxisRotator.apply(this);

View File

@ -674,6 +674,32 @@
"straight": "oak_stairs", "straight": "oak_stairs",
"inner": "oak_stairs_inner", "inner": "oak_stairs_inner",
"outer": "oak_stairs_outer" "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": { "tinted_textures": {