Merge origin/main into fix/water-cauldron-extinguish
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+32
-13
@@ -16,7 +16,7 @@ Horizon is Minecraft: Java Edition 26.3 rewritten from scratch in Rust, so it ru
|
||||
- **Single player as a server: the last differences**: Single player now runs a small server in the background, as vanilla does. We are fixing what still behaves differently there; every fix also works for LAN and server players.
|
||||
- **Horizon's mod registry**: One place for mods, modpacks and resource packs made for Horizon: browse them on the website and install them from the launcher in one click.
|
||||
|
||||
**Next**: Microsoft sign-in (coming soon); CurseForge in the mod browser (coming soon); Fresh benchmarks against vanilla; Pistons push players and mobs; Horizon on Intel Macs; Faster world creation and entry on small CPUs; Servers that hold 20 TPS with 50 to 100 players; Low-end computers: Steam Deck, old Macs, 8 GB; Native upscaling; A batch of targeted optimisations; A Convert to Rust button for what isn't rewritten yet; Mods with code: machines, magic, mobs; Data packs in the mod browser; Prepare a version without Java; Server console, bans and a full admin API; Hosting polish: Windows service, safe updates; Guided hosting with Tailscale and an invite button; An official Docker image for servers; One single-player path: remove the in-frame world; Villages and combat, exactly as in vanilla; Choose the audio output device; Mods that read and change the world; Machines and blocks with inventories (API 0.4); Lua and other languages for mods; Well-known shader looks, rewritten for Horizon; A visible beta label; Wayland and Hyprland polish; A versioned agent-control protocol; Port mods with your own AI agent; Horizon on X (coming soon); Pipeline protection and a GitHub App for agents; Signed updates everywhere, installers included.
|
||||
**Next**: Microsoft sign-in (coming soon); CurseForge in the mod browser (coming soon); Fresh benchmarks against vanilla; Pistons push players and mobs; Horizon on Intel Macs; Faster world creation and entry on small CPUs; Servers that hold 20 TPS with 50 to 100 players; Low-end computers: Steam Deck, old Macs, 8 GB; Native upscaling; A batch of targeted optimisations; A Convert to Rust button for what isn't rewritten yet; Mods with code: machines, magic, mobs; Data packs in the mod browser; Prepare a version without Java; Server console, bans and a full admin API; Hosting polish: Windows service, safe updates; Guided hosting with Tailscale and an invite button; An official Docker image for servers; One single-player path: remove the in-frame world; Villages and combat, exactly as in vanilla; Choose the audio output device; Mods that read and change the world; Machines and blocks with inventories (API 0.4); Lua and other languages for mods; Well-known shader looks, rewritten for Horizon; A visible beta label; Wayland and Hyprland polish; A versioned agent-control protocol; Port mods with your own AI agent; Horizon on X (coming soon); Pipeline protection and a GitHub App for agents; Signed updates everywhere, installers included; A server you install with one command.
|
||||
|
||||
**How to help**: Play it and tell us what differs from vanilla (Discord or GitHub), run the benchmark on your computer, vote for what you want next, or pick one of the Help wanted items.
|
||||
|
||||
@@ -374,6 +374,16 @@ More: [docs/server.md](docs/server.md)
|
||||
|
||||
</details>
|
||||
|
||||
#### A server you install with one command
|
||||
|
||||
Install and run a Horizon dedicated server from a terminal with a single command, no launcher needed, for VPSes and headless machines.
|
||||
|
||||
<details><summary>Technical</summary>
|
||||
|
||||
A player's idea (#horizon-ideas). `horizon-server` already runs headless; left: an install script (Linux/macOS shell, Windows PowerShell) that fetches the signed release, checks it, asks for or points at the player's own game files and starts the server, documented in [docs/hosting.md](docs/hosting.md).
|
||||
|
||||
</details>
|
||||
|
||||
### Mods and API
|
||||
|
||||
#### Mods that read and change the world
|
||||
@@ -790,18 +800,6 @@ Issue [#1709](https://github.com/ludovic111/horizon/issues/1709): aarch64 builds
|
||||
|
||||
</details>
|
||||
|
||||
#### OpenGL for old computers
|
||||
|
||||
A way to play on old PCs and Linux machines that have no Vulkan or DirectX 12, through OpenGL.
|
||||
|
||||
<details><summary>Technical</summary>
|
||||
|
||||
Players on older hardware ask whether Vulkan is the only way. Horizon draws with wgpu, which has an OpenGL backend; what is needed is to see which features hold up on it, how fast it runs, and a launcher switch like the DirectX 12 fallback that already ships.
|
||||
|
||||
More: [docs/graphics.md](docs/graphics.md)
|
||||
|
||||
</details>
|
||||
|
||||
#### Android, iOS and the browser
|
||||
|
||||
Versions of Horizon for Android, iOS and web browsers. Nothing official yet; contributors have started the first pieces.
|
||||
@@ -812,6 +810,16 @@ No official build. Android was first closed as not planned, with touch controls,
|
||||
|
||||
</details>
|
||||
|
||||
#### AppImage and a Nix flake
|
||||
|
||||
Install Horizon on any Linux distribution as an AppImage, and on NixOS through a Nix flake.
|
||||
|
||||
<details><summary>Technical</summary>
|
||||
|
||||
A player's idea (#horizon-ideas). An AppImage of the launcher and game from the release workflow, and a flake.nix packaging the release binaries with their runtime libraries (Vulkan loader, X11/Wayland, ALSA), the way horizon-parity's NixOS setup runs them today.
|
||||
|
||||
</details>
|
||||
|
||||
### Horizon extras
|
||||
|
||||
#### A complete video studio inside the game
|
||||
@@ -824,6 +832,16 @@ Three stages. Recording: capture gameplay in a keypress with an encoder thread a
|
||||
|
||||
</details>
|
||||
|
||||
#### Game menus in the launcher's style
|
||||
|
||||
An optional look for the game's own menus and options that matches the Horizon launcher. Off by default: the vanilla menus stay as they are.
|
||||
|
||||
<details><summary>Technical</summary>
|
||||
|
||||
A player's idea (#horizon-ideas). A built-in resource pack or a Horizon setting that restyles the title, pause and options screens with the launcher's design tokens (crates/horizon-theme), following [docs/design-system.md](docs/design-system.md); off by default because it changes the vanilla look.
|
||||
|
||||
</details>
|
||||
|
||||
### AI and agents
|
||||
|
||||
#### An optional AI teammate
|
||||
@@ -936,6 +954,7 @@ Vanilla's `Chicken.aiStep` updates `flap` and `flapSpeed` when the chicken isn't
|
||||
|
||||
## Recently shipped
|
||||
|
||||
- **OpenGL for old computers** (v0.2.63): Horizon now starts on old PCs whose graphics card has no Vulkan or DirectX 12 driver: it switches to OpenGL by itself, and Options > Graphics can pick OpenGL by hand. [#1917](https://github.com/ludovic111/horizon/issues/1917) · [#1920](https://github.com/ludovic111/horizon/issues/1920) · [#1936](https://github.com/ludovic111/horizon/issues/1936)
|
||||
- **Server resource packs** (v0.2.48): Servers can send you their resource pack: Horizon asks, downloads it and applies it, like vanilla. [#1562](https://github.com/ludovic111/horizon/issues/1562) · [#1569](https://github.com/ludovic111/horizon/issues/1569) · [#1570](https://github.com/ludovic111/horizon/issues/1570)
|
||||
- **Single player on its own server thread** (v0.2.39): Single player runs on a server thread, as vanilla does, so the world keeps ticking smoothly while the window draws. [#1514](https://github.com/ludovic111/horizon/issues/1514) · [docs/server-levels.md](docs/server-levels.md)
|
||||
- **GPU occlusion culling on Macs** (v0.2.17): On Macs the GPU now skips terrain hidden behind hills and caves: 8 to 48% more frames per second at 32 chunks on an M4 Pro. [#1434](https://github.com/ludovic111/horizon/issues/1434)
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//! Lore tooltip companion for tools/test_lore_tooltip_parity.py: the spans
|
||||
//! `item_tooltip::lore_texts` gives each stack (SNBT, one per line).
|
||||
use horizon_client::{
|
||||
item_data::parse_stack,
|
||||
item_tooltip::{TooltipDisplay, lore_texts},
|
||||
};
|
||||
use std::{error::Error, fmt::Write};
|
||||
|
||||
pub fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args: Vec<String> = crate::args().collect();
|
||||
let input = std::fs::read_to_string(&args[1])?;
|
||||
let mut output = String::new();
|
||||
for line in input
|
||||
.lines()
|
||||
.filter(|l| !l.is_empty() && !l.starts_with('#'))
|
||||
{
|
||||
let stack = parse_stack(line)?.ok_or("empty stack")?;
|
||||
let display = TooltipDisplay::for_stack(&stack);
|
||||
if !display.shows("minecraft:lore") {
|
||||
writeln!(output, "-")?;
|
||||
continue;
|
||||
}
|
||||
let lines = lore_texts(&stack);
|
||||
if lines.is_empty() {
|
||||
writeln!(output, "-")?;
|
||||
continue;
|
||||
}
|
||||
let mut rendered = Vec::new();
|
||||
for text in lines {
|
||||
let mut spans = Vec::new();
|
||||
for span in &text.spans {
|
||||
if span.text.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let style = &span.style;
|
||||
spans.push(format!(
|
||||
"{}\t{}\t{}\t{}\t{}\t{}\t{}",
|
||||
span.text,
|
||||
style.color.map(|c| c as i32).unwrap_or(-1),
|
||||
style.bold == Some(true),
|
||||
style.italic == Some(true),
|
||||
style.underlined == Some(true),
|
||||
style.strikethrough == Some(true),
|
||||
style.obfuscated == Some(true),
|
||||
));
|
||||
}
|
||||
rendered.push(spans.join(" | "));
|
||||
}
|
||||
writeln!(output, "{}", rendered.join(" || "))?;
|
||||
}
|
||||
std::fs::write(&args[2], output)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -49,6 +49,7 @@ mod input_probe;
|
||||
mod interaction_input_fixture;
|
||||
mod lan_probe;
|
||||
mod light_parity;
|
||||
mod lore_tooltip_fixture;
|
||||
mod marker_particles_probe;
|
||||
mod menu_fixture;
|
||||
mod mipmap_probe;
|
||||
@@ -133,6 +134,7 @@ probes! {
|
||||
interaction_input_fixture,
|
||||
lan_probe,
|
||||
light_parity,
|
||||
lore_tooltip_fixture,
|
||||
marker_particles_probe,
|
||||
menu_fixture,
|
||||
mipmap_probe,
|
||||
|
||||
@@ -519,7 +519,12 @@ impl Game<'_> {
|
||||
self.draw_tooltip_lines(batch, &lines, self.cursor.0, self.cursor.1);
|
||||
} else if let Some(key) = tooltip {
|
||||
let text = self.translate(&key, &key);
|
||||
self.draw_tooltip_lines(batch, &[(text, u32::MAX)], self.cursor.0, self.cursor.1);
|
||||
self.draw_tooltip_lines(
|
||||
batch,
|
||||
&[(horizon_client::text::Text::literal(text), u32::MAX)],
|
||||
self.cursor.0,
|
||||
self.cursor.1,
|
||||
);
|
||||
}
|
||||
}
|
||||
/// `BeaconRenderer`: each section's rotating solid beam and its glow.
|
||||
|
||||
@@ -18,7 +18,7 @@ fn chat_tree<'a>(
|
||||
mods: &'a super::mods::ModsState,
|
||||
) -> &'a horizon_client::command::Dispatcher {
|
||||
match remote.as_ref().and_then(|r| r.commands.as_ref()) {
|
||||
Some(tree) => tree,
|
||||
Some(tree) => mods.remote_dispatcher().unwrap_or(tree),
|
||||
None => mods.dispatcher(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,15 @@ pub(super) struct Rocket {
|
||||
pub(super) velocity: Vec3,
|
||||
life: i32,
|
||||
lifetime: i32,
|
||||
explosions: Vec<FireworkExplosion>,
|
||||
pub(super) explosions: Vec<FireworkExplosion>,
|
||||
/// Boosting the player (attachedToEntity).
|
||||
pub(super) attached: bool,
|
||||
/// On a server, the player it boosts when not this game's own: a guest's
|
||||
/// connection.
|
||||
pub(super) guest: Option<u32>,
|
||||
/// `DATA_ATTACHED_TO_TARGET`: the server entity the rocket follows;
|
||||
/// boosting happens when it is the local player.
|
||||
pub(super) attached_to: Option<u32>,
|
||||
/// `DATA_SHOT_AT_ANGLE` (dispensers): constant velocity, exploding on
|
||||
/// the first block it hits.
|
||||
pub(super) angled: bool,
|
||||
@@ -48,6 +54,8 @@ impl Rocket {
|
||||
lifetime: i32::MAX,
|
||||
explosions,
|
||||
attached: false,
|
||||
guest: None,
|
||||
attached_to: None,
|
||||
angled: false,
|
||||
item,
|
||||
}
|
||||
@@ -63,7 +71,7 @@ impl Rocket {
|
||||
(self.position, self.velocity)
|
||||
}
|
||||
}
|
||||
fn fireworks_of(stack: &ItemStack) -> (u8, Vec<FireworkExplosion>) {
|
||||
pub(super) fn fireworks_of(stack: &ItemStack) -> (u8, Vec<FireworkExplosion>) {
|
||||
// The item's default component: flight 1, no explosions.
|
||||
stack
|
||||
.data()
|
||||
@@ -89,6 +97,8 @@ impl Game<'_> {
|
||||
lifetime,
|
||||
explosions,
|
||||
attached,
|
||||
guest: None,
|
||||
attached_to: None,
|
||||
angled: false,
|
||||
item: stack.clone(),
|
||||
}
|
||||
@@ -127,7 +137,8 @@ impl Game<'_> {
|
||||
return false;
|
||||
}
|
||||
let at = self.player.as_ref().map_or(Vec3::ZERO, |p| p.position);
|
||||
let rocket = self.new_rocket(at, stack, true);
|
||||
let mut rocket = self.new_rocket(at, stack, true);
|
||||
rocket.guest = self.lan_acting;
|
||||
self.rockets.push(rocket);
|
||||
if !self.creative {
|
||||
self.consume_held();
|
||||
@@ -140,7 +151,18 @@ impl Game<'_> {
|
||||
while i < self.rockets.len() {
|
||||
let mut r = self.rockets.remove(i);
|
||||
r.previous = r.position;
|
||||
if r.attached {
|
||||
if r.attached
|
||||
&& let Some(conn) = r.guest
|
||||
{
|
||||
// A guest's rocket follows them; their own client boosts them.
|
||||
let guest = self
|
||||
.lan
|
||||
.as_ref()
|
||||
.and_then(|host| host.hub.guests.iter().find(|g| g.conn == conn));
|
||||
if let Some(g) = guest {
|
||||
r.position = Vec3::new(g.position[0], g.position[1], g.position[2]);
|
||||
}
|
||||
} else if r.attached {
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
if p.fall_flying {
|
||||
let look = view_vector(self.yaw, self.pitch);
|
||||
@@ -229,8 +251,19 @@ impl Game<'_> {
|
||||
let at = [r.position.x, r.position.y, r.position.z];
|
||||
if !r.explosions.is_empty() {
|
||||
let damage = 5.0 + r.explosions.len() as f32 * 2.0;
|
||||
// The player it boosts takes the full damage, a guest as well.
|
||||
if r.attached {
|
||||
self.hurt_player_by("minecraft:fireworks", damage);
|
||||
match r.guest {
|
||||
None => self.hurt_player_by("minecraft:fireworks", damage),
|
||||
Some(conn) => {
|
||||
if let Some(mut host) = self.lan.take() {
|
||||
self.as_guest(&mut host, conn, |g| {
|
||||
g.hurt_player_by("minecraft:fireworks", damage);
|
||||
});
|
||||
self.lan = Some(host);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let from = r.position;
|
||||
let hits: Vec<(u32, f32)> = {
|
||||
|
||||
@@ -162,6 +162,13 @@ fn mob_meta(
|
||||
meta.push((3, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
}
|
||||
// LivingEntity.DATA_LIVING_ENTITY_FLAGS: using an item 1, in the off
|
||||
// hand 2 (a skeleton draws its bow, a witch raises her potion).
|
||||
let using = i8::from(m.extra.using_item > 0) | i8::from(m.extra.using_off_hand) << 1;
|
||||
if using != 0 {
|
||||
meta.push((8, serializer::BYTE, Value::Byte(using)));
|
||||
}
|
||||
defaults.push((8, serializer::BYTE, Value::Byte(0)));
|
||||
// LivingEntity.DATA_HEALTH_ID: defined as 1, then set to the max health.
|
||||
let health = m.health.max(0.0);
|
||||
if health != 1.0 {
|
||||
@@ -293,6 +300,21 @@ fn mob_meta(
|
||||
meta.push((18, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
}
|
||||
// Pillager.IS_CHARGING_CROSSBOW: the charge pose and the held
|
||||
// item's loading animation.
|
||||
"minecraft:pillager" => {
|
||||
if e.flag {
|
||||
meta.push((17, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
defaults.push((17, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
// SpellcasterIllager.DATA_SPELL_CASTING_ID: the casting pose.
|
||||
"minecraft:evoker" | "minecraft:illusioner" => {
|
||||
if e.variant2 != 0 {
|
||||
meta.push((17, serializer::BYTE, Value::Byte(e.variant2 as i8)));
|
||||
}
|
||||
defaults.push((17, serializer::BYTE, Value::Byte(0)));
|
||||
}
|
||||
// Enderman.DATA_CARRY_STATE.
|
||||
"minecraft:enderman" => {
|
||||
if let Some(state) = e.carried {
|
||||
|
||||
@@ -275,6 +275,8 @@ impl Game<'_> {
|
||||
motion.sprinting = g.sprinting;
|
||||
motion.may_fly = g.creative() || g.game_mode == SPECTATOR;
|
||||
motion.flying = g.flying;
|
||||
// FireworkRocketItem.use boosts only a gliding player.
|
||||
motion.fall_flying = g.fall_flying;
|
||||
motion.invulnerable = motion.may_fly;
|
||||
let _ = motion.set_health(g.health, false);
|
||||
motion.health.food.food = g.food;
|
||||
|
||||
@@ -404,11 +404,19 @@ impl Game<'_> {
|
||||
Value::Item(hub.stack(&Some(r.item.clone()))),
|
||||
));
|
||||
}
|
||||
let boosted = match r.guest {
|
||||
Some(conn) => hub
|
||||
.guests
|
||||
.iter()
|
||||
.find(|g| g.conn == conn)
|
||||
.map(|g| g.entity_id),
|
||||
None => host_entity,
|
||||
};
|
||||
if r.attached
|
||||
&& let Some(host) = host_entity
|
||||
&& let Some(player) = boosted
|
||||
{
|
||||
e.meta
|
||||
.push((9, serializer::OPTIONAL_UNSIGNED_INT, Value::Id(host + 1)));
|
||||
.push((9, serializer::OPTIONAL_UNSIGNED_INT, Value::Id(player + 1)));
|
||||
}
|
||||
if r.angled {
|
||||
e.meta.push((10, serializer::BOOLEAN, Value::Bool(true)));
|
||||
|
||||
@@ -218,7 +218,7 @@ impl Game<'_> {
|
||||
oy: f32,
|
||||
draws: &[ScreenDraw],
|
||||
background: bool,
|
||||
) -> Option<Vec<(String, u32)>> {
|
||||
) -> Option<Vec<(horizon_client::text::Text, u32)>> {
|
||||
let atlas = &self.gui.atlas;
|
||||
let mut tooltip = None;
|
||||
let mut sheet: Option<String> = None;
|
||||
@@ -261,7 +261,10 @@ impl Game<'_> {
|
||||
..
|
||||
} => self.draw_banner_result(batch, ox + *x0 as f32, oy + *y0 as f32, base, layers),
|
||||
ScreenDraw::Tooltip { key } => {
|
||||
tooltip = Some(vec![(self.translate(key, key), u32::MAX)]);
|
||||
tooltip = Some(vec![(
|
||||
horizon_client::text::Text::literal(self.translate(key, key)),
|
||||
u32::MAX,
|
||||
)]);
|
||||
}
|
||||
ScreenDraw::SpriteOf { id } => sheet = Some(id.clone()),
|
||||
ScreenDraw::Fill {
|
||||
@@ -314,7 +317,7 @@ impl Game<'_> {
|
||||
ox: f32,
|
||||
oy: f32,
|
||||
local: (f32, f32),
|
||||
) -> Option<Vec<(String, u32)>> {
|
||||
) -> Option<Vec<(horizon_client::text::Text, u32)>> {
|
||||
let s = self.station.as_ref()?;
|
||||
let l = &s.loom;
|
||||
let dye = s.inputs[1]
|
||||
|
||||
@@ -259,7 +259,7 @@ impl Game<'_> {
|
||||
// ItemInHandLayer submits with OverlayTexture.NO_OVERLAY: no hurt tint.
|
||||
for (item, off_hand) in [(&mob.extra.main_hand, false), (&mob.extra.off_hand, true)] {
|
||||
let Some(item) = item else { continue };
|
||||
let left = off_hand != mob.extra.main_hand_left;
|
||||
let left = off_hand != mob.main_arm_left();
|
||||
let Some(t) =
|
||||
render::held_item_transform(mob, alpha as f32, camera, self.res.mob_data(), left)
|
||||
else {
|
||||
@@ -305,7 +305,7 @@ impl Game<'_> {
|
||||
.player_model
|
||||
.as_ref()
|
||||
.is_some_and(|p| std::ptr::eq(p, mob));
|
||||
owner.main_arm_left = mob.extra.main_hand_left;
|
||||
owner.main_arm_left = mob.main_arm_left();
|
||||
if off_hand == mob.extra.using_off_hand && mob.extra.using_item > 0 {
|
||||
owner.using_this_item = true;
|
||||
owner.use_duration = 72_000;
|
||||
|
||||
@@ -42,6 +42,9 @@ pub(super) struct ModsState {
|
||||
/// The chat's command tree while a running mod owns commands.
|
||||
#[cfg(feature = "mods")]
|
||||
tree: Option<Dispatcher>,
|
||||
/// The server's command tree with the running mods' commands added.
|
||||
#[cfg(feature = "mods")]
|
||||
remote_tree: Option<Dispatcher>,
|
||||
/// A `ui` mod's screen or settings page while it is up.
|
||||
#[cfg(feature = "mods")]
|
||||
screen: Option<ModScreen>,
|
||||
@@ -69,6 +72,14 @@ impl ModsState {
|
||||
}
|
||||
vanilla::game_dispatcher()
|
||||
}
|
||||
/// The server's tree plus the mods' commands, when a mod owns any.
|
||||
pub(super) fn remote_dispatcher(&self) -> Option<&Dispatcher> {
|
||||
#[cfg(feature = "mods")]
|
||||
if let Some(tree) = &self.remote_tree {
|
||||
return Some(tree);
|
||||
}
|
||||
None
|
||||
}
|
||||
/// Whether a mod runs: the chat keeps its lines for them.
|
||||
pub(super) fn running(&self) -> bool {
|
||||
#[cfg(feature = "mods")]
|
||||
@@ -178,6 +189,7 @@ impl Game<'_> {
|
||||
);
|
||||
}
|
||||
}
|
||||
pub(super) fn merge_remote_tree(&mut self) {}
|
||||
pub(super) fn sync_mods(&mut self) {}
|
||||
pub(super) fn tick_mods(&mut self) {}
|
||||
pub(super) fn mods_frame(&mut self, _elapsed: Duration) {}
|
||||
@@ -267,7 +279,20 @@ impl Game<'_> {
|
||||
.peek()
|
||||
.is_some()
|
||||
.then(|| vanilla::game_dispatcher().with_mod_commands(names));
|
||||
self.merge_remote_tree();
|
||||
}
|
||||
|
||||
/// The server's command tree with the mods' commands, for the chat.
|
||||
pub(super) fn merge_remote_tree(&mut self) {
|
||||
let names: Vec<String> = self.mods.mods.commands().map(str::to_owned).collect();
|
||||
self.mods.remote_tree = self
|
||||
.remote
|
||||
.as_ref()
|
||||
.and_then(|r| r.commands.as_ref())
|
||||
.filter(|_| !names.is_empty())
|
||||
.map(|t| t.with_mod_commands(names.iter().map(String::as_str)));
|
||||
}
|
||||
|
||||
/// After the options changed: restart the mods if the list of the ones
|
||||
/// turned on did.
|
||||
pub(super) fn sync_mods(&mut self) {
|
||||
|
||||
@@ -1163,8 +1163,12 @@ impl Game<'_> {
|
||||
}
|
||||
/// Paints recipe book calls; returns the first tooltip set (vanilla keeps
|
||||
/// the first one a frame asks for).
|
||||
fn paint_book(&mut self, batch: &mut HudBatch, calls: &[Drawn]) -> Option<Vec<(String, u32)>> {
|
||||
let mut tooltip: Option<Vec<(String, u32)>> = None;
|
||||
fn paint_book(
|
||||
&mut self,
|
||||
batch: &mut HudBatch,
|
||||
calls: &[Drawn],
|
||||
) -> Option<Vec<(horizon_client::text::Text, u32)>> {
|
||||
let mut tooltip: Option<Vec<(horizon_client::text::Text, u32)>> = None;
|
||||
for d in calls {
|
||||
let start = batch.vertices.len();
|
||||
let atlas = &self.gui.atlas;
|
||||
@@ -1259,7 +1263,14 @@ impl Game<'_> {
|
||||
tooltip = Some(
|
||||
lines
|
||||
.iter()
|
||||
.map(|l| (l.iter().map(|r| r.text.as_str()).collect(), u32::MAX))
|
||||
.map(|l| {
|
||||
(
|
||||
horizon_client::text::Text::literal(
|
||||
l.iter().map(|r| r.text.as_str()).collect::<String>(),
|
||||
),
|
||||
u32::MAX,
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
@@ -1269,10 +1280,10 @@ impl Game<'_> {
|
||||
let mut lines = self.stack_tooltip(stack);
|
||||
if *more {
|
||||
lines.push((
|
||||
self.translate(
|
||||
horizon_client::text::Text::literal(self.translate(
|
||||
"gui.recipebook.moreRecipes",
|
||||
"Right Click for More",
|
||||
),
|
||||
)),
|
||||
u32::MAX,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1904,25 +1904,12 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// LivingEntity.onSyncedDataUpdated(DATA_LIVING_ENTITY_FLAGS):
|
||||
// another player starts using the item in a hand (eating, a
|
||||
// bow drawn, a shield up), or stops.
|
||||
// LivingEntity.DATA_LIVING_ENTITY_FLAGS: for another player
|
||||
// too, remote_mob_data's apply reads index 8 above.
|
||||
let other = self
|
||||
.remote
|
||||
.as_ref()
|
||||
.is_some_and(|r| r.level_players.contains_key(&p.id) && r.entity_id != p.id);
|
||||
if other && let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
|
||||
for (index, _, value) in &p.values {
|
||||
if let (8, Value::Byte(flags)) = (index, value) {
|
||||
m.extra.using_off_hand = flags & 2 != 0;
|
||||
if flags & 1 == 0 {
|
||||
m.extra.using_item = 0;
|
||||
} else if m.extra.using_item == 0 {
|
||||
m.extra.using_item = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// LivingEntity.onSyncedDataUpdated(SLEEPING_POS_ID): another
|
||||
// player lies down in their bed (drawn lying in it), or gets up.
|
||||
if other {
|
||||
@@ -2378,6 +2365,7 @@ impl Game<'_> {
|
||||
if let Some(r) = self.remote.as_mut() {
|
||||
r.commands = Some(tree);
|
||||
}
|
||||
self.merge_remote_tree();
|
||||
}
|
||||
C::SystemChat(p) => {
|
||||
// The component as sent, translated in the client's own
|
||||
@@ -3405,25 +3393,28 @@ impl Game<'_> {
|
||||
m.head_yaw += wrap_degrees(*yaw - m.head_yaw) / *steps as f32;
|
||||
*steps -= 1;
|
||||
}
|
||||
// LivingEntity.updatingUsingItem for another player: the ticks the
|
||||
// item has been used before this one.
|
||||
if player && m.extra.using_item > 0 {
|
||||
let item = if m.extra.using_off_hand {
|
||||
m.extra.off_hand.clone()
|
||||
} else {
|
||||
m.extra.main_hand.clone()
|
||||
};
|
||||
if let Some(item) = item {
|
||||
let eye = if m.extra.crouching { 1.27 } else { 1.62 };
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
using.push((
|
||||
item,
|
||||
m.extra.using_item as u32 - 1,
|
||||
at,
|
||||
eye,
|
||||
m.head_pitch,
|
||||
m.yaw,
|
||||
));
|
||||
// LivingEntity.updatingUsingItem: the ticks the item has been
|
||||
// used before this one. Another player's use particles; a mob's
|
||||
// drawn bow only needs the count (its pull follows it).
|
||||
if m.extra.using_item > 0 {
|
||||
if player {
|
||||
let item = if m.extra.using_off_hand {
|
||||
m.extra.off_hand.clone()
|
||||
} else {
|
||||
m.extra.main_hand.clone()
|
||||
};
|
||||
if let Some(item) = item {
|
||||
let eye = if m.extra.crouching { 1.27 } else { 1.62 };
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
using.push((
|
||||
item,
|
||||
m.extra.using_item as u32 - 1,
|
||||
at,
|
||||
eye,
|
||||
m.head_pitch,
|
||||
m.yaw,
|
||||
));
|
||||
}
|
||||
}
|
||||
m.extra.using_item += 1;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,17 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin) {
|
||||
// client, which draws the flames. A client doesn't count the
|
||||
// fire down: the flag goes off when the server's fire is out.
|
||||
(0, Value::Byte(flags)) => m.fire_ticks = i32::from(flags & 1),
|
||||
// LivingEntity.DATA_LIVING_ENTITY_FLAGS: using an item 1, in the
|
||||
// off hand 2. The flag starts and stops the use; the client ticks
|
||||
// the count itself (a bow's pull follows it).
|
||||
(8, Value::Byte(flags)) => {
|
||||
m.extra.using_off_hand = flags & 2 != 0;
|
||||
if flags & 1 == 0 {
|
||||
m.extra.using_item = 0;
|
||||
} else if m.extra.using_item == 0 {
|
||||
m.extra.using_item = 1;
|
||||
}
|
||||
}
|
||||
// LivingEntity.DATA_HEALTH_ID: the boss bars and the death
|
||||
// animation follow it.
|
||||
(9, Value::Float(health)) => m.health = *health,
|
||||
@@ -53,6 +64,13 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin) {
|
||||
(Species::Slime | Species::MagmaCube, 18, Value::Int(size)) => {
|
||||
m.extra.size = (*size).clamp(1, 127);
|
||||
}
|
||||
// Pillager.IS_CHARGING_CROSSBOW: the charge pose (Raider's
|
||||
// IS_CELEBRATING takes 16).
|
||||
(Species::Pillager, 17, Value::Bool(charging)) => m.extra.flag = *charging,
|
||||
// SpellcasterIllager.DATA_SPELL_CASTING_ID: the casting pose.
|
||||
(Species::Evoker | Species::Illusioner, 17, Value::Byte(spell)) => {
|
||||
m.extra.variant2 = (*spell).max(0) as u8;
|
||||
}
|
||||
// Villager.DATA_VILLAGER_DATA and ZombieVillager's (after
|
||||
// Zombie's three): what VillagerProfessionLayer draws.
|
||||
(Species::Villager, 19, Value::Ids(data))
|
||||
@@ -239,4 +257,42 @@ mod tests {
|
||||
);
|
||||
assert_eq!(name(&z), ("desert", "farmer", 3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_mob_flags_drive_the_aggressive_poses() {
|
||||
let Some(mut m) = mob("minecraft:skeleton") else {
|
||||
return;
|
||||
};
|
||||
apply(&mut m, &[(15, s::BYTE, Value::Byte(2 | 4))]);
|
||||
assert!(m.ai.aggressive && m.extra.left_handed && !m.no_ai);
|
||||
apply(&mut m, &[(15, s::BYTE, Value::Byte(0))]);
|
||||
assert!(!m.ai.aggressive && !m.extra.left_handed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_living_flags_start_and_stop_a_mob_using_an_item() {
|
||||
let Some(mut m) = mob("minecraft:skeleton") else {
|
||||
return;
|
||||
};
|
||||
apply(&mut m, &[(8, s::BYTE, Value::Byte(1))]);
|
||||
assert_eq!(m.extra.using_item, 1);
|
||||
assert!(!m.extra.using_off_hand);
|
||||
// Using in the off hand.
|
||||
apply(&mut m, &[(8, s::BYTE, Value::Byte(3))]);
|
||||
assert!(m.extra.using_off_hand);
|
||||
apply(&mut m, &[(8, s::BYTE, Value::Byte(0))]);
|
||||
assert_eq!(m.extra.using_item, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pillager_charges_and_a_spellcaster_casts() {
|
||||
let Some(mut p) = mob("minecraft:pillager") else {
|
||||
return;
|
||||
};
|
||||
apply(&mut p, &[(17, s::BOOLEAN, Value::Bool(true))]);
|
||||
assert!(p.extra.flag);
|
||||
let mut e = mob("minecraft:evoker").unwrap();
|
||||
apply(&mut e, &[(17, s::BYTE, Value::Byte(2))]);
|
||||
assert_eq!(e.extra.variant2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! end crystals on a server's client (`ClientPacketListener.handleAddEntity`
|
||||
//! and `handleSetEntityData`): the server simulates them, the client draws
|
||||
//! them where it says and interpolates their moves.
|
||||
use super::{FallStep, FallingBlock, Game};
|
||||
use super::{FallStep, FallingBlock, Game, fireworks::fireworks_of, view_vector};
|
||||
use horizon_client::projectiles::{Projectile, ProjectileKind};
|
||||
use horizon_core::{geometry::Vec3, position::BlockPos};
|
||||
use horizon_protocol::entity_data::Value;
|
||||
@@ -125,6 +125,37 @@ impl Game<'_> {
|
||||
pub(super) fn remote_projectile_data(&mut self, id: i32, values: &[(u8, i32, Value)]) {
|
||||
let id = id as u32;
|
||||
self.remote_hook_data(id, values);
|
||||
if self.rockets.iter().any(|r| r.id == id) {
|
||||
for (index, _, value) in values {
|
||||
match (index, value) {
|
||||
// FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM: its
|
||||
// explosions for `createFireworks`.
|
||||
(8, Value::Item(stack)) => {
|
||||
if let Some(stack) = self.to_stack(stack)
|
||||
&& let Some(r) = self.rockets.iter_mut().find(|r| r.id == id)
|
||||
{
|
||||
let (_, explosions) = fireworks_of(&stack);
|
||||
r.explosions = explosions;
|
||||
r.item = stack;
|
||||
}
|
||||
}
|
||||
// DATA_ATTACHED_TO_TARGET (OptionalInt: the id plus 1).
|
||||
(9, Value::Id(v)) => {
|
||||
let v = (*v > 0).then(|| (*v - 1) as u32);
|
||||
if let Some(r) = self.rockets.iter_mut().find(|r| r.id == id) {
|
||||
r.attached_to = v;
|
||||
}
|
||||
}
|
||||
// DATA_SHOT_AT_ANGLE.
|
||||
(10, Value::Bool(a)) => {
|
||||
if let Some(r) = self.rockets.iter_mut().find(|r| r.id == id) {
|
||||
r.angled = *a;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.potions.has_thrown(id) {
|
||||
// ThrowableItemProjectile.DATA_ITEM_STACK: the potion it is.
|
||||
for (index, _, value) in values {
|
||||
@@ -213,9 +244,30 @@ impl Game<'_> {
|
||||
let id = t.id;
|
||||
t.remote_step(|at| step(id, at));
|
||||
}
|
||||
// FireworkRocketEntity.tick: a rocket attached to the gliding local
|
||||
// player boosts it client-side too (attachedToEntity.isFallFlying).
|
||||
let me = self
|
||||
.remote
|
||||
.as_ref()
|
||||
.and_then(|r| u32::try_from(r.entity_id).ok());
|
||||
for r in &mut self.rockets {
|
||||
let id = r.id;
|
||||
r.remote_step(|at| step(id, at));
|
||||
if me.is_some()
|
||||
&& r.attached_to == me
|
||||
&& let Some(p) = self.player.as_mut()
|
||||
&& p.fall_flying
|
||||
{
|
||||
let look = view_vector(self.yaw, self.pitch);
|
||||
let m = p.velocity;
|
||||
p.velocity = Vec3::new(
|
||||
m.x + look[0] * 0.1 + (look[0] * 1.5 - m.x) * 0.5,
|
||||
m.y + look[1] * 0.1 + (look[1] * 1.5 - m.y) * 0.5,
|
||||
m.z + look[2] * 0.1 + (look[2] * 1.5 - m.z) * 0.5,
|
||||
);
|
||||
r.position = p.position;
|
||||
r.velocity = p.velocity;
|
||||
}
|
||||
}
|
||||
for c in &mut self.crystals {
|
||||
c.time += 1;
|
||||
|
||||
@@ -1092,7 +1092,7 @@ impl Game<'_> {
|
||||
}
|
||||
let (ox, oy) = self.inventory_origin(batch);
|
||||
let local = (self.cursor.0 - ox, self.cursor.1 - oy);
|
||||
let mut tooltip: Option<Vec<(String, u32)>> = None;
|
||||
let mut tooltip: Option<Vec<(horizon_client::text::Text, u32)>> = None;
|
||||
{
|
||||
let atlas = &self.gui.atlas;
|
||||
batch.fill(
|
||||
@@ -1341,16 +1341,19 @@ impl Game<'_> {
|
||||
let clue = self
|
||||
.translate("container.enchant.clue", "%s . . . ?")
|
||||
.replace("%s", &name);
|
||||
let mut lines = vec![(clue, u32::MAX)];
|
||||
let mut lines =
|
||||
vec![(horizon_client::text::Text::literal(clue), u32::MAX)];
|
||||
if !self.creative {
|
||||
lines.push((String::new(), u32::MAX));
|
||||
lines.push((horizon_client::text::Text::literal(""), u32::MAX));
|
||||
if level < cost {
|
||||
lines.push((
|
||||
self.translate(
|
||||
"container.enchant.level.requirement",
|
||||
"Level Requirement: %s",
|
||||
)
|
||||
.replace("%s", &cost.to_string()),
|
||||
horizon_client::text::Text::literal(
|
||||
self.translate(
|
||||
"container.enchant.level.requirement",
|
||||
"Level Requirement: %s",
|
||||
)
|
||||
.replace("%s", &cost.to_string()),
|
||||
),
|
||||
rgba(255, 85, 85, 255),
|
||||
));
|
||||
} else {
|
||||
@@ -1368,7 +1371,7 @@ impl Game<'_> {
|
||||
.replace("%s", &n.to_string())
|
||||
};
|
||||
lines.push((
|
||||
lapis,
|
||||
horizon_client::text::Text::literal(lapis),
|
||||
if gold >= n as i32 {
|
||||
rgba(170, 170, 170, 255)
|
||||
} else {
|
||||
@@ -1387,7 +1390,10 @@ impl Game<'_> {
|
||||
)
|
||||
.replace("%s", &n.to_string())
|
||||
};
|
||||
lines.push((levels, rgba(170, 170, 170, 255)));
|
||||
lines.push((
|
||||
horizon_client::text::Text::literal(levels),
|
||||
rgba(170, 170, 170, 255),
|
||||
));
|
||||
}
|
||||
}
|
||||
tooltip = Some(lines);
|
||||
@@ -1496,10 +1502,10 @@ impl Game<'_> {
|
||||
);
|
||||
if inside(local, 65.0, 46.0, 28.0, 21.0) {
|
||||
tooltip = Some(vec![(
|
||||
self.translate(
|
||||
horizon_client::text::Text::literal(self.translate(
|
||||
"container.upgrade.error_tooltip",
|
||||
"Item can't be upgraded this way",
|
||||
),
|
||||
)),
|
||||
u32::MAX,
|
||||
)]);
|
||||
}
|
||||
@@ -1626,9 +1632,12 @@ impl Game<'_> {
|
||||
|
||||
// ---------------------------------------------------------------- tooltips
|
||||
|
||||
/// `ItemStack.getTooltipLines` subset: name in rarity colour, potion
|
||||
/// effects, enchantments (gray, curses red), stored enchantments, trims.
|
||||
pub(super) fn stack_tooltip(&self, stack: &ItemStack) -> Vec<(String, u32)> {
|
||||
/// `ItemStack.getTooltipLines` subset: name in rarity colour, lore,
|
||||
/// potion effects, enchantments (gray, curses red), stored enchantments, trims.
|
||||
pub(super) fn stack_tooltip(
|
||||
&self,
|
||||
stack: &ItemStack,
|
||||
) -> Vec<(horizon_client::text::Text, u32)> {
|
||||
let e: &Enchantments = &self.res.stations().enchantments;
|
||||
let props = e.props(&stack.item);
|
||||
let rarity = horizon_client::item_tooltip::rarity(
|
||||
@@ -1660,24 +1669,27 @@ impl Game<'_> {
|
||||
let display = horizon_client::item_tooltip::TooltipDisplay::for_stack(stack);
|
||||
let mut lines = Vec::new();
|
||||
if display.name_visible(self.screen == Screen::Creative) {
|
||||
lines.push((name, color));
|
||||
lines.push((horizon_client::text::Text::legacy(&name), color));
|
||||
}
|
||||
let translate = |k: &str| self.pack.names.display_get(k);
|
||||
let push = |lines: &mut Vec<(horizon_client::text::Text, u32)>, s: String, c: u32| {
|
||||
lines.push((horizon_client::text::Text::legacy(&s), c));
|
||||
};
|
||||
// ItemContainerContents.addToTooltip.
|
||||
let hover_name = |s: &ItemStack| {
|
||||
s.custom_name()
|
||||
.map_or_else(|| self.pack.names.display_item(&s.item), str::to_owned)
|
||||
};
|
||||
if display.shows("minecraft:container") {
|
||||
for line in
|
||||
for text in
|
||||
horizon_client::item_tooltip::container_lines(stack, &hover_name, &translate)
|
||||
{
|
||||
lines.push((line, u32::MAX));
|
||||
push(&mut lines, text, u32::MAX);
|
||||
}
|
||||
}
|
||||
// Fireworks / FireworkExplosion.addToTooltip.
|
||||
for line in horizon_client::item_tooltip::firework_lines(stack, &translate) {
|
||||
lines.push((line, rgba(170, 170, 170, 255)));
|
||||
for text in horizon_client::item_tooltip::firework_lines(stack, &translate) {
|
||||
push(&mut lines, text, rgba(170, 170, 170, 255));
|
||||
}
|
||||
if display.shows("minecraft:potion_contents")
|
||||
&& (stack.item.ends_with("potion") || &*stack.item == "minecraft:tipped_arrow")
|
||||
@@ -1687,7 +1699,7 @@ impl Game<'_> {
|
||||
"minecraft:tipped_arrow" => 0.125,
|
||||
_ => 1.0,
|
||||
};
|
||||
for (line, cat) in brewing::tooltip(stack.potion(), scale, &|k| {
|
||||
for (text, cat) in brewing::tooltip(stack.potion(), scale, &|k| {
|
||||
e.translate(k).map(str::to_owned)
|
||||
}) {
|
||||
let c = match cat {
|
||||
@@ -1695,18 +1707,19 @@ impl Game<'_> {
|
||||
brewing::Category::Harmful => rgba(255, 85, 85, 255),
|
||||
brewing::Category::Neutral => rgba(170, 170, 170, 255),
|
||||
};
|
||||
lines.push((line, c));
|
||||
push(&mut lines, text, c);
|
||||
}
|
||||
}
|
||||
if display.shows("minecraft:trim")
|
||||
&& let Some((material, pattern)) = stack.data().and_then(|d| d.trim.clone())
|
||||
{
|
||||
lines.push((
|
||||
push(
|
||||
&mut lines,
|
||||
e.translate("item.minecraft.smithing_template.upgrade")
|
||||
.unwrap_or("Upgrade:")
|
||||
.to_owned(),
|
||||
rgba(170, 170, 170, 255),
|
||||
));
|
||||
);
|
||||
let short = |s: &str| s.trim_start_matches("minecraft:").to_owned();
|
||||
let p = e
|
||||
.translate(&format!("trim_pattern.minecraft.{}", short(&pattern)))
|
||||
@@ -1714,38 +1727,51 @@ impl Game<'_> {
|
||||
let m = e
|
||||
.translate(&format!("trim_material.minecraft.{}", short(&material)))
|
||||
.map_or_else(|| short(&material), str::to_owned);
|
||||
lines.push((format!(" {p}"), rgba(170, 170, 170, 255)));
|
||||
lines.push((format!(" {m}"), rgba(170, 170, 170, 255)));
|
||||
push(&mut lines, format!(" {p}"), rgba(170, 170, 170, 255));
|
||||
push(&mut lines, format!(" {m}"), rgba(170, 170, 170, 255));
|
||||
}
|
||||
if display.shows("minecraft:stored_enchantments") {
|
||||
for (text, curse) in e.tooltip(stack.stored_enchantments()) {
|
||||
lines.push((
|
||||
push(
|
||||
&mut lines,
|
||||
text,
|
||||
if curse {
|
||||
rgba(255, 85, 85, 255)
|
||||
} else {
|
||||
rgba(170, 170, 170, 255)
|
||||
},
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
if display.shows("minecraft:enchantments") {
|
||||
for (text, curse) in e.tooltip(stack.enchantments()) {
|
||||
lines.push((
|
||||
push(
|
||||
&mut lines,
|
||||
text,
|
||||
if curse {
|
||||
rgba(255, 85, 85, 255)
|
||||
} else {
|
||||
rgba(170, 170, 170, 255)
|
||||
},
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
// BannerPatternLayers.addToTooltip: up to six layer names.
|
||||
if display.shows("minecraft:banner_patterns") {
|
||||
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)));
|
||||
push(
|
||||
&mut lines,
|
||||
self.translate(&key, &key),
|
||||
rgba(170, 170, 170, 255),
|
||||
);
|
||||
}
|
||||
}
|
||||
// ItemLore.addToTooltip: after the enchantments, before the attributes
|
||||
// (ItemStack.addDetailsToTooltip).
|
||||
if display.shows("minecraft:lore") {
|
||||
for text in horizon_client::item_tooltip::lore_texts(stack) {
|
||||
lines.push((text, u32::MAX));
|
||||
}
|
||||
}
|
||||
// Spawner.appendHoverText: what a spawner or trial spawner item spawns.
|
||||
@@ -1759,15 +1785,15 @@ impl Game<'_> {
|
||||
match block_entity_item::spawner_entity(stack) {
|
||||
Some(id) => {
|
||||
let key = format!("entity.{}", id.replacen(':', ".", 1));
|
||||
lines.push((self.translate(&key, &id), gray));
|
||||
push(&mut lines, self.translate(&key, &id), gray);
|
||||
}
|
||||
None => {
|
||||
lines.push((String::new(), u32::MAX));
|
||||
push(&mut lines, String::new(), u32::MAX);
|
||||
let desc1 =
|
||||
self.translate("block.minecraft.spawner.desc1", "Interact with Spawn Egg:");
|
||||
lines.push((desc1, gray));
|
||||
push(&mut lines, desc1, gray);
|
||||
let desc2 = self.translate("block.minecraft.spawner.desc2", "Sets Mob Type");
|
||||
lines.push((format!(" {desc2}"), rgba(85, 85, 255, 255)));
|
||||
push(&mut lines, format!(" {desc2}"), rgba(85, 85, 255, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1795,11 +1821,13 @@ impl Game<'_> {
|
||||
horizon_client::attack_strength::BASE_ATTACK_SPEED,
|
||||
),
|
||||
];
|
||||
lines.extend(horizon_client::item_tooltip::attribute_lines(
|
||||
for (text, c) in horizon_client::item_tooltip::attribute_lines(
|
||||
&info.modifiers,
|
||||
Some(player_base),
|
||||
&translate,
|
||||
));
|
||||
) {
|
||||
push(&mut lines, text, c);
|
||||
}
|
||||
}
|
||||
if display.shows("minecraft:damage")
|
||||
&& let Some(info) = self.res.items().get(&stack.item)
|
||||
@@ -1807,14 +1835,15 @@ impl Game<'_> {
|
||||
&& stack.damage > 0
|
||||
&& self.options_advanced_tooltips()
|
||||
{
|
||||
lines.push((
|
||||
push(
|
||||
&mut lines,
|
||||
format!(
|
||||
"Durability: {} / {}",
|
||||
info.max_damage - stack.damage,
|
||||
info.max_damage
|
||||
),
|
||||
u32::MAX,
|
||||
));
|
||||
);
|
||||
}
|
||||
// ItemStack.OP_NBT_WARNING, for a player with game master permission.
|
||||
if self.ui.registries.permission >= 2 && block_entity_item::op_warning(stack) {
|
||||
@@ -1829,7 +1858,11 @@ impl Game<'_> {
|
||||
"Do not use unless you know the exact contents!",
|
||||
),
|
||||
] {
|
||||
lines.push((self.translate(key, fallback), rgba(255, 85, 85, 255)));
|
||||
push(
|
||||
&mut lines,
|
||||
self.translate(key, fallback),
|
||||
rgba(255, 85, 85, 255),
|
||||
);
|
||||
}
|
||||
}
|
||||
lines
|
||||
@@ -1860,20 +1893,27 @@ impl Game<'_> {
|
||||
self.settings.file.bool("advancedItemTooltips")
|
||||
}
|
||||
/// `TooltipRenderUtil`: dark box with the purple border, first line spaced.
|
||||
pub(super) fn draw_tooltip_lines(
|
||||
pub(super) fn draw_tooltip_lines<T: Clone + Into<horizon_client::text::Text>>(
|
||||
&self,
|
||||
batch: &mut HudBatch,
|
||||
lines: &[(String, u32)],
|
||||
lines: &[(T, u32)],
|
||||
x: f32,
|
||||
y: f32,
|
||||
) {
|
||||
if lines.is_empty() {
|
||||
return;
|
||||
}
|
||||
let lines: Vec<_> = lines
|
||||
.iter()
|
||||
.map(|(text, color)| {
|
||||
let text: horizon_client::text::Text = text.clone().into();
|
||||
(text.resolve_legacy(), *color)
|
||||
})
|
||||
.collect();
|
||||
let atlas = &self.gui.atlas;
|
||||
let w = lines
|
||||
.iter()
|
||||
.map(|(t, _)| HudBatch::text_width(atlas, t))
|
||||
.map(|(t, _)| atlas.font.width_text(t))
|
||||
.fold(0.0, f32::max);
|
||||
let h = if lines.len() == 1 {
|
||||
8.0
|
||||
@@ -1926,7 +1966,7 @@ impl Game<'_> {
|
||||
);
|
||||
let mut ty = y;
|
||||
for (i, (text, color)) in lines.iter().enumerate() {
|
||||
batch.text(atlas, text, x, ty, *color, true);
|
||||
batch.text_styled(atlas, text, x, ty, *color, true);
|
||||
ty += if i == 0 { 12.0 } else { 10.0 };
|
||||
}
|
||||
}
|
||||
@@ -1943,7 +1983,12 @@ impl Game<'_> {
|
||||
let lines = self.stack_tooltip(&stack);
|
||||
self.draw_tooltip_lines(batch, &lines, self.cursor.0, self.cursor.1);
|
||||
} else if let Some(text) = self.crafter_tooltip(slot) {
|
||||
self.draw_tooltip_lines(batch, &[(text, u32::MAX)], self.cursor.0, self.cursor.1);
|
||||
self.draw_tooltip_lines(
|
||||
batch,
|
||||
&[(horizon_client::text::Text::literal(text), u32::MAX)],
|
||||
self.cursor.0,
|
||||
self.cursor.1,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,14 @@ fn components_tag(s: &Stack, builtin: &Builtin, synced: &Dynamic) -> Option<Tag>
|
||||
("pages", Tag::List(b.pages.clone())),
|
||||
("resolved", Tag::Byte(i8::from(b.resolved))),
|
||||
]),
|
||||
Component::Fireworks { flight, explosions } => Tag::compound([
|
||||
("flight_duration", Tag::Byte(*flight as i8)),
|
||||
(
|
||||
"explosions",
|
||||
Tag::List(explosions.iter().map(fireworks_tag).collect()),
|
||||
),
|
||||
]),
|
||||
Component::FireworkExplosion(e) => fireworks_tag(e),
|
||||
Component::Enchantments(list) => {
|
||||
// Enchantments are a synced (data-driven) registry: the
|
||||
// ids index the server's RegistryData, not the builtin
|
||||
@@ -178,6 +186,29 @@ fn components_tag(s: &Stack, builtin: &Builtin, synced: &Dynamic) -> Option<Tag>
|
||||
Some(Tag::compound(entries))
|
||||
}
|
||||
|
||||
/// A wire `FireworkExplosion` as vanilla's NBT codec writes it
|
||||
/// (`FireworkExplosion.Shape`'s BY_ID order).
|
||||
fn fireworks_tag(e: &horizon_protocol::item::FireworkExplosion) -> Tag {
|
||||
const SHAPES: [&str; 5] = ["small_ball", "large_ball", "star", "creeper", "burst"];
|
||||
let ints = |c: &[i32]| Tag::List(c.iter().map(|c| Tag::Int(*c)).collect());
|
||||
Tag::compound([
|
||||
(
|
||||
"shape",
|
||||
Tag::String(
|
||||
SHAPES
|
||||
.get(e.shape.max(0) as usize)
|
||||
.copied()
|
||||
.unwrap_or("small_ball")
|
||||
.into(),
|
||||
),
|
||||
),
|
||||
("colors", ints(&e.colors)),
|
||||
("fade_colors", ints(&e.fade)),
|
||||
("has_trail", Tag::Byte(i8::from(e.trail))),
|
||||
("has_twinkle", Tag::Byte(i8::from(e.twinkle))),
|
||||
])
|
||||
}
|
||||
|
||||
/// A `minecraft:profile` component as the item data JSON the model reads.
|
||||
fn profile_tag(p: &Profile) -> Tag {
|
||||
let properties = p
|
||||
|
||||
@@ -487,23 +487,31 @@ pub fn lines(
|
||||
) -> Vec<String> {
|
||||
let mut lines = vec![name_line(stack, translate)];
|
||||
if TooltipDisplay::for_stack(stack).shows("minecraft:lore") {
|
||||
lines.extend(lore_lines(stack));
|
||||
lines.extend(lore_texts(stack).into_iter().map(|t| t.plain()));
|
||||
}
|
||||
lines.extend(detail_lines(stack, info, translate));
|
||||
lines
|
||||
}
|
||||
|
||||
/// `LoreComponent.addToTooltip`: the saved component lines, as plain text.
|
||||
fn lore_lines(stack: &ItemStack) -> Vec<String> {
|
||||
/// `ItemLore.addToTooltip`: each lore component under dark purple italic, with
|
||||
/// the component's own styles (including explicit `false`) winning on children.
|
||||
pub fn lore_texts(stack: &ItemStack) -> Vec<crate::text::Text> {
|
||||
let Some(Tag::List(entries)) = stack.data().and_then(|d| d.other("minecraft:lore")) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let base = crate::text::Style {
|
||||
color: Some(crate::text::DARK_PURPLE),
|
||||
italic: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
entries
|
||||
.iter()
|
||||
.map(|entry| {
|
||||
let json = crate::scoreboard::tag_to_json(entry);
|
||||
let text = crate::component::to_text(&json, &mut |s| crate::text::Text::literal(s));
|
||||
text.plain()
|
||||
let mut text = crate::entity_nbt::name_text(entry).resolve_legacy();
|
||||
for span in &mut text.spans {
|
||||
span.style.inherit(&base);
|
||||
}
|
||||
text
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -512,6 +520,42 @@ fn lore_lines(stack: &ItemStack) -> Vec<String> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn lore_keeps_component_colours_under_dark_purple_italic() {
|
||||
let mut stack = ItemStack::new("minecraft:stick", 1);
|
||||
stack.data_mut().set_other(
|
||||
"minecraft:lore",
|
||||
Some(Tag::List(vec![
|
||||
Tag::compound([
|
||||
("text", Tag::String("Gold line".into())),
|
||||
("color", Tag::String("gold".into())),
|
||||
("italic", Tag::Byte(0)),
|
||||
]),
|
||||
Tag::String("Plain lore".into()),
|
||||
])),
|
||||
);
|
||||
let lines = lore_texts(&stack);
|
||||
assert_eq!(lines.len(), 2);
|
||||
assert_eq!(lines[0].plain(), "Gold line");
|
||||
assert_eq!(lines[0].spans[0].style.color, Some(crate::text::GOLD));
|
||||
assert!(!lines[0].spans[0].style.is_italic());
|
||||
assert_eq!(lines[1].plain(), "Plain lore");
|
||||
assert_eq!(
|
||||
lines[1].spans[0].style.color,
|
||||
Some(crate::text::DARK_PURPLE)
|
||||
);
|
||||
assert!(lines[1].spans[0].style.is_italic());
|
||||
assert!(TooltipDisplay::for_stack(&stack).shows("minecraft:lore"));
|
||||
stack.data_mut().set_other(
|
||||
"minecraft:tooltip_display",
|
||||
Some(Tag::compound([(
|
||||
"hidden_components",
|
||||
Tag::List(vec![Tag::String("minecraft:lore".into())]),
|
||||
)])),
|
||||
);
|
||||
assert!(!TooltipDisplay::for_stack(&stack).shows("minecraft:lore"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tooltip_display_controls_name_and_component_visibility() {
|
||||
let mut stack = ItemStack::new("minecraft:diamond_sword", 1);
|
||||
|
||||
@@ -445,6 +445,43 @@ impl Guest {
|
||||
}
|
||||
}
|
||||
|
||||
/// `FireworkExplosion.STREAM_CODEC`'s fields (`Shape` by its BY_ID order).
|
||||
fn network_explosion(
|
||||
e: &crate::particles::FireworkExplosion,
|
||||
) -> horizon_protocol::item::FireworkExplosion {
|
||||
horizon_protocol::item::FireworkExplosion {
|
||||
shape: e.shape as i32,
|
||||
colors: e.colors.iter().map(|c| *c as i32).collect(),
|
||||
fade: e.fade.iter().map(|c| *c as i32).collect(),
|
||||
trail: e.trail,
|
||||
twinkle: e.twinkle,
|
||||
}
|
||||
}
|
||||
|
||||
/// A rocket's `minecraft:fireworks` and a star's `minecraft:firework_explosion`.
|
||||
pub fn firework_components(
|
||||
d: &crate::item_data::StackData,
|
||||
) -> Vec<(i32, horizon_protocol::item::Component)> {
|
||||
use horizon_protocol::item::{Component, component};
|
||||
let mut out = Vec::new();
|
||||
if let Some((flight, explosions)) = &d.fireworks {
|
||||
out.push((
|
||||
component::FIREWORKS,
|
||||
Component::Fireworks {
|
||||
flight: i32::from(*flight),
|
||||
explosions: explosions.iter().map(network_explosion).collect(),
|
||||
},
|
||||
));
|
||||
}
|
||||
if let Some(e) = &d.firework_explosion {
|
||||
out.push((
|
||||
component::FIREWORK_EXPLOSION,
|
||||
Component::FireworkExplosion(network_explosion(e)),
|
||||
));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The off hand slot is conventionally 40 in saves and 45 in the menu.
|
||||
/// `synced_id` names an entry of a synced registry (enchantments, trim
|
||||
/// materials and patterns) by its id on this connection.
|
||||
@@ -535,6 +572,7 @@ fn network_stack(
|
||||
horizon_protocol::item::Component::Int(i32::from(mode)),
|
||||
));
|
||||
}
|
||||
stack.added.extend(firework_components(d));
|
||||
// PotionContents: the potion by its `minecraft:potion` id.
|
||||
if let Some(id) = (d.potion.as_deref()).and_then(|potion| {
|
||||
synced_id(
|
||||
|
||||
@@ -1646,6 +1646,11 @@ impl Mob {
|
||||
pub fn species(&self) -> Species {
|
||||
self.kind.species
|
||||
}
|
||||
/// `Mob.getMainArm`: the left arm when the mob is left-handed, a player's
|
||||
/// `mainHand` option for a player mob.
|
||||
pub fn main_arm_left(&self) -> bool {
|
||||
self.extra.main_hand_left || self.extra.left_handed
|
||||
}
|
||||
/// The player hit this mob (melee): LivingEntity.hurt with knockback.
|
||||
pub fn hurt(
|
||||
&mut self,
|
||||
|
||||
@@ -642,7 +642,7 @@ pub fn setup(
|
||||
} else {
|
||||
ArmPose::Empty
|
||||
};
|
||||
let mut h = if m.extra.main_hand_left {
|
||||
let mut h = if m.main_arm_left() {
|
||||
Hum::new(ArmPose::Empty, main)
|
||||
} else {
|
||||
Hum::new(main, ArmPose::Empty)
|
||||
@@ -693,7 +693,7 @@ pub fn setup(
|
||||
} else {
|
||||
ArmPose::Empty
|
||||
};
|
||||
let mut h = if m.extra.main_hand_left {
|
||||
let mut h = if m.main_arm_left() {
|
||||
Hum::new(off, pose)
|
||||
} else {
|
||||
Hum::new(pose, off)
|
||||
|
||||
@@ -621,8 +621,10 @@ impl BowAttack {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `LivingEntity.isHolding(Items.BOW)`: the bow can sit in either hand.
|
||||
fn holding_bow(m: &Mob) -> bool {
|
||||
m.extra.main_hand.as_deref() == Some("minecraft:bow")
|
||||
|| m.extra.off_hand.as_deref() == Some("minecraft:bow")
|
||||
}
|
||||
impl Goal for BowAttack {
|
||||
goal_clone!();
|
||||
@@ -715,7 +717,10 @@ impl Goal for BowAttack {
|
||||
} else {
|
||||
self.attack_time -= 1;
|
||||
if self.attack_time <= 0 && self.see_time >= -60 {
|
||||
// mob.startUsingItem(ProjectileUtil.getWeaponHoldingHand):
|
||||
// the off hand when the main one doesn't hold the bow.
|
||||
m.extra.using_item = 1;
|
||||
m.extra.using_off_hand = m.extra.main_hand.as_deref() != Some("minecraft:bow");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,15 @@ rust-version = "1.85"
|
||||
description = "The DualSense's output over HID: rumble, adaptive triggers, lightbar and player LEDs"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
|
||||
# hidapi has no iOS backend and its build script stops there, so the output's two
|
||||
# dependencies go only to the targets that have one. On iOS the crate builds without
|
||||
# output: the Link never opens.
|
||||
[target.'cfg(not(target_os = "ios"))'.dependencies]
|
||||
# MIT; bundles the C hidapi under its BSD licence option. hidraw on Linux (libudev, as gilrs),
|
||||
# IOKit on macOS (opened shared, so gilrs keeps reading the pad), the HID API on Windows.
|
||||
hidapi = { version = "2.6.7", default-features = false, features = ["linux-static-hidraw", "macos-shared-device"] }
|
||||
log = "0.4"
|
||||
# HD haptics through the pad's own audio device (USB).
|
||||
cpal = "0.16"
|
||||
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
//! The pad over hidapi, and the thread that writes to it: writes block (a Bluetooth report can
|
||||
//! take milliseconds), so the game only hands over what the pad should do.
|
||||
use crate::{
|
||||
DEFAULT_LIGHTBAR, Output, PLAYER_1, TRIGGER_OFF, TriggerEffect, Vibration, is_dualsense,
|
||||
};
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
use crate::{DEFAULT_LIGHTBAR, Output, PLAYER_1, Vibration, is_dualsense};
|
||||
use crate::{TRIGGER_OFF, TriggerEffect};
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
use hidapi::{BusType, HidApi, HidDevice, HidResult};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
||||
use std::sync::mpsc::{self, RecvTimeoutError, Sender};
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::{AtomicU8, Ordering};
|
||||
use std::sync::mpsc::Sender;
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
use std::sync::mpsc::{self, RecvTimeoutError};
|
||||
use std::thread::JoinHandle;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Duration;
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Transport {
|
||||
@@ -17,6 +24,7 @@ pub enum Transport {
|
||||
}
|
||||
|
||||
/// An open DualSense.
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
pub struct DualSense {
|
||||
device: HidDevice,
|
||||
transport: Transport,
|
||||
@@ -34,6 +42,7 @@ pub fn bluetooth_allowed() -> bool {
|
||||
cfg!(target_os = "linux") || std::env::var_os("HORIZON_DUALSENSE_BT").is_some_and(|v| v == "1")
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
impl DualSense {
|
||||
/// The first DualSense hidapi lists, USB before Bluetooth (as SDL); `None` when there is
|
||||
/// none, an error when it can't be opened (Linux without access to its hidraw node).
|
||||
@@ -119,13 +128,17 @@ impl Default for State {
|
||||
/// A vibration: the motors' levels (left, right), each for a while, in order.
|
||||
pub type Rumble = Vec<([u8; 2], Duration)>;
|
||||
|
||||
// On iOS no thread reads the queue (the Link never opens); the variants stay so the
|
||||
// Link's API is the same everywhere.
|
||||
#[cfg_attr(target_os = "ios", allow(dead_code))]
|
||||
enum Message {
|
||||
State(State),
|
||||
Rumble(Rumble),
|
||||
Scan,
|
||||
}
|
||||
|
||||
/// The writer thread. Dropping it frees the triggers and stops the motors before it ends.
|
||||
/// The output thread. Dropping it frees the triggers and stops the motors before it ends; on
|
||||
/// iOS there is none (no hidapi backend) and the Link stays closed.
|
||||
pub struct Link {
|
||||
tx: Option<Sender<Message>>,
|
||||
/// 0: no pad open, else 1 + the transport.
|
||||
@@ -135,6 +148,7 @@ pub struct Link {
|
||||
|
||||
impl Link {
|
||||
/// Start the thread and look for a DualSense.
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
pub fn start() -> Link {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let open = Arc::new(AtomicU8::new(0));
|
||||
@@ -151,6 +165,16 @@ impl Link {
|
||||
}
|
||||
}
|
||||
|
||||
/// No output on iOS: hidapi has no backend there. The Link never opens.
|
||||
#[cfg(target_os = "ios")]
|
||||
pub fn start() -> Link {
|
||||
Link {
|
||||
tx: None,
|
||||
open: Arc::new(AtomicU8::new(0)),
|
||||
thread: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The pad's transport while one is open and taking reports.
|
||||
pub fn open(&self) -> Option<Transport> {
|
||||
match self.open.load(Ordering::Relaxed) {
|
||||
@@ -194,8 +218,10 @@ impl Drop for Link {
|
||||
|
||||
/// Looks for the pad this many more times, a second apart, after a scan finds nothing (its
|
||||
/// hidraw node may appear after the controller does).
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
const SCAN_TRIES: u32 = 5;
|
||||
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
struct Writer {
|
||||
api: Option<HidApi>,
|
||||
pad: Option<DualSense>,
|
||||
@@ -213,6 +239,7 @@ struct Writer {
|
||||
next_scan: Instant,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
enum Lights {
|
||||
/// Over Bluetooth, until the pad's clock says its animation is over (or this long after
|
||||
@@ -225,11 +252,13 @@ enum Lights {
|
||||
|
||||
/// The pad's sensor clock once its Bluetooth connection animation is over (SDL_hidapi_ps5.c's
|
||||
/// `HIDAPI_DriverPS5_CheckPendingLEDReset`).
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
const ANIMATION_OVER: u32 = 10_200_000;
|
||||
|
||||
/// The sensor clock of a Bluetooth input report 0x31: its state block starts at byte 2 and
|
||||
/// holds the clock at 27..31, little-endian (SDL's `PS5StatePacketCommon_t`, the kernel's
|
||||
/// `dualsense_input_report`).
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
fn bluetooth_clock(report: &[u8]) -> Option<u32> {
|
||||
match report {
|
||||
[0x31, _, state @ ..] if state.len() >= 31 => {
|
||||
@@ -239,6 +268,7 @@ fn bluetooth_clock(report: &[u8]) -> Option<u32> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
impl Writer {
|
||||
fn new(open: Arc<AtomicU8>) -> Self {
|
||||
Writer {
|
||||
@@ -451,7 +481,7 @@ impl Writer {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, not(target_os = "ios")))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//! No HD haptics on iOS: they play through the pad's own four-channel audio device over USB,
|
||||
//! which needs cpal, and cpal is left out there with hidapi (see Cargo.toml).
|
||||
|
||||
/// The pad's audio output, playing the queued samples (left, right actuator).
|
||||
pub struct Haptics;
|
||||
|
||||
impl Haptics {
|
||||
/// The DualSense's audio device, if one is there with its four channels (USB). A phone
|
||||
/// has none.
|
||||
pub fn open() -> Option<Haptics> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Play a vibration (heavy and light levels, 0..1, each for a while), replacing the one
|
||||
/// playing. Nothing plays on iOS.
|
||||
pub fn play(&self, _steps: &[(f32, f32, std::time::Duration)]) {}
|
||||
|
||||
/// Stop at once. Nothing plays on iOS.
|
||||
pub fn stop(&self) {}
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
//! The DualSense's output report, built by hand (docs/controllers.md "DualSense output"): the
|
||||
//! compatible-vibration motors, the adaptive triggers, the lightbar and the player LEDs. Gilrs
|
||||
//! keeps reading the pad; this crate only writes to it, over hidapi ([`device`]).
|
||||
//! On iOS the crate builds without hidapi, which has no backend there: [`Link`] never opens.
|
||||
//!
|
||||
//! The byte layout is the one documented by the Linux kernel's `hid-playstation.c` and SDL's
|
||||
//! `SDL_hidapi_ps5.c`: a 47-byte block shared by both transports, sent as report 0x02 over USB
|
||||
//! and as report 0x31 over Bluetooth, where a sequence tag leads it and a CRC-32 (seeded with
|
||||
//! the byte 0xA2) closes it.
|
||||
pub mod device;
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
pub mod haptics;
|
||||
#[cfg(target_os = "ios")]
|
||||
#[path = "haptics_stub.rs"]
|
||||
pub mod haptics;
|
||||
pub mod trigger;
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ pub mod component {
|
||||
pub const WRITABLE_BOOK_CONTENT: i32 = 56;
|
||||
pub const WRITTEN_BOOK_CONTENT: i32 = 57;
|
||||
pub const TRIM: i32 = 58;
|
||||
pub const FIREWORK_EXPLOSION: i32 = 70;
|
||||
pub const FIREWORKS: i32 = 71;
|
||||
}
|
||||
|
||||
/// A written book's content (`WrittenBookContent.STREAM_CODEC`): the
|
||||
@@ -89,6 +91,13 @@ pub enum Component {
|
||||
WrittenBook(WrittenBook),
|
||||
/// `ChargedProjectiles`: a loaded crossbow's ammunition, as templates.
|
||||
Stacks(Vec<Stack>),
|
||||
/// `Fireworks`: flight duration and its explosions.
|
||||
Fireworks {
|
||||
flight: i32,
|
||||
explosions: Vec<FireworkExplosion>,
|
||||
},
|
||||
/// `FireworkExplosion` (a firework star).
|
||||
FireworkExplosion(FireworkExplosion),
|
||||
/// `ArmorTrim` naming its material and pattern by registry id (`trim_material`,
|
||||
/// `trim_pattern`); a trim with a direct holder stays [`Component::Raw`].
|
||||
Trim {
|
||||
@@ -100,6 +109,41 @@ pub enum Component {
|
||||
Raw(Vec<u8>),
|
||||
}
|
||||
|
||||
/// `FireworkExplosion.STREAM_CODEC`: shape id, colors, fade colors, trail
|
||||
/// and twinkle (FireworkExplosion.Shape's BY_ID order).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct FireworkExplosion {
|
||||
pub shape: i32,
|
||||
pub colors: Vec<i32>,
|
||||
pub fade: Vec<i32>,
|
||||
pub trail: bool,
|
||||
pub twinkle: bool,
|
||||
}
|
||||
impl FireworkExplosion {
|
||||
fn read(r: &mut Reader) -> Result<Self> {
|
||||
let ints = |r: &mut Reader| -> Result<Vec<i32>> {
|
||||
let n = r.count(1024)?;
|
||||
(0..n).map(|_| r.i32()).collect()
|
||||
};
|
||||
Ok(Self {
|
||||
shape: r.varint()?,
|
||||
colors: ints(r)?,
|
||||
fade: ints(r)?,
|
||||
trail: r.bool()?,
|
||||
twinkle: r.bool()?,
|
||||
})
|
||||
}
|
||||
fn write(&self, w: &mut Writer) {
|
||||
w.varint(self.shape);
|
||||
w.varint(self.colors.len() as i32);
|
||||
self.colors.iter().for_each(|c| w.i32(*c));
|
||||
w.varint(self.fade.len() as i32);
|
||||
self.fade.iter().for_each(|c| w.i32(*c));
|
||||
w.bool(self.trail);
|
||||
w.bool(self.twinkle);
|
||||
}
|
||||
}
|
||||
|
||||
/// `Filterable.streamCodec`: the raw value, then an optional filtered one
|
||||
/// (dropped).
|
||||
fn filterable<T>(r: &mut Reader, value: impl Fn(&mut Reader) -> Result<T>) -> Result<T> {
|
||||
@@ -260,6 +304,17 @@ impl Component {
|
||||
hidden: (0..n).map(|_| r.varint()).collect::<Result<_>>()?,
|
||||
}
|
||||
}
|
||||
FIREWORKS => {
|
||||
let flight = r.varint()?;
|
||||
let n = r.count(256)?;
|
||||
Self::Fireworks {
|
||||
flight,
|
||||
explosions: (0..n)
|
||||
.map(|_| FireworkExplosion::read(r))
|
||||
.collect::<Result<_>>()?,
|
||||
}
|
||||
}
|
||||
FIREWORK_EXPLOSION => Self::FireworkExplosion(FireworkExplosion::read(r)?),
|
||||
// ArmorTrim.STREAM_CODEC: two holders, each a reference's id plus
|
||||
// one. A direct material or pattern has no registry name: read past.
|
||||
TRIM => {
|
||||
@@ -375,6 +430,12 @@ impl Component {
|
||||
w.varint(stacks.len() as i32);
|
||||
stacks.iter().for_each(|s| Template::write(s, w));
|
||||
}
|
||||
Self::Fireworks { flight, explosions } => {
|
||||
w.varint(*flight);
|
||||
w.varint(explosions.len() as i32);
|
||||
explosions.iter().for_each(|e| e.write(w));
|
||||
}
|
||||
Self::FireworkExplosion(e) => e.write(w),
|
||||
Self::WritableBook(pages) => {
|
||||
w.varint(pages.len() as i32);
|
||||
for page in pages {
|
||||
@@ -670,6 +731,44 @@ mod tests {
|
||||
round::<Option<Hashed>, HashedSlot>(None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fireworks_components_round_trip() {
|
||||
let mut rocket = Stack::new(42, 1);
|
||||
rocket.added.push((
|
||||
component::FIREWORKS,
|
||||
Component::Fireworks {
|
||||
flight: 3,
|
||||
explosions: vec![
|
||||
FireworkExplosion {
|
||||
shape: 4,
|
||||
colors: vec![0xff0000, 0x00ff00],
|
||||
fade: vec![0x0000ff],
|
||||
trail: true,
|
||||
twinkle: false,
|
||||
},
|
||||
FireworkExplosion {
|
||||
shape: 0,
|
||||
colors: vec![],
|
||||
fade: vec![],
|
||||
trail: false,
|
||||
twinkle: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
));
|
||||
rocket.added.push((
|
||||
component::FIREWORK_EXPLOSION,
|
||||
Component::FireworkExplosion(FireworkExplosion {
|
||||
shape: 2,
|
||||
colors: vec![7],
|
||||
fade: vec![],
|
||||
trail: false,
|
||||
twinkle: false,
|
||||
}),
|
||||
));
|
||||
round::<Option<Stack>, Slot>(Some(rocket));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn charged_projectiles_are_item_stack_templates() {
|
||||
// A crossbow (id 7) loaded with one arrow (id 9): ChargedProjectiles
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package dev.horizonlab.parity;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.component.ItemLore;
|
||||
import net.minecraft.world.item.component.TooltipDisplay;
|
||||
|
||||
/**
|
||||
* The styled lines {@code ItemLore.addToTooltip} adds, one stack (SNBT) per input
|
||||
* line. Each line is its visited spans ({@code text, colour, bold, italic,
|
||||
* underlined, strikethrough, obfuscated}); lines are separated by {@code ||}.
|
||||
*/
|
||||
public final class VanillaLoreTooltipOracle {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ParityData.init();
|
||||
var context = Item.TooltipContext.of(ParityData.lookup);
|
||||
var output = new ArrayList<String>();
|
||||
for (String line : Files.readAllLines(Path.of(args[0]))) {
|
||||
if (line.isBlank() || line.startsWith("#")) continue;
|
||||
var stack = ParityData.stack(line);
|
||||
var display = stack.getOrDefault(DataComponents.TOOLTIP_DISPLAY, TooltipDisplay.DEFAULT);
|
||||
ItemLore lore = stack.get(DataComponents.LORE);
|
||||
if (lore == null || !display.shows(DataComponents.LORE)) {
|
||||
output.add("-");
|
||||
continue;
|
||||
}
|
||||
var lines = new ArrayList<String>();
|
||||
lore.addToTooltip(context, component -> lines.add(spans(component)), TooltipFlag.NORMAL, stack);
|
||||
output.add(lines.isEmpty() ? "-" : String.join(" || ", lines));
|
||||
}
|
||||
Files.write(Path.of(args[1]), output);
|
||||
}
|
||||
|
||||
/** {@code Component.visit} from {@code Style.EMPTY}: the style a tooltip draws. */
|
||||
static String spans(Component component) {
|
||||
var out = new StringBuilder();
|
||||
component.visit((style, text) -> {
|
||||
if (text.isEmpty()) return Optional.empty();
|
||||
if (out.length() > 0) out.append(" | ");
|
||||
int color = style.getColor() == null ? -1 : style.getColor().getValue();
|
||||
out.append(text).append('\t').append(color).append('\t')
|
||||
.append(style.isBold()).append('\t')
|
||||
.append(style.isItalic()).append('\t')
|
||||
.append(style.isUnderlined()).append('\t')
|
||||
.append(style.isStrikethrough()).append('\t')
|
||||
.append(style.isObfuscated());
|
||||
return Optional.empty();
|
||||
}, Style.EMPTY);
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
+43
-6
@@ -968,13 +968,15 @@ links = ["#1709"]
|
||||
[[item]]
|
||||
id = "opengl-fallback"
|
||||
title = "OpenGL for old computers"
|
||||
status = "later"
|
||||
status = "shipped"
|
||||
shipped_in = "v0.2.63"
|
||||
area = "platforms"
|
||||
plain = "A way to play on old PCs and Linux machines that have no Vulkan or DirectX 12, through OpenGL."
|
||||
dev = """Players on older hardware ask whether Vulkan is the only way. Horizon draws with wgpu, which has an OpenGL \
|
||||
backend; what is needed is to see which features hold up on it, how fast it runs, and a launcher switch like \
|
||||
the DirectX 12 fallback that already ships."""
|
||||
links = ["docs/graphics.md"]
|
||||
plain = """Horizon now starts on old PCs whose graphics card has no Vulkan or DirectX 12 driver: it switches to OpenGL \
|
||||
by itself, and Options > Graphics can pick OpenGL by hand."""
|
||||
dev = """wgpu's GL backend (WGL on Windows, EGL on Linux) as the last fallback after Vulkan and DirectX 12 (#1917), \
|
||||
sprite arrays and CPU sprite animation for drivers without compute (#1920), no indirect draws below GL 4.3 \
|
||||
(#1936). Minimum OpenGL 3.3 core. Shader packs don't run on it yet."""
|
||||
links = ["#1917", "#1920", "#1936"]
|
||||
|
||||
[[item]]
|
||||
id = "phones-and-browser"
|
||||
@@ -1187,3 +1189,38 @@ plain = """The launcher's Servers page creates, starts, backs up and updates a H
|
||||
invites friends."""
|
||||
dev = """The launcher's Servers page (#1026) over `horizon-server` (docs/hosting.md)."""
|
||||
links = ["#1026", "docs/hosting.md"]
|
||||
|
||||
[[item]]
|
||||
id = "cli-server-install"
|
||||
title = "A server you install with one command"
|
||||
status = "next"
|
||||
area = "servers"
|
||||
plain = """Install and run a Horizon dedicated server from a terminal with a single command, no launcher needed, for \
|
||||
VPSes and headless machines."""
|
||||
dev = """A player's idea (#horizon-ideas). `horizon-server` already runs headless; left: an install script \
|
||||
(Linux/macOS shell, Windows PowerShell) that fetches the signed release, checks it, asks for or points at the \
|
||||
player's own game files and starts the server, documented in docs/hosting.md."""
|
||||
links = ["docs/hosting.md"]
|
||||
|
||||
[[item]]
|
||||
id = "launcher-look-menus"
|
||||
title = "Game menus in the launcher's style"
|
||||
status = "later"
|
||||
area = "extras"
|
||||
plain = """An optional look for the game's own menus and options that matches the Horizon launcher. Off by default: \
|
||||
the vanilla menus stay as they are."""
|
||||
dev = """A player's idea (#horizon-ideas). A built-in resource pack or a Horizon setting that restyles the title, \
|
||||
pause and options screens with the launcher's design tokens (crates/horizon-theme), following \
|
||||
docs/design-system.md; off by default because it changes the vanilla look."""
|
||||
links = ["docs/design-system.md"]
|
||||
|
||||
[[item]]
|
||||
id = "linux-packages"
|
||||
title = "AppImage and a Nix flake"
|
||||
status = "later"
|
||||
area = "platforms"
|
||||
plain = """Install Horizon on any Linux distribution as an AppImage, and on NixOS through a Nix flake."""
|
||||
dev = """A player's idea (#horizon-ideas). An AppImage of the launcher and game from the release workflow, and a \
|
||||
flake.nix packaging the release binaries with their runtime libraries (Vulkan loader, X11/Wayland, ALSA), \
|
||||
the way horizon-parity's NixOS setup runs them today."""
|
||||
links = []
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare item lore tooltip styles with the pinned vanilla client.
|
||||
|
||||
Vanilla prints what ``ItemLore.addToTooltip`` adds after ``ComponentUtils.mergeStyles``
|
||||
with dark purple italic (VanillaLoreTooltipOracle). Horizon prints what
|
||||
``item_tooltip::lore_texts`` gives (examples/probe/lore_tooltip_fixture).
|
||||
"""
|
||||
try:
|
||||
from . import lab, oracle_harness as harness
|
||||
except ImportError:
|
||||
import lab, oracle_harness as harness
|
||||
|
||||
# SNBT stacks. A lore line is a text component; italic:0b is an explicit false.
|
||||
CASES = [
|
||||
'{id:"minecraft:stick",count:1}',
|
||||
'{id:"minecraft:stick",count:1,components:{"minecraft:lore":[\'"Plain"\']}}',
|
||||
'{id:"minecraft:stick",count:1,components:{"minecraft:lore":[\'{"text":"Gold","color":"gold","italic":0b}\']}}',
|
||||
'{id:"minecraft:stick",count:1,components:{"minecraft:lore":[\'{"text":"A","extra":[{"text":"B","color":"aqua","italic":0b}]}\']}}',
|
||||
'{id:"minecraft:stick",count:1,components:{"minecraft:lore":[\'"One"\',\'{"text":"Two","bold":1b}\']}}',
|
||||
'{id:"minecraft:stick",count:1,components:{"minecraft:lore":[\'"Hidden"\'],"minecraft:tooltip_display":{hidden_components:["minecraft:lore"]}}}',
|
||||
'{id:"minecraft:stick",count:1,components:{"minecraft:lore":[\'{"text":"Line","underlined":1b,"strikethrough":1b}\']}}',
|
||||
]
|
||||
|
||||
|
||||
def cases(build):
|
||||
path = build / 'cases.txt'
|
||||
path.write_text(''.join(line + '\n' for line in CASES))
|
||||
return path, len(CASES)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
harness.differential(
|
||||
'lore-tooltip-parity', 'VanillaLoreTooltipOracle', 'lore_tooltip_fixture', cases,
|
||||
'Item lore tooltip lines: dark purple italic, child colours, explicit non-italic, and tooltip_display',
|
||||
sources=[
|
||||
lab.ROOT / 'crates/horizon-client/src/item_tooltip.rs',
|
||||
lab.ROOT / 'crates/horizon-client/src/item_data.rs',
|
||||
lab.ROOT / 'crates/horizon-client/src/text.rs',
|
||||
lab.ROOT / 'crates/horizon-client/src/component.rs',
|
||||
],
|
||||
expected_lines=len(CASES))
|
||||
@@ -964,13 +964,16 @@
|
||||
{
|
||||
"id": "opengl-fallback",
|
||||
"title": "OpenGL for old computers",
|
||||
"status": "later",
|
||||
"status": "shipped",
|
||||
"area": "platforms",
|
||||
"plain": "A way to play on old PCs and Linux machines that have no Vulkan or DirectX 12, through OpenGL.",
|
||||
"dev": "Players on older hardware ask whether Vulkan is the only way. Horizon draws with wgpu, which has an OpenGL backend; what is needed is to see which features hold up on it, how fast it runs, and a launcher switch like the DirectX 12 fallback that already ships.",
|
||||
"plain": "Horizon now starts on old PCs whose graphics card has no Vulkan or DirectX 12 driver: it switches to OpenGL by itself, and Options > Graphics can pick OpenGL by hand.",
|
||||
"dev": "wgpu's GL backend (WGL on Windows, EGL on Linux) as the last fallback after Vulkan and DirectX 12 (#1917), sprite arrays and CPU sprite animation for drivers without compute (#1920), no indirect draws below GL 4.3 (#1936). Minimum OpenGL 3.3 core. Shader packs don't run on it yet.",
|
||||
"links": [
|
||||
"docs/graphics.md"
|
||||
]
|
||||
"#1917",
|
||||
"#1920",
|
||||
"#1936"
|
||||
],
|
||||
"shipped_in": "v0.2.63"
|
||||
},
|
||||
{
|
||||
"id": "phones-and-browser",
|
||||
@@ -1202,6 +1205,37 @@
|
||||
"docs/hosting.md"
|
||||
],
|
||||
"shipped_in": "launcher-v0.15.0"
|
||||
},
|
||||
{
|
||||
"id": "cli-server-install",
|
||||
"title": "A server you install with one command",
|
||||
"status": "next",
|
||||
"area": "servers",
|
||||
"plain": "Install and run a Horizon dedicated server from a terminal with a single command, no launcher needed, for VPSes and headless machines.",
|
||||
"dev": "A player's idea (#horizon-ideas). `horizon-server` already runs headless; left: an install script (Linux/macOS shell, Windows PowerShell) that fetches the signed release, checks it, asks for or points at the player's own game files and starts the server, documented in docs/hosting.md.",
|
||||
"links": [
|
||||
"docs/hosting.md"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "launcher-look-menus",
|
||||
"title": "Game menus in the launcher's style",
|
||||
"status": "later",
|
||||
"area": "extras",
|
||||
"plain": "An optional look for the game's own menus and options that matches the Horizon launcher. Off by default: the vanilla menus stay as they are.",
|
||||
"dev": "A player's idea (#horizon-ideas). A built-in resource pack or a Horizon setting that restyles the title, pause and options screens with the launcher's design tokens (crates/horizon-theme), following docs/design-system.md; off by default because it changes the vanilla look.",
|
||||
"links": [
|
||||
"docs/design-system.md"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "linux-packages",
|
||||
"title": "AppImage and a Nix flake",
|
||||
"status": "later",
|
||||
"area": "platforms",
|
||||
"plain": "Install Horizon on any Linux distribution as an AppImage, and on NixOS through a Nix flake.",
|
||||
"dev": "A player's idea (#horizon-ideas). An AppImage of the launcher and game from the release workflow, and a flake.nix packaging the release binaries with their runtime libraries (Vulkan loader, X11/Wayland, ALSA), the way horizon-parity's NixOS setup runs them today.",
|
||||
"links": []
|
||||
}
|
||||
],
|
||||
"journal": [
|
||||
|
||||
Reference in New Issue
Block a user