Merge pull request #547 from Online5277/fix/banner-item-components
Fix Ominous Banner data, tooltips and breaking effects
This commit is contained in:
@@ -199,6 +199,14 @@ pub fn dye_rgb(name: &str) -> u32 {
|
||||
pub fn layers(stack: &ItemStack) -> &[BannerLayer] {
|
||||
stack.data().map_or(&[], |d| &d.banner_patterns)
|
||||
}
|
||||
/// The ominous banner's component patch hides its pattern tooltip.
|
||||
pub fn tooltip_layers(stack: &ItemStack) -> &[BannerLayer] {
|
||||
if stack.data().is_some_and(|d| d.ominous_banner) {
|
||||
&[]
|
||||
} else {
|
||||
layers(stack)
|
||||
}
|
||||
}
|
||||
/// `LoomMenu.setupResultSlot`: one banner with the pattern added in the dye colour.
|
||||
pub fn loom_result(banner: &ItemStack, dye: &str, pattern: &str) -> ItemStack {
|
||||
let mut result = ItemStack {
|
||||
@@ -302,6 +310,24 @@ mod tests {
|
||||
}
|
||||
assert!(has_max_layers(&banner));
|
||||
}
|
||||
#[test]
|
||||
fn ominous_banner_hides_tooltip_layers_but_keeps_its_patterns() {
|
||||
let mut banner = crate::mobs::raider::ominous_banner();
|
||||
(banner.damage, banner.extra) = crate::item_data::decode_components(
|
||||
crate::item_data::encode_components(&banner).as_ref(),
|
||||
);
|
||||
assert_eq!(
|
||||
layers(&banner).len(),
|
||||
crate::item_data::OMINOUS_LAYERS.len()
|
||||
);
|
||||
assert!(tooltip_layers(&banner).is_empty());
|
||||
banner.data_mut().custom_name = Some("Captain's Standard".into());
|
||||
assert!(tooltip_layers(&banner).is_empty());
|
||||
banner.data_mut().ominous_banner = false;
|
||||
assert_eq!(tooltip_layers(&banner), layers(&banner));
|
||||
assert!(!tooltip_layers(&banner).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layers_round_trip_through_nbt() {
|
||||
let l = vec![
|
||||
|
||||
@@ -876,7 +876,7 @@ impl BlockEntityRenderer {
|
||||
.as_vec3();
|
||||
let base = Mat4::from_translation(origin);
|
||||
let packed = scene.world.light(pos[0], pos[1], pos[2]);
|
||||
self.render_one(scene, *pos, kind, base, packed, lights, out);
|
||||
self.render_one(scene, *pos, kind, base, packed, lights, false, out);
|
||||
}
|
||||
}
|
||||
/// One block entity at `pos` drawn under `base` with the given packed light
|
||||
@@ -892,12 +892,39 @@ impl BlockEntityRenderer {
|
||||
) {
|
||||
let kind = self.kind(state);
|
||||
let lights = diffuse_lights(scene.nether);
|
||||
self.render_one(scene, pos, kind, base, packed, lights, out);
|
||||
self.render_one(scene, pos, kind, base, packed, lights, false, out);
|
||||
}
|
||||
/// Whether this block state has a block-entity renderer here.
|
||||
pub fn renders(&self, state: u32) -> bool {
|
||||
!matches!(self.kind(state), Kind::None)
|
||||
}
|
||||
/// BannerRenderer submits the support and animated flag once for crumbling.
|
||||
pub fn render_banner_breaking(
|
||||
&self,
|
||||
scene: &Scene,
|
||||
pos: [i32; 3],
|
||||
state: u32,
|
||||
out: &mut Vec<Vertex>,
|
||||
) {
|
||||
if !matches!(self.kind(state), Kind::Banner { .. }) {
|
||||
return;
|
||||
}
|
||||
let origin = (DVec3::new(f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2]))
|
||||
- scene.camera)
|
||||
.as_vec3();
|
||||
let start = out.len();
|
||||
self.render_one(
|
||||
scene,
|
||||
pos,
|
||||
self.kind(state),
|
||||
Mat4::from_translation(origin),
|
||||
0xff,
|
||||
diffuse_lights(scene.nether),
|
||||
true,
|
||||
out,
|
||||
);
|
||||
crate::breaking::entity_geometry(&mut out[start..], origin);
|
||||
}
|
||||
/// `ChestRenderer.extractRenderState`'s openness for the chest of `state`
|
||||
/// at `pos`: `ChestBlock.combine` (`DoubleBlockCombiner.combineWithNeigbour`)
|
||||
/// pairs a double half with its neighbour only when that is the same
|
||||
@@ -970,7 +997,7 @@ impl BlockEntityRenderer {
|
||||
let kind = self.kind(state);
|
||||
if !matches!(kind, Kind::None) {
|
||||
let lights = diffuse_lights(scene.nether);
|
||||
self.render_one(scene, [i32::MAX; 3], kind, base, packed, lights, out);
|
||||
self.render_one(scene, [i32::MAX; 3], kind, base, packed, lights, false, out);
|
||||
}
|
||||
}
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -982,11 +1009,24 @@ impl BlockEntityRenderer {
|
||||
base: Mat4,
|
||||
packed: u8,
|
||||
lights: (Vec3, Vec3),
|
||||
crumbling: bool,
|
||||
out: &mut Vec<Vertex>,
|
||||
) {
|
||||
let sprite = |name: &str| scene.sprites.get(name).copied();
|
||||
let paint = |name: &str, tint: u32, packed: u8| {
|
||||
sprite(name).map(|s| Paint {
|
||||
let rect = if crumbling {
|
||||
Some(Rect {
|
||||
u0: 0.0,
|
||||
v0: 0.0,
|
||||
u1: 1.0,
|
||||
v1: 1.0,
|
||||
w: 16,
|
||||
h: 16,
|
||||
})
|
||||
} else {
|
||||
sprite(name)
|
||||
};
|
||||
rect.map(|s| Paint {
|
||||
sprite: s,
|
||||
tint,
|
||||
light: vertex_light(packed),
|
||||
@@ -1145,6 +1185,10 @@ impl BlockEntityRenderer {
|
||||
draw_part(main, "root", m, &none, paint, out);
|
||||
draw_part(flag, "root", m, &wave, paint, out);
|
||||
}
|
||||
// Pattern passes must not multiply the crumbling decal.
|
||||
if crumbling {
|
||||
return;
|
||||
}
|
||||
// BannerRenderer.submitPatterns: the base pattern layer in the dye colour,
|
||||
// then up to 16 pattern layers in order.
|
||||
if let Some(paint) = paint("entity/banner/base", *color, packed) {
|
||||
@@ -1673,6 +1717,109 @@ fn portal_cube(m: Mat4, faces: &[Direction], layer: u32, out: &mut Vec<Vertex>)
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
#[ignore = "requires prepared models/textures in HORIZON_TEST_RESOURCES"]
|
||||
fn banner_particle_and_breaking_use_exported_models() -> crate::Result<()> {
|
||||
use crate::{models::catalog::StateModels, sprites::Sprites};
|
||||
use horizon_world::{DATA_VERSION, chunk::BlockState, nbt::Tag};
|
||||
let root = std::path::PathBuf::from(
|
||||
std::env::var_os("HORIZON_TEST_RESOURCES").expect("HORIZON_TEST_RESOURCES"),
|
||||
);
|
||||
let names = ["white_banner", "white_wall_banner"];
|
||||
let mut facts: std::collections::BTreeMap<String, Value> =
|
||||
serde_json::from_slice(&std::fs::read(root.join("model-states.json"))?)?;
|
||||
let states = names.map(|name| {
|
||||
let name = format!("minecraft:{name}");
|
||||
let first = facts[&name]["states"][0].clone();
|
||||
facts.get_mut(&name).unwrap()["states"] = serde_json::json!([first.clone()]);
|
||||
BlockState {
|
||||
name,
|
||||
properties: serde_json::from_value(first).unwrap(),
|
||||
}
|
||||
.to_nbt()
|
||||
});
|
||||
let registry = BlockRegistry::from_nbt(&Tag::compound([
|
||||
("DataVersion", Tag::Int(DATA_VERSION)),
|
||||
("states", Tag::List(states.into())),
|
||||
(
|
||||
"defaults",
|
||||
Tag::compound([
|
||||
("minecraft:white_banner", Tag::Int(0)),
|
||||
("minecraft:white_wall_banner", Tag::Int(1)),
|
||||
]),
|
||||
),
|
||||
]))?;
|
||||
let mut sprites = Sprites::default();
|
||||
let catalog = StateModels::from_facts(&root, ®istry, &names, &mut sprites, &facts)?;
|
||||
for id in 0..2 {
|
||||
let models = catalog.collect(
|
||||
BlockStateId(id),
|
||||
horizon_core::position::BlockPos::default(),
|
||||
)?;
|
||||
assert!(models.iter().all(|(_, model)| model.faces.is_empty()));
|
||||
assert_eq!(
|
||||
models[0].1.particle,
|
||||
Some(sprites.layers["minecraft:block/oak_planks"])
|
||||
);
|
||||
}
|
||||
let all: Value = serde_json::from_slice(&std::fs::read(root.join("entity-models.json"))?)?;
|
||||
let renderer = BlockEntityRenderer::new(
|
||||
MODELS
|
||||
.iter()
|
||||
.filter_map(|(key, layer)| all.get(*layer).map(|v| (*key, ModelPart::parse(v))))
|
||||
.collect(),
|
||||
®istry,
|
||||
);
|
||||
let world = World::new(BlockStateId(0), 1);
|
||||
let base_sprites = HashMap::from([(
|
||||
"entity/banner/banner_base".to_owned(),
|
||||
Rect {
|
||||
u0: 0.0,
|
||||
v0: 0.0,
|
||||
u1: 1.0,
|
||||
v1: 1.0,
|
||||
w: 16,
|
||||
h: 16,
|
||||
},
|
||||
)]);
|
||||
let mut scene = Scene {
|
||||
camera: DVec3::ZERO,
|
||||
orientation: Quat::IDENTITY,
|
||||
anim: &|_| BlockAnim::default(),
|
||||
texts: None,
|
||||
partial: 0.5,
|
||||
game_time: 0,
|
||||
max_y: 320,
|
||||
world: &world,
|
||||
sprites: &base_sprites,
|
||||
nether: false,
|
||||
lid: &|_| 0.0,
|
||||
sign: &|_| None,
|
||||
banner: &|_| Vec::new(),
|
||||
glyph: &|_| (None, 0.0),
|
||||
};
|
||||
for state in 0..2 {
|
||||
let mut base = Vec::new();
|
||||
renderer.render_block(&scene, [0; 3], state, Mat4::IDENTITY, 0xff, &mut base);
|
||||
let mut cracks = Vec::new();
|
||||
renderer.render_banner_breaking(&scene, [0; 3], state, &mut cracks);
|
||||
assert!(!cracks.is_empty());
|
||||
assert_eq!(
|
||||
base.iter().map(|v| v.pos).collect::<Vec<_>>(),
|
||||
cracks.iter().map(|v| v.pos).collect::<Vec<_>>()
|
||||
);
|
||||
assert!(cracks.iter().all(|v| v.layer == 11
|
||||
&& v.color == u32::MAX
|
||||
&& v.uv.iter().all(|u| u.is_finite())));
|
||||
scene.game_time = 20;
|
||||
let mut animated = Vec::new();
|
||||
renderer.render_banner_breaking(&scene, [0; 3], state, &mut animated);
|
||||
assert!(cracks.iter().zip(&animated).any(|(a, b)| a.pos != b.pos));
|
||||
scene.game_time = 0;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classifies_vanilla_block_names() {
|
||||
let props = |pairs: &'static [(&'static str, &'static str)]| {
|
||||
|
||||
@@ -41,6 +41,35 @@ pub fn geometry(model: &BakedModel, origin: glam::Vec3, translucent: bool, out:
|
||||
}
|
||||
}
|
||||
|
||||
/// Project a block entity's transformed quads onto the same destroy-stage pass.
|
||||
pub fn entity_geometry(vertices: &mut [Vertex], origin: glam::Vec3) {
|
||||
for quad in vertices.as_chunks_mut::<4>().0 {
|
||||
let positions = [0, 1, 2].map(|i| glam::Vec3::from(quad[i].pos));
|
||||
let normal = (positions[1] - positions[0]).cross(positions[2] - positions[0]);
|
||||
let mut facing = Direction::North;
|
||||
let mut best = f32::from_bits(1);
|
||||
for (direction, dot) in [
|
||||
(Direction::Down, -normal.y),
|
||||
(Direction::Up, normal.y),
|
||||
(Direction::North, -normal.z),
|
||||
(Direction::South, normal.z),
|
||||
(Direction::West, -normal.x),
|
||||
(Direction::East, normal.x),
|
||||
] {
|
||||
if dot > best {
|
||||
facing = direction;
|
||||
best = dot;
|
||||
}
|
||||
}
|
||||
for vertex in quad {
|
||||
vertex.uv = decal_uv((glam::Vec3::from(vertex.pos) - origin).to_array(), facing);
|
||||
vertex.layer = 11;
|
||||
vertex.color = 0xffff_ffff;
|
||||
vertex.light = 240 | (240 << 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -49,6 +78,7 @@ mod tests {
|
||||
fn slab_top() -> BakedModel {
|
||||
BakedModel {
|
||||
ambient_occlusion: true,
|
||||
particle: None,
|
||||
cube: None,
|
||||
faces: vec![BakedFace {
|
||||
layer: 0,
|
||||
@@ -86,6 +116,24 @@ mod tests {
|
||||
assert_eq!(v.color, 0xffff_ffff);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn entity_overlay_uses_block_local_projected_uvs() {
|
||||
let origin = glam::Vec3::new(12.0, -3.0, 8.0);
|
||||
let mut expected = Vec::new();
|
||||
geometry(&slab_top(), origin, false, &mut expected);
|
||||
let mut actual = expected.clone();
|
||||
for vertex in &mut actual {
|
||||
vertex.uv = [0.0; 2];
|
||||
vertex.layer = 0;
|
||||
vertex.color = 0;
|
||||
}
|
||||
entity_geometry(&mut actual, origin);
|
||||
assert_eq!(
|
||||
bytemuck::cast_slice::<_, u8>(&actual),
|
||||
bytemuck::cast_slice::<_, u8>(&expected)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn small_faces_use_projected_not_stretched_uvs() {
|
||||
let a = decal_uv([0.0, 0.0, 0.0], Direction::North);
|
||||
|
||||
@@ -132,6 +132,8 @@ impl Crafter {
|
||||
pub struct Banner {
|
||||
pub layers: Vec<crate::banner::BannerLayer>,
|
||||
pub name: Option<String>,
|
||||
/// Components not consumed by BannerBlockEntity's implicit fields.
|
||||
pub components: horizon_world::nbt::Compound,
|
||||
}
|
||||
/// `CreakingHeartBlockEntity` (the logic is in `game/creaking.rs`).
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
||||
@@ -1449,9 +1449,13 @@ impl Game<'_> {
|
||||
.iter()
|
||||
.flat_map(|(_, m)| m.faces.iter())
|
||||
.find(|f| f.quad.facing == horizon_assets::model::Direction::Up)
|
||||
.or_else(|| models.iter().flat_map(|(_, m)| m.faces.iter()).next())?;
|
||||
let name = self.pack.layer_names.get(&face.layer)?.clone();
|
||||
let tint = if face.quad.tint_index >= 0 {
|
||||
.or_else(|| models.iter().flat_map(|(_, m)| m.faces.iter()).next());
|
||||
// Entity-rendered blocks may have a particle texture without any faces.
|
||||
let layer = face
|
||||
.map(|face| face.layer)
|
||||
.or_else(|| models.iter().find_map(|(_, model)| model.particle))?;
|
||||
let name = self.pack.layer_names.get(&layer)?.clone();
|
||||
let tint = if face.is_some_and(|face| face.quad.tint_index >= 0) {
|
||||
let n = &self.res.facts.get(state).name;
|
||||
if n.contains("leaves") || n.contains("vine") {
|
||||
0x48B518
|
||||
@@ -5581,6 +5585,20 @@ impl Game<'_> {
|
||||
.block_entity_render
|
||||
.render(&scene, visible, &mut out);
|
||||
}
|
||||
if let Some(mining) = &self.mining
|
||||
&& mining.progress > 0.0
|
||||
&& self.atlas.sprites.contains_key(&format!(
|
||||
"block/destroy_stage_{}",
|
||||
((mining.progress * 10.0) as u32).min(9)
|
||||
))
|
||||
{
|
||||
let state = self
|
||||
.world
|
||||
.block(mining.pos[0], mining.pos[1], mining.pos[2]);
|
||||
self.res
|
||||
.block_entity_render
|
||||
.render_banner_breaking(&scene, mining.pos, state.0, &mut out);
|
||||
}
|
||||
}
|
||||
// Experience orbs (ExperienceOrbRenderer): pulsing billboards from a 4x4 icon sheet.
|
||||
if let Some(r) = self
|
||||
@@ -8066,7 +8084,7 @@ impl Game<'_> {
|
||||
self.creative_screen.search_focused.elapsed().as_millis(),
|
||||
);
|
||||
}
|
||||
let mut hovered: Option<String> = None;
|
||||
let mut hovered: Option<ItemStack> = None;
|
||||
if tab.inventory {
|
||||
self.draw_player_preview(
|
||||
batch,
|
||||
@@ -8116,7 +8134,7 @@ impl Game<'_> {
|
||||
&& self.cursor.1 < y + 16.0
|
||||
{
|
||||
batch.fill(&self.atlas, x, y, 16.0, 16.0, rgba(255, 255, 255, 128));
|
||||
hovered = Some(stack.item.to_string());
|
||||
hovered = Some(stack.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8131,7 +8149,7 @@ impl Game<'_> {
|
||||
&& self.cursor.1 >= y
|
||||
&& self.cursor.1 < y + 16.0
|
||||
{
|
||||
hovered = Some(stack.item.to_string());
|
||||
hovered = Some(stack);
|
||||
}
|
||||
}
|
||||
let scrollable = self.creative_screen.rows(&self.pack.names) > 5;
|
||||
@@ -8167,8 +8185,8 @@ impl Game<'_> {
|
||||
} else if self.carried.is_none()
|
||||
&& let Some(item) = hovered
|
||||
{
|
||||
let name = self.pack.names.item(&item);
|
||||
self.tooltip(batch, &name, self.cursor.0, self.cursor.1);
|
||||
let lines = self.stack_tooltip(&item);
|
||||
self.draw_tooltip_lines(batch, &lines, self.cursor.0, self.cursor.1);
|
||||
}
|
||||
self.draw_inventory_effects(batch, (ox, oy), Creative::WIDTH as i32);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
use super::{Game, GameLevel, Screen, dispenser::new_item_motion, storage::is_shulker_box};
|
||||
use horizon_client::{
|
||||
containers::{Banner, BlockEntity},
|
||||
item_data,
|
||||
items::ItemStack,
|
||||
};
|
||||
use horizon_core::position::BlockPos;
|
||||
@@ -15,6 +16,7 @@ use horizon_world::{
|
||||
LevelEvent,
|
||||
removal::{self, PreRemove},
|
||||
},
|
||||
nbt::{JavaString, Tag},
|
||||
registry::BlockStateId,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
@@ -80,14 +82,37 @@ impl Pending {
|
||||
stack.data_mut().pot_decorations = Some(Box::new(sides));
|
||||
}
|
||||
if stack.item.ends_with("_banner")
|
||||
&& let Some(Banner { layers, name }) = self.banner.remove(&pos)
|
||||
&& let Some(Banner {
|
||||
layers,
|
||||
name,
|
||||
components,
|
||||
}) = self.banner.remove(&pos)
|
||||
{
|
||||
let data = stack.data_mut();
|
||||
data.banner_patterns = layers;
|
||||
if name.is_some() {
|
||||
data.custom_name = name;
|
||||
let mut patch = match item_data::encode_components(stack) {
|
||||
Some(Tag::Compound(c)) => c,
|
||||
_ => Default::default(),
|
||||
};
|
||||
// The remaining components in the banner loot table's copy_components.
|
||||
for key in [
|
||||
"minecraft:item_name",
|
||||
"minecraft:rarity",
|
||||
"minecraft:tooltip_display",
|
||||
] {
|
||||
if let Some(value) = components.get(&JavaString::from(key)) {
|
||||
patch.insert(key.into(), value.clone());
|
||||
}
|
||||
}
|
||||
stack.tidy();
|
||||
patch.insert(
|
||||
"minecraft:banner_patterns".into(),
|
||||
horizon_client::banner::layers_to_nbt(&layers),
|
||||
);
|
||||
if let Some(name) = name {
|
||||
patch.insert(
|
||||
"minecraft:custom_name".into(),
|
||||
Tag::String(name.as_str().into()),
|
||||
);
|
||||
}
|
||||
(stack.damage, stack.extra) = item_data::decode_components(Some(&Tag::Compound(patch)));
|
||||
}
|
||||
}
|
||||
/// Remember a decorated pot's sherds from its saved block entity.
|
||||
@@ -553,3 +578,49 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use horizon_client::{block_entity_item, item_data, mobs::raider, save};
|
||||
use horizon_world::nbt::Tag;
|
||||
|
||||
#[test]
|
||||
fn ominous_banner_survives_placement_save_and_drop() {
|
||||
let original = raider::ominous_banner();
|
||||
let Tag::Compound(components) = item_data::encode_components(&original).unwrap() else {
|
||||
panic!("banner components");
|
||||
};
|
||||
for block in ["minecraft:white_banner", "minecraft:white_wall_banner"] {
|
||||
let pos = (1, 64, 2);
|
||||
let fresh = BlockEntity::for_block(block).unwrap();
|
||||
let fresh = save::encode_block_entity(pos, &fresh, block);
|
||||
let placed = block_entity_item::place(&fresh, &components, false);
|
||||
let (_, placed) = save::decode_block_entity(&placed).unwrap();
|
||||
let saved = save::encode_block_entity(pos, &placed, block);
|
||||
let (_, loaded) = save::decode_block_entity(&saved).unwrap();
|
||||
let BlockEntity::Banner(banner) = &loaded else {
|
||||
panic!("placed banner");
|
||||
};
|
||||
assert_eq!(banner.layers.len(), item_data::OMINOUS_LAYERS.len());
|
||||
let mut pending = Pending::default();
|
||||
pending.record([pos.0, pos.1, pos.2], &loaded, block, None);
|
||||
let mut dropped = ItemStack::new("minecraft:white_banner", 1);
|
||||
pending.attach([pos.0, pos.1, pos.2], &mut dropped);
|
||||
assert!(dropped.data().unwrap().ominous_banner);
|
||||
assert!(horizon_client::banner::tooltip_layers(&dropped).is_empty());
|
||||
assert_eq!(
|
||||
horizon_client::item_tooltip::name_line(&dropped, &|_| None),
|
||||
"Ominous Banner"
|
||||
);
|
||||
assert_eq!(
|
||||
horizon_client::item_tooltip::rarity(&dropped, "common"),
|
||||
"uncommon"
|
||||
);
|
||||
assert_eq!(
|
||||
item_data::encode_components(&dropped),
|
||||
Some(Tag::Compound(components.clone()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1860,18 +1860,10 @@ impl Game<'_> {
|
||||
pub(super) fn stack_tooltip(&self, stack: &ItemStack) -> Vec<(String, u32)> {
|
||||
let e: &Enchantments = &self.res.stations.enchantments;
|
||||
let props = e.props(&stack.item);
|
||||
let mut rarity = props.map_or("common", |p| p.rarity.as_str());
|
||||
// The ominous banner's rarity component.
|
||||
if stack.data().is_some_and(|d| d.ominous_banner) {
|
||||
rarity = "uncommon";
|
||||
}
|
||||
if !stack.enchantments().is_empty() {
|
||||
rarity = match rarity {
|
||||
"common" | "uncommon" => "rare",
|
||||
"rare" => "epic",
|
||||
r => r,
|
||||
};
|
||||
}
|
||||
let rarity = horizon_client::item_tooltip::rarity(
|
||||
stack,
|
||||
props.map_or("common", |p| p.rarity.as_str()),
|
||||
);
|
||||
let color = match rarity {
|
||||
"uncommon" => rgba(255, 255, 85, 255),
|
||||
"rare" => rgba(85, 255, 255, 255),
|
||||
@@ -1952,7 +1944,7 @@ impl Game<'_> {
|
||||
));
|
||||
}
|
||||
// BannerPatternLayers.addToTooltip: up to six layer names.
|
||||
for layer in horizon_client::banner::layers(stack).iter().take(6) {
|
||||
for layer in horizon_client::banner::tooltip_layers(stack).iter().take(6) {
|
||||
let key = self.res.stations.banners.layer_key(layer);
|
||||
lines.push((self.translate(&key, &key), rgba(170, 170, 170, 255)));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use horizon_client::{
|
||||
hud::HudBatch,
|
||||
hud_layout,
|
||||
hud_overlays::HeldName,
|
||||
item_tooltip,
|
||||
text::{self, Text},
|
||||
};
|
||||
|
||||
@@ -24,22 +25,14 @@ impl Game<'_> {
|
||||
fn held_name(&self) -> Option<HeldName> {
|
||||
let stack = self.inventory.get(self.selected)?.as_ref()?;
|
||||
let custom = stack.custom_name();
|
||||
// ItemStack.getRarity: enchanting raises common and uncommon to rare
|
||||
// and rare to epic.
|
||||
let mut rarity = self.item_rarity(&stack.item);
|
||||
if !stack.enchantments().is_empty() {
|
||||
rarity = match rarity.as_str() {
|
||||
"common" | "uncommon" => "rare".into(),
|
||||
"rare" => "epic".into(),
|
||||
_ => rarity,
|
||||
};
|
||||
}
|
||||
let default_rarity = self.item_rarity(&stack.item);
|
||||
let rarity = item_tooltip::rarity(stack, &default_rarity);
|
||||
Some(HeldName {
|
||||
item: stack.item.to_string(),
|
||||
hover_name: Text::literal(
|
||||
custom.map_or_else(|| self.pack.names.item(&stack.item), str::to_owned),
|
||||
),
|
||||
rarity_color: match rarity.as_str() {
|
||||
hover_name: Text::literal(item_tooltip::name_line(stack, &|key| {
|
||||
self.pack.names.get(key).map(str::to_owned)
|
||||
})),
|
||||
rarity_color: match rarity {
|
||||
"uncommon" => text::YELLOW,
|
||||
"rare" => text::AQUA,
|
||||
"epic" => text::LIGHT_PURPLE,
|
||||
|
||||
@@ -102,6 +102,10 @@ pub fn name_line(stack: &ItemStack, translate: &dyn Fn(&str) -> Option<String>)
|
||||
if let Some(name) = stack.custom_name() {
|
||||
return name.to_owned();
|
||||
}
|
||||
if stack.data().is_some_and(|d| d.ominous_banner) {
|
||||
return translate("block.minecraft.ominous_banner")
|
||||
.unwrap_or_else(|| "Ominous Banner".to_owned());
|
||||
}
|
||||
let key = if is_potion_item(&stack.item) {
|
||||
Some(crate::brewing::potion_name_key(&stack.item, stack.potion()))
|
||||
} else if let Some(pattern) = path.strip_suffix("_armor_trim_smithing_template") {
|
||||
@@ -120,6 +124,24 @@ pub fn name_line(stack: &ItemStack, translate: &dyn Fn(&str) -> Option<String>)
|
||||
.unwrap_or_else(|| path.replace('_', " "))
|
||||
}
|
||||
|
||||
/// ItemStack.getRarity: the ominous banner override, then the enchantment upgrade.
|
||||
pub fn rarity<'a>(stack: &ItemStack, default: &'a str) -> &'a str {
|
||||
let rarity = if stack.data().is_some_and(|d| d.ominous_banner) {
|
||||
"uncommon"
|
||||
} else {
|
||||
default
|
||||
};
|
||||
if stack.enchantments().is_empty() {
|
||||
rarity
|
||||
} else {
|
||||
match rarity {
|
||||
"common" | "uncommon" => "rare",
|
||||
"rare" => "epic",
|
||||
r => r,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The lines of `stack` below its name that its components give, in
|
||||
/// `ItemStack.addDetailsToTooltip` order.
|
||||
pub fn detail_lines(
|
||||
@@ -292,6 +314,26 @@ pub fn lines(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn ominous_banner_name_and_rarity_use_the_stack() {
|
||||
let translate = |key: &str| match key {
|
||||
"block.minecraft.ominous_banner" => Some("Ominous Banner".to_owned()),
|
||||
"block.minecraft.white_banner" => Some("White Banner".to_owned()),
|
||||
_ => None,
|
||||
};
|
||||
let mut banner = crate::mobs::raider::ominous_banner();
|
||||
assert_eq!(name_line(&banner, &translate), "Ominous Banner");
|
||||
assert_eq!(name_line(&banner, &|_| None), "Ominous Banner");
|
||||
assert_eq!(rarity(&banner, "common"), "uncommon");
|
||||
banner.data_mut().custom_name = Some("Captain's Standard".into());
|
||||
assert_eq!(name_line(&banner, &translate), "Captain's Standard");
|
||||
banner.enchant("minecraft:unbreaking", 1);
|
||||
assert_eq!(rarity(&banner, "common"), "rare");
|
||||
let plain = ItemStack::new("minecraft:white_banner", 1);
|
||||
assert_eq!(name_line(&plain, &translate), "White Banner");
|
||||
assert_eq!(rarity(&plain, "common"), "common");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn container_lines_list_five_stacks_then_how_many_more() {
|
||||
let mut chest = ItemStack::new("minecraft:chest", 1);
|
||||
|
||||
@@ -34,6 +34,8 @@ pub struct BakedFace {
|
||||
}
|
||||
pub struct BakedModel {
|
||||
pub ambient_occlusion: bool,
|
||||
/// The model's particle slot also exists for models without block faces.
|
||||
pub particle: Option<u32>,
|
||||
pub faces: Vec<BakedFace>,
|
||||
pub cube: Option<[super::cube::CubeStyle; 6]>,
|
||||
}
|
||||
@@ -190,6 +192,10 @@ impl StateModels {
|
||||
let mut baked = BTreeMap::new();
|
||||
for (name, turns, lock) in variants {
|
||||
let model = library.resolve(&name)?;
|
||||
let particle = model
|
||||
.material("particle")?
|
||||
.map(|material| sprites.insert(root, &material.sprite))
|
||||
.transpose()?;
|
||||
let faces: Vec<BakedFace> =
|
||||
bake_block_model(&model, BlockModelTransform::new(turns, lock))?
|
||||
.into_iter()
|
||||
@@ -209,6 +215,7 @@ impl StateModels {
|
||||
(name, turns, lock),
|
||||
BakedModel {
|
||||
ambient_occlusion: model.ambient_occlusion,
|
||||
particle,
|
||||
faces,
|
||||
cube,
|
||||
},
|
||||
|
||||
@@ -449,13 +449,17 @@ pub fn encode_block_entity(
|
||||
block: &str,
|
||||
) -> Tag {
|
||||
use crate::containers::BlockEntity;
|
||||
let components = match e {
|
||||
BlockEntity::Banner(b) => b.components.clone(),
|
||||
_ => Compound::new(),
|
||||
};
|
||||
let mut entries = vec![
|
||||
("id", string(&block_entity_id(e, block))),
|
||||
("x", Tag::Int(p.0)),
|
||||
("y", Tag::Int(p.1)),
|
||||
("z", Tag::Int(p.2)),
|
||||
("keepPacked", Tag::Byte(0)),
|
||||
("components", Tag::Compound(Compound::new())),
|
||||
("components", Tag::Compound(components)),
|
||||
];
|
||||
match e {
|
||||
BlockEntity::Chest(items) => entries.push(("Items", encode_items(items))),
|
||||
@@ -583,6 +587,10 @@ pub fn decode_block_entity(tag: &Tag) -> Option<((i32, i32, i32), crate::contain
|
||||
BlockEntity::Banner(crate::containers::Banner {
|
||||
layers: crate::banner::layers_from_nbt(tag.get("patterns")),
|
||||
name: text(tag.get("CustomName")),
|
||||
components: match tag.get("components") {
|
||||
Some(Tag::Compound(c)) => c.clone(),
|
||||
_ => Compound::new(),
|
||||
},
|
||||
}),
|
||||
));
|
||||
}
|
||||
@@ -2985,6 +2993,7 @@ mod tests {
|
||||
let banner = crate::containers::Banner {
|
||||
layers: vec![crate::banner::BannerLayer::new("minecraft:creeper", "lime")],
|
||||
name: Some("Flag".into()),
|
||||
components: [("minecraft:rarity".into(), string("uncommon"))].into(),
|
||||
};
|
||||
let tag = encode_block_entity(
|
||||
(1, 2, 3),
|
||||
@@ -2998,6 +3007,7 @@ mod tests {
|
||||
};
|
||||
assert_eq!(back.layers, banner.layers);
|
||||
assert_eq!(back.name, banner.name);
|
||||
assert_eq!(back.components, banner.components);
|
||||
}
|
||||
use super::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user