christmas chest textures (24-26 december, chests and trapped chests, local_time item models, pixelpics.testDate test property), chest items from the item definition texture, shield banner patterns, item displays turned 180° like vanilla, dropped item lift from the ground model bounds, baby held-item offset, map decorations on framed vanilla maps (banners, frames, markers; none on photo maps), inverted block elements in items and displays (spawner, vault inner faces), deterministic test scenes, items/xmas/marker test scenes

This commit is contained in:
MineTec committed 2026-11-04 21:15:38 +01:00
1 parent 9e48e35680
commit 9093c1ccfb
17 files changed
+681 -74

No files matched your search

@@ -1,5 +1,6 @@
package eu.mhsl.minecraft.pixelpics.render.entity;
import eu.mhsl.minecraft.pixelpics.render.util.SpecialDates;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -237,13 +238,18 @@ public final class BlockEntityModels {
return s.chestKind() == null ? BlockEntityState.ChestKind.SINGLE : s.chestKind();
}
/**
* ChestRenderer.getChestMaterial + Sheets.chooseSprite: copper by stage, ender, CHRISTMAS for regular AND
* trapped chests between 24 and 26 December ({@link SpecialDates#isExtendedChristmas}), else normal/trapped.
*/
private static List<String> chestTextures(BlockEntityState s) {
boolean xmas = SpecialDates.isExtendedChristmas();
String base =
switch (s.kind()) {
case TRAPPED_CHEST -> "trapped";
case TRAPPED_CHEST -> xmas ? "christmas" : "trapped";
case ENDER_CHEST -> "ender";
case COPPER_CHEST -> s.colorName() == null ? "copper" : "copper_" + s.colorName();
default -> "normal";
default -> xmas ? "christmas" : "normal";
};
if (s.kind() == BlockEntityState.Kind.ENDER_CHEST) return List.of("entity/chest/ender");
return switch (chestKind(s)) {
@@ -100,6 +100,7 @@ public final class DecorationBaker implements EntityBaker<DecorationState> {
faces[Direction.NORTH.ordinal()] = new Face(s.mapPixels(), 1, 1, 0, 0, 0, -1);
faces[Direction.SOUTH.ordinal()] = new Face(s.mapPixels(), 0, 1, 1, 0, 0, -1);
cubes.add(new EntityCube(new double[] {0, 0, -0.01}, new double[] {128, 128, -0.01}, faces, m));
addMapMarkers(s, m, cubes);
} else if (s.item() != null && items != null) {
Affine m =
content.mul(Affine.rotZ(Math.toRadians(s.rotation() * 45))).mul(Affine.scale(0.5));
@@ -108,6 +109,31 @@ public final class DecorationBaker implements EntityBaker<DecorationState> {
return cubes.isEmpty() ? null : RenderedEntity.of(cubes);
}
/**
* MapRenderer decorations (only those shown on frames, see {@code MapPixels.markers}): in map pixel space
* {@code T(x/2 + 64, y/2 + 64, -0.02)·rotZ(rot·22.5°)·S(4, 4, 3)·T(-0.125, 0.125, 0)}, the sprite quad
* (-1,1)..(1,-1) at z = n·-0.001 (n-th drawn decoration), {@code map/decorations/<asset>} with v0 at +y.
*/
private void addMapMarkers(DecorationState s, Affine map, List<EntityCube> cubes) {
int count = 0;
for (DecorationState.MapMarker mk : s.mapMarkers()) {
int[][] sprite = textures.get(ResourceLocation.parse("map/decorations/" + mk.asset()))
.orElse(null);
if (sprite != null) {
Affine m = map.mul(Affine.translation(mk.x() / 2.0 + 64, mk.y() / 2.0 + 64, -0.02))
.mul(Affine.rotZ(Math.toRadians(mk.rot() * 360 / 16.0)))
.mul(Affine.scale(4, 4, 3))
.mul(Affine.translation(-0.125, 0.125, 0));
double z = count * -0.001;
Face[] faces = new Face[6];
faces[Direction.SOUTH.ordinal()] = new Face(sprite, 0, 0, 1, 1, 0, -1);
faces[Direction.NORTH.ordinal()] = new Face(sprite, 1, 0, 0, 1, 0, -1);
cubes.add(new EntityCube(new double[] {-1, -1, z}, new double[] {1, 1, z}, faces, m));
}
count++;
}
}
/** Vanilla Direction#toYRot for horizontal facings (south 0, west 90, north 180, east 270). */
private static double yRot(DecorationState.Facing f) {
return switch (f) {
@@ -1,5 +1,7 @@
package eu.mhsl.minecraft.pixelpics.render.entity;
import java.util.List;
/**
* Immutable snapshot of a flat wall decoration (painting or item frame). These are Bukkit
* {@code Hanging} entities, not block-entities, but render as flat textured quads rather than CEM
@@ -21,8 +23,50 @@ public record DecorationState(
int[][] mapPixels, // framed map's 128x128 ARGB colours (row-major [y][x]); null if not a map with data
int rotation, // item-frame content rotation in 45° steps (0..7, vanilla ItemFrame#getRotation)
boolean glow, // glow item frame
boolean invisible // invisible frame (setVisible(false)): no frame model, item sits on the wall
boolean invisible, // invisible frame (setVisible(false)): no frame model, item sits on the wall
List<MapMarker> mapMarkers // framed map's decorations shown on item frames (banners, frames, …); may be empty
) {
/** The layout without map markers (paintings, frames without a map or with an undecorated one). */
public DecorationState(
Kind kind,
double minX,
double minY,
double minZ,
double maxX,
double maxY,
double maxZ,
Facing facing,
String paintingArt,
ItemSpec item,
int[][] mapPixels,
int rotation,
boolean glow,
boolean invisible) {
this(
kind,
minX,
minY,
minZ,
maxX,
maxY,
maxZ,
facing,
paintingArt,
item,
mapPixels,
rotation,
glow,
invisible,
List.of());
}
/**
* One map decoration (vanilla MapDecoration): sprite {@code map/decorations/<asset>}, position in half map
* pixels from the centre ({@code x}, {@code y} in -128..127), rotation in 16ths of a full turn.
*/
public record MapMarker(String asset, int x, int y, int rot) {}
public enum Kind {
PAINTING,
ITEM_FRAME
@@ -15,6 +15,9 @@ public final class EntityCube {
public final Affine toLocal; // inverse
public final boolean additive; // emissive, added to what lies behind (energy swirl) instead of blended
public final boolean unshaded; // no directional face shading (vanilla NO_CARDINAL_LIGHTING: eyes, breeze wind)
// Block-model element with from > to on some axis (spawner/vault inner faces): its faces point INTO the box
// and are back-face culled like vanilla quads (see EntityIntersector); mirrored = toWorld flips handedness.
public final boolean inverted, mirrored;
public final double[] aabbMin = {Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE};
public final double[] aabbMax = {-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE};
@@ -34,6 +37,12 @@ public final class EntityCube {
this.faces = faces;
this.toWorld = toWorld;
this.toLocal = toWorld.inverse();
this.inverted = from[0] > to[0] || from[1] > to[1] || from[2] > to[2];
double[] r = toWorld.r;
double det = r[0] * (r[4] * r[8] - r[5] * r[7])
- r[1] * (r[3] * r[8] - r[5] * r[6])
+ r[2] * (r[3] * r[7] - r[4] * r[6]);
this.mirrored = det < 0;
for (int i = 0; i < 8; i++) {
double x = (i & 1) == 0 ? from[0] : to[0];
double y = (i & 2) == 0 ? from[1] : to[1];
@@ -17,6 +17,7 @@ import org.bukkit.util.Vector;
public final class EntityIntersector {
private static final double EPS = 1e-7;
private static final Direction[] DIRECTIONS = Direction.values();
private EntityIntersector() {}
@@ -55,6 +56,7 @@ public final class EntityIntersector {
d[1] = r[3] * dx + r[4] * dy + r[5] * dz;
d[2] = r[6] * dx + r[7] * dy + r[8] * dz;
double[] from = cube.from, to = cube.to;
if (cube.inverted) return intersectInverted(cube, o, d, Math.max(EPS, minT), maxT, out);
double tmin = Double.NEGATIVE_INFINITY, tmax = Double.POSITIVE_INFINITY;
int inAxis = -1, outAxis = -1;
@@ -110,6 +112,53 @@ public final class EntityIntersector {
return true;
}
/**
* A block-model element with {@code from > to} on some axis (spawner/vault/trial-spawner inner faces) baked as
* an item or display: like {@code ElementIntersector.invertedBox}, vanilla puts the WEST/DOWN/NORTH face at
* {@code from} and EAST/UP/SOUTH at {@code to} of its axis, and each inverted OTHER axis mirrors the quad and
* flips its winding — the faces point into the box and are back-face culled (seen through the cage: the far
* wall's inside). Nearest visible opaque face in {@code (lo, maxT]} wins; UVs follow the mirrored corners.
*/
private static boolean intersectInverted(EntityCube cube, double[] o, double[] d, double lo, double maxT, Hit out) {
double[] from = cube.from, to = cube.to;
double best = Double.POSITIVE_INFINITY;
for (Direction dir : DIRECTIONS) {
int a = dir.nx != 0 ? 0 : dir.ny != 0 ? 1 : 2;
if (Math.abs(d[a]) < EPS) continue;
boolean neg = dir.nx + dir.ny + dir.nz < 0;
int b = (a + 1) % 3, c = (a + 2) % 3;
int flips = (from[b] > to[b] ? 1 : 0) + (from[c] > to[c] ? 1 : 0);
double sign = (neg ? -1 : 1) * (flips % 2 == 0 ? 1 : -1) * (cube.mirrored ? -1 : 1);
if (sign * d[a] >= 0) continue; // back face
double t = ((neg ? from[a] : to[a]) - o[a]) / d[a];
if (!(t > lo) || t > maxT || t >= best) continue;
double pb = o[b] + d[b] * t, pc = o[c] + d[c] * t;
if (pb < Math.min(from[b], to[b]) - EPS || pb > Math.max(from[b], to[b]) + EPS) continue;
if (pc < Math.min(from[c], to[c]) - EPS || pc > Math.max(from[c], to[c]) + EPS) continue;
Face face = cube.faces[dir.ordinal()];
if (face == null) continue;
double fx = signedFrac(o[0] + d[0] * t, from[0], to[0]);
double fy = signedFrac(o[1] + d[1] * t, from[1], to[1]);
double fz = signedFrac(o[2] + d[2] * t, from[2], to[2]);
int color = face.sample(ElementIntersector.faceS(dir, fx, fy, fz), ElementIntersector.faceT(dir, fy, fz));
if (!ColorUtil.opaque(color)) continue;
best = t;
out.t = t;
out.color = color;
out.axis = a;
out.neg = neg;
}
return best < Double.POSITIVE_INFINITY;
}
/** Position between {@code from} (0) and {@code to} (1), also when {@code from > to}; clamped to 0..1. */
private static double signedFrac(double v, double from, double to) {
double span = to - from;
if (Math.abs(span) < 1e-9) return 0;
double f = (v - from) / span;
return f < 0 ? 0 : Math.min(f, 1);
}
/** The result object for a hit of {@code cube} recorded by {@link #intersect} (world point + normal). */
public static FaceHit toFaceHit(
EntityCube cube, Hit h, double ox, double oy, double oz, double dx, double dy, double dz) {
@@ -43,7 +43,10 @@ public final class ObjectBaker implements EntityBaker<ObjectState> {
case ITEM -> {
Affine at = s.toWorld();
if (s.dropped()) {
double lift = 0.1 + 0.25 * items.displayScaleY(s.item(), s.context());
// ItemEntityRenderer: T(0, bob + 0.0625 - modelBox.minY), bob = sin(age/10 + offset)·0.1 + 0.1
// frozen at phase 0: the ground model's lowest point floats 0.1625 above the entity position.
double[] box = items.modelBounds(s.item(), s.context());
double lift = 0.1 + 0.0625 - (box == null ? 0 : box[1]);
at = Affine.translation(0, lift, 0).mul(at);
}
items.bake(s.item(), s.context(), false, at, cubes);
@@ -424,18 +424,28 @@ public final class BlockEntityBaker implements EntityBaker<BlockEntityState> {
* (one geometry, no coplanar layers).
*/
private int[][] bannerFlag(int[][] base, BlockEntityState s) {
int baseColor = s.baseColorArgb();
List<BlockEntityState.BannerPattern> patterns = List.copyOf(s.patterns());
return derived.get(
DerivedTextureCache.key("banner", base, baseColor, patterns),
() -> buildBannerFlag(base, baseColor, patterns));
return patterned(base, "entity/banner/", s.baseColorArgb(), s.patterns());
}
private int[][] buildBannerFlag(int[][] base, int baseColor, List<BlockEntityState.BannerPattern> patterns) {
/**
* BannerRenderer.submitPatterns composited into one texture: {@code base} (banner_base / shield_base), the
* {@code <dir>base} mask dyed with {@code baseColor} (0 = none), then the first 16 pattern masks
* ({@code <dir><key>}) dyed with their colours. {@code dir} = {@code entity/banner/} or {@code entity/shield/}
* (shields, ShieldSpecialRenderer). Cached per input.
*/
public int[][] patterned(int[][] base, String dir, int baseColor, List<BlockEntityState.BannerPattern> patterns) {
List<BlockEntityState.BannerPattern> pats = List.copyOf(patterns.subList(0, Math.min(16, patterns.size())));
return derived.get(
DerivedTextureCache.key("banner", base, dir, baseColor, pats),
() -> buildPatterned(base, dir, baseColor, pats));
}
private int[][] buildPatterned(
int[][] base, String dir, int baseColor, List<BlockEntityState.BannerPattern> patterns) {
int[][] out = TextureOps.deepCopy(base);
if (baseColor != 0) overlayMask(out, "entity/banner/base", baseColor);
if (baseColor != 0) overlayMask(out, dir + "base", baseColor);
for (BlockEntityState.BannerPattern pat : patterns) {
overlayMask(out, "entity/banner/" + pat.patternKey(), pat.colorArgb());
overlayMask(out, dir + pat.patternKey(), pat.colorArgb());
}
return out;
}
@@ -405,7 +405,8 @@ public final class CemBaker implements EntityBaker<EntityState> {
}
/**
* Held items (vanilla ItemInHandLayer: hand frame · rotX(-90) · rotY(180) · T(±1/16, 0.125, -0.625),
* Held items (vanilla ItemInHandLayer: hand frame · rotX(-90) · rotY(180) · T(±1/16, 0.125, -0.625), babies
* T(0, 1/16, -4.5/16),
* third-person display context), crossed-arms items (villagers/witches: root · T(0, 0.4, -0.4) ·
* rotX(180), ground context) and head items (CustomHeadLayer: blocks/items at 0.625 with the "head"
* context, skulls at 1.1875 through the block-entity model). Frames are Java-model frames (blocks).
@@ -421,10 +422,15 @@ public final class CemBaker implements EntityBaker<EntityState> {
if (item == null) continue;
Affine arm = frames.get(left ? "left_arm" : "right_arm");
if (arm != null && !crossed && !(illager && !frames.containsKey(d + "right_arm"))) {
// ItemInHandLayer.useBabyOffset (babies except armor stands): (0, 1, -4.5) px instead of (±1, 2, -10).
boolean babyOffset = s.baby() && !s.typeKey().equals("armor_stand");
Affine x = arm.mul(CemGeometry.JAVA_LOCAL)
.mul(Affine.rotX(Math.toRadians(-90)))
.mul(Affine.rotY(Math.PI))
.mul(Affine.translation((left ? -1 : 1) / 16.0, 0.125, -0.625));
.mul(
babyOffset
? Affine.translation(0, 1 / 16.0, -4.5 / 16)
: Affine.translation((left ? -1 : 1) / 16.0, 0.125, -0.625));
items.bake(item, left ? "thirdperson_lefthand" : "thirdperson_righthand", left, x, out);
} else if (crossed && !left && frames.containsKey("root")) {
Affine x = frames.get("root")
@@ -22,14 +22,21 @@ import eu.mhsl.minecraft.pixelpics.render.entity.TextureOps;
import eu.mhsl.minecraft.pixelpics.render.tint.BiomeTint;
import eu.mhsl.minecraft.pixelpics.render.tint.TintResolver;
import eu.mhsl.minecraft.pixelpics.render.util.ColorUtil;
import eu.mhsl.minecraft.pixelpics.render.util.SpecialDates;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.DyeColor;
import org.bukkit.block.data.BlockData;
/**
@@ -77,6 +84,7 @@ public final class ItemGeometry {
List<String> layers, // generated-item layer textures (layer0, layer1, …); empty if not generated
List<Integer> tints, // ARGB per layer (0 = none)
String special, // special model type ("shield", "trident", "chest", "head", …) or null
JsonObject specialModel, // the special model's own fields (chest texture/chest_type, …) or null
Affine specialTransform) {} // item-model transformation for special models (T·Rl·S·Rr) or null
// --- public API --------------------------------------------------------------------------------
@@ -90,7 +98,10 @@ public final class ItemGeometry {
if (info.special != null) bakeSpecial(item, info, m, out);
if (out.size() == before && !info.layers.isEmpty()) bakeGenerated(info, m, out);
if (out.size() == before && item.block() != null) bakeBlock(item.block(), m, out);
if (out.size() == before && item.blockEntity() != null) bakeBlockEntity(item.blockEntity(), m, out);
// Placed block-entity fallback for block items only (a shield carries its patterns as a banner state).
if (out.size() == before && item.block() != null && item.blockEntity() != null) {
bakeBlockEntity(item.blockEntity(), m, out);
}
if (out.size() == before) {
int[][] sprite = sprite(item.id());
if (sprite != null) addExtruded(sprite, m, out);
@@ -130,13 +141,6 @@ public final class ItemGeometry {
return box;
}
/** The display transform's Y scale for a context (vanilla lifts dropped items by 0.25·scaleY). */
public double displayScaleY(ItemSpec item, String context) {
if (item == null) return 1;
Info info = info(item.id(), context);
return info.display == null ? 1 : info.display[7];
}
/** A block's model elements in the block cube [0,1]³ (tinted with plains colours). */
public void bakeBlock(BlockData data, Affine toWorld, List<EntityCube> out) {
if (data == null) return;
@@ -174,30 +178,34 @@ public final class ItemGeometry {
// --- item definition / model resolution --------------------------------------------------------
private Info info(String id, String context) {
return infos.computeIfAbsent(id + "#" + context, k -> {
// Keyed by date too: minecraft:local_time selects (christmas chest items) change with the day.
ZonedDateTime now = SpecialDates.now();
return infos.computeIfAbsent(id + "#" + context + "#" + now.toLocalDate(), k -> {
try {
return resolve(id, context);
return resolve(id, context, now);
} catch (RuntimeException e) {
// Unexpected item-definition format (newer version?): fall back to the plain sprite.
return new Info(null, List.of(), List.of(), null, null);
return new Info(null, List.of(), List.of(), null, null, null);
}
});
}
private Info resolve(String id, String context) {
private Info resolve(String id, String context, ZonedDateTime now) {
String modelRef = null, special = null;
JsonObject specialModel = null;
Affine specialXf = null;
List<Integer> tints = new ArrayList<>();
Optional<JsonObject> def = reader.readJsonObject("assets/minecraft/items/" + id + ".json");
if (def.isPresent() && def.get().has("model")) {
Affine[] outer = {null};
JsonObject node = pick(def.get().getAsJsonObject("model"), context, outer);
JsonObject node = pick(def.get().getAsJsonObject("model"), context, now, outer);
if (node != null) {
String type = str(node, "type");
if (type.endsWith("special")) {
modelRef = str(node, "base");
JsonObject sm = node.has("model") ? node.getAsJsonObject("model") : null;
special = sm == null ? null : str(sm, "type").replace("minecraft:", "");
specialModel = sm;
// Like ItemModel.Unbaked.bake: the transformations of the enclosing select/condition nodes
// compose with the special's own (shield/trident flips, copper golem statue placement).
specialXf = outer[0];
@@ -249,14 +257,14 @@ public final class ItemGeometry {
if (generated) {
for (int i = 0; tex.containsKey("layer" + i); i++) layers.add(resolveTex(tex, tex.get("layer" + i)));
}
return new Info(display, layers, tints, special, specialXf);
return new Info(display, layers, tints, special, specialModel, specialXf);
}
/**
* Walks an item-model node to the concrete model/special for a display context; {@code outer[0]}
* accumulates the {@code transformation}s of the nodes passed on the way (null = none).
*/
private static JsonObject pick(JsonObject node, String context, Affine[] outer) {
private static JsonObject pick(JsonObject node, String context, ZonedDateTime now, Affine[] outer) {
for (int depth = 0; node != null && depth < 16; depth++) {
String type = str(node, "type").replace("minecraft:", "");
if (!type.equals("model") && !type.equals("special") && node.has("transformation")) {
@@ -270,10 +278,14 @@ public final class ItemGeometry {
case "condition" -> node = obj(node, "on_false");
case "select" -> {
JsonObject chosen = null;
if (str(node, "property").endsWith("display_context") && node.has("cases")) {
String property = str(node, "property");
String value = property.endsWith("display_context")
? context
: property.endsWith("local_time") ? localTime(node, now) : null;
if (value != null && node.has("cases")) {
for (JsonElement c : node.getAsJsonArray("cases")) {
JsonObject co = c.getAsJsonObject();
if (matches(co.get("when"), context)) {
if (matches(co.get("when"), value)) {
chosen = obj(co, "model");
break;
}
@@ -304,6 +316,23 @@ public final class ItemGeometry {
return null;
}
/**
* The {@code minecraft:local_time} select value (LocalTime property: SimpleDateFormat {@code pattern} with
* optional {@code locale} and {@code time_zone}) for {@code now}; null when the format is invalid.
*/
private static String localTime(JsonObject node, ZonedDateTime now) {
try {
String locale = str(node, "locale");
SimpleDateFormat f = new SimpleDateFormat(
str(node, "pattern"), locale.isEmpty() ? Locale.ROOT : Locale.forLanguageTag(locale));
String tz = str(node, "time_zone");
f.setTimeZone(tz.isEmpty() ? TimeZone.getTimeZone(now.getZone()) : TimeZone.getTimeZone(tz));
return f.format(Date.from(now.toInstant()));
} catch (RuntimeException e) {
return null;
}
}
private static boolean matches(JsonElement when, String context) {
if (when == null) return false;
if (when.isJsonArray()) {
@@ -384,33 +413,78 @@ public final class ItemGeometry {
// --- geometry ------------------------------------------------------------------------------------
private void bakeSpecial(ItemSpec item, Info info, Affine m, List<EntityCube> out) {
Affine xf = info.specialTransform != null ? m.mul(info.specialTransform) : m;
switch (info.special) {
case "shield", "trident" -> {
// Entity model in Java model space; the item definition's transformation flips it (1,-1,-1).
boolean shield = info.special.equals("shield");
CemModelLoader.CemModel model = models.vanilla(shield ? "layer/shield#main" : "trident");
if (model == null) model = models.vanilla("layer/" + info.special + "#main");
int[][] tex = textures.get(ResourceLocation.parse(
shield ? "entity/shield/shield_base_nopattern" : "entity/trident/trident"))
case "shield" -> {
// ShieldSpecialRenderer: shield_base_nopattern, or (banner patterns / base colour present)
// shield_base + the dyed shield pattern masks (base colour default white); the item definition's
// transformation flips the model (1,-1,-1).
CemModelLoader.CemModel model = models.vanilla("layer/shield#main");
int[][] tex = shieldTexture(item.blockEntity());
if (model != null && tex != null) bakeEntityModel(model, tex, xf, out);
}
case "trident" -> {
CemModelLoader.CemModel model = models.vanilla("trident");
if (model == null) model = models.vanilla("layer/trident#main");
int[][] tex = textures.get(ResourceLocation.parse("entity/trident/trident"))
.orElse(null);
if (model == null || tex == null) return;
Affine xf = info.specialTransform != null ? m.mul(info.specialTransform) : m;
Affine pre = xf.mul(Affine.scale(1 / 16.0)).mul(CemGeometry.CEM_TO_JAVA);
for (CemGeometry.Baked b : CemGeometry.bakeModel(model, tex, pre, Set.of())) {
out.add(new EntityCube(b.from(), b.to(), b.faces(), b.world()));
if (model != null && tex != null) bakeEntityModel(model, tex, xf, out);
}
case "chest" -> {
// ChestSpecialRenderer: the chest model of the item's chest_type with the item definition's
// texture (Sheets.CHEST_MAPPER: entity/chest/<texture>; christmas via the local_time select).
if (!bakeChest(info.specialModel, xf, out) && item.blockEntity() != null && blockEntities != null) {
blockEntities.bakeModel(item.blockEntity(), xf, out);
}
}
default -> {
// Block-entity specials (chest, head, banner, shulker box, conduit, pot, …): like the vanilla
// special renderers, the bare model (no block pose) placed by the item's transformation.
// Block-entity specials (head, banner, shulker box, conduit, pot, …): like the vanilla special
// renderers, the bare model (no block pose) placed by the item's transformation.
if (item.blockEntity() != null && blockEntities != null) {
Affine xf = info.specialTransform != null ? m.mul(info.specialTransform) : m;
blockEntities.bakeModel(item.blockEntity(), xf, out);
}
}
}
}
/** An entity model (Java model space, px) through {@code xf}. */
private static void bakeEntityModel(CemModelLoader.CemModel model, int[][] tex, Affine xf, List<EntityCube> out) {
Affine pre = xf.mul(Affine.scale(1 / 16.0)).mul(CemGeometry.CEM_TO_JAVA);
for (CemGeometry.Baked b : CemGeometry.bakeModel(model, tex, pre, Set.of())) {
out.add(new EntityCube(b.from(), b.to(), b.faces(), b.world()));
}
}
/** The chest special model from its JSON ({@code texture}, {@code chest_type}); false when unresolvable. */
private boolean bakeChest(JsonObject sm, Affine xf, List<EntityCube> out) {
if (sm == null || str(sm, "texture").isEmpty()) return false;
String layer =
switch (str(sm, "chest_type").replace("minecraft:", "")) {
case "left" -> "layer/double_chest_left#main";
case "right" -> "layer/double_chest_right#main";
default -> "layer/chest#main";
};
CemModelLoader.CemModel model = models.vanilla(layer);
ResourceLocation id = ResourceLocation.parse(str(sm, "texture"));
int[][] tex = textures.get(ResourceLocation.parse(id.namespace() + ":entity/chest/" + id.path()))
.orElse(null);
if (model == null || tex == null) return false;
bakeEntityModel(model, tex, xf, out);
return true;
}
/** The shield texture for the stack's patterns ({@code BANNER} state from the item meta; null = none). */
private int[][] shieldTexture(BlockEntityState patterns) {
boolean patterned = patterns != null
&& (patterns.baseColorArgb() != 0 || !patterns.patterns().isEmpty());
int[][] base = textures.get(ResourceLocation.parse(
patterned ? "entity/shield/shield_base" : "entity/shield/shield_base_nopattern"))
.orElse(null);
if (!patterned || base == null || blockEntities == null) return base;
int baseColor = patterns.baseColorArgb() != 0 ? patterns.baseColorArgb() : ColorUtil.dyeArgb(DyeColor.WHITE, 0);
return blockEntities.patterned(base, "entity/shield/", baseColor, patterns.patterns());
}
private void bakeGenerated(Info info, Affine m, List<EntityCube> out) {
// Cached per Info (one per item+context): a stable texture identity keeps the extrusion cache bounded.
int[][] composed = composedSprites
@@ -44,6 +44,7 @@ import org.bukkit.entity.EntitySnapshot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.ShieldMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerProfile;
import org.bukkit.util.Vector;
@@ -130,6 +131,41 @@ public final class BlockEntitySnapshotBuilder {
return s;
}
/**
* A shield's banner data (ShieldMeta: base colour + patterns) as a {@code BANNER} state at cell 0 for the
* shield special model; null without patterns and base colour (plain shield).
*/
public static BlockEntityState shieldPatterns(ItemMeta meta) {
try {
if (!(meta instanceof ShieldMeta shield)) return null;
DyeColor baseColor = shield.getBaseColor();
List<BannerPattern> pats = new ArrayList<>();
for (Pattern p : shield.getPatterns()) {
pats.add(new BannerPattern(patternKey(p), ColorUtil.dyeArgb(p.getColor(), 0xFFFFFFFF)));
}
if (baseColor == null && pats.isEmpty()) return null;
return new BlockEntityState(
Kind.BANNER,
0,
0,
0,
0,
null,
false,
null,
ColorUtil.dyeArgb(baseColor, 0),
null,
null,
null,
pats,
List.of(),
null,
null);
} catch (Throwable ignored) {
return null; // API drift: plain shield
}
}
private static BlockEntityState copy(BlockEntityState s, String skinUrl, List<BannerPattern> patterns) {
return new BlockEntityState(
s.kind(),
@@ -77,7 +77,8 @@ public final class DecorationSnapshotBuilder {
map,
frame.getRotation().ordinal(),
glow,
!frame.isVisible());
!frame.isVisible(),
map != null ? MapPixels.markers(stack) : List.of());
}
return null;
}
@@ -33,6 +33,9 @@ public final class ItemSpecs {
// Head skins / banner patterns live on the stack, not the material (only those kinds pay for the meta).
if (be != null && ("player".equals(be.headType()) || be.kind() == BlockEntityState.Kind.BANNER)) {
be = BlockEntitySnapshotBuilder.withItemMeta(be, stack.getItemMeta());
} else if (m == Material.SHIELD) {
// Shield banner patterns + base colour (ShieldSpecialRenderer), carried as a BANNER state.
be = BlockEntitySnapshotBuilder.shieldPatterns(stack.getItemMeta());
}
return new ItemSpec(m.getKey().getKey(), b.data, be, glint);
}
@@ -1,9 +1,13 @@
package eu.mhsl.minecraft.pixelpics.render.snapshot;
import eu.mhsl.minecraft.pixelpics.render.entity.DecorationState;
import eu.mhsl.minecraft.pixelpics.utils.ImageMapRenderer;
import eu.mhsl.minecraft.pixelpics.utils.MapColorPalette;
import eu.mhsl.minecraft.pixelpics.utils.MapManager;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.map.MapRenderer;
@@ -59,17 +63,65 @@ public final class MapPixels {
return b;
}
private static volatile Field worldMapField, colorsField;
/**
* The map's decorations an item frame shows (MapRenderer with showOnlyFrame: MapDecorationType.showOnItemFrame
* — banners, frame markers, structure/target markers; never players), in the map data's order. Only for maps
* drawn by the vanilla renderer (CraftMapRenderer sends {@code MapItemSavedData.decorations} as cursors):
* PixelPics photo maps and other plugin-rendered maps get none.
*/
public static List<DecorationState.MapMarker> markers(ItemStack stack) {
try {
if (!(stack.getItemMeta() instanceof MapMeta meta) || !meta.hasMapView()) return List.of();
MapView view = meta.getMapView();
if (view == null || MapManager.isManaged(view.getId())) return List.of();
boolean vanilla = false;
for (MapRenderer r : view.getRenderers()) {
if (r instanceof ImageMapRenderer) return List.of();
if (r.getClass().getSimpleName().equals("CraftMapRenderer")) vanilla = true;
}
if (!vanilla) return List.of();
Object data = worldMap(view);
if (data == null) return List.of();
Field f = decorationsField;
if (f == null || f.getDeclaringClass() != data.getClass()) {
f = data.getClass().getDeclaredField("decorations");
f.setAccessible(true);
decorationsField = f;
}
if (!(f.get(data) instanceof Map<?, ?> decorations) || decorations.isEmpty()) return List.of();
List<DecorationState.MapMarker> out = new ArrayList<>();
for (Object d : decorations.values()) {
Class<?> c = d.getClass();
if (!(Boolean) c.getMethod("renderOnFrame").invoke(d)) continue;
String sprite = String.valueOf(c.getMethod("getSpriteLocation").invoke(d));
String asset = sprite.substring(sprite.indexOf(':') + 1);
out.add(new DecorationState.MapMarker(
asset,
(Byte) c.getMethod("x").invoke(d),
(Byte) c.getMethod("y").invoke(d),
(Byte) c.getMethod("rot").invoke(d)));
}
return out;
} catch (Throwable t) {
return List.of();
}
}
/** CraftMapView#worldMap → MapItemSavedData#colors (what the vanilla CraftMapRenderer sends). */
private static byte[] worldMapColors(MapView view) throws ReflectiveOperationException {
private static volatile Field worldMapField, colorsField, decorationsField;
private static Object worldMap(MapView view) throws ReflectiveOperationException {
Field wm = worldMapField;
if (wm == null || wm.getDeclaringClass() != view.getClass()) {
wm = view.getClass().getDeclaredField("worldMap");
wm.setAccessible(true);
worldMapField = wm;
}
Object data = wm.get(view);
return wm.get(view);
}
/** CraftMapView#worldMap → MapItemSavedData#colors (what the vanilla CraftMapRenderer sends). */
private static byte[] worldMapColors(MapView view) throws ReflectiveOperationException {
Object data = worldMap(view);
if (data == null) return null;
Field c = colorsField;
if (c == null || c.getDeclaringClass() != data.getClass()) {
@@ -70,7 +70,8 @@ public final class ObjectSnapshotBuilder {
}
if (d instanceof ItemDisplay id) {
String ctx = id.getItemDisplayTransform().name().toLowerCase(java.util.Locale.ROOT);
return item(base, id.getItemStack(), ctx, false);
// ItemDisplayRenderer.submitInner turns the item by 180° about Y before submitting it.
return item(base.mul(Affine.rotY(Math.PI)), id.getItemStack(), ctx, false);
}
if (d instanceof TextDisplay td) {
return text(base, td);
@@ -84,8 +85,10 @@ public final class ObjectSnapshotBuilder {
return block(at.mul(Affine.translation(-0.5, 0, -0.5)), Material.TNT.createBlockData());
}
if (e instanceof Item it) {
// Dropped item: vanilla GROUND display transform, lifted by the baker; a fixed per-entity spin.
double spin = (e.getUniqueId().getLeastSignificantBits() & 0xFFFF) / 65536.0 * 2 * Math.PI;
// Dropped item: vanilla GROUND display transform, lifted by the baker. The spin (vanilla: age/20 +
// a random bobOffset) is frozen per entity from its yaw, which ItemEntity also randomises at creation
// (so items differ like in vanilla, and a test can fix it with setRotation).
double spin = Math.toRadians(l.getYaw());
return item(at.mul(Affine.rotY(spin)), it.getItemStack(), "ground", true);
}
if (e instanceof Minecart mc) {
@@ -0,0 +1,44 @@
package eu.mhsl.minecraft.pixelpics.render.util;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.MonthDay;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
/**
* Vanilla {@code net.minecraft.util.SpecialDates} (decompiled 26.3): the server's local date decides the
* christmas chest textures (ChestRenderer.xmasTextures = {@code isExtendedChristmas()}, 24–26 December) and the
* {@code minecraft:local_time} item-model property (chest / trapped chest items).
*
* <p>Testing: the JVM system property {@value #TEST_DATE_PROPERTY} ({@code yyyy-MM-dd}, e.g.
* {@code -Dpixelpics.testDate=2026-12-25}) replaces today's date (time of day stays the current one). Never set
* it in production.
*/
public final class SpecialDates {
public static final String TEST_DATE_PROPERTY = "pixelpics.testDate";
private static final List<MonthDay> CHRISTMAS_RANGE =
List.of(MonthDay.of(12, 24), MonthDay.of(12, 25), MonthDay.of(12, 26));
private SpecialDates() {}
/** The current local date-time ({@code ZonedDateTime.now()}), or the test date at the current time of day. */
public static ZonedDateTime now() {
ZonedDateTime now = ZonedDateTime.now();
String test = System.getProperty(TEST_DATE_PROPERTY);
if (test == null || test.isBlank()) return now;
try {
return ZonedDateTime.of(LocalDate.parse(test.trim()), LocalTime.from(now), ZoneId.systemDefault());
} catch (RuntimeException e) {
return now;
}
}
/** Vanilla {@code SpecialDates.isExtendedChristmas()}: today is 24, 25 or 26 December. */
public static boolean isExtendedChristmas() {
return CHRISTMAS_RANGE.contains(MonthDay.from(now()));
}
}