Add the wither
Building a T of soul sand or soul soil under three wither skeleton skulls (upright along X or Z) summons the wither: eleven seconds of invulnerable charging that heal it and end in a power 7 blast, then flight toward its target while the centre head fires skulls on a ranged-attack clock and the side heads pick their own targets, blocks around it broken when hurt, regeneration, immunity to arrows below half health and to the undead, a purple boss bar with boss music, the nether star drop, its animation, texture and scale. Wither skulls fly like fireballs (blue ones keep their speed), hit for 8 with withering and explode. Block items such as heads aimed at a block are now placed instead of equipped. Vexes no longer drop their swords. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -246,6 +246,9 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
}
|
||||
map.insert("equipment".into(), Tag::Compound(equipment));
|
||||
}
|
||||
"minecraft:wither" => {
|
||||
map.insert("Invul".into(), Tag::Int(m.extra.counter));
|
||||
}
|
||||
"minecraft:ravager" => {
|
||||
map.insert("AttackTick".into(), Tag::Int(m.extra.counter));
|
||||
map.insert("StunTick".into(), Tag::Int(m.extra.counter2));
|
||||
@@ -413,6 +416,9 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
.unwrap_or(0) as u8;
|
||||
}
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Wither {
|
||||
m.extra.counter = number(tag.get("Invul")).unwrap_or(0) as i32;
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Ravager {
|
||||
m.extra.counter = number(tag.get("AttackTick")).unwrap_or(0) as i32;
|
||||
m.extra.counter2 = number(tag.get("StunTick")).unwrap_or(0) as i32;
|
||||
|
||||
@@ -58,6 +58,7 @@ mod tnt;
|
||||
mod totem;
|
||||
mod trading;
|
||||
mod trident;
|
||||
mod wither;
|
||||
use horizon_client::{
|
||||
Result,
|
||||
assets::Assets,
|
||||
@@ -1716,7 +1717,9 @@ impl Game<'_> {
|
||||
|| self.boost_firework(&stack)
|
||||
|| self.use_empty_map(&stack)
|
||||
|| self.use_book(&stack)
|
||||
|| self.equip_from_hand(&stack)
|
||||
// Block items (heads, carved pumpkins) aimed at a block are
|
||||
// placed first (useItemOn before useItem).
|
||||
|| (!(info.block.is_some() && self.pick().is_some()) && self.equip_from_hand(&stack))
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
@@ -1825,6 +1828,7 @@ impl Game<'_> {
|
||||
// BlockItem.place: the used statistic and the placed_block trigger.
|
||||
self.stats.add("used", &stack.item, 1);
|
||||
self.trigger_block("minecraft:placed_block", target, &stack);
|
||||
self.check_wither_spawn(target)?;
|
||||
self.consume_held();
|
||||
Ok(())
|
||||
}
|
||||
@@ -5491,11 +5495,13 @@ impl Game<'_> {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
// Equippable items swap into their armor slot (Equippable.swapWithEquipmentSlot).
|
||||
// Equippable items swap into their armor slot (Equippable.swapWithEquipmentSlot);
|
||||
// block items aimed at a block are placed instead.
|
||||
if let Some(slot) = self
|
||||
.res
|
||||
.items
|
||||
.get(&stack.item)
|
||||
.filter(|i| i.block.is_none())
|
||||
.and_then(|i| i.equip_slot.clone())
|
||||
{
|
||||
let index = match slot.as_str() {
|
||||
|
||||
@@ -619,6 +619,10 @@ impl Game<'_> {
|
||||
if m.extra.saddled {
|
||||
gear.push("minecraft:saddle");
|
||||
}
|
||||
// WitherBoss.dropCustomDeathLoot.
|
||||
if m.species() == Species::Wither {
|
||||
gear.push("minecraft:nether_star");
|
||||
}
|
||||
if m.extra.chested && horizon_client::mobs::equine::is_equine(m.species()) {
|
||||
gear.push("minecraft:chest");
|
||||
}
|
||||
@@ -633,8 +637,10 @@ impl Game<'_> {
|
||||
{
|
||||
let item = &m.extra.main_hand;
|
||||
// Equipment drop chance 8.5% (+ player kill only).
|
||||
// Vexes never drop their sword.
|
||||
if let Some(item) = item
|
||||
&& by_player
|
||||
&& m.species() != Species::Vex
|
||||
&& self.world.random.next_float() < 0.085
|
||||
{
|
||||
self.spawn_item(
|
||||
@@ -1517,6 +1523,13 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
},
|
||||
(ProjectileKind::WitherSkull { .. }, hit) => {
|
||||
let who = match hit {
|
||||
Hit::Entity { who, .. } => Some(who),
|
||||
_ => None,
|
||||
};
|
||||
self.wither_skull_hit(p, who, atp)?;
|
||||
}
|
||||
(ProjectileKind::ShulkerBullet { .. }, Hit::Block { .. }) => {
|
||||
self.audio
|
||||
.play("minecraft:entity.shulker_bullet.hit", Some(atp), 1.0, 1.0);
|
||||
@@ -2155,6 +2168,40 @@ impl Game<'_> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// WitherSkullRenderer: the skull model facing its flight.
|
||||
if let Some(dangerous) = super::wither::skull_kind(a) {
|
||||
static SKULL: std::sync::OnceLock<Option<horizon_client::mobs::Part>> =
|
||||
std::sync::OnceLock::new();
|
||||
let model = SKULL.get_or_init(|| {
|
||||
horizon_client::mobs::load_model(
|
||||
&self.options.resources,
|
||||
"minecraft:wither_skull#main",
|
||||
)
|
||||
});
|
||||
let tex = if dangerous {
|
||||
"entity/wither/wither_invulnerable"
|
||||
} else {
|
||||
"entity/wither/wither"
|
||||
};
|
||||
if let (Some(model), Some(r)) = (model, atlas.sprites.get(tex).copied()) {
|
||||
let mut poses = horizon_client::mobs::anim::Poses::new(model);
|
||||
poses.yrot("head", a.yaw.to_radians());
|
||||
poses.xrot("head", a.pitch.to_radians());
|
||||
let base = glam::Mat4::from_translation(c)
|
||||
* glam::Mat4::from_scale(glam::Vec3::new(-1.0, -1.0, 1.0));
|
||||
horizon_client::mobs::render::draw(
|
||||
model,
|
||||
base,
|
||||
&poses,
|
||||
[r.u0, r.v0, r.u1, r.v1],
|
||||
0xFFFF_FFFF,
|
||||
packed,
|
||||
0,
|
||||
out,
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let Some(name) = a.item_sprite() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -1841,12 +1841,11 @@ impl Game<'_> {
|
||||
}
|
||||
/// The boss bar (`BossHealthOverlay`): name and the pink progress bar.
|
||||
pub(super) fn draw_boss_bar(&self, batch: &mut HudBatch) {
|
||||
let Some(d) = self.dragon.as_ref() else {
|
||||
let dragon = self.dragon.as_ref().filter(|_| self.dim == Dim::End);
|
||||
self.draw_wither_bars(batch, if dragon.is_some() { 31.0 } else { 12.0 });
|
||||
let Some(d) = dragon else {
|
||||
return;
|
||||
};
|
||||
if self.dim != Dim::End {
|
||||
return;
|
||||
}
|
||||
let atlas = &self.res.atlas;
|
||||
let x = (batch.width / 2.0 - 91.0).floor();
|
||||
let y = 12.0;
|
||||
@@ -1866,7 +1865,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// `music.dragon` while the boss bar plays music.
|
||||
pub(super) fn boss_music(&self) -> bool {
|
||||
self.dim == Dim::End && self.dragon.is_some()
|
||||
self.dim == Dim::End && self.dragon.is_some() || self.wither_near()
|
||||
}
|
||||
}
|
||||
pub(super) struct DragonFireball {
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
//! The wither on the game side: building it (`WitherSkullBlock.checkSpawn`),
|
||||
//! its boss bar, and its skulls hitting and exploding.
|
||||
use super::Game;
|
||||
use horizon_client::{
|
||||
hud::{HudBatch, rgba},
|
||||
mobs::{Damage, DamageKind, Species, Who},
|
||||
projectiles::{Projectile, ProjectileKind},
|
||||
};
|
||||
|
||||
impl Game<'_> {
|
||||
fn is_wither_skull(&self, p: [i32; 3]) -> bool {
|
||||
let name = &*self.res.facts.get(self.world.block(p[0], p[1], p[2])).name;
|
||||
matches!(
|
||||
name,
|
||||
"minecraft:wither_skeleton_skull" | "minecraft:wither_skeleton_wall_skull"
|
||||
)
|
||||
}
|
||||
fn is_soul_base(&self, p: [i32; 3]) -> bool {
|
||||
let name = &*self.res.facts.get(self.world.block(p[0], p[1], p[2])).name;
|
||||
matches!(name, "minecraft:soul_sand" | "minecraft:soul_soil")
|
||||
}
|
||||
/// After a wither skeleton skull is placed: the T of soul sand (or soul
|
||||
/// soil) under three skulls, upright along X or Z, becomes a wither.
|
||||
pub(super) fn check_wither_spawn(&mut self, placed: [i32; 3]) -> horizon_client::Result<()> {
|
||||
if !self.is_wither_skull(placed) {
|
||||
return Ok(());
|
||||
}
|
||||
// Pattern rows top to bottom: "^^^", "###", "~#~" ('~' air).
|
||||
for (ax, az) in [(1, 0), (0, 1)] {
|
||||
for col in 0..3 {
|
||||
let left = [placed[0] - ax * col, placed[1], placed[2] - az * col];
|
||||
let at = |c: i32, row: i32| [left[0] + ax * c, left[1] - row, left[2] + az * c];
|
||||
let ok = (0..3).all(|c| self.is_wither_skull(at(c, 0)))
|
||||
&& (0..3).all(|c| self.is_soul_base(at(c, 1)))
|
||||
&& self.is_soul_base(at(1, 2))
|
||||
&& [0, 2].iter().all(|&c| {
|
||||
let p = at(c, 2);
|
||||
self.res.facts.is_air(self.world.block(p[0], p[1], p[2]))
|
||||
});
|
||||
if !ok {
|
||||
continue;
|
||||
}
|
||||
for row in 0..3 {
|
||||
for c in 0..3 {
|
||||
let p = at(c, row);
|
||||
let state = self.world.block(p[0], p[1], p[2]);
|
||||
if !self.res.facts.is_air(state) {
|
||||
self.destroy_particles(p, state);
|
||||
self.world.set(p[0], p[1], p[2], self.world.air)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
let base = at(1, 2);
|
||||
let at = [
|
||||
f64::from(base[0]) + 0.5,
|
||||
f64::from(base[1]) + 0.55,
|
||||
f64::from(base[2]) + 0.5,
|
||||
];
|
||||
if let Some(id) = self.spawn_mob("minecraft:wither", at, true)
|
||||
&& let Some(m) = self.mobs.iter_mut().find(|m| m.id == id)
|
||||
{
|
||||
let yaw = if ax == 1 { 0.0 } else { 90.0 };
|
||||
m.yaw = yaw;
|
||||
m.body_yaw = yaw;
|
||||
m.previous_body_yaw = yaw;
|
||||
m.head_yaw = yaw;
|
||||
horizon_client::mobs::wither::make_invulnerable(m);
|
||||
let view =
|
||||
self.mob_entity(&self.mobs.iter().find(|m| m.id == id).cloned().unwrap());
|
||||
self.trigger_entity("minecraft:summoned_entity", "entity", &view);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
/// The wither boss bars (purple, below the dragon's), within range.
|
||||
pub(super) fn draw_wither_bars(&self, batch: &mut HudBatch, mut y: f32) {
|
||||
let Some(p) = self.player.as_ref() else {
|
||||
return;
|
||||
};
|
||||
let atlas = &self.res.atlas;
|
||||
for m in self
|
||||
.mobs
|
||||
.iter()
|
||||
.filter(|m| m.species() == Species::Wither && m.alive())
|
||||
{
|
||||
if m.position.distance_squared(p.position) > 64.0 * 64.0 {
|
||||
continue;
|
||||
}
|
||||
let x = (batch.width / 2.0 - 91.0).floor();
|
||||
let progress = if m.extra.counter > 0 {
|
||||
1.0 - m.extra.counter as f32 / horizon_client::mobs::wither::INVULNERABLE as f32
|
||||
} else {
|
||||
(m.health / m.attrs.max_health).clamp(0.0, 1.0)
|
||||
};
|
||||
batch.sprite(atlas, "gui/sprites/boss_bar/purple_background", x, y);
|
||||
batch.sprite_part(
|
||||
atlas,
|
||||
"gui/sprites/boss_bar/purple_progress",
|
||||
x,
|
||||
y,
|
||||
progress,
|
||||
);
|
||||
let name = m
|
||||
.custom_name
|
||||
.clone()
|
||||
.unwrap_or_else(|| self.translate("entity.minecraft.wither", "Wither"));
|
||||
let w = HudBatch::text_width(atlas, &name);
|
||||
batch.text(
|
||||
atlas,
|
||||
&name,
|
||||
(batch.width / 2.0 - w / 2.0).floor(),
|
||||
y - 9.0,
|
||||
rgba(255, 255, 255, 255),
|
||||
true,
|
||||
);
|
||||
y += 19.0;
|
||||
}
|
||||
}
|
||||
pub(super) fn wither_near(&self) -> bool {
|
||||
self.player.as_ref().is_some_and(|p| {
|
||||
self.mobs.iter().any(|m| {
|
||||
m.species() == Species::Wither
|
||||
&& m.alive()
|
||||
&& m.position.distance_squared(p.position) <= 64.0 * 64.0
|
||||
})
|
||||
})
|
||||
}
|
||||
/// `WitherSkull.onHitEntity` / `onHit`: 8 damage (healing the wither 5
|
||||
/// when it kills), withering for 10 seconds, then a power 1 blast.
|
||||
pub(super) fn wither_skull_hit(
|
||||
&mut self,
|
||||
p: &Projectile,
|
||||
who: Option<Who>,
|
||||
at: [f64; 3],
|
||||
) -> horizon_client::Result<()> {
|
||||
let owner = match p.owner {
|
||||
Some(Who::Mob(id)) => Some(id),
|
||||
_ => None,
|
||||
};
|
||||
let amount = if owner.is_some() { 8.0 } else { 5.0 };
|
||||
match who {
|
||||
Some(Who::Player) => {
|
||||
if !self.creative {
|
||||
self.mob_hits_player_kind(
|
||||
amount,
|
||||
[p.previous.x, p.previous.y, p.previous.z],
|
||||
"minecraft:wither_skull",
|
||||
);
|
||||
self.give_player_effect("minecraft:wither", 200, 1);
|
||||
}
|
||||
}
|
||||
Some(Who::Mob(id)) => {
|
||||
let source = Damage {
|
||||
kind: DamageKind::Magic,
|
||||
attacker: p.owner,
|
||||
from: Some([p.previous.x, p.previous.y, p.previous.z]),
|
||||
};
|
||||
let killed = match self.mobs.iter_mut().find(|m| m.id == id) {
|
||||
Some(m) => {
|
||||
let hit = m.damage(amount, source);
|
||||
if hit && m.alive() && m.species() != Species::Wither {
|
||||
m.add_effect("minecraft:wither", 200, 1);
|
||||
}
|
||||
hit && !m.alive()
|
||||
}
|
||||
None => false,
|
||||
};
|
||||
if killed
|
||||
&& let Some(o) = owner
|
||||
&& let Some(w) = self.mobs.iter_mut().find(|m| m.id == o)
|
||||
{
|
||||
w.health = (w.health + 5.0).min(w.attrs.max_health);
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
if let Some(id) = owner {
|
||||
self.note_attacker("minecraft:explosion", id);
|
||||
}
|
||||
self.explode(at, 1.0)
|
||||
}
|
||||
}
|
||||
/// Wither skulls drawn as the skull model, blue when dangerous.
|
||||
pub(super) fn skull_kind(p: &Projectile) -> Option<bool> {
|
||||
match p.kind {
|
||||
ProjectileKind::WitherSkull { dangerous } => Some(dangerous),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ pub mod tame;
|
||||
pub mod undead;
|
||||
pub mod vex;
|
||||
pub mod witch;
|
||||
pub mod wither;
|
||||
mod world;
|
||||
|
||||
use crate::{blocks::BlockFacts, mesher::Vertex, world::World};
|
||||
@@ -443,6 +444,8 @@ pub struct Extra {
|
||||
pub using_item: i32,
|
||||
pub flag: bool,
|
||||
pub flag2: bool,
|
||||
/// Species scratch values (the wither's head targets and clocks).
|
||||
pub ints: [i32; 6],
|
||||
pub counter: i32,
|
||||
pub counter2: i32,
|
||||
pub home: Option<[i32; 3]>,
|
||||
|
||||
@@ -84,6 +84,7 @@ pub enum Family {
|
||||
Shulker,
|
||||
Vex,
|
||||
Ravager,
|
||||
Wither,
|
||||
}
|
||||
pub fn family(s: Species) -> Family {
|
||||
use Species as S;
|
||||
@@ -115,6 +116,7 @@ pub fn family(s: Species) -> Family {
|
||||
S::Pillager | S::Vindicator | S::Evoker => Family::Illager,
|
||||
S::Vex => Family::Vex,
|
||||
S::Ravager => Family::Ravager,
|
||||
S::Wither => Family::Wither,
|
||||
S::Piglin | S::PiglinBrute | S::Hoglin | S::Zoglin => Family::Piglin,
|
||||
S::Horse | S::Donkey | S::Mule | S::SkeletonHorse | S::ZombieHorse => Family::Equine,
|
||||
S::Phantom => Family::Phantom,
|
||||
@@ -157,10 +159,14 @@ pub fn register(m: &mut Mob) {
|
||||
Family::Shulker => super::shulker::register(m),
|
||||
Family::Vex => super::vex::register(m),
|
||||
Family::Ravager => super::ravager::register(m),
|
||||
Family::Wither => super::wither::register(m),
|
||||
}
|
||||
}
|
||||
/// Mob.tick additions that run before the entity tick (creeper fuse, puffing).
|
||||
fn pre_tick(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
if m.species() == Species::Wither && m.alive() {
|
||||
super::wither::steer(m);
|
||||
}
|
||||
match family(m.species()) {
|
||||
Family::Hostile => {
|
||||
if m.species() == Species::Creeper {
|
||||
@@ -544,6 +550,7 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
Species::Guardian | Species::ElderGuardian => super::guardian::ai_step(m, w, events),
|
||||
Species::Vex => super::vex::ai_step(m, w),
|
||||
Species::Ravager => super::ravager::ai_step(m, w, events),
|
||||
Species::Wither => super::wither::ai_step(m, w, events),
|
||||
Species::Shulker => {
|
||||
super::shulker::tick(m, w, events);
|
||||
super::shulker::ai_step(m, w, events);
|
||||
@@ -641,6 +648,7 @@ pub fn walk_target_value(m: &Mob, w: &MobWorld, p: [i32; 3]) -> f32 {
|
||||
/// Species damage filters (LivingEntity.hurtServer overrides).
|
||||
pub fn accepts_damage(m: &mut Mob, source: &Damage, _amount: f32) -> bool {
|
||||
match m.species() {
|
||||
Species::Wither => super::wither::accepts(m, source.kind, source.attacker, false),
|
||||
Species::Shulker => super::shulker::accepts(m, source),
|
||||
Species::Enderman => super::enderman::on_damage(m, source),
|
||||
Species::WitherSkeleton | Species::Blaze | Species::MagmaCube | Species::Strider
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::f32::consts::PI;
|
||||
/// The setupAnim implementation a model uses.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Anim {
|
||||
Wither,
|
||||
Vex,
|
||||
Ravager,
|
||||
Guardian,
|
||||
@@ -459,6 +460,7 @@ pub fn setup(
|
||||
Anim::Phantom => super::phantom::anim(m, s, p),
|
||||
Anim::Guardian => super::guardian::anim(m, s, p),
|
||||
Anim::Vex => super::vex::anim(m, s, p),
|
||||
Anim::Wither => super::wither::anim(m, s, p),
|
||||
Anim::Ravager => super::ravager::anim(m, s, p),
|
||||
Anim::Shulker => super::shulker::anim(m, s, p),
|
||||
Anim::Horse => {
|
||||
|
||||
@@ -557,6 +557,10 @@ impl Stroll {
|
||||
self.interval = i;
|
||||
self
|
||||
}
|
||||
/// WaterAvoidingRandomFlyingGoal (a nearby air position).
|
||||
pub fn flying(speed: f64) -> Self {
|
||||
Self::new(speed)
|
||||
}
|
||||
/// RandomSwimmingGoal(speed, interval)
|
||||
pub fn swimming(speed: f64, interval: i32) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -119,6 +119,7 @@ pub fn body(m: &Mob) -> (String, String) {
|
||||
),
|
||||
S::Shulker => ("shulker#main".into(), super::shulker::texture(m)),
|
||||
S::Vex => ("vex#main".into(), super::vex::texture(m).into()),
|
||||
S::Wither => ("wither#main".into(), super::wither::texture(m).into()),
|
||||
S::Ghast => (
|
||||
"ghast#main".into(),
|
||||
if m.extra.flag {
|
||||
@@ -582,6 +583,9 @@ fn species_rotations(m: &Mob, alpha: f32) -> glam::Mat4 {
|
||||
}
|
||||
fn species_scale(m: &Mob, alpha: f32) -> glam::Mat4 {
|
||||
match m.species() {
|
||||
Species::Wither => {
|
||||
glam::Mat4::from_scale(glam::Vec3::splat(super::wither::scale(m, alpha)))
|
||||
}
|
||||
Species::Creeper => {
|
||||
// CreeperRenderer.scale: swelling with a wobble.
|
||||
let s = ((m.previous_swell as f32 + (m.swell - m.previous_swell) as f32 * alpha)
|
||||
|
||||
@@ -79,6 +79,7 @@ pub enum Species {
|
||||
Evoker,
|
||||
Vex,
|
||||
Ravager,
|
||||
Wither,
|
||||
}
|
||||
/// Baby bounding boxes (each class's BABY_DIMENSIONS).
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -882,6 +883,20 @@ pub const ALL: &[Def] = &[
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
def!(
|
||||
Wither,
|
||||
"wither",
|
||||
"wither#main",
|
||||
"entity/wither/wither",
|
||||
A::Wither,
|
||||
[
|
||||
"entity.wither.ambient",
|
||||
"entity.wither.hurt",
|
||||
"entity.wither.death"
|
||||
],
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
def!(
|
||||
Ravager,
|
||||
"ravager",
|
||||
@@ -1169,6 +1184,7 @@ impl Def {
|
||||
| S::Phantom
|
||||
| S::ZombifiedPiglin
|
||||
| S::Zoglin
|
||||
| S::Wither
|
||||
);
|
||||
let aquatic = matches!(
|
||||
s,
|
||||
@@ -1198,6 +1214,7 @@ impl Def {
|
||||
| S::Frog
|
||||
| S::Slime
|
||||
| S::MagmaCube
|
||||
| S::Wither
|
||||
),
|
||||
flying: matches!(s, S::Ghast | S::Phantom),
|
||||
climber: matches!(s, S::Spider | S::CaveSpider),
|
||||
@@ -1214,6 +1231,7 @@ impl Def {
|
||||
| S::ZombifiedPiglin
|
||||
| S::Zoglin
|
||||
| S::Hoglin
|
||||
| S::Wither
|
||||
),
|
||||
burns_in_day: matches!(
|
||||
s,
|
||||
@@ -1288,6 +1306,7 @@ impl Def {
|
||||
| S::Evoker
|
||||
| S::Vex
|
||||
| S::Ravager
|
||||
| S::Wither
|
||||
)
|
||||
}
|
||||
/// The item tag Animal.isFood tests.
|
||||
|
||||
@@ -0,0 +1,374 @@
|
||||
//! The wither (`WitherBoss`): eleven seconds of invulnerable charging that
|
||||
//! end in a blast, then flying after its target while three heads fire
|
||||
//! skulls, breaking blocks around it when hurt, immune to arrows below half
|
||||
//! health.
|
||||
use super::{
|
||||
DamageKind, Mob, MobEvent, MobWorld, Species, Who,
|
||||
anim::{Poses, State},
|
||||
control::{MoveKind, rotlerp},
|
||||
goals::{
|
||||
Cx, Goal, HurtByTarget, JUMP, LOOK, LookAtPlayer, MOVE, NearestTarget, Prey,
|
||||
RandomLookAround, Stroll, goal_clone,
|
||||
},
|
||||
nav::NavKind,
|
||||
};
|
||||
use crate::projectiles::{Projectile, ProjectileKind};
|
||||
use horizon_core::{geometry::Vec3, random::RandomSource};
|
||||
|
||||
// Wither state: `counter` the invulnerable ticks, `counter2` the block
|
||||
// breaking clock, `point` the main target's position. `ints`: the side
|
||||
// heads' targets (mob id, -1 the player, 0 none), their next update ticks
|
||||
// and idle counts. AnimState slots 0-1 the side heads' yaw, 2-3 their pitch.
|
||||
pub const INVULNERABLE: i32 = 220;
|
||||
|
||||
pub fn register(m: &mut Mob) {
|
||||
m.ai.mov.kind = MoveKind::Flying {
|
||||
max_turn: 10.0,
|
||||
hovers: false,
|
||||
};
|
||||
m.ai.nav.kind = NavKind::Flying;
|
||||
m.persistent = true;
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(0, DoNothing);
|
||||
g.add(
|
||||
2,
|
||||
super::witch::RangedAttack::new(1.0, 40, 40, 20.0, |m, who, _, cx| {
|
||||
if let Some(t) = cx.w.target_info(who) {
|
||||
let at = [
|
||||
t.position.x,
|
||||
t.position.y + (t.eye_y - t.position.y) * 0.5,
|
||||
t.position.z,
|
||||
];
|
||||
let dangerous = m.random.next_float() < 0.001;
|
||||
shoot(m, 0, at, dangerous, cx.events);
|
||||
}
|
||||
}),
|
||||
);
|
||||
g.add(5, Stroll::flying(1.0));
|
||||
g.add(6, LookAtPlayer::new(8.0));
|
||||
g.add(7, RandomLookAround::default());
|
||||
m.ai.targets.add(1, HurtByTarget::new());
|
||||
m.ai.targets.add(
|
||||
2,
|
||||
NearestTarget::new(Prey::Filter(|s| !undead(s.species)), false).interval(0),
|
||||
);
|
||||
m.ai.targets
|
||||
.add(2, NearestTarget::player(false).interval(0));
|
||||
}
|
||||
/// `#wither_friends`: the undead.
|
||||
fn undead(s: Species) -> bool {
|
||||
matches!(
|
||||
s,
|
||||
Species::Zombie
|
||||
| Species::Husk
|
||||
| Species::Drowned
|
||||
| Species::ZombieVillager
|
||||
| Species::Skeleton
|
||||
| Species::Stray
|
||||
| Species::Bogged
|
||||
| Species::WitherSkeleton
|
||||
| Species::ZombieHorse
|
||||
| Species::SkeletonHorse
|
||||
| Species::Phantom
|
||||
| Species::ZombifiedPiglin
|
||||
| Species::Zoglin
|
||||
| Species::Wither
|
||||
)
|
||||
}
|
||||
/// `WitherDoNothingGoal`: still while charging.
|
||||
#[derive(Clone, Debug)]
|
||||
struct DoNothing;
|
||||
impl Goal for DoNothing {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE | JUMP | LOOK
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _cx: &mut Cx) -> bool {
|
||||
m.extra.counter > 0
|
||||
}
|
||||
}
|
||||
/// `WitherBoss.makeInvulnerable`: a third of its health, charging up.
|
||||
pub fn make_invulnerable(m: &mut Mob) {
|
||||
m.extra.counter = INVULNERABLE;
|
||||
m.health = m.attrs.max_health / 3.0;
|
||||
}
|
||||
pub fn powered(m: &Mob) -> bool {
|
||||
m.health <= m.attrs.max_health / 2.0
|
||||
}
|
||||
fn head_pos(m: &Mob, i: usize) -> [f64; 3] {
|
||||
if i == 0 {
|
||||
return [m.position.x, m.position.y + 3.0, m.position.z];
|
||||
}
|
||||
let a = (m.body_yaw + 180.0 * (i as f32 - 1.0)).to_radians();
|
||||
[
|
||||
m.position.x + f64::from(a.cos()) * 1.3,
|
||||
m.position.y + 2.2,
|
||||
m.position.z + f64::from(a.sin()) * 1.3,
|
||||
]
|
||||
}
|
||||
/// `performRangedAttack`: a skull from a head toward a point.
|
||||
fn shoot(m: &mut Mob, head: usize, at: [f64; 3], dangerous: bool, events: &mut Vec<MobEvent>) {
|
||||
let h = head_pos(m, head);
|
||||
// Level event 1024: the shoot sound.
|
||||
events.push(MobEvent::Sound(
|
||||
"entity.wither.shoot",
|
||||
h,
|
||||
2.0,
|
||||
(m.random.next_float() - m.random.next_float()) * 0.2 + 1.0,
|
||||
));
|
||||
let dir = [at[0] - h[0], at[1] - h[1], at[2] - h[2]];
|
||||
let p = Projectile::fireball(
|
||||
ProjectileKind::WitherSkull { dangerous },
|
||||
Vec3::new(h[0], h[1], h[2]),
|
||||
Some(Who::Mob(m.id)),
|
||||
dir,
|
||||
);
|
||||
events.push(MobEvent::Projectile(p));
|
||||
}
|
||||
/// `WitherBoss.aiStep` before travel: climb above and close in on the
|
||||
/// main target.
|
||||
pub fn steer(m: &mut Mob) {
|
||||
let mut v = Vec3::new(m.velocity.x, m.velocity.y * 0.6, m.velocity.z);
|
||||
if let (Some(t), Some(_)) = (m.extra.point, m.ai.target) {
|
||||
let mut yd = v.y;
|
||||
if m.position.y < t[1] || !powered(m) && m.position.y < t[1] + 5.0 {
|
||||
yd = yd.max(0.0);
|
||||
yd += 0.3 - yd * 0.6;
|
||||
}
|
||||
v.y = yd;
|
||||
let (dx, dz) = (t[0] - m.position.x, t[2] - m.position.z);
|
||||
if dx * dx + dz * dz > 9.0 {
|
||||
let len = (dx * dx + dz * dz).sqrt();
|
||||
v.x += dx / len * 0.3 - v.x * 0.6;
|
||||
v.z += dz / len * 0.3 - v.z * 0.6;
|
||||
}
|
||||
}
|
||||
m.velocity = v;
|
||||
if v.x * v.x + v.z * v.z > 0.05 {
|
||||
m.yaw = (v.z.atan2(v.x).to_degrees() as f32) - 90.0;
|
||||
}
|
||||
}
|
||||
fn target_pos(w: &MobWorld, id: i32) -> Option<([f64; 3], f64, bool)> {
|
||||
match id {
|
||||
-1 => w
|
||||
.player
|
||||
.as_ref()
|
||||
.filter(|p| p.alive && !p.creative && !p.spectator)
|
||||
.map(|p| ([p.position.x, p.position.y, p.position.z], p.eye[1], true)),
|
||||
0 => None,
|
||||
id => w
|
||||
.others
|
||||
.iter()
|
||||
.find(|s| s.id == id as u32 && s.alive)
|
||||
.map(|s| ([s.position.x, s.position.y, s.position.z], s.eye_y, false)),
|
||||
}
|
||||
}
|
||||
/// `WitherBoss.aiStep` (heads, particles) and `customServerAiStep`.
|
||||
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
m.extra.point = m
|
||||
.target_info(w)
|
||||
.map(|t| [t.position.x, t.position.y, t.position.z]);
|
||||
// Side heads turn toward their targets, else back to the body.
|
||||
for i in 0..2 {
|
||||
match target_pos(w, m.extra.ints[i]) {
|
||||
Some((p, eye, _)) => {
|
||||
let h = head_pos(m, i + 1);
|
||||
let (xd, yd, zd) = (p[0] - h[0], eye - h[1], p[2] - h[2]);
|
||||
let sd = (xd * xd + zd * zd).sqrt();
|
||||
let y_rot = (zd.atan2(xd).to_degrees() as f32) - 90.0;
|
||||
let x_rot = -(yd.atan2(sd).to_degrees() as f32);
|
||||
m.anim.v[2 + i] = rotlerp(m.anim.v[2 + i], x_rot, 40.0);
|
||||
m.anim.v[i] = rotlerp(m.anim.v[i], y_rot, 10.0);
|
||||
}
|
||||
None => m.anim.v[i] = rotlerp(m.anim.v[i], m.body_yaw, 10.0),
|
||||
}
|
||||
}
|
||||
for i in 0..3 {
|
||||
let h = head_pos(m, i);
|
||||
events.push(MobEvent::Particles {
|
||||
kind: "smoke",
|
||||
at: h,
|
||||
count: 0,
|
||||
});
|
||||
}
|
||||
if m.extra.counter > 0 {
|
||||
let left = m.extra.counter - 1;
|
||||
if left <= 0 {
|
||||
events.push(MobEvent::Explode(
|
||||
[m.position.x, m.eye_y(), m.position.z],
|
||||
7.0,
|
||||
));
|
||||
events.push(MobEvent::Sound(
|
||||
"entity.wither.spawn",
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
1.0,
|
||||
1.0,
|
||||
));
|
||||
}
|
||||
m.extra.counter = left;
|
||||
if m.age.is_multiple_of(10) {
|
||||
m.health = (m.health + 10.0).min(m.attrs.max_health);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// The side heads pick targets and fire on their own.
|
||||
let age = m.age as i32;
|
||||
for i in 1..3 {
|
||||
let k = i - 1;
|
||||
if age < m.extra.ints[2 + k] {
|
||||
continue;
|
||||
}
|
||||
m.extra.ints[2 + k] = age + 10 + m.random.next_int_bound(10).unwrap_or(0);
|
||||
m.extra.ints[4 + k] += 1;
|
||||
if m.extra.ints[4 + k] > 16 {
|
||||
let r = &mut m.random;
|
||||
let at = [
|
||||
m.position.x - 10.0 + r.next_double() * 20.0,
|
||||
m.position.y - 5.0 + r.next_double() * 10.0,
|
||||
m.position.z - 10.0 + r.next_double() * 20.0,
|
||||
];
|
||||
shoot(m, i + 1, at, true, events);
|
||||
m.extra.ints[4 + k] = 0;
|
||||
}
|
||||
let id = m.extra.ints[k];
|
||||
if id != 0 {
|
||||
match target_pos(w, id) {
|
||||
Some((p, eye, _))
|
||||
if (p[0] - m.position.x).powi(2)
|
||||
+ (p[1] - m.position.y).powi(2)
|
||||
+ (p[2] - m.position.z).powi(2)
|
||||
<= 900.0 =>
|
||||
{
|
||||
let at = [p[0], p[1] + (eye - p[1]) * 0.5, p[2]];
|
||||
shoot(m, i + 1, at, false, events);
|
||||
m.extra.ints[2 + k] = age + 40 + m.random.next_int_bound(20).unwrap_or(0);
|
||||
m.extra.ints[4 + k] = 0;
|
||||
}
|
||||
_ => m.extra.ints[k] = 0,
|
||||
}
|
||||
} else {
|
||||
// A random living thing within 20 (8 up or down), no undead.
|
||||
let p = m.position;
|
||||
let near = |q: Vec3| {
|
||||
(q.x - p.x).abs() <= 20.0 && (q.y - p.y).abs() <= 8.0 && (q.z - p.z).abs() <= 20.0
|
||||
};
|
||||
let mut found: Vec<i32> = w
|
||||
.others
|
||||
.iter()
|
||||
.filter(|s| s.alive && s.id != m.id && !undead(s.species) && near(s.position))
|
||||
.map(|s| s.id as i32)
|
||||
.collect();
|
||||
if let Some(pl) = &w.player
|
||||
&& pl.alive
|
||||
&& !pl.creative
|
||||
&& !pl.spectator
|
||||
&& near(pl.position)
|
||||
{
|
||||
found.push(-1);
|
||||
}
|
||||
if !found.is_empty() {
|
||||
let pick = m.random.next_int_bound(found.len() as i32).unwrap_or(0) as usize;
|
||||
m.extra.ints[k] = found[pick];
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.extra.counter2 > 0 {
|
||||
m.extra.counter2 -= 1;
|
||||
if m.extra.counter2 == 0 && w.mob_griefing {
|
||||
let width = (m.width() / 2.0 + 1.0).floor() as i32;
|
||||
let height = m.height().floor() as i32;
|
||||
let b = [
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
];
|
||||
let mut destroyed = false;
|
||||
for x in b[0] - width..=b[0] + width {
|
||||
for y in b[1]..=b[1] + height {
|
||||
for z in b[2] - width..=b[2] + width {
|
||||
let name = w.block_name(x, y, z);
|
||||
let immune = w
|
||||
.block_tags
|
||||
.get("minecraft:wither_immune")
|
||||
.is_some_and(|t| t.contains(name));
|
||||
if name != "minecraft:air" && !name.ends_with("_air") && !immune {
|
||||
events.push(MobEvent::BreakBlock {
|
||||
pos: [x, y, z],
|
||||
drop: true,
|
||||
});
|
||||
destroyed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if destroyed {
|
||||
events.push(MobEvent::Sound(
|
||||
"entity.wither.break_block",
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
1.0,
|
||||
1.0,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.age.is_multiple_of(20) {
|
||||
m.health = (m.health + 1.0).min(m.attrs.max_health);
|
||||
}
|
||||
}
|
||||
/// `WitherBoss.hurtServer` filter: not while charging, no arrows once
|
||||
/// powered, nothing from the undead.
|
||||
pub fn accepts(m: &mut Mob, kind: DamageKind, attacker: Option<Who>, others_undead: bool) -> bool {
|
||||
if m.extra.counter > 0 && kind != DamageKind::Generic {
|
||||
return false;
|
||||
}
|
||||
if powered(m) && kind == DamageKind::Arrow {
|
||||
return false;
|
||||
}
|
||||
if others_undead || matches!(attacker, Some(Who::Mob(id)) if id == m.id) {
|
||||
return false;
|
||||
}
|
||||
if m.extra.counter2 <= 0 {
|
||||
m.extra.counter2 = 20;
|
||||
}
|
||||
m.extra.ints[4] += 3;
|
||||
m.extra.ints[5] += 3;
|
||||
true
|
||||
}
|
||||
/// `WitherBossModel.setupAnim`.
|
||||
pub fn anim(m: &Mob, s: &State, p: &mut Poses) {
|
||||
let body =
|
||||
m.previous_body_yaw + super::living::wrap(m.body_yaw - m.previous_body_yaw) * s.partial;
|
||||
for (i, head) in ["right_head", "left_head"].into_iter().enumerate() {
|
||||
let y = m.anim.lerp(i, s.partial);
|
||||
let x = m.anim.lerp(2 + i, s.partial);
|
||||
p.yrot(head, (y - body).to_radians());
|
||||
p.xrot(head, x.to_radians());
|
||||
}
|
||||
let anim = (s.age * 0.1).cos();
|
||||
let rib = (0.065 + 0.05 * anim) * std::f32::consts::PI;
|
||||
p.xrot("ribcage", rib);
|
||||
let tail = p.get("tail");
|
||||
tail[0] = -2.0;
|
||||
tail[1] = 6.9 + rib.cos() * 10.0;
|
||||
tail[2] = -0.5 + rib.sin() * 10.0;
|
||||
p.xrot("tail", (0.265 + 0.1 * anim) * std::f32::consts::PI);
|
||||
p.yrot("center_head", s.y_rot.to_radians());
|
||||
p.xrot("center_head", s.x_rot.to_radians());
|
||||
}
|
||||
/// `WitherBossRenderer`: the blinking blue texture while charging.
|
||||
pub fn texture(m: &Mob) -> &'static str {
|
||||
let t = m.extra.counter;
|
||||
if t > 0 && (t > 80 || t / 5 % 2 != 1) {
|
||||
"entity/wither/wither_invulnerable"
|
||||
} else {
|
||||
"entity/wither/wither"
|
||||
}
|
||||
}
|
||||
/// `WitherBossRenderer.scale`: twice the model, smaller while charging.
|
||||
pub fn scale(m: &Mob, alpha: f32) -> f32 {
|
||||
let mut s = 2.0;
|
||||
if m.extra.counter > 0 {
|
||||
s -= (m.extra.counter as f32 - alpha) / INVULNERABLE as f32 * 0.5;
|
||||
}
|
||||
s
|
||||
}
|
||||
@@ -34,6 +34,10 @@ pub enum ProjectileKind {
|
||||
delta: [f64; 3],
|
||||
seed: u64,
|
||||
},
|
||||
/// `WitherSkull`: blue (dangerous) skulls keep their speed better.
|
||||
WitherSkull {
|
||||
dangerous: bool,
|
||||
},
|
||||
/// Splash potion thrown by witches: effect id, duration.
|
||||
Potion {
|
||||
effect: &'static str,
|
||||
@@ -122,13 +126,17 @@ impl Projectile {
|
||||
pub fn is_fireball(&self) -> bool {
|
||||
matches!(
|
||||
self.kind,
|
||||
ProjectileKind::SmallFireball | ProjectileKind::LargeFireball { .. }
|
||||
ProjectileKind::SmallFireball
|
||||
| ProjectileKind::LargeFireball { .. }
|
||||
| ProjectileKind::WitherSkull { .. }
|
||||
)
|
||||
}
|
||||
fn gravity(&self) -> f64 {
|
||||
match self.kind {
|
||||
ProjectileKind::Arrow { .. } => 0.05,
|
||||
ProjectileKind::SmallFireball | ProjectileKind::LargeFireball { .. } => 0.0,
|
||||
ProjectileKind::SmallFireball
|
||||
| ProjectileKind::LargeFireball { .. }
|
||||
| ProjectileKind::WitherSkull { .. } => 0.0,
|
||||
ProjectileKind::LlamaSpit => 0.06,
|
||||
ProjectileKind::Potion { .. } => 0.05,
|
||||
_ => 0.03,
|
||||
@@ -209,7 +217,6 @@ impl Projectile {
|
||||
self.yaw = v.x.atan2(v.z).to_degrees() as f32;
|
||||
self.pitch = v.y.atan2(sd).to_degrees() as f32;
|
||||
}
|
||||
/// One tick: returns whether to keep the projectile and what it hit.
|
||||
/// A shulker's bullet from its block toward `target`, first leaving
|
||||
/// along an axis other than the one it is attached on.
|
||||
pub fn shulker_bullet(
|
||||
@@ -446,6 +453,7 @@ impl Projectile {
|
||||
}
|
||||
(self.position.y > -128.0, Hit::None)
|
||||
}
|
||||
/// One tick: returns whether to keep the projectile and what it hit.
|
||||
pub fn tick(&mut self, w: &impl ProjectileWorld) -> (bool, Hit) {
|
||||
self.previous = self.position;
|
||||
self.age += 1;
|
||||
@@ -458,8 +466,15 @@ impl Projectile {
|
||||
}
|
||||
let water = w.in_water(self.position);
|
||||
match self.kind {
|
||||
ProjectileKind::SmallFireball | ProjectileKind::LargeFireball { .. } => {
|
||||
let inertia = if water { 0.8 } else { 0.95 };
|
||||
ProjectileKind::SmallFireball
|
||||
| ProjectileKind::LargeFireball { .. }
|
||||
| ProjectileKind::WitherSkull { .. } => {
|
||||
// WitherSkull.getInertia: 0.73 for dangerous skulls.
|
||||
let inertia = match self.kind {
|
||||
ProjectileKind::WitherSkull { dangerous: true } => 0.73,
|
||||
_ if water => 0.8,
|
||||
_ => 0.95,
|
||||
};
|
||||
let v = self.velocity;
|
||||
let len = (v.x * v.x + v.y * v.y + v.z * v.z).sqrt().max(1.0e-9);
|
||||
self.velocity = Vec3::new(
|
||||
@@ -581,6 +596,8 @@ impl Projectile {
|
||||
ProjectileKind::Potion { .. } => "item/splash_potion",
|
||||
ProjectileKind::LlamaSpit => "entity/llama/llama_spit",
|
||||
ProjectileKind::ShulkerBullet { .. } => "entity/shulker/spark",
|
||||
ProjectileKind::WitherSkull { dangerous: false } => "entity/wither/wither",
|
||||
ProjectileKind::WitherSkull { dangerous: true } => "entity/wither/wither_invulnerable",
|
||||
ProjectileKind::Arrow { .. } => return None,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user