Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libraries/data-gen/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
setUpLibrary(project)

dependencies {
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.google.guava:guava:17.0'
}
1 change: 1 addition & 0 deletions libraries/data-gen/data-gen-mc18w43a-mc1.14.4/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setUpModule(project)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#min_mc_version = 1.13-pre6
min_mc_version = 18w43a
max_mc_version = 1.14.4

minecraft_version = 1.14.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.ornithemc.osl.datagen.api.model;

import com.google.gson.JsonObject;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;

import java.util.HashMap;
import java.util.Map;

public class ModelBuilder {
private NamespacedIdentifier parent;
private Map<String, NamespacedIdentifier> textures = new HashMap<>();

public static ModelBuilder create() {
return new ModelBuilder();
}

public static ModelBuilder create(NamespacedIdentifier parent) {
return new ModelBuilder().parent(parent);
}

public ModelBuilder parent(NamespacedIdentifier parent) {
this.parent = parent;
return this;
}

public ModelBuilder texture(String name, NamespacedIdentifier texture) {
this.textures.put(name, texture);
return this;
}

public JsonObject build() {
JsonObject model = new JsonObject();

if (parent != null) {
model.addProperty("parent", parent.toString());
}

if (!textures.isEmpty()) {
JsonObject texturesJson = new JsonObject();
for (Map.Entry<String, NamespacedIdentifier> entry : textures.entrySet()) {
texturesJson.addProperty(entry.getKey(), entry.getValue().toString());
}
model.add("textures", texturesJson);
}

return model;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.ornithemc.osl.datagen.api.model;

import net.minecraft.block.Block;
import net.minecraft.item.ItemLike;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
import net.ornithemc.osl.datagen.api.model.block.BlockModelDefinitionBuilder;
import net.ornithemc.osl.datagen.api.model.block.BlockModelTemplates;

public interface ModelGenerator {
void blockstate(Block block, BlockModelDefinitionBuilder builder);
void itemModel(ItemLike item, ModelBuilder builder);
NamespacedIdentifier blockModel(NamespacedIdentifier identifier, ModelBuilder builder);
NamespacedIdentifier blockModel(Block block, ModelBuilder builder);
NamespacedIdentifier blockModel(Block block, String suffix, ModelBuilder builder);

BlockModelTemplates blockTemplates();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package net.ornithemc.osl.datagen.api.model.block;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.block.state.BlockState;
import net.minecraft.client.render.block.BlockModelShaper;
import net.minecraft.state.property.Property;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;

import java.util.*;

public class BlockModelDefinitionBuilder {
private final Map<String, VariantsBuilder> variants = new HashMap<>();
private final List<SelectorBuilder> selectors = new ArrayList<>();

private BlockModelDefinitionBuilder() {
}

public static BlockModelDefinitionBuilder create() {
return new BlockModelDefinitionBuilder();
}

public static BlockModelDefinitionBuilder createSimple(NamespacedIdentifier modelLocation) {
return new BlockModelDefinitionBuilder().variant("", VariantsBuilder.of(modelLocation));
}

public BlockModelDefinitionBuilder variant(BlockState state, VariantsBuilder variants) {
this.variants.put(BlockModelShaper.propertiesToString(state.values()), variants);
return this;
}

public BlockModelDefinitionBuilder variant(BlockState state, NamespacedIdentifier modelLocation) {
this.variants.put(BlockModelShaper.propertiesToString(state.values()), VariantsBuilder.of(modelLocation));
return this;
}

public BlockModelDefinitionBuilder variant(PredicateBuilder predicateBuilder, VariantsBuilder variants) {
this.variants.put(predicateBuilder.build(), variants);
return this;
}

public BlockModelDefinitionBuilder variant(PredicateBuilder predicateBuilder, NamespacedIdentifier modelLocation) {
this.variants.put(predicateBuilder.build(), VariantsBuilder.of(modelLocation));
return this;
}

private BlockModelDefinitionBuilder variant(String variantName, VariantsBuilder variants) {
this.variants.put(variantName, variants);
return this;
}

public BlockModelDefinitionBuilder selector(VariantsBuilder variants) {
this.selectors.add(new SelectorBuilder(null, variants));
return this;
}

public BlockModelDefinitionBuilder selector(NamespacedIdentifier modelLocation) {
this.selectors.add(new SelectorBuilder(null, VariantsBuilder.of(modelLocation)));
return this;
}

public BlockModelDefinitionBuilder selector(ConditionsBuilder conditions, VariantsBuilder variants) {
this.selectors.add(new SelectorBuilder(conditions, variants));
return this;
}

public BlockModelDefinitionBuilder selector(ConditionsBuilder conditions, NamespacedIdentifier modelLocation) {
this.selectors.add(new SelectorBuilder(conditions, VariantsBuilder.of(modelLocation)));
return this;
}

public JsonObject build() {
JsonObject json = new JsonObject();

if (!variants.isEmpty()) {
JsonObject variantsJson = new JsonObject();

for (Map.Entry<String, VariantsBuilder> entry : variants.entrySet()) {
variantsJson.add(entry.getKey(), entry.getValue().build());
}

json.add("variants", variantsJson);
}

if (!selectors.isEmpty()) {
JsonArray multiPart = new JsonArray();

for (SelectorBuilder entry : selectors) {
multiPart.add(entry.build());
}

json.add("multipart", multiPart);
}

if (json.keySet().isEmpty()) {
throw new IllegalStateException("Block state model definition is empty");
}

return json;
}

static class SelectorBuilder {
private final ConditionsBuilder conditions;
private final VariantsBuilder variants;

SelectorBuilder(ConditionsBuilder conditions, VariantsBuilder variants) {
this.conditions = conditions;
this.variants = variants;
}

private JsonObject build() {
JsonObject json = new JsonObject();

if (conditions != null) json.add("when", conditions.build());
json.add("apply", variants.build());

return json;
}
}

public static <T extends Comparable<T>> PredicateBuilder predicate(Property<T> property, T value) {
return new PredicateBuilder().set(property, value);
}

public static class PredicateBuilder {
private final Map<Property<?>, Comparable<?>> predicates = new HashMap<>();

public <T extends Comparable<T>> PredicateBuilder set(Property<T> property, T value) {
predicates.put(property, value);
return this;
}

private String build() {
return BlockModelShaper.propertiesToString(predicates);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package net.ornithemc.osl.datagen.api.model.block;

import net.minecraft.block.Block;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
import net.ornithemc.osl.datagen.api.model.ModelBuilder;

public interface BlockModelTemplates {
BlockModelTemplates simpleBlock(Block block, NamespacedIdentifier texture);
BlockModelTemplates simpleBlockWithoutItem(Block block, NamespacedIdentifier texture);
BlockModelTemplates slab(Block block, NamespacedIdentifier doubleModelLocation, NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture, NamespacedIdentifier bottomTexture);
BlockModelTemplates simpleSlab(Block block, NamespacedIdentifier doubleModelLocation, NamespacedIdentifier texture);
BlockModelTemplates stairs(Block block, NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture, NamespacedIdentifier bottomTexture);
BlockModelTemplates simpleStairs(Block block, NamespacedIdentifier texture);

static ModelBuilder cube(
NamespacedIdentifier downTexture,
NamespacedIdentifier upTexture,
NamespacedIdentifier northTexture,
NamespacedIdentifier southTexture,
NamespacedIdentifier westTexture,
NamespacedIdentifier eastTexture
) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cube"))
.texture("down", downTexture)
.texture("up", upTexture)
.texture("north", northTexture)
.texture("south", southTexture)
.texture("west", westTexture)
.texture("east", eastTexture);
}

static ModelBuilder cubeAll(NamespacedIdentifier texture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cube_all")).texture("all", texture);
}

static ModelBuilder cubeBottomTop(NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture, NamespacedIdentifier bottomTexture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cube_bottom_top"))
.texture("side", sideTexture)
.texture("bottom", bottomTexture)
.texture("top", topTexture);
}

static ModelBuilder cubeColumn(NamespacedIdentifier sideTexture, NamespacedIdentifier endTexture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cube_column"))
.texture("side", sideTexture)
.texture("end", endTexture);
}

static ModelBuilder cubeDirectional(
NamespacedIdentifier downTexture,
NamespacedIdentifier upTexture,
NamespacedIdentifier northTexture,
NamespacedIdentifier southTexture,
NamespacedIdentifier westTexture,
NamespacedIdentifier eastTexture
) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cube_directional"))
.texture("down", downTexture)
.texture("up", upTexture)
.texture("north", northTexture)
.texture("south", southTexture)
.texture("west", westTexture)
.texture("east", eastTexture);
}

static ModelBuilder cubeMirrored(
NamespacedIdentifier downTexture,
NamespacedIdentifier upTexture,
NamespacedIdentifier northTexture,
NamespacedIdentifier southTexture,
NamespacedIdentifier westTexture,
NamespacedIdentifier eastTexture
) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cube_mirrored"))
.texture("down", downTexture)
.texture("up", upTexture)
.texture("north", northTexture)
.texture("south", southTexture)
.texture("west", westTexture)
.texture("east", eastTexture);
}

static ModelBuilder cubeAllMirrored(NamespacedIdentifier texture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cube_all_mirrored")).texture("all", texture);
}

static ModelBuilder cubeTop(NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cube_top"))
.texture("side", sideTexture)
.texture("top", topTexture);
}

static ModelBuilder slabBottom(NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture, NamespacedIdentifier bottomTexture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/slab"))
.texture("side", sideTexture)
.texture("top", topTexture)
.texture("bottom", bottomTexture);
}

static ModelBuilder slabTop(NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture, NamespacedIdentifier bottomTexture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/slab_top"))
.texture("side", sideTexture)
.texture("top", topTexture)
.texture("bottom", bottomTexture);
}

static ModelBuilder cross(NamespacedIdentifier texture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/cross")).texture("cross", texture);
}

static ModelBuilder stairs(NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture, NamespacedIdentifier bottomTexture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/stairs"))
.texture("side", sideTexture)
.texture("top", topTexture)
.texture("bottom", bottomTexture);
}

static ModelBuilder stairsInner(NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture, NamespacedIdentifier bottomTexture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/inner_stairs"))
.texture("side", sideTexture)
.texture("top", topTexture)
.texture("bottom", bottomTexture);
}

static ModelBuilder stairsOuter(NamespacedIdentifier sideTexture, NamespacedIdentifier topTexture, NamespacedIdentifier bottomTexture) {
return ModelBuilder.create(NamespacedIdentifiers.from("block/outer_stairs"))
.texture("side", sideTexture)
.texture("top", topTexture)
.texture("bottom", bottomTexture);
}
}
Loading
Loading