Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new blocks from 24w44a #1794

Merged
merged 6 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 41 additions & 42 deletions chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +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.model.minecraft.PaleMossCarpetModel;
import se.llbit.chunky.resources.ShulkerTexture;
import se.llbit.chunky.resources.Texture;
import se.llbit.nbt.ListTag;
Expand Down Expand Up @@ -978,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 @@ -1024,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 @@ -1124,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 @@ -1155,7 +1153,24 @@ private static void addBlocks(Texture texture, String... names) {
tag.get("Properties").get("west").stringValue("none")));
addBlock("creaking_heart", (name, tag) -> new CreakingHeart(name,
tag.get("Properties").get("axis").stringValue("y"),
tag.get("Properties").get("creaking").stringValue("active")));
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));
addBlock("resin_brick_slab", (name, tag) -> slab(tag, Texture.resinBricks));
addBlock("resin_brick_walls", (name, tag) -> wall(tag, Texture.resinBricks));
addBlock("resin_clump", (name, tag) -> new ResinClump(
tag.get("Properties").get("north").stringValue("false").equals("true"),
tag.get("Properties").get("south").stringValue("false").equals("true"),
tag.get("Properties").get("east").stringValue("false").equals("true"),
tag.get("Properties").get("west").stringValue("false").equals("true"),
tag.get("Properties").get("up").stringValue("false").equals("true"),
tag.get("Properties").get("down").stringValue("false").equals("true")));
}

