Skip to content

Commit

Permalink
Updated model builder again, added flags to highlight payload, moved …
Browse files Browse the repository at this point in the history
…items/entity/block data into their own objects
  • Loading branch information
LatvianModder committed Sep 7, 2024
1 parent 11e827a commit b561674
Show file tree
Hide file tree
Showing 22 changed files with 219 additions and 138 deletions.
29 changes: 11 additions & 18 deletions src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.serialization.JsonOps;
import dev.latvian.mods.kubejs.bindings.AABBWrapper;
import dev.latvian.mods.kubejs.bindings.DirectionWrapper;
import dev.latvian.mods.kubejs.block.callbacks.AfterEntityFallenOnBlockCallbackJS;
import dev.latvian.mods.kubejs.block.callbacks.BlockExplodedCallbackJS;
import dev.latvian.mods.kubejs.block.callbacks.BlockStateMirrorCallbackJS;
Expand Down Expand Up @@ -256,26 +255,20 @@ protected void generateBlockModels(KubeAssetGenerator generator) {
}

if (tint != null || !customShape.isEmpty()) {
List<AABB> boxes = new ArrayList<>(customShape);

if (boxes.isEmpty()) {
boxes.add(AABBWrapper.CUBE);
}
var boxes = customShape.isEmpty() ? List.of(AABBWrapper.CUBE) : customShape;

for (var box : boxes) {
m.element(e -> {
e.box(box);

for (var direction : DirectionWrapper.VALUES) {
e.face(direction, face -> {
face.tex("#" + direction.getSerializedName());
face.cull();

if (tint != null) {
face.tintindex(0);
}
});
}
e.size(box);

e.allFaces(face -> {
face.tex("#" + face.side.getSerializedName());
face.cull();

if (tint != null) {
face.tintindex(0);
}
});
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class ButtonBlockBuilder extends ShapedBlockBuilder {
BlockTags.BUTTONS.location(),
};

private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/button");
private static final ResourceLocation PRESSED_MODEL = ResourceLocation.withDefaultNamespace("block/button_pressed");
private static final ResourceLocation INVENTORY_MODEL = ResourceLocation.withDefaultNamespace("block/button_inventory");

public transient BlockSetType behaviour;
public transient int ticksToStayPressed;

Expand Down Expand Up @@ -76,19 +80,19 @@ protected void generateBlockState(VariantBlockStateGenerator bs) {
@Override
protected void generateBlockModels(KubeAssetGenerator generator) {
generator.blockModel(id, m -> {
m.parent("minecraft:block/button");
m.parent(MODEL);
m.texture("texture", baseTexture);
});

generator.blockModel(newID("", "_pressed"), m -> {
m.parent("minecraft:block/button_pressed");
m.parent(PRESSED_MODEL);
m.texture("texture", baseTexture);
});
}

@Override
protected void generateItemModel(ModelGenerator m) {
m.parent("minecraft:block/button_inventory");
m.parent(INVENTORY_MODEL);
m.texture("texture", baseTexture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class CarpetBlockBuilder extends ShapedBlockBuilder {
BlockTags.WOOL_CARPETS.location(),
};

private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/carpet");

public CarpetBlockBuilder(ResourceLocation i) {
super(i, "_carpet");
tagBoth(CARPET_TAGS);
Expand All @@ -26,7 +28,7 @@ public Block createObject() {
@Override
protected void generateBlockModels(KubeAssetGenerator generator) {
generator.blockModel(id, m -> {
m.parent("minecraft:block/carpet");
m.parent(MODEL);
m.texture("wool", baseTexture);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class CropBlockBuilder extends BlockBuilder {
Tags.Items.SEEDS.location(),
};

private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/crop");

@FunctionalInterface
public interface SurviveCallback {
boolean survive(BlockState state, LevelReader reader, BlockPos pos);
Expand Down Expand Up @@ -258,7 +260,7 @@ protected void generateBlockModels(KubeAssetGenerator generator) {
for (int i = 0; i <= age; i++) {
final int fi = i;
generator.blockModel(newID("", "/" + i), m -> {
m.parent("minecraft:block/crop");
m.parent(MODEL);
m.texture("crop", textures.get(String.valueOf(fi)));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public class DoorBlockBuilder extends ShapedBlockBuilder {
BlockTags.TRAPDOORS.location(),
};

private static final Map<String, ResourceLocation> MODELS = Map.of(
"top_right", ResourceLocation.withDefaultNamespace("block/door_top_right"),
"top_right_open", ResourceLocation.withDefaultNamespace("block/door_top_right_open"),
"top_left", ResourceLocation.withDefaultNamespace("block/door_top_left"),
"top_left_open", ResourceLocation.withDefaultNamespace("block/door_top_left_open"),
"bottom_right", ResourceLocation.withDefaultNamespace("block/door_bottom_right"),
"bottom_right_open", ResourceLocation.withDefaultNamespace("block/door_bottom_right_open"),
"bottom_left", ResourceLocation.withDefaultNamespace("block/door_bottom_left"),
"bottom_left_open", ResourceLocation.withDefaultNamespace("block/door_bottom_left_open")
);

public transient BlockSetType behaviour;

public DoorBlockBuilder(ResourceLocation i) {
Expand Down Expand Up @@ -151,18 +162,9 @@ protected void generateBlockModels(KubeAssetGenerator generator) {
var topTexture = textures.get("top");
var bottomTexture = textures.get("bottom");

for (var type : List.of(
"top_right",
"top_right_open",
"top_left",
"top_left_open",
"bottom_right",
"bottom_right_open",
"bottom_left",
"bottom_left_open"
)) {
generator.blockModel(newID("", "_" + type), m -> {
m.parent("minecraft:block/door_" + type);
for (var entry : MODELS.entrySet()) {
generator.blockModel(newID("", "_" + entry.getKey()), m -> {
m.parent(entry.getValue());
m.texture("top", topTexture);
m.texture("bottom", bottomTexture);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class FenceBlockBuilder extends ShapedBlockBuilder {
Tags.Blocks.FENCES.location(),
};

private static final ResourceLocation SIDE_MODEL = ResourceLocation.withDefaultNamespace("block/fence_side");
private static final ResourceLocation POST_MODEL = ResourceLocation.withDefaultNamespace("block/fence_post");
private static final ResourceLocation INVENTORY_MODEL = ResourceLocation.withDefaultNamespace("block/fence_inventory");

public FenceBlockBuilder(ResourceLocation i) {
super(i, "_fence");
tagBoth(FENCE_TAGS);
Expand Down Expand Up @@ -44,18 +48,18 @@ protected void generateMultipartBlockState(MultipartBlockStateGenerator bs) {

@Override
protected void generateItemModel(ModelGenerator m) {
m.parent("minecraft:block/fence_inventory");
m.parent(INVENTORY_MODEL);
m.texture("texture", baseTexture);
}

@Override
protected void generateBlockModels(KubeAssetGenerator generator) {
generator.blockModel(newID("", "_post"), m -> {
m.parent("minecraft:block/fence_post");
m.parent(POST_MODEL);
m.texture("texture", baseTexture);
});
generator.blockModel(newID("", "_side"), m -> {
m.parent("minecraft:block/fence_side");
m.parent(SIDE_MODEL);
m.texture("texture", baseTexture);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class FenceGateBlockBuilder extends ShapedBlockBuilder {
Tags.Blocks.FENCE_GATES.location()
};

private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/template_fence_gate");
private static final ResourceLocation OPEN_MODEL = ResourceLocation.withDefaultNamespace("block/template_fence_gate_open");
private static final ResourceLocation WALL_MODEL = ResourceLocation.withDefaultNamespace("block/template_fence_gate_wall");
private static final ResourceLocation OPEN_WALL_MODEL = ResourceLocation.withDefaultNamespace("block/template_fence_gate_wall_open");

public transient WoodType behaviour;

public FenceGateBlockBuilder(ResourceLocation i) {
Expand Down Expand Up @@ -77,29 +82,29 @@ protected void generateBlockState(VariantBlockStateGenerator bs) {
@Override
protected void generateBlockModels(KubeAssetGenerator generator) {
generator.blockModel(id, m -> {
m.parent("minecraft:block/template_fence_gate");
m.parent(MODEL);
m.texture("texture", baseTexture);
});

generator.blockModel(newID("", "_open"), m -> {
m.parent("minecraft:block/template_fence_gate_open");
m.parent(OPEN_MODEL);
m.texture("texture", baseTexture);
});

generator.blockModel(newID("", "_wall"), m -> {
m.parent("minecraft:block/template_fence_gate_wall");
m.parent(WALL_MODEL);
m.texture("texture", baseTexture);
});

generator.blockModel(newID("", "_wall_open"), m -> {
m.parent("minecraft:block/template_fence_gate_wall_open");
m.parent(OPEN_WALL_MODEL);
m.texture("texture", baseTexture);
});
}

@Override
protected void generateItemModel(ModelGenerator m) {
m.parent("minecraft:block/template_fence_gate");
m.parent(MODEL);
m.texture("texture", baseTexture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
import java.util.Map;

@ReturnsSelf
// Cardinal blocks that can face any horizontal direction (NSEW).
public class HorizontalDirectionalBlockBuilder extends BlockBuilder {

// Cardinal blocks that can face any horizontal direction (NSEW).
private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/orientable");
private static final ResourceLocation BOTTOM_MODEL = ResourceLocation.withDefaultNamespace("block/orientable_with_bottom");

public HorizontalDirectionalBlockBuilder(ResourceLocation i) {
super(i);
Expand All @@ -62,10 +63,10 @@ protected void generateBlockModels(KubeAssetGenerator gen) {
mg.texture("top", textures.getOrDefault("top", side));

if (textures.containsKey("bottom")) {
mg.parent("block/orientable_with_bottom");
mg.parent(BOTTOM_MODEL);
mg.texture("bottom", textures.get("bottom"));
} else {
mg.parent("minecraft:block/orientable");
mg.parent(MODEL);
}

if (parentModel != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.latvian.mods.kubejs.block.custom;

import dev.latvian.mods.kubejs.client.ModelGenerator;
import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.kubejs.util.ID;
import dev.latvian.mods.rhino.util.ReturnsSelf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
Expand All @@ -16,6 +16,9 @@ public class PressurePlateBlockBuilder extends ShapedBlockBuilder {
BlockTags.PRESSURE_PLATES.location(),
};

private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/pressure_plate_up");
private static final ResourceLocation PRESSED_MODEL = ResourceLocation.withDefaultNamespace("block/pressure_plate_down");

public transient BlockSetType behaviour;

public PressurePlateBlockBuilder(ResourceLocation i) {
Expand Down Expand Up @@ -44,31 +47,25 @@ public PressurePlateBlockBuilder behaviour(String wt) {

@Override
public Block createObject() {
// TODO: Sensitivity is part of BlockSetType now
return new PressurePlateBlock(behaviour, createProperties());
}

@Override
protected void generateBlockState(VariantBlockStateGenerator bs) {
bs.variant("powered=false", v -> v.model(id.withPath(ID.BLOCK)));
bs.variant("powered=true", v -> v.model(newID("block/", "_down")));
bs.variant("powered=false", v -> v.model(newID("block/", "_up")));
}

@Override
protected void generateBlockModels(KubeAssetGenerator generator) {
generator.blockModel(newID("", "_down"), m -> {
m.parent("minecraft:block/pressure_plate_down");
generator.blockModel(id, m -> {
m.parent(MODEL);
m.texture("texture", baseTexture);
});

generator.blockModel(newID("", "_up"), m -> {
m.parent("minecraft:block/pressure_plate_up");
generator.blockModel(newID("", "_down"), m -> {
m.parent(PRESSED_MODEL);
m.texture("texture", baseTexture);
});
}

@Override
protected void generateItemModel(ModelGenerator m) {
m.parent(newID("block/", "_up"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class SlabBlockBuilder extends ShapedBlockBuilder {
BlockTags.SLABS.location(),
};

private static final ResourceLocation SLAB_BOTTOM = ResourceLocation.withDefaultNamespace("block/slab");
private static final ResourceLocation SLAB_TOP = ResourceLocation.withDefaultNamespace("block/slab_top");
private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/slab");
private static final ResourceLocation TOP_MODEL = ResourceLocation.withDefaultNamespace("block/slab_top");

public SlabBlockBuilder(ResourceLocation i) {
super(i, "_slab");
Expand All @@ -36,14 +36,14 @@ protected void generateBlockState(VariantBlockStateGenerator bs) {
@Override
protected void generateBlockModels(KubeAssetGenerator generator) {
generator.blockModel(id, m -> {
m.parent(SLAB_BOTTOM);
m.parent(MODEL);
m.texture("bottom", baseTexture);
m.texture("top", baseTexture);
m.texture("side", baseTexture);
});

generator.blockModel(newID("", "_top"), m -> {
m.parent(SLAB_TOP);
m.parent(TOP_MODEL);
m.texture("bottom", baseTexture);
m.texture("top", baseTexture);
m.texture("side", baseTexture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class StairBlockBuilder extends ShapedBlockBuilder {
BlockTags.STAIRS.location(),
};

private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/stairs");
private static final ResourceLocation INNER_MODEL = ResourceLocation.withDefaultNamespace("block/inner_stairs");
private static final ResourceLocation OUTER_MODEL = ResourceLocation.withDefaultNamespace("block/outer_stairs");

public StairBlockBuilder(ResourceLocation i) {
super(i, "_stairs");
tagBoth(STAIR_TAGS);
Expand Down Expand Up @@ -75,21 +79,21 @@ protected void generateBlockState(VariantBlockStateGenerator bs) {
@Override
protected void generateBlockModels(KubeAssetGenerator generator) {
generator.blockModel(id, m -> {
m.parent("minecraft:block/stairs");
m.parent(MODEL);
m.texture("bottom", baseTexture);
m.texture("top", baseTexture);
m.texture("side", baseTexture);
});

generator.blockModel(newID("", "_inner"), m -> {
m.parent("minecraft:block/inner_stairs");
m.parent(INNER_MODEL);
m.texture("bottom", baseTexture);
m.texture("top", baseTexture);
m.texture("side", baseTexture);
});

generator.blockModel(newID("", "_outer"), m -> {
m.parent("minecraft:block/outer_stairs");
m.parent(OUTER_MODEL);
m.texture("bottom", baseTexture);
m.texture("top", baseTexture);
m.texture("side", baseTexture);
Expand Down
Loading

0 comments on commit b561674

Please sign in to comment.