Merge main and preserve resource reload and Mods screen tests
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)]
|
||||
|
||||
@@ -68,6 +68,7 @@ impl Corner {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Extras {
|
||||
pub fullbright: bool,
|
||||
pub zoom: bool,
|
||||
/// A vanilla key name (`key.keyboard.z`).
|
||||
pub zoom_key: String,
|
||||
@@ -108,6 +109,7 @@ pub struct Extras {
|
||||
impl Default for Extras {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
fullbright: false,
|
||||
zoom: false,
|
||||
zoom_key: "key.keyboard.z".into(),
|
||||
zoom_level: 4,
|
||||
@@ -155,6 +157,7 @@ impl Extras {
|
||||
_ => d,
|
||||
};
|
||||
match key.trim() {
|
||||
"fullbright" => e.fullbright = flag(e.fullbright),
|
||||
"zoom" => e.zoom = flag(e.zoom),
|
||||
"zoomKey" if value.starts_with("key.") => e.zoom_key = value.to_owned(),
|
||||
"zoomLevel" => {
|
||||
@@ -198,7 +201,8 @@ impl Extras {
|
||||
}
|
||||
pub fn serialize(&self) -> String {
|
||||
format!(
|
||||
"zoom:{}\nzoomKey:{}\nzoomLevel:{}\nzoomSmooth:{}\nzoomSensitivity:{}\nfps:{}\nfpsCorner:{}\nfpsLows:{}\nkeystrokes:{}\nkeystrokesCorner:{}\nkeystrokesCps:{}\nminimap:{}\nminimapCorner:{}\nminimapSize:{}\nminimapShape:{}\nminimapZoom:{}\nminimapRotate:{}\nautoReconnect:{}\nmouseTweaks:{}\nmouseTweaksWheel:{}\nsort:{}\nsortKey:{}\n",
|
||||
"fullbright:{}\nzoom:{}\nzoomKey:{}\nzoomLevel:{}\nzoomSmooth:{}\nzoomSensitivity:{}\nfps:{}\nfpsCorner:{}\nfpsLows:{}\nkeystrokes:{}\nkeystrokesCorner:{}\nkeystrokesCps:{}\nminimap:{}\nminimapCorner:{}\nminimapSize:{}\nminimapShape:{}\nminimapZoom:{}\nminimapRotate:{}\nautoReconnect:{}\nmouseTweaks:{}\nmouseTweaksWheel:{}\nsort:{}\nsortKey:{}\n",
|
||||
bool_text(self.fullbright),
|
||||
bool_text(self.zoom),
|
||||
self.zoom_key,
|
||||
self.zoom_level,
|
||||
@@ -418,6 +422,7 @@ impl Cps {
|
||||
/// The settings the Extras page shows, one per row.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Item {
|
||||
Fullbright,
|
||||
Zoom,
|
||||
ZoomKey,
|
||||
ZoomLevel,
|
||||
@@ -445,6 +450,8 @@ pub enum Item {
|
||||
pub fn rows() -> Vec<Result<Item, &'static str>> {
|
||||
use Item::*;
|
||||
vec![
|
||||
Err("Lighting"),
|
||||
Ok(Fullbright),
|
||||
Err("Zoom"),
|
||||
Ok(Zoom),
|
||||
Ok(ZoomKey),
|
||||
@@ -493,6 +500,7 @@ fn next<T: Copy + PartialEq>(all: &[T], current: T, back: bool) -> T {
|
||||
impl Item {
|
||||
pub fn caption(self) -> &'static str {
|
||||
match self {
|
||||
Item::Fullbright => "Fullbright",
|
||||
Item::Zoom => "Zoom",
|
||||
Item::ZoomKey => "Zoom key",
|
||||
Item::ZoomLevel => "Starting zoom",
|
||||
@@ -518,6 +526,7 @@ impl Item {
|
||||
/// What the row says under its caption.
|
||||
pub fn description(self) -> &'static str {
|
||||
match self {
|
||||
Item::Fullbright => "Show blocks and entities at full light, even in dark areas.",
|
||||
Item::Zoom => "Hold the zoom key to zoom; the wheel changes it while held.",
|
||||
Item::ZoomKey => "Click, then press a key. Escape unbinds it.",
|
||||
Item::ZoomLevel => "The zoom the key starts at.",
|
||||
@@ -556,7 +565,7 @@ impl Item {
|
||||
pub fn cost(self) -> Option<crate::graphics_style::Cost> {
|
||||
use crate::graphics_style::Cost;
|
||||
match self {
|
||||
Item::Zoom | Item::Fps | Item::Keystrokes => Some(Cost::None),
|
||||
Item::Fullbright | Item::Zoom | Item::Fps | Item::Keystrokes => Some(Cost::None),
|
||||
Item::Minimap => Some(Cost::Low),
|
||||
Item::AutoReconnect | Item::MouseTweaks | Item::Sort => Some(Cost::None),
|
||||
_ => None,
|
||||
@@ -565,6 +574,7 @@ impl Item {
|
||||
/// On/off items and their value.
|
||||
pub fn switch(self, e: &Extras) -> Option<bool> {
|
||||
Some(match self {
|
||||
Item::Fullbright => e.fullbright,
|
||||
Item::Zoom => e.zoom,
|
||||
Item::ZoomSmooth => e.zoom_smooth,
|
||||
Item::ZoomSensitivity => e.zoom_sensitivity,
|
||||
@@ -606,6 +616,7 @@ impl Item {
|
||||
/// A click (`back` for the right button). The zoom key binds instead.
|
||||
pub fn cycle(self, e: &mut Extras, back: bool) {
|
||||
match self {
|
||||
Item::Fullbright => e.fullbright = !e.fullbright,
|
||||
Item::Zoom => e.zoom = !e.zoom,
|
||||
Item::ZoomSmooth => e.zoom_smooth = !e.zoom_smooth,
|
||||
Item::ZoomSensitivity => e.zoom_sensitivity = !e.zoom_sensitivity,
|
||||
@@ -651,11 +662,14 @@ mod tests {
|
||||
#[test]
|
||||
fn everything_is_off_by_default_and_round_trips() {
|
||||
let d = Extras::default();
|
||||
assert!(!d.fullbright);
|
||||
assert!(!d.zoom && !d.fps && !d.keystrokes && !d.minimap && !d.auto_reconnect);
|
||||
assert!(!d.mouse_tweaks && !d.sort);
|
||||
assert_eq!(Extras::parse(""), d);
|
||||
assert_eq!(Extras::parse(&d.serialize()), d);
|
||||
let mut e = d.clone();
|
||||
Item::Fullbright.cycle(&mut e, false);
|
||||
assert_eq!(Item::Fullbright.switch(&e), Some(true));
|
||||
e.zoom = true;
|
||||
e.zoom_key = "key.keyboard.c".into();
|
||||
e.zoom_level = 6;
|
||||
|
||||
@@ -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
|
||||
@@ -1779,6 +1783,12 @@ impl Game<'_> {
|
||||
});
|
||||
self.process_level_events()
|
||||
}
|
||||
fn attack_block(&mut self, pos: [i32; 3]) -> Result<()> {
|
||||
self.with_level(|b, level, ticks| {
|
||||
b.attack_block(level, ticks, BlockPos::new(pos[0], pos[1], pos[2]));
|
||||
});
|
||||
self.process_level_events()
|
||||
}
|
||||
/// Track which chunks are ticking (Ticks needs chunk load/unload).
|
||||
fn sync_tick_chunks(&mut self) {
|
||||
if !self.tick_chunks.synchronize(&self.world.chunks) {
|
||||
@@ -2887,6 +2897,7 @@ impl Game<'_> {
|
||||
return Ok(());
|
||||
}
|
||||
if self.mining.as_ref().is_none_or(|m| m.pos != hit.pos) {
|
||||
self.attack_block(hit.pos)?;
|
||||
self.mining = Some(Mining {
|
||||
pos: hit.pos,
|
||||
progress: 0.0,
|
||||
@@ -4338,14 +4349,7 @@ impl Game<'_> {
|
||||
} else {
|
||||
("Crafting", 97.0)
|
||||
};
|
||||
batch.text(
|
||||
atlas,
|
||||
title,
|
||||
ox + tx,
|
||||
oy + if self.craft_size == 3 { 6.0 } else { 8.0 },
|
||||
grey,
|
||||
false,
|
||||
);
|
||||
batch.text(atlas, title, ox + tx, oy + 6.0, grey, false);
|
||||
if self.craft_size == 3 {
|
||||
batch.text(atlas, "Inventory", ox + 8.0, oy + 72.0, grey, false);
|
||||
}
|
||||
@@ -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
|
||||
@@ -8074,7 +8092,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,
|
||||
@@ -8124,7 +8142,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8139,7 +8157,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;
|
||||
@@ -8175,8 +8193,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);
|
||||
}
|
||||
@@ -9359,6 +9377,9 @@ impl ApplicationHandler for Game<'_> {
|
||||
}
|
||||
WindowEvent::MouseInput { state, button, .. } => {
|
||||
let pressed = state == ElementState::Pressed;
|
||||
if pressed && self.sort_mouse_press(button) {
|
||||
return Ok(());
|
||||
}
|
||||
match self.screen {
|
||||
Screen::Playing => {
|
||||
if pressed && !self.captured {
|
||||
|
||||
@@ -29,7 +29,7 @@ const HELP: &[&str] = &[
|
||||
"chat TEXT send a chat line or /command as if typed",
|
||||
"type TEXT type into the open chat box (key enter tap sends)",
|
||||
"chat-log [N] the newest N chat messages (default 10)",
|
||||
"options [PAGE] open the options (video sound controls keybinds mouse chat accessibility language font packs graphics graphics-advanced)",
|
||||
"options [PAGE] open the options (video sound controls keybinds mouse chat accessibility language font packs mods graphics graphics-advanced)",
|
||||
"stats [reset] frame-time summary since the last reset",
|
||||
"bench SECONDS reset stats, wait, then reply with the summary",
|
||||
"fly X1 Y1 Z1 X2 Y2 Z2 SECONDS [PITCH [raw]] fly the camera along a line at constant speed, then reply with the frame summary (raw: every frame time too)",
|
||||
@@ -462,8 +462,10 @@ impl Game<'_> {
|
||||
"language" => Page::Language,
|
||||
"font" => Page::Font,
|
||||
"packs" => Page::Packs,
|
||||
"mods" => Page::Mods,
|
||||
"graphics" => Page::Graphics,
|
||||
"graphics-advanced" => Page::GraphicsAdvanced,
|
||||
"extras" => Page::Extras,
|
||||
other => return Err(format!("unknown options page {other}").into()),
|
||||
};
|
||||
if self.screen == Screen::Playing && self.title.is_none() {
|
||||
|
||||
@@ -58,8 +58,12 @@ impl Game<'_> {
|
||||
pub(super) fn extras_scroll(&mut self, steps: f32) -> bool {
|
||||
self.settings.extras.zoom && self.extras.zoom.scroll(steps)
|
||||
}
|
||||
/// Mouse buttons while playing, for the keystroke overlay.
|
||||
/// Mouse buttons while playing, for zoom and the keystroke overlay.
|
||||
pub(super) fn extras_mouse(&mut self, button: MouseButton, pressed: bool) {
|
||||
let e = &self.settings.extras;
|
||||
if e.zoom && e.zoom_key == keybinds::mouse_name(button) {
|
||||
self.extras.zoom.key(pressed, false, true, e.zoom_level);
|
||||
}
|
||||
let i = match button {
|
||||
MouseButton::Left => 0,
|
||||
MouseButton::Right => 1,
|
||||
|
||||
@@ -409,7 +409,10 @@ impl HandWorld for GameHands<'_, '_> {
|
||||
fn within_border(&mut self, _: [i32; 3]) -> bool {
|
||||
true
|
||||
}
|
||||
fn attack_block(&mut self, _: [i32; 3]) {}
|
||||
fn attack_block(&mut self, pos: [i32; 3]) {
|
||||
let result = self.game.attack_block(pos);
|
||||
self.keep(result);
|
||||
}
|
||||
fn destroy_progress(&mut self, pos: [i32; 3]) -> f32 {
|
||||
self.game.destroy_progress(pos)
|
||||
}
|
||||
|
||||
@@ -186,16 +186,11 @@ impl Game<'_> {
|
||||
}
|
||||
/// Mouse buttons pressed while a key is being bound.
|
||||
pub(super) fn options_waiting_for_key(&self) -> bool {
|
||||
self.ui.options.selected_key.is_some() && self.ui.options.page() == Page::KeyBinds
|
||||
self.ui.options.selected_key.is_some()
|
||||
}
|
||||
pub(super) fn options_bind_mouse(&mut self, button: MouseButton) -> Result<()> {
|
||||
if let Some(name) = self.ui.options.selected_key.take() {
|
||||
self.settings
|
||||
.keys
|
||||
.set(name, &horizon_client::keybinds::mouse_name(button));
|
||||
self.handle_option_events(vec![Event::Changed])?;
|
||||
}
|
||||
Ok(())
|
||||
let events = self.ui.options.bind_mouse(&mut self.settings, button);
|
||||
self.handle_option_events(events)
|
||||
}
|
||||
pub(super) fn handle_option_events(&mut self, events: Vec<Event>) -> Result<()> {
|
||||
for e in events {
|
||||
@@ -245,6 +240,7 @@ impl Game<'_> {
|
||||
let s = &self.settings;
|
||||
if let Some(r) = self.renderer.as_mut() {
|
||||
r.gamma = s.gamma;
|
||||
r.fullbright = s.extras.fullbright;
|
||||
r.set_present_mode(s.vsync, s.horizon.present_mode);
|
||||
r.animated_textures = s.horizon.animated_textures;
|
||||
r.set_mipmap_levels(s.mipmap_levels.max(0) as u32);
|
||||
|
||||
@@ -427,7 +427,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// `extractEntityInInventoryFollowsMouse`: the player in the box
|
||||
/// `[x0, x1) x [y0, y1)`, `size` pixels per block, turned toward the
|
||||
/// cursor; drawn as depth-sorted, back-face-culled quads.
|
||||
/// cursor; drawn with a depth buffer and back-face culling.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn draw_player_preview(
|
||||
&self,
|
||||
@@ -495,9 +495,9 @@ impl Game<'_> {
|
||||
let quads = player_preview_quads(verts, gui, fire, &atlas.sprites);
|
||||
let start = batch.vertices.len();
|
||||
for (_, p, uv, color) in quads {
|
||||
batch.quad(p, uv, color);
|
||||
batch.quad_3d(p, uv, color);
|
||||
}
|
||||
batch.clip_since(start, x0, y0, x1, y1);
|
||||
batch.depth_since(start, [x0, y0, x1, y1]);
|
||||
}
|
||||
/// The survival inventory's player box (`InventoryScreen`).
|
||||
pub(super) fn draw_inventory_player(&self, batch: &mut HudBatch, ox: f32, oy: f32) {
|
||||
@@ -570,7 +570,7 @@ fn player_preview_quads(
|
||||
gui: glam::Mat4,
|
||||
fire: Option<(f32, f32)>,
|
||||
sprites: &std::collections::HashMap<String, horizon_client::hud::Rect>,
|
||||
) -> Vec<(f32, [[f32; 2]; 4], [[f32; 2]; 4], u32)> {
|
||||
) -> Vec<(f32, [[f32; 3]; 4], [[f32; 2]; 4], u32)> {
|
||||
let flame_start = verts.len();
|
||||
if let Some((width, height)) = fire {
|
||||
horizon_client::fire_render::flames(
|
||||
@@ -584,7 +584,7 @@ fn player_preview_quads(
|
||||
&mut verts,
|
||||
);
|
||||
}
|
||||
let mut quads: Vec<(f32, [[f32; 2]; 4], [[f32; 2]; 4], u32)> = Vec::new();
|
||||
let mut quads: Vec<(f32, [[f32; 3]; 4], [[f32; 2]; 4], u32)> = Vec::new();
|
||||
for (index, q) in verts.as_chunks::<4>().0.iter().enumerate() {
|
||||
let p: [glam::Vec3; 4] =
|
||||
std::array::from_fn(|i| gui.transform_point3(glam::Vec3::from_array(q[i].pos)));
|
||||
@@ -606,12 +606,12 @@ fn player_preview_quads(
|
||||
let depth = p.iter().map(|v| v.z).sum::<f32>() / 4.0;
|
||||
quads.push((
|
||||
depth,
|
||||
p.map(|v| [v.x, v.y]),
|
||||
p.map(|v| v.to_array()),
|
||||
std::array::from_fn(|i| q[i].uv),
|
||||
color,
|
||||
));
|
||||
}
|
||||
// Far (low z) first: the viewer is on the +z side.
|
||||
// Keep far-to-near order for translucent faces; opaque overlap uses depth.
|
||||
quads.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
quads
|
||||
}
|
||||
@@ -619,6 +619,60 @@ fn player_preview_quads(
|
||||
#[cfg(test)]
|
||||
mod preview_tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn preview_keeps_crossing_faces_depth_and_clips_without_dropping_faces() {
|
||||
use horizon_client::{
|
||||
hud::{Blend, HudBatch},
|
||||
mesher::Vertex,
|
||||
};
|
||||
let face = |z: [f32; 4]| {
|
||||
[[-2.0, -1.0], [-2.0, 1.0], [2.0, 1.0], [2.0, -1.0]]
|
||||
.into_iter()
|
||||
.zip(z)
|
||||
.map(|([x, y], z)| Vertex {
|
||||
pos: [x, y, z],
|
||||
uv: [0.0; 2],
|
||||
layer: 0,
|
||||
color: u32::MAX,
|
||||
light: 0,
|
||||
normal: [0; 4],
|
||||
})
|
||||
};
|
||||
// A shield and arm can intersect: neither average depth orders both ends.
|
||||
let verts = face([1.0, 1.0, -1.0, -1.0]).chain(face([0.0; 4])).collect();
|
||||
let quads = player_preview_quads(verts, glam::Mat4::IDENTITY, None, &Default::default());
|
||||
assert_eq!(quads.len(), 2);
|
||||
let mut batch = HudBatch::new([320, 240]);
|
||||
for (_, p, uv, color) in quads {
|
||||
batch.quad_3d(p, uv, color);
|
||||
}
|
||||
// Its centre is outside this scissor; the visible part must still be drawn.
|
||||
batch.depth_since(0, [1.0, 0.0, 2.0, 1.0]);
|
||||
assert_eq!(batch.vertices.len(), 12);
|
||||
let shield = &batch.vertices[..6];
|
||||
let arm = &batch.vertices[6..];
|
||||
assert!(shield[0].depth < arm[0].depth);
|
||||
assert!(shield[2].depth > arm[2].depth);
|
||||
assert_eq!(batch.runs(), vec![(0..12, Blend::Depth([1, 0, 1, 1]))]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires prepared model data in HORIZON_TEST_RESOURCES"]
|
||||
fn player_render_transform_uses_vanilla_avatar_scale() {
|
||||
let root = std::path::PathBuf::from(
|
||||
std::env::var_os("HORIZON_TEST_RESOURCES").expect("HORIZON_TEST_RESOURCES"),
|
||||
);
|
||||
let mut m = Mob::new(1, player_type(&root).unwrap(), Vec3::ZERO, 0.0);
|
||||
for (id, expected) in [("minecraft:player", 0.9375), ("minecraft:zombie", 1.0)] {
|
||||
Arc::make_mut(&mut m.kind).id = id.into();
|
||||
let transform =
|
||||
horizon_client::mobs::render::base_transform_at(&m, 1.0, glam::Mat4::IDENTITY);
|
||||
for axis in [glam::Vec3::X, glam::Vec3::Y, glam::Vec3::Z] {
|
||||
assert!((transform.transform_vector3(axis).length() - expected).abs() < 1e-6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn burning_inventory_preview_keeps_visible_fullbright_flames() {
|
||||
let rect = |u0| horizon_client::hud::Rect {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -28,7 +28,7 @@ use horizon_client::{
|
||||
menu::Input,
|
||||
stations::hover_name,
|
||||
};
|
||||
use winit::keyboard::KeyCode;
|
||||
use winit::{event::MouseButton, keyboard::KeyCode};
|
||||
|
||||
/// A sort button's side in GUI pixels.
|
||||
const SORT_BUTTON: f32 = 9.0;
|
||||
@@ -377,8 +377,14 @@ impl Game<'_> {
|
||||
/// The sort key: sorts the part under the cursor (the container when
|
||||
/// the cursor is over no slot).
|
||||
pub(super) fn sort_key_press(&mut self, key: KeyCode) -> bool {
|
||||
keybinds::key_name(key).is_some_and(|name| self.sort_input(name))
|
||||
}
|
||||
pub(super) fn sort_mouse_press(&mut self, button: MouseButton) -> bool {
|
||||
self.sort_input(&keybinds::mouse_name(button))
|
||||
}
|
||||
fn sort_input(&mut self, name: &str) -> bool {
|
||||
let e = &self.settings.extras;
|
||||
if !e.sort || keybinds::key_code(&e.sort_key) != Some(key) || self.recipe_search_focused() {
|
||||
if !e.sort || e.sort_key != name || self.recipe_search_focused() {
|
||||
return false;
|
||||
}
|
||||
let buttons = self.sort_buttons();
|
||||
|
||||
@@ -349,6 +349,8 @@ pub struct Renderer {
|
||||
pub screenshot_result: Option<std::result::Result<[u32; 2], String>>,
|
||||
/// Brightness option (lightmap gamma), 0..1.
|
||||
pub gamma: f32,
|
||||
/// Optional full-light lightmap (Horizon Extras).
|
||||
pub fullbright: bool,
|
||||
/// Advance animated block textures (Horizon setting; vanilla always does).
|
||||
pub animated_textures: bool,
|
||||
present_modes: Vec<wgpu::PresentMode>,
|
||||
@@ -1637,6 +1639,7 @@ impl Renderer {
|
||||
screenshot: None,
|
||||
screenshot_result: None,
|
||||
gamma: 0.5,
|
||||
fullbright: false,
|
||||
animated_textures: true,
|
||||
present_modes,
|
||||
})
|
||||
@@ -2009,6 +2012,9 @@ impl Renderer {
|
||||
pixels[i + 3] = 255;
|
||||
}
|
||||
}
|
||||
if self.fullbright {
|
||||
pixels.fill(255);
|
||||
}
|
||||
// The lightmap changes with the time of day, flicker and effects,
|
||||
// not every frame: upload only what differs from the texture.
|
||||
if pixels == self.lightmap_pixels && self.lightmap_uploaded {
|
||||
@@ -2811,6 +2817,7 @@ impl Renderer {
|
||||
&mut self.uploads,
|
||||
&mut encoder,
|
||||
&view_target,
|
||||
&self.depth,
|
||||
frame.hud,
|
||||
[self.config.width, self.config.height],
|
||||
);
|
||||
|
||||
@@ -349,6 +349,7 @@ pub struct HudVertex {
|
||||
pub pos: [f32; 2],
|
||||
pub uv: [f32; 2],
|
||||
pub color: u32,
|
||||
pub depth: f32,
|
||||
}
|
||||
/// The GUI Scale option (0 = auto).
|
||||
pub static GUI_SCALE: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
@@ -360,10 +361,10 @@ pub struct HudBatch {
|
||||
pub height: f32,
|
||||
/// Glyph pixels to upload into the atlas before drawing.
|
||||
pub patches: Vec<crate::font::Patch>,
|
||||
/// Vertex ranges drawn with another blend than alpha blending, in order.
|
||||
/// Vertex ranges with another blend or depth/scissor state, in order.
|
||||
pub blends: Vec<(std::ops::Range<u32>, Blend)>,
|
||||
}
|
||||
/// How a run of HUD vertices blends with what is under it.
|
||||
/// How a run of HUD vertices blends and tests depth.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum Blend {
|
||||
/// `BlendFunction.TRANSLUCENT`.
|
||||
@@ -372,6 +373,8 @@ pub enum Blend {
|
||||
Invert,
|
||||
/// `BlendFunction.ADDITIVE` (`RenderPipelines.GUI_TEXT_HIGHLIGHT`).
|
||||
Additive,
|
||||
/// Alpha blending with an isolated depth buffer and a pixel scissor.
|
||||
Depth([u32; 4]),
|
||||
}
|
||||
pub fn rgba(r: u8, g: u8, b: u8, a: u8) -> u32 {
|
||||
u32::from(a) << 24 | u32::from(b) << 16 | u32::from(g) << 8 | u32::from(r)
|
||||
@@ -460,9 +463,44 @@ impl HudBatch {
|
||||
pos: p[i],
|
||||
uv: uv[i],
|
||||
color,
|
||||
depth: 0.0,
|
||||
});
|
||||
}
|
||||
}
|
||||
pub fn quad_3d(&mut self, p: [[f32; 3]; 4], uv: [[f32; 2]; 4], color: u32) {
|
||||
for i in [0, 1, 2, 0, 2, 3] {
|
||||
self.vertices.push(HudVertex {
|
||||
pos: [p[i][0], p[i][1]],
|
||||
uv: uv[i],
|
||||
color,
|
||||
depth: p[i][2],
|
||||
});
|
||||
}
|
||||
}
|
||||
/// Keep per-vertex depth for an orthographic GUI model, with +z toward the viewer.
|
||||
pub fn depth_since(&mut self, start: usize, clip: [f32; 4]) {
|
||||
let vertices = &mut self.vertices[start..];
|
||||
if vertices.is_empty() {
|
||||
return;
|
||||
}
|
||||
let min = vertices
|
||||
.iter()
|
||||
.map(|v| v.depth)
|
||||
.fold(f32::INFINITY, f32::min);
|
||||
let max = vertices
|
||||
.iter()
|
||||
.map(|v| v.depth)
|
||||
.fold(f32::NEG_INFINITY, f32::max);
|
||||
for v in vertices {
|
||||
v.depth = (max - v.depth) / (max - min).max(f32::EPSILON);
|
||||
}
|
||||
let [x0, y0, x1, y1] = clip.map(|v| (v * self.scale).max(0.0) as u32);
|
||||
// Separate previews clear depth independently, even if their scissors match.
|
||||
self.blends.push((
|
||||
start as u32..self.vertices.len() as u32,
|
||||
Blend::Depth([x0, y0, x1.saturating_sub(x0), y1.saturating_sub(y0)]),
|
||||
));
|
||||
}
|
||||
pub fn rect_uv(&mut self, x: f32, y: f32, w: f32, h: f32, r: Rect, color: u32) {
|
||||
self.quad(
|
||||
[[x, y], [x + w, y], [x + w, y + h], [x, y + h]],
|
||||
@@ -599,6 +637,7 @@ impl HudBatch {
|
||||
pos: p[i],
|
||||
uv,
|
||||
color: c[i],
|
||||
depth: 0.0,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -759,6 +798,7 @@ pub struct HudRenderer {
|
||||
/// `RenderPipelines.CROSSHAIR`.
|
||||
invert_pipeline: wgpu::RenderPipeline,
|
||||
additive_pipeline: wgpu::RenderPipeline,
|
||||
depth_pipeline: wgpu::RenderPipeline,
|
||||
group: wgpu::BindGroup,
|
||||
uniform: wgpu::Buffer,
|
||||
buffer: wgpu::Buffer,
|
||||
@@ -838,8 +878,8 @@ impl HudRenderer {
|
||||
bind_group_layouts: &[Some(&layout)],
|
||||
..Default::default()
|
||||
});
|
||||
let attributes = wgpu::vertex_attr_array![0=>Float32x2,1=>Float32x2,2=>Unorm8x4];
|
||||
let create = |label, blend, fragment_entry| {
|
||||
let attributes = wgpu::vertex_attr_array![0=>Float32x2,1=>Float32x2,2=>Unorm8x4,3=>Float32];
|
||||
let create = |label, blend, fragment_entry, depth: bool| {
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some(label),
|
||||
layout: Some(&pipeline_layout),
|
||||
@@ -854,7 +894,13 @@ impl HudRenderer {
|
||||
})],
|
||||
},
|
||||
primitive: Default::default(),
|
||||
depth_stencil: None,
|
||||
depth_stencil: depth.then_some(wgpu::DepthStencilState {
|
||||
format: wgpu::TextureFormat::Depth32Float,
|
||||
depth_write_enabled: Some(true),
|
||||
depth_compare: Some(wgpu::CompareFunction::LessEqual),
|
||||
stencil: Default::default(),
|
||||
bias: Default::default(),
|
||||
}),
|
||||
multisample: Default::default(),
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &shader,
|
||||
@@ -870,7 +916,13 @@ impl HudRenderer {
|
||||
cache: None,
|
||||
})
|
||||
};
|
||||
let pipeline = create("HUD", wgpu::BlendState::ALPHA_BLENDING, "fs_main");
|
||||
let pipeline = create("HUD", wgpu::BlendState::ALPHA_BLENDING, "fs_main", false);
|
||||
let depth_pipeline = create(
|
||||
"HUD model",
|
||||
wgpu::BlendState::ALPHA_BLENDING,
|
||||
"fs_main",
|
||||
true,
|
||||
);
|
||||
// BlendFunction.INVERT: ONE_MINUS_DST_COLOR, ONE_MINUS_SRC_COLOR,
|
||||
// ONE, ZERO.
|
||||
let invert_pipeline = create(
|
||||
@@ -888,6 +940,7 @@ impl HudRenderer {
|
||||
},
|
||||
},
|
||||
"fs_crosshair",
|
||||
false,
|
||||
);
|
||||
// BlendFunction.ADDITIVE: ONE, ONE.
|
||||
let add = wgpu::BlendComponent {
|
||||
@@ -902,6 +955,7 @@ impl HudRenderer {
|
||||
alpha: add,
|
||||
},
|
||||
"fs_main",
|
||||
false,
|
||||
);
|
||||
let capacity = 1 << 16;
|
||||
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
@@ -916,6 +970,7 @@ impl HudRenderer {
|
||||
pipeline,
|
||||
invert_pipeline,
|
||||
additive_pipeline,
|
||||
depth_pipeline,
|
||||
group,
|
||||
uniform,
|
||||
buffer,
|
||||
@@ -965,6 +1020,7 @@ impl HudRenderer {
|
||||
uploads: &mut crate::gfx::upload::Uploads,
|
||||
encoder: &mut wgpu::CommandEncoder,
|
||||
target: &wgpu::TextureView,
|
||||
depth: &wgpu::TextureView,
|
||||
batch: &HudBatch,
|
||||
size: [u32; 2],
|
||||
) {
|
||||
@@ -995,7 +1051,7 @@ impl HudRenderer {
|
||||
);
|
||||
}
|
||||
}
|
||||
if batch.vertices.is_empty() {
|
||||
if batch.vertices.is_empty() || size.contains(&0) {
|
||||
return;
|
||||
}
|
||||
let count = batch.vertices.len() as u64;
|
||||
@@ -1031,20 +1087,55 @@ impl HudRenderer {
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})];
|
||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("HUD"),
|
||||
color_attachments: &attachments,
|
||||
..Default::default()
|
||||
});
|
||||
pass.set_bind_group(0, &self.group, &[]);
|
||||
pass.set_vertex_buffer(0, self.buffer.slice(..));
|
||||
for (range, blend) in batch.runs() {
|
||||
pass.set_pipeline(match blend {
|
||||
Blend::Alpha => &self.pipeline,
|
||||
Blend::Invert => &self.invert_pipeline,
|
||||
Blend::Additive => &self.additive_pipeline,
|
||||
let runs = batch.runs();
|
||||
let mut at = 0;
|
||||
while at < runs.len() {
|
||||
let clip = match runs[at].1 {
|
||||
Blend::Depth(clip) => Some(clip),
|
||||
_ => None,
|
||||
};
|
||||
let end = if clip.is_some() {
|
||||
at + 1
|
||||
} else {
|
||||
runs[at..]
|
||||
.iter()
|
||||
.position(|(_, b)| matches!(b, Blend::Depth(_)))
|
||||
.map_or(runs.len(), |n| at + n)
|
||||
};
|
||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("HUD"),
|
||||
color_attachments: &attachments,
|
||||
depth_stencil_attachment: clip.map(|_| wgpu::RenderPassDepthStencilAttachment {
|
||||
view: depth,
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(1.0),
|
||||
store: wgpu::StoreOp::Discard,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
..Default::default()
|
||||
});
|
||||
pass.draw(range, 0..1);
|
||||
pass.set_bind_group(0, &self.group, &[]);
|
||||
pass.set_vertex_buffer(0, self.buffer.slice(..));
|
||||
if let Some([x, y, w, h]) = clip {
|
||||
let (x, y) = (x.min(size[0]), y.min(size[1]));
|
||||
let (w, h) = (w.min(size[0] - x), h.min(size[1] - y));
|
||||
if w == 0 || h == 0 {
|
||||
at = end;
|
||||
continue;
|
||||
}
|
||||
pass.set_scissor_rect(x, y, w, h);
|
||||
}
|
||||
for (range, blend) in &runs[at..end] {
|
||||
pass.set_pipeline(match blend {
|
||||
Blend::Alpha => &self.pipeline,
|
||||
Blend::Invert => &self.invert_pipeline,
|
||||
Blend::Additive => &self.additive_pipeline,
|
||||
Blend::Depth(_) => &self.depth_pipeline,
|
||||
});
|
||||
pass.draw(range.clone(), 0..1);
|
||||
}
|
||||
at = end;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1159,6 +1250,41 @@ mod tests {
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gui_models_keep_separate_depth_runs_between_overlay_draws() {
|
||||
let mut batch = HudBatch::new([640, 480]);
|
||||
batch.scale = 2.0;
|
||||
let p = [
|
||||
[0.0, 0.0, 2.0],
|
||||
[0.0, 1.0, 2.0],
|
||||
[1.0, 1.0, 2.0],
|
||||
[1.0, 0.0, 2.0],
|
||||
];
|
||||
let uv = [[0.0; 2]; 4];
|
||||
batch.quad([[0.0; 2]; 4], uv, u32::MAX);
|
||||
for _ in 0..2 {
|
||||
let start = batch.vertices.len();
|
||||
batch.quad_3d(p, uv, u32::MAX);
|
||||
batch.depth_since(start, [1.0, 2.0, 4.0, 6.0]);
|
||||
}
|
||||
batch.quad([[0.0; 2]; 4], uv, u32::MAX);
|
||||
assert_eq!(
|
||||
batch.runs(),
|
||||
vec![
|
||||
(0..6, Blend::Alpha),
|
||||
(6..12, Blend::Depth([2, 4, 6, 8])),
|
||||
(12..18, Blend::Depth([2, 4, 6, 8])),
|
||||
(18..24, Blend::Alpha),
|
||||
]
|
||||
);
|
||||
assert!(
|
||||
batch
|
||||
.vertices
|
||||
.iter()
|
||||
.all(|v| v.depth.is_finite() && (0.0..=1.0).contains(&v.depth))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hud_shader_validates_both_fragment_entries() {
|
||||
let module = naga::front::wgsl::parse_str(include_str!("hud.wgsl")).unwrap();
|
||||
|
||||
@@ -7,10 +7,10 @@ struct Out {
|
||||
@location(0) uv: vec2<f32>,
|
||||
@location(1) color: vec4<f32>,
|
||||
}
|
||||
@vertex fn vs_main(@location(0) pos: vec2<f32>, @location(1) uv: vec2<f32>, @location(2) color: vec4<f32>) -> Out {
|
||||
@vertex fn vs_main(@location(0) pos: vec2<f32>, @location(1) uv: vec2<f32>, @location(2) color: vec4<f32>, @location(3) depth: f32) -> Out {
|
||||
let pixels = pos * hud.size.z;
|
||||
var out: Out;
|
||||
out.clip = vec4(pixels.x / hud.size.x * 2.0 - 1.0, 1.0 - pixels.y / hud.size.y * 2.0, 0.0, 1.0);
|
||||
out.clip = vec4(pixels.x / hud.size.x * 2.0 - 1.0, 1.0 - pixels.y / hud.size.y * 2.0, depth, 1.0);
|
||||
out.uv = uv;
|
||||
out.color = color;
|
||||
return out;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -847,6 +847,10 @@ fn red_overlay(m: &Mob) -> bool {
|
||||
m.hurt_time > 0 || (m.death_time > 0 && !super::creaking::tearing_down(m))
|
||||
}
|
||||
fn species_scale(m: &Mob, alpha: f32) -> glam::Mat4 {
|
||||
if m.kind.id == "minecraft:player" {
|
||||
// AvatarRenderer.scale, shared by the inventory and world renderer.
|
||||
return glam::Mat4::from_scale(glam::Vec3::splat(0.9375));
|
||||
}
|
||||
match m.species() {
|
||||
Species::Wither => {
|
||||
glam::Mat4::from_scale(glam::Vec3::splat(super::wither::scale(m, alpha)))
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -587,9 +587,16 @@ impl OptionsUi {
|
||||
}
|
||||
return events;
|
||||
}
|
||||
// A click anywhere stops waiting for an extra's key.
|
||||
// Rebinding consumes the click before sidebar or widget actions.
|
||||
if matches!(self.selected_key, Some(extras::ZOOM_KEY | extras::SORT_KEY)) {
|
||||
self.selected_key = None;
|
||||
return self.bind_mouse(
|
||||
s,
|
||||
if right {
|
||||
winit::event::MouseButton::Right
|
||||
} else {
|
||||
winit::event::MouseButton::Left
|
||||
},
|
||||
);
|
||||
}
|
||||
match self.horizon_target(s, atlas, x, y) {
|
||||
Some(Target::Nav(i)) => {
|
||||
|
||||
@@ -708,12 +708,14 @@ pub enum Page {
|
||||
Language,
|
||||
Font,
|
||||
Packs,
|
||||
Mods,
|
||||
/// Horizon's graphics settings (`graphics_ui`).
|
||||
Graphics,
|
||||
GraphicsAdvanced,
|
||||
/// Horizon's controller settings and button binds.
|
||||
Controller,
|
||||
PadBinds,
|
||||
Extras,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum Act {
|
||||
@@ -721,6 +723,7 @@ enum Act {
|
||||
Push(Page),
|
||||
Done,
|
||||
Cycle(Opt),
|
||||
Extra(crate::extras::Item),
|
||||
Key(&'static str),
|
||||
ResetKey(&'static str),
|
||||
ResetKeys,
|
||||
@@ -730,6 +733,7 @@ enum Act {
|
||||
ResetPadKeys,
|
||||
/// Back to Horizon's own menus (Horizon only, see `list_rows`).
|
||||
HorizonMenus,
|
||||
ToggleMod(usize),
|
||||
}
|
||||
enum WKind {
|
||||
Button {
|
||||
@@ -974,9 +978,11 @@ impl OptionsUi {
|
||||
Page::Language => "options.language.title",
|
||||
Page::Font => "options.font.title",
|
||||
Page::Packs => "resourcePack.title",
|
||||
Page::Mods => "Mods",
|
||||
Page::Graphics | Page::GraphicsAdvanced => "options.videoTitle",
|
||||
Page::Controller => "Controller Settings",
|
||||
Page::PadBinds => "Controller Binds",
|
||||
Page::Extras => "Horizon Extras",
|
||||
}
|
||||
}
|
||||
fn scrollbar_x(&self, width: f32) -> f32 {
|
||||
@@ -989,6 +995,22 @@ impl OptionsUi {
|
||||
}
|
||||
fn list_rows(&self, s: &Settings) -> Vec<Row> {
|
||||
match self.page() {
|
||||
Page::Extras => crate::extras::rows()
|
||||
.into_iter()
|
||||
.map(|row| match row {
|
||||
Err(header) => Row::Header(header),
|
||||
Ok(item) => {
|
||||
let value = format!("{}: {}", item.caption(), item.value(&s.extras));
|
||||
let label =
|
||||
if item.key_name().is_some() && self.selected_key == item.key_name() {
|
||||
Text::literal(format!("> {value} <")).with_color(text::YELLOW)
|
||||
} else {
|
||||
Text::literal(value)
|
||||
};
|
||||
Row::Buttons(button(0.0, 0.0, 310.0, label, Act::Extra(item)), None)
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
Page::Video => {
|
||||
// Horizon's graphics screens, Simple and Advanced.
|
||||
let mut rows = vec![Row::Buttons(
|
||||
@@ -1164,6 +1186,36 @@ impl OptionsUi {
|
||||
Opt::AutoJump,
|
||||
]),
|
||||
Page::Font => pairs(&[Opt::ForceUnicode, Opt::JapaneseGlyphs]),
|
||||
Page::Mods => {
|
||||
if s.mods.installed.is_empty() {
|
||||
return vec![Row::Header(
|
||||
"No mods: put .hmod files in the horizon-mods folder",
|
||||
)];
|
||||
}
|
||||
s.mods
|
||||
.installed
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, installed)| {
|
||||
let mut label = Text::literal(format!("{}: ", installed.title))
|
||||
.append(on_off(s.mods.is_on(i)));
|
||||
if installed.problem.is_some() {
|
||||
label = label.append(" (Stopped)");
|
||||
} else if installed.dev {
|
||||
label = label.append(" (Dev)");
|
||||
}
|
||||
let widget = button(0.0, 0.0, 310.0, label, Act::ToggleMod(i));
|
||||
Row::Buttons(
|
||||
if installed.dev || installed.id.is_empty() {
|
||||
inactive(widget)
|
||||
} else {
|
||||
widget
|
||||
},
|
||||
None,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
_ => {
|
||||
let _ = s;
|
||||
Vec::new()
|
||||
@@ -1209,8 +1261,8 @@ impl OptionsUi {
|
||||
("options.chat", Some(Page::Chat)),
|
||||
("options.resourcepack", Some(Page::Packs)),
|
||||
("options.accessibility", Some(Page::Accessibility)),
|
||||
("options.telemetry", None),
|
||||
("options.credits_and_attribution", None),
|
||||
("Mods...", Some(Page::Mods)),
|
||||
("Horizon Extras...", Some(Page::Extras)),
|
||||
];
|
||||
let gy = (61.0 + 30.0f32).min(h - 33.0 - 120.0);
|
||||
for (i, (key, page)) in entries.iter().enumerate() {
|
||||
@@ -1670,6 +1722,13 @@ impl OptionsUi {
|
||||
let hover = ui::hovered(cursor, wd.x, wd.y, wd.w, wd.h)
|
||||
&& (!wd.list || cursor.1 >= top && cursor.1 < bottom);
|
||||
if hover {
|
||||
if let WKind::Button {
|
||||
act: Act::Extra(item),
|
||||
..
|
||||
} = &wd.kind
|
||||
{
|
||||
tooltip = Some(atlas.font.split(&Text::literal(item.description()), 170.0));
|
||||
}
|
||||
let key = match &wd.kind {
|
||||
WKind::Button {
|
||||
act: Act::Cycle(opt),
|
||||
@@ -1689,6 +1748,21 @@ impl OptionsUi {
|
||||
if let Some(key) = key.filter(|key| lang::has(key)) {
|
||||
tooltip = Some(atlas.font.split(&tr(&key), 170.0));
|
||||
}
|
||||
if let WKind::Button {
|
||||
act: Act::ToggleMod(i),
|
||||
..
|
||||
} = &wd.kind
|
||||
&& let Some(installed) = s.mods.installed.get(*i)
|
||||
{
|
||||
let description = installed
|
||||
.problem
|
||||
.as_deref()
|
||||
.unwrap_or(&installed.description);
|
||||
tooltip = Some(atlas.font.split(
|
||||
&Text::literal(format!("{}\n{description}", installed.title)),
|
||||
170.0,
|
||||
));
|
||||
}
|
||||
}
|
||||
match &wd.kind {
|
||||
WKind::Button { label, active, act } => {
|
||||
@@ -1925,15 +1999,13 @@ impl OptionsUi {
|
||||
return events;
|
||||
}
|
||||
// Key Binds: a mouse button pressed while waiting binds it.
|
||||
if let Some(name) = self.selected_key.take() {
|
||||
if self.selected_key.is_some() {
|
||||
let button = if right {
|
||||
"key.mouse.right"
|
||||
winit::event::MouseButton::Right
|
||||
} else {
|
||||
"key.mouse.left"
|
||||
winit::event::MouseButton::Left
|
||||
};
|
||||
s.keys.set(name, button);
|
||||
events.push(Event::Changed);
|
||||
return events;
|
||||
return self.bind_mouse(s, button);
|
||||
}
|
||||
// AbstractWidget accepts only the primary button. Rebinding above
|
||||
// accepts other mouse buttons, but is not a widget activation.
|
||||
@@ -1968,6 +2040,14 @@ impl OptionsUi {
|
||||
}
|
||||
events.push(Event::Changed);
|
||||
}
|
||||
Act::Extra(item) => {
|
||||
if let Some(name) = item.key_name() {
|
||||
self.selected_key = Some(name);
|
||||
} else {
|
||||
item.cycle(&mut s.extras, right);
|
||||
events.push(Event::Changed);
|
||||
}
|
||||
}
|
||||
Act::Key(name) => self.selected_key = Some(name),
|
||||
Act::ResetKey(name) => {
|
||||
s.keys.set(name, KeyBinds::default_of(name));
|
||||
@@ -1993,6 +2073,10 @@ impl OptionsUi {
|
||||
crate::ui_theme::save_preferences(&dir);
|
||||
}
|
||||
}
|
||||
Act::ToggleMod(i) => {
|
||||
s.mods.toggle(i);
|
||||
events.push(Event::Changed);
|
||||
}
|
||||
Act::None => {}
|
||||
}
|
||||
}
|
||||
@@ -2181,6 +2265,23 @@ impl OptionsUi {
|
||||
}
|
||||
false
|
||||
}
|
||||
fn bind_key(&mut self, s: &mut Settings, value: String) -> Vec<Event> {
|
||||
let Some(name) = self.selected_key.take() else {
|
||||
return Vec::new();
|
||||
};
|
||||
if !s.extras.set_key(name, value.clone()) {
|
||||
s.keys.set(name, &value);
|
||||
}
|
||||
vec![Event::Changed]
|
||||
}
|
||||
/// Mouse bindings use the same settings and persistence as keyboard bindings.
|
||||
pub fn bind_mouse(
|
||||
&mut self,
|
||||
s: &mut Settings,
|
||||
button: winit::event::MouseButton,
|
||||
) -> Vec<Event> {
|
||||
self.bind_key(s, keybinds::mouse_name(button))
|
||||
}
|
||||
/// Keys while the options are open. Returns events; `handled` false lets
|
||||
/// Escape fall through.
|
||||
pub fn key(
|
||||
@@ -2221,7 +2322,7 @@ impl OptionsUi {
|
||||
}
|
||||
return vec![Event::Changed];
|
||||
}
|
||||
if let Some(name) = self.selected_key.take() {
|
||||
if self.selected_key.is_some() {
|
||||
// KeyBindsScreen.keyPressed: Escape unbinds.
|
||||
let value = if key == K::Escape {
|
||||
"key.keyboard.unknown".to_owned()
|
||||
@@ -2230,10 +2331,7 @@ impl OptionsUi {
|
||||
.unwrap_or("key.keyboard.unknown")
|
||||
.to_owned()
|
||||
};
|
||||
if !s.extras.set_key(name, value.clone()) {
|
||||
s.keys.set(name, &value);
|
||||
}
|
||||
return vec![Event::Changed];
|
||||
return self.bind_key(s, value);
|
||||
}
|
||||
if key == K::Escape {
|
||||
return self.back(s);
|
||||
@@ -2311,6 +2409,88 @@ mod tests {
|
||||
assert!(ui.resource_error.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classic_mods_page_toggles_mods_and_keeps_dev_and_invalid_entries_inactive() {
|
||||
let atlas = atlas();
|
||||
let mut s = Settings::default();
|
||||
let mut ui = OptionsUi::default();
|
||||
let size = (480.0, 240.0);
|
||||
assert!(ui.layout(&s, size.0, size.1).0.iter().any(|w| {
|
||||
matches!(
|
||||
w.kind,
|
||||
WKind::Button {
|
||||
active: true,
|
||||
act: Act::Push(Page::Mods),
|
||||
..
|
||||
}
|
||||
)
|
||||
}));
|
||||
ui.show(Page::Mods);
|
||||
let empty = ui.layout(&s, size.0, size.1).0;
|
||||
assert!(empty.iter().any(|w| {
|
||||
matches!(&w.kind, WKind::Text { text, .. } if text.plain().contains(".hmod"))
|
||||
}));
|
||||
for (id, dev) in [("normal", false), ("dev", true), ("", false)] {
|
||||
s.mods.installed.push(crate::mod_list::Installed {
|
||||
id: id.into(),
|
||||
title: id.into(),
|
||||
description: "May show HUD panels.".into(),
|
||||
problem: id.is_empty().then(|| "Invalid package".into()),
|
||||
dev,
|
||||
});
|
||||
}
|
||||
let (widgets, ..) = ui.layout(&s, size.0, size.1);
|
||||
let rows: Vec<_> = widgets
|
||||
.iter()
|
||||
.filter(|w| {
|
||||
matches!(
|
||||
w.kind,
|
||||
WKind::Button {
|
||||
act: Act::ToggleMod(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(rows.len(), 3);
|
||||
for (i, row) in rows.iter().enumerate() {
|
||||
let events = ui.click(
|
||||
&mut s,
|
||||
&atlas,
|
||||
row.x + 1.0,
|
||||
row.y + 1.0,
|
||||
size,
|
||||
[480, 240],
|
||||
false,
|
||||
false,
|
||||
);
|
||||
if i == 0 {
|
||||
assert!(events.contains(&Event::Changed));
|
||||
assert!(events.contains(&Event::ButtonClick));
|
||||
} else {
|
||||
assert!(events.is_empty());
|
||||
}
|
||||
}
|
||||
assert!(s.mods.is_on(0));
|
||||
assert!(s.mods.is_on(1));
|
||||
assert!(!s.mods.is_on(2));
|
||||
assert_eq!(s.mods.serialize(), "mod.normal:true\n");
|
||||
let row = rows[0];
|
||||
ui.click(
|
||||
&mut s,
|
||||
&atlas,
|
||||
row.x + 1.0,
|
||||
row.y + 1.0,
|
||||
size,
|
||||
[480, 240],
|
||||
false,
|
||||
false,
|
||||
);
|
||||
assert!(!s.mods.is_on(0));
|
||||
assert!(!ui.back(&mut s).contains(&Event::Close));
|
||||
assert_eq!(ui.page(), Page::Main);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn option_tooltip_keys_follow_value_dependent_descriptions() {
|
||||
let mut s = Settings::default();
|
||||
@@ -2426,6 +2606,83 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classic_extras_entry_edits_shared_settings_and_returns_without_changing_style() {
|
||||
let previous_style = style();
|
||||
set_style(MenuStyle::Classic);
|
||||
let atlas = atlas();
|
||||
let mut s = Settings::default();
|
||||
let mut ui = OptionsUi::default();
|
||||
let size = (480.0, 480.0);
|
||||
let click = |ui: &mut OptionsUi, s: &mut Settings, act: Act| {
|
||||
let (widgets, _, _, _) = ui.layout(s, size.0, size.1);
|
||||
let widget = widgets
|
||||
.iter()
|
||||
.find(
|
||||
|w| matches!(&w.kind, WKind::Button { act: a, active: true, .. } if *a == act),
|
||||
)
|
||||
.unwrap();
|
||||
ui.click(
|
||||
s,
|
||||
&atlas,
|
||||
widget.x + 1.0,
|
||||
widget.y + 1.0,
|
||||
size,
|
||||
[960, 960],
|
||||
false,
|
||||
false,
|
||||
)
|
||||
};
|
||||
assert_eq!(
|
||||
click(&mut ui, &mut s, Act::Push(Page::Extras)),
|
||||
vec![Event::ButtonClick]
|
||||
);
|
||||
assert_eq!(ui.page(), Page::Extras);
|
||||
let (widgets, _, _, _) = ui.layout(&s, size.0, size.1);
|
||||
assert_eq!(
|
||||
widgets
|
||||
.iter()
|
||||
.filter(|w| matches!(
|
||||
w.kind,
|
||||
WKind::Button {
|
||||
act: Act::Extra(_),
|
||||
..
|
||||
}
|
||||
))
|
||||
.count(),
|
||||
crate::extras::rows().iter().filter(|r| r.is_ok()).count()
|
||||
);
|
||||
assert_eq!(
|
||||
click(&mut ui, &mut s, Act::Extra(crate::extras::Item::Zoom)),
|
||||
vec![Event::ButtonClick, Event::Changed]
|
||||
);
|
||||
assert!(s.extras.zoom);
|
||||
assert_eq!(
|
||||
click(&mut ui, &mut s, Act::Extra(crate::extras::Item::ZoomKey)),
|
||||
vec![Event::ButtonClick]
|
||||
);
|
||||
assert_eq!(ui.selected_key, Some(crate::extras::ZOOM_KEY));
|
||||
assert_eq!(
|
||||
ui.key(&mut s, &atlas, winit::keyboard::KeyCode::KeyC, None),
|
||||
vec![Event::Changed]
|
||||
);
|
||||
assert_eq!(s.extras.zoom_key, "key.keyboard.c");
|
||||
assert_eq!(
|
||||
crate::extras::Extras::parse(&s.extras.serialize()),
|
||||
s.extras
|
||||
);
|
||||
ui.scroll(&s, size, -1000.0);
|
||||
let (_, top, bottom, content) = ui.layout(&s, size.0, size.1);
|
||||
assert_eq!(ui.scroll, content - (bottom - top));
|
||||
assert_eq!(
|
||||
ui.key(&mut s, &atlas, winit::keyboard::KeyCode::Escape, None),
|
||||
vec![Event::Changed]
|
||||
);
|
||||
assert_eq!(ui.page(), Page::Main);
|
||||
assert_eq!(style(), MenuStyle::Classic);
|
||||
set_style(previous_style);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classic_graphics_presets_set_the_distances() {
|
||||
let atlas = atlas();
|
||||
@@ -2941,6 +3198,55 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extras_and_vanilla_bindings_accept_mouse_buttons() {
|
||||
use crate::extras::{Extras, SORT_KEY, ZOOM_KEY};
|
||||
use winit::event::MouseButton;
|
||||
for button in [
|
||||
MouseButton::Left,
|
||||
MouseButton::Right,
|
||||
MouseButton::Middle,
|
||||
MouseButton::Back,
|
||||
MouseButton::Forward,
|
||||
] {
|
||||
for name in [SORT_KEY, ZOOM_KEY, "key.jump"] {
|
||||
let mut ui = OptionsUi::default();
|
||||
let mut s = Settings::default();
|
||||
ui.selected_key = Some(name);
|
||||
assert_eq!(ui.bind_mouse(&mut s, button), vec![Event::Changed]);
|
||||
assert_eq!(ui.selected_key, None);
|
||||
let value = keybinds::mouse_name(button);
|
||||
match name {
|
||||
SORT_KEY => assert_eq!(s.extras.sort_key, value),
|
||||
ZOOM_KEY => assert_eq!(s.extras.zoom_key, value),
|
||||
_ => assert_eq!(s.keys.get(name), value),
|
||||
}
|
||||
assert_eq!(Extras::parse(&s.extras.serialize()), s.extras);
|
||||
if name != "key.jump" {
|
||||
assert_eq!(s.keys, Settings::default().keys);
|
||||
}
|
||||
assert!(ui.bind_mouse(&mut s, button).is_empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn horizon_extra_mouse_binding_consumes_the_click() {
|
||||
let atlas = atlas();
|
||||
let mut s = Settings::default();
|
||||
let mut ui = OptionsUi::default();
|
||||
for (right, expected) in [(false, "key.mouse.left"), (true, "key.mouse.right")] {
|
||||
ui.selected_key = Some(crate::extras::SORT_KEY);
|
||||
assert_eq!(
|
||||
ui.click_horizon(&mut s, &atlas, 2.0, 2.0, [960, 480], false, right),
|
||||
vec![Event::Changed]
|
||||
);
|
||||
assert_eq!(s.extras.sort_key, expected);
|
||||
assert_eq!(ui.selected_key, None);
|
||||
assert_eq!(ui.section, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_rebinding_takes_precedence_over_scrollbar_dragging() {
|
||||
let atlas = atlas();
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
|
||||
@@ -694,6 +694,7 @@ impl<'a> Ui<'a> {
|
||||
pos: p[i],
|
||||
uv: [cu, cv],
|
||||
color: c[i],
|
||||
depth: 0.0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,6 +513,22 @@ impl Behaviours {
|
||||
sim.game_event_state(pos, "minecraft:block_change", next);
|
||||
}
|
||||
|
||||
/// The state change of `RedStoneOreBlock.attack` when mining begins.
|
||||
pub fn attack_block<L: LevelAccess + ?Sized>(
|
||||
&self,
|
||||
level: &mut L,
|
||||
ticks: &mut Ticks,
|
||||
pos: BlockPos,
|
||||
) {
|
||||
let mut sim = self.sim(level, ticks);
|
||||
let state = sim.state(pos);
|
||||
if self.data(state).chain.contains(&Class::RedStoneOre)
|
||||
&& !self.table.bool(state, self.props.lit)
|
||||
{
|
||||
sim.set_block_and_update(pos, self.table.set_bool(state, self.props.lit, true));
|
||||
}
|
||||
}
|
||||
|
||||
/// `BlockState.useWithoutItem` for a right-click on `pos` (hit face and
|
||||
/// absolute hit location as in `BlockHitResult`).
|
||||
pub fn use_without_item<L: LevelAccess + ?Sized>(
|
||||
|
||||
@@ -634,6 +634,27 @@ impl World<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mining_lights_redstone_ore_until_its_random_tick() {
|
||||
let mut w = world!();
|
||||
let pos = BlockPos::new(0, 1, 0);
|
||||
for ore in ["redstone_ore", "deepslate_redstone_ore"] {
|
||||
let unlit = w.id(ore, &[("lit", "false")]);
|
||||
let lit = w.id(ore, &[("lit", "true")]);
|
||||
w.put(pos, unlit);
|
||||
w.b().attack_block(&mut w.level, &mut w.ticks, pos);
|
||||
assert_eq!(w.get(pos), lit);
|
||||
w.b().attack_block(&mut w.level, &mut w.ticks, pos);
|
||||
assert_eq!(w.get(pos), lit);
|
||||
w.b().random_tick(&mut w.level, &mut w.ticks, pos);
|
||||
assert_eq!(w.get(pos), unlit);
|
||||
}
|
||||
let stone = w.id("stone", &[]);
|
||||
w.put(pos, stone);
|
||||
w.b().attack_block(&mut w.level, &mut w.ticks, pos);
|
||||
assert_eq!(w.get(pos), stone);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn placement_orients_blocks() {
|
||||
let mut w = world!();
|
||||
|
||||
+6
-1
@@ -1,6 +1,6 @@
|
||||
# Horizon extras
|
||||
|
||||
Optional conveniences built into the client: zoom, a minimap, an FPS counter, a
|
||||
Optional conveniences built into the client: fullbright, zoom, a minimap, an FPS counter, a
|
||||
keystroke overlay, auto-reconnect, Mouse Tweaks-style inventory controls and
|
||||
inventory sorting. **Every one is off by default**: a fresh
|
||||
install looks and behaves exactly like vanilla 26.3, and turning an extra off
|
||||
@@ -36,6 +36,11 @@ Horizon category in Controls, and adding one would put a non-vanilla mapping int
|
||||
|
||||
## The extras
|
||||
|
||||
### Fullbright (`fullbright`, default off)
|
||||
- Displays blocks and entities with a fully bright lightmap, including in dark caves.
|
||||
- Turning it off restores the normal lightmap using the current brightness,
|
||||
time of day and effects. The brightness slider keeps its normal range.
|
||||
|
||||
### Zoom (`zoom`, default off)
|
||||
- Hold the zoom key (default **Z**, unused by every vanilla 26.3 key mapping; C
|
||||
is `key.saveToolbarActivator`) to zoom. The key does nothing while zoom is off.
|
||||
|
||||
Reference in New Issue
Block a user