@Override
Expand Down Expand Up @@ -3585,22 +3600,14 @@ private static Block seaPickle(Tag tag) {

private static Block structureBlock(Tag tag) {
Tag properties = tag.get("Properties");
Texture texture = Texture.structureBlock;
String mode = properties.get("mode").stringValue("");
switch (mode) {
case "corner":
texture = Texture.structureBlockCorner;
break;
case "data":
texture = Texture.structureBlockData;
break;
case "load":
texture = Texture.structureBlockLoad;
break;
case "save":
texture = Texture.structureBlockSave;
break;
}
Texture texture = switch (mode) {
case "corner" -> Texture.structureBlockCorner;
case "data" -> Texture.structureBlockData;
case "load" -> Texture.structureBlockLoad;
case "save" -> Texture.structureBlockSave;
default -> Texture.structureBlock;
};
return new MinecraftBlock("structure_block", texture);
}

Expand All @@ -3620,31 +3627,23 @@ private static Block candleCake(Tag tag, Texture candleTexture, Texture candleTe
private static Block suspiciousSand(Tag tag) {
Tag properties = tag.get("Properties");
String dusted = properties.get("dusted").stringValue("0");
switch(dusted) {
case "1":
return new MinecraftBlock("suspicious_sand", Texture.suspiciousSandStage1);
case "2":
return new MinecraftBlock("suspicious_sand", Texture.suspiciousSandStage2);
case "3":
return new MinecraftBlock("suspicious_sand", Texture.suspiciousSandStage3);
default:
return new MinecraftBlock("suspicious_sand", Texture.suspiciousSandStage0);
}
return switch (dusted) {
case "1" -> new MinecraftBlock("suspicious_sand", Texture.suspiciousSandStage1);
case "2" -> new MinecraftBlock("suspicious_sand", Texture.suspiciousSandStage2);
case "3" -> new MinecraftBlock("suspicious_sand", Texture.suspiciousSandStage3);
default -> new MinecraftBlock("suspicious_sand", Texture.suspiciousSandStage0);
};
}

private static Block suspiciousGravel(Tag tag) {
Tag properties = tag.get("Properties");
String dusted = properties.get("dusted").stringValue("0");
switch(dusted) {
case "1":
return new MinecraftBlock("suspicious_gravel", Texture.suspiciousGravelStage1);
case "2":
return new MinecraftBlock("suspicious_gravel", Texture.suspiciousGravelStage2);
case "3":
return new MinecraftBlock("suspicious_gravel", Texture.suspiciousGravelStage3);
default:
return new MinecraftBlock("suspicious_gravel", Texture.suspiciousGravelStage0);
}
return switch (dusted) {
case "1" -> new MinecraftBlock("suspicious_gravel", Texture.suspiciousGravelStage1);
case "2" -> new MinecraftBlock("suspicious_gravel", Texture.suspiciousGravelStage2);
case "3" -> new MinecraftBlock("suspicious_gravel", Texture.suspiciousGravelStage3);
default -> new MinecraftBlock("suspicious_gravel", Texture.suspiciousGravelStage0);
};
}

private static Block decoratedPot(Tag tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
public class CreakingHeart extends AbstractModelBlock {
private final String description;

public CreakingHeart(String name, String axis, String creaking) {
public CreakingHeart(String name, String axis, boolean active) {
super(name, Texture.creakingHeartTop);
this.model = new LogModel(
axis,
creaking.equals("disabled") ? Texture.creakingHeart : Texture.creakingHeartActive,
creaking.equals("disabled") ? Texture.creakingHeartTop : Texture.creakingHeartTopActive
active ? Texture.creakingHeartActive : Texture.creakingHeart,
active ? Texture.creakingHeartTopActive : Texture.creakingHeartTop
);
this.description = String.format("axis=%s, creaking=%s", axis, creaking);
this.description = String.format("active=%s, axis=%s", active, axis);
}

@Override
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,16 @@
package se.llbit.chunky.block.minecraft;

import se.llbit.chunky.block.AbstractModelBlock;
import se.llbit.chunky.model.minecraft.OpenEyeblossomModel;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.world.Material;
import se.llbit.chunky.world.material.TextureMaterial;

public class OpenEyeblossom extends AbstractModelBlock {
public static final Material emissiveMaterial = new TextureMaterial(Texture.openEyeblossomEmissive);

public OpenEyeblossom() {
super("open_eyeblossom", Texture.openEyeblossom);
model = new OpenEyeblossomModel();
}
}
22 changes: 22 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/minecraft/ResinClump.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package se.llbit.chunky.block.minecraft;

import se.llbit.chunky.block.AbstractModelBlock;
import se.llbit.chunky.model.minecraft.ResinClumpModel;
import se.llbit.chunky.resources.Texture;

public class ResinClump extends AbstractModelBlock {
private final String description;

public ResinClump(boolean north, boolean south, boolean east, boolean west, boolean up,
boolean down) {
super("resin_clump", Texture.resinClump);
this.description = String.format("north=%s, south=%s, east=%s, west=%s, up=%s, down=%s",
north, south, east, west, up, down);
this.model = new ResinClumpModel(north, south, east, west, up, down);
}

@Override
public String description() {
return description;
}
}
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 @@ -69,7 +73,9 @@ public enum Kind {
MANGROVE_PROPAGULE,
TORCHFLOWER,
CHERRY_SAPLING,
PALE_OAK_SAPLING
PALE_OAK_SAPLING,
CLOSED_EYEBLOSSOM,
OPEN_EYEBLOSSOM
}

private static final Texture flowerpot = Texture.flowerPot;
Expand Down Expand Up @@ -480,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 @@ -527,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 @@ -620,6 +634,9 @@ public FlowerPotModel(Kind kind) {
case PALE_OAK_SAPLING:
Arrays.fill(textures, flowerPotTex.length, textures.length, Texture.paleOakSapling);
break;
case CLOSED_EYEBLOSSOM:
Arrays.fill(textures, flowerPotTex.length, textures.length, Texture.closedEyeblossom);
break;
}
break;
}
Expand All @@ -639,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);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package se.llbit.chunky.model.minecraft;

import se.llbit.chunky.block.minecraft.OpenEyeblossom;
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 java.util.Arrays;

public class OpenEyeblossomModel extends QuadModel {
private static final Quad[] quads;
private static final Texture[] textures;

static {
SpriteModel base = new SpriteModel(Texture.openEyeblossom, "up");
SpriteModel emissive = new SpriteModel(Texture.openEyeblossomEmissive, "up");

quads = Model.join(base.getQuads(), emissive.getQuads());
textures = Arrays.copyOf(base.getTextures(), base.getTextures().length + emissive.getTextures().length);
System.arraycopy(emissive.getTextures(), 0, textures, base.getTextures().length, emissive.getTextures().length);
}

@Override
public Quad[] getQuads() {
return quads;
}

@Override
public Texture[] getTextures() {
return textures;
}

@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;
}
}
Loading
Loading