From a3af3a2130fe1dfaca1254e5026d35448c356c4f Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Mon, 16 Dec 2024 01:15:23 +0100 Subject: [PATCH] Add open eyeblossom and potted open eyeblossom. --- .../chunky/block/MinecraftBlockProvider.java | 11 ++-- .../chunky/block/minecraft/FlowerPot.java | 2 +- .../block/minecraft/OpenEyeBlossom.java | 29 ++++++++ .../model/minecraft/FlowerPotModel.java | 66 ++++++++++++++++++- .../se/llbit/chunky/world/ExtraMaterials.java | 5 ++ 5 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 chunky/src/java/se/llbit/chunky/block/minecraft/OpenEyeBlossom.java diff --git a/chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java b/chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java index 195693a5d9..0e041ae92b 100644 --- a/chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java +++ b/chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java @@ -7,7 +7,6 @@ import se.llbit.chunky.entity.BannerDesign; import se.llbit.chunky.entity.SkullEntity; import se.llbit.chunky.model.minecraft.FlowerPotModel; -import se.llbit.chunky.model.minecraft.FlowerPotModel.Kind; import se.llbit.chunky.resources.ShulkerTexture; import se.llbit.chunky.resources.Texture; import se.llbit.nbt.ListTag; @@ -977,7 +976,7 @@ private static void addBlocks(Texture texture, String... names) { addBlock("mangrove_propagule", (name, tag) -> new MangrovePropagule( BlockProvider.stringToInt(tag.get("Properties").get("age"), 0), tag.get("Properties").get("hanging").stringValue("false").equals("true"))); - addBlock("potted_mangrove_propagule", (name, tag) -> new FlowerPot(name, Kind.MANGROVE_PROPAGULE)); + addBlock("potted_mangrove_propagule", (name, tag) -> new FlowerPot(name, FlowerPotModel.Kind.MANGROVE_PROPAGULE)); addBlock("sculk_catalyst", (name, tag) -> new SculkCatalyst(tag.get("Properties").get("bloom").stringValue("false").equals("true"))); addBlock("sculk", Texture.sculk); addBlock("sculk_shrieker", (name, tag) -> new SculkShrieker(tag.get("Properties").get("can_summon").stringValue("false").equals("true"))); @@ -1023,10 +1022,10 @@ private static void addBlocks(Texture texture, String... names) { addBlock("cherry_wood", (name, tag) -> log(tag, Texture.cherryLog, Texture.cherryLog)); addBlock("stripped_cherry_wood", (name, tag) -> log(tag, Texture.strippedCherryLog, Texture.strippedCherryLog)); addBlock("cherry_sapling", (name, tag) -> new SpriteBlock(name, Texture.cherrySapling)); - addBlock("potted_cherry_sapling", (name, tag) -> new FlowerPot(name, Kind.CHERRY_SAPLING)); + addBlock("potted_cherry_sapling", (name, tag) -> new FlowerPot(name, FlowerPotModel.Kind.CHERRY_SAPLING)); addBlock("torchflower", (name, tag) -> new SpriteBlock(name, Texture.torchflower)); addBlock("torchflower_crop", (name, tag) -> new TorchflowerCrop(BlockProvider.stringToInt(tag.get("Properties").get("age"), 2))); - addBlock("potted_torchflower", (name, tag) -> new FlowerPot(name, Kind.TORCHFLOWER)); + addBlock("potted_torchflower", (name, tag) -> new FlowerPot(name, FlowerPotModel.Kind.TORCHFLOWER)); addBlock("suspicious_sand", (name, tag) -> suspiciousSand(tag)); addBlock("suspicious_gravel", (name, tag) -> suspiciousGravel(tag)); addBlock("chiseled_bookshelf", (name, tag) -> new ChiseledBookshelf( @@ -1123,7 +1122,7 @@ private static void addBlocks(Texture texture, String... names) { addBlock("heavy_core", (name, tag) -> new HeavyCore()); addBlock("trial_spawner", (name, tag) -> new TrialSpawner(tag.get("Properties").get("ominous").stringValue().equals("true"), tag.get("Properties").get("trial_spawner_state").stringValue("active"))); - // Winter drop (1.22?) + //1.21.4 (Winter Drop) addBlock("pale_moss_block", Texture.paleMossBlock); addBlock("pale_oak_leaves", (name, tag) -> new UntintedLeaves(name, Texture.paleOakLeaves)); addBlock("pale_oak_log", (name, tag) -> log(tag, Texture.paleOakLog, Texture.paleOakLogTop)); @@ -1157,7 +1156,9 @@ private static void addBlocks(Texture texture, String... names) { tag.get("Properties").get("active").stringValue("false").equals("true"))); addBlock("chiseled_resin_bricks", Texture.chiseledResinBricks); addBlock("closed_eyeblossom", (name, tag) -> new SpriteBlock(name, Texture.closedEyeblossom)); + addBlock("open_eyeblossom", (name, tag) -> new OpenEyeBlossom()); addBlock("potted_closed_eyeblossom", (name, tag) -> new FlowerPot(name, FlowerPotModel.Kind.CLOSED_EYEBLOSSOM)); + addBlock("potted_open_eyeblossom", (name, tag) -> new FlowerPot(name, FlowerPotModel.Kind.OPEN_EYEBLOSSOM)); addBlock("resin_block", Texture.resinBlock); addBlock("resin_bricks", Texture.resinBricks); addBlock("resin_brick_stairs", (name, tag) -> stairs(tag, Texture.resinBricks)); diff --git a/chunky/src/java/se/llbit/chunky/block/minecraft/FlowerPot.java b/chunky/src/java/se/llbit/chunky/block/minecraft/FlowerPot.java index c30f09376f..4289df54d3 100644 --- a/chunky/src/java/se/llbit/chunky/block/minecraft/FlowerPot.java +++ b/chunky/src/java/se/llbit/chunky/block/minecraft/FlowerPot.java @@ -25,6 +25,6 @@ public class FlowerPot extends AbstractModelBlock { public FlowerPot(String name, FlowerPotModel.Kind kind) { super(name, Texture.flowerPot); - this.model = new FlowerPotModel(kind); + this.model = FlowerPotModel.forKind(kind); } } diff --git a/chunky/src/java/se/llbit/chunky/block/minecraft/OpenEyeBlossom.java b/chunky/src/java/se/llbit/chunky/block/minecraft/OpenEyeBlossom.java new file mode 100644 index 0000000000..6dab78ea42 --- /dev/null +++ b/chunky/src/java/se/llbit/chunky/block/minecraft/OpenEyeBlossom.java @@ -0,0 +1,29 @@ +package se.llbit.chunky.block.minecraft; + +import se.llbit.chunky.block.MinecraftBlockTranslucent; +import se.llbit.chunky.model.minecraft.SpriteModel; +import se.llbit.chunky.renderer.scene.Scene; +import se.llbit.chunky.resources.Texture; +import se.llbit.chunky.world.Material; +import se.llbit.chunky.world.material.TextureMaterial; +import se.llbit.math.Ray; + +public class OpenEyeBlossom extends MinecraftBlockTranslucent { + public static final Material emissiveMaterial = new TextureMaterial(Texture.openEyeblossomEmissive); + private static final SpriteModel base = new SpriteModel(Texture.openEyeblossom, "up"); + private static final SpriteModel emissive = new SpriteModel(Texture.openEyeblossomEmissive, "up"); + + public OpenEyeBlossom() { + super("open_eyeblossom", Texture.openEyeblossom); + localIntersect = true; + } + + @Override + public boolean intersect(Ray ray, Scene scene) { + if (emissive.intersect(ray, scene)) { + ray.setCurrentMaterial(emissiveMaterial); + return true; + } + return base.intersect(ray, scene); + } +} diff --git a/chunky/src/java/se/llbit/chunky/model/minecraft/FlowerPotModel.java b/chunky/src/java/se/llbit/chunky/model/minecraft/FlowerPotModel.java index 0be049186a..56b91a04b9 100644 --- a/chunky/src/java/se/llbit/chunky/model/minecraft/FlowerPotModel.java +++ b/chunky/src/java/se/llbit/chunky/model/minecraft/FlowerPotModel.java @@ -17,11 +17,15 @@ */ package se.llbit.chunky.model.minecraft; +import se.llbit.chunky.block.minecraft.OpenEyeBlossom; +import se.llbit.chunky.model.BlockModel; import se.llbit.chunky.model.Model; import se.llbit.chunky.model.QuadModel; import se.llbit.chunky.model.Tint; +import se.llbit.chunky.renderer.scene.Scene; import se.llbit.chunky.resources.Texture; import se.llbit.math.Quad; +import se.llbit.math.Ray; import se.llbit.math.Vector3; import se.llbit.math.Vector4; @@ -70,7 +74,8 @@ public enum Kind { TORCHFLOWER, CHERRY_SAPLING, PALE_OAK_SAPLING, - CLOSED_EYEBLOSSOM + CLOSED_EYEBLOSSOM, + OPEN_EYEBLOSSOM } private static final Texture flowerpot = Texture.flowerPot; @@ -481,7 +486,7 @@ public enum Kind { private final Texture[] textures; private final Tint[] tints; - public FlowerPotModel(Kind kind) { + private FlowerPotModel(Kind kind) { switch (kind) { case NONE: quads = flowerPot; @@ -528,6 +533,14 @@ public FlowerPotModel(Kind kind) { System.arraycopy(flowerPotTex, 0, textures, 0, flowerPotTex.length); Arrays.fill(textures, flowerPotTex.length, textures.length, Texture.mangrovePropagule); break; + case OPEN_EYEBLOSSOM: + quads = Model.join(flowerPot, flowerSmall, flowerSmall); + textures = new Texture[flowerPotTex.length + 2 * flowerSmall.length]; + tints = null; + System.arraycopy(flowerPotTex, 0, textures, 0, flowerPotTex.length); + Arrays.fill(textures, flowerPotTex.length, flowerPotTex.length + flowerSmall.length, Texture.openEyeblossom); + Arrays.fill(textures, flowerPotTex.length + flowerSmall.length, textures.length, Texture.openEyeblossomEmissive); + break; default: quads = Model.join(flowerPot, flowerSmall); textures = new Texture[flowerPotTex.length + flowerSmall.length]; @@ -643,4 +656,53 @@ public Texture[] getTextures() { public Tint[] getTints() { return tints; } + + public static BlockModel forKind(Kind kind) { + if (kind == Kind.OPEN_EYEBLOSSOM) { + return new FlowerPotModel(Kind.OPEN_EYEBLOSSOM) { + @Override + public boolean intersect(Ray ray, Scene scene) { + boolean hit = false; + ray.t = Double.POSITIVE_INFINITY; + + Quad[] quads = getQuads(); + Texture[] textures = getTextures(); + Tint[] tintedQuads = getTints(); + + float[] color = null; + Tint tint = Tint.NONE; + for (int i = 0; i < quads.length; ++i) { + Quad quad = quads[i]; + if (quad.intersect(ray)) { + float[] c = textures[i].getColor(ray.u, ray.v); + if (c[3] > Ray.EPSILON) { + tint = tintedQuads == null ? Tint.NONE : tintedQuads[i]; + color = c; + ray.t = ray.tNext; + if (quad.doubleSided) + ray.orientNormal(quad.n); + else + ray.setNormal(quad.n); + hit = true; + if (textures[i] == Texture.openEyeblossomEmissive) { + ray.setCurrentMaterial(OpenEyeBlossom.emissiveMaterial); + } + } + } + } + + if (hit) { + ray.color.set(color); + tint.tint(ray.color, ray, scene); + ray.distance += ray.t; + ray.o.scaleAdd(ray.t, ray.d); + } + return hit; + } + }; + } else { + return new FlowerPotModel(kind); + } + } + } diff --git a/chunky/src/java/se/llbit/chunky/world/ExtraMaterials.java b/chunky/src/java/se/llbit/chunky/world/ExtraMaterials.java index 560ca1137a..814e374d8d 100644 --- a/chunky/src/java/se/llbit/chunky/world/ExtraMaterials.java +++ b/chunky/src/java/se/llbit/chunky/world/ExtraMaterials.java @@ -17,6 +17,7 @@ package se.llbit.chunky.world; import se.llbit.chunky.block.minecraft.Candle; +import se.llbit.chunky.block.minecraft.OpenEyeBlossom; import se.llbit.chunky.entity.CalibratedSculkSensorAmethyst; import se.llbit.chunky.entity.Campfire; import se.llbit.chunky.entity.SporeBlossom; @@ -39,6 +40,7 @@ public class ExtraMaterials { idMap.put("calibrated_sculk_sensor_amethyst_inactive", CalibratedSculkSensorAmethyst.inactiveMaterial); idMap.put("spore_blossom (base)", SporeBlossom.baseMaterial); idMap.put("spore_blossom (blossom)", SporeBlossom.blossomMaterial); + idMap.put("open_eyeblossom (emissive)", OpenEyeBlossom.emissiveMaterial); } public static void loadDefaultMaterialProperties() { @@ -60,5 +62,8 @@ public static void loadDefaultMaterialProperties() { SporeBlossom.blossomMaterial.restoreDefaults(); SporeBlossom.baseMaterial.restoreDefaults(); + + OpenEyeBlossom.emissiveMaterial.restoreDefaults(); + OpenEyeBlossom.emissiveMaterial.emittance = 1.0f / 15; } }