From 439d70779b3dd642aafe911e8f54dc89fc0d6e5b Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Mon, 2 Sep 2024 10:33:54 +0300 Subject: [PATCH] Renamed Color to KubeColor, added kjs$ prefix to methods, changed some String arguments for model builders to ResourceLocations --- .../mods/kubejs/BuiltinKubeJSPlugin.java | 6 +- .../mods/kubejs/bindings/BlockWrapper.java | 2 +- .../mods/kubejs/bindings/ColorWrapper.java | 94 ++++++++++--------- .../kubejs/bindings/DirectionWrapper.java | 4 +- .../mods/kubejs/block/BlockBuilder.java | 55 ++++++----- .../mods/kubejs/block/BlockRotationType.java | 39 ++++++-- .../mods/kubejs/block/BlockTintFunction.java | 14 +-- .../mods/kubejs/block/DetectorBlock.java | 7 +- .../mods/kubejs/block/SeedItemBuilder.java | 17 ++-- .../kubejs/block/custom/BasicBlockJS.java | 6 +- .../block/custom/ButtonBlockBuilder.java | 8 +- .../block/custom/CarpetBlockBuilder.java | 5 +- .../kubejs/block/custom/CropBlockBuilder.java | 6 +- .../kubejs/block/custom/DoorBlockBuilder.java | 25 ++--- .../block/custom/FallingBlockBuilder.java | 33 +++---- .../block/custom/FenceBlockBuilder.java | 8 +- .../block/custom/FenceGateBlockBuilder.java | 12 +-- .../HorizontalDirectionalBlockBuilder.java | 19 ++-- .../custom/MultipartShapedBlockBuilder.java | 7 +- .../custom/PressurePlateBlockBuilder.java | 8 +- .../block/custom/ShapedBlockBuilder.java | 4 +- .../kubejs/block/custom/SlabBlockBuilder.java | 10 +- .../block/custom/StairBlockBuilder.java | 8 +- .../block/custom/TrapdoorBlockBuilder.java | 10 +- .../kubejs/block/custom/WallBlockBuilder.java | 10 +- .../client/BlockTintFunctionWrapper.java | 2 +- .../client/ItemTintFunctionWrapper.java | 2 +- .../kubejs/client/KubeAnimatedParticle.java | 10 +- .../mods/kubejs/client/LoadedTexture.java | 10 +- .../mods/kubejs/client/ModelGenerator.java | 41 ++++---- .../client/MultipartBlockStateGenerator.java | 5 +- .../mods/kubejs/client/NotificationToast.java | 6 +- .../client/VariantBlockStateGenerator.java | 14 +-- .../dev/latvian/mods/kubejs/color/Color.java | 44 --------- .../latvian/mods/kubejs/color/KubeColor.java | 49 ++++++++++ .../latvian/mods/kubejs/color/NoColor.java | 12 +-- .../mods/kubejs/color/SimpleColor.java | 14 +-- .../kubejs/color/SimpleColorWithAlpha.java | 10 +- .../kubejs/component/ComponentFunctions.java | 10 +- .../component/ItemComponentFunctions.java | 6 +- .../mods/kubejs/core/ComponentKJS.java | 6 +- .../core/mixin/ChatFormattingMixin.java | 8 +- .../mods/kubejs/core/mixin/DyeColorMixin.java | 10 +- .../mods/kubejs/core/mixin/ItemMixin.java | 2 +- .../kubejs/core/mixin/TextColorMixin.java | 17 ++-- .../mods/kubejs/fluid/FluidBuilder.java | 19 ++-- .../mods/kubejs/fluid/FluidTypeBuilder.java | 6 +- .../kubejs/generator/KubeAssetGenerator.java | 34 +++---- .../latvian/mods/kubejs/item/ItemBuilder.java | 43 ++++----- .../mods/kubejs/item/ItemTintFunction.java | 10 +- .../kubejs/item/custom/DiggerItemBuilder.java | 16 +++- .../item/custom/HandheldItemBuilder.java | 3 +- .../kubejs/item/custom/ShearsItemBuilder.java | 3 +- .../kubejs/item/custom/SwordItemBuilder.java | 4 +- .../mods/kubejs/kgui/drawable/KColor.java | 6 +- .../mods/kubejs/misc/MobEffectBuilder.java | 6 +- .../mods/kubejs/recipe/RecipesKubeEvent.java | 5 +- .../mods/kubejs/registry/BuilderBase.java | 2 +- .../kubejs/server/ServerScriptManager.java | 2 +- .../java/dev/latvian/mods/kubejs/util/ID.java | 11 +++ .../kubejs/util/NotificationToastData.java | 30 +++--- 61 files changed, 484 insertions(+), 411 deletions(-) delete mode 100644 src/main/java/dev/latvian/mods/kubejs/color/Color.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/color/KubeColor.java diff --git a/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java b/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java index f6e596573..f077714a5 100644 --- a/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java +++ b/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java @@ -50,7 +50,7 @@ import dev.latvian.mods.kubejs.block.entity.BlockEntityAttachmentType; import dev.latvian.mods.kubejs.block.entity.InventoryAttachment; import dev.latvian.mods.kubejs.block.state.BlockStatePredicate; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.component.DataComponentWrapper; import dev.latvian.mods.kubejs.core.PlayerSelector; import dev.latvian.mods.kubejs.entity.AttributeBuilder; @@ -180,6 +180,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.stats.Stat; import net.minecraft.stats.Stats; +import net.minecraft.util.ColorRGBA; import net.minecraft.util.Unit; import net.minecraft.util.valueproviders.FloatProvider; import net.minecraft.util.valueproviders.IntProvider; @@ -579,6 +580,7 @@ public void registerTypeWrappers(TypeWrapperRegistry registry) { registry.register(BlockSetType.class, BlockWrapper::setTypeOf); registry.register(BlockState.class, BlockWrapper::wrapBlockState); registry.register(ItemAbility.class, ItemWrapper::itemAbilityOf); + registry.register(ColorRGBA.class, ColorWrapper::colorRGBAOf); // KubeJS // registry.register(Map.class, MapJS::of); @@ -614,7 +616,7 @@ public void registerTypeWrappers(TypeWrapperRegistry registry) { // components // registry.register(Component.class, TextWrapper::of); registry.register(MutableComponent.class, TextWrapper::of); - registry.register(Color.class, ColorWrapper::of); + registry.register(KubeColor.class, ColorWrapper::of); registry.register(TextColor.class, ColorWrapper::textColorOf); registry.register(ClickEvent.class, TextWrapper::clickEventOf); diff --git a/src/main/java/dev/latvian/mods/kubejs/bindings/BlockWrapper.java b/src/main/java/dev/latvian/mods/kubejs/bindings/BlockWrapper.java index 7bd20c9ea..205ed8147 100644 --- a/src/main/java/dev/latvian/mods/kubejs/bindings/BlockWrapper.java +++ b/src/main/java/dev/latvian/mods/kubejs/bindings/BlockWrapper.java @@ -67,7 +67,7 @@ public static Map getFacing() { if (facingMap == null) { facingMap = new HashMap<>(6); - for (var facing : Direction.values()) { + for (var facing : DirectionWrapper.VALUES) { facingMap.put(facing.getSerializedName(), facing); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/bindings/ColorWrapper.java b/src/main/java/dev/latvian/mods/kubejs/bindings/ColorWrapper.java index d3dbc66b3..1e1a13ee1 100644 --- a/src/main/java/dev/latvian/mods/kubejs/bindings/ColorWrapper.java +++ b/src/main/java/dev/latvian/mods/kubejs/bindings/ColorWrapper.java @@ -1,19 +1,20 @@ package dev.latvian.mods.kubejs.bindings; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.color.NoColor; import dev.latvian.mods.kubejs.color.SimpleColor; import dev.latvian.mods.kubejs.color.SimpleColorWithAlpha; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.network.chat.TextColor; +import net.minecraft.util.ColorRGBA; import net.minecraft.world.item.DyeColor; import java.util.HashMap; import java.util.Map; public interface ColorWrapper { - Map MAP = new HashMap<>(); + Map MAP = new HashMap<>(); Map TEXT = Util.make(new HashMap<>(), map -> { for (ChatFormatting c : ChatFormatting.values()) { map.put(c.getName(), c); @@ -25,12 +26,12 @@ public interface ColorWrapper { } }); - static Color of(Object o) { - if (o instanceof Color) { - return (Color) o; + static KubeColor of(Object o) { + if (o instanceof KubeColor) { + return (KubeColor) o; } else if (o instanceof String) { String s = o.toString(); - Color c = MAP.get(s); + KubeColor c = MAP.get(s); if (c != null) { return c; @@ -56,11 +57,15 @@ static Color of(Object o) { } static TextColor textColorOf(Object o) { - return of(o).createTextColorJS(); + return of(o).kjs$createTextColor(); } - static Color createMapped(Object o, String... names) { - Color c = of(o); + static ColorRGBA colorRGBAOf(Object o) { + return new ColorRGBA(of(o).kjs$getARGB()); + } + + static KubeColor createMapped(Object o, String... names) { + KubeColor c = of(o); for (String s : names) { MAP.put(s, c); @@ -69,46 +74,45 @@ static Color createMapped(Object o, String... names) { return c; } - Color NONE = createMapped(new NoColor(), "NONE", "none", "", "-", "transparent"); + KubeColor NONE = createMapped(new NoColor(), "NONE", "none", "", "-", "transparent"); - static Color rgba(int r, int g, int b, int a) { + static KubeColor rgba(int r, int g, int b, int a) { return new SimpleColor((r << 16) | (g << 8) | b | (a << 24)); } - Color BLACK = createMapped(ChatFormatting.BLACK, "BLACK", "black"); - Color DARK_BLUE = createMapped(ChatFormatting.DARK_BLUE, "DARK_BLUE", "dark_blue", "darkBlue"); - Color DARK_GREEN = createMapped(ChatFormatting.DARK_GREEN, "DARK_GREEN", "dark_green", "darkGreen"); - Color DARK_AQUA = createMapped(ChatFormatting.DARK_AQUA, "DARK_AQUA", "dark_aqua", "darkAqua"); - Color DARK_RED = createMapped(ChatFormatting.DARK_RED, "DARK_RED", "dark_red", "darkRed"); - Color DARK_PURPLE = createMapped(ChatFormatting.DARK_PURPLE, "DARK_PURPLE", "dark_purple", "darkPurple"); - Color GOLD = createMapped(ChatFormatting.GOLD, "GOLD", "gold"); - Color GRAY = createMapped(ChatFormatting.GRAY, "GRAY", "gray"); - Color DARK_GRAY = createMapped(ChatFormatting.DARK_GRAY, "DARK_GRAY", "dark_gray", "darkGray"); - Color BLUE = createMapped(ChatFormatting.BLUE, "BLUE", "blue"); - Color GREEN = createMapped(ChatFormatting.GREEN, "GREEN", "green"); - Color AQUA = createMapped(ChatFormatting.AQUA, "AQUA", "aqua"); - Color RED = createMapped(ChatFormatting.RED, "RED", "red"); - Color LIGHT_PURPLE = createMapped(ChatFormatting.LIGHT_PURPLE, "LIGHT_PURPLE", "light_purple", "lightPurple"); - Color YELLOW = createMapped(ChatFormatting.YELLOW, "YELLOW", "yellow"); - Color WHITE = createMapped(ChatFormatting.WHITE, "WHITE", "white"); - - - Color WHITE_DYE = createMapped(DyeColor.WHITE, "WHITE_DYE", "white_dye", "whiteDye"); - Color ORANGE_DYE = createMapped(DyeColor.ORANGE, "ORANGE_DYE", "orange_dye", "orangeDye"); - Color MAGENTA_DYE = createMapped(DyeColor.MAGENTA, "MAGENTA_DYE", "magenta_dye", "magentaDye"); - Color LIGHT_BLUE_DYE = createMapped(DyeColor.LIGHT_BLUE, "LIGHT_BLUE_DYE", "light_blue_dye", "lightBlueDye"); - Color YELLOW_DYE = createMapped(DyeColor.YELLOW, "YELLOW_DYE", "yellow_dye", "yellowDye"); - Color LIME_DYE = createMapped(DyeColor.LIME, "LIME_DYE", "lime_dye", "limeDye"); - Color PINK_DYE = createMapped(DyeColor.PINK, "PINK_DYE", "pink_dye", "pinkDye"); - Color GRAY_DYE = createMapped(DyeColor.GRAY, "GRAY_DYE", "gray_dye", "grayDye"); - Color LIGHT_GRAY_DYE = createMapped(DyeColor.LIGHT_GRAY, "LIGHT_GRAY_DYE", "lightGrayDye", "lightGrayDye"); - Color CYAN_DYE = createMapped(DyeColor.CYAN, "CYAN_DYE", "cyan_dye", "cyanDye"); - Color PURPLE_DYE = createMapped(DyeColor.PURPLE, "PURPLE_DYE", "purple_dye", "purpleDye"); - Color BLUE_DYE = createMapped(DyeColor.BLUE, "BLUE_DYE", "blue_dye", "blueDye"); - Color BROWN_DYE = createMapped(DyeColor.BROWN, "BROWN_DYE", "brown_dye", "brownDye"); - Color GREEN_DYE = createMapped(DyeColor.GREEN, "GREEN_DYE", "green_dye", "greenDye"); - Color RED_DYE = createMapped(DyeColor.RED, "RED_DYE", "red_dye", "redDye"); - Color BLACK_DYE = createMapped(DyeColor.BLACK, "BLACK_DYE", "black_dye", "blackDye"); + KubeColor BLACK = createMapped(ChatFormatting.BLACK, "BLACK", "black"); + KubeColor DARK_BLUE = createMapped(ChatFormatting.DARK_BLUE, "DARK_BLUE", "dark_blue", "darkBlue"); + KubeColor DARK_GREEN = createMapped(ChatFormatting.DARK_GREEN, "DARK_GREEN", "dark_green", "darkGreen"); + KubeColor DARK_AQUA = createMapped(ChatFormatting.DARK_AQUA, "DARK_AQUA", "dark_aqua", "darkAqua"); + KubeColor DARK_RED = createMapped(ChatFormatting.DARK_RED, "DARK_RED", "dark_red", "darkRed"); + KubeColor DARK_PURPLE = createMapped(ChatFormatting.DARK_PURPLE, "DARK_PURPLE", "dark_purple", "darkPurple"); + KubeColor GOLD = createMapped(ChatFormatting.GOLD, "GOLD", "gold"); + KubeColor GRAY = createMapped(ChatFormatting.GRAY, "GRAY", "gray"); + KubeColor DARK_GRAY = createMapped(ChatFormatting.DARK_GRAY, "DARK_GRAY", "dark_gray", "darkGray"); + KubeColor BLUE = createMapped(ChatFormatting.BLUE, "BLUE", "blue"); + KubeColor GREEN = createMapped(ChatFormatting.GREEN, "GREEN", "green"); + KubeColor AQUA = createMapped(ChatFormatting.AQUA, "AQUA", "aqua"); + KubeColor RED = createMapped(ChatFormatting.RED, "RED", "red"); + KubeColor LIGHT_PURPLE = createMapped(ChatFormatting.LIGHT_PURPLE, "LIGHT_PURPLE", "light_purple", "lightPurple"); + KubeColor YELLOW = createMapped(ChatFormatting.YELLOW, "YELLOW", "yellow"); + KubeColor WHITE = createMapped(ChatFormatting.WHITE, "WHITE", "white"); + + KubeColor WHITE_DYE = createMapped(DyeColor.WHITE, "WHITE_DYE", "white_dye", "whiteDye"); + KubeColor ORANGE_DYE = createMapped(DyeColor.ORANGE, "ORANGE_DYE", "orange_dye", "orangeDye"); + KubeColor MAGENTA_DYE = createMapped(DyeColor.MAGENTA, "MAGENTA_DYE", "magenta_dye", "magentaDye"); + KubeColor LIGHT_BLUE_DYE = createMapped(DyeColor.LIGHT_BLUE, "LIGHT_BLUE_DYE", "light_blue_dye", "lightBlueDye"); + KubeColor YELLOW_DYE = createMapped(DyeColor.YELLOW, "YELLOW_DYE", "yellow_dye", "yellowDye"); + KubeColor LIME_DYE = createMapped(DyeColor.LIME, "LIME_DYE", "lime_dye", "limeDye"); + KubeColor PINK_DYE = createMapped(DyeColor.PINK, "PINK_DYE", "pink_dye", "pinkDye"); + KubeColor GRAY_DYE = createMapped(DyeColor.GRAY, "GRAY_DYE", "gray_dye", "grayDye"); + KubeColor LIGHT_GRAY_DYE = createMapped(DyeColor.LIGHT_GRAY, "LIGHT_GRAY_DYE", "lightGrayDye", "lightGrayDye"); + KubeColor CYAN_DYE = createMapped(DyeColor.CYAN, "CYAN_DYE", "cyan_dye", "cyanDye"); + KubeColor PURPLE_DYE = createMapped(DyeColor.PURPLE, "PURPLE_DYE", "purple_dye", "purpleDye"); + KubeColor BLUE_DYE = createMapped(DyeColor.BLUE, "BLUE_DYE", "blue_dye", "blueDye"); + KubeColor BROWN_DYE = createMapped(DyeColor.BROWN, "BROWN_DYE", "brown_dye", "brownDye"); + KubeColor GREEN_DYE = createMapped(DyeColor.GREEN, "GREEN_DYE", "green_dye", "greenDye"); + KubeColor RED_DYE = createMapped(DyeColor.RED, "RED_DYE", "red_dye", "redDye"); + KubeColor BLACK_DYE = createMapped(DyeColor.BLACK, "BLACK_DYE", "black_dye", "blackDye"); } diff --git a/src/main/java/dev/latvian/mods/kubejs/bindings/DirectionWrapper.java b/src/main/java/dev/latvian/mods/kubejs/bindings/DirectionWrapper.java index d13958503..759f5fd19 100644 --- a/src/main/java/dev/latvian/mods/kubejs/bindings/DirectionWrapper.java +++ b/src/main/java/dev/latvian/mods/kubejs/bindings/DirectionWrapper.java @@ -3,7 +3,6 @@ import net.minecraft.core.Direction; import java.util.Arrays; -import java.util.Collections; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @@ -21,5 +20,6 @@ public interface DirectionWrapper { Direction SOUTH = Direction.SOUTH; Direction WEST = Direction.WEST; Direction EAST = Direction.EAST; - Map ALL = Collections.unmodifiableMap(Arrays.stream(Direction.values()).collect(Collectors.toMap(Direction::getSerializedName, Function.identity()))); + Direction[] VALUES = Direction.values(); + Map ALL = Map.copyOf(Arrays.stream(VALUES).collect(Collectors.toMap(Direction::getSerializedName, Function.identity()))); } \ No newline at end of file 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 a551815f5..c3fe63d6b 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java @@ -2,6 +2,8 @@ import com.google.gson.JsonObject; 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; @@ -26,6 +28,7 @@ import dev.latvian.mods.kubejs.script.ScriptType; import dev.latvian.mods.kubejs.typings.Info; import dev.latvian.mods.kubejs.util.Cast; +import dev.latvian.mods.kubejs.util.ID; import dev.latvian.mods.rhino.util.HideFromJS; import dev.latvian.mods.rhino.util.ReturnsSelf; import net.minecraft.core.Direction; @@ -55,8 +58,10 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; @@ -79,8 +84,8 @@ public abstract class BlockBuilder extends BuilderBase { public transient boolean requiresTool; public transient BlockRenderType renderType; public transient BlockTintFunction tint; - public transient final JsonObject textures; - public transient String model; + public transient final Map textures; + public transient ResourceLocation model; public transient ItemBuilder itemBuilder; public transient List customShape; public transient boolean noCollision; @@ -122,9 +127,9 @@ public BlockBuilder(ResourceLocation i) { fullBlock = false; requiresTool = false; renderType = BlockRenderType.SOLID; - textures = new JsonObject(); - textureAll(id.getNamespace() + ":block/" + id.getPath()); - model = ""; + textures = new HashMap<>(0); + textureAll(id.withPath("block/" + id.getPath()).toString()); + model = null; itemBuilder = getOrCreateItemBuilder(); if (itemBuilder instanceof BlockItemBuilder b) { @@ -185,7 +190,7 @@ public void generateData(KubeDataGenerator generator) { var table = generateLootTable(); if (table != null) { - generator.json(newID("loot_table/blocks/", ""), LootTable.CODEC.encodeStart(JsonOps.INSTANCE, new Holder.Direct<>(table)).getOrThrow()); + generator.json(id.withPath(ID.BLOCK_LOOT_TABLE), LootTable.CODEC.encodeStart(JsonOps.INSTANCE, new Holder.Direct<>(table)).getOrThrow()); } } @@ -229,13 +234,13 @@ public LootTable generateLootTable() { @Override public void generateAssets(KubeAssetGenerator generator) { if (blockstateJson != null) { - generator.json(newID("blockstates/", ""), blockstateJson); + generator.json(id.withPath(ID.BLOCKSTATE), blockstateJson); } else { generator.blockState(id, this::generateBlockStateJson); } if (modelJson != null) { - generator.json(newID("models/block/", ""), modelJson); + generator.json(id.withPath(ID.BLOCK_MODEL), modelJson); } else { // This is different because there can be multiple models, so we should let the block handle those generateBlockModelJsons(generator); @@ -243,7 +248,7 @@ public void generateAssets(KubeAssetGenerator generator) { if (itemBuilder != null) { if (itemBuilder.modelJson != null) { - generator.json(newID("models/item/", ""), itemBuilder.modelJson); + generator.json(id.withPath(ID.ITEM_MODEL), itemBuilder.modelJson); } else { generator.itemModel(itemBuilder.id, this::generateItemModelJson); } @@ -252,22 +257,22 @@ public void generateAssets(KubeAssetGenerator generator) { } protected void generateItemModelJson(ModelGenerator m) { - if (!model.isEmpty()) { + if (model != null) { m.parent(model); } else { - m.parent(newID("block/", "").toString()); + m.parent(id.withPath(ID.BLOCK)); } } protected void generateBlockModelJsons(KubeAssetGenerator generator) { generator.blockModel(id, mg -> { - var particle = textures.get("particle").getAsString(); + var particle = textures.get("particle"); - if (areAllTexturesEqual(textures, particle)) { - mg.parent("minecraft:block/cube_all"); + if (areAllTexturesEqual(particle)) { + mg.parent(KubeAssetGenerator.CUBE_ALL_BLOCK_MODEL); mg.texture("all", particle); } else { - mg.parent("block/cube"); + mg.parent(KubeAssetGenerator.CUBE_BLOCK_MODEL); mg.textures(textures); } @@ -275,14 +280,14 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { List boxes = new ArrayList<>(customShape); if (boxes.isEmpty()) { - boxes.add(new AABB(0D, 0D, 0D, 1D, 1D, 1D)); + boxes.add(AABBWrapper.CUBE); } for (var box : boxes) { mg.element(e -> { e.box(box); - for (var direction : Direction.values()) { + for (var direction : DirectionWrapper.VALUES) { e.face(direction, face -> { face.tex("#" + direction.getSerializedName()); face.cull(); @@ -299,12 +304,12 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { } protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - bs.simpleVariant("", model.isEmpty() ? (id.getNamespace() + ":block/" + id.getPath()) : model); + bs.simpleVariant("", model == null ? id.withPath(ID.BLOCK) : model); } - protected boolean areAllTexturesEqual(JsonObject tex, String t) { - for (var direction : Direction.values()) { - if (!tex.get(direction.getSerializedName()).getAsString().equals(t)) { + protected boolean areAllTexturesEqual(String t) { + for (var direction : DirectionWrapper.VALUES) { + if (!textures.get(direction.getSerializedName()).equals(t)) { return false; } } @@ -461,11 +466,11 @@ public BlockBuilder color(BlockTintFunction color) { Texture the block on all sides with the same texture. """) public BlockBuilder textureAll(String tex) { - for (var direction : Direction.values()) { + for (var direction : DirectionWrapper.VALUES) { textureSide(direction, tex); } - textures.addProperty("particle", tex); + textures.put("particle", tex); return this; } @@ -480,14 +485,14 @@ public BlockBuilder textureSide(Direction direction, String tex) { Texture a specific texture key of the block. """) public BlockBuilder texture(String id, String tex) { - textures.addProperty(id, tex); + textures.put(id, tex); return this; } @Info(""" Set the block's model. """) - public BlockBuilder model(String m) { + public BlockBuilder model(ResourceLocation m) { model = m; if (itemBuilder != null) { itemBuilder.parentModel(m); diff --git a/src/main/java/dev/latvian/mods/kubejs/block/BlockRotationType.java b/src/main/java/dev/latvian/mods/kubejs/block/BlockRotationType.java index c69b36bd1..7b3a52012 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/BlockRotationType.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/BlockRotationType.java @@ -1,9 +1,36 @@ package dev.latvian.mods.kubejs.block; -public enum BlockRotationType { - NONE, - VERTICAL, - HORIZONTAL, - FACING, - WALL_ATTACHED +import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator; +import dev.latvian.mods.kubejs.generator.KubeAssetGenerator; +import net.minecraft.util.StringRepresentable; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.Property; + +import java.util.List; + +public enum BlockRotationType implements StringRepresentable { + NONE("none"), + HORIZONTAL("horizontal", BlockStateProperties.HORIZONTAL_FACING), + VERTICAL("vertical", BlockStateProperties.ATTACH_FACE), + FACING("facing", BlockStateProperties.FACING), + WALL_ATTACHED("wall_attached", BlockStateProperties.HORIZONTAL_FACING, BlockStateProperties.ATTACH_FACE); + + public final String name; + public final List> properties; + + BlockRotationType(String name, Property... properties) { + this.name = name; + this.properties = List.of(properties); + } + + @Override + public String getSerializedName() { + return name; + } + + public void generateBlockStateJson(VariantBlockStateGenerator bs, BlockBuilder block) { + } + + public void generateBlockModelJsons(KubeAssetGenerator gen) { + } } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/BlockTintFunction.java b/src/main/java/dev/latvian/mods/kubejs/block/BlockTintFunction.java index fb30c6e8b..0734fd740 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/BlockTintFunction.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/BlockTintFunction.java @@ -1,7 +1,7 @@ package dev.latvian.mods.kubejs.block; import dev.latvian.mods.kubejs.bindings.ColorWrapper; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.color.SimpleColor; import dev.latvian.mods.kubejs.color.SimpleColorWithAlpha; import dev.latvian.mods.rhino.BaseFunction; @@ -26,11 +26,11 @@ public interface BlockTintFunction { TypeInfo TYPE_INFO = TypeInfo.of(BlockTintFunction.class); - Color getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int index); + KubeColor getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int index); - record Fixed(Color color) implements BlockTintFunction { + record Fixed(KubeColor color) implements BlockTintFunction { @Override - public Color getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int index) { + public KubeColor getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int index) { return color; } } @@ -39,20 +39,20 @@ class Mapped implements BlockTintFunction { public final Int2ObjectMap map = new Int2ObjectArrayMap<>(1); @Override - public Color getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int index) { + public KubeColor getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int index) { var f = map.get(index); return f == null ? null : f.getColor(state, level, pos, index); } } BlockTintFunction GRASS = (s, l, p, i) -> new SimpleColor(l == null || p == null ? GrassColor.get(0.5, 1.0) : BiomeColors.getAverageGrassColor(l, p)); - Color DEFAULT_FOLIAGE_COLOR = new SimpleColor(FoliageColor.getDefaultColor()); + KubeColor DEFAULT_FOLIAGE_COLOR = new SimpleColor(FoliageColor.getDefaultColor()); BlockTintFunction FOLIAGE = (s, l, p, i) -> l == null || p == null ? DEFAULT_FOLIAGE_COLOR : new SimpleColor(BiomeColors.getAverageFoliageColor(l, p)); Fixed EVERGREEN_FOLIAGE = new Fixed(new SimpleColor(FoliageColor.getEvergreenColor())); Fixed BIRCH_FOLIAGE = new Fixed(new SimpleColor(FoliageColor.getBirchColor())); Fixed MANGROVE_FOLIAGE = new Fixed(new SimpleColor(FoliageColor.getMangroveColor())); BlockTintFunction WATER = (s, l, p, i) -> l == null || p == null ? null : new SimpleColorWithAlpha(BiomeColors.getAverageWaterColor(l, p)); - Color[] REDSTONE_COLORS = new Color[16]; + KubeColor[] REDSTONE_COLORS = new KubeColor[16]; BlockTintFunction REDSTONE = (state, level, pos, index) -> { if (REDSTONE_COLORS[0] == null) { for (int i = 0; i < REDSTONE_COLORS.length; i++) { diff --git a/src/main/java/dev/latvian/mods/kubejs/block/DetectorBlock.java b/src/main/java/dev/latvian/mods/kubejs/block/DetectorBlock.java index 97f4a3bb1..8e4a850c6 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/DetectorBlock.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/DetectorBlock.java @@ -17,6 +17,9 @@ public class DetectorBlock extends Block { @ReturnsSelf public static class Builder extends BlockBuilder { + private static final ResourceLocation OFF_MODEL = KubeJS.id("block/detector"); + private static final ResourceLocation ON_MODEL = KubeJS.id("block/detector_on"); + public transient String detectorId; public Builder(ResourceLocation i) { @@ -48,8 +51,8 @@ public Block createObject() { @Override public void generateAssets(KubeAssetGenerator generator) { generator.blockState(id, bs -> { - bs.simpleVariant("powered=false", "kubejs:block/detector"); - bs.simpleVariant("powered=true", "kubejs:block/detector_on"); + bs.simpleVariant("powered=false", OFF_MODEL); + bs.simpleVariant("powered=true", ON_MODEL); }); generator.itemModel(id, m -> m.parent(KubeJS.MOD_ID + ":block/detector")); diff --git a/src/main/java/dev/latvian/mods/kubejs/block/SeedItemBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/SeedItemBuilder.java index ffa1ff930..e8be848dc 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/SeedItemBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/SeedItemBuilder.java @@ -1,8 +1,8 @@ package dev.latvian.mods.kubejs.block; -import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.block.custom.BasicCropBlockJS; import dev.latvian.mods.kubejs.generator.KubeAssetGenerator; +import dev.latvian.mods.kubejs.util.ID; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; @@ -56,21 +56,18 @@ public Item createObject() { @Override public void generateAssets(KubeAssetGenerator generator) { if (modelJson != null) { - generator.json(KubeAssetGenerator.asItemModelLocation(id), modelJson); + generator.json(id.withPath(ID.ITEM_MODEL), modelJson); return; } generator.itemModel(id, m -> { - if (!parentModel.isEmpty()) { - m.parent(parentModel); - } else { - m.parent("minecraft:item/generated"); - } + m.parent(parentModel != null ? parentModel : KubeAssetGenerator.GENERATED_ITEM_MODEL); - if (textureJson.size() == 0) { - texture(newID("item/", "").toString()); + if (textures.isEmpty()) { + texture(id.withPath(ID.ITEM).toString()); } - m.textures(textureJson); + + m.textures(textures); }); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java index 062607d1c..2741b4f80 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java @@ -76,13 +76,13 @@ public WithEntity(BlockBuilder p) { @Nullable @Override - public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return blockBuilder.blockEntityInfo.createBlockEntity(blockPos, blockState); + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return blockBuilder.blockEntityInfo.createBlockEntity(pos, state); } @Nullable @Override - public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { + public BlockEntityTicker getTicker(Level level, BlockState state, BlockEntityType blockEntityType) { return blockBuilder.blockEntityInfo.getTicker(level); } } 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 d8c77b2d4..d3255f1db 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 @@ -45,8 +45,8 @@ public Block createObject() { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - var mod0 = newID("block/", "").toString(); - var mod1 = newID("block/", "_pressed").toString(); + var mod0 = newID("block/", ""); + var mod1 = newID("block/", "_pressed"); bs.variant("face=ceiling,facing=east,powered=false", v -> v.model(mod0).x(180).y(270)); bs.variant("face=ceiling,facing=east,powered=true", v -> v.model(mod1).x(180).y(270)); @@ -76,7 +76,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) { @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(id, m -> { m.parent("minecraft:block/button"); @@ -92,6 +92,6 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { @Override protected void generateItemModelJson(ModelGenerator m) { m.parent("minecraft:block/button_inventory"); - m.texture("texture", textures.get("texture").getAsString()); + m.texture("texture", textures.get("texture")); } } \ 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 084c4b724..a64a6f192 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 @@ -2,6 +2,7 @@ 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; @@ -26,13 +27,13 @@ public Block createObject() { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - var mod = newID("block/", "").toString(); + var mod = id.withPath(ID.BLOCK); bs.variant("", (v) -> v.model(mod)); } @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(id, m -> { m.parent("minecraft:block/carpet"); 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 f1316d002..1807556c1 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 @@ -198,7 +198,7 @@ public BlockBuilder texture(String id, String tex) { } public CropBlockBuilder farmersCanPlant() { - this.tagItem(new ResourceLocation[]{ResourceLocation.fromNamespaceAndPath("minecraft", "villager_plantable_seeds")}); + this.tagItem(new ResourceLocation[]{ResourceLocation.withDefaultNamespace("villager_plantable_seeds")}); return this; } @@ -255,7 +255,7 @@ public LootTable generateLootTable() { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { for (int i = 0; i <= age; i++) { - bs.simpleVariant("age=" + i, model.isEmpty() ? (id.getNamespace() + ":block/" + id.getPath() + "/" + i) : model); + bs.simpleVariant("age=" + i, model == null ? id.withPath("block/" + id.getPath() + "/" + i) : model); } } @@ -265,7 +265,7 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { final int fi = i; generator.blockModel(newID("", "/" + i), m -> { m.parent("minecraft:block/crop"); - m.texture("crop", textures.get(String.valueOf(fi)).getAsString()); + 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 e46e8b0e6..abcf64ab8 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 @@ -5,6 +5,7 @@ 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.advancements.critereon.StatePropertiesPredicate; import net.minecraft.core.Direction; @@ -64,22 +65,22 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) { var modelMap = Map.of( DoubleBlockHalf.UPPER, Map.of( DoorHingeSide.RIGHT, Map.of( - Boolean.FALSE, newID("block/", "_top_right").toString(), - Boolean.TRUE, newID("block/", "_top_right_open").toString() + Boolean.FALSE, newID("block/", "_top_right"), + Boolean.TRUE, newID("block/", "_top_right_open") ), DoorHingeSide.LEFT, Map.of( - Boolean.FALSE, newID("block/", "_top_left").toString(), - Boolean.TRUE, newID("block/", "_top_left_open").toString() + Boolean.FALSE, newID("block/", "_top_left"), + Boolean.TRUE, newID("block/", "_top_left_open") ) ), DoubleBlockHalf.LOWER, Map.of( DoorHingeSide.RIGHT, Map.of( - Boolean.FALSE, newID("block/", "_bottom_right").toString(), - Boolean.TRUE, newID("block/", "_bottom_right_open").toString() + Boolean.FALSE, newID("block/", "_bottom_right"), + Boolean.TRUE, newID("block/", "_bottom_right_open") ), DoorHingeSide.LEFT, Map.of( - Boolean.FALSE, newID("block/", "_bottom_left").toString(), - Boolean.TRUE, newID("block/", "_bottom_left_open").toString() + Boolean.FALSE, newID("block/", "_bottom_left"), + Boolean.TRUE, newID("block/", "_bottom_left_open") ) ) ); @@ -147,8 +148,8 @@ Boolean.TRUE, newID("block/", "_bottom_left_open").toString() @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var topTexture = textures.get("top").getAsString(); - var bottomTexture = textures.get("bottom").getAsString(); + var topTexture = textures.get("top"); + var bottomTexture = textures.get("bottom"); for (var type : List.of( "top_right", @@ -205,7 +206,7 @@ public LootTable generateLootTable() { @Override protected void generateItemModelJson(ModelGenerator m) { - m.parent("minecraft:item/generated"); - m.texture("layer0", newID("item/", "").toString()); + m.parent(KubeAssetGenerator.GENERATED_ITEM_MODEL); + m.texture("layer0", id.withPath(ID.ITEM).toString()); } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/FallingBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/FallingBlockBuilder.java index 361ad54a1..d5d27a6a7 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/FallingBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/FallingBlockBuilder.java @@ -1,13 +1,12 @@ package dev.latvian.mods.kubejs.block.custom; import com.mojang.serialization.MapCodec; -import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.latvian.mods.kubejs.block.BlockBuilder; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; +import dev.latvian.mods.kubejs.color.SimpleColor; import dev.latvian.mods.rhino.util.ReturnsSelf; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.ColorRGBA; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.FallingBlock; @@ -15,7 +14,7 @@ @ReturnsSelf public class FallingBlockBuilder extends BlockBuilder { - private int dustColor = 0xff807c7b; + private KubeColor dustColor = new SimpleColor(0x807C7B); public FallingBlockBuilder(ResourceLocation i) { super(i); @@ -23,37 +22,29 @@ public FallingBlockBuilder(ResourceLocation i) { @Override public Block createObject() { - var dustRgb = dustColor & 0xffffff; - var dustAlpha = (dustColor >> 24) & 0xff; - var dustColor = new ColorRGBA(dustRgb | (dustAlpha << 24)); - return new KubeJSFallingBlock(dustColor, createProperties()); + return new KubeJSFallingBlock(createProperties()); } - public FallingBlockBuilder dustColor(Color color) { - dustColor = color.getArgbJS(); // TODO: Add Color -> ColorRGBA conversion + public FallingBlockBuilder dustColor(KubeColor color) { + dustColor = color; return this; } static class KubeJSFallingBlock extends FallingBlock { - private final ColorRGBA dustColor; + private static final MapCodec CODEC = simpleCodec(KubeJSFallingBlock::new); - private static final MapCodec CODEC = RecordCodecBuilder.mapCodec( - (instance) -> instance.group(ColorRGBA.CODEC.fieldOf("falling_dust_color").forGetter(block -> block.dustColor), - propertiesCodec()).apply(instance, KubeJSFallingBlock::new)); - - public KubeJSFallingBlock(ColorRGBA dustColor, Properties p) { + public KubeJSFallingBlock(Properties p) { super(p); - this.dustColor = dustColor; } @Override - public int getDustColor(BlockState state, BlockGetter level, BlockPos pos) { - return dustColor.rgba(); + protected MapCodec codec() { + return CODEC; } @Override - protected MapCodec codec() { - return CODEC; + public int getDustColor(BlockState state, BlockGetter level, BlockPos pos) { + return ((FallingBlockBuilder) kjs$getBlockBuilder()).dustColor.kjs$getARGB(); } } } 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 a18e2470a..6d1e7e2dc 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 @@ -27,8 +27,8 @@ public Block createObject() { @Override protected void generateMultipartBlockStateJson(MultipartBlockStateGenerator bs) { - var modPost = newID("block/", "_post").toString(); - var modSide = newID("block/", "_side").toString(); + var modPost = newID("block/", "_post"); + var modSide = newID("block/", "_side"); bs.part("", modPost); bs.part("north=true", p -> p.model(modSide).uvlock()); @@ -40,12 +40,12 @@ protected void generateMultipartBlockStateJson(MultipartBlockStateGenerator bs) @Override protected void generateItemModelJson(ModelGenerator m) { m.parent("minecraft:block/fence_inventory"); - m.texture("texture", textures.get("texture").getAsString()); + m.texture("texture", textures.get("texture")); } @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(newID("", "_post"), m -> { m.parent("minecraft:block/fence_post"); 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 7a2646ee2..41aa91177 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 @@ -51,10 +51,10 @@ public Block createObject() { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - var mod = newID("block/", "").toString(); - var modOpen = newID("block/", "_open").toString(); - var modWall = newID("block/", "_wall").toString(); - var modWallOpen = newID("block/", "_wall_open").toString(); + var mod = newID("block/", ""); + var modOpen = newID("block/", "_open"); + var modWall = newID("block/", "_wall"); + var modWallOpen = newID("block/", "_wall_open"); bs.variant("facing=east,in_wall=false,open=false", v -> v.model(mod).y(270).uvlock()); bs.variant("facing=east,in_wall=false,open=true", v -> v.model(modOpen).y(270).uvlock()); @@ -76,7 +76,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) { @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(id, m -> { m.parent("minecraft:block/template_fence_gate"); @@ -102,6 +102,6 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { @Override protected void generateItemModelJson(ModelGenerator m) { m.parent("minecraft:block/template_fence_gate"); - m.texture("texture", textures.get("texture").getAsString()); + m.texture("texture", textures.get("texture")); } } \ 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 4f3ef2af4..1ea8ae7d7 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 @@ -4,6 +4,7 @@ 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.core.BlockPos; import net.minecraft.core.Direction; @@ -44,7 +45,7 @@ public HorizontalDirectionalBlockBuilder(ResourceLocation i) { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - var modelLocation = model.isEmpty() ? newID("block/", "").toString() : model; + var modelLocation = model == null ? id.withPath(ID.BLOCK) : model; bs.variant("facing=north", v -> v.model(modelLocation)); bs.variant("facing=east", v -> v.model(modelLocation).y(90)); bs.variant("facing=south", v -> v.model(modelLocation).y(180)); @@ -54,16 +55,16 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) { @Override protected void generateBlockModelJsons(KubeAssetGenerator gen) { gen.blockModel(id, mg -> { - var side = getTextureOrDefault("side", newID("block/", "").toString()); + var side = getTextureOrDefault("side", id.withPath(ID.BLOCK).toString()); mg.texture("side", side); mg.texture("front", getTextureOrDefault("front", newID("block/", "_front").toString())); mg.texture("particle", getTextureOrDefault("particle", side)); mg.texture("top", getTextureOrDefault("top", side)); - if (textures.has("bottom")) { + if (textures.containsKey("bottom")) { mg.parent("block/orientable_with_bottom"); - mg.texture("bottom", textures.get("bottom").getAsString()); + mg.texture("bottom", textures.get("bottom")); } else { mg.parent("minecraft:block/orientable"); } @@ -72,7 +73,7 @@ protected void generateBlockModelJsons(KubeAssetGenerator gen) { @Override protected void generateItemModelJson(ModelGenerator m) { - m.parent(model.isEmpty() ? newID("block/", "").toString() : model); + m.parent(model == null ? newID("block/", "") : model); } @Override @@ -83,7 +84,7 @@ public HorizontalDirectionalBlockBuilder textureAll(String tex) { } private String getTextureOrDefault(String name, String defaultTexture) { - return textures.has(name) ? textures.get(name).getAsString() : defaultTexture; + return textures.getOrDefault(name, defaultTexture); } @Override @@ -152,13 +153,13 @@ public WithEntity(BlockBuilder p) { @Nullable @Override - public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return blockBuilder.blockEntityInfo.createBlockEntity(blockPos, blockState); + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return blockBuilder.blockEntityInfo.createBlockEntity(pos, state); } @Nullable @Override - public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { + public BlockEntityTicker getTicker(Level level, BlockState state, BlockEntityType blockEntityType) { return blockBuilder.blockEntityInfo.getTicker(level); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/MultipartShapedBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/MultipartShapedBlockBuilder.java index 9ebce310d..9d09f3dea 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/MultipartShapedBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/MultipartShapedBlockBuilder.java @@ -2,6 +2,7 @@ import dev.latvian.mods.kubejs.client.MultipartBlockStateGenerator; import dev.latvian.mods.kubejs.generator.KubeAssetGenerator; +import dev.latvian.mods.kubejs.util.ID; import net.minecraft.resources.ResourceLocation; public abstract class MultipartShapedBlockBuilder extends ShapedBlockBuilder { @@ -12,20 +13,20 @@ public MultipartShapedBlockBuilder(ResourceLocation i, String... suffixes) { @Override public void generateAssets(KubeAssetGenerator generator) { if (blockstateJson != null) { - generator.json(newID("blockstates/", ""), blockstateJson); + generator.json(id.withPath(ID.BLOCKSTATE), blockstateJson); } else { generator.multipartState(id, this::generateMultipartBlockStateJson); } if (modelJson != null) { - generator.json(newID("models/", ""), modelJson); + generator.json(id.withPath(ID.MODEL), modelJson); } else { generateBlockModelJsons(generator); } if (itemBuilder != null) { if (itemBuilder.modelJson != null) { - generator.json(newID("models/item/", ""), itemBuilder.modelJson); + generator.json(id.withPath(ID.ITEM_MODEL), itemBuilder.modelJson); } else { generator.itemModel(itemBuilder.id, this::generateItemModelJson); } 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 d3f9b1b85..df5b12ce3 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 @@ -50,13 +50,13 @@ public Block createObject() { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - bs.variant("powered=true", v -> v.model(newID("block/", "_down").toString())); - bs.variant("powered=false", v -> v.model(newID("block/", "_up").toString())); + bs.variant("powered=true", v -> v.model(newID("block/", "_down"))); + bs.variant("powered=false", v -> v.model(newID("block/", "_up"))); } @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(newID("", "_down"), m -> { m.parent("minecraft:block/pressure_plate_down"); @@ -71,6 +71,6 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { @Override protected void generateItemModelJson(ModelGenerator m) { - m.parent(newID("block/", "_up").toString()); + m.parent(newID("block/", "_up")); } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/ShapedBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/ShapedBlockBuilder.java index 421230e50..943273bd5 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/ShapedBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/ShapedBlockBuilder.java @@ -11,9 +11,9 @@ public ShapedBlockBuilder(ResourceLocation i, String... suffixes) { property(BlockStateProperties.WATERLOGGED); texture("texture", "kubejs:block/detector"); - for (String s : suffixes) { + for (var s : suffixes) { if (id.getPath().endsWith(s)) { - texture("texture", id.getNamespace() + ":block/" + id.getPath().substring(0, id.getPath().length() - s.length())); + texture("texture", id.withPath("block/" + id.getPath().substring(0, id.getPath().length() - s.length())).toString()); break; } } 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 c1971ead3..a52404d0c 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 @@ -25,14 +25,14 @@ public Block createObject() { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - bs.variant("type=double", v -> v.model(newID("block/", "_double").toString())); - bs.variant("type=bottom", v -> v.model(newID("block/", "_bottom").toString())); - bs.variant("type=top", v -> v.model(newID("block/", "_top").toString())); + bs.variant("type=double", v -> v.model(newID("block/", "_double"))); + bs.variant("type=bottom", v -> v.model(newID("block/", "_bottom"))); + bs.variant("type=top", v -> v.model(newID("block/", "_top"))); } @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - final var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(newID("", "_double"), m -> { m.parent("minecraft:block/cube_all"); @@ -56,6 +56,6 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { @Override protected void generateItemModelJson(ModelGenerator m) { - m.parent(newID("block/", "_bottom").toString()); + m.parent(newID("block/", "_bottom")); } } 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 d258fc303..5dfc1d765 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 @@ -25,9 +25,9 @@ public Block createObject() { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - var mod = newID("block/", "").toString(); - var modInner = newID("block/", "_inner").toString(); - var modOuter = newID("block/", "_outer").toString(); + var mod = newID("block/", ""); + var modInner = newID("block/", "_inner"); + var modOuter = newID("block/", "_outer"); bs.variant("facing=east,half=bottom,shape=inner_left", v -> v.model(modInner).y(270).uvlock()); bs.variant("facing=east,half=bottom,shape=inner_right", v -> v.model(modInner)); @@ -73,7 +73,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) { @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(id, m -> { m.parent("minecraft:block/stairs"); 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 04f77a605..63b6b62aa 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 @@ -46,9 +46,9 @@ public Block createObject() { @Override protected void generateBlockStateJson(VariantBlockStateGenerator bs) { - var modelOpen = newID("block/", "_open").toString(); - var modelBottom = newID("block/", "_bottom").toString(); - var modelTop = newID("block/", "_top").toString(); + var modelOpen = newID("block/", "_open"); + var modelBottom = newID("block/", "_bottom"); + var modelTop = newID("block/", "_top"); var halfValues = Half.values(); var openValues = List.of(Boolean.TRUE, Boolean.FALSE); @@ -76,7 +76,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) { @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(newID("", "_bottom"), m -> { m.parent("minecraft:block/template_trapdoor_bottom"); @@ -96,6 +96,6 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { @Override protected void generateItemModelJson(ModelGenerator m) { - m.parent(newID("block/", "_bottom").toString()); + m.parent(newID("block/", "_bottom")); } } \ No newline at end of file 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 15f430536..bf8487814 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 @@ -25,9 +25,9 @@ public Block createObject() { @Override protected void generateMultipartBlockStateJson(MultipartBlockStateGenerator bs) { - var modPost = newID("block/", "_post").toString(); - var modSide = newID("block/", "_side").toString(); - var modSideTall = newID("block/", "_side_tall").toString(); + var modPost = newID("block/", "_post"); + var modSide = newID("block/", "_side"); + var modSideTall = newID("block/", "_side_tall"); bs.part("up=true", modPost); bs.part("north=low", p -> p.model(modSide).uvlock()); @@ -43,12 +43,12 @@ protected void generateMultipartBlockStateJson(MultipartBlockStateGenerator bs) @Override protected void generateItemModelJson(ModelGenerator m) { m.parent("minecraft:block/wall_inventory"); - m.texture("wall", textures.get("texture").getAsString()); + m.texture("wall", textures.get("texture")); } @Override protected void generateBlockModelJsons(KubeAssetGenerator generator) { - var texture = textures.get("texture").getAsString(); + var texture = textures.get("texture"); generator.blockModel(newID("", "_post"), m -> { m.parent("minecraft:block/template_wall_post"); diff --git a/src/main/java/dev/latvian/mods/kubejs/client/BlockTintFunctionWrapper.java b/src/main/java/dev/latvian/mods/kubejs/client/BlockTintFunctionWrapper.java index 153a0ce02..161bdfb57 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/BlockTintFunctionWrapper.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/BlockTintFunctionWrapper.java @@ -11,6 +11,6 @@ public record BlockTintFunctionWrapper(BlockTintFunction function) implements Bl @Override public int getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int index) { var c = function.getColor(state, level, pos, index); - return c == null ? 0xFFFFFFFF : c.getArgbJS(); + return c == null ? 0xFFFFFFFF : c.kjs$getARGB(); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/ItemTintFunctionWrapper.java b/src/main/java/dev/latvian/mods/kubejs/client/ItemTintFunctionWrapper.java index 744345576..83fd956d0 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/ItemTintFunctionWrapper.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/ItemTintFunctionWrapper.java @@ -8,6 +8,6 @@ public record ItemTintFunctionWrapper(ItemTintFunction function) implements Item @Override public int getColor(ItemStack stack, int index) { var c = function.getColor(stack, index); - return c == null ? 0xFFFFFFFF : c.getArgbJS(); + return c == null ? 0xFFFFFFFF : c.kjs$getARGB(); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/KubeAnimatedParticle.java b/src/main/java/dev/latvian/mods/kubejs/client/KubeAnimatedParticle.java index 78876c2ad..6a169f1bc 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/KubeAnimatedParticle.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/KubeAnimatedParticle.java @@ -1,6 +1,6 @@ package dev.latvian.mods.kubejs.client; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.typings.Info; import it.unimi.dsi.fastutil.floats.Float2IntFunction; import net.minecraft.client.multiplayer.ClientLevel; @@ -34,14 +34,14 @@ public void setFriction(float f) { friction = f; } - public void setColor(Color color, boolean alpha) { - setColor(color.getRgbJS()); + public void setColor(KubeColor color, boolean alpha) { + setColor(color.kjs$getRGB()); if (alpha) { - setAlpha((color.getArgbJS() >>> 24) / 255F); + setAlpha((color.kjs$getARGB() >>> 24) / 255F); } } - public void setColor(Color color) { + public void setColor(KubeColor color) { setColor(color, false); } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/LoadedTexture.java b/src/main/java/dev/latvian/mods/kubejs/client/LoadedTexture.java index b03c46f92..bc8004784 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/LoadedTexture.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/LoadedTexture.java @@ -2,7 +2,7 @@ import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.KubeJSPaths; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -90,7 +90,7 @@ public LoadedTexture copy() { return new LoadedTexture(width, height, pixels.clone(), mcmeta); } - public LoadedTexture remap(Map remap) { + public LoadedTexture remap(Map remap) { if (remap.isEmpty()) { return this; } @@ -100,7 +100,7 @@ public LoadedTexture remap(Map remap) { for (var entry : remap.entrySet()) { var k = entry.getKey(); var v = entry.getValue(); - colorMap.put(k.getArgbJS(), v.getArgbJS()); + colorMap.put(k.kjs$getARGB(), v.kjs$getARGB()); } int[] result = new int[pixels.length]; @@ -131,12 +131,12 @@ public LoadedTexture resize(int newWidth, int newHeight) { return new LoadedTexture(dst, mcmeta); } - public LoadedTexture tint(@Nullable Color tint) { + public LoadedTexture tint(@Nullable KubeColor tint) { if (tint == null) { return this; } - int argb = tint.getArgbJS(); + int argb = tint.kjs$getARGB(); float l = ((argb >> 24) & 0xFF) / 255F; if (l <= 0F) { 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 9676c6630..cdf44d74c 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java @@ -2,18 +2,21 @@ 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 net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.AABB; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.function.Consumer; public class ModelGenerator { public static class Element { - private AABB box = new AABB(0D, 0D, 0D, 1D, 1D, 1D); + private AABB box = AABBWrapper.CUBE; private final JsonObject faces = new JsonObject(); public Element box(AABB b) { @@ -103,19 +106,27 @@ public Face tintindex(int i) { } } - private String parent = "minecraft:block/cube"; - private final JsonObject textures = new JsonObject(); + private static final ResourceLocation CUBE = ResourceLocation.withDefaultNamespace("block/cube"); + + private ResourceLocation parent = CUBE; + private final Map textures = new HashMap<>(1); private final List elements = new ArrayList<>(); public JsonObject toJson() { var json = new JsonObject(); - if (!parent.isEmpty()) { - json.addProperty("parent", parent); + if (parent != null) { + json.addProperty("parent", parent.toString()); } - if (textures.size() > 0) { - json.add("textures", textures); + if (!textures.isEmpty()) { + var o = new JsonObject(); + + for (var entry : textures.entrySet()) { + o.addProperty(entry.getKey(), entry.getValue()); + } + + json.add("textures", o); } if (!elements.isEmpty()) { @@ -131,23 +142,21 @@ public JsonObject toJson() { return json; } - public void parent(String s) { + public void parent(ResourceLocation s) { parent = s; } @HideFromJS - public void texture(String name, String texture) { - textures.addProperty(name, texture); + public void parent(String s) { + parent = ResourceLocation.parse(s); } - public void texture(String name, ResourceLocation texture) { - textures.addProperty(name, texture.toString()); + public void texture(String name, String texture) { + textures.put(name, texture); } - public void textures(JsonObject json) { - for (var entry : json.entrySet()) { - textures.add(entry.getKey(), entry.getValue()); - } + public void textures(Map map) { + textures.putAll(map); } public void element(Consumer consumer) { diff --git a/src/main/java/dev/latvian/mods/kubejs/client/MultipartBlockStateGenerator.java b/src/main/java/dev/latvian/mods/kubejs/client/MultipartBlockStateGenerator.java index df3644095..360e1054d 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/MultipartBlockStateGenerator.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/MultipartBlockStateGenerator.java @@ -2,6 +2,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import net.minecraft.resources.ResourceLocation; import java.util.ArrayList; import java.util.List; @@ -12,7 +13,7 @@ public static class Part { private String when; private final List apply = new ArrayList<>(); - public VariantBlockStateGenerator.Model model(String s) { + public VariantBlockStateGenerator.Model model(ResourceLocation s) { var model = new VariantBlockStateGenerator.Model(); model.model(s); apply.add(model); @@ -61,7 +62,7 @@ public void part(String when, Consumer consumer) { multipart.add(v.toJson()); } - public void part(String when, String model) { + public void part(String when, ResourceLocation model) { part(when, v -> v.model(model)); } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/NotificationToast.java b/src/main/java/dev/latvian/mods/kubejs/client/NotificationToast.java index dc3be0f4e..f752b36df 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/NotificationToast.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/NotificationToast.java @@ -102,17 +102,17 @@ public Toast.Visibility render(GuiGraphics graphics, ToastComponent toastCompone int w = width(); int h = height(); - int oc = notification.outlineColor().getRgbJS(); + int oc = notification.outlineColor().kjs$getRGB(); int ocr = FastColor.ARGB32.red(oc); int ocg = FastColor.ARGB32.green(oc); int ocb = FastColor.ARGB32.blue(oc); - int bc = notification.borderColor().getRgbJS(); + int bc = notification.borderColor().kjs$getRGB(); int bcr = FastColor.ARGB32.red(bc); int bcg = FastColor.ARGB32.green(bc); int bcb = FastColor.ARGB32.blue(bc); - int bgc = notification.backgroundColor().getRgbJS(); + int bgc = notification.backgroundColor().kjs$getRGB(); int bgcr = FastColor.ARGB32.red(bgc); int bgcg = FastColor.ARGB32.green(bgc); int bgcb = FastColor.ARGB32.blue(bgc); diff --git a/src/main/java/dev/latvian/mods/kubejs/client/VariantBlockStateGenerator.java b/src/main/java/dev/latvian/mods/kubejs/client/VariantBlockStateGenerator.java index b1389ecb8..b4d17a50f 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/VariantBlockStateGenerator.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/VariantBlockStateGenerator.java @@ -3,7 +3,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import dev.latvian.mods.kubejs.util.ID; import dev.latvian.mods.rhino.util.HideFromJS; +import net.minecraft.resources.ResourceLocation; import java.util.ArrayList; import java.util.List; @@ -14,7 +16,7 @@ public static class Variant { private String key; private final List models = new ArrayList<>(); - public Model model(String s) { + public Model model(ResourceLocation s) { var model = new Model(); model.model(s); models.add(model); @@ -37,12 +39,12 @@ public JsonElement toJson() { } public static class Model { - private String model = "broken"; + private ResourceLocation model = ID.UNKNOWN; private int x = 0; private int y = 0; private boolean uvlock = false; - public Model model(String s) { + public Model model(ResourceLocation s) { model = s; return this; } @@ -64,7 +66,7 @@ public Model uvlock() { public JsonObject toJson() { var json = new JsonObject(); - json.addProperty("model", model); + json.addProperty("model", model.toString()); if (x != 0) { json.addProperty("x", x); @@ -93,11 +95,11 @@ public void variant(String key, Consumer consumer) { @HideFromJS @Deprecated - public void variant(String key, String model) { + public void variant(String key, ResourceLocation model) { simpleVariant(key, model); } - public void simpleVariant(String key, String model) { + public void simpleVariant(String key, ResourceLocation model) { variant(key, v -> v.model(model)); } diff --git a/src/main/java/dev/latvian/mods/kubejs/color/Color.java b/src/main/java/dev/latvian/mods/kubejs/color/Color.java deleted file mode 100644 index 8040d394f..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/color/Color.java +++ /dev/null @@ -1,44 +0,0 @@ -package dev.latvian.mods.kubejs.color; - -import com.mojang.serialization.Codec; -import dev.latvian.mods.kubejs.KubeJSCodecs; -import dev.latvian.mods.kubejs.bindings.ColorWrapper; -import dev.latvian.mods.rhino.Context; -import dev.latvian.mods.rhino.util.SpecialEquality; -import io.netty.buffer.ByteBuf; -import net.minecraft.network.chat.TextColor; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; - -public interface Color extends SpecialEquality { - Codec CODEC = KubeJSCodecs.stringResolverCodec(Color::toString, ColorWrapper::of); - StreamCodec STREAM_CODEC = ByteBufCodecs.fromCodec(CODEC); - - int getArgbJS(); - - default int getRgbJS() { - return getArgbJS() & 0xFFFFFF; - } - - default int getFireworkColorJS() { - return getRgbJS(); - } - - default String getHexJS() { - return String.format("#%08X", getArgbJS()); - } - - default String getSerializeJS() { - return getHexJS(); - } - - default TextColor createTextColorJS() { - return TextColor.fromRgb(getRgbJS()); - } - - @Override - default boolean specialEquals(Context cx, Object o, boolean shallow) { - Color c = ColorWrapper.of(o); - return shallow ? (getArgbJS() == c.getArgbJS()) : (getRgbJS() == c.getRgbJS()); - } -} \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/color/KubeColor.java b/src/main/java/dev/latvian/mods/kubejs/color/KubeColor.java new file mode 100644 index 000000000..7df2a14e7 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/color/KubeColor.java @@ -0,0 +1,49 @@ +package dev.latvian.mods.kubejs.color; + +import com.mojang.serialization.Codec; +import dev.latvian.mods.kubejs.KubeJSCodecs; +import dev.latvian.mods.kubejs.bindings.ColorWrapper; +import dev.latvian.mods.rhino.Context; +import dev.latvian.mods.rhino.util.RemapForJS; +import dev.latvian.mods.rhino.util.RemapPrefixForJS; +import dev.latvian.mods.rhino.util.SpecialEquality; +import io.netty.buffer.ByteBuf; +import net.minecraft.network.chat.TextColor; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; + +@RemapPrefixForJS("kjs$") +public interface KubeColor extends SpecialEquality { + Codec CODEC = KubeJSCodecs.stringResolverCodec(KubeColor::kjs$serialize, ColorWrapper::of); + StreamCodec STREAM_CODEC = ByteBufCodecs.fromCodec(CODEC); + + @RemapForJS("getArgb") + int kjs$getARGB(); + + @RemapForJS("getRgb") + default int kjs$getRGB() { + return kjs$getARGB() & 0xFFFFFF; + } + + default int kjs$getFireworkRGB() { + return kjs$getRGB(); + } + + default String kjs$toHexString() { + return String.format("#%08X", kjs$getARGB()); + } + + default String kjs$serialize() { + return kjs$toHexString(); + } + + default TextColor kjs$createTextColor() { + return TextColor.fromRgb(kjs$getRGB()); + } + + @Override + default boolean specialEquals(Context cx, Object o, boolean shallow) { + KubeColor c = ColorWrapper.of(o); + return shallow ? (kjs$getARGB() == c.kjs$getARGB()) : (kjs$getRGB() == c.kjs$getRGB()); + } +} \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/color/NoColor.java b/src/main/java/dev/latvian/mods/kubejs/color/NoColor.java index 4f858233a..ba39d1482 100644 --- a/src/main/java/dev/latvian/mods/kubejs/color/NoColor.java +++ b/src/main/java/dev/latvian/mods/kubejs/color/NoColor.java @@ -2,31 +2,31 @@ import net.minecraft.network.chat.TextColor; -public final class NoColor implements Color { +public final class NoColor implements KubeColor { private static final TextColor TEXT_COLOR = TextColor.fromRgb(0); @Override - public int getArgbJS() { + public int kjs$getARGB() { return 0; } @Override - public int getRgbJS() { + public int kjs$getRGB() { return 0; } @Override - public String getHexJS() { + public String kjs$toHexString() { return "#00000000"; } @Override - public String getSerializeJS() { + public String kjs$serialize() { return "none"; } @Override - public TextColor createTextColorJS() { + public TextColor kjs$createTextColor() { return TEXT_COLOR; } } diff --git a/src/main/java/dev/latvian/mods/kubejs/color/SimpleColor.java b/src/main/java/dev/latvian/mods/kubejs/color/SimpleColor.java index bd578bfdc..bc29ae68e 100644 --- a/src/main/java/dev/latvian/mods/kubejs/color/SimpleColor.java +++ b/src/main/java/dev/latvian/mods/kubejs/color/SimpleColor.java @@ -2,7 +2,7 @@ import net.minecraft.network.chat.TextColor; -public class SimpleColor implements Color { +public class SimpleColor implements KubeColor { public static final SimpleColor BLACK = new SimpleColor(0xFF000000); public static final SimpleColor WHITE = new SimpleColor(0xFFFFFFFF); @@ -14,24 +14,24 @@ public SimpleColor(int v) { } @Override - public int getArgbJS() { + public int kjs$getARGB() { return value; } @Override - public String getHexJS() { - return String.format("#%06X", getRgbJS()); + public String kjs$toHexString() { + return String.format("#%06X", kjs$getRGB()); } @Override public String toString() { - return getHexJS(); + return kjs$toHexString(); } @Override - public TextColor createTextColorJS() { + public TextColor kjs$createTextColor() { if (textColor == null) { - textColor = TextColor.fromRgb(getRgbJS()); + textColor = TextColor.fromRgb(kjs$getRGB()); } return textColor; diff --git a/src/main/java/dev/latvian/mods/kubejs/color/SimpleColorWithAlpha.java b/src/main/java/dev/latvian/mods/kubejs/color/SimpleColorWithAlpha.java index 728b187d6..08c679f27 100644 --- a/src/main/java/dev/latvian/mods/kubejs/color/SimpleColorWithAlpha.java +++ b/src/main/java/dev/latvian/mods/kubejs/color/SimpleColorWithAlpha.java @@ -2,7 +2,7 @@ import net.minecraft.network.chat.TextColor; -public class SimpleColorWithAlpha implements Color { +public class SimpleColorWithAlpha implements KubeColor { private final int value; private TextColor textColor; @@ -11,14 +11,14 @@ public SimpleColorWithAlpha(int v) { } @Override - public int getArgbJS() { + public int kjs$getARGB() { return value; } @Override - public TextColor createTextColorJS() { + public TextColor kjs$createTextColor() { if (textColor == null) { - textColor = TextColor.fromRgb(getRgbJS()); + textColor = TextColor.fromRgb(kjs$getRGB()); } return textColor; @@ -26,6 +26,6 @@ public TextColor createTextColorJS() { @Override public String toString() { - return getHexJS(); + return kjs$toHexString(); } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/component/ComponentFunctions.java b/src/main/java/dev/latvian/mods/kubejs/component/ComponentFunctions.java index 9a1edda41..8212d44f4 100644 --- a/src/main/java/dev/latvian/mods/kubejs/component/ComponentFunctions.java +++ b/src/main/java/dev/latvian/mods/kubejs/component/ComponentFunctions.java @@ -2,7 +2,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.PropertyMap; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.util.Cast; import dev.latvian.mods.kubejs.util.RegistryAccessContainer; import dev.latvian.mods.rhino.Context; @@ -165,12 +165,12 @@ public interface ComponentFunctions { kjs$override(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, override); } - default void kjs$setDyedColor(Color color) { - kjs$override(DataComponents.DYED_COLOR, new DyedItemColor(color.getRgbJS(), false)); + default void kjs$setDyedColor(KubeColor color) { + kjs$override(DataComponents.DYED_COLOR, new DyedItemColor(color.kjs$getRGB(), false)); } - default void kjs$setDyedColorWithTooltip(Color color) { - kjs$override(DataComponents.DYED_COLOR, new DyedItemColor(color.getRgbJS(), true)); + default void kjs$setDyedColorWithTooltip(KubeColor color) { + kjs$override(DataComponents.DYED_COLOR, new DyedItemColor(color.kjs$getRGB(), true)); } default void kjs$setPotionContents(PotionContents contents) { diff --git a/src/main/java/dev/latvian/mods/kubejs/component/ItemComponentFunctions.java b/src/main/java/dev/latvian/mods/kubejs/component/ItemComponentFunctions.java index a3794fa6f..fb532280e 100644 --- a/src/main/java/dev/latvian/mods/kubejs/component/ItemComponentFunctions.java +++ b/src/main/java/dev/latvian/mods/kubejs/component/ItemComponentFunctions.java @@ -1,6 +1,6 @@ package dev.latvian.mods.kubejs.component; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.rhino.util.RemapPrefixForJS; import net.minecraft.core.Holder; import net.minecraft.core.component.DataComponents; @@ -67,8 +67,8 @@ public interface ItemComponentFunctions extends ComponentFunctions { kjs$override(DataComponents.TOOL, tool); } - default void kjs$setMapItemColor(Color color) { - kjs$override(DataComponents.MAP_COLOR, new MapItemColor(color.getRgbJS())); + default void kjs$setMapItemColor(KubeColor color) { + kjs$override(DataComponents.MAP_COLOR, new MapItemColor(color.kjs$getRGB())); } default void kjs$setChargedProjectiles(List items) { diff --git a/src/main/java/dev/latvian/mods/kubejs/core/ComponentKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/ComponentKJS.java index 583c27401..6753a47ca 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/ComponentKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/ComponentKJS.java @@ -4,7 +4,7 @@ import com.mojang.serialization.Codec; import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.bindings.TextWrapper; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.util.WithCodec; import dev.latvian.mods.kubejs.util.WrappedJS; import dev.latvian.mods.rhino.Context; @@ -144,8 +144,8 @@ default void forEach(Consumer action) { // endregion ChatFormatting extensions // region Style extensions - default MutableComponent kjs$color(@Nullable Color c) { - var col = c == null ? null : c.createTextColorJS(); + default MutableComponent kjs$color(@Nullable KubeColor c) { + var col = c == null ? null : c.kjs$createTextColor(); return kjs$self().setStyle(getStyle().withColor(col)); } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/ChatFormattingMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/ChatFormattingMixin.java index 960894eaa..ddd71654e 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/ChatFormattingMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/ChatFormattingMixin.java @@ -1,24 +1,24 @@ package dev.latvian.mods.kubejs.core.mixin; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import net.minecraft.ChatFormatting; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @Mixin(ChatFormatting.class) -public abstract class ChatFormattingMixin implements Color { +public abstract class ChatFormattingMixin implements KubeColor { @Shadow @Final private Integer color; @Override - public int getArgbJS() { + public int kjs$getARGB() { return color == null ? 0xFF000000 : (0xFF000000 | color); } @Override - public int getRgbJS() { + public int kjs$getRGB() { return color == null ? 0 : color; } } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/DyeColorMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/DyeColorMixin.java index c331eb6b9..e35e4e7ed 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/DyeColorMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/DyeColorMixin.java @@ -1,13 +1,13 @@ package dev.latvian.mods.kubejs.core.mixin; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import net.minecraft.world.item.DyeColor; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @Mixin(DyeColor.class) -public abstract class DyeColorMixin implements Color { +public abstract class DyeColorMixin implements KubeColor { @Shadow @Final private int textColor; @@ -17,17 +17,17 @@ public abstract class DyeColorMixin implements Color { private int fireworkColor; @Override - public int getArgbJS() { + public int kjs$getARGB() { return 0xFF000000 | textColor; } @Override - public int getRgbJS() { + public int kjs$getRGB() { return textColor; } @Override - public int getFireworkColorJS() { + public int kjs$getFireworkRGB() { return fireworkColor; } } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/ItemMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/ItemMixin.java index 8a58f9353..31e5dc1e9 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/ItemMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/ItemMixin.java @@ -153,7 +153,7 @@ private void getBarWidth(ItemStack stack, CallbackInfoReturnable ci) { @Inject(method = "getBarColor", at = @At("HEAD"), cancellable = true) private void getBarColor(ItemStack stack, CallbackInfoReturnable ci) { if (kjs$itemBuilder != null && kjs$itemBuilder.barColor != null) { - ci.setReturnValue(kjs$itemBuilder.barColor.apply(stack).getRgbJS()); + ci.setReturnValue(kjs$itemBuilder.barColor.apply(stack).kjs$getRGB()); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/TextColorMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/TextColorMixin.java index 1e8e707f7..7e4be7079 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/TextColorMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/TextColorMixin.java @@ -1,32 +1,29 @@ package dev.latvian.mods.kubejs.core.mixin; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import net.minecraft.network.chat.TextColor; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(TextColor.class) -public abstract class TextColorMixin implements Color { +public abstract class TextColorMixin implements KubeColor { @Shadow @Final private int value; @Override - public int getArgbJS() { + public int kjs$getARGB() { return 0xFF000000 | value; } @Override - public int getRgbJS() { + public int kjs$getRGB() { return value; } @Override - public String getSerializeJS() { - return serialize(); - } - - @Shadow - public abstract String serialize(); + @Invoker("serialize") + public abstract String kjs$serialize(); } 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 349ee4907..86fd1e84c 100644 --- a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java @@ -2,11 +2,12 @@ import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.block.BlockRenderType; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.color.SimpleColor; 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; @@ -20,7 +21,7 @@ @ReturnsSelf public class FluidBuilder extends BuilderBase { - public static final Color WATER_COLOR = new SimpleColor(0xFF3F76E4); + public static final KubeColor WATER_COLOR = new SimpleColor(0xFF3F76E4); public transient int slopeFindDistance = 4; public transient int levelDecreasePerBlock = 1; @@ -98,7 +99,7 @@ public FluidBuilder type(Consumer builder) { return this; } - public FluidBuilder tint(Color c) { + public FluidBuilder tint(KubeColor c) { fluidType.tint = c; return this; } @@ -166,7 +167,7 @@ public void generateAssets(KubeAssetGenerator generator) { generator.texture(fluidType.actualFlowingTexture, flowingTexture.tint(fluidType.tint)); } - generator.blockState(id, m -> m.simpleVariant("", id.getNamespace() + ":block/" + id.getPath())); + generator.blockState(id, m -> m.simpleVariant("", id.withPath("block/" + id.getPath()))); generator.blockModel(id, m -> { m.parent(""); m.texture("particle", fluidType.actualStillTexture.toString()); @@ -174,7 +175,7 @@ public void generateAssets(KubeAssetGenerator generator) { if (bucketItem != null) { if (bucketItem.modelJson != null) { - generator.json(KubeAssetGenerator.asItemModelLocation(id), bucketItem.modelJson); + generator.json(id.withPath(ID.ITEM_MODEL), bucketItem.modelJson); return; } @@ -183,16 +184,16 @@ public void generateAssets(KubeAssetGenerator generator) { generator.mask(fluidPath, KubeJS.id("item/bucket_mask"), fluidType.actualStillTexture); generator.itemModel(bucketItem.id, m -> { - if (!bucketItem.parentModel.isEmpty()) { + if (bucketItem.parentModel != null) { m.parent(bucketItem.parentModel); } else { m.parent("kubejs:item/generated_bucket"); } - m.texture("bucket_fluid", fluidPath); + m.texture("bucket_fluid", fluidPath.toString()); - if (bucketItem.textureJson.size() > 0) { - m.textures(bucketItem.textureJson); + if (!bucketItem.textures.isEmpty()) { + m.textures(bucketItem.textures); } }); } diff --git a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidTypeBuilder.java b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidTypeBuilder.java index aacc00195..66959bf8f 100644 --- a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidTypeBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidTypeBuilder.java @@ -1,7 +1,7 @@ package dev.latvian.mods.kubejs.fluid; import dev.latvian.mods.kubejs.block.BlockRenderType; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.registry.BuilderBase; import dev.latvian.mods.rhino.util.ReturnsSelf; import net.minecraft.core.particles.ParticleOptions; @@ -34,7 +34,7 @@ public KubeFluidType(FluidTypeBuilder builder) { public transient ResourceLocation actualFlowingTexture; public transient ResourceLocation screenOverlayTexture; public transient ResourceLocation blockOverlayTexture; - public transient Color tint; + public transient KubeColor tint; public transient BlockRenderType renderType; public FluidTypeBuilder(ResourceLocation id) { @@ -77,7 +77,7 @@ public FluidTypeBuilder blockOverlayTexture(ResourceLocation blockOverlayTexture return this; } - public FluidTypeBuilder tint(Color tint) { + public FluidTypeBuilder tint(KubeColor tint) { this.tint = tint; return this; } diff --git a/src/main/java/dev/latvian/mods/kubejs/generator/KubeAssetGenerator.java b/src/main/java/dev/latvian/mods/kubejs/generator/KubeAssetGenerator.java index eacddc8d6..59794e74b 100644 --- a/src/main/java/dev/latvian/mods/kubejs/generator/KubeAssetGenerator.java +++ b/src/main/java/dev/latvian/mods/kubejs/generator/KubeAssetGenerator.java @@ -6,10 +6,11 @@ import dev.latvian.mods.kubejs.client.ParticleGenerator; import dev.latvian.mods.kubejs.client.SoundsGenerator; import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.event.EventResult; import dev.latvian.mods.kubejs.script.ConsoleJS; import dev.latvian.mods.kubejs.script.data.GeneratedData; +import dev.latvian.mods.kubejs.util.ID; import net.minecraft.Util; import net.minecraft.resources.ResourceLocation; @@ -17,9 +18,10 @@ import java.util.function.Consumer; public interface KubeAssetGenerator extends KubeResourceGenerator { - static ResourceLocation asItemModelLocation(ResourceLocation id) { - return ResourceLocation.fromNamespaceAndPath(id.getNamespace(), "models/item/" + id.getPath()); - } + ResourceLocation GENERATED_ITEM_MODEL = ResourceLocation.withDefaultNamespace("item/generated"); + ResourceLocation HANDHELD_ITEM_MODEL = ResourceLocation.withDefaultNamespace("item/handheld"); + ResourceLocation CUBE_BLOCK_MODEL = ResourceLocation.withDefaultNamespace("block/cube"); + ResourceLocation CUBE_ALL_BLOCK_MODEL = ResourceLocation.withDefaultNamespace("block/cube_all"); default LoadedTexture loadTexture(ResourceLocation id) { return LoadedTexture.load(id); @@ -27,35 +29,35 @@ default LoadedTexture loadTexture(ResourceLocation id) { default void blockState(ResourceLocation id, Consumer consumer) { var gen = Util.make(new VariantBlockStateGenerator(), consumer); - json(ResourceLocation.fromNamespaceAndPath(id.getNamespace(), "blockstates/" + id.getPath()), gen.toJson()); + json(id.withPath(ID.BLOCKSTATE), gen.toJson()); } default void multipartState(ResourceLocation id, Consumer consumer) { var gen = Util.make(new MultipartBlockStateGenerator(), consumer); - json(ResourceLocation.fromNamespaceAndPath(id.getNamespace(), "blockstates/" + id.getPath()), gen.toJson()); + json(id.withPath(ID.BLOCKSTATE), gen.toJson()); } default void blockModel(ResourceLocation id, Consumer consumer) { var gen = Util.make(new ModelGenerator(), consumer); - json(ResourceLocation.fromNamespaceAndPath(id.getNamespace(), "models/block/" + id.getPath()), gen.toJson()); + json(id.withPath(ID.BLOCK_MODEL), gen.toJson()); } default void itemModel(ResourceLocation id, Consumer consumer) { var gen = Util.make(new ModelGenerator(), consumer); - json(asItemModelLocation(id), gen.toJson()); + json(id.withPath(ID.ITEM_MODEL), gen.toJson()); } default void defaultItemModel(ResourceLocation id) { itemModel(id, model -> { - model.parent("minecraft:item/generated"); - model.texture("layer0", id.getNamespace() + ":item/" + id.getPath()); + model.parent(GENERATED_ITEM_MODEL); + model.texture("layer0", id.withPath(ID.ITEM).toString()); }); } default void defaultHandheldItemModel(ResourceLocation id) { itemModel(id, model -> { - model.parent("minecraft:item/handheld"); - model.texture("layer0", id.getNamespace() + ":item/" + id.getPath()); + model.parent(HANDHELD_ITEM_MODEL); + model.texture("layer0", id.withPath(ID.ITEM).toString()); }); } @@ -65,14 +67,14 @@ default void texture(ResourceLocation target, LoadedTexture texture) { return; } - add(new GeneratedData(ResourceLocation.fromNamespaceAndPath(target.getNamespace(), "textures/" + target.getPath() + ".png"), texture::toBytes)); + add(new GeneratedData(target.withPath(ID.PNG_TEXTURE), texture::toBytes)); if (texture.mcmeta != null) { - add(new GeneratedData(ResourceLocation.fromNamespaceAndPath(target.getNamespace(), "textures/" + target.getPath() + ".png.mcmeta"), () -> texture.mcmeta)); + add(new GeneratedData(target.withPath(ID.PNG_TEXTURE_MCMETA), () -> texture.mcmeta)); } } - default void stencil(ResourceLocation target, ResourceLocation stencil, Map colors) { + default void stencil(ResourceLocation target, ResourceLocation stencil, Map colors) { var stencilTexture = loadTexture(stencil); if (stencilTexture.width == 0 || stencilTexture.height == 0) { @@ -135,7 +137,7 @@ default boolean mask(ResourceLocation target, ResourceLocation mask, ResourceLoc } default void particle(ResourceLocation id, Consumer consumer) { - json(ResourceLocation.fromNamespaceAndPath(id.getNamespace(), "particles/" + id.getPath()), Util.make(new ParticleGenerator(), consumer).toJson()); + json(id.withPath(ID.PARTICLE), Util.make(new ParticleGenerator(), consumer).toJson()); } default void sounds(String namespace, Consumer consumer) { diff --git a/src/main/java/dev/latvian/mods/kubejs/item/ItemBuilder.java b/src/main/java/dev/latvian/mods/kubejs/item/ItemBuilder.java index e6b144776..e6e20fcee 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/ItemBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/ItemBuilder.java @@ -2,12 +2,13 @@ import com.google.gson.JsonObject; import dev.latvian.mods.kubejs.bindings.ItemWrapper; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.component.DataComponentWrapper; import dev.latvian.mods.kubejs.generator.KubeAssetGenerator; import dev.latvian.mods.kubejs.registry.BuilderBase; import dev.latvian.mods.kubejs.script.ConsoleJS; import dev.latvian.mods.kubejs.typings.Info; +import dev.latvian.mods.kubejs.util.ID; import dev.latvian.mods.kubejs.util.TickDuration; import dev.latvian.mods.rhino.util.ReturnsSelf; import net.minecraft.core.component.DataComponentType; @@ -61,7 +62,7 @@ public record HurtEnemyContext(ItemStack getItem, LivingEntity getTarget, Living @Nullable public transient ItemTintFunction tint; public transient FoodBuilder foodBuilder; - public transient Function barColor; + public transient Function barColor; public transient ToIntFunction barWidth; public transient NameCallback nameGetter; @@ -73,9 +74,9 @@ public record HurtEnemyContext(ItemStack getItem, LivingEntity getTarget, Living public transient Predicate hurtEnemy; public transient JukeboxPlayable jukeboxPlayable; - public String texture; - public String parentModel; - public JsonObject textureJson; + public ResourceLocation texture; + public ResourceLocation parentModel; + public Map textures; public JsonObject modelJson; public transient Tool tool; @@ -92,8 +93,8 @@ public ItemBuilder(ResourceLocation i) { rarity = null; glow = false; tooltip = new ArrayList<>(); - textureJson = new JsonObject(); - parentModel = ""; + textures = new HashMap<>(); + parentModel = null; foodBuilder = null; modelJson = null; anim = null; @@ -123,22 +124,18 @@ public Item transformObject(Item obj) { @Override public void generateAssets(KubeAssetGenerator generator) { if (modelJson != null) { - generator.json(KubeAssetGenerator.asItemModelLocation(id), modelJson); + generator.json(id.withPath(ID.ITEM_MODEL), modelJson); return; } generator.itemModel(id, m -> { - if (!parentModel.isEmpty()) { - m.parent(parentModel); - } else { - m.parent("minecraft:item/generated"); - } + m.parent(parentModel != null ? parentModel : KubeAssetGenerator.GENERATED_ITEM_MODEL); - if (textureJson.size() == 0) { - texture(newID("item/", "").toString()); + if (textures.isEmpty()) { + texture(id.withPath(ID.ITEM).toString()); } - m.textures(textureJson); + m.textures(textures); }); } @@ -232,19 +229,19 @@ public ItemBuilder color(ItemTintFunction callback) { @Info("Sets the item's texture (layer0).") public ItemBuilder texture(String tex) { - textureJson.addProperty("layer0", tex); + textures.put("layer0", tex); return this; } @Info("Sets the item's texture by given key.") public ItemBuilder texture(String key, String tex) { - textureJson.addProperty(key, tex); + textures.put(key, tex); return this; } - @Info("Directlys set the item's texture json.") - public ItemBuilder textureJson(JsonObject json) { - textureJson = json; + @Info("Directly set the item's texture json.") + public ItemBuilder textures(Map tex) { + textures.putAll(tex); return this; } @@ -255,13 +252,13 @@ public ItemBuilder modelJson(JsonObject json) { } @Info("Sets the item's model (parent).") - public ItemBuilder parentModel(String m) { + public ItemBuilder parentModel(ResourceLocation m) { parentModel = m; return this; } @Info("Determines the color of the item's durability bar. Defaulted to vanilla behavior.") - public ItemBuilder barColor(Function barColor) { + public ItemBuilder barColor(Function barColor) { this.barColor = barColor; return this; } diff --git a/src/main/java/dev/latvian/mods/kubejs/item/ItemTintFunction.java b/src/main/java/dev/latvian/mods/kubejs/item/ItemTintFunction.java index 7e64b58a6..6e56e1135 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/ItemTintFunction.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/ItemTintFunction.java @@ -1,7 +1,7 @@ package dev.latvian.mods.kubejs.item; import dev.latvian.mods.kubejs.bindings.ColorWrapper; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.color.SimpleColor; import dev.latvian.mods.rhino.BaseFunction; import dev.latvian.mods.rhino.Context; @@ -20,11 +20,11 @@ public interface ItemTintFunction { TypeInfo TYPE_INFO = TypeInfo.of(ItemTintFunction.class); - Color getColor(ItemStack stack, int index); + KubeColor getColor(ItemStack stack, int index); - record Fixed(Color color) implements ItemTintFunction { + record Fixed(KubeColor color) implements ItemTintFunction { @Override - public Color getColor(ItemStack stack, int index) { + public KubeColor getColor(ItemStack stack, int index) { return color; } } @@ -33,7 +33,7 @@ class Mapped implements ItemTintFunction { public final Int2ObjectMap map = new Int2ObjectArrayMap<>(1); @Override - public Color getColor(ItemStack stack, int index) { + public KubeColor getColor(ItemStack stack, int index) { var f = map.get(index); return f == null ? null : f.getColor(stack, index); } diff --git a/src/main/java/dev/latvian/mods/kubejs/item/custom/DiggerItemBuilder.java b/src/main/java/dev/latvian/mods/kubejs/item/custom/DiggerItemBuilder.java index 52e6cf5c8..324155c0d 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/custom/DiggerItemBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/custom/DiggerItemBuilder.java @@ -34,9 +34,11 @@ public static class Pickaxe extends DiggerItemBuilder { Tags.Items.MINING_TOOL_TOOLS.location(), }; + public static final ResourceLocation PICKAXE_MODEL = ResourceLocation.withDefaultNamespace("item/iron_pickaxe"); + public Pickaxe(ResourceLocation i) { super(i, 1F, -2.8F, PickaxeItem::new); - parentModel = "minecraft:item/iron_pickaxe"; + parentModel = PICKAXE_MODEL; tag(PICKAXE_TAGS); } } @@ -46,9 +48,11 @@ public static class Shovel extends DiggerItemBuilder { ItemTags.SHOVELS.location(), }; + public static final ResourceLocation SHOVEL_MODEL = ResourceLocation.withDefaultNamespace("item/iron_shovel"); + public Shovel(ResourceLocation i) { super(i, 1.5F, -3F, ShovelItem::new); - parentModel = "minecraft:item/iron_shovel"; + parentModel = SHOVEL_MODEL; tag(SHOVEL_TAGS); } } @@ -58,9 +62,11 @@ public static class Axe extends DiggerItemBuilder { ItemTags.AXES.location(), }; + public static final ResourceLocation AXE_MODEL = ResourceLocation.withDefaultNamespace("item/iron_axe"); + public Axe(ResourceLocation i) { super(i, 6F, -3.1F, AxeItem::new); - parentModel = "minecraft:item/iron_axe"; + parentModel = AXE_MODEL; tag(AXE_TAGS); } } @@ -70,9 +76,11 @@ public static class Hoe extends DiggerItemBuilder { ItemTags.HOES.location(), }; + public static final ResourceLocation HOE_MODEL = ResourceLocation.withDefaultNamespace("item/iron_hoe"); + public Hoe(ResourceLocation i) { super(i, 0F, -3F, HoeItem::new); - parentModel = "minecraft:item/iron_hoe"; + parentModel = HOE_MODEL; tag(HOE_TAGS); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/item/custom/HandheldItemBuilder.java b/src/main/java/dev/latvian/mods/kubejs/item/custom/HandheldItemBuilder.java index b2dfea890..14d41ba72 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/custom/HandheldItemBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/custom/HandheldItemBuilder.java @@ -1,5 +1,6 @@ package dev.latvian.mods.kubejs.item.custom; +import dev.latvian.mods.kubejs.generator.KubeAssetGenerator; import dev.latvian.mods.kubejs.item.ItemBuilder; import dev.latvian.mods.kubejs.item.MutableToolTier; import dev.latvian.mods.kubejs.typings.Info; @@ -21,7 +22,7 @@ public HandheldItemBuilder(ResourceLocation i, float d, float s) { toolTier = new MutableToolTier(Tiers.IRON); attackDamageBaseline = d; speedBaseline = s; - parentModel("minecraft:item/handheld"); + parentModel(KubeAssetGenerator.HANDHELD_ITEM_MODEL); unstackable(); } diff --git a/src/main/java/dev/latvian/mods/kubejs/item/custom/ShearsItemBuilder.java b/src/main/java/dev/latvian/mods/kubejs/item/custom/ShearsItemBuilder.java index 16360ee91..a38d561ff 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/custom/ShearsItemBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/custom/ShearsItemBuilder.java @@ -1,5 +1,6 @@ package dev.latvian.mods.kubejs.item.custom; +import dev.latvian.mods.kubejs.generator.KubeAssetGenerator; import dev.latvian.mods.kubejs.item.ItemBuilder; import dev.latvian.mods.rhino.util.ReturnsSelf; import net.minecraft.core.dispenser.ShearsDispenseItemBehavior; @@ -28,7 +29,7 @@ public static boolean isCustomShears(ItemStack stack) { public ShearsItemBuilder(ResourceLocation i) { super(i); speedBaseline(5f); - parentModel("minecraft:item/handheld"); + parentModel(KubeAssetGenerator.HANDHELD_ITEM_MODEL); unstackable(); tag(SHEAR_TAGS); tool = ShearsItem.createToolProperties(); diff --git a/src/main/java/dev/latvian/mods/kubejs/item/custom/SwordItemBuilder.java b/src/main/java/dev/latvian/mods/kubejs/item/custom/SwordItemBuilder.java index c18959cc8..77f888d8b 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/custom/SwordItemBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/custom/SwordItemBuilder.java @@ -10,10 +10,12 @@ public class SwordItemBuilder extends HandheldItemBuilder { ItemTags.SWORDS.location(), }; + public static final ResourceLocation SWORD_MODEL = ResourceLocation.withDefaultNamespace("item/iron_sword"); + public SwordItemBuilder(ResourceLocation i) { super(i, 3F, -2.4F); itemAttributeModifiers = SwordItem.createAttributes(toolTier, attackDamageBaseline, speedBaseline); - parentModel = "minecraft:item/iron_sword"; + parentModel = SWORD_MODEL; tag(SWORD_TAGS); } diff --git a/src/main/java/dev/latvian/mods/kubejs/kgui/drawable/KColor.java b/src/main/java/dev/latvian/mods/kubejs/kgui/drawable/KColor.java index bd840263b..d489a59c9 100644 --- a/src/main/java/dev/latvian/mods/kubejs/kgui/drawable/KColor.java +++ b/src/main/java/dev/latvian/mods/kubejs/kgui/drawable/KColor.java @@ -1,9 +1,9 @@ package dev.latvian.mods.kubejs.kgui.drawable; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.color.SimpleColorWithAlpha; -public record KColor(Color color) implements KDrawable { +public record KColor(KubeColor color) implements KDrawable { public static KColor of(int col) { return new KColor(new SimpleColorWithAlpha(col)); } @@ -15,7 +15,7 @@ public static KColor of(int col) { @Override public void draw(KDrawContext ctx, int x, int y, int w, int h) { if (w > 0 && h > 0) { - ctx.graphics().fill(x, y, x + w, y + h, color.getArgbJS()); + ctx.graphics().fill(x, y, x + w, y + h, color.kjs$getARGB()); } } } diff --git a/src/main/java/dev/latvian/mods/kubejs/misc/MobEffectBuilder.java b/src/main/java/dev/latvian/mods/kubejs/misc/MobEffectBuilder.java index 0e71503a9..3592006ac 100644 --- a/src/main/java/dev/latvian/mods/kubejs/misc/MobEffectBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/misc/MobEffectBuilder.java @@ -1,6 +1,6 @@ package dev.latvian.mods.kubejs.misc; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.registry.BuilderBase; import dev.latvian.mods.rhino.util.ReturnsSelf; import net.minecraft.resources.ResourceLocation; @@ -66,8 +66,8 @@ public MobEffectBuilder effectTick(EffectEntityCallback effectTick) { return this; } - public MobEffectBuilder color(Color col) { - color = col.getRgbJS(); + public MobEffectBuilder color(KubeColor col) { + color = col.kjs$getRGB(); return this; } diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java index 4bb3c822e..9f713993c 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java @@ -42,6 +42,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.util.GsonHelper; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; @@ -124,6 +125,7 @@ private String recipeToString(Recipe recipe) { public final RecipeSchemaStorage recipeSchemaStorage; public final RegistryAccessContainer registries; + public final ResourceManager resourceManager; public final RegistryOps jsonOps; public final Map originalRecipes; public final Collection addedRecipes; @@ -147,10 +149,11 @@ private String recipeToString(Recipe recipe) { final RecipeSerializer stageSerializer; - public RecipesKubeEvent(ServerScriptManager manager) { + public RecipesKubeEvent(ServerScriptManager manager, ResourceManager resourceManager) { ConsoleJS.SERVER.info("Initializing recipe event..."); this.recipeSchemaStorage = manager.recipeSchemaStorage; this.registries = manager.getRegistries(); + this.resourceManager = resourceManager; this.jsonOps = new ConditionalOps<>(registries.json(), registries); this.originalRecipes = new HashMap<>(); this.addedRecipes = new ConcurrentLinkedQueue<>(); diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java b/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java index 8d4244e4a..e6925b79b 100644 --- a/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java +++ b/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java @@ -123,7 +123,7 @@ public ResourceLocation newID(String pre, String post) { return id; } - return ResourceLocation.fromNamespaceAndPath(id.getNamespace(), pre + id.getPath() + post); + return id.withPath(pre + id.getPath() + post); } @HideFromJS diff --git a/src/main/java/dev/latvian/mods/kubejs/server/ServerScriptManager.java b/src/main/java/dev/latvian/mods/kubejs/server/ServerScriptManager.java index 7924a4110..aab7c8118 100644 --- a/src/main/java/dev/latvian/mods/kubejs/server/ServerScriptManager.java +++ b/src/main/java/dev/latvian/mods/kubejs/server/ServerScriptManager.java @@ -268,7 +268,7 @@ public boolean recipes(RecipeManagerKJS recipeManager, ResourceManager resourceM ServerEvents.SPECIAL_RECIPES.post(ScriptType.SERVER, SpecialRecipeSerializerManager.INSTANCE); if (ServerEvents.RECIPES.hasListeners()) { - new RecipesKubeEvent(this).post(recipeManager, new HashMap<>(map)); + new RecipesKubeEvent(this, resourceManager).post(recipeManager, new HashMap<>(map)); result = true; } diff --git a/src/main/java/dev/latvian/mods/kubejs/util/ID.java b/src/main/java/dev/latvian/mods/kubejs/util/ID.java index 54eff1835..889475322 100644 --- a/src/main/java/dev/latvian/mods/kubejs/util/ID.java +++ b/src/main/java/dev/latvian/mods/kubejs/util/ID.java @@ -11,9 +11,20 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.function.UnaryOperator; public interface ID { ResourceLocation UNKNOWN = ResourceLocation.fromNamespaceAndPath("unknown", "unknown"); + UnaryOperator BLOCKSTATE = s -> "blockstates/" + s; + UnaryOperator BLOCK = s -> "block/" + s; + UnaryOperator ITEM = s -> "item/" + s; + UnaryOperator MODEL = s -> "models/" + s; + UnaryOperator BLOCK_MODEL = s -> "models/block/" + s; + UnaryOperator ITEM_MODEL = s -> "models/item/" + s; + UnaryOperator BLOCK_LOOT_TABLE = s -> "loot_table/blocks/" + s; + UnaryOperator PNG_TEXTURE = s -> "textures/" + s + ".png"; + UnaryOperator PNG_TEXTURE_MCMETA = s -> "textures/" + s + ".png.mcmeta"; + UnaryOperator PARTICLE = s -> "particles/" + s; static String string(@Nullable String id) { if (id == null || id.isEmpty()) { diff --git a/src/main/java/dev/latvian/mods/kubejs/util/NotificationToastData.java b/src/main/java/dev/latvian/mods/kubejs/util/NotificationToastData.java index 3326e4525..06b85c850 100644 --- a/src/main/java/dev/latvian/mods/kubejs/util/NotificationToastData.java +++ b/src/main/java/dev/latvian/mods/kubejs/util/NotificationToastData.java @@ -4,7 +4,7 @@ import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.latvian.mods.kubejs.client.NotificationToast; -import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.color.KubeColor; import dev.latvian.mods.kubejs.color.SimpleColor; import net.minecraft.client.Minecraft; import net.minecraft.network.RegistryFriendlyByteBuf; @@ -23,23 +23,23 @@ public record NotificationToastData( Component text, IconKJS icon, int iconSize, - Color outlineColor, - Color borderColor, - Color backgroundColor, + KubeColor outlineColor, + KubeColor borderColor, + KubeColor backgroundColor, boolean textShadow ) { public static final Duration DEFAULT_DURATION = Duration.ofSeconds(5L); - public static final Color DEFAULT_BORDER_COLOR = new SimpleColor(0x472954); - public static final Color DEFAULT_BACKGROUND_COLOR = new SimpleColor(0x241335); + public static final KubeColor DEFAULT_BORDER_COLOR = new SimpleColor(0x472954); + public static final KubeColor DEFAULT_BACKGROUND_COLOR = new SimpleColor(0x241335); public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( TimeJS.DURATION.optionalFieldOf("duration", DEFAULT_DURATION).forGetter(NotificationToastData::duration), ComponentSerialization.CODEC.optionalFieldOf("text", Component.empty()).forGetter(NotificationToastData::text), IconKJS.CODEC.optionalFieldOf("icon", IconKJS.NONE).forGetter(NotificationToastData::icon), Codec.INT.optionalFieldOf("icon_size", 16).forGetter(NotificationToastData::iconSize), - Color.CODEC.optionalFieldOf("outline_color", SimpleColor.BLACK).forGetter(NotificationToastData::outlineColor), - Color.CODEC.optionalFieldOf("border_color", DEFAULT_BORDER_COLOR).forGetter(NotificationToastData::borderColor), - Color.CODEC.optionalFieldOf("background_color", DEFAULT_BACKGROUND_COLOR).forGetter(NotificationToastData::backgroundColor), + KubeColor.CODEC.optionalFieldOf("outline_color", SimpleColor.BLACK).forGetter(NotificationToastData::outlineColor), + KubeColor.CODEC.optionalFieldOf("border_color", DEFAULT_BORDER_COLOR).forGetter(NotificationToastData::borderColor), + KubeColor.CODEC.optionalFieldOf("background_color", DEFAULT_BACKGROUND_COLOR).forGetter(NotificationToastData::backgroundColor), Codec.BOOL.optionalFieldOf("text_shadow", false).forGetter(NotificationToastData::textShadow) ).apply(instance, NotificationToastData::new)); @@ -50,9 +50,9 @@ public NotificationToastData decode(RegistryFriendlyByteBuf buf) { var text = ComponentSerialization.STREAM_CODEC.decode(buf); var icon = IconKJS.STREAM_CODEC.decode(buf); var iconSize = ByteBufCodecs.VAR_INT.decode(buf); - var outlineColor = Color.STREAM_CODEC.decode(buf); - var borderColor = Color.STREAM_CODEC.decode(buf); - var backgroundColor = Color.STREAM_CODEC.decode(buf); + var outlineColor = KubeColor.STREAM_CODEC.decode(buf); + var borderColor = KubeColor.STREAM_CODEC.decode(buf); + var backgroundColor = KubeColor.STREAM_CODEC.decode(buf); var textShadow = ByteBufCodecs.BOOL.decode(buf); return new NotificationToastData(duration, text, icon, iconSize, outlineColor, borderColor, backgroundColor, textShadow); } @@ -63,9 +63,9 @@ public void encode(RegistryFriendlyByteBuf buf, NotificationToastData data) { ComponentSerialization.STREAM_CODEC.encode(buf, data.text()); IconKJS.STREAM_CODEC.encode(buf, data.icon()); ByteBufCodecs.VAR_INT.encode(buf, data.iconSize()); - Color.STREAM_CODEC.encode(buf, data.outlineColor()); - Color.STREAM_CODEC.encode(buf, data.borderColor()); - Color.STREAM_CODEC.encode(buf, data.backgroundColor()); + KubeColor.STREAM_CODEC.encode(buf, data.outlineColor()); + KubeColor.STREAM_CODEC.encode(buf, data.borderColor()); + KubeColor.STREAM_CODEC.encode(buf, data.backgroundColor()); ByteBufCodecs.BOOL.encode(buf, data.textShadow()); } };