Skip to content

Commit

Permalink
Add open eyeblossom and potted open eyeblossom.
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed Dec 16, 2024
1 parent 833780a commit a3af3a2
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")));
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}
}

}
5 changes: 5 additions & 0 deletions chunky/src/java/se/llbit/chunky/world/ExtraMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -60,5 +62,8 @@ public static void loadDefaultMaterialProperties() {

SporeBlossom.blossomMaterial.restoreDefaults();
SporeBlossom.baseMaterial.restoreDefaults();

OpenEyeBlossom.emissiveMaterial.restoreDefaults();
OpenEyeBlossom.emissiveMaterial.emittance = 1.0f / 15;
}
}

0 comments on commit a3af3a2

Please sign in to comment.