Commit Graph

55 Commits

Author SHA1 Message Date
kedor
a11f40a403 chore: move ItemStack from pumpkin_world to pumpkin_data (#1944) 2026-03-31 10:08:41 +02:00
Alexander Medvedev
0635b048b5 Port to 26.1 2026-03-30 16:43:15 +02:00
Andrei Șugubete
a0ff7f46dc feat: Durability Overhaul (#1848)
* feat: broadcast EntityStatus when equipment breaks

Pumpkin did not play any sound or show break particles when a tool or
piece of armour reached zero durability. Vanilla sends a per-slot
EntityStatus packet (47-52, 65, 68) that every nearby client uses to
play the break sound and spawn break particles textured with the item
that just broke.

Changes
-------

player.rs – new damage_item_in_slot(slot, amount) method:
- Generalises the old damage_held_item to cover all EquipmentSlots:
  MainHand, OffHand, Head, Chest, Legs, Feet.
- Resolves the correct PlayerInventory slot index per slot (36-39 for
  armour, 40 for off-hand) consistent with build_equipment_slots().
- Sends the EntityStatus break packet BEFORE clearing the slot so
  clients can use the item texture for break particles.
- Bypasses sync_hand_slot (which only broadcast for hand slots) and
  instead calls enqueue_slot_set_packet + send_equipment_changes
  directly, ensuring armour equipment changes also propagate.
- damage_held_item is kept as a thin convenience wrapper.

apply_mending_from_xp – DRY refactor:
- Replaces three separate candidate-gathering blocks (main hand, off
  hand, armour loop) with a single unified slot_pairs list iterated
  once. Behaviour is identical.

living.rs – damage_armor_items:
- When a player takes hit damage, armour durability is reduced through
  LivingEntity::damage_armor_items, a separate code path from the
  player item-damage methods. This path now also broadcasts the
  EntityStatus break packet when an armour piece's durability hits zero.

entity/mod.rs – shared helper:
- Add equipment_break_status(slot) -> EntityStatus as a #[must_use]
  pub const fn. Eliminates the duplicated slot→status match that would
  otherwise exist in both call sites (player.rs and living.rs).

Tests (16 new)
--------------
- entity::tests::equipment_break_status_maps_all_slots – asserts every
  EquipmentSlot variant (including Body and Saddle) maps to its
  expected EntityStatus break variant.
- item::tests (15 tests) – first unit tests for ItemStack durability
  logic, covering damage_item_with_context (zero/negative amount,
  non-damageable item, unbreakable item, accumulation, stack break at
  max damage, over-damage) and repair_item (zero/negative amount,
  undamaged item, partial repair, cap at current damage, full repair
  clears the Damage component patch entry) and set_damage (negative
  value clamps to zero).

* refactor: use table-driven cases in damage_increases_damage_value test

* chore: make clippy happy

* refactor: the rest of damage and repair tests to use table-driven cases

* feat: broadcast EntityStatus when equipment breaks

- Implement strict packet ordering (EntityStatus before slot sync)
- Add break broadcast in play.rs use_on_block for all tools
- Generalize damage_item_in_slot to support all equipped slots
- Trim PR comments to 1-2 professional lines
- Convert equipment_break_status test to table-driven format
- Ensure vanilla parity per decompiled 1.21.11 EntityEvent mappings

* feat(item): durability overhaul — DamageResult, armor/weapon parity, elytra fix

pumpkin-world
- Add DamageResult enum (Untouched/Damaged/Broken) replacing bool return on
  damage_item_with_context and damage_item
- Elytra clamped at max_damage-1; never deleted from inventory
- Stacked item break correctly returns Broken regardless of remaining count
- Add is_axe/is_pickaxe/is_shovel/is_hoe tag-based predicates to ItemStack
- 21 new unit tests covering all cases (elytra, stacks, Unbreaking, categories)

pumpkin
- Armor damage type filter: bypasses_armor_durability() driven by the
  vanilla minecraft:bypasses_armor data tag (1.21.11); id-based u8 lookup
- Elytra worn in armor slot skipped from hit damage
- Thorns: extra +2 durability cost + 1-4 magic retaliation damage
- Weapon 2-durability cost: axes/pickaxes/shovels/hoes in combat
- Fix armor slot Unbreaking formula (is_armor_slot() gate)
- Fix stacked-item break broadcast (Broken not is_empty())
- Extract combat_weapon_durability_cost as sync fn; reuse existing lock
- 5 forward-compatible TODO one-liners for shield/trident/crossbow/fishing rod/brush

* fix(item): resolve vanilla parity issues in durability and combat tracking

- Move armor durability calculation to pre-absorption damage
- Fix Thorns damage range to uniform float [1.0, 5.0) and correct execution order
- Attribute Thorns damage to victim for correct combat tracking
- Refactor `damage_item` to auto-infer armor via `#minecraft:enchantable/armor`
- Decouple Elytra clamping from generic item damage loop into dedicated methods
- Add TODOs for DAMAGE_RESISTANT, post-attack effects, and data-driven bypasses

Also reformatted long comments to be concise and techincal

* chore: trigger CI rerun

* fix: shears no longer take durability damage when attacking mobs (refactor + codegen to standardize)

Replace hardcoded item-category checks in combat_weapon_durability_cost
with a data-driven lookup of the minecraft:weapon component.

- Add item_damage_per_attack field to WeaponImpl with DataComponentImpl
- Wire WeaponComponent deserialization into pumpkin-codegen item builder
- Regenerate item data so weapon durability values come from items.json
- Items without the Weapon component (e.g. shears) return 0 cost

* chore: retrigger CI

* refactor: Remove Thorns retaliation and trigger mechanics

- Remove Thorns enchantment trigger check and probability
- Remove Thorns extra +2 durability cost on armor
- Remove Thorns retaliation damage to attacker (1-5 magic damage)
- Remove Thorns combat attribution via damage_with_context
- Remove related imports and TODO comments
- Keep source parameter for future compatibility

* fix: glaring issues

- Fix WeaponImpl::read_data to actually read item_damage_per_attack from NBT
  instead of hardcoding 1; custom weapons now load correctly
- Remove unused _source parameter from damage_armor_items signature
- Move is_axe/is_pickaxe/is_shovel/is_hoe behind #[cfg(test)] since they're
  test-only helpers, keeping public API clean

* fix: elytra unbreaking and Pre-absorption Armor Test
Also a comment for clarity

* refactor: remove elytra scope creep: damage handling and related tests

* adjustment: tighten unbreaking test, update comments to be correct

* fix: clamp negative NBT, widen Unbreaking test, document elytra and shield-disable TODOs

* refactor: armor bypass logic: use bitmask, hoist lookups, optimize durability loop

* feat: Remove hardcoded Elytra armor check; use EquippableImpl::damage_on_hurt for data-driven durability logic.

* fix: add bitmask compile-time assert, clarify NBT clamping, document damage_on_hurt logic, rename slot_result, add #[must_use] to damage_item, and fix all unused result warnings.

* fix: clarify stacked item break edge, strengthen bitmask asserts, document NBT error handling, add TODOs for tool break handling and loop short-circuit, remove dead code and trident stub, note TOCTOU, and document test determinism. All tests passing.

* fix: Various

CRITICAL ITEMS:
  * bypasses_armor_durability correctness: Verified by existing test suite
    (validates all 19 bypass types return true, 12 physical types return false).
  * TOCTOU race in attack(): Enhanced documentation with 3 specific mitigation
    options and justification for single-player safety.
  * must_use suppressions: Removed #[must_use] from damage_item; added TODO to
    restore once all DamageResult::Broken handlers implement proper semantics.

SIGNIFICANT ITEMS:
  * DamageResult::Broken semantics: Updated doc comment to clarify that breaking
    always broadcasts correctly—whether consuming a single item or decrementing
    a stack. Callers need not split the enum.
  * Stacked item multi-break behavior: Verified matches vanilla (one break per
    call, never chains). Updated comment to document this as correct behavior,
    not a regression.
  * should_apply_durability_damage_with visibility: Made private to prevent
    incorrect unbreaking formula usage outside durability context.
  * Elytra exemption caching optimization: Added PERF comment noting O(1)
    component lookup is already efficient (max 4/hit). Deferred to dedicated
    caching architecture pass.

MINOR ITEMS:
  * Unbreaking test windows: Tightened from (500–1500) to (865–1135) for ±5σ
    confidence—catches actual formula regressions while remaining statistically
    sound. Updated both tool and armor tests.
  * WeaponImpl NBT error handling: Documented conservative fallback behavior
    (clamp negatives, default missing keys). Added TODO for tracing::warn! at
    higher-level call site.
  * default_item_damage naming: Renamed return_1u32 for consistency and clarity
    in weapon damage context.
  * WeaponImpl Hash collision prevention: Added struct-level NOTE reminding
    developers to update get_hash() if fields are added. Deferred until
    multi-field scenario (currently impossible with one field).

* fix: Resolve duplicate `return_1f32` and restore `#[must_use]` on `damage_item`

- Removed duplicate `return_1f32` function in `pumpkin-codegen/src/item.rs` to fix a compile blocker.
- Restored `#[must_use]` attribute on `damage_item` in `pumpkin-world/src/item/mod.rs` to enforce proper handling of `DamageResult`.
2026-03-15 14:17:18 +01:00
Rotstein
bf52dabd77 feat: add Vanilla powder snow behaviour (#1743)
* Powder snow now has vanilla behavior

* Fix rustfmt in player freeze tick update

* Fix right click armor equip slot; powder snow vanilla

* Apply rustfmt to powder snow changes

* Fix clippy warnings in powder snow changes

* Fix clippy pedantic warnings
2026-03-03 19:16:04 +01:00
Legends of Xania
a187220761 feat: Mob sunburn (#1767)
* move DestroyEggGoal

* make mob burn

* update imports

* update sun sensitive implementation

* update sun sensitive implementation

* fix clippy

* fix ci

* fix ci (again :,))

---------

Signed-off-by: Legends of Xania <legendsofxania@gmail.com>
2026-03-02 10:16:52 +01:00
RB007
c40ac36a65 fix: some entity effects and attributes system (#1526)
* fix: several effects (ticking and instant)

* chore: clippy and formatting

* fix: optimize send_attribute_update calls and stored active_effects

* feat: add infested support

* feat: per-entity attributes system

* refactor: clean up living.rs and apply some fixes

* feat: attributes system, absorption, and health boost!

* chore: clippy and formatting

* chore: oof

* chore: installed typos lol

* fix: updated some default attributes

* fix: glowing and invisibility

* fix: imports and proper base_damage

* fix: remove effect damage dupe from try_attack

* fix: bat default attributes

* fix: silverfish default attributes

* fix: check local attribute base first

* Remove erroneous comment (near glowing effect removal)

forgot to remove this after copying the block from add_effect 💀

* fix: update other mob default attributes
2026-02-27 17:51:33 +01:00
Richard Marshall
b72256b7b2 feat: enderman ai (#1579) 2026-02-24 02:58:55 +00:00
とぴ。(おーけ
44989c86f4 feat: More compatible Java Edition versions (>=1.21) (#1435)
* 1.21.9

* 771: 1.21.6

* 770: 1.21.5

* 769: 1.21.4

* better impl

* missing data

* 768: 1.21.2

* added >=1.21.2 mapping

* impl abstract remapper.

* added entity_id remap

* fix commands packet (<1.21.6)

* fix 1.21.4 level_chunk_with_light

* fix reading packet

* fix sneak <=1.21.6

* Merge branch 'master' into protocol

* fixed `level_chunk_with_light` packet (<=1.21.4)

* 767: 1.21

* fixed `login_finished` packet (<=1.21.1)

* fixed `login` packet (<=1.21.1)

* fixed `player_position` packet (<=1.21.1)

* fixed `set_held_slot` packet (<=1.21.1)

* fixed `set_time` packet (<=1.21.1)

---------

Signed-off-by: とぴ。(おーけ <support@topi-banana.com>
Co-authored-by: Alexander Medvedev <lilalexmed@proton.me>
2026-02-23 12:06:37 +01:00
Richard Marshall
296b8c23f9 owner hurt goals (#1608)
* owner hurt goals

* add distance check and can_attack_with_owner hook
2026-02-19 02:20:09 +00:00
Richard Marshall
654dbc7a18 breed goal (#1613)
* breed goal

* clippy fixes

* fix breeding cooldown, baby spawn position, and tick decrements

* add panicking check and update navigation every tick
2026-02-19 02:04:30 +00:00
Richard Marshall
41b4f286a5 follow owner goal (#1615)
* sheep ai (#1604)

* feat: sheep AI with wool color, eating grass, escape panic, and tempt

* fix: check both hands for tempt items

* beg goal (#1611)

* follow owner goal

* fix teleport validation and look target

* trigger ci
2026-02-19 01:38:28 +00:00
Richard Marshall
ad96041f09 sheep ai (#1604)
* feat: sheep AI with wool color, eating grass, escape panic, and tempt

* fix: check both hands for tempt items
2026-02-18 23:36:30 +00:00
Richard Marshall
ce46bf8e0e feat: creeper ai, explosion, and entity interaction (#1575)
* feat: add swim and wander around goals for creeper

* feat: implement creeper fuse countdown and explosion

* feat: add revenge goal and attacker tracking for mobs

* clean up code

* fix: mobs no longer target creative/spectator players

* feat: add creeper nbt persistence and swim depth check

* feat: flint and steel ignites creepers

* fix: creeper NBT parent call and attacker tracking ordering
2026-02-17 17:30:17 +00:00
Richard Marshall
c0aea8cf07 feat: bat ai (#1580)
* feat: bat ai with roosting, flying, and damage wake-up

* fix clippy

* fix: bat ai improvements matching vanilla behavior

- Move velo.y dampening into travel_in_air via get_y_velocity_drag
- Set bat gravity to 0 (vanilla bat travel has no gravity)
- Fix on_damage firing before damage validation
- Remove unused caller param from post_tick (eliminates Arc clone)
- Add ambient idle sounds every 80 ticks
- Pre-validate flight targets to avoid water, lava, and hazards
2026-02-17 15:50:55 +00:00
PrintedScript
8433f05094 fix: prevent mobs from attacking when already dead (#1549) 2026-02-15 16:31:29 +00:00
Alexander Medvedev
05763ea19c feat: add AI to more entities 2026-02-10 22:36:33 +01:00
vyPal
8b6c8bbee6 feat: Basic pathfinder impl from vanilla (#1456)
* Basic pathfinder impl from vanilla

* Satisfy clippy

* Forgot to save

* Fix compilation issues

* Finally fix clippy

* implement swing

* fix pathfinder a* algorithm, mob look system, and rotation packets

* fix cargo fmt

* implement zombie melee attack, fix a* target-reached threshold

* fix cargo fmt

* physics-based mob movement, position sync, and speed fixes

* fix mob step height

* made TargetPredicate more complete

---------

Co-authored-by: Alexander Medvedev <lilalexmed@proton.me>
Co-authored-by: Purdze <r.s.sutton@hotmail.co.uk>
2026-02-08 21:14:30 +01:00
Alexander Medvedev
53803c5e94 feat: add infested blocks & silverfish spawn
ofc also includes a bunch of other things like i always do :D
2026-02-05 19:34:04 +01:00
Alexander Medvedev
ac4c85192f chore: less ugly code
and less allocations
2026-01-26 22:23:58 +01:00
Alexander Medvedev
274c7e195d chore: don't spam so many packets
also use CancellationToken instead of Notify in some places
2026-01-21 00:22:13 +01:00
Alexander Medvedev
bcdde4526f fix: fixed entity knockback 2026-01-18 10:41:37 +01:00
Alexander Medvedev
49490237d4 chore: replaced rustyline-async with rustyline
also added console tab support
fixes https://github.com/Pumpkin-MC/Pumpkin/issues/429
2026-01-17 21:59:51 +01:00
Alexander Medvedev
3fbefafe4d feat: some more entity AI work 2026-01-17 19:26:25 +01:00
Alexander Medvedev
b8e0dc85e8 chore: batch some things together
also added DrownedEntity
2026-01-14 22:31:58 +01:00
Alexander Medvedev
a44a5babe3 feat: partially implement Stronghold
also fixed some bugs
2026-01-10 17:56:25 +01:00
Clicks
714e970292 feat: Sweet Berry Bushes (#1248)
* switch to btreemap to comply with lint

* amplifier i32 -> u8

* switch allow to expect lint

* remove many many unnecessary clippy lints

* dont use expect inside quotes

* beetroot chance 1/3

* prevent sugar cane from growing more than 3 high

* add sweet berry bush

* check for block above

* start nether warts

* nether warts with random ticks

* cargo fmt

* bamboo!

* pass when using bone meal on sweet berry bush with age < 3

* fix first two bamboo not being wide

* use early returns to flatten nesting

* switch damage and damage context to take references instead of arcs

* entity collision damage with sweet berry bush and campfire

* prevent panic and instead just reject placement if y < 0

* fix cactus growing and add cactus flowers

* cargo fmt
2026-01-03 13:44:20 +01:00
Clicks
70b3132396 chore: Remove Redundant Clippy Allows (#1247)
* switch to btreemap to comply with lint

* amplifier i32 -> u8

* switch allow to expect lint

* remove many many unnecessary clippy lints

* dont use expect inside quotes
2025-12-30 12:16:31 +01:00
Alexander Medvedev
ae751f3a83 remove #[async_trait] from many many places
Compile time got improved by 77% (including last commit)
2025-12-04 13:57:03 +01:00
unschlagbar
26fadedca2 Goal system rework (life saving)! (#1177)
* initial

* fixed incorect type

* fixed spelling
2025-09-28 10:19:03 +02:00
Alexander Medvedev
94bdae9684 feat: make totems work 2025-08-21 16:43:13 +02:00
Liyan Zhao
73c2c0115e Refactor entity argument (#1098)
* refactor: implement entity arguments

* refactor: use dyn EntityBase in EntitiesArgument, unify entities & players

[skip ci]

* refactor: use dyn EntityBase in EntitiesArgument, unify entities & players

[skip ci]

* refactor: use dyn EntityBase in EntitiesArgument, unify entities & players

[skip ci]

* refactor: use dyn EntityBase in EntitiesArgument, unify entities & players

[skip ci]

* refactor: use dyn EntityBase in EntitiesArgument, unify entities & players

[skip ci]

* refactor: use dyn EntityBase in EntitiesArgument, unify entities & players

* fix clippy

* feat: server.select_entities

* fix clippy

* fix clippy

* fix /kill

* fix /kill damage

* fix entity filter parsing

* type filtering

* chore

* fix entity argument

* fix clippy

* fix entity arg

* Update player.rs

* Update entities.rs

* Update entity_type.rs

* fix

* fix clippy

* fix kill
2025-08-03 12:10:21 +02:00
Alexander Medvedev
6e4a05d66d More Entity Physics work
Co-Authored-By: akashbeh <112662680+akashbeh@users.noreply.github.com>
2025-08-02 16:24:06 +02:00
TheDarkSword
fab33370b5 Implements some AI Goals for Zombie (#1011)
* Starting implementing AI goals

* Implement LookAtEntityGoal

* Implement ActiveTargetGoal

* Cleanup code

* Fix error when merging

* Implement LookAroundGoal

* Mob refactoring and implemented MoveToTargetPosGoal

* Implement StepAndDestroyBlockGoal

* Implement DestroyEggGoal

* cargo fmt

* Start implementation of Path and collisions

* Revert "Start implementation of Path and collisions"

This reverts commit 833941f4d1.

* Fix looking

* cargo fmt

* Implement priority

* fix clippy

* Implement mob moving with MeleeAttackGoal

* cargo fmt
2025-07-31 09:33:48 +02:00
Liyan Zhao
0e375434c5 Improve entity damage handling & entity name, Add death message & void damage, Weak reference to server in worlds. (#961)
* fix: enhance damage handling with context in LivingEntity

* feat: add out-of-world damage handling

Fix: #957

* fix: refine damage handling with context for entities

* fix: clippy

* feat: death message

* fix

* fix

* fix

* fix: review suggestions

* fix

* Update mod.rs

* fix display name

* fix display name

* fix clippy

* fix clippy

* fix

* fix

* fix world load

* fix logger timestamp

* fix logger timestamp

* fix compiling

* fix fall damage

* fix: pass fat ptr in damage_with_context

* refactor: Refactor commands to use styled name instead of plain text.

---------

Co-authored-by: Alexander Medvedev <lilalexmed@proton.me>
2025-07-28 18:07:52 +02:00
Alexander Medvedev
a31c9ec703 Implement Entity data Saving/Reading 2025-06-25 03:47:05 +02:00
Alexander Medvedev
f16d4a6247 Add Entity loot
not done, but works
2025-06-21 16:38:05 +02:00
Laurent Stéphenne
39e78a43fe Sleep and respawn point support (#799)
* Added bed block entity

* Player can sleep

* Format

* Respawn point works

* Clippy

* Added dimension support

* Sleeping works!

* Bed explodes when not in overworld

* Omg there was a packet missing

* Clippy

* Sleeping checks fully working!

* Clippy

* Wrong tick time

* Bruh mb
2025-06-09 16:13:53 +02:00
Alexander Medvedev
705ecfe221 Allow to enter other dimensions
a bit broken though
2025-05-18 14:59:01 +02:00
Alexander Medvedev
06c82c75f0 Multi Dimension refactor 2025-05-15 22:59:00 +02:00
Alexander Medvedev
4b9c92dff0 Cactus hurts now 2025-05-15 18:35:41 +02:00
Alexander Medvedev
be44ccc8df Don't require server when spawning a entity
Makes it much simpler
2025-03-02 16:05:31 +01:00
Alexander Medvedev
fe400e4970 Make non living entities not attackable
Adds a cool abstraction to progress damage, Now implementing End Crystals should be very easy
2025-02-26 22:48:19 +01:00
Alexander Medvedev
8aef30ee13 Make TNT Work (#590)
* make tnt work

* Spawn TNT at right position

* Fix tnt
2025-02-25 16:38:12 +01:00
Alexander Medvedev
1fb2be46d4 Update to Rust edition 2024 2025-02-20 18:42:20 +01:00
Alexander Medvedev
8a5a0cdee8 Drop item when destroying blocks
Also make EntityType consts
2025-02-07 21:20:03 +01:00
Alexander Medvedev
819e0c62ac Some more Item dropping work
And also some fixes
2025-01-31 23:21:24 +01:00
Alexander Medvedev
ef497fb435 Refactor World Entity System
Also support Item drops (WIP)
2025-01-31 21:45:20 +01:00
Alexander Medvedev
2fdf0777f6 Add Summon Command
Also refactor some things:

- Remove cmd_ prefix from commands
- Remove arg_ prefix from arguments
2025-01-26 20:06:20 +01:00
Kris
69cb3bb4f0 Add Mobs to Login Sequence (#488)
* Added mobs to login sequence

* Fix naming and add inital velocity
2025-01-26 15:42:55 +01:00
Alexander Medvedev
23dbb72bbe rename WorldPosition 2025-01-12 16:45:22 +01:00