diff --git a/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java index 4c1ac05e4..3cd78138f 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java @@ -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; @@ -256,26 +255,20 @@ protected void generateBlockModels(KubeAssetGenerator generator) { } if (tint != null || !customShape.isEmpty()) { - List 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); + } + }); }); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/ButtonBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/ButtonBlockBuilder.java index f89e28360..648f3447c 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/ButtonBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/ButtonBlockBuilder.java @@ -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; @@ -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); } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/CarpetBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/CarpetBlockBuilder.java index e22ae7454..9a050a9b1 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/CarpetBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/CarpetBlockBuilder.java @@ -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); @@ -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); }); } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java index f297d6ecb..ae73b81ea 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java @@ -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); @@ -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))); }); } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/DoorBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/DoorBlockBuilder.java index 97313a904..697e1717f 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/DoorBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/DoorBlockBuilder.java @@ -36,6 +36,17 @@ public class DoorBlockBuilder extends ShapedBlockBuilder { BlockTags.TRAPDOORS.location(), }; + private static final Map 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) { @@ -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); }); diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/FenceBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/FenceBlockBuilder.java index 41a334a0d..02f84954c 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/FenceBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/FenceBlockBuilder.java @@ -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); @@ -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); }); } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/FenceGateBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/FenceGateBlockBuilder.java index bf0f2a654..2bed24b1d 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/FenceGateBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/FenceGateBlockBuilder.java @@ -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) { @@ -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); } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/HorizontalDirectionalBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/HorizontalDirectionalBlockBuilder.java index 80c4371e5..6bb300594 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/HorizontalDirectionalBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/HorizontalDirectionalBlockBuilder.java @@ -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); @@ -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) { diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/PressurePlateBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/PressurePlateBlockBuilder.java index f86278e69..4c901f3ec 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/PressurePlateBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/PressurePlateBlockBuilder.java @@ -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; @@ -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) { @@ -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")); - } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/SlabBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/SlabBlockBuilder.java index 299ece50e..eced9adf5 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/SlabBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/SlabBlockBuilder.java @@ -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"); @@ -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); diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/StairBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/StairBlockBuilder.java index 3a11ce10d..de44ea77c 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/StairBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/StairBlockBuilder.java @@ -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); @@ -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); diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/TrapdoorBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/TrapdoorBlockBuilder.java index 3dbb7f602..3a56050f4 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/TrapdoorBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/TrapdoorBlockBuilder.java @@ -21,6 +21,10 @@ public class TrapdoorBlockBuilder extends ShapedBlockBuilder { BlockTags.TRAPDOORS.location(), }; + private static final ResourceLocation MODEL = ResourceLocation.withDefaultNamespace("block/template_trapdoor_bottom"); + private static final ResourceLocation TOP_MODEL = ResourceLocation.withDefaultNamespace("block/template_trapdoor_top"); + private static final ResourceLocation OPEN_MODEL = ResourceLocation.withDefaultNamespace("block/template_trapdoor_open"); + public transient BlockSetType behaviour; public TrapdoorBlockBuilder(ResourceLocation i) { @@ -77,17 +81,17 @@ protected void generateBlockState(VariantBlockStateGenerator bs) { @Override protected void generateBlockModels(KubeAssetGenerator generator) { generator.blockModel(id, m -> { - m.parent("minecraft:block/template_trapdoor_bottom"); + m.parent(MODEL); m.texture("texture", baseTexture); }); generator.blockModel(newID("", "_top"), m -> { - m.parent("minecraft:block/template_trapdoor_top"); + m.parent(TOP_MODEL); m.texture("texture", baseTexture); }); generator.blockModel(newID("", "_open"), m -> { - m.parent("minecraft:block/template_trapdoor_open"); + m.parent(OPEN_MODEL); m.texture("texture", baseTexture); }); } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/WallBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/WallBlockBuilder.java index dceaebdbf..9f246a710 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/WallBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/WallBlockBuilder.java @@ -14,6 +14,11 @@ public class WallBlockBuilder extends ShapedBlockBuilder { BlockTags.WALLS.location(), }; + private static final ResourceLocation POST_MODEL = ResourceLocation.withDefaultNamespace("block/template_wall_post"); + private static final ResourceLocation SIDE_MODEL = ResourceLocation.withDefaultNamespace("block/template_wall_side"); + private static final ResourceLocation TALL_SIDE_MODEL = ResourceLocation.withDefaultNamespace("block/template_wall_side_tall"); + private static final ResourceLocation INVENTORY_MODEL = ResourceLocation.withDefaultNamespace("block/wall_inventory"); + public WallBlockBuilder(ResourceLocation i) { super(i, "_wall"); tagBoth(WALL_TAGS); @@ -48,24 +53,24 @@ protected void generateMultipartBlockState(MultipartBlockStateGenerator bs) { @Override protected void generateItemModel(ModelGenerator m) { - m.parent("minecraft:block/wall_inventory"); + m.parent(INVENTORY_MODEL); m.texture("wall", baseTexture); } @Override protected void generateBlockModels(KubeAssetGenerator generator) { generator.blockModel(newID("", "_post"), m -> { - m.parent("minecraft:block/template_wall_post"); + m.parent(POST_MODEL); m.texture("wall", baseTexture); }); generator.blockModel(newID("", "_side"), m -> { - m.parent("minecraft:block/template_wall_side"); + m.parent(SIDE_MODEL); m.texture("wall", baseTexture); }); generator.blockModel(newID("", "_side_tall"), m -> { - m.parent("minecraft:block/template_wall_side_tall"); + m.parent(TALL_SIDE_MODEL); m.texture("wall", baseTexture); }); } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java b/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java index c8e2bf68d..c332b0b74 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java @@ -3,7 +3,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.latvian.mods.kubejs.bindings.AABBWrapper; -import dev.latvian.mods.rhino.util.HideFromJS; +import dev.latvian.mods.kubejs.bindings.DirectionWrapper; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.AABB; @@ -17,47 +17,69 @@ public class ModelGenerator { public static class Element { - private AABB box = AABBWrapper.CUBE; - private final JsonObject faces = new JsonObject(); + private AABB size = AABBWrapper.CUBE; + private final Face[] faces = new Face[6]; public JsonObject toJson() { var json = new JsonObject(); var f = new JsonArray(); - f.add(box.minX * 16D); - f.add(box.minY * 16D); - f.add(box.minZ * 16D); + f.add(size.minX * 16D); + f.add(size.minY * 16D); + f.add(size.minZ * 16D); json.add("from", f); var t = new JsonArray(); - t.add(box.maxX * 16D); - t.add(box.maxY * 16D); - t.add(box.maxZ * 16D); + t.add(size.maxX * 16D); + t.add(size.maxY * 16D); + t.add(size.maxZ * 16D); json.add("to", t); - json.add("faces", faces); + var fc = new JsonObject(); + + for (var face : faces) { + if (face != null) { + fc.add(face.side.getSerializedName(), face.toJson()); + } + } + + json.add("faces", fc); return json; } - public Element box(AABB b) { - box = b; + public Element size(AABB b) { + size = b; return this; } - public void face(Direction direction, Consumer consumer) { - var f = new Face(); - f.direction = direction; - consumer.accept(f); - faces.add(direction.getSerializedName(), f.toJson()); + public void allFaces(Consumer face) { + faces(DirectionWrapper.VALUES, face); + } + + public void faces(Direction[] sides, Consumer face) { + for (var d : sides) { + var f = faces[d.ordinal()]; + + if (f == null) { + f = new Face(d); + faces[d.ordinal()] = f; + } + + face.accept(f); + } } } public static class Face { - private Direction direction; - private String texture = "broken"; + public final Direction side; + private String texture = "kubejs:block/unknown"; private Direction cullface = null; private double[] uv = null; private int tintindex = -1; + public Face(Direction side) { + this.side = side; + } + public JsonObject toJson() { var json = new JsonObject(); json.addProperty("texture", texture); @@ -93,7 +115,7 @@ public Face cull(Direction d) { } public Face cull() { - return cull(direction); + return cull(side); } public Face uv(double u0, double v0, double u1, double v1) { @@ -147,15 +169,16 @@ public void parent(@Nullable ResourceLocation s) { parent = s; } - @HideFromJS - public void parent(String s) { - parent = s.isEmpty() ? null : ResourceLocation.parse(s); - } - public void texture(String name, String texture) { textures.put(name, texture); } + public void texture(String[] name, String texture) { + for (var n : name) { + textures.put(n, texture); + } + } + public void textures(Map map) { textures.putAll(map); } diff --git a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBlockBuilder.java index 09bbf337e..0d7cb92ff 100644 --- a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBlockBuilder.java @@ -31,7 +31,7 @@ public Block createObject() { @Override protected void generateBlockModels(KubeAssetGenerator generator) { generator.blockModel(id, mg -> { - mg.parent(""); + mg.parent(null); mg.texture("particle", fluidBuilder.fluidType.stillTexture.toString()); }); } diff --git a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java index 9ba9841f3..c06c30b1f 100644 --- a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java @@ -7,6 +7,7 @@ import dev.latvian.mods.kubejs.generator.KubeAssetGenerator; import dev.latvian.mods.kubejs.registry.AdditionalObjectRegistry; import dev.latvian.mods.kubejs.registry.BuilderBase; +import dev.latvian.mods.kubejs.util.ID; import dev.latvian.mods.rhino.util.ReturnsSelf; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; @@ -22,6 +23,8 @@ public class FluidBuilder extends BuilderBase { public static final KubeColor WATER_COLOR = new SimpleColor(0xFF3F76E4); + private static final ResourceLocation GENERATED_BUCKET_MODEL = KubeJS.id("item/generated_bucket"); + public transient int slopeFindDistance = 4; public transient int levelDecreasePerBlock = 1; public transient float explosionResistance = 1; @@ -166,9 +169,9 @@ public void generateAssets(KubeAssetGenerator generator) { generator.texture(fluidType.actualFlowingTexture, flowingTexture.tint(fluidType.tint)); } - generator.blockState(id, m -> m.simpleVariant("", id.withPath("block/" + id.getPath()))); + generator.blockState(id, m -> m.simpleVariant("", id.withPath(ID.BLOCK))); generator.blockModel(id, m -> { - m.parent(""); + m.parent(null); m.texture("particle", fluidType.actualStillTexture.toString()); }); @@ -178,12 +181,7 @@ public void generateAssets(KubeAssetGenerator generator) { generator.mask(fluidPath, KubeJS.id("item/bucket_mask"), fluidType.actualStillTexture); generator.itemModel(bucketItem.id, m -> { - if (bucketItem.parentModel != null) { - m.parent(bucketItem.parentModel); - } else { - m.parent("kubejs:item/generated_bucket"); - } - + m.parent(bucketItem.parentModel == null ? GENERATED_BUCKET_MODEL : bucketItem.parentModel); m.texture("bucket_fluid", fluidPath.toString()); m.textures(bucketItem.textures); }); diff --git a/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexHighlight.java b/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexHighlight.java index 6d0d576fa..81d02e515 100644 --- a/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexHighlight.java +++ b/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexHighlight.java @@ -16,6 +16,7 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.MultiBufferSource; @@ -208,12 +209,20 @@ private void playSound(Minecraft mc) { } } + private int getFlags() { + int flags = 0; + flags |= Screen.hasShiftDown() ? 1 : 0; + flags |= Screen.hasControlDown() ? 2 : 0; + flags |= Screen.hasAltDown() ? 4 : 0; + return flags; + } + private void requestBlock(BlockPos pos) { - PacketDistributor.sendToServer(new RequestBlockKubedexPayload(pos)); + PacketDistributor.sendToServer(new RequestBlockKubedexPayload(pos, getFlags())); } private void requestEntity(Entity entity) { - PacketDistributor.sendToServer(new RequestEntityKubedexPayload(entity.getId())); + PacketDistributor.sendToServer(new RequestEntityKubedexPayload(entity.getId(), getFlags())); } private void requestInventory(Set slots) { @@ -228,7 +237,7 @@ private void requestInventory(Set slots) { } } - PacketDistributor.sendToServer(new RequestInventoryKubedexPayload(slotIds, stacks)); + PacketDistributor.sendToServer(new RequestInventoryKubedexPayload(slotIds, stacks, getFlags())); } private void keyToggled(Minecraft mc, Mode newMode, boolean success) { diff --git a/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexPayloadHandler.java b/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexPayloadHandler.java index 24181fed4..c62e72324 100644 --- a/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexPayloadHandler.java +++ b/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexPayloadHandler.java @@ -39,23 +39,35 @@ private static ListTag sortedTagList(Stream> stream) { .collect(ListTag::new, ListTag::add, ListTag::addAll); } - public static void block(ServerPlayer player, BlockPos pos) { + private static CompoundTag flags(int flags) { + var tag = new OrderedCompoundTag(); + tag.putBoolean("shift", (flags & 1) != 0); + tag.putBoolean("ctrl", (flags & 2) != 0); + tag.putBoolean("alt", (flags & 4) != 0); + return tag; + } + + public static void block(ServerPlayer player, BlockPos pos, int flags) { var registries = player.server.registryAccess(); var blockState = player.level().getBlockState(pos); if (!blockState.isAir()) { var payload = new OrderedCompoundTag(); - payload.putString("id", blockState.getBlock().kjs$getId()); - payload.putString("dimension", player.level().dimension().location().toString()); + payload.put("flags", flags(flags)); + + var payloadBlock = new OrderedCompoundTag(); + + payloadBlock.putString("id", blockState.getBlock().kjs$getId()); + payloadBlock.putString("dimension", player.level().dimension().location().toString()); var jpos = new OrderedCompoundTag(); - payload.put("pos", jpos); + payloadBlock.put("pos", jpos); jpos.putInt("x", pos.getX()); jpos.putInt("y", pos.getY()); jpos.putInt("z", pos.getZ()); var p = new CompoundTag(); - payload.put("properties", p); + payloadBlock.put("properties", p); for (var pk : blockState.getBlock().getStateDefinition().getProperties()) { p.putString(pk.getName(), pk.getName(Cast.to(blockState.getValue(pk)))); @@ -65,7 +77,7 @@ public static void block(ServerPlayer player, BlockPos pos) { if (blockEntity != null) { var ejson = new CompoundTag(); - payload.put("block_entity", ejson); + payloadBlock.put("block_entity", ejson); ejson.putString("id", BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(blockEntity.getType()).toString()); try { @@ -81,37 +93,45 @@ public static void block(ServerPlayer player, BlockPos pos) { } } + payload.put("block", payloadBlock); + PacketDistributor.sendToPlayer(player, new WebServerUpdateNBTPayload("highlight/block", "highlight", Optional.of(payload))); } } - public static void entity(ServerPlayer player, int entityId) { + public static void entity(ServerPlayer player, int entityId, int flags) { var entity = player.level().getEntity(entityId); if (entity != null) { var payload = new OrderedCompoundTag(); - payload.putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).toString()); - payload.putInt("network_id", entityId); - payload.putString("unique_id", entity.getUUID().toString()); - payload.putString("dimension", player.level().dimension().location().toString()); + payload.put("flags", flags(flags)); + + var payloadEntity = new OrderedCompoundTag(); + + payloadEntity.putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).toString()); + payloadEntity.putInt("network_id", entityId); + payloadEntity.putString("unique_id", entity.getUUID().toString()); + payloadEntity.putString("dimension", player.level().dimension().location().toString()); var jpos = new OrderedCompoundTag(); - payload.put("pos", jpos); + payloadEntity.put("pos", jpos); jpos.putDouble("x", entity.position().x); jpos.putDouble("y", entity.position().y); jpos.putDouble("z", entity.position().z); try { - payload.put("data", entity.saveWithoutId(new CompoundTag())); + payloadEntity.put("data", entity.saveWithoutId(new CompoundTag())); } catch (Exception ex) { - payload.put("data", new CompoundTag()); + payloadEntity.put("data", new CompoundTag()); } + payload.put("entity", payloadEntity); + PacketDistributor.sendToPlayer(player, new WebServerUpdateNBTPayload("highlight/entity", "highlight", Optional.of(payload))); } } - public static void inventory(ServerPlayer player, List slots, List stacks) { + public static void inventory(ServerPlayer player, List slots, List stacks, int flags) { var allStacks = new LinkedHashSet<>(stacks); for (int s : slots) { @@ -124,13 +144,16 @@ public static void inventory(ServerPlayer player, List slots, List stacks) { + public static void itemStacks(ServerPlayer player, Collection stacks, int flags) { var ops = player.server.registryAccess().createSerializationContext(NbtOps.INSTANCE); - var payload = new ListTag(); + var payload = new CompoundTag(); + payload.put("flags", flags(flags)); + + var payloadItems = new ListTag(); for (var stack : stacks) { var tag = new OrderedCompoundTag(); @@ -179,9 +202,11 @@ public static void itemStacks(ServerPlayer player, Collection stacks) } } - payload.add(tag); + payloadItems.add(tag); } + payload.put("items", payloadItems); + PacketDistributor.sendToPlayer(player, new WebServerUpdateNBTPayload("highlight/items", "highlight", Optional.of(payload))); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/net/RequestBlockKubedexPayload.java b/src/main/java/dev/latvian/mods/kubejs/net/RequestBlockKubedexPayload.java index 5fb776a5f..d26552abe 100644 --- a/src/main/java/dev/latvian/mods/kubejs/net/RequestBlockKubedexPayload.java +++ b/src/main/java/dev/latvian/mods/kubejs/net/RequestBlockKubedexPayload.java @@ -3,14 +3,16 @@ import dev.latvian.mods.kubejs.kubedex.KubedexPayloadHandler; import io.netty.buffer.ByteBuf; import net.minecraft.core.BlockPos; +import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.level.ServerPlayer; import net.neoforged.neoforge.network.handling.IPayloadContext; -public record RequestBlockKubedexPayload(BlockPos pos) implements CustomPacketPayload { +public record RequestBlockKubedexPayload(BlockPos pos, int flags) implements CustomPacketPayload { public static final StreamCodec STREAM_CODEC = StreamCodec.composite( BlockPos.STREAM_CODEC, RequestBlockKubedexPayload::pos, + ByteBufCodecs.VAR_INT, RequestBlockKubedexPayload::flags, RequestBlockKubedexPayload::new ); @@ -21,7 +23,7 @@ public Type type() { public void handle(IPayloadContext ctx) { if (ctx.player() instanceof ServerPlayer serverPlayer && serverPlayer.hasPermissions(2)) { - ctx.enqueueWork(() -> KubedexPayloadHandler.block(serverPlayer, pos)); + ctx.enqueueWork(() -> KubedexPayloadHandler.block(serverPlayer, pos, flags)); } } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/net/RequestEntityKubedexPayload.java b/src/main/java/dev/latvian/mods/kubejs/net/RequestEntityKubedexPayload.java index 61db28767..516298566 100644 --- a/src/main/java/dev/latvian/mods/kubejs/net/RequestEntityKubedexPayload.java +++ b/src/main/java/dev/latvian/mods/kubejs/net/RequestEntityKubedexPayload.java @@ -8,9 +8,10 @@ import net.minecraft.server.level.ServerPlayer; import net.neoforged.neoforge.network.handling.IPayloadContext; -public record RequestEntityKubedexPayload(int entityId) implements CustomPacketPayload { +public record RequestEntityKubedexPayload(int entityId, int flags) implements CustomPacketPayload { public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.VAR_INT, RequestEntityKubedexPayload::entityId, + ByteBufCodecs.VAR_INT, RequestEntityKubedexPayload::flags, RequestEntityKubedexPayload::new ); @@ -21,7 +22,7 @@ public Type type() { public void handle(IPayloadContext ctx) { if (ctx.player() instanceof ServerPlayer serverPlayer && serverPlayer.hasPermissions(2)) { - ctx.enqueueWork(() -> KubedexPayloadHandler.entity(serverPlayer, entityId)); + ctx.enqueueWork(() -> KubedexPayloadHandler.entity(serverPlayer, entityId, flags)); } } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/net/RequestInventoryKubedexPayload.java b/src/main/java/dev/latvian/mods/kubejs/net/RequestInventoryKubedexPayload.java index cda16c978..587df71b2 100644 --- a/src/main/java/dev/latvian/mods/kubejs/net/RequestInventoryKubedexPayload.java +++ b/src/main/java/dev/latvian/mods/kubejs/net/RequestInventoryKubedexPayload.java @@ -11,10 +11,11 @@ import java.util.List; -public record RequestInventoryKubedexPayload(List slots, List stacks) implements CustomPacketPayload { +public record RequestInventoryKubedexPayload(List slots, List stacks, int flags) implements CustomPacketPayload { public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.VAR_INT.apply(ByteBufCodecs.list()), RequestInventoryKubedexPayload::slots, ItemStack.STREAM_CODEC.apply(ByteBufCodecs.list()), RequestInventoryKubedexPayload::stacks, + ByteBufCodecs.VAR_INT, RequestInventoryKubedexPayload::flags, RequestInventoryKubedexPayload::new ); @@ -25,7 +26,7 @@ public Type type() { public void handle(IPayloadContext ctx) { if (ctx.player() instanceof ServerPlayer serverPlayer && serverPlayer.hasPermissions(2)) { - ctx.enqueueWork(() -> KubedexPayloadHandler.inventory(serverPlayer, slots, stacks)); + ctx.enqueueWork(() -> KubedexPayloadHandler.inventory(serverPlayer, slots, stacks, flags)); } } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/net/WebServerUpdateNBTPayload.java b/src/main/java/dev/latvian/mods/kubejs/net/WebServerUpdateNBTPayload.java index 47c204858..15e36e121 100644 --- a/src/main/java/dev/latvian/mods/kubejs/net/WebServerUpdateNBTPayload.java +++ b/src/main/java/dev/latvian/mods/kubejs/net/WebServerUpdateNBTPayload.java @@ -4,7 +4,6 @@ import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.web.local.KubeJSWeb; import io.netty.buffer.ByteBuf; -import net.minecraft.nbt.CollectionTag; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtOps; @@ -33,13 +32,13 @@ public void handle(IPayloadContext ctx) { int count = KubeJSWeb.broadcastUpdate("server/" + event, requiredTag, () -> payload.map(tag -> NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, tag)).orElse(null)); if (count == 0 && event.equals("highlight/items")) { - for (var e : (CollectionTag) payload.get()) { + for (var e : ((CompoundTag) payload.get()).getList("items", Tag.TAG_COMPOUND)) { var t = (CompoundTag) e; KubeJS.LOGGER.info("[Highlighted Item] " + t.getString("string")); if (t.get("tags") instanceof ListTag l) { for (var tag : l) { - KubeJS.LOGGER.info("[Highlighted Item] Item Tag: #" + tag.getAsString()); + KubeJS.LOGGER.info("[Highlighted Item] - #" + tag.getAsString()); } } }