From 92abb1e44e4fd154222f41cec40d1ee0f7a54fe6 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Thu, 14 May 2026 12:28:43 +0200 Subject: [PATCH] chore: less awaits more fun --- Cargo.lock | 4 +- Cargo.toml | 2 +- .../src/chunk_system/generation_cache.rs | 34 +- pumpkin-world/src/generation/proto_chunk.rs | 33 +- pumpkin-world/src/level.rs | 32 +- pumpkin-world/src/lighting/runtime.rs | 44 ++ pumpkin-world/src/world.rs | 20 +- .../block/blocks/abstract_wall_mounting.rs | 14 +- pumpkin/src/block/blocks/banners.rs | 12 +- pumpkin/src/block/blocks/barrel.rs | 2 +- pumpkin/src/block/blocks/beacon.rs | 2 +- pumpkin/src/block/blocks/bed.rs | 50 +- pumpkin/src/block/blocks/blast_furnace.rs | 4 +- pumpkin/src/block/blocks/brewing_stand.rs | 2 +- pumpkin/src/block/blocks/cake.rs | 18 +- pumpkin/src/block/blocks/campfire.rs | 4 +- pumpkin/src/block/blocks/candle_cakes.rs | 10 +- pumpkin/src/block/blocks/candles.rs | 28 +- pumpkin/src/block/blocks/carpet.rs | 28 +- pumpkin/src/block/blocks/carved_pumpkin.rs | 36 +- pumpkin/src/block/blocks/chests.rs | 68 +-- .../src/block/blocks/chiseled_bookshelf.rs | 18 +- pumpkin/src/block/blocks/command.rs | 59 +-- pumpkin/src/block/blocks/composter.rs | 12 +- pumpkin/src/block/blocks/dirt_path.rs | 14 +- pumpkin/src/block/blocks/doors.rs | 59 +-- pumpkin/src/block/blocks/dragon_egg.rs | 6 +- pumpkin/src/block/blocks/dripstone.rs | 107 ++-- pumpkin/src/block/blocks/enchanting_table.rs | 45 +- pumpkin/src/block/blocks/end_rod.rs | 3 +- pumpkin/src/block/blocks/ender_chest.rs | 12 +- pumpkin/src/block/blocks/falling.rs | 4 +- pumpkin/src/block/blocks/farmland.rs | 23 +- pumpkin/src/block/blocks/fence_gates.rs | 38 +- pumpkin/src/block/blocks/fences.rs | 8 +- pumpkin/src/block/blocks/fire/fire.rs | 133 ++--- pumpkin/src/block/blocks/fire/mod.rs | 77 ++- pumpkin/src/block/blocks/fire/soul_fire.rs | 10 +- pumpkin/src/block/blocks/furnace.rs | 4 +- pumpkin/src/block/blocks/glass_panes.rs | 8 +- pumpkin/src/block/blocks/grindstone.rs | 19 +- pumpkin/src/block/blocks/hopper.rs | 4 +- pumpkin/src/block/blocks/iron_bars.rs | 8 +- pumpkin/src/block/blocks/jukebox.rs | 29 +- pumpkin/src/block/blocks/ladder.rs | 36 +- pumpkin/src/block/blocks/lanterns.rs | 21 +- pumpkin/src/block/blocks/lectern.rs | 12 +- pumpkin/src/block/blocks/nether_portal.rs | 1 - pumpkin/src/block/blocks/note.rs | 34 +- pumpkin/src/block/blocks/piston/mod.rs | 14 +- pumpkin/src/block/blocks/piston/piston.rs | 63 +-- .../block/blocks/piston/piston_extension.rs | 2 +- .../src/block/blocks/piston/piston_head.rs | 8 +- pumpkin/src/block/blocks/plant/bamboo.rs | 59 +-- .../src/block/blocks/plant/bamboo_sapling.rs | 23 +- .../src/block/blocks/plant/big_dripleaf.rs | 35 +- .../block/blocks/plant/big_dripleaf_stem.rs | 16 +- pumpkin/src/block/blocks/plant/bush.rs | 6 +- pumpkin/src/block/blocks/plant/cactus.rs | 26 +- .../src/block/blocks/plant/cactus_flower.rs | 13 +- .../src/block/blocks/plant/chorus_flower.rs | 15 +- .../src/block/blocks/plant/chorus_plant.rs | 44 +- .../src/block/blocks/plant/crop/beetroot.rs | 11 +- pumpkin/src/block/blocks/plant/crop/carrot.rs | 11 +- .../blocks/plant/crop/gourds/attached_stem.rs | 10 +- .../block/blocks/plant/crop/gourds/stem.rs | 16 +- pumpkin/src/block/blocks/plant/crop/mod.rs | 23 +- .../block/blocks/plant/crop/nether_wart.rs | 20 +- .../src/block/blocks/plant/crop/potatoes.rs | 11 +- .../blocks/plant/crop/sweet_berry_bush.rs | 26 +- .../block/blocks/plant/crop/torch_flower.rs | 11 +- pumpkin/src/block/blocks/plant/crop/wheat.rs | 11 +- .../src/block/blocks/plant/dry_vegetation.rs | 14 +- pumpkin/src/block/blocks/plant/flower.rs | 6 +- pumpkin/src/block/blocks/plant/flowerbed.rs | 14 +- pumpkin/src/block/blocks/plant/fungus.rs | 14 +- pumpkin/src/block/blocks/plant/kelp.rs | 19 +- pumpkin/src/block/blocks/plant/leaf_litter.rs | 17 +- pumpkin/src/block/blocks/plant/lily_pad.rs | 12 +- pumpkin/src/block/blocks/plant/mod.rs | 9 +- .../src/block/blocks/plant/mushroom_plant.rs | 10 +- .../src/block/blocks/plant/nether_sprouts.rs | 10 +- pumpkin/src/block/blocks/plant/roots.rs | 13 +- pumpkin/src/block/blocks/plant/sapling.rs | 8 +- pumpkin/src/block/blocks/plant/sea_pickles.rs | 25 +- pumpkin/src/block/blocks/plant/seagrass.rs | 14 +- pumpkin/src/block/blocks/plant/segmented.rs | 8 +- pumpkin/src/block/blocks/plant/short_plant.rs | 6 +- .../src/block/blocks/plant/small_dripleaf.rs | 22 +- .../src/block/blocks/plant/spore_blossom.rs | 12 +- pumpkin/src/block/blocks/plant/sugar_cane.rs | 29 +- pumpkin/src/block/blocks/plant/tall_plant.rs | 43 +- .../src/block/blocks/plant/tall_seagrass.rs | 16 +- .../src/block/blocks/plant/twisting_vines.rs | 17 +- .../src/block/blocks/plant/weeping_vines.rs | 17 +- pumpkin/src/block/blocks/plant/wither_rose.rs | 10 +- pumpkin/src/block/blocks/powder_snow.rs | 2 +- pumpkin/src/block/blocks/pumpkin.rs | 6 +- .../blocks/redstone/abstract_redstone_gate.rs | 43 +- pumpkin/src/block/blocks/redstone/bell.rs | 72 ++- pumpkin/src/block/blocks/redstone/buttons.rs | 19 +- .../src/block/blocks/redstone/comparator.rs | 19 +- .../src/block/blocks/redstone/copper_bulb.rs | 34 +- .../blocks/redstone/daylight_detector.rs | 2 +- pumpkin/src/block/blocks/redstone/dropper.rs | 51 +- pumpkin/src/block/blocks/redstone/lever.rs | 17 +- pumpkin/src/block/blocks/redstone/mod.rs | 16 +- pumpkin/src/block/blocks/redstone/observer.rs | 2 +- .../blocks/redstone/pressure_plate/mod.rs | 6 +- .../blocks/redstone/pressure_plate/plate.rs | 8 +- .../redstone/pressure_plate/weighted.rs | 8 +- .../blocks/redstone/rails/activator_rail.rs | 49 +- .../src/block/blocks/redstone/rails/common.rs | 38 +- .../blocks/redstone/rails/detector_rail.rs | 4 +- .../src/block/blocks/redstone/rails/mod.rs | 18 +- .../blocks/redstone/rails/powered_rail.rs | 49 +- .../src/block/blocks/redstone/rails/rail.rs | 32 +- .../block/blocks/redstone/redstone_lamp.rs | 4 +- .../block/blocks/redstone/redstone_torch.rs | 47 +- .../block/blocks/redstone/redstone_wire.rs | 50 +- pumpkin/src/block/blocks/redstone/repeater.rs | 11 +- pumpkin/src/block/blocks/redstone/tripwire.rs | 9 +- .../block/blocks/redstone/tripwire_hook.rs | 59 +-- pumpkin/src/block/blocks/redstone/turbo.rs | 20 +- pumpkin/src/block/blocks/shulker_box.rs | 2 +- pumpkin/src/block/blocks/signs.rs | 117 ++--- pumpkin/src/block/blocks/skull_block.rs | 2 +- pumpkin/src/block/blocks/slabs.rs | 24 +- pumpkin/src/block/blocks/smoker.rs | 4 +- pumpkin/src/block/blocks/snow.rs | 14 +- pumpkin/src/block/blocks/sponge.rs | 42 +- pumpkin/src/block/blocks/stairs.rs | 22 +- pumpkin/src/block/blocks/tnt.rs | 16 +- pumpkin/src/block/blocks/torches.rs | 41 +- pumpkin/src/block/blocks/trapdoor.rs | 30 +- pumpkin/src/block/blocks/vine.rs | 93 ++-- pumpkin/src/block/blocks/walls.rs | 10 +- pumpkin/src/block/blocks/wither_skull.rs | 28 +- pumpkin/src/block/entities/barrel.rs | 26 +- pumpkin/src/block/entities/beacon.rs | 6 +- pumpkin/src/block/entities/bell.rs | 16 +- pumpkin/src/block/entities/brewing_stand.rs | 6 +- .../block/entities/chest_like_block_entity.rs | 18 +- .../src/block/entities/daylight_detector.rs | 2 +- pumpkin/src/block/entities/ender_chest.rs | 22 +- .../entities/furnace_like_block_entity.rs | 2 +- pumpkin/src/block/entities/hopper.rs | 10 +- pumpkin/src/block/entities/mob_spawner.rs | 30 +- pumpkin/src/block/entities/piston.rs | 4 +- pumpkin/src/block/entities/shulker_box.rs | 24 +- pumpkin/src/block/fluid/flowing_trait.rs | 24 +- pumpkin/src/block/fluid/lava.rs | 23 +- pumpkin/src/block/fluid/pathfinder.rs | 17 +- pumpkin/src/block/mod.rs | 8 +- pumpkin/src/block/registry.rs | 52 +- pumpkin/src/command/commands/difficulty.rs | 2 +- pumpkin/src/command/commands/fill.rs | 12 +- pumpkin/src/command/commands/particle.rs | 4 +- pumpkin/src/command/commands/setblock.rs | 2 +- pumpkin/src/command/commands/summon.rs | 2 +- pumpkin/src/command/commands/tick.rs | 15 +- pumpkin/src/command/commands/weather.rs | 12 +- pumpkin/src/command/commands/worldborder.rs | 18 +- pumpkin/src/command/mod.rs | 2 +- pumpkin/src/entity/ai/goal/avoid_entity.rs | 24 +- pumpkin/src/entity/ai/goal/beg.rs | 11 +- pumpkin/src/entity/ai/goal/blaze_attack.rs | 5 +- pumpkin/src/entity/ai/goal/breed.rs | 17 +- pumpkin/src/entity/ai/goal/chase_player.rs | 4 +- pumpkin/src/entity/ai/goal/creeper_ignite.rs | 10 +- pumpkin/src/entity/ai/goal/destroy_egg.rs | 32 +- pumpkin/src/entity/ai/goal/eat_grass.rs | 10 +- pumpkin/src/entity/ai/goal/escape_danger.rs | 4 +- pumpkin/src/entity/ai/goal/follow_owner.rs | 42 +- pumpkin/src/entity/ai/goal/follow_parent.rs | 2 +- pumpkin/src/entity/ai/goal/look_around.rs | 2 +- pumpkin/src/entity/ai/goal/look_at_entity.rs | 2 +- pumpkin/src/entity/ai/goal/melee_attack.rs | 10 +- .../src/entity/ai/goal/move_to_target_pos.rs | 2 +- pumpkin/src/entity/ai/goal/pick_up_block.rs | 8 +- pumpkin/src/entity/ai/goal/place_block.rs | 6 +- .../entity/ai/goal/step_and_destroy_block.rs | 23 +- .../entity/ai/goal/teleport_towards_player.rs | 8 +- pumpkin/src/entity/ai/goal/tempt.rs | 4 +- pumpkin/src/entity/ai/goal/wander_around.rs | 4 +- pumpkin/src/entity/ai/goal/zombie_attack.rs | 6 +- .../ai/pathfinder/pathfinding_context.rs | 36 +- .../ai/pathfinder/walk_node_evaluator.rs | 23 +- pumpkin/src/entity/area_effect_cloud.rs | 23 +- pumpkin/src/entity/boss/ender_dragon.rs | 28 +- .../entity/boss/ender_dragon/phase/dying.rs | 36 +- pumpkin/src/entity/boss/wither.rs | 4 +- pumpkin/src/entity/breath.rs | 40 +- pumpkin/src/entity/combat.rs | 50 +- pumpkin/src/entity/decoration/armor_stand.rs | 68 +-- pumpkin/src/entity/decoration/end_crystal.rs | 14 +- pumpkin/src/entity/experience_orb.rs | 5 +- pumpkin/src/entity/falling.rs | 16 +- pumpkin/src/entity/item.rs | 55 +- pumpkin/src/entity/living.rs | 242 ++++----- pumpkin/src/entity/mob/bat.rs | 41 +- pumpkin/src/entity/mob/blaze.rs | 6 +- pumpkin/src/entity/mob/breeze.rs | 6 +- pumpkin/src/entity/mob/cave_spider.rs | 4 +- pumpkin/src/entity/mob/creaking.rs | 6 +- pumpkin/src/entity/mob/creeper.rs | 57 +- pumpkin/src/entity/mob/elder_guardian.rs | 6 +- pumpkin/src/entity/mob/enderman.rs | 93 ++-- pumpkin/src/entity/mob/endermite.rs | 6 +- pumpkin/src/entity/mob/evoker.rs | 6 +- pumpkin/src/entity/mob/ghast.rs | 6 +- pumpkin/src/entity/mob/giant.rs | 6 +- pumpkin/src/entity/mob/guardian.rs | 6 +- pumpkin/src/entity/mob/hoglin.rs | 6 +- pumpkin/src/entity/mob/illusioner.rs | 6 +- pumpkin/src/entity/mob/magma_cube.rs | 4 +- pumpkin/src/entity/mob/mod.rs | 141 ++--- pumpkin/src/entity/mob/phantom.rs | 4 +- pumpkin/src/entity/mob/piglin.rs | 6 +- pumpkin/src/entity/mob/piglin_brute.rs | 6 +- pumpkin/src/entity/mob/pillager.rs | 6 +- pumpkin/src/entity/mob/ravager.rs | 6 +- pumpkin/src/entity/mob/shulker.rs | 150 +++--- pumpkin/src/entity/mob/silverfish.rs | 6 +- pumpkin/src/entity/mob/skeleton/bogged.rs | 4 +- pumpkin/src/entity/mob/skeleton/mod.rs | 12 +- pumpkin/src/entity/mob/skeleton/parched.rs | 4 +- pumpkin/src/entity/mob/skeleton/skeleton.rs | 4 +- pumpkin/src/entity/mob/skeleton/stray.rs | 4 +- pumpkin/src/entity/mob/skeleton/wither.rs | 8 +- pumpkin/src/entity/mob/slime.rs | 6 +- pumpkin/src/entity/mob/spider.rs | 6 +- pumpkin/src/entity/mob/vex.rs | 6 +- pumpkin/src/entity/mob/vindicator.rs | 6 +- pumpkin/src/entity/mob/warden.rs | 6 +- pumpkin/src/entity/mob/witch.rs | 6 +- pumpkin/src/entity/mob/zoglin.rs | 6 +- pumpkin/src/entity/mob/zombie/drowned.rs | 6 +- pumpkin/src/entity/mob/zombie/husk.rs | 4 +- pumpkin/src/entity/mob/zombie/mod.rs | 6 +- pumpkin/src/entity/mob/zombie/zombie.rs | 6 +- .../src/entity/mob/zombie/zombie_villager.rs | 4 +- pumpkin/src/entity/mob/zombified_piglin.rs | 6 +- pumpkin/src/entity/mod.rs | 348 +++++------- pumpkin/src/entity/passive/allay.rs | 4 +- pumpkin/src/entity/passive/armadillo.rs | 4 +- pumpkin/src/entity/passive/axolotl.rs | 4 +- pumpkin/src/entity/passive/bee.rs | 4 +- pumpkin/src/entity/passive/camel.rs | 4 +- pumpkin/src/entity/passive/cat.rs | 4 +- pumpkin/src/entity/passive/chicken.rs | 32 +- pumpkin/src/entity/passive/cod.rs | 4 +- pumpkin/src/entity/passive/cow.rs | 32 +- pumpkin/src/entity/passive/dolphin.rs | 4 +- pumpkin/src/entity/passive/donkey.rs | 4 +- pumpkin/src/entity/passive/fox.rs | 4 +- pumpkin/src/entity/passive/frog.rs | 4 +- pumpkin/src/entity/passive/glow_squid.rs | 4 +- pumpkin/src/entity/passive/goat.rs | 4 +- pumpkin/src/entity/passive/horse.rs | 4 +- pumpkin/src/entity/passive/iron_golem.rs | 6 +- pumpkin/src/entity/passive/llama.rs | 4 +- pumpkin/src/entity/passive/mooshroom.rs | 4 +- pumpkin/src/entity/passive/mule.rs | 4 +- pumpkin/src/entity/passive/ocelot.rs | 4 +- pumpkin/src/entity/passive/panda.rs | 4 +- pumpkin/src/entity/passive/parrot.rs | 4 +- pumpkin/src/entity/passive/pig.rs | 32 +- pumpkin/src/entity/passive/polar_bear.rs | 6 +- pumpkin/src/entity/passive/pufferfish.rs | 4 +- pumpkin/src/entity/passive/rabbit.rs | 4 +- pumpkin/src/entity/passive/salmon.rs | 4 +- pumpkin/src/entity/passive/sheep.rs | 47 +- pumpkin/src/entity/passive/skeleton_horse.rs | 4 +- pumpkin/src/entity/passive/sniffer.rs | 4 +- pumpkin/src/entity/passive/snow_golem.rs | 6 +- pumpkin/src/entity/passive/squid.rs | 4 +- pumpkin/src/entity/passive/strider.rs | 4 +- pumpkin/src/entity/passive/tadpole.rs | 4 +- pumpkin/src/entity/passive/trader_llama.rs | 4 +- pumpkin/src/entity/passive/tropical_fish.rs | 4 +- pumpkin/src/entity/passive/turtle.rs | 4 +- pumpkin/src/entity/passive/villager/mod.rs | 86 ++- .../src/entity/passive/wandering_trader.rs | 4 +- pumpkin/src/entity/passive/wolf.rs | 4 +- pumpkin/src/entity/passive/zombie_horse.rs | 4 +- pumpkin/src/entity/player.rs | 374 ++++++------- pumpkin/src/entity/projectile/arrow.rs | 26 +- pumpkin/src/entity/projectile/egg.rs | 32 +- pumpkin/src/entity/projectile/ender_pearl.rs | 41 +- pumpkin/src/entity/projectile/eye_of_ender.rs | 32 +- .../src/entity/projectile/firework_rocket.rs | 53 +- .../src/entity/projectile/fishing_bobber.rs | 56 +- .../src/entity/projectile/lingering_potion.rs | 35 +- pumpkin/src/entity/projectile/mod.rs | 2 +- .../src/entity/projectile/shulker_bullet.rs | 137 +++-- pumpkin/src/entity/projectile/snowball.rs | 15 +- .../src/entity/projectile/splash_potion.rs | 35 +- pumpkin/src/entity/tnt.rs | 33 +- pumpkin/src/entity/type.rs | 195 ++++--- pumpkin/src/entity/vehicle/boat.rs | 58 +- pumpkin/src/item/items/armor_stand.rs | 14 +- pumpkin/src/item/items/axe.rs | 4 +- pumpkin/src/item/items/boat.rs | 4 +- pumpkin/src/item/items/bow.rs | 4 +- pumpkin/src/item/items/bucket.rs | 36 +- pumpkin/src/item/items/crossbow.rs | 28 +- pumpkin/src/item/items/dye.rs | 12 +- pumpkin/src/item/items/egg.rs | 14 +- pumpkin/src/item/items/end_crystal.rs | 6 +- pumpkin/src/item/items/ender_eye.rs | 26 +- pumpkin/src/item/items/ender_pearl.rs | 14 +- pumpkin/src/item/items/firework_rocket.rs | 4 +- pumpkin/src/item/items/fishing_rod.rs | 26 +- pumpkin/src/item/items/glowing_ink_sac.rs | 12 +- pumpkin/src/item/items/hoe.rs | 9 +- pumpkin/src/item/items/honeycomb.rs | 5 +- pumpkin/src/item/items/ignite/fire_charge.rs | 4 +- pumpkin/src/item/items/ignite/ignition.rs | 12 +- pumpkin/src/item/items/ink_sac.rs | 12 +- pumpkin/src/item/items/minecart.rs | 2 +- pumpkin/src/item/items/name_tag.rs | 4 +- pumpkin/src/item/items/potions.rs | 28 +- pumpkin/src/item/items/shovel.rs | 8 +- pumpkin/src/item/items/snowball.rs | 14 +- pumpkin/src/item/items/spawn_egg.rs | 4 +- pumpkin/src/item/items/wind_charge.rs | 12 +- pumpkin/src/item/potion.rs | 2 +- pumpkin/src/net/bedrock/mod.rs | 19 + pumpkin/src/net/bedrock/play.rs | 4 +- pumpkin/src/net/java/mod.rs | 31 ++ pumpkin/src/net/java/play.rs | 164 +++--- pumpkin/src/net/mod.rs | 24 +- .../loader/wasm/wasm_host/wit/v0_1/entity.rs | 2 +- .../loader/wasm/wasm_host/wit/v0_1/player.rs | 8 +- .../wasm/wasm_host/wit/v0_1/scoreboard.rs | 46 +- .../loader/wasm/wasm_host/wit/v0_1/world.rs | 63 +-- pumpkin/src/server/mod.rs | 19 +- pumpkin/src/server/tick_rate_manager.rs | 55 +- pumpkin/src/server/ticker.rs | 2 +- pumpkin/src/world/border.rs | 41 +- pumpkin/src/world/dragon_fight.rs | 27 +- pumpkin/src/world/explosion.rs | 12 +- pumpkin/src/world/map.rs | 8 +- pumpkin/src/world/mod.rs | 494 ++++++++---------- pumpkin/src/world/natural_spawner.rs | 155 ++---- pumpkin/src/world/portal/end.rs | 20 +- pumpkin/src/world/portal/nether.rs | 89 ++-- pumpkin/src/world/scoreboard.rs | 156 +++--- pumpkin/src/world/weather.rs | 36 +- 350 files changed, 3888 insertions(+), 4927 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9aa498e02..dace72112 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -886,9 +886,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crossfire" -version = "3.1.10" +version = "3.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebed7d0a3a92ebc771f880516a5eecef5942a0fc67855dc4f30e719b04c77ac5" +checksum = "72bdfcf389b100bb85fcf39ad434f67b617813cf0608095c905b79f6b2194aea" dependencies = [ "crossbeam-utils", "futures-core", diff --git a/Cargo.toml b/Cargo.toml index 6cbedfefc..d01674336 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -120,7 +120,7 @@ console-subscriber = { version = "0.5.0", default-features = false } crc-fast = "1.10.0" criterion = { version = "0.8", default-features = false } crossbeam-utils = "0.8.21" -crossfire = { version = "3.1.10", features = ["compat"] } +crossfire = { version = "3.1.12", features = ["compat"] } crypto-bigint = "0.7.3" dashmap = "6.1" ecdsa = "0.16.9" diff --git a/pumpkin-world/src/chunk_system/generation_cache.rs b/pumpkin-world/src/chunk_system/generation_cache.rs index 3bfd58868..74eba0212 100644 --- a/pumpkin-world/src/chunk_system/generation_cache.rs +++ b/pumpkin-world/src/chunk_system/generation_cache.rs @@ -15,8 +15,6 @@ use pumpkin_nbt::compound::NbtCompound; use pumpkin_util::HeightMap; use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::vector3::Vector3; -use std::future::Future; -use std::pin::Pin; use tracing::debug; pub struct Cache { @@ -45,35 +43,21 @@ impl HeightLimitView for Cache { } impl BlockAccessor for Cache { - fn get_block<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { GenerationCache::get_block_state(self, &position.0).to_block() }) + fn get_block(&self, position: &BlockPos) -> &'static Block { + GenerationCache::get_block_state(self, &position.0).to_block() } - fn get_block_state<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { GenerationCache::get_block_state(self, &position.0).to_state() }) + fn get_block_state(&self, position: &BlockPos) -> &'static BlockState { + GenerationCache::get_block_state(self, &position.0).to_state() } - fn get_block_state_id<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { GenerationCache::get_block_state(self, &position.0).0 }) + fn get_block_state_id(&self, position: &BlockPos) -> BlockStateId { + GenerationCache::get_block_state(self, &position.0).0 } - fn get_block_and_state<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { - let id = GenerationCache::get_block_state(self, &position.0); - (id.to_block(), id.to_state()) - }) + fn get_block_and_state(&self, position: &BlockPos) -> (&'static Block, &'static BlockState) { + let state = GenerationCache::get_block_state(self, &position.0); + (state.to_block(), state.to_state()) } } diff --git a/pumpkin-world/src/generation/proto_chunk.rs b/pumpkin-world/src/generation/proto_chunk.rs index 919a8b344..a39c1b7cd 100644 --- a/pumpkin-world/src/generation/proto_chunk.rs +++ b/pumpkin-world/src/generation/proto_chunk.rs @@ -1,4 +1,3 @@ -use std::pin::Pin; use std::sync::Arc; use pumpkin_data::block_properties::is_air; @@ -1362,34 +1361,20 @@ impl ProtoChunk { } impl BlockAccessor for ProtoChunk { - fn get_block<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { self.get_block_state(&position.0).to_block() }) + fn get_block(&self, position: &BlockPos) -> &'static Block { + self.get_block_state(&position.0).to_block() } - fn get_block_state<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { self.get_block_state(&position.0).to_state() }) + fn get_block_state(&self, position: &BlockPos) -> &'static BlockState { + self.get_block_state(&position.0).to_state() } - fn get_block_state_id<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { self.get_block_state(&position.0).0 }) + fn get_block_state_id(&self, position: &BlockPos) -> BlockStateId { + self.get_block_state(&position.0).0 } - fn get_block_and_state<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { - let id = self.get_block_state(&position.0); - BlockState::from_id_with_block(id.0) - }) + fn get_block_and_state(&self, position: &BlockPos) -> (&'static Block, &'static BlockState) { + let id = self.get_block_state(&position.0); + BlockState::from_id_with_block(id.0) } } diff --git a/pumpkin-world/src/level.rs b/pumpkin-world/src/level.rs index b3d31225a..cceb14fb3 100644 --- a/pumpkin-world/src/level.rs +++ b/pumpkin-world/src/level.rs @@ -711,20 +711,6 @@ impl Level { RawBlockState(id.unwrap_or(Block::VOID_AIR.default_state.id)) } - pub async fn get_rough_biome(self: &Arc, position: &BlockPos) -> &'static Biome { - let (chunk_coordinate, relative) = position.chunk_and_chunk_relative_position(); - let id = self - .get_or_fetch_chunk(chunk_coordinate, |chunk| { - chunk.section.get_rough_biome_absolute_y( - relative.x as usize, - relative.y, - relative.z as usize, - ) - }) - .await; - Biome::from_id(id.unwrap_or(0)).unwrap_or(&Biome::THE_VOID) - } - pub async fn set_block_state( self: &Arc, position: &BlockPos, @@ -798,6 +784,18 @@ impl Level { self.loaded_chunks.get(coordinates).map(|x| f(x.value())) } + pub fn get_rough_biome(&self, position: &BlockPos) -> &'static Biome { + let (chunk_coordinate, relative) = position.chunk_and_chunk_relative_position(); + let id = self.read_chunk_sync(&chunk_coordinate, |chunk| { + chunk.section.get_rough_biome_absolute_y( + relative.x as usize, + relative.y, + relative.z as usize, + ) + }); + Biome::from_id(id.flatten().unwrap_or(0)).unwrap_or(&Biome::THE_VOID) + } + pub fn read_entity_chunk_sync R>( &self, coordinates: &Vector2, @@ -808,6 +806,12 @@ impl Level { .map(|x| f(x.value())) } + pub fn get_entity_chunk_sync(&self, pos: &Vector2) -> Option { + self.loaded_entity_chunks + .get(pos) + .map(|x| x.value().clone()) + } + pub async fn get_or_fetch_entity_chunk R>( self: &Arc, pos: Vector2, diff --git a/pumpkin-world/src/lighting/runtime.rs b/pumpkin-world/src/lighting/runtime.rs index 5e03d6529..ceafeedc1 100644 --- a/pumpkin-world/src/lighting/runtime.rs +++ b/pumpkin-world/src/lighting/runtime.rs @@ -445,6 +445,50 @@ impl DynamicLightEngine { } } + pub fn get_block_light_level_sync(&self, level: &Level, position: &BlockPos) -> Option { + let (chunk_pos, relative) = position.chunk_and_chunk_relative_position(); + + level.read_chunk_sync(&chunk_pos, |chunk| { + let section_idx = (relative.y - chunk.section.min_y) as usize / 16; + let light_engine = chunk.light_engine.lock().ok()?; + + light_engine + .block_light + .get(section_idx)? + .get( + relative.x as usize, + (relative.y - chunk.section.min_y) as usize % 16, + relative.z as usize, + ) + .into() + })? + } + + pub fn get_sky_light_level_sync(&self, level: &Level, position: &BlockPos) -> u8 { + let (chunk_coordinate, relative) = position.chunk_and_chunk_relative_position(); + level + .read_chunk_sync(&chunk_coordinate, |chunk| { + let section_index = + (relative.y - chunk.section.min_y) as usize / BlockPalette::SIZE; + + let light_engine = chunk + .light_engine + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + // Bounds check for section index (lock the light engine) + if section_index >= light_engine.sky_light.len() { + return 15; + } + + light_engine.sky_light[section_index].get( + relative.x as usize, + (relative.y - chunk.section.min_y) as usize % BlockPalette::SIZE, + relative.z as usize, + ) + }) + .unwrap_or(0) + } + pub async fn get_block_light_level( &self, level: &Arc, diff --git a/pumpkin-world/src/world.rs b/pumpkin-world/src/world.rs index 915cac2cf..293492b3c 100644 --- a/pumpkin-world/src/world.rs +++ b/pumpkin-world/src/world.rs @@ -74,23 +74,11 @@ pub trait WorldPortalExt: Send + Sync { } pub trait BlockAccessor: Send + Sync { - fn get_block<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>>; + fn get_block(&self, position: &BlockPos) -> &'static Block; - fn get_block_state<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>>; + fn get_block_state(&self, position: &BlockPos) -> &'static BlockState; - fn get_block_state_id<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>>; + fn get_block_state_id(&self, position: &BlockPos) -> BlockStateId; - fn get_block_and_state<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>>; + fn get_block_and_state(&self, position: &BlockPos) -> (&'static Block, &'static BlockState); } diff --git a/pumpkin/src/block/blocks/abstract_wall_mounting.rs b/pumpkin/src/block/blocks/abstract_wall_mounting.rs index 878854b5d..ad7aab43d 100644 --- a/pumpkin/src/block/blocks/abstract_wall_mounting.rs +++ b/pumpkin/src/block/blocks/abstract_wall_mounting.rs @@ -53,12 +53,10 @@ pub trait WallMountedBlock: Send + Sync { world: &'a dyn BlockAccessor, pos: &'a BlockPos, direction: BlockDirection, - ) -> BlockFuture<'a, bool> { - Box::pin(async move { - let block_pos = pos.offset(direction.to_offset()); - let block_state = world.get_block_state(&block_pos).await; - block_state.is_side_solid(direction.opposite()) - }) + ) -> bool { + let block_pos = pos.offset(direction.to_offset()); + let block_state = world.get_block_state(&block_pos); + block_state.is_side_solid(direction.opposite()) } fn get_state_for_neighbor_update<'a>( @@ -67,9 +65,7 @@ pub trait WallMountedBlock: Send + Sync { ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { if self.get_direction(args.state_id, args.block).opposite() == args.direction - && !self - .can_place_at(args.world, args.position, args.direction) - .await + && !self.can_place_at(args.world, args.position, args.direction) { Block::AIR.default_state.id } else { diff --git a/pumpkin/src/block/blocks/banners.rs b/pumpkin/src/block/blocks/banners.rs index befb1ac26..8fc142ed0 100644 --- a/pumpkin/src/block/blocks/banners.rs +++ b/pumpkin/src/block/blocks/banners.rs @@ -21,13 +21,13 @@ impl BlockBehaviour for BannerBlock { }) } - fn can_place_at<'a>(&'a self, args: crate::block::CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: crate::block::CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -40,7 +40,7 @@ impl BlockBehaviour for BannerBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -50,7 +50,7 @@ impl BlockBehaviour for BannerBlock { } } -async fn can_place_at(world: &dyn BlockAccessor, position: &BlockPos) -> bool { - let state = world.get_block_state(&position.down()).await; +fn can_place_at(world: &dyn BlockAccessor, position: &BlockPos) -> bool { + let state = world.get_block_state(&position.down()); state.is_solid() } diff --git a/pumpkin/src/block/blocks/barrel.rs b/pumpkin/src/block/blocks/barrel.rs index f56ef1658..38da7befe 100644 --- a/pumpkin/src/block/blocks/barrel.rs +++ b/pumpkin/src/block/blocks/barrel.rs @@ -60,7 +60,7 @@ impl BlockBehaviour for BarrelBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(inventory) = block_entity.get_inventory() { args.player diff --git a/pumpkin/src/block/blocks/beacon.rs b/pumpkin/src/block/blocks/beacon.rs index 7baeb581b..174200f89 100644 --- a/pumpkin/src/block/blocks/beacon.rs +++ b/pumpkin/src/block/blocks/beacon.rs @@ -51,7 +51,7 @@ pub struct BeaconBlock; impl BlockBehaviour for BeaconBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let block_entity = args.world.get_block_entity(args.position).await; + let block_entity = args.world.get_block_entity(args.position); // Extract the inventory from the entity let Some(inventory) = block_entity.and_then(BlockEntity::get_inventory) else { diff --git a/pumpkin/src/block/blocks/bed.rs b/pumpkin/src/block/blocks/bed.rs index 5e5cc6bb3..05d99591b 100644 --- a/pumpkin/src/block/blocks/bed.rs +++ b/pumpkin/src/block/blocks/bed.rs @@ -70,23 +70,19 @@ const NO_SLEEP_IDS: &[u16] = &[ pub struct BedBlock; impl BlockBehaviour for BedBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - if let Some(player) = args.player { - let facing = player.living_entity.entity.get_horizontal_facing(); - return args + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + if let Some(player) = args.player { + let facing = player.living_entity.entity.get_horizontal_facing(); + return args + .block_accessor + .get_block_state(args.position) + .replaceable() + && args .block_accessor - .get_block_state(args.position) - .await - .replaceable() - && args - .block_accessor - .get_block_state(&args.position.offset(facing.to_offset())) - .await - .replaceable(); - } - false - }) + .get_block_state(&args.position.offset(facing.to_offset())) + .replaceable(); + } + false } fn on_landed_upon<'a>(&'a self, args: OnLandedUponArgs<'a>) -> BlockFuture<'a, ()> { @@ -150,7 +146,7 @@ impl BlockBehaviour for BedBlock { args.position.offset(bed_props.facing.to_offset()) }; - let neighbor_block_id = args.world.get_block_state_id(&other_half_pos).await; + let neighbor_block_id = args.world.get_block_state_id(&other_half_pos); if neighbor_block_id != args.block.id { args.world.update_neighbors(&other_half_pos, None).await; return; @@ -180,7 +176,7 @@ impl BlockBehaviour for BedBlock { // If the block is being replaced with air (i.e., broken), the `broken` callback // will handle breaking the other half with the correct drop flags. Only handle it here // if the block is being replaced with something else (e.g., piston movement). - let new_state_id = args.world.get_block_state_id(args.position).await; + let new_state_id = args.world.get_block_state_id(args.position); let new_block = Block::from_state_id(new_state_id); if new_block == &Block::AIR { return; @@ -194,7 +190,7 @@ impl BlockBehaviour for BedBlock { args.position.offset(bed_props.facing.to_offset()) }; - let (other_block, other_state) = args.world.get_block_and_state(&other_half_pos).await; + let (other_block, other_state) = args.world.get_block_and_state(&other_half_pos); if other_block == args.block { let other_props = BedProperties::from_state_id(other_state.id, other_block); if other_props.part != bed_props.part { @@ -213,7 +209,7 @@ impl BlockBehaviour for BedBlock { #[expect(clippy::too_many_lines)] fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let bed_props = BedProperties::from_state_id(state_id, args.block); let (bed_head_pos, bed_foot_pos) = if bed_props.part == BedPart::Head { @@ -246,16 +242,8 @@ impl BlockBehaviour for BedBlock { } // Make sure the bed is not obstructed - if args - .world - .get_block_state(&bed_head_pos.up()) - .await - .is_solid() - || args - .world - .get_block_state(&bed_foot_pos.up()) - .await - .is_solid() + if args.world.get_block_state(&bed_head_pos.up()).is_solid() + || args.world.get_block_state(&bed_foot_pos.up()).is_solid() { args.player .send_system_message_raw( @@ -370,7 +358,7 @@ impl BlockBehaviour for BedBlock { } } - args.player.sleep(bed_head_pos).await; + args.player.sleep(bed_head_pos); Self::set_occupied(true, args.world, args.block, args.position, state_id).await; BlockActionResult::SuccessServer diff --git a/pumpkin/src/block/blocks/blast_furnace.rs b/pumpkin/src/block/blocks/blast_furnace.rs index 4dc521dd6..4c5080d9b 100644 --- a/pumpkin/src/block/blocks/blast_furnace.rs +++ b/pumpkin/src/block/blocks/blast_furnace.rs @@ -86,7 +86,7 @@ pub struct BlastFurnaceBlock; impl BlockBehaviour for BlastFurnaceBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(inventory) = block_entity.clone().get_inventory() && let Some(property_delegate) = block_entity.clone().to_property_delegate() && let Some(experience_container) = block_entity.to_experience_container() @@ -130,7 +130,7 @@ impl BlockBehaviour for BlastFurnaceBlock { fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { // Extract and drop accumulated XP as orbs before removing the block entity - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(experience_container) = block_entity.to_experience_container() { let xp = experience_container.extract_experience(); diff --git a/pumpkin/src/block/blocks/brewing_stand.rs b/pumpkin/src/block/blocks/brewing_stand.rs index 336c36674..065614b5b 100644 --- a/pumpkin/src/block/blocks/brewing_stand.rs +++ b/pumpkin/src/block/blocks/brewing_stand.rs @@ -52,7 +52,7 @@ pub struct BrewingStandBlock; impl BlockBehaviour for BrewingStandBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(inventory) = block_entity.clone().get_inventory() && let Some(pd) = block_entity.clone().to_property_delegate() { diff --git a/pumpkin/src/block/blocks/cake.rs b/pumpkin/src/block/blocks/cake.rs index 6d273827d..3883d1ad1 100644 --- a/pumpkin/src/block/blocks/cake.rs +++ b/pumpkin/src/block/blocks/cake.rs @@ -84,15 +84,15 @@ impl CakeBlock { impl BlockBehaviour for CakeBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { return Block::AIR.default_state.id; } Block::CAKE.default_state.id }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } fn use_with_item<'a>( @@ -100,7 +100,7 @@ impl BlockBehaviour for CakeBlock { args: UseWithItemArgs<'a>, ) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let properties = CakeLikeProperties::from_state_id(state_id, args.block); let item_lock = args.item_stack.lock().await; let item = item_lock.item; @@ -159,7 +159,7 @@ impl BlockBehaviour for CakeBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); Self::consume_if_hungry(args.world, args.player, args.block, args.position, state_id) .await }) @@ -167,7 +167,7 @@ impl BlockBehaviour for CakeBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -180,7 +180,7 @@ impl BlockBehaviour for CakeBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -190,7 +190,7 @@ impl BlockBehaviour for CakeBlock { } } -async fn can_place_at(world: &dyn BlockAccessor, position: &BlockPos) -> bool { - let state = world.get_block_state(&position.down()).await; +fn can_place_at(world: &dyn BlockAccessor, position: &BlockPos) -> bool { + let state = world.get_block_state(&position.down()); state.is_solid() } diff --git a/pumpkin/src/block/blocks/campfire.rs b/pumpkin/src/block/blocks/campfire.rs index 8d42ff43c..eeb6ad7b9 100644 --- a/pumpkin/src/block/blocks/campfire.rs +++ b/pumpkin/src/block/blocks/campfire.rs @@ -66,7 +66,7 @@ impl BlockBehaviour for CampfireBlock { CampfireLikeProperties::from_state_id(args.block.default_state.id, args.block); props.waterlogged = is_replacing_water; props.signal_fire = - is_signal_fire_base_block(args.world.get_block(&args.position.down()).await); + is_signal_fire_base_block(args.world.get_block(&args.position.down())); props.lit = !is_replacing_water; props.facing = args.player.get_entity().get_horizontal_facing(); props.to_state_id(args.block) @@ -93,7 +93,7 @@ impl BlockBehaviour for CampfireBlock { if args.direction == BlockDirection::Down { props.signal_fire = - is_signal_fire_base_block(args.world.get_block(args.neighbor_position).await); + is_signal_fire_base_block(args.world.get_block(args.neighbor_position)); } props.to_state_id(args.block) diff --git a/pumpkin/src/block/blocks/candle_cakes.rs b/pumpkin/src/block/blocks/candle_cakes.rs index 41c470cb6..c2cf5a475 100644 --- a/pumpkin/src/block/blocks/candle_cakes.rs +++ b/pumpkin/src/block/blocks/candle_cakes.rs @@ -92,7 +92,7 @@ impl CandleCakeBlock { ) .await; - let (block, state) = world.get_block_and_state_id(location).await; + let (block, state) = world.get_block_and_state_id(location); CakeBlock::consume_if_hungry(world, player, block, location, state).await } @@ -122,7 +122,7 @@ impl BlockBehaviour for CandleCakeBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -135,7 +135,7 @@ impl BlockBehaviour for CandleCakeBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -145,7 +145,7 @@ impl BlockBehaviour for CandleCakeBlock { } } -async fn can_place_at(world: &dyn BlockAccessor, position: &BlockPos) -> bool { - let state = world.get_block_state(&position.down()).await; +fn can_place_at(world: &dyn BlockAccessor, position: &BlockPos) -> bool { + let state = world.get_block_state(&position.down()); state.is_solid() } diff --git a/pumpkin/src/block/blocks/candles.rs b/pumpkin/src/block/blocks/candles.rs index d806b3a90..a98da4796 100644 --- a/pumpkin/src/block/blocks/candles.rs +++ b/pumpkin/src/block/blocks/candles.rs @@ -50,7 +50,7 @@ impl BlockBehaviour for CandleBlock { args: UseWithItemArgs<'a>, ) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut properties = CandleLikeProperties::from_state_id(state.id, args.block); let item_lock = args.item_stack.lock().await; @@ -102,7 +102,7 @@ impl BlockBehaviour for CandleBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let mut properties = CandleLikeProperties::from_state_id(state_id, args.block); if properties.lit { @@ -121,22 +121,20 @@ impl BlockBehaviour for CandleBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } - fn can_update_at<'a>(&'a self, args: CanUpdateAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let b = args.world.get_block(args.position).await; - args.player.get_entity().pose.load() != EntityPose::Crouching - && CandleLikeProperties::from_state_id(args.state_id, args.block).candles != 4 - && args.block.id == b.id - }) + fn can_update_at(&self, args: CanUpdateAtArgs<'_>) -> bool { + let b = BlockAccessor::get_block(args.world, args.position); + args.player.get_entity().pose.load() != EntityPose::Crouching + && CandleLikeProperties::from_state_id(args.state_id, args.block).candles != 4 + && args.block.id == b.id } fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -149,7 +147,7 @@ impl BlockBehaviour for CandleBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -159,7 +157,7 @@ impl BlockBehaviour for CandleBlock { } } -async fn can_place_at(block_accessor: &dyn BlockAccessor, position: &BlockPos) -> bool { - let (support_block, state) = block_accessor.get_block_and_state(&position.down()).await; +fn can_place_at(block_accessor: &dyn BlockAccessor, position: &BlockPos) -> bool { + let (support_block, state) = block_accessor.get_block_and_state(&position.down()); !support_block.is_waterlogged(state.id) && state.is_center_solid(BlockDirection::Up) } diff --git a/pumpkin/src/block/blocks/carpet.rs b/pumpkin/src/block/blocks/carpet.rs index be0d3a0a3..b1d533db4 100644 --- a/pumpkin/src/block/blocks/carpet.rs +++ b/pumpkin/src/block/blocks/carpet.rs @@ -12,8 +12,8 @@ use pumpkin_world::world::{BlockAccessor, BlockFlags}; pub struct CarpetBlock; impl BlockBehaviour for CarpetBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -21,7 +21,7 @@ impl BlockBehaviour for CarpetBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -32,7 +32,7 @@ impl BlockBehaviour for CarpetBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -45,8 +45,8 @@ impl BlockBehaviour for CarpetBlock { pub struct MossCarpetBlock; impl BlockBehaviour for MossCarpetBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -54,7 +54,7 @@ impl BlockBehaviour for MossCarpetBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -65,7 +65,7 @@ impl BlockBehaviour for MossCarpetBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -78,8 +78,8 @@ impl BlockBehaviour for MossCarpetBlock { pub struct PaleMossCarpetBlock; impl BlockBehaviour for PaleMossCarpetBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -87,7 +87,7 @@ impl BlockBehaviour for PaleMossCarpetBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -98,7 +98,7 @@ impl BlockBehaviour for PaleMossCarpetBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -107,6 +107,6 @@ impl BlockBehaviour for PaleMossCarpetBlock { } } -async fn can_place_at(block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - !is_air(block_accessor.get_block_state_id(&block_pos.down()).await) +fn can_place_at(block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + !is_air(block_accessor.get_block_state_id(&block_pos.down())) } diff --git a/pumpkin/src/block/blocks/carved_pumpkin.rs b/pumpkin/src/block/blocks/carved_pumpkin.rs index eb94ac997..612abb308 100644 --- a/pumpkin/src/block/blocks/carved_pumpkin.rs +++ b/pumpkin/src/block/blocks/carved_pumpkin.rs @@ -40,8 +40,8 @@ impl BlockBehaviour for CarvedPumpkinBlock { // Mojang uses some BlockPattern magic, way too complex tbh Box::pin(async { let down_pos = args.position.down(); - let upper = args.world.get_block(&down_pos).await; - let lower = args.world.get_block(&down_pos.down()).await; + let upper = args.world.get_block(&down_pos); + let lower = args.world.get_block(&down_pos.down()); if upper == &Block::SNOW_BLOCK && lower == &Block::SNOW_BLOCK { for i in 0..3 { let pos = args.position.down_height(i); @@ -52,20 +52,18 @@ impl BlockBehaviour for CarvedPumpkinBlock { BlockFlags::NOTIFY_LISTENERS, ) .await; - args.world - .sync_world_event( - WorldEvent::ParticlesDestroyBlock, - pos, - Block::SNOW_BLOCK.default_state.id.into(), - ) - .await; + args.world.sync_world_event( + WorldEvent::ParticlesDestroyBlock, + pos, + Block::SNOW_BLOCK.default_state.id.into(), + ); } let entity = Entity::new( args.world.clone(), down_pos.down().to_centered_f64(), &EntityType::SNOW_GOLEM, ); - let golem = SnowGolemEntity::new(entity).await; + let golem = SnowGolemEntity::new(entity); args.world.spawn_entity(golem).await; return; } @@ -76,8 +74,8 @@ impl BlockBehaviour for CarvedPumpkinBlock { let arm1 = down_pos.offset(dir.to_offset()); let arm2 = down_pos.offset(opposite.to_offset()); - if args.world.get_block(&arm1).await == &Block::IRON_BLOCK - && args.world.get_block(&arm2).await == &Block::IRON_BLOCK + if args.world.get_block(&arm1) == &Block::IRON_BLOCK + && args.world.get_block(&arm2) == &Block::IRON_BLOCK { let pattern = [*args.position, down_pos, down_pos.down(), arm1, arm2]; @@ -89,13 +87,11 @@ impl BlockBehaviour for CarvedPumpkinBlock { BlockFlags::NOTIFY_LISTENERS, ) .await; - args.world - .sync_world_event( - WorldEvent::ParticlesDestroyBlock, - p, - Block::IRON_BLOCK.default_state.id.into(), - ) - .await; + args.world.sync_world_event( + WorldEvent::ParticlesDestroyBlock, + p, + Block::IRON_BLOCK.default_state.id.into(), + ); } let entity = Entity::new( @@ -103,7 +99,7 @@ impl BlockBehaviour for CarvedPumpkinBlock { down_pos.down().to_centered_f64(), &EntityType::IRON_GOLEM, ); - let golem = IronGolemEntity::new(entity).await; + let golem = IronGolemEntity::new(entity); args.world.spawn_entity(golem).await; return; } diff --git a/pumpkin/src/block/blocks/chests.rs b/pumpkin/src/block/blocks/chests.rs index 69b85ceea..5448e5464 100644 --- a/pumpkin/src/block/blocks/chests.rs +++ b/pumpkin/src/block/blocks/chests.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use crate::block::entities::BlockEntity; use crate::block::entities::chest::ChestBlockEntity; -use futures::future::join; use pumpkin_data::block_properties::{ BlockProperties, ChestLikeProperties, ChestType, HorizontalFacing, }; @@ -75,7 +74,7 @@ impl ScreenHandlerFactory for ChestScreenFactory { // Shared chest behavior implementations const LID_ANIMATION_EVENT_TYPE: u8 = 1; -async fn on_place_chest_impl(args: OnPlaceArgs<'_>) -> BlockStateId { +fn on_place_chest_impl(args: &OnPlaceArgs<'_>) -> BlockStateId { let mut chest_props = ChestLikeProperties::default(args.block); chest_props.waterlogged = args.replacing.water_source(); @@ -85,8 +84,7 @@ async fn on_place_chest_impl(args: OnPlaceArgs<'_>) -> BlockStateId { args.block, args.position, args.direction, - ) - .await; + ); chest_props.facing = facing; chest_props.r#type = r#type; @@ -114,9 +112,7 @@ async fn placed_chest_impl( chest_props.facing, connected_towards, ChestType::Single, - ) - .await - { + ) { neighbor_props.r#type = chest_props.r#type.opposite(); args.world @@ -130,11 +126,8 @@ async fn placed_chest_impl( } async fn normal_use_chest_impl(args: NormalUseArgs<'_>) -> BlockActionResult { - let (state, first_chest) = join( - args.world.get_block_state_id(args.position), - args.world.get_block_entity(args.position), - ) - .await; + let state = args.world.get_block_state_id(args.position); + let first_chest = args.world.get_block_entity(args.position); let Some(first_inventory) = first_chest.and_then(BlockEntity::get_inventory) else { return BlockActionResult::Fail; @@ -147,13 +140,13 @@ async fn normal_use_chest_impl(args: NormalUseArgs<'_>) -> BlockActionResult { ChestType::Right => Some(chest_props.facing.rotate_counter_clockwise()), }; - if is_chest_blocked(args.world, args.position).await { + if is_chest_blocked(args.world, args.position) { return BlockActionResult::Success; } if let Some(direction) = connected_towards { let neighbor_pos = args.position.offset(direction.to_offset()); - if is_chest_blocked(args.world, &neighbor_pos).await { + if is_chest_blocked(args.world, &neighbor_pos) { return BlockActionResult::Success; } } @@ -162,7 +155,6 @@ async fn normal_use_chest_impl(args: NormalUseArgs<'_>) -> BlockActionResult { && let Some(second_inventory) = args .world .get_block_entity(&args.position.offset(direction.to_offset())) - .await .and_then(BlockEntity::get_inventory) { // Vanilla: chestType == ChestType.RIGHT ? DoubleBlockProperties.Type.FIRST : DoubleBlockProperties.Type.SECOND; @@ -197,9 +189,7 @@ async fn broken_chest_impl(args: BrokenArgs<'_>) { chest_props.facing, connected_towards, chest_props.r#type.opposite(), - ) - .await - { + ) { neighbor_props.r#type = ChestType::Single; args.world @@ -217,7 +207,7 @@ pub struct ChestBlock; impl BlockBehaviour for ChestBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { - Box::pin(on_place_chest_impl(args)) + Box::pin(async move { on_place_chest_impl(&args) }) } fn on_synced_block_event<'a>( @@ -246,7 +236,7 @@ pub struct CopperChestBlock; impl BlockBehaviour for CopperChestBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { - Box::pin(on_place_chest_impl(args)) + Box::pin(async move { on_place_chest_impl(&args) }) } fn on_synced_block_event<'a>( @@ -270,7 +260,7 @@ impl BlockBehaviour for CopperChestBlock { fn random_tick<'a>(&'a self, args: RandomTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let current_state_id = args.world.get_block_state_id(args.position).await; + let current_state_id = args.world.get_block_state_id(args.position); let chest_props = ChestLikeProperties::from_state_id(current_state_id, args.block); // Only oxidize LEFT or SINGLE chests (not RIGHT) to prevent double oxidation @@ -279,7 +269,7 @@ impl BlockBehaviour for CopperChestBlock { } // Only oxidize if no players are viewing the chest - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(chest_entity) = block_entity.as_any().downcast_ref::() && chest_entity.get_viewer_count() > 0 { @@ -355,7 +345,7 @@ async fn try_oxidize_copper_chest( // Scan neighbors in 4-block Manhattan distance to calculate oxidation chance let (same_level_count, higher_level_count) = - count_neighbor_oxidation_levels(world, position, current_level).await; + count_neighbor_oxidation_levels(world, position, current_level); // If we found any neighbors at a LOWER level, oxidation is blocked // (This is handled in count_neighbor_oxidation_levels by returning early) @@ -380,7 +370,7 @@ async fn try_oxidize_copper_chest( /// Count copper blocks at same and higher oxidation levels within 4-block Manhattan distance. /// Returns (same, higher) counts, or (0, 0) if a lower-level neighbor was found (blocking oxidation). -async fn count_neighbor_oxidation_levels( +fn count_neighbor_oxidation_levels( world: &Arc, center: &BlockPos, current_level: u8, @@ -405,7 +395,7 @@ async fn count_neighbor_oxidation_levels( center.0.z + dz, )); - let neighbor_block = world.get_block(&neighbor_pos).await; + let neighbor_block = world.get_block(&neighbor_pos); if let Some(neighbor_level) = get_oxidation_level(neighbor_block) { match neighbor_level.cmp(¤t_level) { @@ -434,7 +424,7 @@ pub struct TrappedChestBlock; impl BlockBehaviour for TrappedChestBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { - Box::pin(on_place_chest_impl(args)) + Box::pin(async move { on_place_chest_impl(&args) }) } fn on_synced_block_event<'a>( @@ -473,7 +463,7 @@ impl BlockBehaviour for TrappedChestBlock { // Get viewer count from this chest let viewer_count = if let Some(block_entity) = - args.world.get_block_entity(args.position).await + args.world.get_block_entity(args.position) && let Some(trapped_chest) = block_entity .as_any() .downcast_ref::() @@ -503,7 +493,7 @@ impl BlockBehaviour for TrappedChestBlock { } } -async fn compute_chest_props( +fn compute_chest_props( world: &World, player: &Player, block: &Block, @@ -518,9 +508,8 @@ async fn compute_chest_props( return (ChestType::Single, chest_facing); }; - let (clicked_block, clicked_block_state) = world - .get_block_and_state_id(&block_pos.offset(face.to_offset())) - .await; + let (clicked_block, clicked_block_state) = + world.get_block_and_state_id(&block_pos.offset(face.to_offset())); if clicked_block == block { let clicked_props = @@ -548,7 +537,6 @@ async fn compute_chest_props( chest_facing.rotate_clockwise(), ChestType::Single, ) - .await .is_some() { (ChestType::Left, chest_facing) @@ -560,7 +548,6 @@ async fn compute_chest_props( chest_facing.rotate_counter_clockwise(), ChestType::Single, ) - .await .is_some() { (ChestType::Right, chest_facing) @@ -569,7 +556,7 @@ async fn compute_chest_props( } } -async fn get_chest_properties_if_can_connect( +fn get_chest_properties_if_can_connect( world: &World, block: &Block, block_pos: &BlockPos, @@ -577,9 +564,8 @@ async fn get_chest_properties_if_can_connect( direction: HorizontalFacing, wanted_type: ChestType, ) -> Option { - let (neighbor_block, neighbor_block_state) = world - .get_block_and_state_id(&block_pos.offset(direction.to_offset())) - .await; + let (neighbor_block, neighbor_block_state) = + world.get_block_and_state_id(&block_pos.offset(direction.to_offset())); if neighbor_block != block { return None; @@ -593,13 +579,13 @@ async fn get_chest_properties_if_can_connect( None } -async fn is_chest_blocked(world: &World, block_pos: &BlockPos) -> bool { +fn is_chest_blocked(world: &World, block_pos: &BlockPos) -> bool { // TODO: Block opening when a cat is sitting on top. - has_block_on_top(world, block_pos).await + has_block_on_top(world, block_pos) } -async fn has_block_on_top(world: &World, block_pos: &BlockPos) -> bool { +fn has_block_on_top(world: &World, block_pos: &BlockPos) -> bool { let above_pos = block_pos.up(); - let above_state = world.get_block_state(&above_pos).await; + let above_state = world.get_block_state(&above_pos); above_state.is_solid_block() } diff --git a/pumpkin/src/block/blocks/chiseled_bookshelf.rs b/pumpkin/src/block/blocks/chiseled_bookshelf.rs index 8e951b010..1ec0ab183 100644 --- a/pumpkin/src/block/blocks/chiseled_bookshelf.rs +++ b/pumpkin/src/block/blocks/chiseled_bookshelf.rs @@ -41,12 +41,12 @@ impl BlockBehaviour for ChiseledBookshelfBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let properties = ChiseledBookshelfLikeProperties::from_state_id(state.id, args.block); if let Some(slot) = Self::get_slot_for_hit(args.hit, properties.facing) { if Self::is_slot_used(properties, slot) { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(block_entity) = block_entity .as_any() .downcast_ref::() @@ -75,7 +75,7 @@ impl BlockBehaviour for ChiseledBookshelfBlock { args: UseWithItemArgs<'a>, ) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let properties = ChiseledBookshelfLikeProperties::from_state_id(state.id, args.block); if !args @@ -90,7 +90,7 @@ impl BlockBehaviour for ChiseledBookshelfBlock { if let Some(slot) = Self::get_slot_for_hit(args.hit, properties.facing) { if Self::is_slot_used(properties, slot) { return BlockActionResult::PassToDefaultBlockAction; - } else if let Some(block_entity) = args.world.get_block_entity(args.position).await + } else if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(block_entity) = block_entity .as_any() .downcast_ref::() @@ -125,7 +125,7 @@ impl BlockBehaviour for ChiseledBookshelfBlock { args: GetComparatorOutputArgs<'a>, ) -> BlockFuture<'a, Option> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(block_entity) = block_entity .as_any() .downcast_ref::() @@ -164,9 +164,7 @@ impl ChiseledBookshelfBlock { .await; entity.update_state(properties, world.clone(), slot).await; - world - .play_sound(sound, SoundCategory::Blocks, &position.to_centered_f64()) - .await; + world.play_sound(sound, SoundCategory::Blocks, &position.to_centered_f64()); } async fn try_remove_book( @@ -195,9 +193,7 @@ impl ChiseledBookshelfBlock { } entity.update_state(properties, world.clone(), slot).await; - world - .play_sound(sound, SoundCategory::Blocks, &position.to_centered_f64()) - .await; + world.play_sound(sound, SoundCategory::Blocks, &position.to_centered_f64()); } fn get_slot_for_hit(hit: &BlockHitResult<'_>, facing: HorizontalFacing) -> Option { diff --git a/pumpkin/src/block/blocks/command.rs b/pumpkin/src/block/blocks/command.rs index 1db1093ab..65326f855 100644 --- a/pumpkin/src/block/blocks/command.rs +++ b/pumpkin/src/block/blocks/command.rs @@ -23,13 +23,13 @@ use tracing::warn; pub struct CommandBlock; impl CommandBlock { - async fn get_relative_facing( + fn get_relative_facing( world: &World, pos: &BlockPos, dir: Facing, ) -> Option<(BlockPos, CommandBlockLikeProperties)> { let target_pos = pos.offset(dir.to_block_direction().to_offset()); - let block = world.get_block(&target_pos).await; + let block = world.get_block(&target_pos); let allowed_blocks = [ Block::COMMAND_BLOCK.name, @@ -40,24 +40,24 @@ impl CommandBlock { return None; } - let state_id = world.get_block_state_id(&target_pos).await; + let state_id = world.get_block_state_id(&target_pos); let props = CommandBlockLikeProperties::from_state_id(state_id, block); Some((target_pos, props)) } - async fn conditions_met(world: &Arc, pos: &BlockPos, facing: Facing) -> bool { - let (block, state_id) = world.get_block_and_state_id(pos).await; + fn conditions_met(world: &Arc, pos: &BlockPos, facing: Facing) -> bool { + let (block, state_id) = world.get_block_and_state_id(pos); let props = CommandBlockLikeProperties::from_state_id(state_id, block); if !props.conditional { return true; } - let Some(before) = Self::get_relative_facing(world, pos, facing.opposite()).await else { + let Some(before) = Self::get_relative_facing(world, pos, facing.opposite()) else { return false; }; - let Some(before_entity) = world.get_block_entity(&before.0).await else { + let Some(before_entity) = world.get_block_entity(&before.0) else { warn!("Command block has no matching entity"); return false; }; @@ -83,7 +83,7 @@ impl CommandBlock { return; } - let state_id = world.get_block_state_id(pos).await; + let state_id = world.get_block_state_id(pos); let props = CommandBlockLikeProperties::from_state_id(state_id, block); if !props.conditional { @@ -93,11 +93,10 @@ impl CommandBlock { return; } - let Some(behind) = Self::get_relative_facing(world, pos, props.facing.opposite()).await - else { + let Some(behind) = Self::get_relative_facing(world, pos, props.facing.opposite()) else { return; }; - let Some(behind_entity) = world.get_block_entity(&behind.0).await else { + let Some(behind_entity) = world.get_block_entity(&behind.0) else { warn!( "Command Block exists at {} with no matching block entity!", behind.0 @@ -159,12 +158,12 @@ impl CommandBlock { if !command_blocks_work { return; } - let block = world.get_block(&pos).await; + let block = world.get_block(&pos); if block.id != Block::CHAIN_COMMAND_BLOCK.id { break; } - let Some(block_entity) = world.get_block_entity(&pos).await else { + let Some(block_entity) = world.get_block_entity(&pos) else { warn!("Missing command block entity"); break; }; @@ -172,14 +171,14 @@ impl CommandBlock { let command_entity: &CommandBlockEntity = block_entity.as_any().downcast_ref().unwrap(); let powered = command_entity.powered.load(Ordering::Relaxed); let auto = command_entity.auto.load(Ordering::Relaxed); - let state_id = world.get_block_state_id(&pos).await; + let state_id = world.get_block_state_id(&pos); let props = CommandBlockLikeProperties::from_state_id(state_id, block); if powered || auto { - let conditions_met = Self::conditions_met(&world, &pos, direction).await; + let conditions_met = Self::conditions_met(&world, &pos, direction); if conditions_met { let command = command_entity.command.lock().await; - let entity = world.get_block_entity(&pos).await.unwrap(); + let entity = world.get_block_entity(&pos).unwrap(); Self::execute(server, world.clone(), entity, &command).await; } else if props.conditional { command_entity.success_count.store(0, Ordering::Release); @@ -224,7 +223,7 @@ impl BlockBehaviour for CommandBlock { if args.player.permission_lvl.load() < PermissionLvl::Two { return BlockActionResult::Pass; } - let Some(block_entity) = args.world.get_block_entity(args.position).await else { + let Some(block_entity) = args.world.get_block_entity(args.position) else { return BlockActionResult::Pass; }; args.world.update_block_entity(&block_entity).await; @@ -239,7 +238,7 @@ impl BlockBehaviour for CommandBlock { if !command_blocks_work { return; } - if let Some(block_entity) = args.world.get_block_entity(args.position).await { + if let Some(block_entity) = args.world.get_block_entity(args.position) { if block_entity.resource_location() != CommandBlockEntity::ID { return; } @@ -267,7 +266,7 @@ impl BlockBehaviour for CommandBlock { if !command_blocks_work { return; } - let Some(block_entity) = args.world.get_block_entity(args.position).await else { + let Some(block_entity) = args.world.get_block_entity(args.position) else { return; }; if block_entity.resource_location() != CommandBlockEntity::ID { @@ -279,7 +278,7 @@ impl BlockBehaviour for CommandBlock { return; }; let props = CommandBlockLikeProperties::from_state_id( - args.world.get_block_state_id(args.position).await, + args.world.get_block_state_id(args.position), args.block, ); @@ -300,7 +299,7 @@ impl BlockBehaviour for CommandBlock { ) .await; - let block = args.world.get_block(args.position).await; + let block = args.world.get_block(args.position); let is_auto = command_entity.auto.load(Ordering::Relaxed); let can_run = command_entity.powered.load(Ordering::Relaxed) || is_auto; if block == &Block::REPEATING_COMMAND_BLOCK && can_run { @@ -311,16 +310,14 @@ impl BlockBehaviour for CommandBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - if let Some(player) = args.player - && player.gamemode.load() == GameMode::Creative - { - return true; - } + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + if let Some(player) = args.player + && player.gamemode.load() == GameMode::Creative + { + return true; + } - false - }) + false } fn placed<'a>(&'a self, args: PlacedArgs<'a>) -> BlockFuture<'a, ()> { @@ -344,7 +341,7 @@ impl BlockBehaviour for CommandBlock { args: crate::block::GetComparatorOutputArgs<'a>, ) -> BlockFuture<'a, Option> { Box::pin(async { - let entity = args.world.get_block_entity(args.position).await; + let entity = args.world.get_block_entity(args.position); entity.map_or_else( || { diff --git a/pumpkin/src/block/blocks/composter.rs b/pumpkin/src/block/blocks/composter.rs index 52f7dcab5..ff5b0f096 100644 --- a/pumpkin/src/block/blocks/composter.rs +++ b/pumpkin/src/block/blocks/composter.rs @@ -29,7 +29,7 @@ pub struct ComposterBlock; impl BlockBehaviour for ComposterBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let props = ComposterLikeProperties::from_state_id(state_id, args.block); if props.level == 8 { self.clear_composter(args.world, args.position, state_id, args.block) @@ -45,7 +45,7 @@ impl BlockBehaviour for ComposterBlock { args: UseWithItemArgs<'a>, ) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let props = ComposterLikeProperties::from_state_id(state_id, args.block); let level = props.level; @@ -80,8 +80,7 @@ impl BlockBehaviour for ComposterBlock { ) .await; args.world - .sync_world_event(WorldEvent::ComposterFill, *args.position, 1) - .await; + .sync_world_event(WorldEvent::ComposterFill, *args.position, 1); } // Consume the item @@ -91,7 +90,7 @@ impl BlockBehaviour for ComposterBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let props = ComposterLikeProperties::from_state_id(state_id, args.block); let level = props.level; if level == 7 { @@ -161,8 +160,7 @@ impl ComposterBlock { let item_entity = ItemEntity::new( Entity::new(world.clone(), item_position, &EntityType::ITEM), ItemStack::new(1, &Item::BONE_MEAL), - ) - .await; + ); world.spawn_entity(Arc::new(item_entity)).await; } diff --git a/pumpkin/src/block/blocks/dirt_path.rs b/pumpkin/src/block/blocks/dirt_path.rs index f2f97a9e4..92f9275b1 100644 --- a/pumpkin/src/block/blocks/dirt_path.rs +++ b/pumpkin/src/block/blocks/dirt_path.rs @@ -32,7 +32,7 @@ impl BlockBehaviour for DirtPathBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { return Block::DIRT.default_state.id; } @@ -45,9 +45,7 @@ impl BlockBehaviour for DirtPathBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if args.direction == BlockDirection::Up - && !can_place_at(args.world, args.position).await - { + if args.direction == BlockDirection::Up && !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -56,12 +54,12 @@ impl BlockBehaviour for DirtPathBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } } -async fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - let state = world.get_block_state(&block_pos.up()).await; +fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + let state = world.get_block_state(&block_pos.up()); !state.is_solid() // TODO: add fence gate block } diff --git a/pumpkin/src/block/blocks/doors.rs b/pumpkin/src/block/blocks/doors.rs index b991015f4..aabd9c108 100644 --- a/pumpkin/src/block/blocks/doors.rs +++ b/pumpkin/src/block/blocks/doors.rs @@ -37,7 +37,7 @@ use pumpkin_util::GameMode; type DoorProperties = pumpkin_data::block_properties::OakDoorLikeProperties; async fn toggle_door(player: &Player, world: &Arc, block_pos: &BlockPos) { - let (block, block_state) = world.get_block_and_state_id(block_pos).await; + let (block, block_state) = world.get_block_and_state_id(block_pos); let mut door_props = DoorProperties::from_state_id(block_state, block); door_props.open = !door_props.open; @@ -47,18 +47,16 @@ async fn toggle_door(player: &Player, world: &Arc, block_pos: &BlockPos) }; let other_pos = block_pos.offset(other_half.to_offset()); - let (other_block, other_state_id) = world.get_block_and_state_id(&other_pos).await; + let (other_block, other_state_id) = world.get_block_and_state_id(&other_pos); let mut other_door_props = DoorProperties::from_state_id(other_state_id, other_block); other_door_props.open = door_props.open; - world - .play_block_sound_expect( - player, - get_sound(block, door_props.open), - SoundCategory::Blocks, - *block_pos, - ) - .await; + world.play_block_sound_expect( + player, + get_sound(block, door_props.open), + SoundCategory::Blocks, + *block_pos, + ); world .set_block_state( @@ -114,24 +112,22 @@ async fn get_hinge( let top_pos = pos.up(); let left_dir = facing.rotate_counter_clockwise(); let left_pos = pos.offset(left_dir.to_block_direction().to_offset()); - let (left_block, left_state) = world.get_block_and_state(&left_pos).await; + let (left_block, left_state) = world.get_block_and_state(&left_pos); let top_facing = top_pos.offset(facing.to_block_direction().to_offset()); - let top_state = world.get_block_state(&top_facing).await; + let top_state = world.get_block_state(&top_facing); let right_dir = facing.rotate_clockwise(); let right_pos = pos.offset(right_dir.to_block_direction().to_offset()); - let (right_block, right_state) = world.get_block_and_state(&right_pos).await; + let (right_block, right_state) = world.get_block_and_state(&right_pos); let top_right = top_pos.offset(facing.to_block_direction().to_offset()); - let top_right_state = world.get_block_state(&top_right).await; + let top_right_state = world.get_block_state(&top_right); let has_left_door = world .get_block(&left_pos) - .await .has_tag(&tag::Block::MINECRAFT_DOORS) && DoorProperties::from_state_id(left_state.id, left_block).half == DoubleBlockHalf::Lower; let has_right_door = world .get_block(&right_pos) - .await .has_tag(&tag::Block::MINECRAFT_DOORS) && DoorProperties::from_state_id(right_state.id, right_block).half == DoubleBlockHalf::Lower; @@ -184,8 +180,8 @@ impl BlockBehaviour for DoorBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } fn placed<'a>(&'a self, args: PlacedArgs<'a>) -> BlockFuture<'a, ()> { @@ -223,7 +219,7 @@ impl BlockBehaviour for DoorBlock { DoubleBlockHalf::Lower => args.position.up(), }; - let neighbor_block_id = args.world.get_block_state_id(&other_half_pos).await; + let neighbor_block_id = args.world.get_block_state_id(&other_half_pos); if neighbor_block_id != args.block.id { args.world.update_neighbors(&other_half_pos, None).await; return; // Neighbor is already gone or is a different block @@ -244,7 +240,7 @@ impl BlockBehaviour for DoorBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let block_state = args.world.get_block_state(args.position).await; + let block_state = args.world.get_block_state(args.position); let mut door_props = DoorProperties::from_state_id(block_state.id, args.block); let other_half = match door_props.half { @@ -252,7 +248,7 @@ impl BlockBehaviour for DoorBlock { DoubleBlockHalf::Lower => BlockDirection::Up, }; let other_pos = args.position.offset(other_half.to_offset()); - let (other_block, other_state_id) = args.world.get_block_and_state_id(&other_pos).await; + let (other_block, other_state_id) = args.world.get_block_and_state_id(&other_pos); if other_block.id != args.block.id { return; @@ -271,13 +267,11 @@ impl BlockBehaviour for DoorBlock { door_props.open = door_props.powered; other_door_props.open = other_door_props.powered; - args.world - .play_block_sound( - get_sound(args.block, powered), - SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + get_sound(args.block, powered), + SoundCategory::Blocks, + *args.position, + ); } args.world @@ -309,7 +303,7 @@ impl BlockBehaviour for DoorBlock { { if lv == DoubleBlockHalf::Lower && args.direction == BlockDirection::Down - && !can_place_at(args.world, args.position).await + && !can_place_at(args.world, args.position) { return 0; } @@ -333,7 +327,7 @@ impl BlockBehaviour for DoorBlock { return; } - let new_state_id = args.world.get_block_state_id(args.position).await; + let new_state_id = args.world.get_block_state_id(args.position); let new_block = Block::from_state_id(new_state_id); if new_block == &Block::AIR { return; @@ -356,10 +350,9 @@ impl BlockBehaviour for DoorBlock { } } -async fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - world.get_block_state(&block_pos.up()).await.replaceable() +fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + world.get_block_state(&block_pos.up()).replaceable() && world .get_block_state(&block_pos.down()) - .await .is_side_solid(BlockDirection::Up) } diff --git a/pumpkin/src/block/blocks/dragon_egg.rs b/pumpkin/src/block/blocks/dragon_egg.rs index 1668da5c6..87d281cfe 100644 --- a/pumpkin/src/block/blocks/dragon_egg.rs +++ b/pumpkin/src/block/blocks/dragon_egg.rs @@ -19,11 +19,11 @@ impl DragonEggBlock { let z = pos.0.z + rng().random_range(-16..16); let test_pos = BlockPos::new(x, y, z); - let state = world.get_block_state(&test_pos).await; - let below_state = world.get_block_state(&test_pos.down()).await; + let state = world.get_block_state(&test_pos); + let below_state = world.get_block_state(&test_pos.down()); if state.is_air() && !below_state.is_air() { - let current_state = world.get_block_state(pos).await; + let current_state = world.get_block_state(pos); world .set_block_state( &test_pos, diff --git a/pumpkin/src/block/blocks/dripstone.rs b/pumpkin/src/block/blocks/dripstone.rs index 208dcf44c..74ea05d9b 100644 --- a/pumpkin/src/block/blocks/dripstone.rs +++ b/pumpkin/src/block/blocks/dripstone.rs @@ -28,16 +28,13 @@ impl BlockMetadata for DripstoneBlock { } impl BlockBehaviour for DripstoneBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - can_place_at_pos( - args.block_accessor, - args.position, - args.direction, - args.player, - ) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at_pos( + args.block_accessor, + args.position, + args.direction, + args.player, + ) } fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { @@ -48,9 +45,7 @@ impl BlockBehaviour for DripstoneBlock { args.position, Some(args.direction), Some(args.player), - ) - .await - else { + ) else { //this shouldn't happen return Block::AIR.id; }; @@ -65,8 +60,7 @@ impl BlockBehaviour for DripstoneBlock { args.world, args.position, args.state_id, - ) - .await; + ); match vertical_dir { VerticalDirection::Up => { update_stalagmite(args.world, len, args.position).await; @@ -90,8 +84,7 @@ impl BlockBehaviour for DripstoneBlock { args.world, &new_tip_pos, args.state.id, - ) - .await; + ); match vertical_dir { VerticalDirection::Up => { update_stalagmite(args.world, len, &new_tip_pos).await; @@ -107,7 +100,7 @@ impl BlockBehaviour for DripstoneBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at_pos(args.world, args.position, None, None).await { + if !can_place_at_pos(args.world, args.position, None, None) { return Block::AIR.default_state.id; } let mut dripstone_props = @@ -117,14 +110,14 @@ impl BlockBehaviour for DripstoneBlock { } match dripstone_props.vertical_direction { VerticalDirection::Up => { - let block_above = args.world.get_block(&args.position.up()).await; + let block_above = args.world.get_block(&args.position.up()); if block_above != &Block::POINTED_DRIPSTONE { dripstone_props.thickness = DripstoneThickness::Tip; return dripstone_props.to_state_id(args.block); } } VerticalDirection::Down => { - let block_below = args.world.get_block(&args.position.down()).await; + let block_below = args.world.get_block(&args.position.down()); if block_below != &Block::POINTED_DRIPSTONE { dripstone_props.thickness = DripstoneThickness::Tip; return dripstone_props.to_state_id(args.block); @@ -136,7 +129,7 @@ impl BlockBehaviour for DripstoneBlock { } } async fn update_stalagmite(world: &Arc, stalagmite_len: u8, tip_pos: &BlockPos) { - let block_above = world.get_block(&tip_pos.up()).await; + let block_above = world.get_block(&tip_pos.up()); if block_above == &Block::POINTED_DRIPSTONE { modify_dripstone_thickness_to(world, tip_pos, DripstoneThickness::TipMerge).await; modify_dripstone_thickness_to(world, &tip_pos.up(), DripstoneThickness::TipMerge).await; @@ -203,7 +196,7 @@ async fn update_stalagmite(world: &Arc, stalagmite_len: u8, tip_pos: &Blo } async fn update_stalactite(world: &Arc, stalagmite_len: u8, tip_pos: &BlockPos) { - let block_below = world.get_block(&tip_pos.down()).await; + let block_below = world.get_block(&tip_pos.down()); if block_below == &Block::POINTED_DRIPSTONE { modify_dripstone_thickness_to(world, tip_pos, DripstoneThickness::TipMerge).await; modify_dripstone_thickness_to(world, &tip_pos.down(), DripstoneThickness::TipMerge).await; @@ -256,7 +249,7 @@ async fn update_stalactite(world: &Arc, stalagmite_len: u8, tip_pos: &Blo _ => {} } } -async fn get_stalagmite_or_stalactice_len_and_dir_from_tip_pos( +fn get_stalagmite_or_stalactice_len_and_dir_from_tip_pos( world: &Arc, position: &BlockPos, block_state_id: BlockStateId, @@ -268,7 +261,7 @@ async fn get_stalagmite_or_stalactice_len_and_dir_from_tip_pos( let mut next_dripstone_pos = offset_pos_by_vertical_dir(position, props.vertical_direction); //We dont care if it's longer than 5 blocks because of how thickness system works. while dripstone_len < 5 { - if world.get_block(&next_dripstone_pos).await != &Block::POINTED_DRIPSTONE { + if world.get_block(&next_dripstone_pos) != &Block::POINTED_DRIPSTONE { break; } next_dripstone_pos = @@ -277,7 +270,7 @@ async fn get_stalagmite_or_stalactice_len_and_dir_from_tip_pos( } (dripstone_len, props.vertical_direction) } -async fn can_place_at_pos( +fn can_place_at_pos( block_accessor: &dyn BlockAccessor, position: &BlockPos, placing_direction: Option, @@ -289,22 +282,21 @@ async fn can_place_at_pos( position, placing_direction, player_option, - ) - .await - else { + ) else { return false; }; let support_pos = match support_block_vertical_direction { VerticalDirection::Up => position.up(), VerticalDirection::Down => position.down(), }; - let support_block = block_accessor.get_block(&support_pos).await; + let support_block = block_accessor.get_block(&support_pos); if can_support_dripstone(support_block) { return true; } false } -async fn get_support_block_vertical_direction( + +fn get_support_block_vertical_direction( block_accessor: &dyn BlockAccessor, position: &BlockPos, placing_direction_wrapper: Option, @@ -312,7 +304,7 @@ async fn get_support_block_vertical_direction( ) -> Option { let Some(placing_direction) = placing_direction_wrapper else { //then this is basically called by a neighbor update check - let (block, state) = block_accessor.get_block_and_state(position).await; + let (block, state) = block_accessor.get_block_and_state(position); if block != &Block::POINTED_DRIPSTONE { return None; } @@ -322,8 +314,8 @@ async fn get_support_block_vertical_direction( match block_direction_to_vertical_direction(placing_direction) { Some(ver_dir) => match ver_dir { VerticalDirection::Up => { - let block_above = block_accessor.get_block(&position.up()).await; - let block_below = block_accessor.get_block(&position.down()).await; + let block_above = block_accessor.get_block(&position.up()); + let block_below = block_accessor.get_block(&position.down()); if can_support_dripstone(block_above) { return Some(VerticalDirection::Up); } else if can_support_dripstone(block_below) { @@ -332,8 +324,8 @@ async fn get_support_block_vertical_direction( None } VerticalDirection::Down => { - let block_above = block_accessor.get_block(&position.up()).await; - let block_below = block_accessor.get_block(&position.down()).await; + let block_above = block_accessor.get_block(&position.up()); + let block_below = block_accessor.get_block(&position.down()); if can_support_dripstone(block_below) { return Some(VerticalDirection::Down); } else if can_support_dripstone(block_above) { @@ -342,32 +334,29 @@ async fn get_support_block_vertical_direction( None } }, - None => match player_option { - Some(player) => { - let (_, pitch) = player.rotation(); - let (can_place_above, can_place_below) = { - let block_above = block_accessor.get_block(&position.up()).await; - let block_below = block_accessor.get_block(&position.down()).await; - ( - can_support_dripstone(block_above), - can_support_dripstone(block_below), - ) - }; - match (can_place_above, can_place_below) { - (true, true) => { - if pitch > 0.0 { - Some(VerticalDirection::Down) - } else { - Some(VerticalDirection::Up) - } + None => player_option.map_or(Some(VerticalDirection::Up), |player| { + let (_, pitch) = player.rotation(); + let (can_place_above, can_place_below) = { + let block_above = block_accessor.get_block(&position.up()); + let block_below = block_accessor.get_block(&position.down()); + ( + can_support_dripstone(block_above), + can_support_dripstone(block_below), + ) + }; + match (can_place_above, can_place_below) { + (true, true) => { + if pitch > 0.0 { + Some(VerticalDirection::Down) + } else { + Some(VerticalDirection::Up) } - (false, false) => None, - (true, false) => Some(VerticalDirection::Up), - (false, true) => Some(VerticalDirection::Down), } + (false, false) => None, + (true, false) => Some(VerticalDirection::Up), + (false, true) => Some(VerticalDirection::Down), } - None => Some(VerticalDirection::Up), - }, + }), } } fn can_support_dripstone(support_block: &Block) -> bool { @@ -384,7 +373,7 @@ async fn modify_dripstone_thickness_to( pos: &BlockPos, new_thickness: DripstoneThickness, ) { - let (block, support_block_state_id) = world.get_block_and_state_id(pos).await; + let (block, support_block_state_id) = world.get_block_and_state_id(pos); if block != &Block::POINTED_DRIPSTONE { //this shouldn't happen diff --git a/pumpkin/src/block/blocks/enchanting_table.rs b/pumpkin/src/block/blocks/enchanting_table.rs index 38396b040..dc0156363 100644 --- a/pumpkin/src/block/blocks/enchanting_table.rs +++ b/pumpkin/src/block/blocks/enchanting_table.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use crate::block::registry::BlockActionResult; use crate::block::{BlockBehaviour, BlockFuture, NormalUseArgs}; -use pumpkin_data::translation; +use pumpkin_data::{Block, translation}; use pumpkin_inventory::enchanting::enchanting_screen_handler::EnchantingTableScreenHandler; use pumpkin_inventory::player::player_inventory::PlayerInventory; use pumpkin_inventory::screen_handler::{ @@ -25,37 +25,28 @@ impl BlockBehaviour for EnchantingTableBlock { for off_z in -1..=1 { for off_x in -1..=1 { if (off_z != 0 || off_x != 0) - && args.world.get_block_state(&args.position.add(off_x, 0, off_z)).await.id == 0 // Air - && args.world.get_block_state(&args.position.add(off_x, 1, off_z)).await.id == 0 + && args.world.get_block_state(&args.position.add(off_x, 0, off_z)).id == 0 // Air + && args.world.get_block_state(&args.position.add(off_x, 1, off_z)).id == 0 // Air { for off_y in 0..=1 { - if self - .is_bookshelf( - args.world, - &args.position.add(off_x * 2, off_y, off_z * 2), - ) - .await - { + if Self::is_bookshelf( + args.world, + &args.position.add(off_x * 2, off_y, off_z * 2), + ) { bookshelf_count += 1; } if off_x != 0 && off_z != 0 { - if self - .is_bookshelf( - args.world, - &args.position.add(off_x * 2, off_y, off_z), - ) - .await - { + if Self::is_bookshelf( + args.world, + &args.position.add(off_x * 2, off_y, off_z), + ) { bookshelf_count += 1; } - if self - .is_bookshelf( - args.world, - &args.position.add(off_x, off_y, off_z * 2), - ) - .await - { + if Self::is_bookshelf( + args.world, + &args.position.add(off_x, off_y, off_z * 2), + ) { bookshelf_count += 1; } } @@ -80,10 +71,10 @@ impl BlockBehaviour for EnchantingTableBlock { } impl EnchantingTableBlock { - async fn is_bookshelf(&self, world: &Arc, pos: &BlockPos) -> bool { - let state = world.get_block_state(pos).await; + fn is_bookshelf(world: &Arc, pos: &BlockPos) -> bool { + let state = world.get_block_state(pos); let block = pumpkin_data::Block::from_state_id(state.id); - block.name == "bookshelf" + block == &Block::BOOKSHELF } } diff --git a/pumpkin/src/block/blocks/end_rod.rs b/pumpkin/src/block/blocks/end_rod.rs index 72a67be71..941f92e0d 100644 --- a/pumpkin/src/block/blocks/end_rod.rs +++ b/pumpkin/src/block/blocks/end_rod.rs @@ -16,8 +16,7 @@ impl BlockBehaviour for EndRodBlock { let blockstate = args .world - .get_block_state_id(&args.position.offset(args.direction.to_offset())) - .await; + .get_block_state_id(&args.position.offset(args.direction.to_offset())); if Block::from_state_id(blockstate).eq(args.block) && EndRodLikeProperties::from_state_id(blockstate, args.block).facing diff --git a/pumpkin/src/block/blocks/ender_chest.rs b/pumpkin/src/block/blocks/ender_chest.rs index a9444d78d..d8f6aa10e 100644 --- a/pumpkin/src/block/blocks/ender_chest.rs +++ b/pumpkin/src/block/blocks/ender_chest.rs @@ -74,11 +74,11 @@ impl BlockBehaviour for EnderChestBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if is_chest_blocked(args.world, args.position).await { + if is_chest_blocked(args.world, args.position) { return BlockActionResult::Success; } - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(block_entity) = block_entity .as_any() .downcast_ref::() @@ -108,13 +108,13 @@ impl BlockBehaviour for EnderChestBlock { } } -async fn is_chest_blocked(world: &World, block_pos: &BlockPos) -> bool { +fn is_chest_blocked(world: &World, block_pos: &BlockPos) -> bool { // TODO: Block opening when a cat is sitting on top. - has_block_on_top(world, block_pos).await + has_block_on_top(world, block_pos) } -async fn has_block_on_top(world: &World, block_pos: &BlockPos) -> bool { +fn has_block_on_top(world: &World, block_pos: &BlockPos) -> bool { let above_pos = block_pos.up(); - let above_state = world.get_block_state(&above_pos).await; + let above_state = world.get_block_state(&above_pos); above_state.is_solid_block() } impl EnderChestBlock { diff --git a/pumpkin/src/block/blocks/falling.rs b/pumpkin/src/block/blocks/falling.rs index 5c2b594cf..59aa415fa 100644 --- a/pumpkin/src/block/blocks/falling.rs +++ b/pumpkin/src/block/blocks/falling.rs @@ -52,11 +52,11 @@ impl BlockBehaviour for FallingBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let (block, state) = args.world.get_block_and_state(&args.position.down()).await; + let (block, state) = args.world.get_block_and_state(&args.position.down()); if !Self::can_fall_through(state, block) || args.position.0.y < args.world.min_y { return; } - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); FallingEntity::replace_spawn(args.world, *args.position, state.id).await; }) } diff --git a/pumpkin/src/block/blocks/farmland.rs b/pumpkin/src/block/blocks/farmland.rs index a760205b7..432cba396 100644 --- a/pumpkin/src/block/blocks/farmland.rs +++ b/pumpkin/src/block/blocks/farmland.rs @@ -43,7 +43,7 @@ impl BlockBehaviour for FarmlandBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { return Block::DIRT.default_state.id; } args.block.default_state.id @@ -55,9 +55,7 @@ impl BlockBehaviour for FarmlandBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if args.direction == BlockDirection::Up - && !can_place_at(args.world, args.position).await - { + if args.direction == BlockDirection::Up && !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -66,14 +64,14 @@ impl BlockBehaviour for FarmlandBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } fn random_tick<'a>(&'a self, args: RandomTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { // TODO: add rain check. Remember to check which one is most optimized. - if is_water_nearby(args.world, args.position).await { + if is_water_nearby(args.world, args.position) { let mut props = FarmlandProperties::default(args.block); props.moisture = 7; args.world @@ -84,13 +82,12 @@ impl BlockBehaviour for FarmlandBlock { ) .await; } else { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let mut props = FarmlandProperties::from_state_id(state_id, args.block); if props.moisture == 0 { if !args .world .get_block(&args.position.up()) - .await .has_tag(&tag::Block::MINECRAFT_MAINTAINS_FARMLAND) { //TODO push entities up @@ -117,12 +114,12 @@ impl BlockBehaviour for FarmlandBlock { } } -async fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - let state = world.get_block_state(&block_pos.up()).await; +fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + let state = world.get_block_state(&block_pos.up()); !state.is_solid() // TODO: add fence gate block } -async fn is_water_nearby(world: &Arc, block_pos: &BlockPos) -> bool { +fn is_water_nearby(world: &Arc, block_pos: &BlockPos) -> bool { for dx in -4..=4 { for dy in 0..=1 { for dz in -4..=4 { @@ -132,7 +129,7 @@ async fn is_water_nearby(world: &Arc, block_pos: &BlockPos) -> bool { z: dz, }); //TODO this should use tag water. It does not seem to work rn. - if world.get_block(&check_pos).await == &Block::WATER { + if world.get_block(&check_pos) == &Block::WATER { return true; } } diff --git a/pumpkin/src/block/blocks/fence_gates.rs b/pumpkin/src/block/blocks/fence_gates.rs index 12bf17b58..f6a6209b4 100644 --- a/pumpkin/src/block/blocks/fence_gates.rs +++ b/pumpkin/src/block/blocks/fence_gates.rs @@ -42,7 +42,7 @@ pub async fn toggle_fence_gate( block_pos: &BlockPos, player: &Player, ) -> BlockStateId { - let (block, state) = world.get_block_and_state_id(block_pos).await; + let (block, state) = world.get_block_and_state_id(block_pos); let mut fence_gate_props = FenceGateProperties::from_state_id(state, block); if fence_gate_props.open { @@ -60,14 +60,12 @@ pub async fn toggle_fence_gate( fence_gate_props.open = true; } - world - .play_block_sound_expect( - player, - get_sound(block, fence_gate_props.open), - SoundCategory::Blocks, - *block_pos, - ) - .await; + world.play_block_sound_expect( + player, + get_sound(block, fence_gate_props.open), + SoundCategory::Blocks, + *block_pos, + ); world .set_block_state( @@ -101,7 +99,7 @@ impl BlockBehaviour for FenceGateBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - let fence_props = is_in_wall(&args).await; + let fence_props = is_in_wall(&args); fence_props.to_state_id(args.block) }) } @@ -116,7 +114,7 @@ impl BlockBehaviour for FenceGateBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let block_state = args.world.get_block_state(args.position).await; + let block_state = args.world.get_block_state(args.position); let mut fence_gate_props = FenceGateProperties::from_state_id(block_state.id, args.block); let powered = block_receives_redstone_power(args.world, args.position).await; @@ -130,13 +128,11 @@ impl BlockBehaviour for FenceGateBlock { if powered != fence_gate_props.open { fence_gate_props.open = powered; - args.world - .play_block_sound( - get_sound(args.block, powered), - SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + get_sound(args.block, powered), + SoundCategory::Blocks, + *args.position, + ); } args.world @@ -150,7 +146,7 @@ impl BlockBehaviour for FenceGateBlock { } } -async fn is_in_wall(args: &GetStateForNeighborUpdateArgs<'_>) -> FenceGateProperties { +fn is_in_wall(args: &GetStateForNeighborUpdateArgs<'_>) -> FenceGateProperties { let mut fence_props = FenceGateProperties::from_state_id(args.state_id, args.block); let side_offset_left = args @@ -165,8 +161,8 @@ async fn is_in_wall(args: &GetStateForNeighborUpdateArgs<'_>) -> FenceGateProper args.neighbor_position == &side_offset_left || args.neighbor_position == &side_offset_right; if neighbor_on_side { - let neighbor_right = args.world.get_block(&side_offset_right).await; - let neighbor_left = args.world.get_block(&side_offset_left).await; + let neighbor_right = args.world.get_block(&side_offset_right); + let neighbor_left = args.world.get_block(&side_offset_left); fence_props.in_wall = neighbor_left.has_tag(&tag::Block::MINECRAFT_WALLS) || neighbor_right.has_tag(&tag::Block::MINECRAFT_WALLS); diff --git a/pumpkin/src/block/blocks/fences.rs b/pumpkin/src/block/blocks/fences.rs index df36614b0..73c360679 100644 --- a/pumpkin/src/block/blocks/fences.rs +++ b/pumpkin/src/block/blocks/fences.rs @@ -28,7 +28,7 @@ impl BlockBehaviour for FenceBlock { let mut fence_props = FenceProperties::default(args.block); fence_props.waterlogged = args.replacing.water_source(); - compute_fence_state(fence_props, args.world, args.block, args.position).await + compute_fence_state(fence_props, args.world, args.block, args.position) }) } @@ -38,12 +38,12 @@ impl BlockBehaviour for FenceBlock { ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { let fence_props = FenceProperties::from_state_id(args.state_id, args.block); - compute_fence_state(fence_props, args.world, args.block, args.position).await + compute_fence_state(fence_props, args.world, args.block, args.position) }) } } -pub async fn compute_fence_state( +pub fn compute_fence_state( mut fence_props: FenceProperties, world: &World, block: &Block, @@ -51,7 +51,7 @@ pub async fn compute_fence_state( ) -> u16 { for direction in BlockDirection::horizontal() { let other_block_pos = block_pos.offset(direction.to_offset()); - let (other_block, other_block_state) = world.get_block_and_state(&other_block_pos).await; + let (other_block, other_block_state) = world.get_block_and_state(&other_block_pos); let connected = connects_to(block, other_block, other_block_state, direction); match direction { diff --git a/pumpkin/src/block/blocks/fire/fire.rs b/pumpkin/src/block/blocks/fire/fire.rs index 42d6ca294..b27422c27 100644 --- a/pumpkin/src/block/blocks/fire/fire.rs +++ b/pumpkin/src/block/blocks/fire/fire.rs @@ -54,14 +54,10 @@ impl FireBlock { .is_some_and(|f| f.burn_chance > 0) } - async fn are_blocks_around_flammable( - &self, - block_accessor: &dyn BlockAccessor, - pos: &BlockPos, - ) -> bool { + fn are_blocks_around_flammable(block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { for direction in BlockDirection::all() { let neighbor_pos = pos.offset(direction.to_offset()); - let block_state = block_accessor.get_block_state(&neighbor_pos).await; + let block_state = block_accessor.get_block_state(&neighbor_pos); if Self::is_flammable(block_state) { return true; } @@ -69,21 +65,21 @@ impl FireBlock { false } - pub async fn get_state_for_position( + pub fn get_state_for_position( &self, world: &World, block: &Block, pos: &BlockPos, ) -> BlockStateId { let down_pos = pos.down(); - let down_state = world.get_block_state(&down_pos).await; + let down_state = world.get_block_state(&down_pos); if Self::is_flammable(down_state) || down_state.is_side_solid(BlockDirection::Up) { return block.default_state.id; } let mut fire_props = FireProperties::from_state_id(block.default_state.id, block); for direction in BlockDirection::all() { let neighbor_pos = pos.offset(direction.to_offset()); - let neighbor_state = world.get_block_state(&neighbor_pos).await; + let neighbor_state = world.get_block_state(&neighbor_pos); if Self::is_flammable(neighbor_state) { match direction { BlockDirection::North => fire_props.north = true, @@ -99,16 +95,16 @@ impl FireBlock { } // Used for spreading fire - pub async fn get_burn_chance(&self, world: &Arc, pos: &BlockPos) -> i32 { - let block_state = world.get_block_state(pos).await; + pub fn get_burn_chance(&self, world: &Arc, pos: &BlockPos) -> i32 { + let block_state = world.get_block_state(pos); if !block_state.is_air() { return 0; } let mut total_burn_chance = 0; for dir in BlockDirection::all() { - let neighbor_block = world.get_block(&pos.offset(dir.to_offset())).await; - if world.get_fluid(&pos.offset(dir.to_offset())).await.name != Fluid::EMPTY.name { + let neighbor_block = world.get_block(&pos.offset(dir.to_offset())); + if world.get_fluid(&pos.offset(dir.to_offset())).name != Fluid::EMPTY.name { continue; // Skip if there is a fluid } if let Some(flammable) = &neighbor_block.flammable { @@ -130,7 +126,7 @@ impl FireBlock { block.flammable.as_ref().map_or(0, |f| f.burn_chance.into()) } - async fn is_increased_burnout_biome(world: &World, pos: &BlockPos) -> bool { + fn is_increased_burnout_biome(world: &World, pos: &BlockPos) -> bool { // Fire burnout increases in the Nether if world.dimension == Dimension::THE_NETHER { return true; @@ -138,7 +134,7 @@ impl FireBlock { // Fire burnout increases in specific biomes // TODO: Use proper tag or bool for this when available - let biome_id = world.level.get_rough_biome(pos).await.id; + let biome_id = world.level.get_rough_biome(pos).id; matches!( biome_id, id if id == Biome::BAMBOO_JUNGLE.id @@ -153,7 +149,7 @@ impl FireBlock { } async fn try_spreading_fire(&self, world: &Arc, pos: &BlockPos, chance: i32, age: u8) { - let block = world.get_block(pos).await; + let block = world.get_block(pos); let odds = Self::get_burn_odds(block); if rand::rng().random_range(0..chance) < odds { let old_block = block; @@ -161,9 +157,7 @@ impl FireBlock { && !Self::is_near_rain(world.as_ref(), pos) { let new_age = (age + (rand::rng().random_range(0..5) / 4)).min(15) as u8; - let state_id = self - .get_state_for_position(world.as_ref(), &Block::FIRE, pos) - .await; + let state_id = self.get_state_for_position(world.as_ref(), &Block::FIRE, pos); let mut fire_props = FireProperties::from_state_id(state_id, &Block::FIRE); fire_props.age = new_age; let new_state_id = fire_props.to_state_id(&Block::FIRE); @@ -199,7 +193,7 @@ impl BlockBehaviour for FireBlock { // First lets check if we are in OverWorld or Nether, its not possible to place an Nether portal in other dimensions in Vanilla if (dimension == &Dimension::OVERWORLD || dimension == &Dimension::THE_NETHER) && let Some(portal) = - NetherPortal::get_new_portal(args.world, args.position, HorizontalAxis::X).await + NetherPortal::get_new_portal(args.world, args.position, HorizontalAxis::X) { portal.create(args.world).await; return; @@ -225,24 +219,20 @@ impl BlockBehaviour for FireBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if self - .can_place_at(CanPlaceAtArgs { - server: None, - world: Some(args.world), - block_accessor: args.world, - block: &Block::FIRE, - state: Block::FIRE.default_state, - position: args.position, - direction: None, - player: None, - use_item_on: None, - }) - .await - { + if self.can_place_at(CanPlaceAtArgs { + server: None, + world: Some(args.world), + block_accessor: args.world, + block: &Block::FIRE, + state: Block::FIRE.default_state, + position: args.position, + direction: None, + player: None, + use_item_on: None, + }) { let old_fire_props = FireProperties::from_state_id(args.state_id, &Block::FIRE); - let fire_state_id = self - .get_state_for_position(args.world, &Block::FIRE, args.position) - .await; + let fire_state_id = + self.get_state_for_position(args.world, &Block::FIRE, args.position); let mut fire_props = FireProperties::from_state_id(fire_state_id, &Block::FIRE); fire_props.age = old_fire_props.age; return fire_props.to_state_id(&Block::FIRE); @@ -251,18 +241,12 @@ impl BlockBehaviour for FireBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let state = args - .block_accessor - .get_block_state(&args.position.down()) - .await; - if state.is_side_solid(BlockDirection::Up) { - return true; - } - self.are_blocks_around_flammable(args.block_accessor, args.position) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let state = args.block_accessor.get_block_state(&args.position.down()); + if state.is_side_solid(BlockDirection::Up) { + return true; + } + Self::are_blocks_around_flammable(args.block_accessor, args.position) } #[expect(clippy::too_many_lines)] @@ -281,20 +265,17 @@ impl BlockBehaviour for FireBlock { .await; // Check if fire can survive - if !Self - .can_place_at(CanPlaceAtArgs { - server: None, - world: Some(world), - block_accessor: world.as_ref(), - block, - state: block.default_state, - position: pos, - direction: None, - player: None, - use_item_on: None, - }) - .await - { + if !self.can_place_at(CanPlaceAtArgs { + server: None, + world: Some(world), + block_accessor: world.as_ref(), + block, + state: block.default_state, + position: pos, + direction: None, + player: None, + use_item_on: None, + }) { world .set_block_state( pos, @@ -305,8 +286,8 @@ impl BlockBehaviour for FireBlock { return; } - let block_state = world.get_block_state(pos).await; - let block_below = world.get_block(&pos.down()).await; + let block_state = world.get_block_state(pos); + let block_below = world.get_block(&pos.down()); // Check for infiniburn blocks (depending on dimension) let infiniburn = match world.dimension.id { @@ -353,8 +334,8 @@ impl BlockBehaviour for FireBlock { if !infiniburn { // Check if fire should extinguish due to lack of fuel - if !self.are_blocks_around_flammable(world.as_ref(), pos).await { - let block_below_state = world.get_block_state(&pos.down()).await; + if !Self::are_blocks_around_flammable(world.as_ref(), pos) { + let block_below_state = world.get_block_state(&pos.down()); if !block_below_state.is_side_solid(BlockDirection::Up) || new_age > 3 { world .set_block_state( @@ -370,7 +351,7 @@ impl BlockBehaviour for FireBlock { // At max age, fire has a chance to extinguish if not on flammable block if new_age == 15 && rand::rng().random_range(0..4) == 0 - && !Self::is_flammable(world.get_block_state(&pos.down()).await) + && !Self::is_flammable(world.get_block_state(&pos.down())) { world .set_block_state( @@ -384,7 +365,7 @@ impl BlockBehaviour for FireBlock { } // Burn adjacent blocks - let extra = if Self::is_increased_burnout_biome(world, pos).await { + let extra = if Self::is_increased_burnout_biome(world, pos) { -50 // Increases chance of block being destroyed } else { 0 @@ -448,7 +429,7 @@ impl BlockBehaviour for FireBlock { for yy in -1..=4 { if xx != 0 || yy != 0 || zz != 0 { let offset_pos = pos.offset(Vector3::new(xx, yy, zz)); - let ignite_odds = self.get_burn_chance(world, &offset_pos).await; + let ignite_odds = self.get_burn_chance(world, &offset_pos); if ignite_odds > 0 { // Skip if spreding is disabled or if there are no players nearby @@ -473,7 +454,7 @@ impl BlockBehaviour for FireBlock { (ignite_odds + 40 + difficulty * 7) / (new_age as i32 + 30); // Reduce spread odds in certain biomes - if Self::is_increased_burnout_biome(world, &offset_pos).await { + if Self::is_increased_burnout_biome(world, &offset_pos) { odds /= 2; // Fire spreads 50% slower } @@ -484,9 +465,11 @@ impl BlockBehaviour for FireBlock { let spread_age = (new_age + rand::rng().random_range(0..5) / 4) .min(15) as u8; - let fire_state_id = self - .get_state_for_position(world.as_ref(), block, &offset_pos) - .await; + let fire_state_id = self.get_state_for_position( + world.as_ref(), + block, + &offset_pos, + ); let mut new_fire_props = FireProperties::from_state_id(fire_state_id, &Block::FIRE); new_fire_props.age = spread_age; @@ -509,7 +492,7 @@ impl BlockBehaviour for FireBlock { fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - FireBlockBase::broken(args.world, *args.position).await; + FireBlockBase::broken(args.world, *args.position); }) } } diff --git a/pumpkin/src/block/blocks/fire/mod.rs b/pumpkin/src/block/blocks/fire/mod.rs index 113ab8bdc..14860fc22 100644 --- a/pumpkin/src/block/blocks/fire/mod.rs +++ b/pumpkin/src/block/blocks/fire/mod.rs @@ -26,8 +26,8 @@ pub mod soul_fire; pub struct FireBlockBase; impl FireBlockBase { - pub async fn get_fire_type(world: &World, pos: &BlockPos) -> Block { - let block = world.get_block(&pos.down()).await; + pub fn get_fire_type(world: &World, pos: &BlockPos) -> Block { + let block = world.get_block(&pos.down()); if SoulFireBlock::is_soul_base(block) { return Block::SOUL_FIRE; } @@ -43,49 +43,44 @@ impl FireBlockBase { && block != &Block::LAVA } - pub async fn is_soul_fire(world: &Arc, block_pos: &BlockPos) -> bool { - let block = world.get_block(&block_pos.down()).await; + pub fn is_soul_fire(world: &Arc, block_pos: &BlockPos) -> bool { + let block = world.get_block(&block_pos.down()); block.has_tag(&tag::Block::MINECRAFT_SOUL_FIRE_BASE_BLOCKS) } - pub async fn can_place_at(world: &Arc, block_pos: &BlockPos) -> bool { - let block_state = world.get_block_state(block_pos).await; + pub fn can_place_at(world: &Arc, block_pos: &BlockPos) -> bool { + let block_state = world.get_block_state(block_pos); if !block_state.is_air() { return false; } - if Self::is_soul_fire(world, block_pos).await { - SoulFireBlock - .can_place_at(CanPlaceAtArgs { - server: None, - world: Some(world), - block_accessor: world.as_ref(), - block: &Block::SOUL_FIRE, - state: Block::SOUL_FIRE.default_state, - position: block_pos, - direction: None, - player: None, - use_item_on: None, - }) - .await + if Self::is_soul_fire(world, block_pos) { + SoulFireBlock.can_place_at(CanPlaceAtArgs { + server: None, + world: Some(world), + block_accessor: world.as_ref(), + block: &Block::SOUL_FIRE, + state: Block::SOUL_FIRE.default_state, + position: block_pos, + direction: None, + player: None, + use_item_on: None, + }) } else { - FireBlock - .can_place_at(CanPlaceAtArgs { - server: None, - world: Some(world), - block_accessor: world.as_ref(), - block: &Block::FIRE, - state: Block::FIRE.default_state, - position: block_pos, - direction: None, - player: None, - use_item_on: None, - }) - .await - || Self::should_light_portal_at(world, block_pos, BlockDirection::Up).await + FireBlock.can_place_at(CanPlaceAtArgs { + server: None, + world: Some(world), + block_accessor: world.as_ref(), + block: &Block::FIRE, + state: Block::FIRE.default_state, + position: block_pos, + direction: None, + player: None, + use_item_on: None, + }) || Self::should_light_portal_at(world, block_pos, BlockDirection::Up) } } - pub async fn should_light_portal_at( + pub fn should_light_portal_at( world: &Arc, block_pos: &BlockPos, direction: BlockDirection, @@ -97,7 +92,7 @@ impl FireBlockBase { let mut found = false; for dir in BlockDirection::all() { - if world.get_block(&block_pos.offset(dir.to_offset())).await == &Block::OBSIDIAN { + if world.get_block(&block_pos.offset(dir.to_offset())) == &Block::OBSIDIAN { found = true; break; } @@ -114,9 +109,7 @@ impl FireBlockBase { Xoroshiro::from_seed(rand::rng().random()), )) }; - return NetherPortal::get_new_portal(world, block_pos, dir.to_horizontal_axis().unwrap()) - .await - .is_some(); + NetherPortal::get_new_portal(world, block_pos, dir.to_horizontal_axis().unwrap()).is_some() } /// Shared fire collision behavior used by `fire` and `soul_fire`. @@ -162,9 +155,7 @@ impl FireBlockBase { }) } - async fn broken(world: &World, block_pos: BlockPos) { - world - .sync_world_event(WorldEvent::SoundExtinguishFire, block_pos, 0) - .await; + fn broken(world: &World, block_pos: BlockPos) { + world.sync_world_event(WorldEvent::SoundExtinguishFire, block_pos, 0); } } diff --git a/pumpkin/src/block/blocks/fire/soul_fire.rs b/pumpkin/src/block/blocks/fire/soul_fire.rs index fff1ca4c3..128a81624 100644 --- a/pumpkin/src/block/blocks/fire/soul_fire.rs +++ b/pumpkin/src/block/blocks/fire/soul_fire.rs @@ -30,7 +30,7 @@ impl BlockBehaviour for SoulFireBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !Self::is_soul_base(args.world.get_block(&args.position.down()).await) { + if !Self::is_soul_base(args.world.get_block(&args.position.down())) { return Block::AIR.default_state.id; } @@ -38,15 +38,13 @@ impl BlockBehaviour for SoulFireBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - Self::is_soul_base(args.block_accessor.get_block(&args.position.down()).await) - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + Self::is_soul_base(args.block_accessor.get_block(&args.position.down())) } fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - FireBlockBase::broken(args.world, *args.position).await; + FireBlockBase::broken(args.world, *args.position); }) } } diff --git a/pumpkin/src/block/blocks/furnace.rs b/pumpkin/src/block/blocks/furnace.rs index d0971fb47..e7de891b1 100644 --- a/pumpkin/src/block/blocks/furnace.rs +++ b/pumpkin/src/block/blocks/furnace.rs @@ -85,7 +85,7 @@ pub struct FurnaceBlock; impl BlockBehaviour for FurnaceBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(inventory) = block_entity.clone().get_inventory() && let Some(property_delegate) = block_entity.clone().to_property_delegate() && let Some(experience_container) = block_entity.to_experience_container() @@ -126,7 +126,7 @@ impl BlockBehaviour for FurnaceBlock { fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { // Extract and drop accumulated XP as orbs before removing the block entity - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(experience_container) = block_entity.to_experience_container() { let xp = experience_container.extract_experience(); diff --git a/pumpkin/src/block/blocks/glass_panes.rs b/pumpkin/src/block/blocks/glass_panes.rs index 1b9d7ffe8..9eaeb13df 100644 --- a/pumpkin/src/block/blocks/glass_panes.rs +++ b/pumpkin/src/block/blocks/glass_panes.rs @@ -26,7 +26,7 @@ impl BlockBehaviour for GlassPaneBlock { let mut pane_props = GlassPaneProperties::default(args.block); pane_props.waterlogged = args.replacing.water_source(); - compute_pane_state(pane_props, args.world, args.block, args.position).await + compute_pane_state(pane_props, args.world, args.block, args.position) }) } @@ -36,12 +36,12 @@ impl BlockBehaviour for GlassPaneBlock { ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { let pane_props = GlassPaneProperties::from_state_id(args.state_id, args.block); - compute_pane_state(pane_props, args.world, args.block, args.position).await + compute_pane_state(pane_props, args.world, args.block, args.position) }) } } -pub async fn compute_pane_state( +pub fn compute_pane_state( mut pane_props: GlassPaneProperties, world: &World, block: &Block, @@ -49,7 +49,7 @@ pub async fn compute_pane_state( ) -> u16 { for direction in BlockDirection::horizontal() { let other_block_pos = block_pos.offset(direction.to_offset()); - let (other_block, other_block_state) = world.get_block_and_state(&other_block_pos).await; + let (other_block, other_block_state) = world.get_block_and_state(&other_block_pos); let connected = other_block == block || other_block_state.is_side_solid(direction.opposite()) diff --git a/pumpkin/src/block/blocks/grindstone.rs b/pumpkin/src/block/blocks/grindstone.rs index f98d974a4..ad30678de 100644 --- a/pumpkin/src/block/blocks/grindstone.rs +++ b/pumpkin/src/block/blocks/grindstone.rs @@ -27,16 +27,13 @@ impl BlockBehaviour for GrindstoneBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - // Use the provided direction, or fallback to the current state's direction if missing - let direction = args - .direction - .unwrap_or_else(|| self.get_direction(args.state.id, args.block)); + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + // Use the provided direction, or fallback to the current state's direction if missing + let direction = args + .direction + .unwrap_or_else(|| self.get_direction(args.state.id, args.block)); - WallMountedBlock::can_place_at(self, args.block_accessor, args.position, direction) - .await - }) + WallMountedBlock::can_place_at(self, args.block_accessor, args.position, direction) } fn get_state_for_neighbor_update<'a>( @@ -53,8 +50,8 @@ impl WallMountedBlock for GrindstoneBlock { _world: &'a dyn BlockAccessor, _pos: &'a BlockPos, _direction: BlockDirection, - ) -> BlockFuture<'a, bool> { - Box::pin(async move { true }) + ) -> bool { + true } fn get_direction(&self, state_id: BlockStateId, block: &Block) -> BlockDirection { diff --git a/pumpkin/src/block/blocks/hopper.rs b/pumpkin/src/block/blocks/hopper.rs index 3e507cb2a..8bbc100d6 100644 --- a/pumpkin/src/block/blocks/hopper.rs +++ b/pumpkin/src/block/blocks/hopper.rs @@ -59,7 +59,7 @@ type HopperLikeProperties = pumpkin_data::block_properties::HopperLikeProperties impl BlockBehaviour for HopperBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(inventory) = block_entity.get_inventory() { args.player @@ -104,7 +104,7 @@ impl BlockBehaviour for HopperBlock { check_powered_state( args.world, args.position, - args.world.get_block_state_id(args.position).await, + args.world.get_block_state_id(args.position), args.block, ) .await; diff --git a/pumpkin/src/block/blocks/iron_bars.rs b/pumpkin/src/block/blocks/iron_bars.rs index 86c5824bc..6fe108f9e 100644 --- a/pumpkin/src/block/blocks/iron_bars.rs +++ b/pumpkin/src/block/blocks/iron_bars.rs @@ -23,7 +23,7 @@ impl BlockBehaviour for IronBarsBlock { let mut bars_props = IronBarsProperties::default(args.block); bars_props.waterlogged = args.replacing.water_source(); - compute_bars_state(bars_props, args.world, args.block, args.position).await + compute_bars_state(bars_props, args.world, args.block, args.position) }) } @@ -33,12 +33,12 @@ impl BlockBehaviour for IronBarsBlock { ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { let bars_props = IronBarsProperties::from_state_id(args.state_id, args.block); - compute_bars_state(bars_props, args.world, args.block, args.position).await + compute_bars_state(bars_props, args.world, args.block, args.position) }) } } -pub async fn compute_bars_state( +pub fn compute_bars_state( mut bars_props: IronBarsProperties, world: &World, block: &Block, @@ -46,7 +46,7 @@ pub async fn compute_bars_state( ) -> u16 { for direction in BlockDirection::horizontal() { let other_block_pos = block_pos.offset(direction.to_offset()); - let (other_block, other_block_state) = world.get_block_and_state(&other_block_pos).await; + let (other_block, other_block_state) = world.get_block_and_state(&other_block_pos); let connected = other_block == block || other_block_state.is_side_solid(direction.opposite()) diff --git a/pumpkin/src/block/blocks/jukebox.rs b/pumpkin/src/block/blocks/jukebox.rs index 0a615bfd4..d402c41c0 100644 --- a/pumpkin/src/block/blocks/jukebox.rs +++ b/pumpkin/src/block/blocks/jukebox.rs @@ -52,7 +52,7 @@ impl JukeboxBlock { /// Drops the record from the jukebox - matches vanilla's `JukeboxBlockEntity.dropRecord()` /// Spawns item at (pos + 0.5, pos + 1.01, pos + 0.5) with horizontal random offset async fn drop_record(position: &BlockPos, world: &Arc) { - if let Some(block_entity) = world.get_block_entity(position).await + if let Some(block_entity) = world.get_block_entity(position) && let Some(jukebox_entity) = block_entity.as_any().downcast_ref::() { let record = jukebox_entity.clear_record().await; @@ -67,7 +67,7 @@ impl JukeboxBlock { let entity = Entity::new(world.clone(), spawn_pos, &EntityType::ITEM); // Vanilla: setToDefaultPickupDelay() = 10 ticks - let item_entity = Arc::new(ItemEntity::new(entity, record).await); + let item_entity = Arc::new(ItemEntity::new(entity, record)); world.spawn_entity(item_entity).await; } } @@ -76,16 +76,12 @@ impl JukeboxBlock { /// Stops the music and updates block state async fn stop_playing(block: &Block, position: &BlockPos, world: &Arc) { Self::set_record_state(false, block, position, world).await; - world - .sync_world_event(WorldEvent::SoundStopJukeboxSong, *position, 0) - .await; + world.sync_world_event(WorldEvent::SoundStopJukeboxSong, *position, 0); } /// Starts playing music - async fn start_playing(position: &BlockPos, world: &Arc, song_id: u32) { - world - .sync_world_event(WorldEvent::SoundPlayJukeboxSong, *position, song_id as i32) - .await; + fn start_playing(position: &BlockPos, world: &Arc, song_id: u32) { + world.sync_world_event(WorldEvent::SoundPlayJukeboxSong, *position, song_id as i32); } } @@ -102,7 +98,7 @@ impl BlockBehaviour for JukeboxBlock { /// Vanilla: `JukeboxBlock.onUse()` - drops record if present fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state(args.position).await.id; + let state_id = args.world.get_block_state(args.position).id; // Vanilla: if (state.get(HAS_RECORD) && world.getBlockEntity(pos) instanceof JukeboxBlockEntity lv) if Self::has_record_state(args.block, state_id) { @@ -125,7 +121,7 @@ impl BlockBehaviour for JukeboxBlock { ) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { let world = args.world; - let state_id = world.get_block_state(args.position).await.id; + let state_id = world.get_block_state(args.position).id; // Vanilla: if (state.get(HAS_RECORD)) return PASS_TO_DEFAULT_BLOCK_ACTION if Self::has_record_state(args.block, state_id) { @@ -157,7 +153,7 @@ impl BlockBehaviour for JukeboxBlock { let record = item_stack.split_unless_creative(args.player.gamemode.load(), 1); // Vanilla: lv4.setStack(lv3) - if let Some(block_entity) = world.get_block_entity(args.position).await + if let Some(block_entity) = world.get_block_entity(args.position) && let Some(jukebox_entity) = block_entity.as_any().downcast_ref::() { @@ -170,7 +166,7 @@ impl BlockBehaviour for JukeboxBlock { Self::set_record_state(true, args.block, args.position, world).await; // Start playing the music (client-side audio) - Self::start_playing(args.position, world, jukebox_song.get_id()).await; + Self::start_playing(args.position, world, jukebox_song.get_id()); // TODO: world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, ...) // TODO: player.incrementStat(Stats.PLAY_RECORD) @@ -186,8 +182,7 @@ impl BlockBehaviour for JukeboxBlock { Self::drop_record(args.position, args.world).await; // Stop the music args.world - .sync_world_event(WorldEvent::SoundStopJukeboxSong, *args.position, 0) - .await; + .sync_world_event(WorldEvent::SoundStopJukeboxSong, *args.position, 0); }) } @@ -214,7 +209,7 @@ impl BlockBehaviour for JukeboxBlock { ) -> BlockFuture<'a, u8> { Box::pin(async move { // Vanilla: return world.getBlockEntity(pos) instanceof JukeboxBlockEntity lv && lv.getManager().isPlaying() ? 15 : 0 - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(jukebox_entity) = block_entity.as_any().downcast_ref::() && jukebox_entity.is_playing() @@ -233,7 +228,7 @@ impl BlockBehaviour for JukeboxBlock { ) -> BlockFuture<'a, Option> { Box::pin(async move { // Vanilla: return world.getBlockEntity(pos) instanceof JukeboxBlockEntity lv ? lv.getComparatorOutput() : 0 - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(jukebox_entity) = block_entity.as_any().downcast_ref::() { diff --git a/pumpkin/src/block/blocks/ladder.rs b/pumpkin/src/block/blocks/ladder.rs index b228fb2c2..9d9e8739c 100644 --- a/pumpkin/src/block/blocks/ladder.rs +++ b/pumpkin/src/block/blocks/ladder.rs @@ -20,7 +20,7 @@ impl BlockBehaviour for LadderBlock { Box::pin(async move { let clicked_pos = args.use_item_on.position; let (clicked_block, clicked_block_state_id) = - args.world.get_block_and_state_id(&clicked_pos).await; + args.world.get_block_and_state_id(&clicked_pos); if clicked_block == &Block::LADDER { //you can't click on a ladder and place a ladder let props = @@ -38,7 +38,7 @@ impl BlockBehaviour for LadderBlock { if dir == Facing::Up || dir == Facing::Down { continue; } - if !can_place_ladder_at(args.world, args.position, dir.to_block_direction()).await { + if !can_place_ladder_at(args.world, args.position, dir.to_block_direction()) { continue; } props.facing = dir @@ -51,19 +51,17 @@ impl BlockBehaviour for LadderBlock { Block::AIR.default_state.id }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - for dir in BlockDirection::horizontal() { - let Some(world) = args.world else { - //this won't happen - return false; - }; - if can_place_ladder_at(world, args.position, dir).await { - return true; - } + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + for dir in BlockDirection::horizontal() { + let Some(world) = args.world else { + //this won't happen + return false; + }; + if can_place_ladder_at(world, args.position, dir) { + return true; } - false - }) + } + false } fn get_state_for_neighbor_update<'a>( &'a self, @@ -77,7 +75,6 @@ impl BlockBehaviour for LadderBlock { args.position, props.facing.to_block_direction().opposite(), ) - .await { return 0; } @@ -87,7 +84,7 @@ impl BlockBehaviour for LadderBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); if Block::from_state_id(state_id) != &Block::LADDER { return; } @@ -96,9 +93,7 @@ impl BlockBehaviour for LadderBlock { args.world, args.position, props.facing.to_block_direction().opposite(), - ) - .await - { + ) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -116,9 +111,8 @@ pub const fn horizontal_facing_from_offset(offset: Vector3) -> Option None, } } -async fn can_place_ladder_at(world: &World, block_pos: &BlockPos, facing: BlockDirection) -> bool { +fn can_place_ladder_at(world: &World, block_pos: &BlockPos, facing: BlockDirection) -> bool { world .get_block_state(&block_pos.offset(facing.to_offset())) - .await .is_side_solid(facing.opposite()) } diff --git a/pumpkin/src/block/blocks/lanterns.rs b/pumpkin/src/block/blocks/lanterns.rs index 8918b8d7f..f91e20ec7 100644 --- a/pumpkin/src/block/blocks/lanterns.rs +++ b/pumpkin/src/block/blocks/lanterns.rs @@ -38,7 +38,7 @@ impl BlockBehaviour for LanternBlock { pumpkin_data::block_properties::LanternLikeProperties::default(args.block); props.r#waterlogged = args.replacing.water_source(); - let block_up_state = args.world.get_block_state(&args.position.up()).await; + let block_up_state = args.world.get_block_state(&args.position.up()); if block_up_state.is_center_solid(BlockDirection::Down) { props.r#hanging = true; } @@ -47,8 +47,8 @@ impl BlockBehaviour for LanternBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.world.unwrap(), args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.world.unwrap(), args.position) } fn get_state_for_neighbor_update<'a>( @@ -56,7 +56,7 @@ impl BlockBehaviour for LanternBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -67,7 +67,7 @@ impl BlockBehaviour for LanternBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -76,25 +76,24 @@ impl BlockBehaviour for LanternBlock { } } -async fn can_place_at(world: &World, position: &BlockPos) -> bool { +fn can_place_at(world: &World, position: &BlockPos) -> bool { //idk why this don't update with .is_center_solid so this is a 'temporary patch' if world .get_block(&position.down()) - .await .has_tag(&tag::Block::C_FENCE_GATES) { let fence_gate_props = pumpkin_data::block_properties::OakFenceGateLikeProperties::from_state_id( - world.get_block_state_id(&position.down()).await, - world.get_block(&position.down()).await, + world.get_block_state_id(&position.down()), + world.get_block(&position.down()), ); if fence_gate_props.open { return false; } } - let (block_down, block_down_state) = world.get_block_and_state(&position.down()).await; - let block_up_state = world.get_block_state(&position.up()).await; + let (block_down, block_down_state) = world.get_block_and_state(&position.down()); + let block_up_state = world.get_block_state(&position.up()); block_down_state.is_center_solid(BlockDirection::Up) || block_up_state.is_center_solid(BlockDirection::Down) || block_down.has_tag(&tag::Block::MINECRAFT_UNSTABLE_BOTTOM_CENTER) diff --git a/pumpkin/src/block/blocks/lectern.rs b/pumpkin/src/block/blocks/lectern.rs index 0f413e8eb..6a01a8d6e 100644 --- a/pumpkin/src/block/blocks/lectern.rs +++ b/pumpkin/src/block/blocks/lectern.rs @@ -60,7 +60,7 @@ impl BlockBehaviour for LecternBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(lectern_entity) = block_entity.as_any().downcast_ref::() { @@ -70,7 +70,7 @@ impl BlockBehaviour for LecternBlock { // Need to find a proper way to give items to player. For now skip. let mut props = LecternLikeProperties::from_state_id( - args.world.get_block_state(args.position).await.id, + args.world.get_block_state(args.position).id, args.block, ); Self::update_lectern_state( @@ -97,7 +97,7 @@ impl BlockBehaviour for LecternBlock { // Check if it's a book if item_stack.item.registry_key.contains("book") - && let Some(block_entity) = args.world.get_block_entity(args.position).await + && let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(lectern_entity) = block_entity.as_any().downcast_ref::() && lectern_entity.book.lock().await.is_empty() @@ -106,7 +106,7 @@ impl BlockBehaviour for LecternBlock { lectern_entity.set_stack(0, book).await; let mut props = LecternLikeProperties::from_state_id( - args.world.get_block_state(args.position).await.id, + args.world.get_block_state(args.position).id, args.block, ); Self::update_lectern_state(true, args.block, args.position, args.world, &mut props) @@ -119,7 +119,7 @@ impl BlockBehaviour for LecternBlock { fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(lectern_entity) = block_entity.as_any().downcast_ref::() { @@ -135,7 +135,7 @@ impl BlockBehaviour for LecternBlock { ), &EntityType::ITEM, ); - let item_entity = ItemEntity::new(entity, book).await; + let item_entity = ItemEntity::new(entity, book); args.world.spawn_entity(Arc::new(item_entity)).await; } } diff --git a/pumpkin/src/block/blocks/nether_portal.rs b/pumpkin/src/block/blocks/nether_portal.rs index 9b286978b..75b8c5e5c 100644 --- a/pumpkin/src/block/blocks/nether_portal.rs +++ b/pumpkin/src/block/blocks/nether_portal.rs @@ -60,7 +60,6 @@ impl BlockBehaviour for NetherPortalBlock { if is_horizontal_and_different || args.neighbor_state_id == args.state_id || NetherPortal::get_on_axis(args.world, args.position, state_axis) - .await .is_some_and(|e| e.was_already_valid()) { return args.state_id; diff --git a/pumpkin/src/block/blocks/note.rs b/pumpkin/src/block/blocks/note.rs index eba56b3c6..1309b6ca7 100644 --- a/pumpkin/src/block/blocks/note.rs +++ b/pumpkin/src/block/blocks/note.rs @@ -26,7 +26,7 @@ pub struct NoteBlock; impl NoteBlock { pub async fn play_note(props: &NoteBlockLikeProperties, world: &World, pos: &BlockPos) { - if !is_base_block(props.instrument) || world.get_block_state(&pos.up()).await.is_air() { + if !is_base_block(props.instrument) || world.get_block_state(&pos.up()).is_air() { world.add_synced_block_event(*pos, 0, 0).await; } } @@ -34,20 +34,20 @@ impl NoteBlock { ((f32::from(note) - 12.0) / 12.0).exp2() } - async fn get_state_with_instrument( + fn get_state_with_instrument( world: &World, pos: &BlockPos, state: BlockStateId, block: &Block, ) -> BlockStateId { - let upper_instrument = world.get_block_state(&pos.up()).await.instrument; + let upper_instrument = world.get_block_state(&pos.up()).instrument; let mut note_props = NoteBlockLikeProperties::from_state_id(state, block); if !is_base_block(upper_instrument) { note_props.instrument = upper_instrument; return note_props.to_state_id(block); } - let below_instrument = world.get_block_state(&pos.down()).await.instrument; + let below_instrument = world.get_block_state(&pos.down()).instrument; let below_instrument = if is_base_block(below_instrument) { below_instrument } else { @@ -61,7 +61,7 @@ impl NoteBlock { impl BlockBehaviour for NoteBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let block_state = args.world.get_block_state(args.position).await; + let block_state = args.world.get_block_state(args.position); let mut note_props = NoteBlockLikeProperties::from_state_id(block_state.id, args.block); let powered = block_receives_redstone_power(args.world, args.position).await; // check if powered state changed @@ -83,7 +83,7 @@ impl BlockBehaviour for NoteBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let block_state = args.world.get_block_state(args.position).await; + let block_state = args.world.get_block_state(args.position); let mut note_props = NoteBlockLikeProperties::from_state_id(block_state.id, args.block); note_props.note = (note_props.note + 1) % 25; args.world @@ -114,7 +114,7 @@ impl BlockBehaviour for NoteBlock { args: OnSyncedBlockEventArgs<'a>, ) -> BlockFuture<'a, bool> { Box::pin(async move { - let block_state = args.world.get_block_state(args.position).await; + let block_state = args.world.get_block_state(args.position); let note_props = NoteBlockLikeProperties::from_state_id(block_state.id, args.block); let instrument = note_props.instrument; let pitch = if is_base_block(instrument) { @@ -124,15 +124,13 @@ impl BlockBehaviour for NoteBlock { 1.0 // default pitch }; // check hasCustomSound - args.world - .play_sound_raw( - convert_instrument_to_sound(instrument) as u16, - SoundCategory::Records, - &args.position.to_f64(), - 3.0, - pitch, - ) - .await; + args.world.play_sound_raw( + convert_instrument_to_sound(instrument) as u16, + SoundCategory::Records, + &args.position.to_f64(), + 3.0, + pitch, + ); true }) } @@ -145,7 +143,6 @@ impl BlockBehaviour for NoteBlock { Block::NOTE_BLOCK.default_state.id, args.block, ) - .await }) } @@ -160,8 +157,7 @@ impl BlockBehaviour for NoteBlock { args.position, args.state_id, args.block, - ) - .await; + ); } args.state_id }) diff --git a/pumpkin/src/block/blocks/piston/mod.rs b/pumpkin/src/block/blocks/piston/mod.rs index f985c1258..0970d84c0 100644 --- a/pumpkin/src/block/blocks/piston/mod.rs +++ b/pumpkin/src/block/blocks/piston/mod.rs @@ -49,7 +49,7 @@ impl<'a> PistonHandler<'a> { pub async fn calculate_push(&mut self) -> bool { self.moved_blocks.clear(); self.broken_blocks.clear(); - let (block, block_state) = self.world.get_block_and_state(&self.pos_to).await; + let (block, block_state) = self.world.get_block_and_state(&self.pos_to); if !PistonBlock::is_movable( block, @@ -69,7 +69,7 @@ impl<'a> PistonHandler<'a> { } for i in 0..self.moved_blocks.len() { let block_pos = self.moved_blocks[i]; - let block = self.world.get_block(&block_pos).await; + let block = self.world.get_block(&block_pos); if Self::is_block_sticky(block) && !self.try_move_adjacent_block(block, &block_pos).await { @@ -94,7 +94,7 @@ impl<'a> PistonHandler<'a> { } async fn try_move(&mut self, pos: BlockPos, dir: BlockDirection) -> bool { - let (block, block_state) = self.world.get_block_and_state(&pos).await; + let (block, block_state) = self.world.get_block_and_state(&pos); if block_state.is_air() { return true; } @@ -114,7 +114,7 @@ impl<'a> PistonHandler<'a> { while Self::is_block_sticky(block) { let block_pos = pos.offset_dir(self.motion_direction.opposite().to_offset(), i as i32); let block2 = block; - let (block, block_state) = self.world.get_block_and_state(&block_pos).await; + let (block, block_state) = self.world.get_block_and_state(&block_pos); if block_state.is_air() || !Self::is_adjacent_block_stuck(block2, block) || !PistonBlock::is_movable( @@ -146,7 +146,7 @@ impl<'a> PistonHandler<'a> { self.set_moved_blocks(j, l); for m in 0..=(l + j) { let block_pos3 = self.moved_blocks[m]; - let block = self.world.get_block(&block_pos3).await; + let block = self.world.get_block(&block_pos3); if Self::is_block_sticky(block) && !Box::pin(self.try_move_adjacent_block(block, &block_pos3)).await { @@ -155,7 +155,7 @@ impl<'a> PistonHandler<'a> { } return true; } - let (block, block_state) = self.world.get_block_and_state(&block_pos2).await; + let (block, block_state) = self.world.get_block_and_state(&block_pos2); if block_state.is_air() { return true; } @@ -201,7 +201,7 @@ impl<'a> PistonHandler<'a> { continue; } let block_pos = pos.offset(direction.to_offset()); - let block_state2 = self.world.get_block(&block_pos).await; + let block_state2 = self.world.get_block(&block_pos); if Self::is_adjacent_block_stuck(block_state2, block) && !self.try_move(block_pos, direction).await { diff --git a/pumpkin/src/block/blocks/piston/piston.rs b/pumpkin/src/block/blocks/piston/piston.rs index ec8e1d384..f58c51c0c 100644 --- a/pumpkin/src/block/blocks/piston/piston.rs +++ b/pumpkin/src/block/blocks/piston/piston.rs @@ -91,8 +91,7 @@ impl BlockBehaviour for PistonBlock { let pos = args .position .offset(props.facing.to_block_direction().to_offset()); - let (block_to_check, block_to_check_state_id) = - args.world.get_block_and_state_id(&pos).await; + let (block_to_check, block_to_check_state_id) = args.world.get_block_and_state_id(&pos); if &Block::PISTON_HEAD == block_to_check { let head_props = PistonHeadProperties::from_state_id(block_to_check_state_id, block_to_check); @@ -144,7 +143,7 @@ impl BlockBehaviour for PistonBlock { args.data, ); - let state = world.get_block_state(pos).await; + let state = world.get_block_state(pos); let mut props = PistonProps::from_state_id(state.id, block); let dir = props.facing.to_block_direction(); @@ -180,22 +179,20 @@ impl BlockBehaviour for PistonBlock { .await; // Play piston extend sound let pitch = rand::rng().random_range(0.6f32..0.85); - world - .play_sound_fine( - Sound::BlockPistonExtend, - SoundCategory::Blocks, - &pos.to_centered_f64(), - 0.5, - pitch, - ) - .await; + world.play_sound_fine( + Sound::BlockPistonExtend, + SoundCategory::Blocks, + &pos.to_centered_f64(), + 0.5, + pitch, + ); return true; } // Reduce Piston let extended_pos = pos.offset(dir.to_offset()); - if let Some(block_entity) = world.get_block_entity(&extended_pos).await + if let Some(block_entity) = world.get_block_entity(&extended_pos) && let Some(piston) = block_entity.as_any().downcast_ref::() { piston.finish(world.clone()).await; @@ -237,9 +234,9 @@ impl BlockBehaviour for PistonBlock { world.update_neighbors(pos, None).await; if sticky { let pull_pos = pos.offset_dir(dir.to_offset(), 2); - let (block, state) = world.get_block_and_state(&pull_pos).await; + let (block, state) = world.get_block_and_state(&pull_pos); let piston_piece = if block == &Block::MOVING_PISTON - && let Some(entity) = world.get_block_entity(&pull_pos).await + && let Some(entity) = world.get_block_entity(&pull_pos) && let Some(piston) = entity.as_any().downcast_ref::() && piston.facing == dir && piston.extending @@ -281,15 +278,13 @@ impl BlockBehaviour for PistonBlock { } // Play piston contract sound let pitch = rand::rng().random_range(0.6f32..0.75); - world - .play_sound_fine( - Sound::BlockPistonContract, - SoundCategory::Blocks, - &pos.to_centered_f64(), - 0.5, - pitch, - ) - .await; + world.play_sound_fine( + Sound::BlockPistonContract, + SoundCategory::Blocks, + &pos.to_centered_f64(), + 0.5, + pitch, + ); true }) } @@ -298,7 +293,7 @@ impl BlockBehaviour for PistonBlock { async fn should_extend(world: &World, block_pos: &BlockPos, piston_dir: BlockDirection) -> bool { for dir in BlockDirection::all() { let neighbor_pos = block_pos.offset(dir.to_offset()); - let (block, state) = world.get_block_and_state(&neighbor_pos).await; + let (block, state) = world.get_block_and_state(&neighbor_pos); // Pistons can't be powered from the same direction as they are facing if dir == piston_dir || !is_emitting_redstone_power(block, state, world, &neighbor_pos, dir).await @@ -308,13 +303,13 @@ async fn should_extend(world: &World, block_pos: &BlockPos, piston_dir: BlockDir return true; } let neighbor_pos = block_pos.offset(BlockDirection::Down.to_offset()); - let (block, state) = world.get_block_and_state(&neighbor_pos).await; + let (block, state) = world.get_block_and_state(&neighbor_pos); if is_emitting_redstone_power(block, state, world, block_pos, BlockDirection::Down).await { return true; } for dir in BlockDirection::all() { let neighbor_pos = block_pos.up().offset(dir.to_offset()); - let (block, state) = world.get_block_and_state(&neighbor_pos).await; + let (block, state) = world.get_block_and_state(&neighbor_pos); if dir == BlockDirection::Down || !is_emitting_redstone_power(block, state, world, &neighbor_pos, dir).await { @@ -326,7 +321,7 @@ async fn should_extend(world: &World, block_pos: &BlockPos, piston_dir: BlockDir } pub async fn try_move(world: &Arc, block: &Block, block_pos: &BlockPos) { - let state = world.get_block_state(block_pos).await; + let state = world.get_block_state(block_pos); let props = PistonProps::from_state_id(state.id, block); let dir = props.facing.to_block_direction(); let should_extent = should_extend(world, block_pos, dir).await; @@ -342,13 +337,13 @@ pub async fn try_move(world: &Arc, block: &Block, block_pos: &BlockPos) { } } else if !should_extent && props.extended { let new_pos = block_pos.offset_dir(dir.to_offset(), 2); - let (new_block, new_state) = world.get_block_and_state_id(&new_pos).await; + let (new_block, new_state) = world.get_block_and_state_id(&new_pos); let mut r#type = 1; if new_block == &Block::MOVING_PISTON { let new_props = MovingPistonLikeProperties::from_state_id(new_state, new_block); if new_props.facing == props.facing - && let Some(entity) = world.get_block_entity(&new_pos).await + && let Some(entity) = world.get_block_entity(&new_pos) { let piston = entity.as_any().downcast_ref::().unwrap(); if piston.extending && piston.current_progress.load() < 0.5 @@ -374,7 +369,7 @@ async fn move_piston( sticky: bool, ) -> bool { let extended_pos = block_pos.offset(dir.to_offset()); - if !extend && world.get_block(&extended_pos).await == &Block::PISTON_HEAD { + if !extend && world.get_block(&extended_pos) == &Block::PISTON_HEAD { world .set_block_state( &extended_pos, @@ -394,7 +389,7 @@ async fn move_piston( let mut moved_block_states: Vec<&BlockState> = Vec::new(); for &block_pos in &moved_blocks { - let block_state = world.get_block_state(&block_pos).await; + let block_state = world.get_block_state(&block_pos); moved_block_states.push(block_state); moved_blocks_map.insert(block_pos, block_state); } @@ -405,7 +400,7 @@ async fn move_piston( let move_direction = if extend { dir } else { dir.opposite() }; for &broken_block_pos in broken_blocks.iter().rev() { - let block_state = world.get_block_state(&broken_block_pos).await; + let block_state = world.get_block_state(&broken_block_pos); world .break_block( &broken_block_pos, @@ -417,7 +412,7 @@ async fn move_piston( } for (index, &moved_block_pos) in moved_blocks.iter().rev().enumerate() { - let block_state = world.get_block_state(&moved_block_pos).await; + let block_state = world.get_block_state(&moved_block_pos); let target_pos = moved_block_pos.offset(move_direction.to_offset()); moved_blocks_map.remove(&target_pos); diff --git a/pumpkin/src/block/blocks/piston/piston_extension.rs b/pumpkin/src/block/blocks/piston/piston_extension.rs index 8277c2093..09d1fb635 100644 --- a/pumpkin/src/block/blocks/piston/piston_extension.rs +++ b/pumpkin/src/block/blocks/piston/piston_extension.rs @@ -20,7 +20,7 @@ impl BlockBehaviour for PistonExtensionBlock { let pos = args .position .offset(props.facing.opposite().to_block_direction().to_offset()); - let (new_block, new_state) = args.world.get_block_and_state_id(&pos).await; + let (new_block, new_state) = args.world.get_block_and_state_id(&pos); if &Block::PISTON == new_block || &Block::STICKY_PISTON == new_block { let props = PistonProps::from_state_id(new_state, new_block); if props.extended { diff --git a/pumpkin/src/block/blocks/piston/piston_head.rs b/pumpkin/src/block/blocks/piston/piston_head.rs index 692e61376..9b4f5ff93 100644 --- a/pumpkin/src/block/blocks/piston/piston_head.rs +++ b/pumpkin/src/block/blocks/piston/piston_head.rs @@ -21,7 +21,7 @@ impl BlockBehaviour for PistonHeadBlock { let pos = args .position .offset(props.facing.opposite().to_block_direction().to_offset()); - let (new_block, new_state) = args.world.get_block_and_state_id(&pos).await; + let (new_block, new_state) = args.world.get_block_and_state_id(&pos); if &Block::PISTON == new_block || &Block::STICKY_PISTON == new_block { let props = PistonProps::from_state_id(new_state, new_block); if props.extended { @@ -35,7 +35,7 @@ impl BlockBehaviour for PistonHeadBlock { } fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let head_state_id = args.world.get_block_state_id(args.position).await; + let head_state_id = args.world.get_block_state_id(args.position); let head_props = PistonHeadProperties::from_state_id(head_state_id, &Block::PISTON_HEAD); if head_props.facing != Facing::Up { @@ -48,12 +48,12 @@ impl BlockBehaviour for PistonHeadBlock { .to_block_direction() .to_offset(), ); - let piston_block = args.world.get_block(&piston_pos).await; + let piston_block = args.world.get_block(&piston_pos); if &Block::PISTON == piston_block || &Block::STICKY_PISTON == piston_block { let up_pos = args .position .offset(head_props.facing.to_block_direction().to_offset()); - let upper_block = args.world.get_block(&up_pos).await; + let upper_block = args.world.get_block(&up_pos); if upper_block != &Block::REDSTONE_BLOCK { //Then somebody probably broke the redstone block, try to check if piston should still be extended. try_move(args.world, piston_block, &piston_pos).await; diff --git a/pumpkin/src/block/blocks/plant/bamboo.rs b/pumpkin/src/block/blocks/plant/bamboo.rs index 6053302eb..c35a818b9 100644 --- a/pumpkin/src/block/blocks/plant/bamboo.rs +++ b/pumpkin/src/block/blocks/plant/bamboo.rs @@ -27,10 +27,8 @@ pub struct BambooBlock; impl BlockBehaviour for BambooBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - let (block_below, state_id_below) = args - .world - .get_block_and_state_id(&args.position.down()) - .await; + let (block_below, state_id_below) = + args.world.get_block_and_state_id(&args.position.down()); if block_below.has_tag(&MINECRAFT_SUPPORTS_BAMBOO) { let mut props = BambooLikeProperties::from_state_id( @@ -47,7 +45,7 @@ impl BlockBehaviour for BambooBlock { } } else { let (block_above, state_id_above) = - args.world.get_block_and_state_id(&args.position.up()).await; + args.world.get_block_and_state_id(&args.position.up()); if block_above == &Block::BAMBOO { let props_above = BambooLikeProperties::from_state_id(state_id_above, block_above); @@ -76,21 +74,17 @@ impl BlockBehaviour for BambooBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !::can_place_at(self, args.world.as_ref(), args.position) - .await - { + if !::can_place_at(self, args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; - } else if args.world.get_block(&args.position.down()).await == &Block::BAMBOO_SAPLING { + } else if args.world.get_block(&args.position.down()) == &Block::BAMBOO_SAPLING { args.world .set_block_state( &args.position.down(), @@ -107,12 +101,12 @@ impl BlockBehaviour for BambooBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !::can_place_at(self, args.world, args.position).await { + if !::can_place_at(self, args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; } - let neighbor_block = args.world.get_block(args.neighbor_position).await; + let neighbor_block = args.world.get_block(args.neighbor_position); if args.direction == BlockDirection::Up && neighbor_block == &Block::BAMBOO { let neighbor_props = BambooLikeProperties::from_state_id(args.neighbor_state_id, neighbor_block); @@ -143,8 +137,8 @@ async fn update_leaves_and_grow(world: Arc, position: &BlockPos) { let below_pos = position.down(); let two_below_pos = position.down_height(2); - let (block, state_id) = world.get_block_and_state_id(position).await; - let state_above = world.get_block_state(&above_pos).await; + let (block, state_id) = world.get_block_and_state_id(position); + let state_above = world.get_block_state(&above_pos); if !state_above.is_air() { return; @@ -155,12 +149,12 @@ async fn update_leaves_and_grow(world: Arc, position: &BlockPos) { return; } - let bamboo_count = count_bamboo_below(world.clone(), position).await; + let bamboo_count = count_bamboo_below(&world, position); if bamboo_count >= 16 { return; } - let (block_below, state_id_below) = world.get_block_and_state_id(&below_pos).await; - let (block_two_below, state_id_two_below) = world.get_block_and_state_id(&two_below_pos).await; + let (block_below, state_id_below) = world.get_block_and_state_id(&below_pos); + let (block_two_below, state_id_two_below) = world.get_block_and_state_id(&two_below_pos); let mut props_below = BambooLikeProperties::from_state_id(state_id_below, block_below); @@ -209,13 +203,13 @@ async fn update_leaves_and_grow(world: Arc, position: &BlockPos) { .await; } -async fn count_bamboo_below(world: Arc, pos: &BlockPos) -> usize { +fn count_bamboo_below(world: &World, pos: &BlockPos) -> usize { let mut bamboo_count = 0; let mut found_bamboo_below = true; let mut current_position = pos.down(); while found_bamboo_below && bamboo_count < 16 { found_bamboo_below = false; - if world.get_block(¤t_position).await == &Block::BAMBOO { + if world.get_block(¤t_position) == &Block::BAMBOO { current_position = current_position.down(); bamboo_count += 1; found_bamboo_below = true; @@ -224,13 +218,13 @@ async fn count_bamboo_below(world: Arc, pos: &BlockPos) -> usize { bamboo_count } -async fn count_bamboo_above(world: Arc, pos: &BlockPos) -> usize { +fn count_bamboo_above(world: &World, pos: &BlockPos) -> usize { let mut bamboo_count = 0; let mut found_bamboo_below = true; let mut current_position = pos.up(); while found_bamboo_below && bamboo_count < 16 { found_bamboo_below = false; - if world.get_block(¤t_position).await == &Block::BAMBOO { + if world.get_block(¤t_position) == &Block::BAMBOO { current_position = current_position.up(); bamboo_count += 1; found_bamboo_below = true; @@ -240,16 +234,15 @@ async fn count_bamboo_above(world: Arc, pos: &BlockPos) -> usize { } async fn bone_meal(world: Arc, position: &BlockPos) { - let mut bamboo_above = count_bamboo_above(Arc::clone(&world), position).await; - let bamboo_below = count_bamboo_below(Arc::clone(&world), position).await; + let bamboo_below = count_bamboo_below(&world, position); let growth_amount = rand::rng().random_range(1..=3); - for _ in 0..growth_amount { + for (bamboo_above, _) in (count_bamboo_above(&world, position)..).zip(0..growth_amount) { let current_total_height = bamboo_above + bamboo_below + 1; let next_pos = position.up_height(bamboo_above as i32); - let next_state = world.get_block_state(&next_pos).await; + let next_state = world.get_block_state(&next_pos); if !next_state.is_air() || current_total_height >= 16 { return; @@ -261,22 +254,20 @@ async fn bone_meal(world: Arc, position: &BlockPos) { } update_leaves_and_grow(Arc::clone(&world), position).await; - - bamboo_above += 1; } } impl PlantBlockBase for BambooBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { - let block = block_accessor.get_block(pos).await; + let block = block_accessor.get_block(pos); block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_BAMBOO) } - async fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - ::can_plant_on_top(self, block_accessor, &block_pos.down()).await + fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + ::can_plant_on_top(self, block_accessor, &block_pos.down()) } } diff --git a/pumpkin/src/block/blocks/plant/bamboo_sapling.rs b/pumpkin/src/block/blocks/plant/bamboo_sapling.rs index 1cc8eac0f..249e26531 100644 --- a/pumpkin/src/block/blocks/plant/bamboo_sapling.rs +++ b/pumpkin/src/block/blocks/plant/bamboo_sapling.rs @@ -22,11 +22,8 @@ use crate::block::{ pub struct BambooSaplingBlock; impl BlockBehaviour for BambooSaplingBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, &args.position.down()) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, &args.position.down()) } fn use_with_item<'a>( @@ -57,7 +54,7 @@ impl BlockBehaviour for BambooSaplingBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { if args.block == &Block::BAMBOO_SAPLING - && args.world.get_block(&args.position.up()).await == &Block::BAMBOO + && args.world.get_block(&args.position.up()) == &Block::BAMBOO { args.world .set_block_state( @@ -75,11 +72,11 @@ impl BlockBehaviour for BambooSaplingBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !::can_place_at(self, args.world, args.position).await { + if !::can_place_at(self, args.world, args.position) { return Block::AIR.default_state.id; } if args.direction == BlockDirection::Up - && args.world.get_block(args.neighbor_position).await == &Block::BAMBOO + && args.world.get_block(args.neighbor_position) == &Block::BAMBOO { return Block::BAMBOO.default_state.id; } @@ -89,7 +86,7 @@ impl BlockBehaviour for BambooSaplingBlock { fn random_tick<'a>(&'a self, args: crate::block::RandomTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state_above = args.world.get_block_state(&args.position.up()).await; + let state_above = args.world.get_block_state(&args.position.up()); if !state_above.is_air() || rand::rng().random_range(0..3) > 0 { return; } @@ -108,12 +105,12 @@ impl BlockBehaviour for BambooSaplingBlock { } impl PlantBlockBase for BambooSaplingBlock { - async fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - ::can_plant_on_top(self, block_accessor, &block_pos.down()).await + fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + ::can_plant_on_top(self, block_accessor, &block_pos.down()) } - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block = block_accessor.get_block(pos); block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_SUPPORTS_BAMBOO) } } diff --git a/pumpkin/src/block/blocks/plant/big_dripleaf.rs b/pumpkin/src/block/blocks/plant/big_dripleaf.rs index e4df4d45c..29738d46e 100644 --- a/pumpkin/src/block/blocks/plant/big_dripleaf.rs +++ b/pumpkin/src/block/blocks/plant/big_dripleaf.rs @@ -50,7 +50,7 @@ impl BlockBehaviour for BigDripleafBlock { } fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); if block_receives_redstone_power(args.world, args.position).await { reset_tilt(state.id, args.world, args.position).await; } else { @@ -82,17 +82,13 @@ impl BlockBehaviour for BigDripleafBlock { }) } //TODO: onProjectileHit - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - let (support_block, support_block_state_id) = args - .world - .get_block_and_state_id(&args.position.down()) - .await; + let (support_block, support_block_state_id) = + args.world.get_block_and_state_id(&args.position.down()); let facing = if support_block == &Block::BIG_DRIPLEAF { get_dripleaf_facing_dir(support_block_state_id) } else { @@ -128,7 +124,7 @@ impl BlockBehaviour for BigDripleafBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { if block_receives_redstone_power(args.world, args.position).await { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); reset_tilt(state_id, args.world, args.position).await; } }) @@ -138,8 +134,7 @@ impl BlockBehaviour for BigDripleafBlock { fn placed<'a>(&'a self, args: PlacedArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { let support_pos = args.position.down(); - let (support_block, support_state_id) = - args.world.get_block_and_state_id(&support_pos).await; + let (support_block, support_state_id) = args.world.get_block_and_state_id(&support_pos); if support_block == &Block::BIG_DRIPLEAF { let old_dripleaf_props = BigDripleafLikeProperties::from_state_id( support_state_id, @@ -175,7 +170,7 @@ async fn set_tilt_and_schedule_tick( ) { set_tilt(state_id, world, pos, tilt).await; if let Some(tilt_sound) = sound_wrapper { - play_tilt_sound(world, pos, tilt_sound).await; + play_tilt_sound(world, pos, tilt_sound); } let tick_delay = match tilt { Tilt::None => -1, @@ -193,19 +188,17 @@ async fn set_tilt_and_schedule_tick( .await; } } -async fn play_tilt_sound(world: &Arc, pos: &BlockPos, tilt_sound: Sound) { +fn play_tilt_sound(world: &Arc, pos: &BlockPos, tilt_sound: Sound) { let pitch = rand::rng().random_range(0.8f32..1.2f32); let v = pos.as_vector3(); let position = Vector3::new(v.x as f64, v.y as f64, v.z as f64); - world - .play_sound_fine(tilt_sound, SoundCategory::Blocks, &position, 1f32, pitch) - .await; + world.play_sound_fine(tilt_sound, SoundCategory::Blocks, &position, 1f32, pitch); } async fn reset_tilt(state_id: BlockStateId, world: &Arc, pos: &BlockPos) { set_tilt(state_id, world, pos, Tilt::None).await; let props = BigDripleafLikeProperties::from_state_id(state_id, &Block::BIG_DRIPLEAF); if props.tilt != Tilt::None { - play_tilt_sound(world, pos, Sound::BlockBigDripleafTiltUp).await; + play_tilt_sound(world, pos, Sound::BlockBigDripleafTiltUp); } } async fn set_tilt(state_id: BlockStateId, world: &Arc, pos: &BlockPos, new_tilt: Tilt) { @@ -234,8 +227,8 @@ fn is_dripleaf_waterlogged(state_id: BlockStateId) -> bool { dripleaf_props.waterlogged } impl PlantBlockBase for BigDripleafBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let support_block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let support_block = block_accessor.get_block(pos); can_plant_dripleaf_on_top(support_block) } async fn get_state_for_neighbor_update( @@ -244,7 +237,7 @@ impl PlantBlockBase for BigDripleafBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { if is_dripleaf_waterlogged(block_state) { return Block::WATER.default_state.id; } diff --git a/pumpkin/src/block/blocks/plant/big_dripleaf_stem.rs b/pumpkin/src/block/blocks/plant/big_dripleaf_stem.rs index a3edd013d..a31dc2c21 100644 --- a/pumpkin/src/block/blocks/plant/big_dripleaf_stem.rs +++ b/pumpkin/src/block/blocks/plant/big_dripleaf_stem.rs @@ -21,10 +21,8 @@ pub struct BigDripleafStemBlock; pub type BigDripleafStemLikeProperties = LadderLikeProperties; impl BlockBehaviour for BigDripleafStemBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -46,8 +44,8 @@ impl BlockBehaviour for BigDripleafStemBlock { } } impl PlantBlockBase for BigDripleafStemBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let support_block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let support_block = block_accessor.get_block(pos); can_plant_dripleaf_on_top(support_block) } @@ -57,8 +55,8 @@ impl PlantBlockBase for BigDripleafStemBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { - let block = block_accessor.get_block(block_pos).await; + if !::can_place_at(self, block_accessor, block_pos) { + let block = block_accessor.get_block(block_pos); let dripleaf_stem_props = BigDripleafStemLikeProperties::from_state_id(block_state, block); @@ -72,7 +70,7 @@ impl PlantBlockBase for BigDripleafStemBlock { } pub async fn handle_big_dripleaf_breaking(world: &Arc, position: &BlockPos) { let support_pos = position.down(); - let (support_block, support_state_id) = world.get_block_and_state_id(&support_pos).await; + let (support_block, support_state_id) = world.get_block_and_state_id(&support_pos); if support_block == &Block::BIG_DRIPLEAF_STEM { let dripleaf_stem_props = BigDripleafStemLikeProperties::from_state_id(support_state_id, support_block); diff --git a/pumpkin/src/block/blocks/plant/bush.rs b/pumpkin/src/block/blocks/plant/bush.rs index 8f10223f5..7939cb9ec 100644 --- a/pumpkin/src/block/blocks/plant/bush.rs +++ b/pumpkin/src/block/blocks/plant/bush.rs @@ -15,10 +15,8 @@ impl BlockMetadata for BushBlock { } impl BlockBehaviour for BushBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/cactus.rs b/pumpkin/src/block/blocks/plant/cactus.rs index 1a950f1d7..f06494f69 100644 --- a/pumpkin/src/block/blocks/plant/cactus.rs +++ b/pumpkin/src/block/blocks/plant/cactus.rs @@ -20,7 +20,7 @@ pub struct CactusBlock; impl BlockBehaviour for CactusBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -31,19 +31,19 @@ impl BlockBehaviour for CactusBlock { fn random_tick<'a>(&'a self, args: RandomTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { let block_up = args.position.up(); - if args.world.get_block_state(&block_up).await.is_air() { - let state = args.world.get_block_state(args.position).await; + if args.world.get_block_state(&block_up).is_air() { + let state = args.world.get_block_state(args.position); let mut props = CactusLikeProperties::from_state_id(state.id, args.block); let age = props.age; let mut i = 1; - while args.world.get_block(&args.position.down_height(i)).await == &Block::CACTUS { + while args.world.get_block(&args.position.down_height(i)) == &Block::CACTUS { i += 1; if 1 == 3 && age == 15 { return; } } - if age == 8 && can_place_at(args.world.as_ref(), &block_up).await { + if age == 8 && can_place_at(args.world.as_ref(), &block_up) { let d = if i >= 3 { 0.25 } else { 0.1 }; if rand::rng().random_range(0.0..1.0) <= d { args.world @@ -102,7 +102,7 @@ impl BlockBehaviour for CactusBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -112,21 +112,19 @@ impl BlockBehaviour for CactusBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } } -async fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { +fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { for direction in BlockDirection::horizontal() { - let (block, state) = world - .get_block_and_state(&block_pos.offset(direction.to_offset())) - .await; + let (block, state) = world.get_block_and_state(&block_pos.offset(direction.to_offset())); if state.is_solid() || block == &Block::LAVA { return false; } } - let block = world.get_block(&block_pos.down()).await; + let block = world.get_block(&block_pos.down()); (block == &Block::CACTUS || block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_CACTUS)) - && !world.get_block_state(&block_pos.up()).await.is_liquid() + && !world.get_block_state(&block_pos.up()).is_liquid() } diff --git a/pumpkin/src/block/blocks/plant/cactus_flower.rs b/pumpkin/src/block/blocks/plant/cactus_flower.rs index 6e2536a11..1cd3b7b88 100644 --- a/pumpkin/src/block/blocks/plant/cactus_flower.rs +++ b/pumpkin/src/block/blocks/plant/cactus_flower.rs @@ -11,10 +11,8 @@ use pumpkin_world::world::BlockAccessor; pub struct CactusFlowerBlock; impl BlockBehaviour for CactusFlowerBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -33,14 +31,13 @@ impl BlockBehaviour for CactusFlowerBlock { } impl PlantBlockBase for CactusFlowerBlock { - async fn can_place_at( + fn can_place_at( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { let support_pos = pos.down(); - let (support_block, support_block_state) = - block_accessor.get_block_and_state(&support_pos).await; + let (support_block, support_block_state) = block_accessor.get_block_and_state(&support_pos); if supports_cactus_flower(support_block, support_block_state) { return true; } @@ -52,7 +49,7 @@ impl PlantBlockBase for CactusFlowerBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { return Block::AIR.default_state.id; } block_state diff --git a/pumpkin/src/block/blocks/plant/chorus_flower.rs b/pumpkin/src/block/blocks/plant/chorus_flower.rs index dbdfdafa1..b818f26e5 100644 --- a/pumpkin/src/block/blocks/plant/chorus_flower.rs +++ b/pumpkin/src/block/blocks/plant/chorus_flower.rs @@ -18,8 +18,8 @@ use crate::block::{ pub struct ChorusFlowerBlock; impl BlockBehaviour for ChorusFlowerBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_survive(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_survive(args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -27,8 +27,7 @@ impl BlockBehaviour for ChorusFlowerBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if args.direction != BlockDirection::Up && !can_survive(args.world, args.position).await - { + if args.direction != BlockDirection::Up && !can_survive(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -39,7 +38,7 @@ impl BlockBehaviour for ChorusFlowerBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_survive(args.world.as_ref(), args.position).await { + if !can_survive(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -48,8 +47,8 @@ impl BlockBehaviour for ChorusFlowerBlock { } } -async fn can_survive(block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block_below = block_accessor.get_block(&pos.down()).await; +fn can_survive(block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block_below = block_accessor.get_block(&pos.down()); if block_below == &Block::CHORUS_PLANT || block_below.has_tag(&tag::Block::MINECRAFT_SUPPORTS_CHORUS_FLOWER) @@ -65,7 +64,7 @@ async fn can_survive(block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool // Exactly one horizontal neighbor must be a chorus plant stem. let mut plant_count = 0u32; for dir in BlockDirection::horizontal() { - let neighbor = block_accessor.get_block(&pos.offset(dir.to_offset())).await; + let neighbor = block_accessor.get_block(&pos.offset(dir.to_offset())); if neighbor == &Block::CHORUS_PLANT { plant_count += 1; if plant_count > 1 { diff --git a/pumpkin/src/block/blocks/plant/chorus_plant.rs b/pumpkin/src/block/blocks/plant/chorus_plant.rs index bab1d8eb7..0dcc70075 100644 --- a/pumpkin/src/block/blocks/plant/chorus_plant.rs +++ b/pumpkin/src/block/blocks/plant/chorus_plant.rs @@ -23,12 +23,12 @@ impl BlockBehaviour for ChorusPlantBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { // Compute all 6 face connections immediately so the placed block visually connects to its neighbors. - get_state_with_connections(args.world, args.block, args.position).await + get_state_with_connections(args.world, args.block, args.position) }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_survive(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_survive(args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -36,7 +36,7 @@ impl BlockBehaviour for ChorusPlantBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_survive(args.world, args.position).await { + if !can_survive(args.world, args.position) { // Schedule delayed destruction so the whole plant cascades down. args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) @@ -45,7 +45,7 @@ impl BlockBehaviour for ChorusPlantBlock { } // Update the single face connection for the direction that changed. - let neighbor_block = args.world.get_block(args.neighbor_position).await; + let neighbor_block = args.world.get_block(args.neighbor_position); let connect = neighbor_block == &Block::CHORUS_PLANT || neighbor_block == &Block::CHORUS_FLOWER || (args.direction == BlockDirection::Down @@ -69,7 +69,7 @@ impl BlockBehaviour for ChorusPlantBlock { Box::pin(async move { // Destroy if unsupported; breaking propagates neighbor-update callbacks // to connected chorus blocks, which schedule their own ticks. - if !can_survive(args.world.as_ref(), args.position).await { + if !can_survive(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -78,7 +78,7 @@ impl BlockBehaviour for ChorusPlantBlock { } } -async fn get_state_with_connections( +fn get_state_with_connections( block_accessor: &dyn BlockAccessor, block: &Block, pos: &BlockPos, @@ -89,20 +89,12 @@ async fn get_state_with_connections( let connects = |b: &Block| b.id == plant_id || b.id == flower_id; - let block_down = block_accessor.get_block(&pos.down()).await; - let block_up = block_accessor.get_block(&pos.up()).await; - let block_north = block_accessor - .get_block(&pos.offset(BlockDirection::North.to_offset())) - .await; - let block_east = block_accessor - .get_block(&pos.offset(BlockDirection::East.to_offset())) - .await; - let block_south = block_accessor - .get_block(&pos.offset(BlockDirection::South.to_offset())) - .await; - let block_west = block_accessor - .get_block(&pos.offset(BlockDirection::West.to_offset())) - .await; + let block_down = block_accessor.get_block(&pos.down()); + let block_up = block_accessor.get_block(&pos.up()); + let block_north = block_accessor.get_block(&pos.offset(BlockDirection::North.to_offset())); + let block_east = block_accessor.get_block(&pos.offset(BlockDirection::East.to_offset())); + let block_south = block_accessor.get_block(&pos.offset(BlockDirection::South.to_offset())); + let block_west = block_accessor.get_block(&pos.offset(BlockDirection::West.to_offset())); let props = BrownMushroomBlockLikeProperties { down: connects(block_down) || block_down.has_tag(supports), @@ -115,12 +107,12 @@ async fn get_state_with_connections( props.to_state_id(block) } -async fn can_survive(block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { +fn can_survive(block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { let below_pos = pos.down(); let above_pos = pos.up(); - let (block_below, state_below) = block_accessor.get_block_and_state(&below_pos).await; - let state_above = block_accessor.get_block_state(&above_pos).await; + let (block_below, state_below) = block_accessor.get_block_and_state(&below_pos); + let state_above = block_accessor.get_block_state(&above_pos); // A horizontal branch is invalid when both the block immediately above and // below this one are non-air (enclosed inside something). @@ -128,12 +120,12 @@ async fn can_survive(block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool for dir in BlockDirection::horizontal() { let neighbor_pos = pos.offset(dir.to_offset()); - let neighbor_block = block_accessor.get_block(&neighbor_pos).await; + let neighbor_block = block_accessor.get_block(&neighbor_pos); if neighbor_block == &Block::CHORUS_PLANT { if block_above_or_below { return false; } - let neighbor_below = block_accessor.get_block(&neighbor_pos.down()).await; + let neighbor_below = block_accessor.get_block(&neighbor_pos.down()); if neighbor_below == &Block::CHORUS_PLANT || neighbor_below.has_tag(&tag::Block::MINECRAFT_SUPPORTS_CHORUS_PLANT) { diff --git a/pumpkin/src/block/blocks/plant/crop/beetroot.rs b/pumpkin/src/block/blocks/plant/crop/beetroot.rs index 454f7e115..ccd8eb065 100644 --- a/pumpkin/src/block/blocks/plant/crop/beetroot.rs +++ b/pumpkin/src/block/blocks/plant/crop/beetroot.rs @@ -16,15 +16,8 @@ type BeetrootProperties = NetherWartLikeProperties; pub struct BeetrootBlock; impl BlockBehaviour for BeetrootBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_plant_on_top( - self, - args.block_accessor, - &args.position.down(), - ) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_plant_on_top(self, args.block_accessor, &args.position.down()) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/crop/carrot.rs b/pumpkin/src/block/blocks/plant/crop/carrot.rs index 4dfbed95a..cf002a3de 100644 --- a/pumpkin/src/block/blocks/plant/crop/carrot.rs +++ b/pumpkin/src/block/blocks/plant/crop/carrot.rs @@ -11,15 +11,8 @@ use crate::block::{ pub struct CarrotBlock; impl BlockBehaviour for CarrotBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_plant_on_top( - self, - args.block_accessor, - &args.position.down(), - ) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_plant_on_top(self, args.block_accessor, &args.position.down()) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/crop/gourds/attached_stem.rs b/pumpkin/src/block/blocks/plant/crop/gourds/attached_stem.rs index cb540bb34..6ce5bb1fb 100644 --- a/pumpkin/src/block/blocks/plant/crop/gourds/attached_stem.rs +++ b/pumpkin/src/block/blocks/plant/crop/gourds/attached_stem.rs @@ -45,10 +45,8 @@ impl AttachedStemBlock { } impl BlockBehaviour for AttachedStemBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -76,8 +74,8 @@ impl BlockBehaviour for AttachedStemBlock { } impl PlantBlockBase for AttachedStemBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block = block_accessor.get_block(pos); if block == &Block::ATTACHED_PUMPKIN_STEM { block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_PUMPKIN_STEM) } else { diff --git a/pumpkin/src/block/blocks/plant/crop/gourds/stem.rs b/pumpkin/src/block/blocks/plant/crop/gourds/stem.rs index 6b2799be8..0bc54db92 100644 --- a/pumpkin/src/block/blocks/plant/crop/gourds/stem.rs +++ b/pumpkin/src/block/blocks/plant/crop/gourds/stem.rs @@ -58,10 +58,8 @@ impl StemBlock { } impl BlockBehaviour for StemBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -84,7 +82,7 @@ impl BlockBehaviour for StemBlock { // TODO add light level check let f: f32 = get_available_moisture(args.world, args.position, args.block).await; if rand::rng().random_range(0..=(25.0 / f).floor() as i32) == 0 { - let (block, state) = args.world.get_block_and_state_id(args.position).await; + let (block, state) = args.world.get_block_and_state_id(args.position); let props = StemProperties::from_state_id(state, block); let age = i32::from(props.age); if age < 7 { @@ -100,8 +98,8 @@ impl BlockBehaviour for StemBlock { Xoroshiro::from_seed(rand::rng().random()), )); let plant_block_pos = args.position.offset(dir.to_offset()); - let plant_block_state = args.world.get_block_state(&plant_block_pos).await; - let under_block: &Block = args.world.get_block(&plant_block_pos.down()).await; + let plant_block_state = args.world.get_block_state(&plant_block_pos); + let under_block: &Block = args.world.get_block(&plant_block_pos.down()); if plant_block_state.is_air() && (under_block == &Block::FARMLAND || under_block.has_tag(&tag::Block::MINECRAFT_DIRT)) @@ -130,8 +128,8 @@ impl BlockBehaviour for StemBlock { } impl PlantBlockBase for StemBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block = block_accessor.get_block(pos); if block == &Block::PUMPKIN_STEM { block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_PUMPKIN_STEM) } else { diff --git a/pumpkin/src/block/blocks/plant/crop/mod.rs b/pumpkin/src/block/blocks/plant/crop/mod.rs index c5c91c9aa..e8fcf9d09 100644 --- a/pumpkin/src/block/blocks/plant/crop/mod.rs +++ b/pumpkin/src/block/blocks/plant/crop/mod.rs @@ -30,8 +30,8 @@ pub mod torch_flower; pub mod wheat; trait CropBlockBase: PlantBlockBase { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block = block_accessor.get_block(pos); block == &Block::FARMLAND } @@ -51,7 +51,7 @@ trait CropBlockBase: PlantBlockBase { } async fn random_tick(&self, world: &Arc, pos: &BlockPos) { - let (block, state) = world.get_block_and_state_id(pos).await; + let (block, state) = world.get_block_and_state_id(pos); let age = self.get_age(state, block); if age < self.max_age() { let f = get_available_moisture(world, pos, block).await; @@ -90,9 +90,8 @@ pub async fn get_available_moisture(world: &Arc, pos: &BlockPos, block: & for dz in -1..=1 { let mut local_moisture = 0.0; - let (block, block_state) = world - .get_block_and_state_id(&down_pos.offset(Vector3 { x: dx, y: 0, z: dz })) - .await; + let (block, block_state) = + world.get_block_and_state_id(&down_pos.offset(Vector3 { x: dx, y: 0, z: dz })); if block == &Block::FARMLAND { local_moisture = 1.0; let props = FarmlandProperties::from_state_id(block_state, block); @@ -113,13 +112,13 @@ pub async fn get_available_moisture(world: &Arc, pos: &BlockPos, block: & let south = pos.offset(South.to_offset()); let west = pos.offset(West.to_offset()); let east = pos.offset(East.to_offset()); - let horizontal = world.get_block(&west).await == block || world.get_block(&east).await == block; - let vertical = world.get_block(&north).await == block || world.get_block(&south).await == block; + let horizontal = world.get_block(&west) == block || world.get_block(&east) == block; + let vertical = world.get_block(&north) == block || world.get_block(&south) == block; if (horizontal && vertical) - || world.get_block(&west.offset(North.to_offset())).await == block - || world.get_block(&east.offset(North.to_offset())).await == block - || world.get_block(&east.offset(South.to_offset())).await == block - || world.get_block(&west.offset(South.to_offset())).await == block + || world.get_block(&west.offset(North.to_offset())) == block + || world.get_block(&east.offset(North.to_offset())) == block + || world.get_block(&east.offset(South.to_offset())) == block + || world.get_block(&west.offset(South.to_offset())) == block { moisture /= 2.0; } diff --git a/pumpkin/src/block/blocks/plant/crop/nether_wart.rs b/pumpkin/src/block/blocks/plant/crop/nether_wart.rs index 51e01445b..dbf993dae 100644 --- a/pumpkin/src/block/blocks/plant/crop/nether_wart.rs +++ b/pumpkin/src/block/blocks/plant/crop/nether_wart.rs @@ -25,10 +25,8 @@ use crate::{ pub struct NetherWartBlock; impl BlockBehaviour for NetherWartBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -54,19 +52,19 @@ impl BlockBehaviour for NetherWartBlock { } impl PlantBlockBase for NetherWartBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block = block_accessor.get_block(pos); block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_NETHER_WART) } - async fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - ::can_plant_on_top(self, block_accessor, &block_pos.down()).await + fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + ::can_plant_on_top(self, block_accessor, &block_pos.down()) } } impl CropBlockBase for NetherWartBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - ::can_plant_on_top(self, block_accessor, pos).await + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + ::can_plant_on_top(self, block_accessor, pos) } fn max_age(&self) -> i32 { @@ -85,7 +83,7 @@ impl CropBlockBase for NetherWartBlock { } async fn random_tick(&self, world: &Arc, pos: &BlockPos) { - let (block, state) = world.get_block_and_state_id(pos).await; + let (block, state) = world.get_block_and_state_id(pos); let age = self.get_age(state, block); if age < self.max_age() && rand::rng().random_range(0..=10) == 0 { world diff --git a/pumpkin/src/block/blocks/plant/crop/potatoes.rs b/pumpkin/src/block/blocks/plant/crop/potatoes.rs index 2590b9dd2..92cfd7e53 100644 --- a/pumpkin/src/block/blocks/plant/crop/potatoes.rs +++ b/pumpkin/src/block/blocks/plant/crop/potatoes.rs @@ -11,15 +11,8 @@ use crate::block::{ pub struct PotatoBlock; impl BlockBehaviour for PotatoBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_plant_on_top( - self, - args.block_accessor, - &args.position.down(), - ) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_plant_on_top(self, args.block_accessor, &args.position.down()) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/crop/sweet_berry_bush.rs b/pumpkin/src/block/blocks/plant/crop/sweet_berry_bush.rs index c7aa858e6..f620a940d 100644 --- a/pumpkin/src/block/blocks/plant/crop/sweet_berry_bush.rs +++ b/pumpkin/src/block/blocks/plant/crop/sweet_berry_bush.rs @@ -32,7 +32,7 @@ pub struct SweetBerryBushBlock; impl BlockBehaviour for SweetBerryBushBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let mut props = NetherWartLikeProperties::from_state_id(state_id, args.block); match props.age { 2 | 3 => { @@ -66,7 +66,7 @@ impl BlockBehaviour for SweetBerryBushBlock { args: UseWithItemArgs<'a>, ) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let props = NetherWartLikeProperties::from_state_id(state_id, &Block::SWEET_BERRY_BUSH); if props.age != 3 && args.item_stack.lock().await.get_item() == &Item::BONE_MEAL { BlockActionResult::Pass @@ -76,10 +76,8 @@ impl BlockBehaviour for SweetBerryBushBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -119,7 +117,7 @@ impl BlockBehaviour for SweetBerryBushBlock { entity.last_pos.load() - entity.pos.load() }; - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let props = NetherWartLikeProperties::from_state_id(state_id, args.block); if props.age == 0 { return; @@ -153,20 +151,20 @@ impl PlantBlockBase for SweetBerryBushBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { return Block::AIR.default_state.id; } block_state } - async fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - ::can_plant_on_top(self, block_accessor, &block_pos.down()).await + fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + ::can_plant_on_top(self, block_accessor, &block_pos.down()) } } impl CropBlockBase for SweetBerryBushBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - ::can_plant_on_top(self, block_accessor, pos).await + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + ::can_plant_on_top(self, block_accessor, pos) } fn max_age(&self) -> i32 { @@ -185,10 +183,10 @@ impl CropBlockBase for SweetBerryBushBlock { } async fn random_tick(&self, world: &Arc, pos: &BlockPos) { - let (block, state) = world.get_block_and_state_id(pos).await; + let (block, state) = world.get_block_and_state_id(pos); let age = self.get_age(state, block); if age < self.max_age() { - let state_above = world.get_block_state(&pos.up()).await; + let state_above = world.get_block_state(&pos.up()); if state_above.is_full_cube() || state_above.is_solid() { return; diff --git a/pumpkin/src/block/blocks/plant/crop/torch_flower.rs b/pumpkin/src/block/blocks/plant/crop/torch_flower.rs index 9a0b30cfa..090f2408a 100644 --- a/pumpkin/src/block/blocks/plant/crop/torch_flower.rs +++ b/pumpkin/src/block/blocks/plant/crop/torch_flower.rs @@ -16,15 +16,8 @@ type TorchFlowerProperties = TorchflowerCropLikeProperties; pub struct TorchFlowerBlock; impl BlockBehaviour for TorchFlowerBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_plant_on_top( - self, - args.block_accessor, - &args.position.down(), - ) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_plant_on_top(self, args.block_accessor, &args.position.down()) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/crop/wheat.rs b/pumpkin/src/block/blocks/plant/crop/wheat.rs index a795d4f94..c80a4aec3 100644 --- a/pumpkin/src/block/blocks/plant/crop/wheat.rs +++ b/pumpkin/src/block/blocks/plant/crop/wheat.rs @@ -11,15 +11,8 @@ use crate::block::{ pub struct WheatBlock; impl BlockBehaviour for WheatBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_plant_on_top( - self, - args.block_accessor, - &args.position.down(), - ) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_plant_on_top(self, args.block_accessor, &args.position.down()) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/dry_vegetation.rs b/pumpkin/src/block/blocks/plant/dry_vegetation.rs index 62794e530..61c4dc3f2 100644 --- a/pumpkin/src/block/blocks/plant/dry_vegetation.rs +++ b/pumpkin/src/block/blocks/plant/dry_vegetation.rs @@ -22,10 +22,8 @@ impl BlockMetadata for DryVegetationBlock { } impl BlockBehaviour for DryVegetationBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -45,12 +43,8 @@ impl BlockBehaviour for DryVegetationBlock { } impl PlantBlockBase for DryVegetationBlock { - async fn can_plant_on_top( - &self, - block_accessor: &dyn BlockAccessor, - block_pos: &BlockPos, - ) -> bool { - let block_below = block_accessor.get_block(block_pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + let block_below = block_accessor.get_block(block_pos); block_below.has_tag(&tag::Block::MINECRAFT_SUPPORTS_DRY_VEGETATION) } } diff --git a/pumpkin/src/block/blocks/plant/flower.rs b/pumpkin/src/block/blocks/plant/flower.rs index c417b10e5..b9731e0d8 100644 --- a/pumpkin/src/block/blocks/plant/flower.rs +++ b/pumpkin/src/block/blocks/plant/flower.rs @@ -19,10 +19,8 @@ impl BlockMetadata for FlowerBlock { } impl BlockBehaviour for FlowerBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/flowerbed.rs b/pumpkin/src/block/blocks/plant/flowerbed.rs index d3c7c2c83..f826f9baa 100644 --- a/pumpkin/src/block/blocks/plant/flowerbed.rs +++ b/pumpkin/src/block/blocks/plant/flowerbed.rs @@ -22,19 +22,17 @@ impl BlockMetadata for FlowerbedBlock { } impl BlockBehaviour for FlowerbedBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let block_below = args.block_accessor.get_block(&args.position.down()).await; - block_below.has_tag(&tag::Block::MINECRAFT_DIRT) || block_below == &Block::FARMLAND - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let block_below = args.block_accessor.get_block(&args.position.down()); + block_below.has_tag(&tag::Block::MINECRAFT_DIRT) || block_below == &Block::FARMLAND } - fn can_update_at<'a>(&'a self, args: CanUpdateAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { Segmented::can_update_at(self, args).await }) + fn can_update_at(&self, args: CanUpdateAtArgs<'_>) -> bool { + Segmented::can_update_at(self, args) } fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { - Box::pin(async move { Segmented::on_place(self, args).await }) + Segmented::on_place(self, args) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/fungus.rs b/pumpkin/src/block/blocks/plant/fungus.rs index b545bebe7..fe6bfe9c4 100644 --- a/pumpkin/src/block/blocks/plant/fungus.rs +++ b/pumpkin/src/block/blocks/plant/fungus.rs @@ -14,10 +14,8 @@ impl BlockMetadata for FungusBlock { } impl BlockBehaviour for FungusBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -35,19 +33,19 @@ impl BlockBehaviour for FungusBlock { } } impl PlantBlockBase for FungusBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { - let block = block_accessor.get_block(pos).await; + let block = block_accessor.get_block(pos); if block == &Block::WARPED_FUNGUS { return block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_WARPED_FUNGUS); } block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_CRIMSON_FUNGUS) } - async fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - ::can_plant_on_top(self, block_accessor, &block_pos.down()).await + fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + ::can_plant_on_top(self, block_accessor, &block_pos.down()) } } diff --git a/pumpkin/src/block/blocks/plant/kelp.rs b/pumpkin/src/block/blocks/plant/kelp.rs index bb93b8421..c90b9be62 100644 --- a/pumpkin/src/block/blocks/plant/kelp.rs +++ b/pumpkin/src/block/blocks/plant/kelp.rs @@ -18,10 +18,8 @@ impl BlockMetadata for KelpBlock { } impl BlockBehaviour for KelpBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -40,7 +38,7 @@ impl BlockBehaviour for KelpBlock { fn placed<'a>(&'a self, args: PlacedArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { let support_pos = args.position.down(); - let support_block = args.world.get_block(&support_pos).await; + let support_block = args.world.get_block(&support_pos); if support_block == &Block::KELP { args.world .set_block_state( @@ -55,7 +53,7 @@ impl BlockBehaviour for KelpBlock { fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { let support_pos = args.position.down(); - let support_block = args.world.get_block(&support_pos).await; + let support_block = args.world.get_block(&support_pos); if support_block == &Block::KELP_PLANT { args.world .set_block_state( @@ -77,7 +75,7 @@ impl BlockBehaviour for KelpBlock { } impl PlantBlockBase for KelpBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, @@ -85,9 +83,8 @@ impl PlantBlockBase for KelpBlock { // Determine support block let support_pos = pos; let (replacing_block, replacing_block_state) = - block_accessor.get_block_and_state(&pos.up()).await; - let (support_block, support_block_state) = - block_accessor.get_block_and_state(support_pos).await; + block_accessor.get_block_and_state(&pos.up()); + let (support_block, support_block_state) = block_accessor.get_block_and_state(support_pos); if replacing_block == &Block::WATER { let water_props = WaterLikeProperties::from_state_id(replacing_block_state.id, replacing_block); @@ -122,7 +119,7 @@ impl PlantBlockBase for KelpBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { return Block::WATER.default_state.id; } block_state diff --git a/pumpkin/src/block/blocks/plant/leaf_litter.rs b/pumpkin/src/block/blocks/plant/leaf_litter.rs index de7807970..a67f9a313 100644 --- a/pumpkin/src/block/blocks/plant/leaf_litter.rs +++ b/pumpkin/src/block/blocks/plant/leaf_litter.rs @@ -19,18 +19,13 @@ impl BlockMetadata for LeafLitterBlock { } impl BlockBehaviour for LeafLitterBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let block_below = args - .block_accessor - .get_block_state(&args.position.down()) - .await; - block_below.is_side_solid(BlockDirection::Up) - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let block_below = args.block_accessor.get_block_state(&args.position.down()); + block_below.is_side_solid(BlockDirection::Up) } - fn can_update_at<'a>(&'a self, args: CanUpdateAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { Segmented::can_update_at(self, args).await }) + fn can_update_at(&self, args: CanUpdateAtArgs<'_>) -> bool { + Segmented::can_update_at(self, args) } fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { @@ -43,7 +38,7 @@ impl BlockBehaviour for LeafLitterBlock { ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { if args.direction == BlockDirection::Down { - let block_below_state = args.world.get_block_state(&args.position.down()).await; + let block_below_state = args.world.get_block_state(&args.position.down()); if !block_below_state.is_side_solid(BlockDirection::Up) { return Block::AIR.default_state.id; } diff --git a/pumpkin/src/block/blocks/plant/lily_pad.rs b/pumpkin/src/block/blocks/plant/lily_pad.rs index 00080c9c1..1a64d71a3 100644 --- a/pumpkin/src/block/blocks/plant/lily_pad.rs +++ b/pumpkin/src/block/blocks/plant/lily_pad.rs @@ -31,10 +31,8 @@ impl BlockBehaviour for LilyPadBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -54,10 +52,10 @@ impl BlockBehaviour for LilyPadBlock { } impl PlantBlockBase for LilyPadBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { // TODO: get and use fluids not blocks - let block = block_accessor.get_block(pos).await; - let above_fluid = block_accessor.get_block(&pos.up()).await; + let block = block_accessor.get_block(pos); + let above_fluid = block_accessor.get_block(&pos.up()); (block.has_tag(&tag::Fluid::MINECRAFT_SUPPORTS_LILY_PAD) || block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_LILY_PAD)) && above_fluid.is_air() diff --git a/pumpkin/src/block/blocks/plant/mod.rs b/pumpkin/src/block/blocks/plant/mod.rs index 3aa847563..d7181943f 100644 --- a/pumpkin/src/block/blocks/plant/mod.rs +++ b/pumpkin/src/block/blocks/plant/mod.rs @@ -37,8 +37,8 @@ pub mod weeping_vines; pub mod wither_rose; trait PlantBlockBase { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block = block_accessor.get_block(pos); block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_VEGETATION) } @@ -48,14 +48,13 @@ trait PlantBlockBase { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !self.can_place_at(block_accessor, block_pos).await { + if !self.can_place_at(block_accessor, block_pos) { return Block::AIR.default_state.id; } block_state } - async fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { self.can_plant_on_top(block_accessor, &block_pos.down()) - .await } } diff --git a/pumpkin/src/block/blocks/plant/mushroom_plant.rs b/pumpkin/src/block/blocks/plant/mushroom_plant.rs index 008c86f19..52790b3bf 100644 --- a/pumpkin/src/block/blocks/plant/mushroom_plant.rs +++ b/pumpkin/src/block/blocks/plant/mushroom_plant.rs @@ -17,10 +17,8 @@ impl BlockMetadata for MushroomPlantBlock { } impl BlockBehaviour for MushroomPlantBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -40,8 +38,8 @@ impl BlockBehaviour for MushroomPlantBlock { } impl PlantBlockBase for MushroomPlantBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block = block_accessor.get_block(pos); block.has_tag(&tag::Block::MINECRAFT_OVERRIDES_MUSHROOM_LIGHT_REQUIREMENT) // TODO: Check light level and isOpaqueFullCube } diff --git a/pumpkin/src/block/blocks/plant/nether_sprouts.rs b/pumpkin/src/block/blocks/plant/nether_sprouts.rs index ba72b0854..365a0e165 100644 --- a/pumpkin/src/block/blocks/plant/nether_sprouts.rs +++ b/pumpkin/src/block/blocks/plant/nether_sprouts.rs @@ -7,10 +7,8 @@ use pumpkin_world::BlockStateId; pub struct NetherSproutsBlock; impl BlockBehaviour for NetherSproutsBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -28,12 +26,12 @@ impl BlockBehaviour for NetherSproutsBlock { } } impl PlantBlockBase for NetherSproutsBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { - let block = block_accessor.get_block(pos).await; + let block = block_accessor.get_block(pos); block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_NETHER_SPROUTS) } } diff --git a/pumpkin/src/block/blocks/plant/roots.rs b/pumpkin/src/block/blocks/plant/roots.rs index 7bc1b7f32..13053f733 100644 --- a/pumpkin/src/block/blocks/plant/roots.rs +++ b/pumpkin/src/block/blocks/plant/roots.rs @@ -18,10 +18,8 @@ impl BlockMetadata for RootsBlock { } impl BlockBehaviour for RootsBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -41,8 +39,8 @@ impl BlockBehaviour for RootsBlock { } impl PlantBlockBase for RootsBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let block_below = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let block_below = block_accessor.get_block(pos); if block_below == &Block::WARPED_ROOTS { block_below.has_tag(&tag::Block::MINECRAFT_SUPPORTS_WARPED_ROOTS) } else { @@ -50,8 +48,7 @@ impl PlantBlockBase for RootsBlock { } } - async fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { self.can_plant_on_top(block_accessor, &block_pos.down()) - .await } } diff --git a/pumpkin/src/block/blocks/plant/sapling.rs b/pumpkin/src/block/blocks/plant/sapling.rs index 12c547279..b405379f3 100644 --- a/pumpkin/src/block/blocks/plant/sapling.rs +++ b/pumpkin/src/block/blocks/plant/sapling.rs @@ -18,7 +18,7 @@ pub struct SaplingBlock; impl SaplingBlock { async fn generate(&self, world: &Arc, pos: &BlockPos) { - let (block, state) = world.get_block_and_state_id(pos).await; + let (block, state) = world.get_block_and_state_id(pos); let mut props = SaplingProperties::from_state_id(state, block); if props.stage == 0 { props.stage = 1; @@ -32,10 +32,8 @@ impl SaplingBlock { } impl BlockBehaviour for SaplingBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/sea_pickles.rs b/pumpkin/src/block/blocks/plant/sea_pickles.rs index 995572583..964aa906a 100644 --- a/pumpkin/src/block/blocks/plant/sea_pickles.rs +++ b/pumpkin/src/block/blocks/plant/sea_pickles.rs @@ -32,10 +32,9 @@ impl BlockBehaviour for SeaPickleBlock { || !args .world .get_block(&args.position.down()) - .await .has_tag(&tag::Block::MINECRAFT_CORAL_BLOCKS) || !SeaPickleProperties::from_state_id( - args.world.get_block_state_id(args.position).await, + args.world.get_block_state_id(args.position), args.block, ) .waterlogged @@ -62,11 +61,10 @@ impl BlockBehaviour for SeaPickleBlock { ); if &lv == args.position || rand::rng().random_range(0..6) != 0 - || !args.world.get_block(&lv).await.eq(&Block::WATER) + || !args.world.get_block(&lv).eq(&Block::WATER) || !args .world .get_block(&lv.down()) - .await .has_tag(&tag::Block::MINECRAFT_CORAL_BLOCKS) { continue; @@ -124,21 +122,14 @@ impl BlockBehaviour for SeaPickleBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let support_block = args - .block_accessor - .get_block_state(&args.position.down()) - .await; - support_block.is_center_solid(BlockDirection::Up) - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let support_block = args.block_accessor.get_block_state(&args.position.down()); + support_block.is_center_solid(BlockDirection::Up) } - fn can_update_at<'a>(&'a self, args: CanUpdateAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - args.player.get_entity().pose.load() != EntityPose::Crouching - && SeaPickleProperties::from_state_id(args.state_id, args.block).pickles < 4 - }) + fn can_update_at(&self, args: CanUpdateAtArgs<'_>) -> bool { + args.player.get_entity().pose.load() != EntityPose::Crouching + && SeaPickleProperties::from_state_id(args.state_id, args.block).pickles < 4 } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/seagrass.rs b/pumpkin/src/block/blocks/plant/seagrass.rs index bf0eebea0..6e7a3b6a5 100644 --- a/pumpkin/src/block/blocks/plant/seagrass.rs +++ b/pumpkin/src/block/blocks/plant/seagrass.rs @@ -13,10 +13,8 @@ use crate::block::{ #[pumpkin_block("minecraft:seagrass")] pub struct SeaGrassBlock; impl BlockBehaviour for SeaGrassBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -36,13 +34,13 @@ impl BlockBehaviour for SeaGrassBlock { } impl PlantBlockBase for SeaGrassBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { - let (support_block, support_block_state) = block_accessor.get_block_and_state(pos).await; - let replacing_block = block_accessor.get_block(&pos.up()).await; + let (support_block, support_block_state) = block_accessor.get_block_and_state(pos); + let replacing_block = block_accessor.get_block(&pos.up()); if replacing_block != &Block::WATER && replacing_block != &Block::SEAGRASS { return false; } @@ -57,7 +55,7 @@ impl PlantBlockBase for SeaGrassBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { return Block::WATER.default_state.id; } block_state diff --git a/pumpkin/src/block/blocks/plant/segmented.rs b/pumpkin/src/block/blocks/plant/segmented.rs index 47680a897..43a264a81 100644 --- a/pumpkin/src/block/blocks/plant/segmented.rs +++ b/pumpkin/src/block/blocks/plant/segmented.rs @@ -73,11 +73,9 @@ pub trait Segmented: BlockBehaviour { } } - fn can_update_at<'a>(&'a self, ctx: CanUpdateAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let current_props = Self::Properties::from_state_id(ctx.state_id, ctx.block); - self.can_add_segment(¤t_props) - }) + fn can_update_at(&self, ctx: CanUpdateAtArgs<'_>) -> bool { + let current_props = Self::Properties::from_state_id(ctx.state_id, ctx.block); + self.can_add_segment(¤t_props) } fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { diff --git a/pumpkin/src/block/blocks/plant/short_plant.rs b/pumpkin/src/block/blocks/plant/short_plant.rs index eaa0a4345..741357a09 100644 --- a/pumpkin/src/block/blocks/plant/short_plant.rs +++ b/pumpkin/src/block/blocks/plant/short_plant.rs @@ -15,10 +15,8 @@ impl BlockMetadata for ShortPlantBlock { } impl BlockBehaviour for ShortPlantBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/plant/small_dripleaf.rs b/pumpkin/src/block/blocks/plant/small_dripleaf.rs index 458d1bdb2..7852d00e5 100644 --- a/pumpkin/src/block/blocks/plant/small_dripleaf.rs +++ b/pumpkin/src/block/blocks/plant/small_dripleaf.rs @@ -17,10 +17,8 @@ use pumpkin_world::world::{BlockAccessor, BlockFlags}; pub struct SmallDripleafBlock; impl BlockBehaviour for SmallDripleafBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { @@ -65,7 +63,7 @@ impl BlockBehaviour for SmallDripleafBlock { let mut upper_small_dripleaf_props = SmallDripleafLikeProperties::default(&Block::SMALL_DRIPLEAF); - let upper_block = args.world.get_block(&args.position.up()).await; + let upper_block = args.world.get_block(&args.position.up()); upper_small_dripleaf_props.facing = lower_small_dripleaf_props.facing; upper_small_dripleaf_props.waterlogged = upper_block == &Block::WATER; upper_small_dripleaf_props.half = DoubleBlockHalf::Upper; @@ -86,13 +84,13 @@ fn is_small_dripleaf_waterlogged(state_id: BlockStateId) -> bool { dripleaf_props.waterlogged } impl PlantBlockBase for SmallDripleafBlock { - async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let support_block = block_accessor.get_block(pos).await; + fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let support_block = block_accessor.get_block(pos); if support_block == &Block::SMALL_DRIPLEAF { return true; } - let upper_block = block_accessor.get_block(&pos.up_height(2)).await; + let upper_block = block_accessor.get_block(&pos.up_height(2)); if upper_block != &Block::AIR && upper_block != &Block::WATER && upper_block != &Block::SMALL_DRIPLEAF @@ -100,7 +98,7 @@ impl PlantBlockBase for SmallDripleafBlock { return false; } let (replacing_block, replacing_block_state) = - block_accessor.get_block_and_state(&pos.up()).await; + block_accessor.get_block_and_state(&pos.up()); if replacing_block == &Block::SMALL_DRIPLEAF && replacing_block_state.is_waterlogged() { //in case of neighbor update check supports_small_dripleaf(support_block, true) @@ -115,14 +113,14 @@ impl PlantBlockBase for SmallDripleafBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { if is_small_dripleaf_waterlogged(block_state) { return Block::WATER.default_state.id; } return Block::AIR.default_state.id; } - let upper_block = block_accessor.get_block(&block_pos.up()).await; - let below_blow = block_accessor.get_block(&block_pos.down()).await; + let upper_block = block_accessor.get_block(&block_pos.up()); + let below_blow = block_accessor.get_block(&block_pos.down()); if upper_block != &Block::SMALL_DRIPLEAF && below_blow != &Block::SMALL_DRIPLEAF { if is_small_dripleaf_waterlogged(block_state) { return Block::WATER.default_state.id; diff --git a/pumpkin/src/block/blocks/plant/spore_blossom.rs b/pumpkin/src/block/blocks/plant/spore_blossom.rs index 089db5af1..85c991f87 100644 --- a/pumpkin/src/block/blocks/plant/spore_blossom.rs +++ b/pumpkin/src/block/blocks/plant/spore_blossom.rs @@ -11,10 +11,8 @@ use pumpkin_world::world::BlockAccessor; pub struct SporeBlossomBlock; impl BlockBehaviour for SporeBlossomBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -32,15 +30,15 @@ impl BlockBehaviour for SporeBlossomBlock { } } impl PlantBlockBase for SporeBlossomBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, _block_accessor: &dyn pumpkin_world::world::BlockAccessor, _pos: &pumpkin_util::math::position::BlockPos, ) -> bool { false } - async fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - let ceiling_block = block_accessor.get_block(&block_pos.up()).await; + fn can_place_at(&self, block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + let ceiling_block = block_accessor.get_block(&block_pos.up()); supports_spore_blossom(ceiling_block) } } diff --git a/pumpkin/src/block/blocks/plant/sugar_cane.rs b/pumpkin/src/block/blocks/plant/sugar_cane.rs index 4412e7a0e..8bc6cc0ef 100644 --- a/pumpkin/src/block/blocks/plant/sugar_cane.rs +++ b/pumpkin/src/block/blocks/plant/sugar_cane.rs @@ -22,7 +22,7 @@ pub struct SugarCaneBlock; impl BlockBehaviour for SugarCaneBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -32,16 +32,11 @@ impl BlockBehaviour for SugarCaneBlock { fn random_tick<'a>(&'a self, args: RandomTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if args - .world - .get_block_state(&args.position.up()) - .await - .is_air() - && !(args.world.get_block(&args.position.down()).await == &Block::SUGAR_CANE - && args.world.get_block(&args.position.down().down()).await - == &Block::SUGAR_CANE) + if args.world.get_block_state(&args.position.up()).is_air() + && !(args.world.get_block(&args.position.down()) == &Block::SUGAR_CANE + && args.world.get_block(&args.position.down().down()) == &Block::SUGAR_CANE) { - let state_id = args.world.get_block_state(args.position).await.id; + let state_id = args.world.get_block_state(args.position).id; let age = CactusLikeProperties::from_state_id(state_id, args.block).age; if age == 15 { args.world @@ -74,7 +69,7 @@ impl BlockBehaviour for SugarCaneBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -83,13 +78,13 @@ impl BlockBehaviour for SugarCaneBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } } -async fn can_place_at(block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - let block_below = block_accessor.get_block(&block_pos.down()).await; +fn can_place_at(block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + let block_below = block_accessor.get_block(&block_pos.down()); if block_below == &Block::SUGAR_CANE { return true; @@ -97,9 +92,7 @@ async fn can_place_at(block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) if block_below.has_tag(&tag::Block::MINECRAFT_SUPPORTS_SUGAR_CANE) { for direction in HorizontalFacing::all() { - let block = block_accessor - .get_block(&block_pos.down().offset(direction.to_offset())) - .await; + let block = block_accessor.get_block(&block_pos.down().offset(direction.to_offset())); // TODO: use fluid if block.has_tag(&tag::Fluid::MINECRAFT_SUPPORTS_SUGAR_CANE_ADJACENTLY) && block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_SUGAR_CANE_ADJACENTLY) diff --git a/pumpkin/src/block/blocks/plant/tall_plant.rs b/pumpkin/src/block/blocks/plant/tall_plant.rs index 6e8a0e4c6..4c033a006 100644 --- a/pumpkin/src/block/blocks/plant/tall_plant.rs +++ b/pumpkin/src/block/blocks/plant/tall_plant.rs @@ -32,32 +32,23 @@ impl BlockMetadata for TallPlantBlock { } impl BlockBehaviour for TallPlantBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let up_pos = args.position.up(); + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let up_pos = args.position.up(); - let upper_state = args.block_accessor.get_block_state(&up_pos).await; - let Some(world) = args.world else { - return ::can_place_at( - self, - args.block_accessor, - args.position, - ) - .await - && upper_state.is_air(); - }; - - if up_pos.0.y > world.get_top_y() { - return false; - } + let upper_state = args.block_accessor.get_block_state(&up_pos); + let Some(world) = args.world else { return ::can_place_at( self, args.block_accessor, args.position, - ) - .await - && upper_state.is_air(); - }) + ) && upper_state.is_air(); + }; + + if up_pos.0.y > world.get_top_y() { + return false; + } + ::can_place_at(self, args.block_accessor, args.position) + && upper_state.is_air() } fn get_state_for_neighbor_update<'a>( @@ -71,14 +62,11 @@ impl BlockBehaviour for TallPlantBlock { DoubleBlockHalf::Upper => (args.position.down_height(2), args.position.down()), DoubleBlockHalf::Lower => (args.position.down(), args.position.up()), }; - if !::can_place_at(self, args.world, &support_block_pos.up()) - .await - { + if !::can_place_at(self, args.world, &support_block_pos.up()) { return Block::AIR.default_state.id; } - let (other_block, other_state_id) = - args.world.get_block_and_state_id(&other_block_pos).await; + let (other_block, other_state_id) = args.world.get_block_and_state_id(&other_block_pos); if Self::ids().contains(&other_block.id) { let other_props = TallSeagrassLikeProperties::from_state_id(other_state_id, other_block); @@ -117,8 +105,7 @@ impl BlockBehaviour for TallPlantBlock { DoubleBlockHalf::Upper => args.position.down(), DoubleBlockHalf::Lower => args.position.up(), }; - let (other_block, other_state_id) = - args.world.get_block_and_state_id(&other_block_pos).await; + let (other_block, other_state_id) = args.world.get_block_and_state_id(&other_block_pos); if Self::ids().contains(&other_block.id) { let other_props = TallSeagrassLikeProperties::from_state_id(other_state_id, other_block); diff --git a/pumpkin/src/block/blocks/plant/tall_seagrass.rs b/pumpkin/src/block/blocks/plant/tall_seagrass.rs index 72da556ea..f45eb9fea 100644 --- a/pumpkin/src/block/blocks/plant/tall_seagrass.rs +++ b/pumpkin/src/block/blocks/plant/tall_seagrass.rs @@ -10,10 +10,8 @@ use crate::block::{ #[pumpkin_block("minecraft:tall_seagrass")] pub struct TallSeaGrassBlock; impl BlockBehaviour for TallSeaGrassBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( @@ -33,20 +31,20 @@ impl BlockBehaviour for TallSeaGrassBlock { } impl PlantBlockBase for TallSeaGrassBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { - let (support_block, support_block_state) = block_accessor.get_block_and_state(pos).await; - let replacing_block = block_accessor.get_block(&pos.up()).await; + let (support_block, support_block_state) = block_accessor.get_block_and_state(pos); + let replacing_block = block_accessor.get_block(&pos.up()); if replacing_block != &Block::WATER && replacing_block != &Block::TALL_SEAGRASS { return false; } if replacing_block == &Block::TALL_SEAGRASS { //only for blockupdate - let block_above = block_accessor.get_block(&pos.up_height(2)).await; + let block_above = block_accessor.get_block(&pos.up_height(2)); let is_support_seagrass_block = support_block == &Block::TALL_SEAGRASS; let is_above_seagrass_block = block_above == &Block::TALL_SEAGRASS; match (is_support_seagrass_block, is_above_seagrass_block) { @@ -68,7 +66,7 @@ impl PlantBlockBase for TallSeaGrassBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { return Block::WATER.default_state.id; } block_state diff --git a/pumpkin/src/block/blocks/plant/twisting_vines.rs b/pumpkin/src/block/blocks/plant/twisting_vines.rs index 1ae1cc9ff..963568c55 100644 --- a/pumpkin/src/block/blocks/plant/twisting_vines.rs +++ b/pumpkin/src/block/blocks/plant/twisting_vines.rs @@ -16,10 +16,8 @@ impl BlockMetadata for TwistingVinesBlock { } impl BlockBehaviour for TwistingVinesBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -38,7 +36,7 @@ impl BlockBehaviour for TwistingVinesBlock { fn placed<'a>(&'a self, args: PlacedArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { let support_pos = args.position.down(); - let support_block = args.world.get_block(&support_pos).await; + let support_block = args.world.get_block(&support_pos); if support_block == &Block::TWISTING_VINES { args.world .set_block_state( @@ -53,7 +51,7 @@ impl BlockBehaviour for TwistingVinesBlock { fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { let support_pos = args.position.down(); - let support_block = args.world.get_block(&support_pos).await; + let support_block = args.world.get_block(&support_pos); if support_block == &Block::TWISTING_VINES_PLANT { args.world .set_block_state( @@ -68,15 +66,14 @@ impl BlockBehaviour for TwistingVinesBlock { } impl PlantBlockBase for TwistingVinesBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { // Determine support block let support_pos = pos; - let (support_block, support_block_state) = - block_accessor.get_block_and_state(support_pos).await; + let (support_block, support_block_state) = block_accessor.get_block_and_state(support_pos); if support_block == &Block::TWISTING_VINES || support_block == &Block::TWISTING_VINES_PLANT { @@ -95,7 +92,7 @@ impl PlantBlockBase for TwistingVinesBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { return Block::AIR.default_state.id; } block_state diff --git a/pumpkin/src/block/blocks/plant/weeping_vines.rs b/pumpkin/src/block/blocks/plant/weeping_vines.rs index 92a935794..ac539b947 100644 --- a/pumpkin/src/block/blocks/plant/weeping_vines.rs +++ b/pumpkin/src/block/blocks/plant/weeping_vines.rs @@ -16,10 +16,8 @@ impl BlockMetadata for WeepingVinesBlock { } impl BlockBehaviour for WeepingVinesBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -38,7 +36,7 @@ impl BlockBehaviour for WeepingVinesBlock { fn placed<'a>(&'a self, args: PlacedArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { let support_pos = args.position.up(); - let support_block = args.world.get_block(&support_pos).await; + let support_block = args.world.get_block(&support_pos); if support_block == &Block::WEEPING_VINES { args.world .set_block_state( @@ -53,7 +51,7 @@ impl BlockBehaviour for WeepingVinesBlock { fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { let support_pos = args.position.up(); - let support_block = args.world.get_block(&support_pos).await; + let support_block = args.world.get_block(&support_pos); if support_block == &Block::WEEPING_VINES_PLANT { args.world .set_block_state( @@ -68,15 +66,14 @@ impl BlockBehaviour for WeepingVinesBlock { } impl PlantBlockBase for WeepingVinesBlock { - async fn can_place_at( + fn can_place_at( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { // Determine support block let support_pos = pos.up(); - let (support_block, support_block_state) = - block_accessor.get_block_and_state(&support_pos).await; + let (support_block, support_block_state) = block_accessor.get_block_and_state(&support_pos); if support_block == &Block::WEEPING_VINES || support_block == &Block::WEEPING_VINES_PLANT { return true; @@ -94,7 +91,7 @@ impl PlantBlockBase for WeepingVinesBlock { block_pos: &BlockPos, block_state: BlockStateId, ) -> BlockStateId { - if !::can_place_at(self, block_accessor, block_pos).await { + if !::can_place_at(self, block_accessor, block_pos) { return Block::AIR.default_state.id; } block_state diff --git a/pumpkin/src/block/blocks/plant/wither_rose.rs b/pumpkin/src/block/blocks/plant/wither_rose.rs index 3751e3139..1b30b8418 100644 --- a/pumpkin/src/block/blocks/plant/wither_rose.rs +++ b/pumpkin/src/block/blocks/plant/wither_rose.rs @@ -42,10 +42,8 @@ impl BlockBehaviour for WitherRoseBlock { } }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - ::can_place_at(self, args.block_accessor, args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + ::can_place_at(self, args.block_accessor, args.position) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -64,12 +62,12 @@ impl BlockBehaviour for WitherRoseBlock { } impl PlantBlockBase for WitherRoseBlock { - async fn can_plant_on_top( + fn can_plant_on_top( &self, block_accessor: &dyn pumpkin_world::world::BlockAccessor, pos: &pumpkin_util::math::position::BlockPos, ) -> bool { - let support_block = block_accessor.get_block(pos).await; + let support_block = block_accessor.get_block(pos); support_block.has_tag(&tag::Block::MINECRAFT_SUPPORTS_WITHER_ROSE) } } diff --git a/pumpkin/src/block/blocks/powder_snow.rs b/pumpkin/src/block/blocks/powder_snow.rs index c97f83571..4a156994d 100644 --- a/pumpkin/src/block/blocks/powder_snow.rs +++ b/pumpkin/src/block/blocks/powder_snow.rs @@ -96,7 +96,7 @@ impl BlockBehaviour for PowderSnowBlock { Sound::EntityGenericBigFall }; - living.entity.play_sound(sound).await; + living.entity.play_sound(sound); } }) } diff --git a/pumpkin/src/block/blocks/pumpkin.rs b/pumpkin/src/block/blocks/pumpkin.rs index 787314d92..0f56d4458 100644 --- a/pumpkin/src/block/blocks/pumpkin.rs +++ b/pumpkin/src/block/blocks/pumpkin.rs @@ -42,8 +42,10 @@ impl crate::block::BlockBehaviour for PumpkinBlock { args.position.to_f64(), &EntityType::ITEM, ); - let item_entity = - Arc::new(ItemEntity::new(entity, ItemStack::new(4, &Item::PUMPKIN_SEEDS)).await); + let item_entity = Arc::new(ItemEntity::new( + entity, + ItemStack::new(4, &Item::PUMPKIN_SEEDS), + )); args.world.spawn_entity(item_entity).await; // TODO: Deduct 1 durability from held shears (skip in Creative mode). BlockActionResult::Consume diff --git a/pumpkin/src/block/blocks/redstone/abstract_redstone_gate.rs b/pumpkin/src/block/blocks/redstone/abstract_redstone_gate.rs index 96e17562f..41749bf05 100644 --- a/pumpkin/src/block/blocks/redstone/abstract_redstone_gate.rs +++ b/pumpkin/src/block/blocks/redstone/abstract_redstone_gate.rs @@ -32,30 +32,24 @@ pub trait RedstoneGateBlockProperties { } pub trait RedstoneGateBlock { - // 💡 Converted async fn to fn returning BlockFuture - fn can_place_at<'a>( - &'a self, - world: &'a dyn BlockAccessor, - pos: BlockPos, - ) -> BlockFuture<'a, bool> + // 💡 Converted async fn to fn + fn can_place_at(&self, world: &dyn BlockAccessor, pos: BlockPos) -> bool where Self: Send + Sync, { - Box::pin(async move { - let under_pos = pos.down(); - let under_state = world.get_block_state(&under_pos).await; - self.can_place_above(world, under_pos, under_state).await - }) + let under_pos = pos.down(); + let under_state = world.get_block_state(&under_pos); + self.can_place_above(world, under_pos, under_state) } - // 💡 Converted async fn to fn returning BlockFuture - fn can_place_above<'a>( - &'a self, - _world: &'a dyn BlockAccessor, + // 💡 Converted async fn to fn + fn can_place_above( + &self, + _world: &dyn BlockAccessor, _pos: BlockPos, - state: &'a BlockState, - ) -> BlockFuture<'a, bool> { - Box::pin(async { state.is_side_solid(BlockDirection::Up) }) + state: &BlockState, + ) -> bool { + state.is_side_solid(BlockDirection::Up) } fn get_weak_redstone_power<'a>(&'a self, args: GetRedstonePowerArgs<'a>) -> BlockFuture<'a, u8> @@ -90,8 +84,8 @@ pub trait RedstoneGateBlock( let props = T::from_state_id(state_id, block); let facing = props.get_facing(); let source_pos = pos.offset(facing.to_offset()); - let (source_block, source_state) = world.get_block_and_state(&source_pos).await; + let (source_block, source_state) = world.get_block_and_state(&source_pos); let source_level = get_redstone_power( source_block, source_state, @@ -314,7 +307,7 @@ async fn get_power_on_side( only_gate: bool, ) -> u8 { let side_pos = pos.offset(side.to_block_direction().to_offset()); - let (side_block, side_state) = world.get_block_and_state(&side_pos).await; + let (side_block, side_state) = world.get_block_and_state(&side_pos); if !only_gate || is_diode(side_block) { world .block_registry diff --git a/pumpkin/src/block/blocks/redstone/bell.rs b/pumpkin/src/block/blocks/redstone/bell.rs index 396186429..34a528a90 100644 --- a/pumpkin/src/block/blocks/redstone/bell.rs +++ b/pumpkin/src/block/blocks/redstone/bell.rs @@ -21,31 +21,25 @@ use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; use pumpkin_world::world::BlockFlags; -async fn ring_bell( - position: BlockPos, - world: &Arc, - hit_direction: Option, -) { - let (block, state_id) = world.get_block_and_state_id(&position).await; +fn ring_bell(position: BlockPos, world: &Arc, hit_direction: Option) { + let (block, state_id) = world.get_block_and_state_id(&position); let props = BellLikeProperties::from_state_id(state_id, block); let direction = hit_direction.map_or(props.facing, |direction3| direction3); - if let Some(block_entity) = world.get_block_entity(&position).await + if let Some(block_entity) = world.get_block_entity(&position) && let Some(be) = block_entity.as_any().downcast_ref::() { be.activate(direction); } - world - .play_sound_fine( - Sound::BlockBellUse, - SoundCategory::Blocks, - &position.to_centered_f64(), - 1.0, - 2.0, - ) - .await; + world.play_sound_fine( + Sound::BlockBellUse, + SoundCategory::Blocks, + &position.to_centered_f64(), + 1.0, + 2.0, + ); //TODO Emit game event: BLOCK_CHANGE -> Send block update Packet } @@ -73,10 +67,9 @@ fn is_point_on_bell( } } -async fn is_single_wall(position: BlockPos, facing: HorizontalFacing, world: &World) -> bool { +fn is_single_wall(position: BlockPos, facing: HorizontalFacing, world: &World) -> bool { !world .get_block(&position.offset(facing.to_offset())) - .await .is_solid() } @@ -97,28 +90,26 @@ impl WallMountedBlock for BellBlock { } impl BlockBehaviour for BellBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - if let Some(direction) = args.direction - && let Some(world) = args.world - { - if direction == BlockDirection::Up { - let block: &Block = world.get_block(args.position).await; + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + if let Some(direction) = args.direction + && let Some(world) = args.world + { + if direction == BlockDirection::Up { + let block: &Block = world.get_block(args.position); - if block.has_tag(&tag::Block::MINECRAFT_UNSTABLE_BOTTOM_CENTER) { - false - } else { - let block_pos = args.position.offset(direction.to_offset()); - let block_state = world.get_block_state(&block_pos).await; - block_state.is_center_solid(direction) - } + if block.has_tag(&tag::Block::MINECRAFT_UNSTABLE_BOTTOM_CENTER) { + false } else { - WallMountedBlock::can_place_at(self, world, args.position, direction).await + let block_pos = args.position.offset(direction.to_offset()); + let block_state = world.get_block_state(&block_pos); + block_state.is_center_solid(direction) } } else { - false + WallMountedBlock::can_place_at(self, world, args.position, direction) } - }) + } else { + false + } } fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { @@ -136,7 +127,7 @@ impl BlockBehaviour for BellBlock { } fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let props = BellLikeProperties::from_state_id(state.id, args.block); @@ -147,8 +138,7 @@ impl BlockBehaviour for BellBlock { *args.position, args.world, args.hit.face.to_horizontal_facing(), - ) - .await; + ); BlockActionResult::Success }) @@ -170,7 +160,7 @@ impl BlockBehaviour for BellBlock { props.attachment = match block_face { AttachFace::Wall => { - if is_single_wall(*args.position, props.facing.opposite(), args.world).await { + if is_single_wall(*args.position, props.facing.opposite(), args.world) { BellAttachment::SingleWall } else { BellAttachment::DoubleWall @@ -189,7 +179,7 @@ impl BlockBehaviour for BellBlock { let world: &World = args.world; let is_receiving_power = block_receives_redstone_power(world, args.position).await; - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut props = BellLikeProperties::from_state_id(state.id, args.block); @@ -205,7 +195,7 @@ impl BlockBehaviour for BellBlock { .await; if is_receiving_power { - ring_bell(*args.position, args.world, None).await; + ring_bell(*args.position, args.world, None); } } }) diff --git a/pumpkin/src/block/blocks/redstone/buttons.rs b/pumpkin/src/block/blocks/redstone/buttons.rs index 775472d6e..45d1d9c84 100644 --- a/pumpkin/src/block/blocks/redstone/buttons.rs +++ b/pumpkin/src/block/blocks/redstone/buttons.rs @@ -28,7 +28,7 @@ use crate::block::{BlockBehaviour, NormalUseArgs}; use crate::world::World; async fn click_button(world: &Arc, block_pos: &BlockPos) { - let (block, state) = world.get_block_and_state_id(block_pos).await; + let (block, state) = world.get_block_and_state_id(block_pos); let mut button_props = ButtonLikeProperties::from_state_id(state, block); if !button_props.powered { @@ -66,7 +66,7 @@ impl BlockBehaviour for ButtonBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut props = ButtonLikeProperties::from_state_id(state.id, args.block); props.powered = false; args.world @@ -134,16 +134,13 @@ impl BlockBehaviour for ButtonBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - // Use the provided direction, or fallback to the current state's direction if missing - let direction = args - .direction - .unwrap_or_else(|| self.get_direction(args.state.id, args.block)); + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + // Use the provided direction, or fallback to the current state's direction if missing + let direction = args + .direction + .unwrap_or_else(|| self.get_direction(args.state.id, args.block)); - WallMountedBlock::can_place_at(self, args.block_accessor, args.position, direction) - .await - }) + WallMountedBlock::can_place_at(self, args.block_accessor, args.position, direction) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/redstone/comparator.rs b/pumpkin/src/block/blocks/redstone/comparator.rs index 3afbcf43a..7772ba602 100644 --- a/pumpkin/src/block/blocks/redstone/comparator.rs +++ b/pumpkin/src/block/blocks/redstone/comparator.rs @@ -34,7 +34,7 @@ impl BlockBehaviour for ComparatorBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let props = ComparatorLikeProperties::from_state_id(state.id, args.block); self.on_use(props, args.world, *args.position, args.block) .await; @@ -50,10 +50,8 @@ impl BlockBehaviour for ComparatorBlock { Box::pin(async move { true }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - RedstoneGateBlock::can_place_at(self, args.block_accessor, *args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + RedstoneGateBlock::can_place_at(self, args.block_accessor, *args.position) } fn placed<'a>(&'a self, args: PlacedArgs<'a>) -> BlockFuture<'a, ()> { @@ -96,7 +94,6 @@ impl BlockBehaviour for ComparatorBlock { *args.neighbor_position, BlockState::from_id(args.neighbor_state_id), ) - .await { return Block::AIR.default_state.id; } @@ -126,7 +123,7 @@ impl BlockBehaviour for ComparatorBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); self.update(args.world, *args.position, state, args.block) .await; }) @@ -156,7 +153,7 @@ impl RedstoneGateBlockProperties for ComparatorLikeProperties { impl RedstoneGateBlock for ComparatorBlock { fn get_output_level<'a>(&'a self, world: &'a World, pos: BlockPos) -> BlockFuture<'a, u8> { Box::pin(async move { - if let Some(blockentity) = world.get_block_entity(&pos).await + if let Some(blockentity) = world.get_block_entity(&pos) && blockentity.resource_location() == ComparatorBlockEntity::ID { let comparator = blockentity @@ -249,7 +246,7 @@ impl RedstoneGateBlock for ComparatorBlock { let props = ComparatorLikeProperties::from_state_id(state.id, block); let facing = props.facing; let source_pos = pos.offset(facing.to_offset()); - let (source_block, source_state) = world.get_block_and_state(&source_pos).await; + let (source_block, source_state) = world.get_block_and_state(&source_pos); // Note: .get_comparator_output is assumed to be an async method returning Option if let Some(pumpkin_block) = world.block_registry.get_pumpkin_block(source_block.id) @@ -267,7 +264,7 @@ impl RedstoneGateBlock for ComparatorBlock { if redstone_level < 15 && source_state.is_solid_block() { let source_pos = source_pos.offset(facing.to_offset()); - let (source_block, source_state) = world.get_block_and_state(&source_pos).await; + let (source_block, source_state) = world.get_block_and_state(&source_pos); // Note: self.get_attached_itemframe_level is assumed to be an async method let itemframe_level = Self::get_attached_itemframe_level(world, facing, source_pos); @@ -365,7 +362,7 @@ impl ComparatorBlock { async fn update(&self, world: &Arc, pos: BlockPos, state: &BlockState, block: &Block) { let future_level = i32::from(self.calculate_output_signal(world, pos, state, block).await); let mut now_level = 0; - if let Some(blockentity) = world.get_block_entity(&pos).await + if let Some(blockentity) = world.get_block_entity(&pos) && blockentity.resource_location() == ComparatorBlockEntity::ID { let comparator = blockentity diff --git a/pumpkin/src/block/blocks/redstone/copper_bulb.rs b/pumpkin/src/block/blocks/redstone/copper_bulb.rs index 5f6f7f493..254414f72 100644 --- a/pumpkin/src/block/blocks/redstone/copper_bulb.rs +++ b/pumpkin/src/block/blocks/redstone/copper_bulb.rs @@ -33,13 +33,11 @@ impl BlockBehaviour for CopperBulbBlock { let is_receiving_power = block_receives_redstone_power(args.world, args.position).await; if is_receiving_power { props.lit = true; - args.world - .play_block_sound( - Sound::BlockCopperBulbTurnOn, - SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + Sound::BlockCopperBulbTurnOn, + SoundCategory::Blocks, + *args.position, + ); props.powered = true; } props.to_state_id(args.block) @@ -48,23 +46,21 @@ impl BlockBehaviour for CopperBulbBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut props = CopperBulbLikeProperties::from_state_id(state.id, args.block); let is_receiving_power = block_receives_redstone_power(args.world, args.position).await; if props.powered != is_receiving_power { if !props.powered { props.lit = !props.lit; - args.world - .play_block_sound( - if props.lit { - Sound::BlockCopperBulbTurnOn - } else { - Sound::BlockCopperBulbTurnOff - }, - SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + if props.lit { + Sound::BlockCopperBulbTurnOn + } else { + Sound::BlockCopperBulbTurnOff + }, + SoundCategory::Blocks, + *args.position, + ); } props.powered = is_receiving_power; args.world diff --git a/pumpkin/src/block/blocks/redstone/daylight_detector.rs b/pumpkin/src/block/blocks/redstone/daylight_detector.rs index 90fd7030d..d709b7dd8 100644 --- a/pumpkin/src/block/blocks/redstone/daylight_detector.rs +++ b/pumpkin/src/block/blocks/redstone/daylight_detector.rs @@ -39,7 +39,7 @@ impl BlockBehaviour for DaylightDetectorBlock { return BlockActionResult::Pass; } - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let props = DaylightDetectorProperties::from_state_id(state.id, args.block); self.update_inverted(props, args.world, args.position, args.block) diff --git a/pumpkin/src/block/blocks/redstone/dropper.rs b/pumpkin/src/block/blocks/redstone/dropper.rs index 2ee399037..66b188c7b 100644 --- a/pumpkin/src/block/blocks/redstone/dropper.rs +++ b/pumpkin/src/block/blocks/redstone/dropper.rs @@ -89,7 +89,7 @@ const fn to_data3d(facing: Facing) -> i32 { impl BlockBehaviour for DropperBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(inventory) = block_entity.get_inventory() { args.player @@ -122,7 +122,7 @@ impl BlockBehaviour for DropperBlock { let powered = block_receives_redstone_power(args.world, args.position).await || block_receives_redstone_power(args.world, &args.position.up()).await; let mut props = DispenserLikeProperties::from_state_id( - args.world.get_block_state(args.position).await.id, + args.world.get_block_state(args.position).id, args.block, ); if powered && !props.triggered { @@ -152,25 +152,21 @@ impl BlockBehaviour for DropperBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await { + if let Some(block_entity) = args.world.get_block_entity(args.position) { let dropper = block_entity .as_any() .downcast_ref::() .unwrap(); if let Some(mut item) = dropper.get_random_slot().await { let props = DispenserLikeProperties::from_state_id( - args.world.get_block_state(args.position).await.id, + args.world.get_block_state(args.position).id, args.block, ); - if let Some(entity) = args - .world - .get_block_entity( - &args - .position - .offset(props.facing.to_block_direction().to_offset()), - ) - .await - && let Some(container) = entity.get_inventory() + if let Some(entity) = args.world.get_block_entity( + &args + .position + .offset(props.facing.to_block_direction().to_offset()), + ) && let Some(container) = entity.get_inventory() { // TODO check WorldlyContainer let mut is_full = true; @@ -210,24 +206,23 @@ impl BlockBehaviour for DropperBlock { triangle(&mut rng(), 0.2, 0.017_227_5 * 6.), triangle(&mut rng(), facing.z * rd, 0.017_227_5 * 6.), ); - let item_entity = Arc::new( - ItemEntity::new_with_velocity(entity, drop_item, velocity, 40).await, - ); + let item_entity = Arc::new(ItemEntity::new_with_velocity( + entity, drop_item, velocity, 40, + )); args.world.spawn_entity(item_entity).await; - args.world - .sync_world_event(WorldEvent::SoundDispenserDispense, *args.position, 0) - .await; - args.world - .sync_world_event( - WorldEvent::SoundDispenserProjectileLaunch, - *args.position, - to_data3d(props.facing), - ) - .await; + args.world.sync_world_event( + WorldEvent::SoundDispenserDispense, + *args.position, + 0, + ); + args.world.sync_world_event( + WorldEvent::SoundDispenserProjectileLaunch, + *args.position, + to_data3d(props.facing), + ); } else { args.world - .sync_world_event(WorldEvent::SoundDispenserFail, *args.position, 0) - .await; + .sync_world_event(WorldEvent::SoundDispenserFail, *args.position, 0); } } }) diff --git a/pumpkin/src/block/blocks/redstone/lever.rs b/pumpkin/src/block/blocks/redstone/lever.rs index 52f34e649..d3a96f19d 100644 --- a/pumpkin/src/block/blocks/redstone/lever.rs +++ b/pumpkin/src/block/blocks/redstone/lever.rs @@ -22,7 +22,7 @@ use crate::{ }; async fn toggle_lever(world: &Arc, block_pos: &BlockPos) { - let (block, state) = world.get_block_and_state_id(block_pos).await; + let (block, state) = world.get_block_and_state_id(block_pos); let mut lever_props = LeverLikeProperties::from_state_id(state, block); lever_props.powered = !lever_props.powered; @@ -102,16 +102,13 @@ impl BlockBehaviour for LeverBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - // Use the provided direction, or fallback to the current state's direction if missing - let direction = args - .direction - .unwrap_or_else(|| self.get_direction(args.state.id, args.block)); + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + // Use the provided direction, or fallback to the current state's direction if missing + let direction = args + .direction + .unwrap_or_else(|| self.get_direction(args.state.id, args.block)); - WallMountedBlock::can_place_at(self, args.block_accessor, args.position, direction) - .await - }) + WallMountedBlock::can_place_at(self, args.block_accessor, args.position, direction) } fn get_state_for_neighbor_update<'a>( diff --git a/pumpkin/src/block/blocks/redstone/mod.rs b/pumpkin/src/block/blocks/redstone/mod.rs index 784fa3391..c65273096 100644 --- a/pumpkin/src/block/blocks/redstone/mod.rs +++ b/pumpkin/src/block/blocks/redstone/mod.rs @@ -36,7 +36,7 @@ pub mod dispenser; pub async fn update_wire_neighbors(world: &Arc, pos: &BlockPos) { for direction in BlockDirection::all() { let neighbor_pos = pos.offset(direction.to_offset()); - let block = world.get_block(&neighbor_pos).await; + let block = world.get_block(&neighbor_pos); world .block_registry .on_neighbor_update(world, block, &neighbor_pos, block, true) @@ -44,7 +44,7 @@ pub async fn update_wire_neighbors(world: &Arc, pos: &BlockPos) { for n_direction in BlockDirection::all() { let n_neighbor_pos = neighbor_pos.offset(n_direction.to_offset()); - let block = world.get_block(&n_neighbor_pos).await; + let block = world.get_block(&n_neighbor_pos); world .block_registry .on_neighbor_update(world, block, &n_neighbor_pos, block, true) @@ -98,9 +98,7 @@ async fn get_redstone_power_no_dust( async fn get_max_strong_power(world: &World, pos: &BlockPos, dust_power: bool) -> u8 { let mut max_power = 0; for side in BlockDirection::all() { - let (block, state) = world - .get_block_and_state(&pos.offset(side.to_offset())) - .await; + let (block, state) = world.get_block_and_state(&pos.offset(side.to_offset())); max_power = max_power.max( get_strong_power( block, @@ -119,9 +117,7 @@ async fn get_max_strong_power(world: &World, pos: &BlockPos, dust_power: bool) - async fn get_max_weak_power(world: &World, pos: &BlockPos, dust_power: bool) -> u8 { let mut max_power = 0; for side in BlockDirection::all() { - let (block, state) = world - .get_block_and_state(&pos.offset(side.to_offset())) - .await; + let (block, state) = world.get_block_and_state(&pos.offset(side.to_offset())); max_power = max_power.max( get_weak_power( block, @@ -174,7 +170,7 @@ async fn get_strong_power( pub async fn block_receives_redstone_power(world: &World, pos: &BlockPos) -> bool { for facing in BlockDirection::all() { let neighbor_pos = pos.offset(facing.to_offset()); - let (block, state) = world.get_block_and_state(&neighbor_pos).await; + let (block, state) = world.get_block_and_state(&neighbor_pos); if is_emitting_redstone_power(block, state, world, &neighbor_pos, facing).await { return true; } @@ -189,7 +185,7 @@ pub fn is_diode(block: &Block) -> bool { pub async fn diode_get_input_strength(world: &World, pos: &BlockPos, facing: BlockDirection) -> u8 { let input_pos = pos.offset(facing.to_offset()); - let (input_block, input_state) = world.get_block_and_state(&input_pos).await; + let (input_block, input_state) = world.get_block_and_state(&input_pos); let power: u8 = get_redstone_power(input_block, input_state, world, &input_pos, facing).await; if power == 0 && input_state.is_solid_block() { return get_max_weak_power(world, &input_pos, true).await; diff --git a/pumpkin/src/block/blocks/redstone/observer.rs b/pumpkin/src/block/blocks/redstone/observer.rs index 112fc9572..a6d0d993b 100644 --- a/pumpkin/src/block/blocks/redstone/observer.rs +++ b/pumpkin/src/block/blocks/redstone/observer.rs @@ -28,7 +28,7 @@ impl BlockBehaviour for ObserverBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut props = ObserverLikeProperties::from_state_id(state.id, args.block); if props.powered { diff --git a/pumpkin/src/block/blocks/redstone/pressure_plate/mod.rs b/pumpkin/src/block/blocks/redstone/pressure_plate/mod.rs index 02d016f53..f07d715ac 100644 --- a/pumpkin/src/block/blocks/redstone/pressure_plate/mod.rs +++ b/pumpkin/src/block/blocks/redstone/pressure_plate/mod.rs @@ -22,7 +22,7 @@ pub(crate) trait PressurePlate { } async fn on_scheduled_tick_pp(&self, args: OnScheduledTickArgs<'_>) { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let output = self.get_redstone_output(args.block, state.id); if output > 0 { self.update_plate_state(args.world, args.position, args.block, state, output) @@ -80,8 +80,8 @@ pub(crate) trait PressurePlate { } } - async fn can_pressure_plate_place_at(world: &World, block_pos: &BlockPos) -> bool { - let floor = world.get_block_state(&block_pos.down()).await; + fn can_pressure_plate_place_at(world: &World, block_pos: &BlockPos) -> bool { + let floor = world.get_block_state(&block_pos.down()); floor.is_side_solid(BlockDirection::Up) } diff --git a/pumpkin/src/block/blocks/redstone/pressure_plate/plate.rs b/pumpkin/src/block/blocks/redstone/pressure_plate/plate.rs index 625fbdd84..ee2490659 100644 --- a/pumpkin/src/block/blocks/redstone/pressure_plate/plate.rs +++ b/pumpkin/src/block/blocks/redstone/pressure_plate/plate.rs @@ -78,7 +78,7 @@ impl BlockBehaviour for PressurePlateBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !Self::can_pressure_plate_place_at(args.world, args.position).await { + if !Self::can_pressure_plate_place_at(args.world, args.position) { args.world .break_block(args.position, None, BlockFlags::NOTIFY_ALL) .await; @@ -86,10 +86,8 @@ impl BlockBehaviour for PressurePlateBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - Self::can_pressure_plate_place_at(args.world.unwrap(), args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + Self::can_pressure_plate_place_at(args.world.unwrap(), args.position) } } diff --git a/pumpkin/src/block/blocks/redstone/pressure_plate/weighted.rs b/pumpkin/src/block/blocks/redstone/pressure_plate/weighted.rs index d384787d5..8074af326 100644 --- a/pumpkin/src/block/blocks/redstone/pressure_plate/weighted.rs +++ b/pumpkin/src/block/blocks/redstone/pressure_plate/weighted.rs @@ -77,7 +77,7 @@ impl BlockBehaviour for WeightedPressurePlateBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !Self::can_pressure_plate_place_at(args.world, args.position).await { + if !Self::can_pressure_plate_place_at(args.world, args.position) { args.world .break_block(args.position, None, BlockFlags::NOTIFY_ALL) .await; @@ -85,10 +85,8 @@ impl BlockBehaviour for WeightedPressurePlateBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - Self::can_pressure_plate_place_at(args.world.unwrap(), args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + Self::can_pressure_plate_place_at(args.world.unwrap(), args.position) } } diff --git a/pumpkin/src/block/blocks/redstone/rails/activator_rail.rs b/pumpkin/src/block/blocks/redstone/rails/activator_rail.rs index be40d3b7a..a99a47e54 100644 --- a/pumpkin/src/block/blocks/redstone/rails/activator_rail.rs +++ b/pumpkin/src/block/blocks/redstone/rails/activator_rail.rs @@ -59,7 +59,7 @@ impl BlockBehaviour for ActivatorRailBlock { self.update_powered_state(args.world, args.block, args.position) .await; - let final_state_id = args.world.get_block_state_id(args.position).await; + let final_state_id = args.world.get_block_state_id(args.position); let rail_props = RailProperties::new(final_state_id, args.block); self.update_connected_rails(args.world, args.position, &rail_props, true, 0) @@ -70,8 +70,7 @@ impl BlockBehaviour for ActivatorRailBlock { for direction in rail_props.directions() { let neighbor_pos = args.position.offset(direction.to_offset()); - if let Some(neighbor_rail) = - self.find_rail_at_position(args.world, &neighbor_pos).await + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &neighbor_pos) { self.update_powered_state_internal( args.world, @@ -99,7 +98,7 @@ impl BlockBehaviour for ActivatorRailBlock { } let up_pos = neighbor_pos.up(); - if let Some(neighbor_rail) = self.find_rail_at_position(args.world, &up_pos).await { + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &up_pos) { self.update_powered_state_internal(args.world, neighbor_rail.0, &up_pos, false) .await; self.update_connected_rails(args.world, &up_pos, &neighbor_rail.1, true, 0) @@ -109,8 +108,7 @@ impl BlockBehaviour for ActivatorRailBlock { } let down_pos = neighbor_pos.down(); - if let Some(neighbor_rail) = self.find_rail_at_position(args.world, &down_pos).await - { + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &down_pos) { self.update_powered_state_internal( args.world, neighbor_rail.0, @@ -139,7 +137,7 @@ impl BlockBehaviour for ActivatorRailBlock { self.update_powered_state(args.world, args.block, args.position) .await; - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let rail_props = RailProperties::new(state_id, args.block); self.update_connected_rails(args.world, args.position, &rail_props, true, 0) @@ -168,8 +166,7 @@ impl BlockBehaviour for ActivatorRailBlock { for direction in directions { let neighbor_pos = args.position.offset(direction.to_offset()); - if let Some(neighbor_rail) = - self.find_rail_at_position(args.world, &neighbor_pos).await + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &neighbor_pos) { self.update_powered_state(args.world, neighbor_rail.0, &neighbor_pos) .await; @@ -192,7 +189,7 @@ impl BlockBehaviour for ActivatorRailBlock { } let up_pos = neighbor_pos.up(); - if let Some(neighbor_rail) = self.find_rail_at_position(args.world, &up_pos).await { + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &up_pos) { self.update_powered_state(args.world, neighbor_rail.0, &up_pos) .await; self.update_connected_rails(args.world, &up_pos, &neighbor_rail.1, true, 0) @@ -202,8 +199,7 @@ impl BlockBehaviour for ActivatorRailBlock { } let down_pos = neighbor_pos.down(); - if let Some(neighbor_rail) = self.find_rail_at_position(args.world, &down_pos).await - { + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &down_pos) { self.update_powered_state(args.world, neighbor_rail.0, &down_pos) .await; self.update_connected_rails(args.world, &down_pos, &neighbor_rail.1, true, 0) @@ -215,8 +211,8 @@ impl BlockBehaviour for ActivatorRailBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_rail_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_rail_at(args.block_accessor, args.position) } } @@ -327,12 +323,12 @@ impl ActivatorRailBlock { distance: u8, expected_shape: pumpkin_data::block_properties::RailShape, ) -> bool { - let block = world.get_block(pos).await; + let block = world.get_block(pos); if *block != Block::ACTIVATOR_RAIL { return false; } - let state_id = world.get_block_state_id(pos).await; + let state_id = world.get_block_state_id(pos); let rail_props = RailProperties::new(state_id, block); let rail_shape = rail_props.shape(); @@ -384,7 +380,7 @@ impl ActivatorRailBlock { pos: &BlockPos, propagate: bool, ) { - let state_id = world.get_block_state_id(pos).await; + let state_id = world.get_block_state_id(pos); let mut rail_props = RailProperties::new(state_id, block); let current_powered = rail_props.is_powered(); @@ -516,12 +512,12 @@ impl ActivatorRailBlock { distance: u8, expected_shape: pumpkin_data::block_properties::RailShape, ) { - let block = world.get_block(pos).await; + let block = world.get_block(pos); if *block != Block::ACTIVATOR_RAIL { return; } - let state_id = world.get_block_state_id(pos).await; + let state_id = world.get_block_state_id(pos); let rail_props = RailProperties::new(state_id, block); let rail_shape = rail_props.shape(); @@ -550,18 +546,15 @@ impl ActivatorRailBlock { } } - async fn find_rail_at_position( - &self, + fn find_rail_at_position( world: &World, pos: &BlockPos, ) -> Option<(&'static Block, RailProperties)> { - let block = world.get_block(pos).await; - if *block == Block::ACTIVATOR_RAIL { - let state_id = world.get_block_state_id(pos).await; + let block = world.get_block(pos); + (*block == Block::ACTIVATOR_RAIL).then(|| { + let state_id = world.get_block_state_id(pos); let rail_props = RailProperties::new(state_id, block); - Some((block, rail_props)) - } else { - None - } + (block, rail_props) + }) } } diff --git a/pumpkin/src/block/blocks/redstone/rails/common.rs b/pumpkin/src/block/blocks/redstone/rails/common.rs index be7626627..b68864cab 100644 --- a/pumpkin/src/block/blocks/redstone/rails/common.rs +++ b/pumpkin/src/block/blocks/redstone/rails/common.rs @@ -15,11 +15,11 @@ use crate::world::World; use super::{HorizontalFacingRailExt, Rail, RailElevation, RailProperties, StraightRailShapeExt}; pub(super) async fn rail_placement_is_valid(world: &World, block: &Block, pos: &BlockPos) -> bool { - if !can_place_rail_at(world, pos).await { + if !can_place_rail_at(world, pos) { return false; } - let state_id = world.get_block_state_id(pos).await; + let state_id = world.get_block_state_id(pos); let rail_props = RailProperties::new(state_id, block); let rail_leaning_direction = match rail_props.shape() { RailShape::AscendingNorth => Some(HorizontalFacing::North), @@ -30,7 +30,7 @@ pub(super) async fn rail_placement_is_valid(world: &World, block: &Block, pos: & }; if let Some(direction) = rail_leaning_direction - && !can_place_rail_at(world, &pos.offset(direction.to_offset()).up()).await + && !can_place_rail_at(world, &pos.offset(direction.to_offset()).up()) { return false; } @@ -38,8 +38,8 @@ pub(super) async fn rail_placement_is_valid(world: &World, block: &Block, pos: & true } -pub(super) async fn can_place_rail_at(world: &dyn BlockAccessor, pos: &BlockPos) -> bool { - let state = world.get_block_state(&pos.down()).await; +pub(super) fn can_place_rail_at(world: &dyn BlockAccessor, pos: &BlockPos) -> bool { + let state = world.get_block_state(&pos.down()); state.is_side_solid(BlockDirection::Up) } @@ -52,12 +52,9 @@ pub(super) async fn compute_placed_rail_shape( // Check each direction for rail connections, similar to normal rail placement // Check East first - if let Some(east_rail) = Rail::find_if_unlocked(world, block_pos, HorizontalFacing::East).await - { + if let Some(east_rail) = Rail::find_if_unlocked(world, block_pos, HorizontalFacing::East) { // Check for opposite connection (West) to form a straight line - if let Some(west_rail) = - Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West).await - { + if let Some(west_rail) = Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West) { // We have connections in both East and West if east_rail.elevation == RailElevation::Up { return RailShapeStraight::AscendingEast; @@ -74,12 +71,9 @@ pub(super) async fn compute_placed_rail_shape( } // Check South - if let Some(south_rail) = - Rail::find_if_unlocked(world, block_pos, HorizontalFacing::South).await - { + if let Some(south_rail) = Rail::find_if_unlocked(world, block_pos, HorizontalFacing::South) { // Check for opposite connection (North) to form a straight line - if let Some(north_rail) = - Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North).await + if let Some(north_rail) = Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North) { // We have connections in both South and North if south_rail.elevation == RailElevation::Up { @@ -97,8 +91,7 @@ pub(super) async fn compute_placed_rail_shape( } // Check West - if let Some(west_rail) = Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West).await - { + if let Some(west_rail) = Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West) { if west_rail.elevation == RailElevation::Up { return RailShapeStraight::AscendingWest; } @@ -106,9 +99,7 @@ pub(super) async fn compute_placed_rail_shape( } // Check North - if let Some(north_rail) = - Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North).await - { + if let Some(north_rail) = Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North) { if north_rail.elevation == RailElevation::Up { return RailShapeStraight::AscendingNorth; } @@ -127,14 +118,14 @@ pub(super) async fn update_flanking_rails_shape( ) { for direction in RailProperties::new(state_id, block).directions() { let Some(mut flanking_rail) = - Rail::find_with_elevation(world, block_pos.offset(direction.to_offset())).await + Rail::find_with_elevation(world, block_pos.offset(direction.to_offset())) else { // Skip non-rail blocks continue; }; let new_shape = - compute_flanking_rail_new_shape(world, &flanking_rail, direction.opposite()).await; + compute_flanking_rail_new_shape(world, &flanking_rail, direction.opposite()); if new_shape != flanking_rail.properties.shape() { flanking_rail.properties.set_shape(new_shape); @@ -149,7 +140,7 @@ pub(super) async fn update_flanking_rails_shape( } } -async fn compute_flanking_rail_new_shape( +fn compute_flanking_rail_new_shape( world: &World, rail: &Rail, flanking_from: HorizontalFacing, @@ -165,7 +156,6 @@ async fn compute_flanking_rail_new_shape( let Some(maybe_connected_rail) = Rail::find_with_elevation(world, rail.position.offset(neighbor_direction.to_offset())) - .await else { // Rails pointing to non-rail blocks are not connected continue; diff --git a/pumpkin/src/block/blocks/redstone/rails/detector_rail.rs b/pumpkin/src/block/blocks/redstone/rails/detector_rail.rs index 2becf95fb..437d5e076 100644 --- a/pumpkin/src/block/blocks/redstone/rails/detector_rail.rs +++ b/pumpkin/src/block/blocks/redstone/rails/detector_rail.rs @@ -49,7 +49,7 @@ impl BlockBehaviour for DetectorRailBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_rail_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_rail_at(args.block_accessor, args.position) } } diff --git a/pumpkin/src/block/blocks/redstone/rails/mod.rs b/pumpkin/src/block/blocks/redstone/rails/mod.rs index 7ac3c710a..c63cbe3d1 100644 --- a/pumpkin/src/block/blocks/redstone/rails/mod.rs +++ b/pumpkin/src/block/blocks/redstone/rails/mod.rs @@ -26,8 +26,8 @@ struct Rail { } impl Rail { - async fn find_with_elevation(world: &World, position: BlockPos) -> Option { - let (block, block_state) = world.get_block_and_state_id(&position).await; + fn find_with_elevation(world: &World, position: BlockPos) -> Option { + let (block, block_state) = world.get_block_and_state_id(&position); if block.has_tag(&tag::Item::MINECRAFT_RAILS) { let properties = RailProperties::new(block_state, block); return Some(Self { @@ -39,7 +39,7 @@ impl Rail { } let pos = position.up(); - let (block, block_state) = world.get_block_and_state_id(&pos).await; + let (block, block_state) = world.get_block_and_state_id(&pos); if block.has_tag(&tag::Item::MINECRAFT_RAILS) { let properties = RailProperties::new(block_state, block); return Some(Self { @@ -51,7 +51,7 @@ impl Rail { } let pos = position.down(); - let (block, block_state) = world.get_block_and_state_id(&pos).await; + let (block, block_state) = world.get_block_and_state_id(&pos); if block.has_tag(&tag::Item::MINECRAFT_RAILS) { let properties = RailProperties::new(block_state, block); return Some(Self { @@ -65,25 +65,25 @@ impl Rail { None } - async fn find_if_unlocked( + fn find_if_unlocked( world: &World, place_pos: &BlockPos, direction: HorizontalFacing, ) -> Option { let rail_position = place_pos.offset(direction.to_offset()); - let rail = Self::find_with_elevation(world, rail_position).await?; + let rail = Self::find_with_elevation(world, rail_position)?; - if rail.is_locked(world).await { + if rail.is_locked(world) { return None; } Some(rail) } - async fn is_locked(&self, world: &World) -> bool { + fn is_locked(&self, world: &World) -> bool { for direction in self.properties.directions() { let Some(other_rail) = - Self::find_with_elevation(world, self.position.offset(direction.to_offset())).await + Self::find_with_elevation(world, self.position.offset(direction.to_offset())) else { // Rails pointing to non-rail blocks are not locked return false; diff --git a/pumpkin/src/block/blocks/redstone/rails/powered_rail.rs b/pumpkin/src/block/blocks/redstone/rails/powered_rail.rs index a6a53342b..397a1084f 100644 --- a/pumpkin/src/block/blocks/redstone/rails/powered_rail.rs +++ b/pumpkin/src/block/blocks/redstone/rails/powered_rail.rs @@ -59,7 +59,7 @@ impl BlockBehaviour for PoweredRailBlock { self.update_powered_state(args.world, args.block, args.position) .await; - let final_state_id = args.world.get_block_state_id(args.position).await; + let final_state_id = args.world.get_block_state_id(args.position); let rail_props = RailProperties::new(final_state_id, args.block); self.update_connected_rails(args.world, args.position, &rail_props, true, 0) @@ -70,8 +70,7 @@ impl BlockBehaviour for PoweredRailBlock { for direction in rail_props.directions() { let neighbor_pos = args.position.offset(direction.to_offset()); - if let Some(neighbor_rail) = - self.find_rail_at_position(args.world, &neighbor_pos).await + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &neighbor_pos) { self.update_powered_state_internal( args.world, @@ -99,7 +98,7 @@ impl BlockBehaviour for PoweredRailBlock { } let up_pos = neighbor_pos.up(); - if let Some(neighbor_rail) = self.find_rail_at_position(args.world, &up_pos).await { + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &up_pos) { self.update_powered_state_internal(args.world, neighbor_rail.0, &up_pos, false) .await; self.update_connected_rails(args.world, &up_pos, &neighbor_rail.1, true, 0) @@ -109,8 +108,7 @@ impl BlockBehaviour for PoweredRailBlock { } let down_pos = neighbor_pos.down(); - if let Some(neighbor_rail) = self.find_rail_at_position(args.world, &down_pos).await - { + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &down_pos) { self.update_powered_state_internal( args.world, neighbor_rail.0, @@ -139,7 +137,7 @@ impl BlockBehaviour for PoweredRailBlock { self.update_powered_state(args.world, args.block, args.position) .await; - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let rail_props = RailProperties::new(state_id, args.block); self.update_connected_rails(args.world, args.position, &rail_props, true, 0) @@ -169,8 +167,7 @@ impl BlockBehaviour for PoweredRailBlock { for direction in directions { let neighbor_pos = args.position.offset(direction.to_offset()); - if let Some(neighbor_rail) = - self.find_rail_at_position(args.world, &neighbor_pos).await + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &neighbor_pos) { self.update_powered_state(args.world, neighbor_rail.0, &neighbor_pos) .await; @@ -193,7 +190,7 @@ impl BlockBehaviour for PoweredRailBlock { } let up_pos = neighbor_pos.up(); - if let Some(neighbor_rail) = self.find_rail_at_position(args.world, &up_pos).await { + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &up_pos) { self.update_powered_state(args.world, neighbor_rail.0, &up_pos) .await; self.update_connected_rails(args.world, &up_pos, &neighbor_rail.1, true, 0) @@ -203,8 +200,7 @@ impl BlockBehaviour for PoweredRailBlock { } let down_pos = neighbor_pos.down(); - if let Some(neighbor_rail) = self.find_rail_at_position(args.world, &down_pos).await - { + if let Some(neighbor_rail) = Self::find_rail_at_position(args.world, &down_pos) { self.update_powered_state(args.world, neighbor_rail.0, &down_pos) .await; self.update_connected_rails(args.world, &down_pos, &neighbor_rail.1, true, 0) @@ -216,8 +212,8 @@ impl BlockBehaviour for PoweredRailBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_rail_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_rail_at(args.block_accessor, args.position) } } @@ -328,12 +324,12 @@ impl PoweredRailBlock { distance: u8, expected_shape: pumpkin_data::block_properties::RailShape, ) -> bool { - let block = world.get_block(pos).await; + let block = world.get_block(pos); if *block != Block::POWERED_RAIL { return false; } - let state_id = world.get_block_state_id(pos).await; + let state_id = world.get_block_state_id(pos); let rail_props = RailProperties::new(state_id, block); let rail_shape = rail_props.shape(); @@ -385,7 +381,7 @@ impl PoweredRailBlock { pos: &BlockPos, propagate: bool, ) { - let state_id = world.get_block_state_id(pos).await; + let state_id = world.get_block_state_id(pos); let mut rail_props = RailProperties::new(state_id, block); let current_powered = rail_props.is_powered(); @@ -517,12 +513,12 @@ impl PoweredRailBlock { distance: u8, expected_shape: pumpkin_data::block_properties::RailShape, ) { - let block = world.get_block(pos).await; + let block = world.get_block(pos); if *block != Block::POWERED_RAIL { return; } - let state_id = world.get_block_state_id(pos).await; + let state_id = world.get_block_state_id(pos); let rail_props = RailProperties::new(state_id, block); let rail_shape = rail_props.shape(); @@ -551,18 +547,15 @@ impl PoweredRailBlock { } } - async fn find_rail_at_position( - &self, + fn find_rail_at_position( world: &World, pos: &BlockPos, ) -> Option<(&'static Block, RailProperties)> { - let block = world.get_block(pos).await; - if *block == Block::POWERED_RAIL { - let state_id = world.get_block_state_id(pos).await; + let block = world.get_block(pos); + (*block == Block::POWERED_RAIL).then(|| { + let state_id = world.get_block_state_id(pos); let rail_props = RailProperties::new(state_id, block); - Some((block, rail_props)) - } else { - None - } + (block, rail_props) + }) } } diff --git a/pumpkin/src/block/blocks/redstone/rails/rail.rs b/pumpkin/src/block/blocks/redstone/rails/rail.rs index e2778cc0d..9cb6634a5 100644 --- a/pumpkin/src/block/blocks/redstone/rails/rail.rs +++ b/pumpkin/src/block/blocks/redstone/rails/rail.rs @@ -27,20 +27,16 @@ impl BlockBehaviour for RailBlock { rail_props.set_waterlogged(args.replacing.water_source()); let shape = if let Some(east_rail) = - Rail::find_if_unlocked(world, block_pos, HorizontalFacing::East).await + Rail::find_if_unlocked(world, block_pos, HorizontalFacing::East) { - if Rail::find_if_unlocked(world, block_pos, HorizontalFacing::South) - .await - .is_some() - { + if Rail::find_if_unlocked(world, block_pos, HorizontalFacing::South).is_some() { RailShape::SouthEast } else if Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North) - .await .is_some() { RailShape::NorthEast } else { - match Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West).await { + match Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West) { Some(west_rail) if west_rail.elevation == RailElevation::Up => { RailShape::AscendingWest } @@ -54,17 +50,14 @@ impl BlockBehaviour for RailBlock { } } } else if let Some(south_rail) = - Rail::find_if_unlocked(world, block_pos, HorizontalFacing::South).await + Rail::find_if_unlocked(world, block_pos, HorizontalFacing::South) { - if Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West) - .await - .is_some() - { + if Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West).is_some() { RailShape::SouthWest } else if south_rail.elevation == RailElevation::Up { RailShape::AscendingSouth } else { - match Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North).await { + match Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North) { Some(north_rail) if north_rail.elevation == RailElevation::Up => { RailShape::AscendingNorth } @@ -72,12 +65,9 @@ impl BlockBehaviour for RailBlock { } } } else if let Some(west_rail) = - Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West).await + Rail::find_if_unlocked(world, block_pos, HorizontalFacing::West) { - if Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North) - .await - .is_some() - { + if Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North).is_some() { RailShape::NorthWest } else if west_rail.elevation == RailElevation::Up { RailShape::AscendingWest @@ -85,7 +75,7 @@ impl BlockBehaviour for RailBlock { RailShape::EastWest } } else if let Some(north_rail) = - Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North).await + Rail::find_if_unlocked(world, block_pos, HorizontalFacing::North) { if north_rail.elevation == RailElevation::Up { RailShape::AscendingNorth @@ -122,7 +112,7 @@ impl BlockBehaviour for RailBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_rail_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_rail_at(args.block_accessor, args.position) } } diff --git a/pumpkin/src/block/blocks/redstone/redstone_lamp.rs b/pumpkin/src/block/blocks/redstone/redstone_lamp.rs index bb9c672de..c294c115e 100644 --- a/pumpkin/src/block/blocks/redstone/redstone_lamp.rs +++ b/pumpkin/src/block/blocks/redstone/redstone_lamp.rs @@ -23,7 +23,7 @@ impl BlockBehaviour for RedstoneLamp { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut props = RedstoneLampProperties::from_state_id(state.id, args.block); let is_lit = props.lit; let is_receiving_power = block_receives_redstone_power(args.world, args.position).await; @@ -49,7 +49,7 @@ impl BlockBehaviour for RedstoneLamp { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut props = RedstoneLampProperties::from_state_id(state.id, args.block); let is_lit = props.lit; let is_receiving_power = block_receives_redstone_power(args.world, args.position).await; diff --git a/pumpkin/src/block/blocks/redstone/redstone_torch.rs b/pumpkin/src/block/blocks/redstone/redstone_torch.rs index 9d94857dd..5f82daa96 100644 --- a/pumpkin/src/block/blocks/redstone/redstone_torch.rs +++ b/pumpkin/src/block/blocks/redstone/redstone_torch.rs @@ -48,7 +48,7 @@ impl BlockBehaviour for RedstoneTorchBlock { let location = args.position; if args.direction == BlockDirection::Down { - let support_block = world.get_block_state(&location.down()).await; + let support_block = world.get_block_state(&location.down()); if support_block.is_center_solid(BlockDirection::Up) { return block.default_state.id; } @@ -67,7 +67,7 @@ impl BlockBehaviour for RedstoneTorchBlock { directions[0] = face; } } else if directions[0] == Facing::Down { - let support_block = world.get_block_state(&location.down()).await; + let support_block = world.get_block_state(&location.down()); if support_block.is_center_solid(BlockDirection::Up) { return block.default_state.id; } @@ -76,7 +76,7 @@ impl BlockBehaviour for RedstoneTorchBlock { for dir in directions { if dir != Facing::Up && dir != Facing::Down - && can_place_at(world, location, dir.to_block_direction()).await + && can_place_at(world, location, dir.to_block_direction()) { let mut torch_props = RWallTorchProps::default(&Block::REDSTONE_WALL_TORCH); torch_props.facing = dir @@ -88,7 +88,7 @@ impl BlockBehaviour for RedstoneTorchBlock { } } - let support_block = world.get_block_state(&location.down()).await; + let support_block = world.get_block_state(&location.down()); if support_block.is_center_solid(BlockDirection::Up) { block.default_state.id } else { @@ -97,22 +97,17 @@ impl BlockBehaviour for RedstoneTorchBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let support_block = args - .block_accessor - .get_block_state(&args.position.down()) - .await; - if support_block.is_center_solid(BlockDirection::Up) { + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let support_block = args.block_accessor.get_block_state(&args.position.down()); + if support_block.is_center_solid(BlockDirection::Up) { + return true; + } + for dir in BlockDirection::horizontal() { + if can_place_at(args.block_accessor, args.position, dir) { return true; } - for dir in BlockDirection::horizontal() { - if can_place_at(args.block_accessor, args.position, dir).await { - return true; - } - } - false - }) + } + false } fn get_state_for_neighbor_update<'a>( @@ -128,12 +123,11 @@ impl BlockBehaviour for RedstoneTorchBlock { args.position, props.facing.to_block_direction().opposite(), ) - .await { return 0; } } else if args.direction == BlockDirection::Down { - let support_block = args.world.get_block_state(&args.position.down()).await; + let support_block = args.world.get_block_state(&args.position.down()); if !support_block.is_center_solid(BlockDirection::Up) { return 0; } @@ -144,7 +138,7 @@ impl BlockBehaviour for RedstoneTorchBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); if args .world @@ -231,7 +225,7 @@ impl BlockBehaviour for RedstoneTorchBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); if args.block == &Block::REDSTONE_WALL_TORCH { let mut props = RWallTorchProps::from_state_id(state.id, args.block); let should_be_lit_now = should_be_lit( @@ -285,7 +279,7 @@ impl BlockBehaviour for RedstoneTorchBlock { pub async fn should_be_lit(world: &World, pos: &BlockPos, face: BlockDirection) -> bool { let other_pos = pos.offset(face.to_offset()); - let (block, state) = world.get_block_and_state(&other_pos).await; + let (block, state) = world.get_block_and_state(&other_pos); get_redstone_power(block, state, world, &other_pos, face).await == 0 } @@ -296,13 +290,8 @@ pub async fn update_neighbors(world: &Arc, pos: &BlockPos) { } } -async fn can_place_at( - world: &dyn BlockAccessor, - block_pos: &BlockPos, - facing: BlockDirection, -) -> bool { +fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos, facing: BlockDirection) -> bool { world .get_block_state(&block_pos.offset(facing.to_offset())) - .await .is_side_solid(facing.opposite()) } diff --git a/pumpkin/src/block/blocks/redstone/redstone_wire.rs b/pumpkin/src/block/blocks/redstone/redstone_wire.rs index 1d529ffd3..7e9f42293 100644 --- a/pumpkin/src/block/blocks/redstone/redstone_wire.rs +++ b/pumpkin/src/block/blocks/redstone/redstone_wire.rs @@ -29,8 +29,8 @@ type RedstoneWireProperties = RedstoneWireLikeProperties; pub struct RedstoneWireBlock; impl BlockBehaviour for RedstoneWireBlock { - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { can_place_at(args.block_accessor, args.position).await }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_at(args.block_accessor, args.position) } fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { @@ -107,11 +107,11 @@ impl BlockBehaviour for RedstoneWireBlock { for direction in BlockDirection::horizontal() { let other_block_pos = args.position.offset(direction.to_offset()); - let other_block = args.world.get_block(&other_block_pos).await; + let other_block = args.world.get_block(&other_block_pos); if wire_props.is_side_connected(direction) && other_block != &Block::REDSTONE_WIRE { let up_block_pos = other_block_pos.up(); - let up_block = args.world.get_block(&up_block_pos).await; + let up_block = args.world.get_block(&up_block_pos); if up_block == &Block::REDSTONE_WIRE { args.world .replace_with_state_for_neighbor_update( @@ -123,7 +123,7 @@ impl BlockBehaviour for RedstoneWireBlock { } let down_block_pos = other_block_pos.down(); - let down_block = args.world.get_block(&down_block_pos).await; + let down_block = args.world.get_block(&down_block_pos); if down_block == &Block::REDSTONE_WIRE { args.world .replace_with_state_for_neighbor_update( @@ -142,7 +142,7 @@ impl BlockBehaviour for RedstoneWireBlock { continue; } let side_neighbor_pos = side_block_pos.offset(dir.to_offset()); - let side_neighbor_block = args.world.get_block(&side_neighbor_pos).await; + let side_neighbor_block = args.world.get_block(&side_neighbor_pos); if side_neighbor_block == &Block::REDSTONE_WALL_TORCH || side_neighbor_block == &Block::PISTON || side_neighbor_block == &Block::STICKY_PISTON @@ -158,7 +158,7 @@ impl BlockBehaviour for RedstoneWireBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let wire = RedstoneWireProperties::from_state_id(state.id, args.block); if on_use(wire, args.world, args.position).await { BlockActionResult::Success @@ -170,8 +170,8 @@ impl BlockBehaviour for RedstoneWireBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if can_place_at(args.world.as_ref(), args.position).await { - let state = args.world.get_block_state(args.position).await; + if can_place_at(args.world.as_ref(), args.position) { + let state = args.world.get_block_state(args.position); let mut wire = RedstoneWireProperties::from_state_id(state.id, args.block); let new_power = calculate_power(args.world, args.position).await; if wire.power != new_power { @@ -239,8 +239,8 @@ impl BlockBehaviour for RedstoneWireBlock { } } -async fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - let floor = world.get_block_state(&block_pos.down()).await; +fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + let floor = world.get_block_state(&block_pos.down()); floor.is_side_solid(BlockDirection::Up) } @@ -312,29 +312,25 @@ fn can_connect_diagonal_to(block: &Block) -> bool { pub async fn get_side(world: &World, pos: &BlockPos, side: BlockDirection) -> WireConnection { let neighbor_pos: BlockPos = pos.offset(side.to_offset()); - let (neighbor, state) = world.get_block_and_state(&neighbor_pos).await; + let (neighbor, state) = world.get_block_and_state(&neighbor_pos); if can_connect_to(world, neighbor, side, state).await { return WireConnection::Side; } let up_pos = pos.offset(BlockDirection::Up.to_offset()); - let up_state = world.get_block_state(&up_pos).await; + let up_state = world.get_block_state(&up_pos); if !up_state.is_solid_block() && state.is_side_solid(side.opposite()) && can_connect_diagonal_to( - world - .get_block(&neighbor_pos.offset(BlockDirection::Up.to_offset())) - .await, + world.get_block(&neighbor_pos.offset(BlockDirection::Up.to_offset())), ) { WireConnection::Up } else if !state.is_solid_block() && can_connect_diagonal_to( - world - .get_block(&neighbor_pos.offset(BlockDirection::Down.to_offset())) - .await, + world.get_block(&neighbor_pos.offset(BlockDirection::Down.to_offset())), ) { WireConnection::Side @@ -522,8 +518,8 @@ impl CardinalWireConnectionExt for WestRedstone { } } -async fn max_wire_power(wire_power: u8, world: &World, pos: BlockPos) -> u8 { - let (block, block_state) = world.get_block_and_state(&pos).await; +fn max_wire_power(wire_power: u8, world: &World, pos: BlockPos) -> u8 { + let (block, block_state) = world.get_block_and_state(&pos); if block == &Block::REDSTONE_WIRE { let wire = RedstoneWireProperties::from_state_id(block_state.id, block); wire_power.max(wire.power) @@ -537,12 +533,12 @@ async fn calculate_power(world: &World, pos: &BlockPos) -> u8 { let mut wire_power: u8 = 0; let up_pos = pos.offset(BlockDirection::Up.to_offset()); - let up_state = world.get_block_state(&up_pos).await; + let up_state = world.get_block_state(&up_pos); for side in BlockDirection::all() { let neighbor_pos = pos.offset(side.to_offset()); - wire_power = max_wire_power(wire_power, world, neighbor_pos).await; - let (neighbor, neighbor_state) = world.get_block_and_state(&neighbor_pos).await; + wire_power = max_wire_power(wire_power, world, neighbor_pos); + let (neighbor, neighbor_state) = world.get_block_and_state(&neighbor_pos); block_power = block_power.max( get_redstone_power_no_dust(neighbor, neighbor_state, world, neighbor_pos, side).await, ); @@ -552,8 +548,7 @@ async fn calculate_power(world: &World, pos: &BlockPos) -> u8 { wire_power, world, neighbor_pos.offset(BlockDirection::Up.to_offset()), - ) - .await; + ); } if !neighbor_state.is_solid_block() { @@ -561,8 +556,7 @@ async fn calculate_power(world: &World, pos: &BlockPos) -> u8 { wire_power, world, neighbor_pos.offset(BlockDirection::Down.to_offset()), - ) - .await; + ); } } } diff --git a/pumpkin/src/block/blocks/redstone/repeater.rs b/pumpkin/src/block/blocks/redstone/repeater.rs index 648d3436f..b88612135 100644 --- a/pumpkin/src/block/blocks/redstone/repeater.rs +++ b/pumpkin/src/block/blocks/redstone/repeater.rs @@ -48,7 +48,7 @@ impl BlockBehaviour for RepeaterBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); if self .is_locked(args.world, *args.position, state.id, args.block) .await @@ -116,7 +116,7 @@ impl BlockBehaviour for RepeaterBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let props = RepeaterProperties::from_state_id(state.id, args.block); self.on_use(props, args.world, *args.position, args.block) .await; @@ -150,10 +150,8 @@ impl BlockBehaviour for RepeaterBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - RedstoneGateBlock::can_place_at(self, args.block_accessor, *args.position).await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + RedstoneGateBlock::can_place_at(self, args.block_accessor, *args.position) } fn placed<'a>(&'a self, args: PlacedArgs<'a>) -> BlockFuture<'a, ()> { @@ -181,7 +179,6 @@ impl BlockBehaviour for RepeaterBlock { *args.neighbor_position, BlockState::from_id(args.neighbor_state_id), ) - .await { return Block::AIR.default_state.id; } diff --git a/pumpkin/src/block/blocks/redstone/tripwire.rs b/pumpkin/src/block/blocks/redstone/tripwire.rs index adbebc096..4e64258bf 100644 --- a/pumpkin/src/block/blocks/redstone/tripwire.rs +++ b/pumpkin/src/block/blocks/redstone/tripwire.rs @@ -58,7 +58,7 @@ impl BlockBehaviour for TripwireBlock { ] .map(async |dir| { let current_pos = args.position.offset(dir.to_offset()); - let state_id = args.world.get_block_state_id(¤t_pos).await; + let state_id = args.world.get_block_state_id(¤t_pos); Self::should_connect_to(state_id, dir) }); @@ -132,7 +132,7 @@ impl BlockBehaviour for TripwireBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let mut props = TripwireProperties::from_state_id(state_id, args.block); if !props.powered { @@ -163,7 +163,7 @@ impl BlockBehaviour for TripwireBlock { if args.moved || Block::from_state_id(args.old_state_id) == args.block { return; } - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); Self::update(args.world, args.position, state_id).await; }) } @@ -174,8 +174,7 @@ impl TripwireBlock { for dir in [BlockDirection::South, BlockDirection::West] { for i in 1..42 { let current_pos = pos.offset_dir(dir.to_offset(), i); - let (current_block, current_state) = - world.get_block_and_state_id(¤t_pos).await; + let (current_block, current_state) = world.get_block_and_state_id(¤t_pos); if current_block == &Block::TRIPWIRE_HOOK { let current_props = TripwireHookProperties::from_state_id(current_state, &Block::TRIPWIRE_HOOK); diff --git a/pumpkin/src/block/blocks/redstone/tripwire_hook.rs b/pumpkin/src/block/blocks/redstone/tripwire_hook.rs index 301de6b15..9cffc0c7d 100644 --- a/pumpkin/src/block/blocks/redstone/tripwire_hook.rs +++ b/pumpkin/src/block/blocks/redstone/tripwire_hook.rs @@ -35,7 +35,7 @@ impl BlockBehaviour for TripwireHookBlock { let mut props = TripwireHookProperties::default(args.block); props.powered = false; props.attached = false; - if Self::can_place_at(args.world, args.position, args.direction).await { + if Self::can_place_at(args.world, args.position, args.direction) { props.facing = args.direction.opposite().to_cardinal_direction(); return props.to_state_id(args.block); } @@ -43,17 +43,14 @@ impl BlockBehaviour for TripwireHookBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let props = TripwireHookProperties::from_state_id(args.state.id, args.block); + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let props = TripwireHookProperties::from_state_id(args.state.id, args.block); - Self::can_place_at( - args.block_accessor, - args.position, - props.facing.to_block_direction(), - ) - .await - }) + Self::can_place_at( + args.block_accessor, + args.position, + props.facing.to_block_direction(), + ) } fn player_placed<'a>(&'a self, args: PlayerPlacedArgs<'a>) -> BlockFuture<'a, ()> { @@ -79,7 +76,7 @@ impl BlockBehaviour for TripwireHookBlock { if args.direction.to_horizontal_facing().is_some_and(|facing| { let props = TripwireHookProperties::from_state_id(args.state_id, args.block); facing.opposite() == props.facing - }) && !Self::can_place_at(args.world, args.position, args.direction).await + }) && !Self::can_place_at(args.world, args.position, args.direction) { Block::AIR.default_state.id } else { @@ -90,7 +87,7 @@ impl BlockBehaviour for TripwireHookBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); Self::update(args.world, *args.position, state_id, false, true, -1, None).await; }) } @@ -164,7 +161,7 @@ impl BlockBehaviour for TripwireHookBlock { } impl TripwireHookBlock { - pub async fn can_place_at( + pub fn can_place_at( world: &dyn BlockAccessor, block_pos: &BlockPos, face: BlockDirection, @@ -173,7 +170,7 @@ impl TripwireHookBlock { return false; } let place_block_pos = block_pos.offset(face.to_offset()); - let place_block_state = world.get_block_state(&place_block_pos).await; + let place_block_state = world.get_block_state(&place_block_pos); place_block_state.is_side_solid(face) } @@ -196,10 +193,10 @@ impl TripwireHookBlock { for k in 1..42 { let current_pos = start_hook_pos.offset_dir(start_hook_props.facing.to_offset(), k); - let current_block = world.get_block(¤t_pos).await; + let current_block = world.get_block(¤t_pos); if current_block == &Block::TRIPWIRE_HOOK { let current_hook_props = { - let state_id = world.get_block_state_id(¤t_pos).await; + let state_id = world.get_block_state_id(¤t_pos); TripwireHookProperties::from_state_id(state_id, &Block::TRIPWIRE_HOOK) }; if current_hook_props.facing == start_hook_props.facing.opposite() { @@ -209,7 +206,7 @@ impl TripwireHookBlock { } if current_block == &Block::TRIPWIRE || k == raw_wire_index { let current_wire_props = { - let ro_state_id = world.get_block_state_id(¤t_pos).await; + let ro_state_id = world.get_block_state_id(¤t_pos); let state_id = if k == raw_wire_index { raw_wire_state.unwrap_or(ro_state_id) } else { @@ -268,8 +265,7 @@ impl TripwireHookBlock { future_powered, start_hook_props.attached, start_hook_props.powered, - ) - .await; + ); } Self::play_sound( @@ -279,8 +275,7 @@ impl TripwireHookBlock { future_powered, start_hook_props.attached, start_hook_props.powered, - ) - .await; + ); if !skip_state_update { let mut future_start_hook_state = future_hook_state; @@ -316,14 +311,14 @@ impl TripwireHookBlock { BlockFlags::NOTIFY_ALL, ) .await; - // if world.get_block(&lv7).await != Block::AIR {} + // if world.get_block(&lv7) != Block::AIR {} } } } } #[expect(clippy::fn_params_excessive_bools)] - async fn play_sound( + fn play_sound( world: &Arc, block_pos: &BlockPos, attached: bool, @@ -334,25 +329,17 @@ impl TripwireHookBlock { let cat = SoundCategory::Blocks; let pos = block_pos.to_f64(); if on && !off { - world - .play_sound_raw(Sound::BlockTripwireClickOn as u16, cat, &pos, 0.4, 0.6) - .await; + world.play_sound_raw(Sound::BlockTripwireClickOn as u16, cat, &pos, 0.4, 0.6); // TODO world.emitGameEvent((Entity)null, GameEvent.BLOCK_ACTIVATE, pos); } else if !on && off { - world - .play_sound_raw(Sound::BlockTripwireClickOff as u16, cat, &pos, 0.4, 0.5) - .await; + world.play_sound_raw(Sound::BlockTripwireClickOff as u16, cat, &pos, 0.4, 0.5); // TODO world.emitGameEvent((Entity)null, GameEvent.BLOCK_DEACTIVATE, pos); } else if attached && !detached { - world - .play_sound_raw(Sound::BlockTripwireAttach as u16, cat, &pos, 0.4, 0.7) - .await; + world.play_sound_raw(Sound::BlockTripwireAttach as u16, cat, &pos, 0.4, 0.7); // TODO world.emitGameEvent((Entity)null, GameEvent.BLOCK_ATTACH, pos); } else if !attached && detached { let pitch = 1.2 / rng().random::().mul_add(0.2, 0.9); - world - .play_sound_raw(Sound::BlockTripwireDetach as u16, cat, &pos, 0.4, pitch) - .await; + world.play_sound_raw(Sound::BlockTripwireDetach as u16, cat, &pos, 0.4, pitch); // TODO world.emitGameEvent((Entity)null, GameEvent.BLOCK_DETACH, pos); } } diff --git a/pumpkin/src/block/blocks/redstone/turbo.rs b/pumpkin/src/block/blocks/redstone/turbo.rs index 2c4f33358..b6b44854c 100644 --- a/pumpkin/src/block/blocks/redstone/turbo.rs +++ b/pumpkin/src/block/blocks/redstone/turbo.rs @@ -39,10 +39,10 @@ struct UpdateNode { } impl UpdateNode { - async fn new(world: &World, pos: BlockPos) -> Self { + fn new(world: &World, pos: BlockPos) -> Self { Self { pos, - state: world.get_block_state(&pos).await, + state: world.get_block_state(&pos), visited: false, neighbors: None, xbias: 0, @@ -129,7 +129,7 @@ impl RedstoneWireTurbo { // true, false, true, true, false, false // 18 to 23 // ]; - async fn identify_neighbors(&mut self, world: &World, upd1: NodeId) { + fn identify_neighbors(&mut self, world: &World, upd1: NodeId) { let pos = self.nodes[upd1.index].pos; let neighbors = Self::compute_all_neighbors(pos); let mut neighbors_visited = Vec::with_capacity(24); @@ -143,7 +143,7 @@ impl RedstoneWireTurbo { index: self.nodes.len(), }; self.node_cache.insert(*neighbor_pos, node_id); - self.nodes.push(UpdateNode::new(world, *neighbor_pos).await); + self.nodes.push(UpdateNode::new(world, *neighbor_pos)); node_id }; @@ -245,18 +245,18 @@ impl RedstoneWireTurbo { /// This is the start of a great adventure pub async fn update_surrounding_neighbors(world: &Arc, pos: BlockPos) { let mut turbo = Self::new(); - let mut root_node = UpdateNode::new(world, pos).await; + let mut root_node = UpdateNode::new(world, pos); root_node.visited = true; let node_id = NodeId { index: 0 }; turbo.node_cache.insert(pos, node_id); turbo.nodes.push(root_node); - turbo.propagate_changes(world, node_id, 0).await; + turbo.propagate_changes(world, node_id, 0); turbo.breadth_first_walk(world).await; } - async fn propagate_changes(&mut self, world: &World, upd1: NodeId, layer: u32) { + fn propagate_changes(&mut self, world: &World, upd1: NodeId, layer: u32) { if self.nodes[upd1.index].neighbors.is_none() { - self.identify_neighbors(world, upd1).await; + self.identify_neighbors(world, upd1); } let neighbors: [NodeId; 24] = self.nodes[upd1.index].neighbors.as_ref().unwrap()[0..24] @@ -337,7 +337,7 @@ impl RedstoneWireTurbo { wire.power = new_wire.power; node.state = BlockState::from_id(wire.to_state_id(&Block::REDSTONE_WIRE)); - self.propagate_changes(world, upd1, layer).await; + self.propagate_changes(world, upd1, layer); } } @@ -355,7 +355,7 @@ impl RedstoneWireTurbo { let mut block_power = 0; if self.nodes[upd.index].neighbors.is_none() { - self.identify_neighbors(world, upd).await; + self.identify_neighbors(world, upd); } let pos = self.nodes[upd.index].pos; diff --git a/pumpkin/src/block/blocks/shulker_box.rs b/pumpkin/src/block/blocks/shulker_box.rs index 223e4dbb8..b47420855 100644 --- a/pumpkin/src/block/blocks/shulker_box.rs +++ b/pumpkin/src/block/blocks/shulker_box.rs @@ -87,7 +87,7 @@ impl BlockBehaviour for ShulkerBoxBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(inventory) = block_entity.get_inventory() { args.player diff --git a/pumpkin/src/block/blocks/signs.rs b/pumpkin/src/block/blocks/signs.rs index bacfeacf4..2333c7843 100644 --- a/pumpkin/src/block/blocks/signs.rs +++ b/pumpkin/src/block/blocks/signs.rs @@ -52,8 +52,8 @@ struct SignPlacement { impl SignBlock { /// Checks if a block can provide support for a sign. - async fn is_valid_support(world: &World, pos: &BlockPos, direction: BlockDirection) -> bool { - let (block, state) = world.get_block_and_state(pos).await; + fn is_valid_support(world: &World, pos: &BlockPos, direction: BlockDirection) -> bool { + let (block, state) = world.get_block_and_state(pos); let is_permissive = block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_LEAVES) || block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_SIGNS); @@ -65,8 +65,8 @@ impl SignBlock { } /// Detects available support points around a position. - async fn detect_support(world: &World, position: &BlockPos) -> SupportInfo { - let (block_above, state_above) = world.get_block_and_state(&position.up()).await; + fn detect_support(world: &World, position: &BlockPos) -> SupportInfo { + let (block_above, state_above) = world.get_block_and_state(&position.up()); let above_is_valid = state_above.is_side_solid(BlockDirection::Down) || block_above.has_tag(&pumpkin_data::tag::Block::MINECRAFT_SIGNS) || block_above.has_tag(&pumpkin_data::tag::Block::MINECRAFT_LEAVES); @@ -74,7 +74,7 @@ impl SignBlock { let mut side_direction = None; for direction in BlockDirection::horizontal() { let pos = position.offset(direction.to_offset()); - if Self::is_valid_support(world, &pos, direction.opposite()).await { + if Self::is_valid_support(world, &pos, direction.opposite()) { side_direction = Some(direction); break; } @@ -293,7 +293,7 @@ impl SignBlock { impl BlockBehaviour for SignBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - let support = Self::detect_support(args.world, args.position).await; + let support = Self::detect_support(args.world, args.position); let Some(placement) = Self::determine_placement(&args, &support) else { return 0; // Invalid placement @@ -323,49 +323,47 @@ impl BlockBehaviour for SignBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let is_hanging = args.block.name.contains("hanging"); - let clicked_face = args - .use_item_on - .and_then(|u| pumpkin_data::BlockDirection::try_from(u.face.0).ok()) - .unwrap_or(pumpkin_data::BlockDirection::Up); + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let is_hanging = args.block.name.contains("hanging"); + let clicked_face = args + .use_item_on + .and_then(|u| pumpkin_data::BlockDirection::try_from(u.face.0).ok()) + .unwrap_or(pumpkin_data::BlockDirection::Up); - // Detection for floor-to-wall attachment (broken rn) - if is_hanging && clicked_face == BlockDirection::Up { - for d in pumpkin_data::BlockDirection::horizontal() { - let wall_pos = args.position.offset(d.to_offset()); - let (block, state) = args.block_accessor.get_block_and_state(&wall_pos).await; - if state.is_side_solid(d.opposite()) - || block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_LEAVES) - || block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_SIGNS) - { - return true; - } + // Detection for floor-to-wall attachment (broken rn) + if is_hanging && clicked_face == BlockDirection::Up { + for d in pumpkin_data::BlockDirection::horizontal() { + let wall_pos = args.position.offset(d.to_offset()); + let (block, state) = args.block_accessor.get_block_and_state(&wall_pos); + if state.is_side_solid(d.opposite()) + || block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_LEAVES) + || block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_SIGNS) + { + return true; } } + } - // Standard support validation with permissive tags - let support_pos = match clicked_face { - BlockDirection::Up => args.position.down(), - BlockDirection::Down => args.position.up(), - _ => args.position.offset(clicked_face.opposite().to_offset()), - }; + // Standard support validation with permissive tags + let support_pos = match clicked_face { + BlockDirection::Up => args.position.down(), + BlockDirection::Down => args.position.up(), + _ => args.position.offset(clicked_face.opposite().to_offset()), + }; - let (block, state) = args.block_accessor.get_block_and_state(&support_pos).await; - let is_permissive = block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_LEAVES) - || block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_SIGNS); + let (block, state) = args.block_accessor.get_block_and_state(&support_pos); + let is_permissive = block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_LEAVES) + || block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_SIGNS); - match clicked_face { - BlockDirection::Up => { - !is_hanging && (state.is_center_solid(BlockDirection::Up) || is_permissive) - } - BlockDirection::Down => { - is_hanging && (state.is_side_solid(BlockDirection::Down) || is_permissive) - } - _ => state.is_side_solid(clicked_face.opposite()) || is_permissive, + match clicked_face { + BlockDirection::Up => { + !is_hanging && (state.is_center_solid(BlockDirection::Up) || is_permissive) } - }) + BlockDirection::Down => { + is_hanging && (state.is_side_solid(BlockDirection::Down) || is_permissive) + } + _ => state.is_side_solid(clicked_face.opposite()) || is_permissive, + } } fn on_state_replaced<'a>(&'a self, args: OnStateReplacedArgs<'a>) -> BlockFuture<'a, ()> { @@ -399,7 +397,7 @@ impl BlockBehaviour for SignBlock { if args.direction == dir { let support_pos = args.position.offset(dir.to_offset()); let (support_block, support_state) = - args.world.get_block_and_state(&support_pos).await; + args.world.get_block_and_state(&support_pos); // Permissive support check let is_leaf = @@ -428,7 +426,7 @@ impl BlockBehaviour for SignBlock { /// Handles normal use (right-click) on the sign block. fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let Some(block_entity) = args.world.get_block_entity(args.position).await else { + let Some(block_entity) = args.world.get_block_entity(args.position) else { return BlockActionResult::Pass; }; let Some(sign_entity) = block_entity.as_any().downcast_ref::() else { @@ -436,13 +434,11 @@ impl BlockBehaviour for SignBlock { }; if sign_entity.is_waxed.load(Ordering::Relaxed) { - args.world - .play_block_sound( - pumpkin_data::sound::Sound::BlockSignWaxedInteractFail, - pumpkin_data::sound::SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + pumpkin_data::sound::Sound::BlockSignWaxedInteractFail, + pumpkin_data::sound::SoundCategory::Blocks, + *args.position, + ); return BlockActionResult::SuccessServer; } @@ -457,7 +453,7 @@ impl BlockBehaviour for SignBlock { } let is_facing_front_text = - is_facing_front_text(args.world, args.position, args.block, args.player).await; + is_facing_front_text(args.world, args.position, args.block, args.player); match &args.player.client { ClientPlatform::Java(java) => { java.send_sign_packet(*args.position, is_facing_front_text) @@ -476,7 +472,7 @@ impl BlockBehaviour for SignBlock { args: UseWithItemArgs<'a>, ) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let Some(block_entity) = args.world.get_block_entity(args.position).await else { + let Some(block_entity) = args.world.get_block_entity(args.position) else { return BlockActionResult::Pass; }; let Some(sign_entity) = block_entity.as_any().downcast_ref::() else { @@ -498,12 +494,11 @@ impl BlockBehaviour for SignBlock { return BlockActionResult::PassToDefaultBlockAction; } - let text = - if is_facing_front_text(args.world, args.position, args.block, args.player).await { - &sign_entity.front_text - } else { - &sign_entity.back_text - }; + let text = if is_facing_front_text(args.world, args.position, args.block, args.player) { + &sign_entity.front_text + } else { + &sign_entity.back_text + }; let mut item = args.item_stack.lock().await; @@ -581,13 +576,13 @@ fn get_sign_variant(base: &Block, is_hanging: bool) -> u16 { pumpkin_data::Block::from_name(&target_name).map_or(base.id, |b| b.id) } -async fn is_facing_front_text( +fn is_facing_front_text( world: &World, location: &BlockPos, block: &Block, player: &Player, ) -> bool { - let state_id = world.get_block_state_id(location).await; + let state_id = world.get_block_state_id(location); // Read properties dynamically: some sign types use a `rotation` property (0..15), // others (wall signs) use a `facing` property (north/south/west/east), // hanging signs may have `rotation` + `attached`. diff --git a/pumpkin/src/block/blocks/skull_block.rs b/pumpkin/src/block/blocks/skull_block.rs index f2ddb0415..b26cfb9fd 100644 --- a/pumpkin/src/block/blocks/skull_block.rs +++ b/pumpkin/src/block/blocks/skull_block.rs @@ -36,7 +36,7 @@ impl BlockBehaviour for SkullBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut props = SkeletonSkullLikeProperties::from_state_id(state.id, args.block); let is_receiving_power = block_receives_redstone_power(args.world, args.position).await; if props.powered != is_receiving_power { diff --git a/pumpkin/src/block/blocks/slabs.rs b/pumpkin/src/block/blocks/slabs.rs index 27d8ccea6..b71457162 100644 --- a/pumpkin/src/block/blocks/slabs.rs +++ b/pumpkin/src/block/blocks/slabs.rs @@ -40,19 +40,17 @@ impl BlockBehaviour for SlabBlock { }) } - fn can_update_at<'a>(&'a self, args: CanUpdateAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let slab_props = SlabProperties::from_state_id(args.state_id, args.block); + fn can_update_at(&self, args: CanUpdateAtArgs<'_>) -> bool { + let slab_props = SlabProperties::from_state_id(args.state_id, args.block); - slab_props.r#type - == match args.direction { - BlockDirection::Up => SlabType::Bottom, - BlockDirection::Down => SlabType::Top, - _ => match args.use_item_on.cursor_pos.y { - 0.0..0.5 => SlabType::Top, - _ => SlabType::Bottom, - }, - } - }) + slab_props.r#type + == match args.direction { + BlockDirection::Up => SlabType::Bottom, + BlockDirection::Down => SlabType::Top, + _ => match args.use_item_on.cursor_pos.y { + 0.0..0.5 => SlabType::Top, + _ => SlabType::Bottom, + }, + } } } diff --git a/pumpkin/src/block/blocks/smoker.rs b/pumpkin/src/block/blocks/smoker.rs index b38627a6e..58e6c9da3 100644 --- a/pumpkin/src/block/blocks/smoker.rs +++ b/pumpkin/src/block/blocks/smoker.rs @@ -84,7 +84,7 @@ pub struct SmokerBlock; impl BlockBehaviour for SmokerBlock { fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(inventory) = block_entity.clone().get_inventory() && let Some(property_delegate) = block_entity.clone().to_property_delegate() && let Some(experience_container) = block_entity.to_experience_container() @@ -125,7 +125,7 @@ impl BlockBehaviour for SmokerBlock { fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { // Extract and drop accumulated XP as orbs before removing the block entity - if let Some(block_entity) = args.world.get_block_entity(args.position).await + if let Some(block_entity) = args.world.get_block_entity(args.position) && let Some(experience_container) = block_entity.to_experience_container() { let xp = experience_container.extract_experience(); diff --git a/pumpkin/src/block/blocks/snow.rs b/pumpkin/src/block/blocks/snow.rs index ffe1ad782..93e495e0b 100644 --- a/pumpkin/src/block/blocks/snow.rs +++ b/pumpkin/src/block/blocks/snow.rs @@ -19,7 +19,7 @@ pub struct LayeredSnowBlock; impl BlockBehaviour for LayeredSnowBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { return Block::AIR.default_state.id; } let mut props = SnowLikeProperties::default(args.block); @@ -44,10 +44,10 @@ impl BlockBehaviour for LayeredSnowBlock { } else { args.position }; - if !can_place_at(args.world.as_ref(), pos).await { + if !can_place_at(args.world.as_ref(), pos) { return BlockActionResult::Pass; } - let (block, state_id) = args.world.get_block_and_state_id(pos).await; + let (block, state_id) = args.world.get_block_and_state_id(pos); if block != &Block::SNOW { return BlockActionResult::Pass; @@ -78,7 +78,7 @@ impl BlockBehaviour for LayeredSnowBlock { fn on_scheduled_tick<'a>(&'a self, args: OnScheduledTickArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - if !can_place_at(args.world.as_ref(), args.position).await { + if !can_place_at(args.world.as_ref(), args.position) { args.world .break_block(args.position, None, BlockFlags::empty()) .await; @@ -91,7 +91,7 @@ impl BlockBehaviour for LayeredSnowBlock { args: GetStateForNeighborUpdateArgs<'a>, ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { - if !can_place_at(args.world, args.position).await { + if !can_place_at(args.world, args.position) { args.world .schedule_block_tick(args.block, *args.position, 1, TickPriority::Normal) .await; @@ -101,7 +101,7 @@ impl BlockBehaviour for LayeredSnowBlock { } } -async fn can_place_at(block_accessor: &dyn BlockAccessor, position: &BlockPos) -> bool { - let state = block_accessor.get_block_state(&position.down()).await; +fn can_place_at(block_accessor: &dyn BlockAccessor, position: &BlockPos) -> bool { + let state = block_accessor.get_block_state(&position.down()); state.is_side_solid(BlockDirection::Up) } diff --git a/pumpkin/src/block/blocks/sponge.rs b/pumpkin/src/block/blocks/sponge.rs index 023576ff3..ed9101cd8 100644 --- a/pumpkin/src/block/blocks/sponge.rs +++ b/pumpkin/src/block/blocks/sponge.rs @@ -53,7 +53,7 @@ impl SpongeBlock { } visited.insert(next_pos); - let (block, _state) = world.get_block_and_state(&next_pos).await; + let (block, _state) = world.get_block_and_state(&next_pos); // Only add to queue if it's water. // This prevents "jumping" through air or solid blocks. @@ -80,9 +80,7 @@ impl SpongeBlock { ) .await; - world - .play_block_sound(Sound::BlockSpongeAbsorb, SoundCategory::Blocks, *position) - .await; + world.play_block_sound(Sound::BlockSpongeAbsorb, SoundCategory::Blocks, *position); true } @@ -124,27 +122,23 @@ impl BlockBehaviour for WetSpongeBlock { .await; // Play dry sound and spawn smoke particles - args.world - .play_block_sound( - Sound::BlockWetSpongeDries, - SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + Sound::BlockWetSpongeDries, + SoundCategory::Blocks, + *args.position, + ); - args.world - .spawn_particle( - Vector3::new( - args.position.0.x as f64 + 0.5, - args.position.0.y as f64 + 1.0, - args.position.0.z as f64 + 0.5, - ), - Vector3::new(0.25, 0.0, 0.25), - 0.01, - 16, - Particle::Cloud, - ) - .await; + args.world.spawn_particle( + Vector3::new( + args.position.0.x as f64 + 0.5, + args.position.0.y as f64 + 1.0, + args.position.0.z as f64 + 0.5, + ), + Vector3::new(0.25, 0.0, 0.25), + 0.01, + 16, + Particle::Cloud, + ); } }) } diff --git a/pumpkin/src/block/blocks/stairs.rs b/pumpkin/src/block/blocks/stairs.rs index 83884f200..1c0eb1b95 100644 --- a/pumpkin/src/block/blocks/stairs.rs +++ b/pumpkin/src/block/blocks/stairs.rs @@ -44,8 +44,7 @@ impl BlockBehaviour for StairBlock { args.position, stair_props.facing, stair_props.half, - ) - .await; + ); stair_props.to_state_id(args.block) }) @@ -53,7 +52,7 @@ impl BlockBehaviour for StairBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let state_id = args.world.get_block_state_id(args.position).await; + let state_id = args.world.get_block_state_id(args.position); let mut stair_props = StairsProperties::from_state_id(state_id, args.block); let new_shape = compute_stair_shape( @@ -61,8 +60,7 @@ impl BlockBehaviour for StairBlock { args.position, stair_props.facing, stair_props.half, - ) - .await; + ); if stair_props.shape != new_shape { stair_props.shape = new_shape; @@ -78,7 +76,7 @@ impl BlockBehaviour for StairBlock { } } -async fn compute_stair_shape( +fn compute_stair_shape( world: &World, block_pos: &BlockPos, facing: HorizontalFacing, @@ -88,7 +86,6 @@ async fn compute_stair_shape( world, &block_pos.offset(facing.rotate_clockwise().to_offset()), ) - .await .is_some_and(|other_stair_props| { other_stair_props.half == half && other_stair_props.facing == facing }); @@ -97,7 +94,6 @@ async fn compute_stair_shape( world, &block_pos.offset(facing.rotate_counter_clockwise().to_offset()), ) - .await .is_some_and(|other_stair_props| { other_stair_props.half == half && other_stair_props.facing == facing }); @@ -107,7 +103,7 @@ async fn compute_stair_shape( } if let Some(other_stair_props) = - get_stair_properties_if_exists(world, &block_pos.offset(facing.to_offset())).await + get_stair_properties_if_exists(world, &block_pos.offset(facing.to_offset())) && other_stair_props.half == half { if !left_locked && other_stair_props.facing == facing.rotate_clockwise() { @@ -119,7 +115,6 @@ async fn compute_stair_shape( if let Some(other_stair_props) = get_stair_properties_if_exists(world, &block_pos.offset(facing.opposite().to_offset())) - .await && other_stair_props.half == half { if !right_locked && other_stair_props.facing == facing.rotate_clockwise() { @@ -132,11 +127,8 @@ async fn compute_stair_shape( StairsShape::Straight } -async fn get_stair_properties_if_exists( - world: &World, - block_pos: &BlockPos, -) -> Option { - let (block, block_state) = world.get_block_and_state_id(block_pos).await; +fn get_stair_properties_if_exists(world: &World, block_pos: &BlockPos) -> Option { + let (block, block_state) = world.get_block_and_state_id(block_pos); block .has_tag(&tag::Block::MINECRAFT_STAIRS) .then(|| StairsProperties::from_state_id(block_state, block)) diff --git a/pumpkin/src/block/blocks/tnt.rs b/pumpkin/src/block/blocks/tnt.rs index 75f32f10c..d3477fd96 100644 --- a/pumpkin/src/block/blocks/tnt.rs +++ b/pumpkin/src/block/blocks/tnt.rs @@ -27,13 +27,11 @@ impl TNTBlock { let pos = entity.pos.load(); let tnt = Arc::new(TNTEntity::new(entity, DEFAULT_POWER, DEFAULT_FUSE)); world.spawn_entity(tnt).await; - world - .play_sound( - pumpkin_data::sound::Sound::EntityTntPrimed, - SoundCategory::Blocks, - &pos, - ) - .await; + world.play_sound( + pumpkin_data::sound::Sound::EntityTntPrimed, + SoundCategory::Blocks, + &pos, + ); world .set_block_state(location, 0, BlockFlags::NOTIFY_ALL) .await; @@ -80,9 +78,7 @@ impl BlockBehaviour for TNTBlock { Box::pin(async move { let entity = Entity::new(args.world.clone(), args.position.to_f64(), &EntityType::TNT); let angle = rand::random::() * std::f64::consts::TAU; - entity - .set_velocity(Vector3::new(-angle.sin() * 0.02, 0.2, -angle.cos() * 0.02)) - .await; + entity.set_velocity(Vector3::new(-angle.sin() * 0.02, 0.2, -angle.cos() * 0.02)); let fuse = rand::rng().random_range(0..DEFAULT_FUSE / 4) + DEFAULT_FUSE / 8; let tnt = Arc::new(TNTEntity::new(entity, DEFAULT_POWER, fuse)); args.world.spawn_entity(tnt).await; diff --git a/pumpkin/src/block/blocks/torches.rs b/pumpkin/src/block/blocks/torches.rs index 741fd07a9..303956e68 100644 --- a/pumpkin/src/block/blocks/torches.rs +++ b/pumpkin/src/block/blocks/torches.rs @@ -34,7 +34,7 @@ impl BlockBehaviour for TorchBlock { fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { if args.direction == BlockDirection::Down { - let support_block = args.world.get_block_state(&args.position.down()).await; + let support_block = args.world.get_block_state(&args.position.down()); if support_block.is_center_solid(BlockDirection::Up) { return args.block.default_state.id; } @@ -53,7 +53,7 @@ impl BlockBehaviour for TorchBlock { directions[0] = face; } } else if directions[0] == Facing::Down { - let support_block = args.world.get_block_state(&args.position.down()).await; + let support_block = args.world.get_block_state(&args.position.down()); if support_block.is_center_solid(BlockDirection::Up) { return args.block.default_state.id; } @@ -62,7 +62,7 @@ impl BlockBehaviour for TorchBlock { for dir in directions { if dir != Facing::Up && dir != Facing::Down - && can_place_at(args.world, args.position, dir.to_block_direction()).await + && can_place_at(args.world, args.position, dir.to_block_direction()) { let wall_block = { if args.block == &Block::TORCH { @@ -83,7 +83,7 @@ impl BlockBehaviour for TorchBlock { } } - let support_block = args.world.get_block_state(&args.position.down()).await; + let support_block = args.world.get_block_state(&args.position.down()); if support_block.is_center_solid(BlockDirection::Up) { args.block.default_state.id } else { @@ -92,22 +92,17 @@ impl BlockBehaviour for TorchBlock { }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - let support_block = args - .block_accessor - .get_block_state(&args.position.down()) - .await; - if support_block.is_center_solid(BlockDirection::Up) { + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + let support_block = args.block_accessor.get_block_state(&args.position.down()); + if support_block.is_center_solid(BlockDirection::Up) { + return true; + } + for dir in BlockDirection::horizontal() { + if can_place_at(args.block_accessor, args.position, dir) { return true; } - for dir in BlockDirection::horizontal() { - if can_place_at(args.block_accessor, args.position, dir).await { - return true; - } - } - false - }) + } + false } fn get_state_for_neighbor_update<'a>( @@ -126,12 +121,11 @@ impl BlockBehaviour for TorchBlock { args.position, props.facing.to_block_direction().opposite(), ) - .await { return 0; } } else if args.direction == BlockDirection::Down { - let support_block = args.world.get_block_state(&args.position.down()).await; + let support_block = args.world.get_block_state(&args.position.down()); if !support_block.is_center_solid(BlockDirection::Up) { return 0; } @@ -141,13 +135,8 @@ impl BlockBehaviour for TorchBlock { } } -async fn can_place_at( - world: &dyn BlockAccessor, - block_pos: &BlockPos, - facing: BlockDirection, -) -> bool { +fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos, facing: BlockDirection) -> bool { world .get_block_state(&block_pos.offset(facing.to_offset())) - .await .is_side_solid(facing.opposite()) } diff --git a/pumpkin/src/block/blocks/trapdoor.rs b/pumpkin/src/block/blocks/trapdoor.rs index 5eac8c39c..413b5d069 100644 --- a/pumpkin/src/block/blocks/trapdoor.rs +++ b/pumpkin/src/block/blocks/trapdoor.rs @@ -17,18 +17,16 @@ use std::sync::Arc; type TrapDoorProperties = pumpkin_data::block_properties::OakTrapdoorLikeProperties; async fn toggle_trapdoor(player: &Player, world: &Arc, block_pos: &BlockPos) { - let (block, block_state) = world.get_block_and_state_id(block_pos).await; + let (block, block_state) = world.get_block_and_state_id(block_pos); let mut trapdoor_props = TrapDoorProperties::from_state_id(block_state, block); trapdoor_props.open = !trapdoor_props.open; - world - .play_block_sound_expect( - player, - get_sound(block, trapdoor_props.open), - SoundCategory::Blocks, - *block_pos, - ) - .await; + world.play_block_sound_expect( + player, + get_sound(block, trapdoor_props.open), + SoundCategory::Blocks, + *block_pos, + ); world .set_block_state( @@ -115,7 +113,7 @@ impl BlockBehaviour for TrapDoorBlock { fn on_neighbor_update<'a>(&'a self, args: OnNeighborUpdateArgs<'a>) -> BlockFuture<'a, ()> { Box::pin(async move { - let block_state = args.world.get_block_state(args.position).await; + let block_state = args.world.get_block_state(args.position); let mut trapdoor_props = TrapDoorProperties::from_state_id(block_state.id, args.block); let powered = block_receives_redstone_power(args.world, args.position).await; @@ -125,13 +123,11 @@ impl BlockBehaviour for TrapDoorBlock { if powered != trapdoor_props.open { trapdoor_props.open = trapdoor_props.powered; - args.world - .play_block_sound( - get_sound(args.block, powered), - SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + get_sound(args.block, powered), + SoundCategory::Blocks, + *args.position, + ); } } diff --git a/pumpkin/src/block/blocks/vine.rs b/pumpkin/src/block/blocks/vine.rs index a2046468c..0b6922516 100644 --- a/pumpkin/src/block/blocks/vine.rs +++ b/pumpkin/src/block/blocks/vine.rs @@ -32,9 +32,7 @@ impl BlockBehaviour for VineBlock { Some(args.player), args.direction, true, - ) - .await - else { + ) else { return Block::AIR.default_state.id; }; let mut props = VineLikeProperties::from_state_id(state_id, args.block); @@ -47,9 +45,7 @@ impl BlockBehaviour for VineBlock { Some(args.player), args.direction, false, - ) - .await - else { + ) else { return Block::AIR.default_state.id; }; let mut props = VineLikeProperties::default(args.block); @@ -57,17 +53,14 @@ impl BlockBehaviour for VineBlock { props.to_state_id(args.block) }) } - fn can_place_at<'a>(&'a self, args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - can_place_vine_at( - args.block_accessor, - args.position, - args.direction, - args.player, - false, - ) - .await - }) + fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { + can_place_vine_at( + args.block_accessor, + args.position, + args.direction, + args.player, + false, + ) } fn get_state_for_neighbor_update<'a>( &'a self, @@ -80,10 +73,9 @@ impl BlockBehaviour for VineBlock { for old_dir in old_directions { let support_block = args .world - .get_block(&args.position.offset(old_dir.to_offset())) - .await; + .get_block(&args.position.offset(old_dir.to_offset())); if !supports_vine(support_block) - && !is_top_block_full_vine(args.world, args.position).await + && !is_top_block_full_vine(args.world, args.position) { new_directions.remove(&old_dir); } @@ -100,26 +92,23 @@ impl BlockBehaviour for VineBlock { new_props.to_state_id(args.block) }) } - fn can_update_at<'a>(&'a self, args: CanUpdateAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { - get_accurate_direction( - args.world, - args.position, - Some(args.player), - args.direction, - true, - ) - .await - .0 - .is_some() - }) + fn can_update_at(&self, args: CanUpdateAtArgs<'_>) -> bool { + get_accurate_direction( + args.world, + args.position, + Some(args.player), + args.direction, + true, + ) + .0 + .is_some() } fn use_with_item<'a>( &'a self, args: UseWithItemArgs<'a>, ) -> BlockFuture<'a, BlockActionResult> { Box::pin(async move { - let state = args.world.get_block_state(args.position).await; + let state = args.world.get_block_state(args.position); let mut props = VineLikeProperties::from_state_id(state.id, args.block); let item_lock = args.item_stack.lock().await; @@ -135,9 +124,7 @@ impl BlockBehaviour for VineBlock { Some(args.player), BlockDirection::Down, true, - ) - .await - else { + ) else { return BlockActionResult::Fail; }; vine_direction_mapper(accurate_dir, &mut props); @@ -186,7 +173,7 @@ pub fn get_nearest_looking_directions( } directions } -async fn can_place_vine_at( +fn can_place_vine_at( block_accessor: &dyn BlockAccessor, block_pos: &BlockPos, click_direction_wrapper: Option, @@ -196,21 +183,20 @@ async fn can_place_vine_at( let Some(click_direction) = click_direction_wrapper else { return false; }; - let (Some(direction), _) = get_accurate_direction( + let (direction, _) = get_accurate_direction( block_accessor, block_pos, player_wrapper, click_direction, replacing, - ) - .await - else { + ); + let Some(direction) = direction else { return false; }; + let support_pos = block_pos.offset(direction.to_offset()); - let (support_block, _support_block_state) = - block_accessor.get_block_and_state(&support_pos).await; - if !supports_vine(support_block) && !is_top_block_full_vine(block_accessor, block_pos).await { + let (support_block, _support_block_state) = block_accessor.get_block_and_state(&support_pos); + if !supports_vine(support_block) && !is_top_block_full_vine(block_accessor, block_pos) { return false; } true @@ -224,16 +210,14 @@ const fn supports_vine(support_block: &Block) -> bool { //returns (accurate direction, boolean) // true if this direction is for hanging vine // false if it is not -async fn get_accurate_direction( +fn get_accurate_direction( block_accessor: &dyn BlockAccessor, block_pos: &BlockPos, player_wrapper: Option<&Player>, click_direction: BlockDirection, replacing: bool, ) -> (Option, bool) { - let clicked_block = block_accessor - .get_block(&block_pos.offset(click_direction.to_offset())) - .await; + let clicked_block = block_accessor.get_block(&block_pos.offset(click_direction.to_offset())); if !replacing && clicked_block == &Block::VINE && click_direction != BlockDirection::Up { return (None, false); } @@ -241,8 +225,7 @@ async fn get_accurate_direction( if click_direction != BlockDirection::Down && supports_vine(clicked_block) { return (Some(click_direction), false); } - let (replacing_block, replacing_block_state) = - block_accessor.get_block_and_state(block_pos).await; + let (replacing_block, replacing_block_state) = block_accessor.get_block_and_state(block_pos); let already_active_directions = if replacing_block == &Block::VINE { let props = VineLikeProperties::from_state_id(replacing_block_state.id, replacing_block); get_vine_block_directions(props) @@ -255,10 +238,10 @@ async fn get_accurate_direction( if dir != BlockDirection::Down && !already_active_directions.contains(&dir) { let support_pos = block_pos.offset(dir.to_offset()); let (support_block, _support_block_state) = - block_accessor.get_block_and_state(&support_pos).await; + block_accessor.get_block_and_state(&support_pos); if !supports_vine(support_block) { //handler for hanging vine - if is_top_block_full_vine(block_accessor, block_pos).await { + if is_top_block_full_vine(block_accessor, block_pos) { if dir == BlockDirection::Up { continue; } @@ -280,8 +263,8 @@ async fn get_accurate_direction( } (None, false) } -async fn is_top_block_full_vine(block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { - let (top_block, top_block_state) = block_accessor.get_block_and_state(&block_pos.up()).await; +fn is_top_block_full_vine(block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { + let (top_block, top_block_state) = block_accessor.get_block_and_state(&block_pos.up()); if top_block != &Block::VINE { return false; } diff --git a/pumpkin/src/block/blocks/walls.rs b/pumpkin/src/block/blocks/walls.rs index 0068389d9..61b997890 100644 --- a/pumpkin/src/block/blocks/walls.rs +++ b/pumpkin/src/block/blocks/walls.rs @@ -30,7 +30,7 @@ impl BlockBehaviour for WallBlock { let mut wall_props = WallProperties::default(args.block); wall_props.waterlogged = args.replacing.water_source(); - compute_wall_state(wall_props, args.world, args.block, args.position).await + compute_wall_state(wall_props, args.world, args.block, args.position) }) } @@ -40,22 +40,22 @@ impl BlockBehaviour for WallBlock { ) -> BlockFuture<'a, BlockStateId> { Box::pin(async move { let wall_props = WallProperties::from_state_id(args.state_id, args.block); - compute_wall_state(wall_props, args.world, args.block, args.position).await + compute_wall_state(wall_props, args.world, args.block, args.position) }) } } -pub async fn compute_wall_state( +pub fn compute_wall_state( mut wall_props: WallProperties, world: &World, block: &Block, block_pos: &BlockPos, ) -> u16 { - let (block_above, block_above_state) = world.get_block_and_state(&block_pos.up()).await; + let (block_above, block_above_state) = world.get_block_and_state(&block_pos.up()); for direction in HorizontalFacing::all() { let other_block_pos = block_pos.offset(direction.to_offset()); - let (other_block, other_block_state) = world.get_block_and_state(&other_block_pos).await; + let (other_block, other_block_state) = world.get_block_and_state(&other_block_pos); let connected = is_connected(block, direction, other_block, other_block_state); diff --git a/pumpkin/src/block/blocks/wither_skull.rs b/pumpkin/src/block/blocks/wither_skull.rs index aea1ac4d7..b0bc0118e 100644 --- a/pumpkin/src/block/blocks/wither_skull.rs +++ b/pumpkin/src/block/blocks/wither_skull.rs @@ -48,13 +48,13 @@ impl BlockBehaviour for WitherSkeletonSkullBlock { let skull1_pos = arm1.up(); let skull2_pos = arm2.up(); - if is_soul_block(world.get_block(&top_middle).await) - && is_soul_block(world.get_block(&base).await) - && is_soul_block(world.get_block(&arm1).await) - && is_soul_block(world.get_block(&arm2).await) - && is_skull(world.get_block(¢er_skull_pos).await) - && is_skull(world.get_block(&skull1_pos).await) - && is_skull(world.get_block(&skull2_pos).await) + if is_soul_block(world.get_block(&top_middle)) + && is_soul_block(world.get_block(&base)) + && is_soul_block(world.get_block(&arm1)) + && is_soul_block(world.get_block(&arm2)) + && is_skull(world.get_block(¢er_skull_pos)) + && is_skull(world.get_block(&skull1_pos)) + && is_skull(world.get_block(&skull2_pos)) { let pattern = [ center_skull_pos, @@ -74,13 +74,11 @@ impl BlockBehaviour for WitherSkeletonSkullBlock { BlockFlags::NOTIFY_ALL, ) .await; - world - .sync_world_event( - WorldEvent::ParticlesDestroyBlock, - p, - Block::SOUL_SAND.default_state.id.into(), - ) - .await; + world.sync_world_event( + WorldEvent::ParticlesDestroyBlock, + p, + Block::SOUL_SAND.default_state.id.into(), + ); } let entity = Entity::new( @@ -88,7 +86,7 @@ impl BlockBehaviour for WitherSkeletonSkullBlock { top_middle.to_centered_f64(), &EntityType::WITHER, ); - let wither = WitherEntity::new(entity).await; + let wither = WitherEntity::new(entity); world.spawn_entity(wither).await; return; } diff --git a/pumpkin/src/block/entities/barrel.rs b/pumpkin/src/block/entities/barrel.rs index 4bde3dc5f..dc4217640 100644 --- a/pumpkin/src/block/entities/barrel.rs +++ b/pumpkin/src/block/entities/barrel.rs @@ -101,7 +101,7 @@ impl ViewerCountListener for BarrelBlockEntity { _position: &'a BlockPos, ) -> ViewerFuture<'a, ()> { Box::pin(async move { - self.play_sound(world, Sound::BlockBarrelOpen).await; + self.play_sound(world, Sound::BlockBarrelOpen); self.set_open(world, true).await; }) } @@ -112,7 +112,7 @@ impl ViewerCountListener for BarrelBlockEntity { _position: &'a BlockPos, ) -> ViewerFuture<'a, ()> { Box::pin(async move { - self.play_sound(world, Sound::BlockBarrelClose).await; + self.play_sound(world, Sound::BlockBarrelClose); self.set_open(world, false).await; }) } @@ -133,7 +133,7 @@ impl BarrelBlockEntity { } async fn set_open(&self, world: &Arc, open: bool) { - let state = world.get_block_state(&self.position).await; + let state = world.get_block_state(&self.position); let mut properties = BarrelLikeProperties::from_state_id(state.id, &Block::BARREL); properties.open = open; @@ -148,10 +148,10 @@ impl BarrelBlockEntity { .await; } - async fn play_sound(&self, world: &Arc, sound: Sound) { + fn play_sound(&self, world: &Arc, sound: Sound) { let mut rng = Xoroshiro::from_seed(get_seed()); - let state = world.get_block_state(&self.position).await; + let state = world.get_block_state(&self.position); let properties = BarrelLikeProperties::from_state_id(state.id, &Block::BARREL); let direction = properties.facing.to_block_direction().to_offset(); let position = Vector3::new( @@ -159,15 +159,13 @@ impl BarrelBlockEntity { self.position.0.y as f64 + 0.5 + direction.y as f64 / 2.0, self.position.0.z as f64 + 0.5 + direction.z as f64 / 2.0, ); - world - .play_sound_fine( - sound, - SoundCategory::Blocks, - &position, - 0.5, - rng.next_f32() * 0.1 + 0.9, - ) - .await; + world.play_sound_fine( + sound, + SoundCategory::Blocks, + &position, + 0.5, + rng.next_f32() * 0.1 + 0.9, + ); } } diff --git a/pumpkin/src/block/entities/beacon.rs b/pumpkin/src/block/entities/beacon.rs index 638bb1f79..18f3a6afb 100644 --- a/pumpkin/src/block/entities/beacon.rs +++ b/pumpkin/src/block/entities/beacon.rs @@ -76,7 +76,7 @@ impl BeaconBlockEntity { } /// Replicates Java's `updateBase` logic - async fn update_base(&self, world: &Arc) -> i32 { + fn update_base(&self, world: &Arc) -> i32 { let mut levels = 0; let x = self.position.0.x; let y = self.position.0.y; @@ -92,7 +92,7 @@ impl BeaconBlockEntity { for lx in (x - step)..=(x + step) { for lz in (z - step)..=(z + step) { let pos = BlockPos::new(lx, ly, lz); - let block = world.get_block(&pos).await; + let block = world.get_block(&pos); if !block.has_tag(&pumpkin_data::tag::Block::MINECRAFT_BEACON_BASE_BLOCKS) { is_ok = false; break; @@ -245,7 +245,7 @@ impl BlockEntity for BeaconBlockEntity { Box::pin(async move { // Check properties every 80 ticks matching Java if world.get_time_of_day().await % 80 == 0 { - let levels = self.update_base(world).await; + let levels = self.update_base(world); self.levels.store(levels, Ordering::Relaxed); // TODO: Beam Section validation (scanning upward to heightmap to check for sky visibility) diff --git a/pumpkin/src/block/entities/bell.rs b/pumpkin/src/block/entities/bell.rs index adade4690..e34947914 100644 --- a/pumpkin/src/block/entities/bell.rs +++ b/pumpkin/src/block/entities/bell.rs @@ -75,15 +75,13 @@ impl BlockEntity for BellBlockEntity { && self.raiders_hear_bell() { self.resonating.store(true); - world - .play_sound_fine( - Sound::BlockBellResonate, - SoundCategory::Blocks, - &self.position.to_f64(), - 1.0, - 1.0, - ) - .await; + world.play_sound_fine( + Sound::BlockBellResonate, + SoundCategory::Blocks, + &self.position.to_f64(), + 1.0, + 1.0, + ); } if self.resonating.load() { diff --git a/pumpkin/src/block/entities/brewing_stand.rs b/pumpkin/src/block/entities/brewing_stand.rs index f5b9b3eff..8d8d4dc70 100644 --- a/pumpkin/src/block/entities/brewing_stand.rs +++ b/pumpkin/src/block/entities/brewing_stand.rs @@ -191,9 +191,7 @@ impl BrewingStandBlockEntity { self.position.0.y as f64 + 0.5, self.position.0.z as f64 + 0.5, ); - world - .play_sound(Sound::BlockBrewingStandBrew, SoundCategory::Blocks, &pos) - .await; + world.play_sound(Sound::BlockBrewingStandBrew, SoundCategory::Blocks, &pos); // Mark dirty to trigger update self.mark_dirty(); @@ -486,7 +484,7 @@ impl crate::block::entities::BlockEntity for BrewingStandBlockEntity { if needs_update { // Update the block state properties for the brewing stand to reflect bottle presence let world = world.clone(); - let (block, state) = world.get_block_and_state(&self.position).await; + let (block, state) = world.get_block_and_state(&self.position); // Use generated block properties helper to produce a new state id with the bits set let mut props = pumpkin_data::block_properties::BrewingStandLikeProperties::from_state_id( diff --git a/pumpkin/src/block/entities/chest_like_block_entity.rs b/pumpkin/src/block/entities/chest_like_block_entity.rs index af868b486..8c6e529d2 100644 --- a/pumpkin/src/block/entities/chest_like_block_entity.rs +++ b/pumpkin/src/block/entities/chest_like_block_entity.rs @@ -283,7 +283,7 @@ macro_rules! impl_chest_helper_methods { pumpkin_util::random::get_seed(), ); - let (block, state) = world.get_block_and_state(&self.position).await; + let (block, state) = world.get_block_and_state(&self.position); let properties = pumpkin_data::block_properties::ChestLikeProperties::from_state_id( state.id, block, ); @@ -309,15 +309,13 @@ macro_rules! impl_chest_helper_methods { } }; - world - .play_sound_fine( - sound, - pumpkin_data::sound::SoundCategory::Blocks, - &position, - 0.5, - pumpkin_util::random::RandomImpl::next_f32(&mut rng) * 0.1 + 0.9, - ) - .await; + world.play_sound_fine( + sound, + pumpkin_data::sound::SoundCategory::Blocks, + &position, + 0.5, + pumpkin_util::random::RandomImpl::next_f32(&mut rng) * 0.1 + 0.9, + ); } } }; diff --git a/pumpkin/src/block/entities/daylight_detector.rs b/pumpkin/src/block/entities/daylight_detector.rs index 2b174c296..d3c3e79c6 100644 --- a/pumpkin/src/block/entities/daylight_detector.rs +++ b/pumpkin/src/block/entities/daylight_detector.rs @@ -62,7 +62,7 @@ impl DaylightDetectorBlockEntity { pub async fn update_power(world: &Arc, block_pos: &BlockPos) { use std::f32::consts::PI; - let (block, state) = world.get_block_and_state(block_pos).await; + let (block, state) = world.get_block_and_state(block_pos); let mut props = DaylightDetectorProperties::from_state_id(state.id, block); let level = world.level.clone(); diff --git a/pumpkin/src/block/entities/ender_chest.rs b/pumpkin/src/block/entities/ender_chest.rs index 232b829c6..f9e1bdb7c 100644 --- a/pumpkin/src/block/entities/ender_chest.rs +++ b/pumpkin/src/block/entities/ender_chest.rs @@ -67,7 +67,7 @@ impl ViewerCountListener for EnderChestBlockEntity { _position: &'a BlockPos, ) -> ViewerFuture<'a, ()> { Box::pin(async move { - self.play_sound(world, Sound::BlockEnderChestOpen).await; + self.play_sound(world, Sound::BlockEnderChestOpen); }) } @@ -77,7 +77,7 @@ impl ViewerCountListener for EnderChestBlockEntity { _position: &'a BlockPos, ) -> ViewerFuture<'a, ()> { Box::pin(async move { - self.play_sound(world, Sound::BlockEnderChestClose).await; + self.play_sound(world, Sound::BlockEnderChestClose); }) } @@ -113,17 +113,15 @@ impl EnderChestBlockEntity { self.viewers.clone() } - async fn play_sound(&self, world: &Arc, sound: Sound) { + fn play_sound(&self, world: &Arc, sound: Sound) { let mut rng = Xoroshiro::from_seed(get_seed()); - world - .play_sound_fine( - sound, - SoundCategory::Blocks, - &self.position.to_centered_f64(), - 0.5, - rng.next_f32() * 0.1 + 0.9, - ) - .await; + world.play_sound_fine( + sound, + SoundCategory::Blocks, + &self.position.to_centered_f64(), + 0.5, + rng.next_f32() * 0.1 + 0.9, + ); } } diff --git a/pumpkin/src/block/entities/furnace_like_block_entity.rs b/pumpkin/src/block/entities/furnace_like_block_entity.rs index 8f66fe065..79183f4c7 100644 --- a/pumpkin/src/block/entities/furnace_like_block_entity.rs +++ b/pumpkin/src/block/entities/furnace_like_block_entity.rs @@ -457,7 +457,7 @@ macro_rules! impl_block_entity_for_cooking { let world = world.clone(); let (furnace_block, furnace_block_state) = - world.get_block_and_state(&self.position).await; + world.get_block_and_state(&self.position); let mut props = pumpkin_data::block_properties::FurnaceLikeProperties::from_state_id( furnace_block_state.id, diff --git a/pumpkin/src/block/entities/hopper.rs b/pumpkin/src/block/entities/hopper.rs index 08ebf2de2..7a02a5d3e 100644 --- a/pumpkin/src/block/entities/hopper.rs +++ b/pumpkin/src/block/entities/hopper.rs @@ -79,7 +79,7 @@ impl BlockEntity for HopperBlockEntity { if self.cooldown_time.fetch_sub(1, Ordering::Relaxed) <= 0 { self.cooldown_time.store(0, Ordering::Relaxed); let state = HopperLikeProperties::from_state_id( - world.get_block_state(&self.position).await.id, + world.get_block_state(&self.position).id, &Block::HOPPER, ); self.try_move_items(&state, world).await; @@ -162,7 +162,7 @@ impl HopperBlockEntity { async fn suck_in_items(&self, world: &Arc) -> bool { // TODO getEntityContainer let pos_up = &self.position.up(); - if let Some(entity) = world.get_block_entity(pos_up).await + if let Some(entity) = world.get_block_entity(pos_up) && let Some(container) = entity.clone().get_inventory() { // TODO check WorldlyContainer @@ -193,7 +193,7 @@ impl HopperBlockEntity { } return false; } - let (block, state) = world.get_block_and_state(pos_up).await; + let (block, state) = world.get_block_and_state(pos_up); if !(state.is_solid() && block.has_tag(&tag::Block::MINECRAFT_DOES_NOT_BLOCK_HOPPERS)) { // TODO getItemsAtAndAbove(level, hopper) return false; @@ -204,9 +204,7 @@ impl HopperBlockEntity { async fn eject_items(&self, world: &Arc) -> bool { // TODO getEntityContainer - if let Some(entity) = world - .get_block_entity(&self.position.offset(to_offset(&self.facing))) - .await + if let Some(entity) = world.get_block_entity(&self.position.offset(to_offset(&self.facing))) && let Some(container) = entity.get_inventory() { // TODO check WorldlyContainer diff --git a/pumpkin/src/block/entities/mob_spawner.rs b/pumpkin/src/block/entities/mob_spawner.rs index 13626a069..8294c1c35 100644 --- a/pumpkin/src/block/entities/mob_spawner.rs +++ b/pumpkin/src/block/entities/mob_spawner.rs @@ -122,19 +122,16 @@ impl BlockEntity for MobSpawnerBlockEntity { + 0.5, ); // TODO: we should use getSpawnBox, but this is only modified for slimes and magma slimes - if !world - .is_space_empty(BoundingBox::new_from_pos( - spawn_pos.x, - spawn_pos.y, - spawn_pos.z, - &EntityDimensions { - width: entity_type.dimension[0], - height: entity_type.dimension[1], - eye_height: entity_type.eye_height, - }, - )) - .await - { + if !world.is_space_empty(BoundingBox::new_from_pos( + spawn_pos.x, + spawn_pos.y, + spawn_pos.z, + &EntityDimensions { + width: entity_type.dimension[0], + height: entity_type.dimension[1], + eye_height: entity_type.eye_height, + }, + )) { continue; } let entity = crate::entity::r#type::from_type( @@ -142,12 +139,9 @@ impl BlockEntity for MobSpawnerBlockEntity { spawn_pos, world, uuid::Uuid::new_v4(), - ) - .await; + ); world.spawn_entity(entity).await; - world - .sync_world_event(WorldEvent::ParticlesMobblockSpawn, self.position, 0) - .await; + world.sync_world_event(WorldEvent::ParticlesMobblockSpawn, self.position, 0); update_spawns = true; } if update_spawns { diff --git a/pumpkin/src/block/entities/piston.rs b/pumpkin/src/block/entities/piston.rs index 693c58071..356c75ded 100644 --- a/pumpkin/src/block/entities/piston.rs +++ b/pumpkin/src/block/entities/piston.rs @@ -26,7 +26,7 @@ impl PistonBlockEntity { if self.last_progress.load() < 1.0 { let pos = self.position; world.remove_block_entity(&pos).await; - if world.get_block(&pos).await == &Block::MOVING_PISTON { + if world.get_block(&pos) == &Block::MOVING_PISTON { let state = if self.source { Block::AIR.default_state.id } else { @@ -68,7 +68,7 @@ impl BlockEntity for PistonBlockEntity { if current_progress >= 1.0 { let pos = self.position; world.remove_block_entity(&pos).await; - if world.get_block(&pos).await == &Block::MOVING_PISTON { + if world.get_block(&pos) == &Block::MOVING_PISTON { if self.pushed_block_state.is_air() { world .clone() diff --git a/pumpkin/src/block/entities/shulker_box.rs b/pumpkin/src/block/entities/shulker_box.rs index b7fbf3883..90df0ae2a 100644 --- a/pumpkin/src/block/entities/shulker_box.rs +++ b/pumpkin/src/block/entities/shulker_box.rs @@ -110,8 +110,7 @@ impl ViewerCountListener for ShulkerBoxBlockEntity { position: &'a BlockPos, ) -> ViewerFuture<'a, ()> { Box::pin(async move { - self.play_sound(world, position, Sound::BlockShulkerBoxOpen) - .await; + Self::play_sound(world, position, Sound::BlockShulkerBoxOpen); // TODO: this.world.emitGameEvent(player, GameEvent.CONTAINER_OPEN, this.pos); }) } @@ -122,8 +121,7 @@ impl ViewerCountListener for ShulkerBoxBlockEntity { position: &'a BlockPos, ) -> ViewerFuture<'a, ()> { Box::pin(async move { - self.play_sound(world, position, Sound::BlockShulkerBoxClose) - .await; + Self::play_sound(world, position, Sound::BlockShulkerBoxClose); // TODO: this.world.emitGameEvent(player, GameEvent.CONTAINER_CLOSE, this.pos); }) } @@ -158,18 +156,16 @@ impl ShulkerBoxBlockEntity { } } - async fn play_sound(&self, world: &Arc, position: &BlockPos, sound: Sound) { + fn play_sound(world: &Arc, position: &BlockPos, sound: Sound) { let mut rng = Xoroshiro::from_seed(get_seed()); - world - .play_sound_fine( - sound, - SoundCategory::Blocks, - &position.to_centered_f64(), - 0.5, - rng.next_f32() * 0.1 + 0.9, - ) - .await; + world.play_sound_fine( + sound, + SoundCategory::Blocks, + &position.to_centered_f64(), + 0.5, + rng.next_f32() * 0.1 + 0.9, + ); } } diff --git a/pumpkin/src/block/fluid/flowing_trait.rs b/pumpkin/src/block/fluid/flowing_trait.rs index be3f62372..095dd09fc 100644 --- a/pumpkin/src/block/fluid/flowing_trait.rs +++ b/pumpkin/src/block/fluid/flowing_trait.rs @@ -79,8 +79,8 @@ pub trait FlowingFluid: Send + Sync { block_pos: &'a BlockPos, ) -> impl std::future::Future + Send + 'a { async move { - //let block = world.get_block(block_pos).await; - let current_block_state_id = world.get_block_state_id(block_pos).await; + //let block = world.get_block(block_pos); + let current_block_state_id = world.get_block_state_id(block_pos); let block = Block::from_state_id(current_block_state_id); if !self.has_fluid_at(fluid, current_block_state_id) { @@ -160,7 +160,7 @@ pub trait FlowingFluid: Send + Sync { ) -> impl std::future::Future + Send + 'a { async move { let below_pos = block_pos.down(); - let below_state = world.get_block_state(&below_pos).await; + let below_state = world.get_block_state(&below_pos); let below_block = Block::from_state_id(below_state.id); let is_hole = physics::can_be_replaced(below_state, below_block, fluid); @@ -200,7 +200,7 @@ pub trait FlowingFluid: Send + Sync { BlockDirection::East, ] { let neighbor_pos = block_pos.offset(direction.to_offset()); - let neighbor_id = world.get_block_state_id(&neighbor_pos).await; + let neighbor_id = world.get_block_state_id(&neighbor_pos); if self .get_effective_props(fluid, neighbor_id) .is_some_and(|p| p.level == Level::L8 && p.falling == Falling::False) @@ -229,7 +229,7 @@ pub trait FlowingFluid: Send + Sync { block_pos: &'a BlockPos, ) -> impl std::future::Future> + Send + 'a { async move { - let current_state_id = world.get_block_state_id(block_pos).await; + let current_state_id = world.get_block_state_id(block_pos); let current_props = FlowingFluidProperties::from_state_id(current_state_id, fluid); // Sources never change @@ -247,7 +247,7 @@ pub trait FlowingFluid: Send + Sync { BlockDirection::East, ] { let neighbor_pos = block_pos.offset(direction.to_offset()); - let neighbor_state_id = world.get_block_state_id(&neighbor_pos).await; + let neighbor_state_id = world.get_block_state_id(&neighbor_pos); let Some(neighbor_props) = self.get_effective_props(fluid, neighbor_state_id) else { continue; @@ -271,7 +271,7 @@ pub trait FlowingFluid: Send + Sync { // Attempt infinite source formation first if self.can_convert_to_source(world) && neighbor_source_count >= 2 { let below_pos = block_pos.down(); - let below_state = world.get_block_state(&below_pos).await; + let below_state = world.get_block_state(&below_pos); let below_state_id = below_state.id; // Check if block below is a stable source of the same fluid @@ -288,7 +288,7 @@ pub trait FlowingFluid: Send + Sync { // Then: if there's water above, this block is ALWAYS level 8, falling=true let above_pos = block_pos.up(); - let above_state_id = world.get_block_state_id(&above_pos).await; + let above_state_id = world.get_block_state_id(&above_pos); if self.has_fluid_at(fluid, above_state_id) { return Some(self.get_flowing(fluid, Level::L8, true)); @@ -324,7 +324,7 @@ pub trait FlowingFluid: Send + Sync { new_props: FlowingFluidProperties, ) -> impl std::future::Future + Send + 'a { async move { - let current_state_id = world.get_block_state_id(pos).await; + let current_state_id = world.get_block_state_id(pos); if let Some(current_props) = self.get_effective_props(fluid, current_state_id) { let current_level = i32::from(current_props.level.to_index()) + 1; let new_level = i32::from(new_props.level.to_index()) + 1; @@ -367,7 +367,7 @@ pub trait FlowingFluid: Send + Sync { } } else { // Replace non-fluid blocks - let block = world.get_block(pos).await; + let block = world.get_block(pos); if block.id != Block::AIR.id { world.break_block(pos, None, BlockFlags::NOTIFY_ALL).await; } @@ -431,7 +431,7 @@ pub trait FlowingFluid: Send + Sync { BlockDirection::East, ] { let neighbor_pos = pos.offset(direction.to_offset()); - let neighbor_state_id = world.get_block_state_id(&neighbor_pos).await; + let neighbor_state_id = world.get_block_state_id(&neighbor_pos); if self .get_effective_props(fluid, neighbor_state_id) @@ -448,7 +448,7 @@ pub trait FlowingFluid: Send + Sync { // Check the block below let below_pos = pos.down(); - let below_state = world.get_block_state(&below_pos).await; + let below_state = world.get_block_state(&below_pos); let below_state_id = below_state.id; // Check if block below is a stable source of the same fluid diff --git a/pumpkin/src/block/fluid/lava.rs b/pumpkin/src/block/fluid/lava.rs index 66513f8ac..58477f7ee 100644 --- a/pumpkin/src/block/fluid/lava.rs +++ b/pumpkin/src/block/fluid/lava.rs @@ -86,9 +86,7 @@ impl FlowingLava { return; } - let fire_state_id = FireBlock - .get_state_for_position(world.as_ref(), &Block::FIRE, pos) - .await; + let fire_state_id = FireBlock.get_state_for_position(world.as_ref(), &Block::FIRE, pos); world .set_block_state(pos, fire_state_id, BlockFlags::NOTIFY_ALL) .await; @@ -102,13 +100,12 @@ impl FlowingLava { // Logic to determine if we should replace the fluid with any of (cobble, obsidian, stone, etc.) let below_is_soul_soil = world .get_block(&block_pos.offset(BlockDirection::Down.to_offset())) - .await == &Block::SOUL_SOIL; - let is_still = world.get_block_state_id(block_pos).await == Block::LAVA.default_state.id; + let is_still = world.get_block_state_id(block_pos) == Block::LAVA.default_state.id; for dir in BlockDirection::all() { let neighbor_pos = block_pos.offset(dir.to_offset()); - if world.get_block(&neighbor_pos).await == &Block::WATER { + if world.get_block(&neighbor_pos) == &Block::WATER { if dir == BlockDirection::Down { return true; } @@ -124,12 +121,10 @@ impl FlowingLava { BlockFlags::NOTIFY_NEIGHBORS, ) .await; - world - .sync_world_event(WorldEvent::LavaFizz, *block_pos, 0) - .await; + world.sync_world_event(WorldEvent::LavaFizz, *block_pos, 0); return false; } - if below_is_soul_soil && world.get_block(&neighbor_pos).await == &Block::BLUE_ICE { + if below_is_soul_soil && world.get_block(&neighbor_pos) == &Block::BLUE_ICE { world .set_block_state( block_pos, @@ -137,9 +132,7 @@ impl FlowingLava { BlockFlags::NOTIFY_NEIGHBORS, ) .await; - world - .sync_world_event(WorldEvent::LavaFizz, *block_pos, 0) - .await; + world.sync_world_event(WorldEvent::LavaFizz, *block_pos, 0); return false; } } @@ -326,7 +319,7 @@ impl FlowingFluid for FlowingLava { state_id: BlockStateId, ) { let new_props = FlowingFluidProperties::from_state_id(state_id, fluid); - let current_state_id = world.get_block_state_id(pos).await; + let current_state_id = world.get_block_state_id(pos); let block = Block::from_state_id(current_state_id); if new_props.level == Level::L8 && new_props.falling == Falling::True { @@ -335,7 +328,7 @@ impl FlowingFluid for FlowingLava { world .set_block_state(pos, Block::STONE.default_state.id, BlockFlags::NOTIFY_ALL) .await; - world.sync_world_event(WorldEvent::LavaFizz, *pos, 0).await; + world.sync_world_event(WorldEvent::LavaFizz, *pos, 0); return; } } diff --git a/pumpkin/src/block/fluid/pathfinder.rs b/pumpkin/src/block/fluid/pathfinder.rs index 4d205b615..4b554f010 100644 --- a/pumpkin/src/block/fluid/pathfinder.rs +++ b/pumpkin/src/block/fluid/pathfinder.rs @@ -18,9 +18,9 @@ pub struct PathNode { } /// Checks if a position has a hole (downward flow opportunity) below it. -async fn is_hole(world: &Arc, fluid: &Fluid, pos: &BlockPos) -> bool { +fn is_hole(world: &Arc, fluid: &Fluid, pos: &BlockPos) -> bool { let below_pos = pos.down(); - let below_state = world.get_block_state(&below_pos).await; + let below_state = world.get_block_state(&below_pos); let below_block = Block::from_state_id(below_state.id); physics::can_be_replaced(below_state, below_block, fluid) } @@ -47,7 +47,7 @@ pub async fn get_spread( BlockDirection::East, ] { let side_pos = block_pos.offset(direction.to_offset()); - let side_state = world.get_block_state(&side_pos).await; + let side_state = world.get_block_state(&side_pos); let side_state_id = side_state.id; let side_block = Block::from_state_id(side_state.id); @@ -70,7 +70,7 @@ pub async fn get_spread( let new_state_id = new_fluid_props.to_state_id(fluid); // Holes get distance 0 - let slope_dist = if is_hole(world, fluid, &side_pos).await { + let slope_dist = if is_hole(world, fluid, &side_pos) { 0 } else { get_in_flow_down_distance_iterative( @@ -80,7 +80,6 @@ pub async fn get_spread( side_pos, direction.opposite(), ) - .await }; // Clear results if we find a shorter path @@ -116,7 +115,7 @@ pub async fn get_spread( /// /// # Returns /// Distance to nearest hole, or 1000 if no hole found within search distance -pub async fn get_in_flow_down_distance_iterative( +pub fn get_in_flow_down_distance_iterative( fluid_impl: &T, world: &Arc, fluid: &Fluid, @@ -171,7 +170,7 @@ pub async fn get_in_flow_down_distance_iterative(&'a self, _args: CanPlaceAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { true }) + fn can_place_at(&self, _args: CanPlaceAtArgs<'_>) -> bool { + true } - fn can_update_at<'a>(&'a self, _args: CanUpdateAtArgs<'a>) -> BlockFuture<'a, bool> { - Box::pin(async move { false }) + fn can_update_at(&self, _args: CanUpdateAtArgs<'_>) -> bool { + false } /// onBlockAdded in source code diff --git a/pumpkin/src/block/registry.rs b/pumpkin/src/block/registry.rs index 6c0a539f3..b54d73ff2 100644 --- a/pumpkin/src/block/registry.rs +++ b/pumpkin/src/block/registry.rs @@ -553,7 +553,7 @@ impl BlockRegistry { } #[expect(clippy::too_many_arguments)] - pub async fn can_place_at( + pub fn can_place_at( &self, server: Option<&Server>, world: Option<&World>, @@ -567,25 +567,23 @@ impl BlockRegistry { ) -> bool { let pumpkin_block = self.get_pumpkin_block(block.id); if let Some(pumpkin_block) = pumpkin_block { - return pumpkin_block - .can_place_at(CanPlaceAtArgs { - server, - world, - block_accessor, - block, - state, - position, - direction, - player, - use_item_on, - }) - .await; + return pumpkin_block.can_place_at(CanPlaceAtArgs { + server, + world, + block_accessor, + block, + state, + position, + direction, + player, + use_item_on, + }); } true } #[expect(clippy::too_many_arguments)] - pub async fn can_update_at( + pub fn can_update_at( &self, world: &World, block: &Block, @@ -597,17 +595,15 @@ impl BlockRegistry { ) -> bool { let pumpkin_block = self.get_pumpkin_block(block.id); if let Some(pumpkin_block) = pumpkin_block { - return pumpkin_block - .can_update_at(CanUpdateAtArgs { - world, - block, - state_id, - position, - direction, - player, - use_item_on, - }) - .await; + return pumpkin_block.can_update_at(CanUpdateAtArgs { + world, + block, + state_id, + position, + direction, + player, + use_item_on, + }); } false } @@ -796,10 +792,10 @@ impl BlockRegistry { block: &Block, flags: BlockFlags, ) { - let state_id = world.get_block_state_id(position).await; + let state_id = world.get_block_state_id(position); for direction in BlockDirection::all() { let neighbor_pos = position.offset(direction.to_offset()); - let neighbor_state_id = world.get_block_state_id(&neighbor_pos).await; + let neighbor_state_id = world.get_block_state_id(&neighbor_pos); let pumpkin_block = self.get_pumpkin_block(block.id); if let Some(pumpkin_block) = pumpkin_block { let new_state = pumpkin_block diff --git a/pumpkin/src/command/commands/difficulty.rs b/pumpkin/src/command/commands/difficulty.rs index d7fd30834..5e250020a 100644 --- a/pumpkin/src/command/commands/difficulty.rs +++ b/pumpkin/src/command/commands/difficulty.rs @@ -59,7 +59,7 @@ impl CommandExecutor for DifficultySetExecutor { } } - server.set_difficulty(difficulty, true).await; + server.set_difficulty(difficulty, true); context .source diff --git a/pumpkin/src/command/commands/fill.rs b/pumpkin/src/command/commands/fill.rs index 213c04f6e..3454012e5 100644 --- a/pumpkin/src/command/commands/fill.rs +++ b/pumpkin/src/command/commands/fill.rs @@ -116,7 +116,7 @@ struct DestroyFiller; impl Filler for DestroyFiller { async fn execute_for_pos(context: &Context, block_position: BlockPos) -> FillerResult { if let Some(filter) = &context.option_filter - && not_in_filter(filter, context.world.get_block(&block_position).await) + && not_in_filter(filter, context.world.get_block(&block_position)) { return FillerResult::DidNotPlaceBlock; } @@ -144,7 +144,7 @@ struct HollowFiller; impl Filler for HollowFiller { async fn execute_for_pos(context: &Context, block_position: BlockPos) -> FillerResult { if let Some(filter) = &context.option_filter - && not_in_filter(filter, context.world.get_block(&block_position).await) + && not_in_filter(filter, context.world.get_block(&block_position)) { return FillerResult::DidNotPlaceBlock; } @@ -170,7 +170,7 @@ impl Filler for HollowFiller { struct KeepFiller; impl Filler for KeepFiller { async fn execute_for_pos(context: &Context, block_position: BlockPos) -> FillerResult { - let (old_block, old_state) = context.world.get_block_and_state(&block_position).await; + let (old_block, old_state) = context.world.get_block_and_state(&block_position); if old_state.is_air() { if let Some(filter) = &context.option_filter && not_in_filter(filter, old_block) @@ -199,7 +199,7 @@ impl Filler for OutlineFiller { return FillerResult::DidNotPlaceBlock; } if let Some(filter) = &context.option_filter - && not_in_filter(filter, context.world.get_block(&block_position).await) + && not_in_filter(filter, context.world.get_block(&block_position)) { return FillerResult::DidNotPlaceBlock; } @@ -219,7 +219,7 @@ struct ReplaceFiller; impl Filler for ReplaceFiller { async fn execute_for_pos(context: &Context, block_position: BlockPos) -> FillerResult { if let Some(filter) = &context.option_filter - && not_in_filter(filter, context.world.get_block(&block_position).await) + && not_in_filter(filter, context.world.get_block(&block_position)) { return FillerResult::DidNotPlaceBlock; } @@ -239,7 +239,7 @@ struct StrictFiller; impl Filler for StrictFiller { async fn execute_for_pos(context: &Context, block_position: BlockPos) -> FillerResult { if let Some(filter) = &context.option_filter - && not_in_filter(filter, context.world.get_block(&block_position).await) + && not_in_filter(filter, context.world.get_block(&block_position)) { return FillerResult::DidNotPlaceBlock; } diff --git a/pumpkin/src/command/commands/particle.rs b/pumpkin/src/command/commands/particle.rs index 129f2912d..6da4e0b3e 100644 --- a/pumpkin/src/command/commands/particle.rs +++ b/pumpkin/src/command/commands/particle.rs @@ -69,9 +69,7 @@ impl CommandExecutor for Executor { } }; - world - .spawn_particle(pos, delta, speed, count, *particle) - .await; + world.spawn_particle(pos, delta, speed, count, *particle); sender .send_message(TextComponent::translate_cross( diff --git a/pumpkin/src/command/commands/setblock.rs b/pumpkin/src/command/commands/setblock.rs index cfcc161bf..96222559b 100644 --- a/pumpkin/src/command/commands/setblock.rs +++ b/pumpkin/src/command/commands/setblock.rs @@ -83,7 +83,7 @@ impl CommandExecutor for Executor { true } Mode::Keep => { - let old_state = world.get_block_state(&pos).await; + let old_state = world.get_block_state(&pos); if old_state.is_air() { world .set_block_state( diff --git a/pumpkin/src/command/commands/summon.rs b/pumpkin/src/command/commands/summon.rs index cf6a871c5..1592ecb6d 100644 --- a/pumpkin/src/command/commands/summon.rs +++ b/pumpkin/src/command/commands/summon.rs @@ -64,7 +64,7 @@ impl CommandExecutor for Executor { (w.clone(), pos) } }; - let entity = from_type(entity_type, pos, &world, Uuid::new_v4()).await; + let entity = from_type(entity_type, pos, &world, Uuid::new_v4()); let name = entity.get_display_name().await; world.spawn_entity(entity).await; sender diff --git a/pumpkin/src/command/commands/tick.rs b/pumpkin/src/command/commands/tick.rs index ae0a31a87..807bbba88 100644 --- a/pumpkin/src/command/commands/tick.rs +++ b/pumpkin/src/command/commands/tick.rs @@ -171,7 +171,7 @@ impl TickExecutor { manager: &crate::server::tick_rate_manager::ServerTickRateManager, ticks: i32, ) { - if manager.step_game_if_paused(source.server(), ticks).await { + if manager.step_game_if_paused(source.server(), ticks) { source .send_feedback( TextComponent::translate_cross( @@ -201,10 +201,7 @@ impl TickExecutor { manager: &crate::server::tick_rate_manager::ServerTickRateManager, ticks: i32, ) { - if manager - .request_game_to_sprint(source.server(), i64::from(ticks)) - .await - { + if manager.request_game_to_sprint(source.server(), i64::from(ticks)) { source .send_feedback( TextComponent::translate_cross( @@ -233,7 +230,7 @@ impl TickExecutor { manager: &crate::server::tick_rate_manager::ServerTickRateManager, rate: f32, ) -> Result { - manager.set_tick_rate(source.server(), rate).await; + manager.set_tick_rate(source.server(), rate); source .send_feedback( TextComponent::translate_cross( @@ -261,7 +258,7 @@ impl CommandExecutor for TickExecutor { Self::handle_set_tick_rate(source, manager, rate).await } SubCommand::Freeze(freeze) => { - manager.set_frozen(server, freeze).await; + manager.set_frozen(server, freeze); let message_key = if freeze { "commands.tick.status.frozen" } else { @@ -282,7 +279,7 @@ impl CommandExecutor for TickExecutor { Ok(1) } SubCommand::StepStop => { - if manager.stop_stepping(server).await { + if manager.stop_stepping(server) { source .send_feedback( TextComponent::translate_cross( @@ -315,7 +312,7 @@ impl CommandExecutor for TickExecutor { Ok(1) } SubCommand::SprintStop => { - if manager.stop_sprinting(server).await { + if manager.stop_sprinting(server) { source .send_feedback( TextComponent::translate_cross( diff --git a/pumpkin/src/command/commands/weather.rs b/pumpkin/src/command/commands/weather.rs index fd740e98e..025102ab4 100644 --- a/pumpkin/src/command/commands/weather.rs +++ b/pumpkin/src/command/commands/weather.rs @@ -48,9 +48,7 @@ impl CommandExecutor for Executor { let processed_duration = duration.unwrap_or_else(|| rand::random_range(12_000..=180_000)); - weather - .set_weather_parameters(&world, processed_duration, 0, false, false) - .await; + weather.set_weather_parameters(&world, processed_duration, 0, false, false); sender .send_message(TextComponent::translate_cross( translation::java::COMMANDS_WEATHER_SET_CLEAR, @@ -63,9 +61,7 @@ impl CommandExecutor for Executor { let processed_duration = duration.unwrap_or_else(|| rand::random_range(12_000..=24_000)); - weather - .set_weather_parameters(&world, 0, processed_duration, true, false) - .await; + weather.set_weather_parameters(&world, 0, processed_duration, true, false); sender .send_message(TextComponent::translate_cross( translation::java::COMMANDS_WEATHER_SET_RAIN, @@ -78,9 +74,7 @@ impl CommandExecutor for Executor { let processed_duration = duration.unwrap_or_else(|| rand::random_range(3_600..=15_600)); - weather - .set_weather_parameters(&world, 0, processed_duration, true, true) - .await; + weather.set_weather_parameters(&world, 0, processed_duration, true, true); sender .send_message(TextComponent::translate_cross( translation::java::COMMANDS_WEATHER_SET_THUNDER, diff --git a/pumpkin/src/command/commands/worldborder.rs b/pumpkin/src/command/commands/worldborder.rs index 925de6d57..c05f056b5 100644 --- a/pumpkin/src/command/commands/worldborder.rs +++ b/pumpkin/src/command/commands/worldborder.rs @@ -112,7 +112,7 @@ impl CommandExecutor for SetExecutor { .await; let d = border.new_diameter; - border.set_diameter(world, distance, None).await; + border.set_diameter(world, distance, None); Ok((distance - d) as i32) }) @@ -186,9 +186,7 @@ impl CommandExecutor for SetTimeExecutor { } let d = border.new_diameter; - border - .set_diameter(world, distance, Some(i64::from(time) * 1000)) - .await; + border.set_diameter(world, distance, Some(i64::from(time) * 1000)); Ok((distance - d) as i32) }) @@ -237,7 +235,7 @@ impl CommandExecutor for AddExecutor { [TextComponent::text(dist)], )) .await; - border.set_diameter(world, distance, None).await; + border.set_diameter(world, distance, None); Ok(distance_add as i32) }) } @@ -310,9 +308,7 @@ impl CommandExecutor for AddTimeExecutor { } } - border - .set_diameter(world, distance, Some(i64::from(time) * 1000)) - .await; + border.set_diameter(world, distance, Some(i64::from(time) * 1000)); Ok(distance_add as i32) }) @@ -348,7 +344,7 @@ impl CommandExecutor for CenterExecutor { ], )) .await; - border.set_center(world, x, y).await; + border.set_center(world, x, y); Ok(0) }) } @@ -486,7 +482,7 @@ impl CommandExecutor for WarningDistanceExecutor { [TextComponent::text(distance.to_string())], )) .await; - border.set_warning_distance(world, distance).await; + border.set_warning_distance(world, distance); Ok(distance) }) } @@ -531,7 +527,7 @@ impl CommandExecutor for WarningTimeExecutor { [TextComponent::text(time.to_string())], )) .await; - border.set_warning_delay(world, time).await; + border.set_warning_delay(world, time); Ok(time) }) } diff --git a/pumpkin/src/command/mod.rs b/pumpkin/src/command/mod.rs index 4f61f3cd5..300a0d514 100644 --- a/pumpkin/src/command/mod.rs +++ b/pumpkin/src/command/mod.rs @@ -302,7 +302,7 @@ impl CommandSender { Self::CommandBlock(command_entity, world) => { let pos = command_entity.position; - let (block, state_id) = world.get_block_and_state_id(&pos).await; + let (block, state_id) = world.get_block_and_state_id(&pos); let command_block_props = CommandBlockLikeProperties::from_state_id(state_id, block); let facing = command_block_props.facing; diff --git a/pumpkin/src/entity/ai/goal/avoid_entity.rs b/pumpkin/src/entity/ai/goal/avoid_entity.rs index 194ead042..13f79511c 100644 --- a/pumpkin/src/entity/ai/goal/avoid_entity.rs +++ b/pumpkin/src/entity/ai/goal/avoid_entity.rs @@ -55,7 +55,7 @@ impl AvoidEntityGoal { /// Generates a random walkable position within a cone pointing away from the threat. /// Mirrors vanilla's `NoPenaltyTargeting.findFrom()`. - async fn find_flee_position(mob: &dyn Mob, threat_pos: &Vector3) -> Option> { + fn find_flee_position(mob: &dyn Mob, threat_pos: &Vector3) -> Option> { let entity = &mob.get_mob_entity().living_entity.entity; let mob_pos = entity.pos.load(); let world = entity.world.load(); @@ -98,14 +98,12 @@ impl AvoidEntityGoal { (mob_pos.z + dz) as i32, ); - let block_at = world.get_block_state(&candidate).await; - let block_below = world - .get_block_state(&BlockPos::new( - candidate.0.x, - candidate.0.y - 1, - candidate.0.z, - )) - .await; + let block_at = world.get_block_state(&candidate); + let block_below = world.get_block_state(&BlockPos::new( + candidate.0.x, + candidate.0.y - 1, + candidate.0.z, + )); if block_at.is_solid() || !block_below.is_solid() { continue; @@ -137,7 +135,7 @@ impl Goal for AvoidEntityGoal { }; let threat_pos = target.get_entity().pos.load(); - let flee_pos = Self::find_flee_position(mob, &threat_pos).await; + let flee_pos = Self::find_flee_position(mob, &threat_pos); let Some(pos) = flee_pos else { return false; }; @@ -150,7 +148,7 @@ impl Goal for AvoidEntityGoal { fn should_continue<'a>(&'a self, mob: &'a dyn Mob) -> GoalFuture<'a, bool> { Box::pin(async move { - let navigator = mob.get_mob_entity().navigator.lock().await; + let navigator = mob.get_mob_entity().navigator.lock().unwrap(); !navigator.is_idle() }) } @@ -159,7 +157,7 @@ impl Goal for AvoidEntityGoal { Box::pin(async move { if let Some(flee_pos) = self.flee_pos { let mob_pos = mob.get_mob_entity().living_entity.entity.pos.load(); - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.set_progress(NavigatorGoal::new(mob_pos, flee_pos, self.slow_speed)); } }) @@ -176,7 +174,7 @@ impl Goal for AvoidEntityGoal { } else { self.slow_speed }; - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.set_speed(speed); } }) diff --git a/pumpkin/src/entity/ai/goal/beg.rs b/pumpkin/src/entity/ai/goal/beg.rs index 671314d6b..776247be1 100644 --- a/pumpkin/src/entity/ai/goal/beg.rs +++ b/pumpkin/src/entity/ai/goal/beg.rs @@ -49,7 +49,7 @@ impl BegGoal { mob_pos.squared_distance_to_vec(&player_pos) } - async fn set_begging(mob: &dyn Mob, begging: bool) { + fn set_begging(mob: &dyn Mob, begging: bool) { mob.get_mob_entity() .living_entity .entity @@ -57,8 +57,7 @@ impl BegGoal { TrackedData::INTERESTED_ID, MetaDataType::BOOLEAN, begging, - )]) - .await; + )]); } } @@ -103,7 +102,7 @@ impl Goal for BegGoal { fn start<'a>(&'a mut self, mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async { - Self::set_begging(mob, true).await; + Self::set_begging(mob, true); let ticks = 40 + mob.get_random().random_range(0..40); self.timer = self.get_tick_count(ticks); }) @@ -111,7 +110,7 @@ impl Goal for BegGoal { fn stop<'a>(&'a mut self, mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async { - Self::set_begging(mob, false).await; + Self::set_begging(mob, false); self.target = None; }) } @@ -120,7 +119,7 @@ impl Goal for BegGoal { Box::pin(async { if let Some(player) = &self.target { let player_pos = player.living_entity.entity.get_eye_pos(); - let mut look_control = mob.get_mob_entity().look_control.lock().await; + let mut look_control = mob.get_mob_entity().look_control.lock().unwrap(); look_control.look_at_with_range( player_pos.x, player_pos.y, diff --git a/pumpkin/src/entity/ai/goal/blaze_attack.rs b/pumpkin/src/entity/ai/goal/blaze_attack.rs index dba54c5c1..2614340cc 100644 --- a/pumpkin/src/entity/ai/goal/blaze_attack.rs +++ b/pumpkin/src/entity/ai/goal/blaze_attack.rs @@ -161,8 +161,7 @@ impl Goal for BlazeShootFireballGoal { blaze.entity.living_entity.entity.block_pos.load(), 0, false, - )) - .await; + )); for _ in 0..1 { // Vanilla loops 1 time @@ -206,7 +205,7 @@ impl Goal for BlazeShootFireballGoal { .entity .look_control .lock() - .await + .unwrap() .look_at_entity(&*blaze, &target); } else if self.last_seen < 5 { // TODO: set wanted position to target diff --git a/pumpkin/src/entity/ai/goal/breed.rs b/pumpkin/src/entity/ai/goal/breed.rs index 738aed049..8d5a93b7f 100644 --- a/pumpkin/src/entity/ai/goal/breed.rs +++ b/pumpkin/src/entity/ai/goal/breed.rs @@ -74,7 +74,7 @@ impl BreedGoal { mate.set_breeding_cooldown(6000); let parent_pos = entity.pos.load(); - let baby = from_type(entity.entity_type, parent_pos, &world, Uuid::new_v4()).await; + let baby = from_type(entity.entity_type, parent_pos, &world, Uuid::new_v4()); baby.get_entity().set_age(-24000); world.spawn_entity(baby).await; } @@ -117,7 +117,7 @@ impl Goal for BreedGoal { Box::pin(async { self.mate = None; self.timer = 0; - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.stop(); }) } @@ -131,15 +131,18 @@ impl Goal for BreedGoal { let mob_entity = mob.get_mob_entity(); let mate_pos = mate.get_entity().pos.load(); - let mut look_control = mob_entity.look_control.lock().await; - look_control.look_at_entity(mob, mate); - drop(look_control); + { + let mut look_control = mob_entity.look_control.lock().unwrap(); + look_control.look_at_entity(mob, mate); + }; let my_pos = mob.get_entity().pos.load(); let dist_sq = my_pos.squared_distance_to_vec(&mate_pos); - let mut navigator = mob_entity.navigator.lock().await; - navigator.set_progress(NavigatorGoal::new(my_pos, mate_pos, self.speed)); + { + let mut navigator = mob_entity.navigator.lock().unwrap(); + navigator.set_progress(NavigatorGoal::new(my_pos, mate_pos, self.speed)); + }; self.timer += 1; diff --git a/pumpkin/src/entity/ai/goal/chase_player.rs b/pumpkin/src/entity/ai/goal/chase_player.rs index cc1c2fee7..f007b5631 100644 --- a/pumpkin/src/entity/ai/goal/chase_player.rs +++ b/pumpkin/src/entity/ai/goal/chase_player.rs @@ -83,7 +83,7 @@ impl Goal for ChasePlayerGoal { fn start<'a>(&'a mut self, mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async move { - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.stop(); }) } @@ -93,7 +93,7 @@ impl Goal for ChasePlayerGoal { if let Some(player) = &self.target { let player_pos = player.get_entity().pos.load(); let eye_y = player_pos.y + PLAYER_EYE_HEIGHT; - let mut look_control = mob.get_mob_entity().look_control.lock().await; + let mut look_control = mob.get_mob_entity().look_control.lock().unwrap(); look_control.look_at(mob, player_pos.x, eye_y, player_pos.z); } }) diff --git a/pumpkin/src/entity/ai/goal/creeper_ignite.rs b/pumpkin/src/entity/ai/goal/creeper_ignite.rs index be1fd48ef..bad0acf06 100644 --- a/pumpkin/src/entity/ai/goal/creeper_ignite.rs +++ b/pumpkin/src/entity/ai/goal/creeper_ignite.rs @@ -46,14 +46,14 @@ impl Goal for CreeperIgniteGoal { fn start<'a>(&'a mut self, mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async move { - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.stop(); }) } fn stop<'a>(&'a mut self, _mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async move { - self.creeper.set_fuse_speed(-1).await; + self.creeper.set_fuse_speed(-1); }) } @@ -62,7 +62,7 @@ impl Goal for CreeperIgniteGoal { let target_lock = mob.get_mob_entity().target.lock().await; let Some(target) = target_lock.as_ref() else { - self.creeper.set_fuse_speed(-1).await; + self.creeper.set_fuse_speed(-1); return; }; @@ -73,11 +73,11 @@ impl Goal for CreeperIgniteGoal { .squared_distance_to_vec(&target.get_entity().pos.load()); if dist_sq > 49.0 { - self.creeper.set_fuse_speed(-1).await; + self.creeper.set_fuse_speed(-1); } // TODO: line of sight check (needs world raycast) else { - self.creeper.set_fuse_speed(1).await; + self.creeper.set_fuse_speed(1); } }) } diff --git a/pumpkin/src/entity/ai/goal/destroy_egg.rs b/pumpkin/src/entity/ai/goal/destroy_egg.rs index f028fa704..758e7252f 100644 --- a/pumpkin/src/entity/ai/goal/destroy_egg.rs +++ b/pumpkin/src/entity/ai/goal/destroy_egg.rs @@ -82,15 +82,13 @@ impl Stepping for DestroyEggGoal { // NOTE: block_pos.0.to_f64() is assumed to be the correct way to get Vector3 let pos_f64 = (block_pos.0).to_f64(); - world - .play_sound_raw( - Sound::EntityZombieDestroyEgg as u16, - SoundCategory::Hostile, - &pos_f64, - 0.7, - random.mul_add(0.2, 0.9), - ) - .await; + world.play_sound_raw( + Sound::EntityZombieDestroyEgg as u16, + SoundCategory::Hostile, + &pos_f64, + 0.7, + random.mul_add(0.2, 0.9), + ); }) } @@ -101,15 +99,13 @@ impl Stepping for DestroyEggGoal { // NOTE: block_pos.0.to_f64() is assumed to be the correct way to get Vector3 let pos_f64 = (block_pos.0).to_f64(); - world - .play_sound_raw( - Sound::EntityTurtleEggBreak as u16, - SoundCategory::Blocks, - &pos_f64, - 0.7, - random.mul_add(0.2, 0.9), - ) - .await; + world.play_sound_raw( + Sound::EntityTurtleEggBreak as u16, + SoundCategory::Blocks, + &pos_f64, + 0.7, + random.mul_add(0.2, 0.9), + ); }) } } diff --git a/pumpkin/src/entity/ai/goal/eat_grass.rs b/pumpkin/src/entity/ai/goal/eat_grass.rs index 576920b1a..8bbef373c 100644 --- a/pumpkin/src/entity/ai/goal/eat_grass.rs +++ b/pumpkin/src/entity/ai/goal/eat_grass.rs @@ -39,12 +39,12 @@ impl Goal for EatGrassGoal { let block_pos = entity.block_pos.load(); let world = entity.world.load(); - let block_at_pos = world.get_block(&block_pos).await; + let block_at_pos = world.get_block(&block_pos); if block_at_pos.has_tag(&tag::Block::MINECRAFT_EDIBLE_FOR_SHEEP) { return true; } - let block_below = world.get_block(&block_pos.down()).await; + let block_below = world.get_block(&block_pos.down()); block_below.id == Block::GRASS_BLOCK.id }) } @@ -56,7 +56,7 @@ impl Goal for EatGrassGoal { fn start<'a>(&'a mut self, mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async move { self.timer = MAX_TIMER; - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.stop(); }) } @@ -70,7 +70,7 @@ impl Goal for EatGrassGoal { let block_pos = entity.block_pos.load(); let world = entity.world.load_full(); - let block_at_pos = world.get_block(&block_pos).await; + let block_at_pos = world.get_block(&block_pos); if block_at_pos.has_tag(&tag::Block::MINECRAFT_EDIBLE_FOR_SHEEP) { world .set_block_state( @@ -82,7 +82,7 @@ impl Goal for EatGrassGoal { mob.on_eating_grass().await; } else { let below_pos = block_pos.down(); - let block_below = world.get_block(&below_pos).await; + let block_below = world.get_block(&below_pos); if block_below.id == Block::GRASS_BLOCK.id { world .set_block_state( diff --git a/pumpkin/src/entity/ai/goal/escape_danger.rs b/pumpkin/src/entity/ai/goal/escape_danger.rs index 0b86a9a90..d20eaf12b 100644 --- a/pumpkin/src/entity/ai/goal/escape_danger.rs +++ b/pumpkin/src/entity/ai/goal/escape_danger.rs @@ -70,7 +70,7 @@ impl Goal for EscapeDangerGoal { fn should_continue<'a>(&'a self, mob: &'a dyn Mob) -> GoalFuture<'a, bool> { Box::pin(async move { - let navigator = mob.get_mob_entity().navigator.lock().await; + let navigator = mob.get_mob_entity().navigator.lock().unwrap(); !navigator.is_idle() }) } @@ -79,7 +79,7 @@ impl Goal for EscapeDangerGoal { Box::pin(async move { if let Some(target) = self.target { let pos = mob.get_mob_entity().living_entity.entity.pos.load(); - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.set_progress(NavigatorGoal::new(pos, target, self.speed)); } }) diff --git a/pumpkin/src/entity/ai/goal/follow_owner.rs b/pumpkin/src/entity/ai/goal/follow_owner.rs index 0f9208fa0..455cab415 100644 --- a/pumpkin/src/entity/ai/goal/follow_owner.rs +++ b/pumpkin/src/entity/ai/goal/follow_owner.rs @@ -50,7 +50,7 @@ impl FollowOwnerGoal { mob_pos.squared_distance_to_vec(&owner_pos) } - async fn try_teleport_to_owner(mob: &dyn Mob, owner: &Player) { + fn try_teleport_to_owner(mob: &dyn Mob, owner: &Player) { let owner_pos = owner.living_entity.entity.pos.load(); let mob_entity = &mob.get_mob_entity().living_entity.entity; let world = mob_entity.world.load_full(); @@ -76,33 +76,31 @@ impl FollowOwnerGoal { let target_z = owner_pos.z.floor() as i32 + dz; let below = BlockPos(Vector3::new(target_x, target_y - 1, target_z)); - let block_below = world.get_block_state(&below).await; + let block_below = world.get_block_state(&below); if !block_below.is_solid() { continue; } let at = BlockPos(Vector3::new(target_x, target_y, target_z)); let above = BlockPos(Vector3::new(target_x, target_y + 1, target_z)); - let block_at = world.get_block_state(&at).await; - let block_above = world.get_block_state(&above).await; + let block_at = world.get_block_state(&at); + let block_above = world.get_block_state(&above); if !block_at.is_air() || !block_above.is_air() { continue; } - mob_entity - .teleport( - Vector3::new( - target_x as f64 + 0.5, - target_y as f64, - target_z as f64 + 0.5, - ), - None, - None, - world.clone(), - ) - .await; + mob_entity.teleport( + Vector3::new( + target_x as f64 + 0.5, + target_y as f64, + target_z as f64 + 0.5, + ), + None, + None, + world.clone(), + ); - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.stop(); return; } @@ -149,7 +147,7 @@ impl Goal for FollowOwnerGoal { return false; } - let navigator = mob.get_mob_entity().navigator.lock().await; + let navigator = mob.get_mob_entity().navigator.lock().unwrap(); !navigator.is_idle() }) } @@ -172,7 +170,7 @@ impl Goal for FollowOwnerGoal { if !should_teleport { let mob_entity = mob.get_mob_entity(); let owner_eye_pos = owner.living_entity.entity.get_eye_pos(); - let mut look_control = mob_entity.look_control.lock().await; + let mut look_control = mob_entity.look_control.lock().unwrap(); look_control.look_at_with_range( owner_eye_pos.x, owner_eye_pos.y, @@ -188,11 +186,11 @@ impl Goal for FollowOwnerGoal { self.update_countdown = to_goal_ticks(10); if should_teleport { - Self::try_teleport_to_owner(mob, owner).await; + Self::try_teleport_to_owner(mob, owner); } else { let mob_pos = mob.get_mob_entity().living_entity.entity.pos.load(); let owner_pos = owner.living_entity.entity.pos.load(); - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.set_progress(NavigatorGoal::new(mob_pos, owner_pos, self.speed)); } } @@ -202,7 +200,7 @@ impl Goal for FollowOwnerGoal { fn stop<'a>(&'a mut self, mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async { self.owner = None; - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.stop(); }) } diff --git a/pumpkin/src/entity/ai/goal/follow_parent.rs b/pumpkin/src/entity/ai/goal/follow_parent.rs index f7d0d9b65..670c27030 100644 --- a/pumpkin/src/entity/ai/goal/follow_parent.rs +++ b/pumpkin/src/entity/ai/goal/follow_parent.rs @@ -109,7 +109,7 @@ impl Goal for FollowParentGoal { if let Some(parent) = &self.parent { let mob_pos = mob.get_mob_entity().living_entity.entity.pos.load(); let parent_pos = parent.get_entity().pos.load(); - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.set_progress(NavigatorGoal::new(mob_pos, parent_pos, self.speed)); } }) diff --git a/pumpkin/src/entity/ai/goal/look_around.rs b/pumpkin/src/entity/ai/goal/look_around.rs index 54292a46e..5cb3a850e 100644 --- a/pumpkin/src/entity/ai/goal/look_around.rs +++ b/pumpkin/src/entity/ai/goal/look_around.rs @@ -45,7 +45,7 @@ impl Goal for RandomLookAroundGoal { Box::pin(async { let mob_entity = mob.get_mob_entity(); self.look_time -= 1; - let mut look_control = mob_entity.look_control.lock().await; + let mut look_control = mob_entity.look_control.lock().unwrap(); let pos = mob_entity.living_entity.entity.pos.load(); look_control.look_at( diff --git a/pumpkin/src/entity/ai/goal/look_at_entity.rs b/pumpkin/src/entity/ai/goal/look_at_entity.rs index 0910cf3c1..79dee52d3 100644 --- a/pumpkin/src/entity/ai/goal/look_at_entity.rs +++ b/pumpkin/src/entity/ai/goal/look_at_entity.rs @@ -151,7 +151,7 @@ impl Goal for LookAtEntityGoal { } else { target_entity.get_eye_y() }; - mob_entity.look_control.lock().await.look_at( + mob_entity.look_control.lock().unwrap().look_at( mob, target_pos.x, look_y, diff --git a/pumpkin/src/entity/ai/goal/melee_attack.rs b/pumpkin/src/entity/ai/goal/melee_attack.rs index 43078a85e..68f931ecb 100644 --- a/pumpkin/src/entity/ai/goal/melee_attack.rs +++ b/pumpkin/src/entity/ai/goal/melee_attack.rs @@ -111,7 +111,7 @@ impl Goal for MeleeAttackGoal { let target = mob.get_mob_entity().target.lock().await.clone(); if let Some(target) = target { - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); let target_pos = target.get_entity().pos.load(); navigator.set_progress(NavigatorGoal { current_progress: mob.get_entity().pos.load(), @@ -143,7 +143,7 @@ impl Goal for MeleeAttackGoal { } // Vanilla: this.mob.getNavigation().stop() - mob.get_mob_entity().navigator.lock().await.stop(); + mob.get_mob_entity().navigator.lock().unwrap().stop(); self.last_target_position = None; }) } @@ -158,7 +158,7 @@ impl Goal for MeleeAttackGoal { mob.get_mob_entity() .look_control .lock() - .await + .unwrap() .look_at_entity_with_range(&target, 30.0, 30.0); self.update_countdown_ticks = (self.update_countdown_ticks - 1).max(0); @@ -172,7 +172,7 @@ impl Goal for MeleeAttackGoal { if should_update_nav { let mob_pos = mob.get_entity().pos.load(); let dist_sq = mob_pos.squared_distance_to_vec(¤t_target_pos); - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.set_progress(NavigatorGoal { current_progress: mob_pos, destination: current_target_pos, @@ -197,7 +197,7 @@ impl Goal for MeleeAttackGoal { .await { self.cooldown = self.get_max_cooldown(); - mob.get_mob_entity().living_entity.swing_hand().await; + mob.get_mob_entity().living_entity.swing_hand(); mob.get_mob_entity().try_attack(mob, target.as_ref()).await; } }) diff --git a/pumpkin/src/entity/ai/goal/move_to_target_pos.rs b/pumpkin/src/entity/ai/goal/move_to_target_pos.rs index 38995d67b..64d8fa58d 100644 --- a/pumpkin/src/entity/ai/goal/move_to_target_pos.rs +++ b/pumpkin/src/entity/ai/goal/move_to_target_pos.rs @@ -185,7 +185,7 @@ impl Goal for MoveToTargetPosGoal { self.reached = false; self.trying_time += 1; if self.should_reset_path() { - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.set_progress(NavigatorGoal { current_progress: mob.get_entity().pos.load(), diff --git a/pumpkin/src/entity/ai/goal/pick_up_block.rs b/pumpkin/src/entity/ai/goal/pick_up_block.rs index 63a65d999..7df6b7cf7 100644 --- a/pumpkin/src/entity/ai/goal/pick_up_block.rs +++ b/pumpkin/src/entity/ai/goal/pick_up_block.rs @@ -56,7 +56,7 @@ impl Goal for PickUpBlockGoal { let world = entity.world.load(); let target_pos = BlockPos::new(bx, by, bz); - let block = world.get_block(&target_pos).await; + let block = world.get_block(&target_pos); if !block.has_tag(&tag::Block::MINECRAFT_ENDERMAN_HOLDABLE) { return; @@ -71,7 +71,7 @@ impl Goal for PickUpBlockGoal { let block_center = Vector3::new(bx as f64 + 0.5, by as f64 + 0.5, bz as f64 + 0.5); if let Some((hit_pos, _)) = world .raycast(enderman_center, block_center, async |block_pos, w| { - let state = w.get_block_state(block_pos).await; + let state = w.get_block_state(block_pos); state.is_solid() }) .await @@ -86,9 +86,7 @@ impl Goal for PickUpBlockGoal { world .set_block_state(&target_pos, 0, BlockFlags::NOTIFY_ALL) .await; - self.enderman - .set_carried_block(Some(default_state_id)) - .await; + self.enderman.set_carried_block(Some(default_state_id)); }) } diff --git a/pumpkin/src/entity/ai/goal/place_block.rs b/pumpkin/src/entity/ai/goal/place_block.rs index 26428225f..f47834977 100644 --- a/pumpkin/src/entity/ai/goal/place_block.rs +++ b/pumpkin/src/entity/ai/goal/place_block.rs @@ -61,13 +61,13 @@ impl Goal for PlaceBlockGoal { let world = entity.world.load(); let target_pos = BlockPos::new(bx, by, bz); - let state_id = world.get_block_state_id(&target_pos).await; + let state_id = world.get_block_state_id(&target_pos); if !is_air(state_id) { return; } let below_pos = BlockPos::new(bx, by - 1, bz); - let (below_block, below_state) = world.get_block_and_state(&below_pos).await; + let (below_block, below_state) = world.get_block_and_state(&below_pos); if !below_state.is_solid() || !below_state.is_full_cube() || below_block == &Block::BEDROCK @@ -79,7 +79,7 @@ impl Goal for PlaceBlockGoal { world .set_block_state(&target_pos, block_state_id, BlockFlags::NOTIFY_ALL) .await; - self.enderman.set_carried_block(None).await; + self.enderman.set_carried_block(None); }) } diff --git a/pumpkin/src/entity/ai/goal/step_and_destroy_block.rs b/pumpkin/src/entity/ai/goal/step_and_destroy_block.rs index 7ba7de18f..5dd2e2374 100644 --- a/pumpkin/src/entity/ai/goal/step_and_destroy_block.rs +++ b/pumpkin/src/entity/ai/goal/step_and_destroy_block.rs @@ -49,8 +49,8 @@ impl StepAndDestroyBlockGoal { max_y_difference, ) } - async fn tweak_to_proper_pos(&self, pos: BlockPos, world: Arc) -> Option { - if world.get_block(&pos).await.id == self.target_block.id { + fn tweak_to_proper_pos(&self, pos: BlockPos, world: &World) -> Option { + if world.get_block(&pos).id == self.target_block.id { Some(pos) } else { let block_pos = [ @@ -63,7 +63,7 @@ impl StepAndDestroyBlockGoal { ]; for pos in block_pos { - if world.get_block(&pos).await.id == self.target_block.id { + if world.get_block(&pos).id == self.target_block.id { return Some(pos); } } @@ -131,7 +131,7 @@ impl Goal let world = mob.get_entity().world.load_full(); let block_pos = mob.get_entity().block_pos.load(); - let tweak_pos = self.tweak_to_proper_pos(block_pos, world.clone()).await; + let tweak_pos = self.tweak_to_proper_pos(block_pos, &world); // TODO: drop world? if !self.move_to_target_pos_goal.reached || tweak_pos.is_none() { return; @@ -144,8 +144,7 @@ impl Goal mob_entity .living_entity .entity - .set_velocity(Vector3::new(velocity.x, 0.3, velocity.z)) - .await; + .set_velocity(Vector3::new(velocity.x, 0.3, velocity.z)); // TODO: spawn particles } @@ -154,8 +153,7 @@ impl Goal mob_entity .living_entity .entity - .set_velocity(Vector3::new(velocity.x, -0.3, velocity.z)) - .await; + .set_velocity(Vector3::new(velocity.x, -0.3, velocity.z)); if counter % 6 == 0 { if let Some(stepping) = self.stepping.get() { stepping @@ -196,12 +194,9 @@ impl MoveToTargetPo block_pos: BlockPos, ) -> Pin + Send + 'a>> { Box::pin(async move { - world.get_block(&block_pos).await.id == self.target_block.id - && world.get_block_state(&block_pos.up()).await.is_air() - && world - .get_block_state(&block_pos.up_height(2)) - .await - .is_air() + world.get_block(&block_pos).id == self.target_block.id + && world.get_block_state(&block_pos.up()).is_air() + && world.get_block_state(&block_pos.up_height(2)).is_air() }) } } diff --git a/pumpkin/src/entity/ai/goal/teleport_towards_player.rs b/pumpkin/src/entity/ai/goal/teleport_towards_player.rs index ab894c8c6..ff03dfc1d 100644 --- a/pumpkin/src/entity/ai/goal/teleport_towards_player.rs +++ b/pumpkin/src/entity/ai/goal/teleport_towards_player.rs @@ -94,7 +94,7 @@ impl Goal for TeleportTowardsPlayerGoal { return false; } let player_pos = player.get_entity().pos.load(); - let mut look_control = mob.get_mob_entity().look_control.lock().await; + let mut look_control = mob.get_mob_entity().look_control.lock().unwrap(); look_control.look_at_with_range( player_pos.x, player_pos.y + PLAYER_EYE_HEIGHT, @@ -137,7 +137,7 @@ impl Goal for TeleportTowardsPlayerGoal { Box::pin(async move { self.warmup = to_goal_ticks(5); self.unseen_ticks = 0; - self.enderman.set_provoked(true).await; + self.enderman.set_provoked(true); }) } @@ -176,13 +176,13 @@ impl Goal for TeleportTowardsPlayerGoal { && self.enderman.is_player_staring(player).await { if dist_sq < STARE_CLOSE_DISTANCE_SQ { - self.enderman.teleport_randomly().await; + self.enderman.teleport_randomly(); } self.unseen_ticks = 0; } else if dist_sq > TELEPORT_FAR_DISTANCE_SQ { self.unseen_ticks += 1; if self.unseen_ticks >= to_goal_ticks(30) { - self.enderman.teleport_towards(target.as_ref()).await; + self.enderman.teleport_towards(target.as_ref()); self.unseen_ticks = 0; } } diff --git a/pumpkin/src/entity/ai/goal/tempt.rs b/pumpkin/src/entity/ai/goal/tempt.rs index 7d5ce3029..600a80462 100644 --- a/pumpkin/src/entity/ai/goal/tempt.rs +++ b/pumpkin/src/entity/ai/goal/tempt.rs @@ -91,7 +91,7 @@ impl Goal for TemptGoal { let mob_entity = mob.get_mob_entity(); let player_pos = player.living_entity.entity.pos.load(); - mob_entity.look_control.lock().await.look_at( + mob_entity.look_control.lock().unwrap().look_at( mob, player_pos.x, player.living_entity.entity.get_eye_y(), @@ -100,7 +100,7 @@ impl Goal for TemptGoal { let mob_pos = mob_entity.living_entity.entity.pos.load(); if mob_pos.squared_distance_to_vec(&player_pos) > STOP_DISTANCE * STOP_DISTANCE { - let mut navigator = mob_entity.navigator.lock().await; + let mut navigator = mob_entity.navigator.lock().unwrap(); navigator.set_progress(NavigatorGoal::new(mob_pos, player_pos, self.speed)); } } diff --git a/pumpkin/src/entity/ai/goal/wander_around.rs b/pumpkin/src/entity/ai/goal/wander_around.rs index 1f8f117a4..a9bebabde 100644 --- a/pumpkin/src/entity/ai/goal/wander_around.rs +++ b/pumpkin/src/entity/ai/goal/wander_around.rs @@ -51,7 +51,7 @@ impl Goal for WanderAroundGoal { fn should_continue<'a>(&'a self, mob: &'a dyn Mob) -> GoalFuture<'a, bool> { Box::pin(async move { - let navigator = mob.get_mob_entity().navigator.lock().await; + let navigator = mob.get_mob_entity().navigator.lock().unwrap(); !navigator.is_idle() }) } @@ -60,7 +60,7 @@ impl Goal for WanderAroundGoal { Box::pin(async move { if let Some(target) = self.target { let pos = mob.get_mob_entity().living_entity.entity.pos.load(); - let mut navigator = mob.get_mob_entity().navigator.lock().await; + let mut navigator = mob.get_mob_entity().navigator.lock().unwrap(); navigator.set_progress(NavigatorGoal::new(pos, target, self.speed)); } }) diff --git a/pumpkin/src/entity/ai/goal/zombie_attack.rs b/pumpkin/src/entity/ai/goal/zombie_attack.rs index 72d19d4ec..2920ef6cb 100644 --- a/pumpkin/src/entity/ai/goal/zombie_attack.rs +++ b/pumpkin/src/entity/ai/goal/zombie_attack.rs @@ -37,7 +37,7 @@ impl Goal for ZombieAttackGoal { fn stop<'a>(&'a mut self, mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async { self.melee_attack_goal.stop(mob).await; - mob.get_mob_entity().set_attacking(false).await; + mob.get_mob_entity().set_attacking(false); }) } @@ -48,9 +48,9 @@ impl Goal for ZombieAttackGoal { if self.ticks >= 5 && self.melee_attack_goal.cooldown < self.melee_attack_goal.get_max_cooldown() / 2 { - mob.get_mob_entity().set_attacking(true).await; + mob.get_mob_entity().set_attacking(true); } else { - mob.get_mob_entity().set_attacking(false).await; + mob.get_mob_entity().set_attacking(false); } }) } diff --git a/pumpkin/src/entity/ai/pathfinder/pathfinding_context.rs b/pumpkin/src/entity/ai/pathfinder/pathfinding_context.rs index 3a7f44d5c..d4eadeb14 100644 --- a/pumpkin/src/entity/ai/pathfinder/pathfinding_context.rs +++ b/pumpkin/src/entity/ai/pathfinder/pathfinding_context.rs @@ -46,14 +46,14 @@ impl PathfindingContext { self.mob_position } - pub async fn get_path_type_from_state(&mut self, pos: Vector3) -> PathType { + pub fn get_path_type_from_state(&mut self, pos: Vector3) -> PathType { if let Some(ref cache) = self.path_type_cache && let Some(pt) = cache.get(pos) { return pt; } - let pt = self.compute_path_type_from_state(pos).await; + let pt = self.compute_path_type_from_state(pos); if let Some(ref mut cache) = self.path_type_cache { cache.insert(pos, pt); @@ -63,11 +63,12 @@ impl PathfindingContext { } /// Classifies a block position into a `PathType` for pathfinding. - pub async fn compute_path_type_from_state(&self, pos: Vector3) -> PathType { + #[must_use] + pub fn compute_path_type_from_state(&self, pos: Vector3) -> PathType { let block_pos = pos.as_blockpos(); // Single async chunk lookup, then derive block & state from static arrays - let state_id = self.world.get_block_state_id(&block_pos).await; + let state_id = self.world.get_block_state_id(&block_pos); let block = Block::from_state_id(state_id); let state = BlockState::from_id(state_id); @@ -162,13 +163,11 @@ impl PathfindingContext { } /// Wraps the raw block type with below-check and neighbor danger scanning for OPEN nodes. - pub async fn get_land_node_type(&mut self, pos: Vector3) -> PathType { - let raw_type = self.get_path_type_from_state(pos).await; + pub fn get_land_node_type(&mut self, pos: Vector3) -> PathType { + let raw_type = self.get_path_type_from_state(pos); if raw_type == PathType::Open { - let below_type = self - .get_path_type_from_state(Vector3::new(pos.x, pos.y - 1, pos.z)) - .await; + let below_type = self.get_path_type_from_state(Vector3::new(pos.x, pos.y - 1, pos.z)); return match below_type { PathType::Open | PathType::Water | PathType::Lava | PathType::Walkable => { PathType::Open @@ -179,10 +178,7 @@ impl PathfindingContext { PathType::PowderSnow => PathType::DangerPowderSnow, PathType::DamageCautious => PathType::DamageCautious, PathType::Trapdoor => PathType::DangerTrapdoor, - _ => { - self.get_node_type_from_neighbors(pos, PathType::Walkable) - .await - } + _ => self.get_node_type_from_neighbors(pos, PathType::Walkable), }; } @@ -190,7 +186,7 @@ impl PathfindingContext { } /// Scans a 3x3x3 neighborhood for danger blocks and returns the appropriate danger type. - pub async fn get_node_type_from_neighbors( + pub fn get_node_type_from_neighbors( &mut self, pos: Vector3, fallback: PathType, @@ -202,9 +198,11 @@ impl PathfindingContext { continue; } - let neighbor_type = self - .get_path_type_from_state(Vector3::new(pos.x + dx, pos.y + dy, pos.z + dz)) - .await; + let neighbor_type = self.get_path_type_from_state(Vector3::new( + pos.x + dx, + pos.y + dy, + pos.z + dz, + )); if neighbor_type == PathType::DamageOther { return PathType::DangerOther; @@ -225,13 +223,13 @@ impl PathfindingContext { fallback } - pub async fn has_collisions(&mut self, pos: Vector3) -> bool { + pub fn has_collisions(&mut self, pos: Vector3) -> bool { if let Some(&cached) = self.collision_cache.get(&pos) { return cached; } let block_pos = pos.as_blockpos(); - let state_id = self.world.get_block_state_id(&block_pos).await; + let state_id = self.world.get_block_state_id(&block_pos); let state = BlockState::from_id(state_id); let has_collision = state.is_full_cube(); diff --git a/pumpkin/src/entity/ai/pathfinder/walk_node_evaluator.rs b/pumpkin/src/entity/ai/pathfinder/walk_node_evaluator.rs index 5cf361fce..c38330363 100644 --- a/pumpkin/src/entity/ai/pathfinder/walk_node_evaluator.rs +++ b/pumpkin/src/entity/ai/pathfinder/walk_node_evaluator.rs @@ -303,17 +303,16 @@ impl WalkNodeEvaluator { path_type } - async fn has_collisions(&mut self, center: Vector3) -> bool { - if let Some(ref mut ctx) = self.base.context { - ctx.has_collisions(center).await - } else { - false - } + fn has_collisions(&mut self, center: Vector3) -> bool { + self.base + .context + .as_mut() + .is_some_and(|ctx| ctx.has_collisions(center)) } async fn can_start_at(&mut self, pos: Vector3) -> bool { let path_type = self.get_cached_path_type(pos).await; - path_type.is_passable() && !self.has_collisions(pos).await + path_type.is_passable() && !self.has_collisions(pos) } async fn get_start_node(&mut self, pos: Vector3) -> Option { @@ -490,7 +489,7 @@ impl NodeEvaluator for WalkNodeEvaluator { for dx in 0..mob_data.get_bb_width() { for dz in 0..mob_data.get_bb_width() { let check_pos = pos.add_raw(dx, dy, dz); - let mut cell_type = context.get_land_node_type(check_pos).await; + let mut cell_type = context.get_land_node_type(check_pos); if cell_type == PathType::DoorWoodClosed && self.base.can_open_doors @@ -508,8 +507,8 @@ impl NodeEvaluator for WalkNodeEvaluator { Vector3::new(mob_block_pos.0, mob_block_pos.1, mob_block_pos.2); let mob_below = Vector3::new(mob_block_pos.0, mob_block_pos.1 - 1, mob_block_pos.2); - let mob_type = context.get_land_node_type(mob_pos).await; - let mob_below_type = context.get_land_node_type(mob_below).await; + let mob_type = context.get_land_node_type(mob_pos); + let mob_below_type = context.get_land_node_type(mob_below); if mob_type != PathType::Rail && mob_below_type != PathType::Rail { cell_type = PathType::UnpassableRail; } @@ -548,7 +547,7 @@ impl NodeEvaluator for WalkNodeEvaluator { && result != PathType::Open && mob_data.get_pathfinding_malus(result) == 0.0 { - let raw_center = context.get_land_node_type(pos).await; + let raw_center = context.get_land_node_type(pos); if raw_center == PathType::Open { return PathType::Open; } @@ -562,7 +561,7 @@ impl NodeEvaluator for WalkNodeEvaluator { context: &mut PathfindingContext, pos: Vector3, ) -> PathType { - context.get_path_type_from_state(pos).await + context.get_path_type_from_state(pos) } fn set_can_pass_doors(&mut self, can_pass: bool) { diff --git a/pumpkin/src/entity/area_effect_cloud.rs b/pumpkin/src/entity/area_effect_cloud.rs index a011cbe23..53f568196 100644 --- a/pumpkin/src/entity/area_effect_cloud.rs +++ b/pumpkin/src/entity/area_effect_cloud.rs @@ -178,16 +178,14 @@ impl EntityBase for AreaEffectCloudEntity { pumpkin_data::tracked_data::TrackedData::PARTICLE, pumpkin_data::meta_data_type::MetaDataType::PARTICLE, &meta, - )]) - .await; + )]); self.entity .send_meta_data(&[pumpkin_protocol::java::client::play::Metadata::new( pumpkin_data::tracked_data::TrackedData::RADIUS, pumpkin_data::meta_data_type::MetaDataType::FLOAT, radius, - )]) - .await; + )]); // Initial waiting flag let wait_time = *self.wait_time.lock().await; @@ -197,8 +195,7 @@ impl EntityBase for AreaEffectCloudEntity { pumpkin_data::tracked_data::TrackedData::WAITING, pumpkin_data::meta_data_type::MetaDataType::BOOLEAN, is_waiting, - )]) - .await; + )]); }) } @@ -233,8 +230,7 @@ impl EntityBase for AreaEffectCloudEntity { pumpkin_data::tracked_data::TrackedData::WAITING, pumpkin_data::meta_data_type::MetaDataType::BOOLEAN, false, - )]) - .await; + )]); } if age < wait_time { @@ -260,8 +256,7 @@ impl EntityBase for AreaEffectCloudEntity { pumpkin_data::tracked_data::TrackedData::RADIUS, pumpkin_data::meta_data_type::MetaDataType::FLOAT, current_radius, - )]) - .await; + )]); } // Tick down reapplication map @@ -385,13 +380,13 @@ impl EntityBase for AreaEffectCloudEntity { drop(radius_lock); // Send updated radius to clients - self.entity - .send_meta_data(&[pumpkin_protocol::java::client::play::Metadata::new( + self.entity.send_meta_data(&[ + pumpkin_protocol::java::client::play::Metadata::new( pumpkin_data::tracked_data::TrackedData::RADIUS, pumpkin_data::meta_data_type::MetaDataType::FLOAT, current_radius, - )]) - .await; + ), + ]); } // Apply duration-on-use (shorten lifespan) diff --git a/pumpkin/src/entity/boss/ender_dragon.rs b/pumpkin/src/entity/boss/ender_dragon.rs index 09506f2d5..1e33524e4 100644 --- a/pumpkin/src/entity/boss/ender_dragon.rs +++ b/pumpkin/src/entity/boss/ender_dragon.rs @@ -3,7 +3,7 @@ use pumpkin_data::damage::DamageType; use pumpkin_data::entity::EntityType; use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::vector3::Vector3; -use pumpkin_world::world::BlockFlags; +use pumpkin_world::{chunk::ChunkHeightmapType, world::BlockFlags}; use std::sync::Arc; use std::sync::atomic::Ordering; use tokio::sync::Mutex; @@ -236,7 +236,7 @@ pub struct EnderDragonEntity { } impl EnderDragonEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { entity.no_clip.store(true, Ordering::Relaxed); let base_id = entity.entity_id; let dragon_uuid = entity.entity_uuid; @@ -254,9 +254,7 @@ impl EnderDragonEntity { &EntityType::ENDER_DRAGON, ); let part = Arc::new(EnderDragonPart::new(part_entity, dragon_uuid)); - world - .add_entity_silent(part.clone() as Arc) - .await; + // TODO: world.add_entity_silent(part.clone() as Arc); parts.push(part); } @@ -348,7 +346,8 @@ impl EnderDragonEntity { + (20.0 * ((multiplier as f32) * std::f32::consts::TAU / 4.0).sin()) as i32; } - let height = world.get_motion_blocking_height(node_x, node_z).await; + let height = + world.get_heightmap_height(ChunkHeightmapType::MotionBlocking, node_x, node_z); let node_y = 73.max(height + y_adjustment); nodes[i] = Some(DragonNode::new(node_x as f64, node_y as f64, node_z as f64)); } @@ -575,7 +574,7 @@ impl EnderDragonEntity { .living_entity .entity .apply_knockback(4.0, xd / dd, zd / dd); - player.living_entity.entity.send_velocity().await; + player.living_entity.entity.send_velocity(); if !self.phase.lock().await.is_sitting() { player.damage(self, 5.0, DamageType::MOB_ATTACK).await; @@ -584,7 +583,7 @@ impl EnderDragonEntity { } } - async fn tick_crystal_healing(&self) { + fn tick_crystal_healing(&self) { let world = self.mob_entity.living_entity.entity.world.load(); let pos = self.mob_entity.living_entity.entity.pos.load(); @@ -605,7 +604,7 @@ impl EnderDragonEntity { if let Some(_crystal) = nearest_crystal { let living = &self.mob_entity.living_entity; if living.health.load() < living.get_max_health() { - living.heal(1.0).await; + living.heal(1.0); } } } @@ -623,7 +622,7 @@ impl EnderDragonEntity { let max = bbox.max_block_pos(); for pos in BlockPos::iterate(min, max) { - let block = world.get_block(&pos).await; + let block = world.get_block(&pos); if block != &Block::BEDROCK && block != &Block::END_STONE && block != &Block::OBSIDIAN @@ -637,7 +636,8 @@ impl EnderDragonEntity { } async fn tick_parts(&self) { - let history = self.flight_history.lock().await; + let history: tokio::sync::MutexGuard<'_, DragonFlightHistory> = + self.flight_history.lock().await; let p5 = history.get(5); let p10 = history.get(10); let p0 = history.get(0); @@ -710,7 +710,7 @@ impl EnderDragonEntity { } for part in &self.parts { - part.entity.send_pos_rot().await; + part.entity.send_pos_rot(); } } @@ -726,7 +726,7 @@ impl EnderDragonEntity { }; self.tick_growl().await; - self.tick_crystal_healing().await; + self.tick_crystal_healing(); { let world = self.mob_entity.living_entity.entity.world.load(); @@ -769,7 +769,7 @@ impl EnderDragonEntity { .await; } - self.mob_entity.living_entity.entity.send_pos_rot().await; + self.mob_entity.living_entity.entity.send_pos_rot(); self.tick_parts().await; } diff --git a/pumpkin/src/entity/boss/ender_dragon/phase/dying.rs b/pumpkin/src/entity/boss/ender_dragon/phase/dying.rs index 02662577e..a2a576595 100644 --- a/pumpkin/src/entity/boss/ender_dragon/phase/dying.rs +++ b/pumpkin/src/entity/boss/ender_dragon/phase/dying.rs @@ -28,13 +28,11 @@ impl super::Phase for DyingPhase { let world = entity.world.load(); if *t == 1 { - world - .play_sound( - Sound::EntityEnderDragonDeath, - SoundCategory::Hostile, - &entity.pos.load(), - ) - .await; + world.play_sound( + Sound::EntityEnderDragonDeath, + SoundCategory::Hostile, + &entity.pos.load(), + ); } if *t >= 180 && *t <= 200 { @@ -42,19 +40,17 @@ impl super::Phase for DyingPhase { let yo = (rand::random::() - 0.5) * 4.0; let zo = (rand::random::() - 0.5) * 8.0; let pos = entity.pos.load(); - world - .spawn_particle( - Vector3::new( - pos.x + xo as f64, - pos.y + 2.0 + yo as f64, - pos.z + zo as f64, - ), - Vector3::new(0.0, 0.0, 0.0), - 0.0, - 1, - Particle::ExplosionEmitter, - ) - .await; + world.spawn_particle( + Vector3::new( + pos.x + xo as f64, + pos.y + 2.0 + yo as f64, + pos.z + zo as f64, + ), + Vector3::new(0.0, 0.0, 0.0), + 0.0, + 1, + Particle::ExplosionEmitter, + ); } let xp_count = if let Some(ref fight_mutex) = world.dragon_fight diff --git a/pumpkin/src/entity/boss/wither.rs b/pumpkin/src/entity/boss/wither.rs index 94115dc26..429a5a944 100644 --- a/pumpkin/src/entity/boss/wither.rs +++ b/pumpkin/src/entity/boss/wither.rs @@ -12,7 +12,7 @@ pub struct WitherEntity { } impl WitherEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let wither = Self { mob_entity }; let mob_arc = Arc::new(wither); @@ -22,7 +22,7 @@ impl WitherEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); // TODO goal_selector.add_goal( diff --git a/pumpkin/src/entity/breath.rs b/pumpkin/src/entity/breath.rs index ef4a2dd45..7207a6b7e 100644 --- a/pumpkin/src/entity/breath.rs +++ b/pumpkin/src/entity/breath.rs @@ -40,7 +40,7 @@ impl BreathManager { if matches!(mode, GameMode::Creative | GameMode::Spectator) { if self.air_supply.load(Ordering::Relaxed) != MAX_AIR { self.air_supply.store(MAX_AIR, Ordering::Relaxed); - self.send_air_supply(player).await; + self.send_air_supply(player); } self.drowning_tick.store(0, Ordering::Relaxed); return; @@ -56,13 +56,13 @@ impl BreathManager { .await { if self.air_supply.swap(MAX_AIR, Ordering::Relaxed) != MAX_AIR { - self.send_air_supply(player).await; + self.send_air_supply(player); } self.drowning_tick.store(0, Ordering::Relaxed); return; } - let in_water = self.is_eye_in_water(player).await; + let in_water = Self::is_eye_in_water(player); if in_water { let prev = self @@ -71,7 +71,7 @@ impl BreathManager { let new_air = (prev - AIR_DEPLETION_RATE).max(0); if new_air != prev { self.air_supply.store(new_air, Ordering::Relaxed); - self.send_air_supply(player).await; + self.send_air_supply(player); } if new_air <= 0 { @@ -90,13 +90,13 @@ impl BreathManager { let new_air = (prev + AIR_RECOVERY_RATE).min(MAX_AIR); if new_air != prev { self.air_supply.store(new_air, Ordering::Relaxed); - self.send_air_supply(player).await; + self.send_air_supply(player); } self.drowning_tick.store(0, Ordering::Relaxed); } } - async fn is_eye_in_water(&self, player: &Player) -> bool { + fn is_eye_in_water(player: &Player) -> bool { let e = &player.living_entity.entity; let pos = e.pos.load(); let eye_y = e.get_eye_y(); @@ -108,15 +108,15 @@ impl BreathManager { ); let world = player.world(); - let (fluid, state) = world.get_fluid_and_fluid_state(&bp).await; + let (fluid, state) = world.get_fluid_and_fluid_state(&bp); let mut in_water_fluid = fluid.has_tag(&tag::Fluid::MINECRAFT_WATER); if !in_water_fluid { - let state_here = world.get_block_state(&bp).await; + let state_here = world.get_block_state(&bp); if !state_here.is_solid() { let above = BlockPos::new(bp.0.x, bp.0.y + 1, bp.0.z); - let fluid_above_x = world.get_fluid(&above).await; + let fluid_above_x = world.get_fluid(&above); if fluid_above_x.has_tag(&tag::Fluid::MINECRAFT_WATER) { in_water_fluid = true; } @@ -128,7 +128,7 @@ impl BreathManager { } let above = BlockPos::new(bp.0.x, bp.0.y + 1, bp.0.z); - let fluid_above = world.get_fluid(&above).await; + let fluid_above = world.get_fluid(&above); let surface_y = if fluid_above.has_tag(&tag::Fluid::MINECRAFT_WATER) { f64::from(bp.0.y as f32 + 1.0) @@ -149,23 +149,19 @@ impl BreathManager { surface_y > eye_y } - pub async fn send_air_supply(&self, player: &Player) { + pub fn send_air_supply(&self, player: &Player) { let air = self.air_supply.load(Ordering::Relaxed).clamp(0, MAX_AIR); - player - .living_entity - .entity - .send_meta_data(&[Metadata::new( - TrackedData::AIR_SUPPLY_ID, - MetaDataType::INTEGER, - VarInt(air), - )]) - .await; + player.living_entity.entity.send_meta_data(&[Metadata::new( + TrackedData::AIR_SUPPLY_ID, + MetaDataType::INTEGER, + VarInt(air), + )]); } - pub async fn reset(&self, player: &Player) { + pub fn reset(&self, player: &Player) { self.air_supply.store(MAX_AIR, Ordering::Relaxed); - self.send_air_supply(player).await; + self.send_air_supply(player); self.drowning_tick.store(0, Ordering::Relaxed); } } diff --git a/pumpkin/src/entity/combat.rs b/pumpkin/src/entity/combat.rs index c56d08f00..683dca245 100644 --- a/pumpkin/src/entity/combat.rs +++ b/pumpkin/src/entity/combat.rs @@ -72,7 +72,7 @@ pub fn handle_knockback(attacker: &Entity, victim: &Entity, strength: f64) { attacker.velocity.store(velocity.multiply(0.6, 1.0, 0.6)); } -pub async fn spawn_sweep_particle(attacker_entity: &Entity, world: &World, pos: &Vector3) { +pub fn spawn_sweep_particle(attacker_entity: &Entity, world: &World, pos: &Vector3) { let yaw = attacker_entity.yaw.load(); let d = -f64::from((yaw.to_radians()).sin()); let e = f64::from((yaw.to_radians()).cos()); @@ -80,52 +80,38 @@ pub async fn spawn_sweep_particle(attacker_entity: &Entity, world: &World, pos: let scale = 0.5; let body_y = f64::from(attacker_entity.height()).mul_add(scale, pos.y); - world - .spawn_particle( - Vector3::new(pos.x + d, body_y, pos.z + e), - Vector3::new(0.0, 0.0, 0.0), - 0.0, - 0, - Particle::SweepAttack, - ) - .await; + world.spawn_particle( + Vector3::new(pos.x + d, body_y, pos.z + e), + Vector3::new(0.0, 0.0, 0.0), + 0.0, + 0, + Particle::SweepAttack, + ); } pub async fn player_attack_sound(pos: &Vector3, world: &World, attack_type: AttackType) { match attack_type { AttackType::Knockback => { - world - .play_sound( - Sound::EntityPlayerAttackKnockback, - SoundCategory::Players, - pos, - ) - .await; + world.play_sound( + Sound::EntityPlayerAttackKnockback, + SoundCategory::Players, + pos, + ); } AttackType::Critical => { - world - .play_sound(Sound::EntityPlayerAttackCrit, SoundCategory::Players, pos) - .await; + world.play_sound(Sound::EntityPlayerAttackCrit, SoundCategory::Players, pos); } AttackType::Sweeping => { - world - .play_sound(Sound::EntityPlayerAttackSweep, SoundCategory::Players, pos) - .await; + world.play_sound(Sound::EntityPlayerAttackSweep, SoundCategory::Players, pos); } AttackType::Strong => { - world - .play_sound(Sound::EntityPlayerAttackStrong, SoundCategory::Players, pos) - .await; + world.play_sound(Sound::EntityPlayerAttackStrong, SoundCategory::Players, pos); } AttackType::Weak => { - world - .play_sound(Sound::EntityPlayerAttackWeak, SoundCategory::Players, pos) - .await; + world.play_sound(Sound::EntityPlayerAttackWeak, SoundCategory::Players, pos); } AttackType::MaceSmash => { - world - .play_sound(Sound::ItemMaceSmashAir, SoundCategory::Players, pos) - .await; + world.play_sound(Sound::ItemMaceSmashAir, SoundCategory::Players, pos); } } } diff --git a/pumpkin/src/entity/decoration/armor_stand.rs b/pumpkin/src/entity/decoration/armor_stand.rs index f78e1d0f5..7794a6996 100644 --- a/pumpkin/src/entity/decoration/armor_stand.rs +++ b/pumpkin/src/entity/decoration/armor_stand.rs @@ -199,40 +199,36 @@ impl ArmorStandEntity { .drop_stack(&entity.block_pos.load(), armor_stand_item) .await; - self.on_break(entity).await; + Self::on_break(entity); } - async fn on_break(&self, entity: &Entity) { + fn on_break(entity: &Entity) { let world = entity.world.load(); - world - .play_sound( - Sound::EntityArmorStandBreak, - SoundCategory::Neutral, - &entity.pos.load(), - ) - .await; + world.play_sound( + Sound::EntityArmorStandBreak, + SoundCategory::Neutral, + &entity.pos.load(), + ); // TODO: Implement equipment slots and make them drop all of their stored items. } /// Spawns break particles at the armor stand's position. // TODO: use oak plank block particles like vanilla (requires block state data in particle system) - async fn spawn_break_particles(&self, entity: &Entity) { + fn spawn_break_particles(entity: &Entity) { let world = entity.world.load(); let pos = entity.pos.load(); let width = entity.width(); let height = entity.height(); // Spawn particles similar to vanilla: 10 particles with offset based on entity size - world - .spawn_particle( - Vector3::new(pos.x, pos.y + f64::from(height) * 0.6666, pos.z), - Vector3::new(width / 4.0, height / 4.0, width / 4.0), - 0.05, - 10, - Particle::Poof, - ) - .await; + world.spawn_particle( + Vector3::new(pos.x, pos.y + f64::from(height) * 0.6666, pos.z), + Vector3::new(width / 4.0, height / 4.0, width / 4.0), + 0.05, + 10, + Particle::Poof, + ); } } @@ -373,7 +369,7 @@ impl EntityBase for ArmorStandEntity { || damage_type == DamageType::BAD_RESPAWN_POINT; if is_explosion { - self.on_break(entity).await; + Self::on_break(entity); entity.kill(caller).await; return false; } @@ -403,7 +399,7 @@ impl EntityBase for ArmorStandEntity { if !player.abilities.lock().await.allow_modify_world { return false; } else if player.is_creative() { - self.spawn_break_particles(entity).await; + Self::spawn_break_particles(entity); entity.kill(caller).await; return true; } @@ -412,26 +408,20 @@ impl EntityBase for ArmorStandEntity { let time = world.level_time.lock().await.query_gametime(); if time - self.last_hit_time.load(Ordering::Relaxed) > 5 && !always_kills { - world - .send_entity_status(entity, EntityStatus::ArmorstandWobble) - .await; - world - .play_sound( - Sound::EntityArmorStandHit, - SoundCategory::Neutral, - &entity.block_pos.load().to_f64(), - ) - .await; + world.send_entity_status(entity, EntityStatus::ArmorstandWobble); + world.play_sound( + Sound::EntityArmorStandHit, + SoundCategory::Neutral, + &entity.block_pos.load().to_f64(), + ); self.last_hit_time.store(time, Ordering::Relaxed); } else { - self.spawn_break_particles(entity).await; - world - .play_sound( - Sound::EntityArmorStandBreak, - SoundCategory::Neutral, - &entity.block_pos.load().to_f64(), - ) - .await; + Self::spawn_break_particles(entity); + world.play_sound( + Sound::EntityArmorStandBreak, + SoundCategory::Neutral, + &entity.block_pos.load().to_f64(), + ); self.break_and_drop_items().await; entity.kill(caller).await; } diff --git a/pumpkin/src/entity/decoration/end_crystal.rs b/pumpkin/src/entity/decoration/end_crystal.rs index 67b58b36f..342cd8308 100644 --- a/pumpkin/src/entity/decoration/end_crystal.rs +++ b/pumpkin/src/entity/decoration/end_crystal.rs @@ -21,14 +21,12 @@ impl EndCrystalEntity { } impl EndCrystalEntity { - pub async fn set_show_bottom(&self, show_bottom: bool) { - self.entity - .send_meta_data(&[Metadata::new( - TrackedData::SHOW_BOTTOM, - MetaDataType::BOOLEAN, - show_bottom, - )]) - .await; + pub fn set_show_bottom(&self, show_bottom: bool) { + self.entity.send_meta_data(&[Metadata::new( + TrackedData::SHOW_BOTTOM, + MetaDataType::BOOLEAN, + show_bottom, + )]); } } diff --git a/pumpkin/src/entity/experience_orb.rs b/pumpkin/src/entity/experience_orb.rs index 2e137f5db..37b9787bd 100644 --- a/pumpkin/src/entity/experience_orb.rs +++ b/pumpkin/src/entity/experience_orb.rs @@ -86,8 +86,7 @@ impl EntityBase for ExperienceOrbEntity { .entity .world .load() - .is_space_empty(bounding_box.expand(-1.0e-7, -1.0e-7, -1.0e-7)) - .await; + .is_space_empty(bounding_box.expand(-1.0e-7, -1.0e-7, -1.0e-7)); // TODO: isSubmergedIn if !no_clip { velo.y -= self.get_gravity(); @@ -116,7 +115,7 @@ impl EntityBase for ExperienceOrbEntity { let mut delay = player.experience_pick_up_delay.lock().await; if *delay == 0 { *delay = 2; - player.living_entity.pickup(&self.entity, 1).await; + player.living_entity.pickup(&self.entity, 1); let remaining = player.apply_mending_from_xp(self.amount as i32).await; if remaining > 0 { player.add_experience_points(remaining).await; diff --git a/pumpkin/src/entity/falling.rs b/pumpkin/src/entity/falling.rs index 4fc74d543..89507ddc8 100644 --- a/pumpkin/src/entity/falling.rs +++ b/pumpkin/src/entity/falling.rs @@ -82,21 +82,19 @@ impl EntityBase for FallingEntity { entity.velocity.store(velo.multiply(0.98, 0.98, 0.98)); if entity.velocity_dirty.swap(false, Ordering::SeqCst) { - entity.send_pos_rot().await; - entity.send_velocity().await; + entity.send_pos_rot(); + entity.send_velocity(); } }) } fn init_data_tracker(&self) -> EntityBaseFuture<'_, ()> { Box::pin(async move { - self.entity - .send_meta_data(&[Metadata::new( - TrackedData::START_POS, - MetaDataType::BLOCK_POS, - self.entity.block_pos.load(), - )]) - .await; + self.entity.send_meta_data(&[Metadata::new( + TrackedData::START_POS, + MetaDataType::BLOCK_POS, + self.entity.block_pos.load(), + )]); }) } diff --git a/pumpkin/src/entity/item.rs b/pumpkin/src/entity/item.rs index 3274e0ffe..645f2a153 100644 --- a/pumpkin/src/entity/item.rs +++ b/pumpkin/src/entity/item.rs @@ -36,14 +36,12 @@ pub struct ItemEntity { } impl ItemEntity { - pub async fn new(entity: Entity, item_stack: ItemStack) -> Self { - entity - .set_velocity(Vector3::new( - rand::random::().mul_add(0.2, -0.1), - 0.2, - rand::random::().mul_add(0.2, -0.1), - )) - .await; + pub fn new(entity: Entity, item_stack: ItemStack) -> Self { + entity.velocity.store(Vector3::new( + rand::random::().mul_add(0.2, -0.1), + 0.2, + rand::random::().mul_add(0.2, -0.1), + )); entity.yaw.store(rand::random::() * 360.0); // Set fire immunity for certain items @@ -64,13 +62,13 @@ impl ItemEntity { } } - pub async fn new_with_velocity( + pub fn new_with_velocity( entity: Entity, item_stack: ItemStack, velocity: Vector3, pickup_delay: u8, ) -> Self { - entity.set_velocity(velocity).await; + entity.velocity.store(velocity); entity.yaw.store(rand::random::() * 360.0); // Set fire immunity for certain items @@ -242,7 +240,7 @@ impl ItemEntity { velo } - async fn update_no_clip_and_push_out(&self) { + fn update_no_clip_and_push_out(&self) { let entity = &self.entity; let pos = entity.pos.load(); let bounding_box = entity.bounding_box.load(); @@ -250,19 +248,16 @@ impl ItemEntity { let no_clip = !entity .world .load() - .is_space_empty(bounding_box.expand(-1.0e-7, -1.0e-7, -1.0e-7)) - .await; + .is_space_empty(bounding_box.expand(-1.0e-7, -1.0e-7, -1.0e-7)); entity.no_clip.store(no_clip, Ordering::Relaxed); if no_clip { - entity - .push_out_of_blocks(Vector3::new( - pos.x, - f64::midpoint(bounding_box.min.y, bounding_box.max.y), - pos.z, - )) - .await; + entity.push_out_of_blocks(Vector3::new( + pos.x, + f64::midpoint(bounding_box.min.y, bounding_box.max.y), + pos.z, + )); } } @@ -300,7 +295,7 @@ impl ItemEntity { let mut velo = entity.velocity.load(); if on_ground { - let block_affecting_velo = entity.get_block_with_y_offset(0.999_999).await.1; + let block_affecting_velo = entity.get_block_with_y_offset(0.999_999).1; friction *= f64::from(block_affecting_velo.slipperiness) * 0.98; } @@ -360,8 +355,8 @@ impl ItemEntity { || entity.velocity.load().sub(&original_velo).length_squared() > 0.1; if velocity_dirty { - entity.send_pos_rot().await; - entity.send_velocity().await; + entity.send_pos_rot(); + entity.send_velocity(); } } } @@ -383,7 +378,7 @@ impl EntityBase for ItemEntity { .velocity .store(self.apply_fluid_drag_or_gravity(original_velo)); - self.update_no_clip_and_push_out().await; + self.update_no_clip_and_push_out(); let move_velo = entity.velocity.load(); // In case push_out_of_blocks modifies it @@ -404,13 +399,11 @@ impl EntityBase for ItemEntity { fn init_data_tracker(&self) -> EntityBaseFuture<'_, ()> { Box::pin(async { - self.entity - .send_meta_data(&[Metadata::new( - TrackedData::ITEM, - MetaDataType::ITEM_STACK, - &ItemStackSerializer::from(self.item_stack.lock().await.clone()), - )]) - .await; + self.entity.send_meta_data(&[Metadata::new( + TrackedData::ITEM, + MetaDataType::ITEM_STACK, + &ItemStackSerializer::from(self.item_stack.lock().await.clone()), + )]); }) } diff --git a/pumpkin/src/entity/living.rs b/pumpkin/src/entity/living.rs index 43f0e783e..2784a4347 100644 --- a/pumpkin/src/entity/living.rs +++ b/pumpkin/src/entity/living.rs @@ -181,7 +181,7 @@ impl LivingEntity { } } - pub async fn send_equipment_changes(&self, equipment: &[(EquipmentSlot, ItemStack)]) { + pub fn send_equipment_changes(&self, equipment: &[(EquipmentSlot, ItemStack)]) { let equipment: Vec<(i8, ItemStackSerializer)> = equipment .iter() .map(|(slot, stack)| { @@ -191,18 +191,14 @@ impl LivingEntity { ) }) .collect(); - self.entity - .world - .load() - .broadcast_packet_except( - &[self.entity.entity_uuid], - &CSetEquipment::new(self.entity_id().into(), equipment), - ) - .await; + self.entity.world.load().broadcast_packet_except( + &[self.entity.entity_uuid], + &CSetEquipment::new(self.entity_id().into(), equipment), + ); } /// Picks up and Item entity or XP Orb - pub async fn pickup(&self, item: &Entity, stack_amount: u32) { + pub fn pickup(&self, item: &Entity, stack_amount: u32) { // TODO: Only nearby self.entity .world @@ -211,8 +207,7 @@ impl LivingEntity { item.entity_id.into(), self.entity.entity_id.into(), stack_amount.try_into().unwrap(), - )) - .await; + )); } /// Sends the Hand animation to all others, used when Eating for example @@ -220,12 +215,11 @@ impl LivingEntity { self.item_use_time.store(duration, Ordering::Relaxed); *self.item_in_use.lock().await = Some(stack); *self.active_hand.lock().await = Some(hand); - self.set_living_flag(Self::USING_ITEM_FLAG, true).await; - self.set_living_flag(Self::OFF_HAND_ACTIVE_FLAG, hand == Hand::Left) - .await; + self.set_living_flag(Self::USING_ITEM_FLAG, true); + self.set_living_flag(Self::OFF_HAND_ACTIVE_FLAG, hand == Hand::Left); } - async fn set_living_flag(&self, flag: u8, value: bool) { + fn set_living_flag(&self, flag: u8, value: bool) { let index = flag; let mut b = self.livings_flags.load(Ordering::Relaxed); if value { @@ -234,13 +228,11 @@ impl LivingEntity { b &= !index; } self.livings_flags.store(b, Ordering::Relaxed); - self.entity - .send_meta_data(&[Metadata::new( - TrackedData::LIVING_ENTITY_FLAGS, - MetaDataType::BYTE, - b, - )]) - .await; + self.entity.send_meta_data(&[Metadata::new( + TrackedData::LIVING_ENTITY_FLAGS, + MetaDataType::BYTE, + b, + )]); } pub async fn clear_active_hand(&self) { @@ -248,7 +240,7 @@ impl LivingEntity { *self.active_hand.lock().await = None; self.item_use_time.store(0, Ordering::Relaxed); - self.set_living_flag(Self::USING_ITEM_FLAG, false).await; + self.set_living_flag(Self::USING_ITEM_FLAG, false); } pub async fn is_blocking(&self) -> bool { @@ -262,25 +254,22 @@ impl LivingEntity { false } - pub async fn heal(&self, additional_health: f32) { + pub fn heal(&self, additional_health: f32) { assert!(additional_health > 0.0); - self.set_health(self.health.load() + additional_health) - .await; + self.set_health(self.health.load() + additional_health); } - pub async fn set_health(&self, health: f32) { + pub fn set_health(&self, health: f32) { // Clamp to [0, max_health] let max_health = self.get_max_health(); let clamped = health.max(0.0).min(max_health); self.health.store(clamped); // tell everyone entities health changed - self.entity - .send_meta_data(&[Metadata::new( - TrackedData::HEALTH_ID, - MetaDataType::FLOAT, - clamped, - )]) - .await; + self.entity.send_meta_data(&[Metadata::new( + TrackedData::HEALTH_ID, + MetaDataType::FLOAT, + clamped, + )]); } /// Returns the current maximum health for this entity @@ -303,7 +292,7 @@ impl LivingEntity { // Clamp current health to new max if needed and send metadata update let current_health = self.health.load(); if current_health > max_health { - self.set_health(max_health).await; + self.set_health(max_health); } } @@ -331,8 +320,7 @@ impl LivingEntity { // Send absorption metadata for players (visual yellow hearts) if let Some(tracked_id) = self.player_absorption_id() { self.entity - .send_meta_data(&[Metadata::new(tracked_id, MetaDataType::FLOAT, new_abs)]) - .await; + .send_meta_data(&[Metadata::new(tracked_id, MetaDataType::FLOAT, new_abs)]); } } @@ -437,7 +425,7 @@ impl LivingEntity { // Apply instant effects immediately before storing if effect.effect_type == &StatusEffect::INSTANT_HEALTH { let heal_amount = 4.0 * (1 << effect.amplifier) as f32; - self.heal(heal_amount).await; + self.heal(heal_amount); } else if effect.effect_type == &StatusEffect::INSTANT_DAMAGE { let damage_amount = 6.0 * (1 << effect.amplifier) as f32; if let Some(dyn_self) = self @@ -539,7 +527,7 @@ impl LivingEntity { flag, ); - self.entity.world.load().broadcast_packet_all(&packet).await; + self.entity.world.load().broadcast_packet_all(&packet); } pub async fn remove_effect(&self, effect_type: &'static StatusEffect) -> bool { @@ -555,8 +543,7 @@ impl LivingEntity { self.entity .world .load() - .send_remove_mob_effect(&self.entity, effect_type) - .await; + .send_remove_mob_effect(&self.entity, effect_type); // Remove attribute modifiers, if any if !effect_type.attribute_modifiers.is_empty() { @@ -596,7 +583,7 @@ impl LivingEntity { let new_max = self.get_max_health(); if self.health.load() > new_max { // Update local health and send both health and absorption metadata together - self.set_health(new_max.max(0.0)).await; + self.set_health(new_max.max(0.0)); } } @@ -623,9 +610,9 @@ impl LivingEntity { effects.get(&effect).cloned() } - pub async fn is_in_fall_damage_resetting(&self) -> (bool, &Block) { + pub fn is_in_fall_damage_resetting(&self) -> (bool, &Block) { let block_pos = self.entity.block_pos.load(); - let block = self.entity.world.load().get_block(&block_pos).await; + let block = self.entity.world.load().get_block(&block_pos); ( block.has_tag(&tag::Block::MINECRAFT_FALL_DAMAGE_RESETTING), block, @@ -633,19 +620,19 @@ impl LivingEntity { } // Check if the entity is in water - pub async fn is_in_water(&self) -> bool { + pub fn is_in_water(&self) -> bool { let block_pos = self.entity.block_pos.load(); - self.entity.world.load().get_block(&block_pos).await == &Block::WATER + self.entity.world.load().get_block(&block_pos) == &Block::WATER } // Check if the entity is in powder snow - pub async fn is_in_powder_snow(&self) -> bool { + pub fn is_in_powder_snow(&self) -> bool { let block_pos = self.entity.block_pos.load(); - self.entity.world.load().get_block(&block_pos).await == &Block::POWDER_SNOW + self.entity.world.load().get_block(&block_pos) == &Block::POWDER_SNOW } - pub async fn should_prevent_fall_damage(&self) -> bool { - let (prevents, block) = self.is_in_fall_damage_resetting().await; + pub fn should_prevent_fall_damage(&self) -> bool { + let (prevents, block) = self.is_in_fall_damage_resetting(); if block == &Block::SCAFFOLDING && !self.entity.sneaking.load(Ordering::Relaxed) { return false; @@ -671,7 +658,7 @@ impl LivingEntity { prevents } - pub async fn should_prevent_fall_damage_in_area(&self) -> bool { + pub fn should_prevent_fall_damage_in_area(&self) -> bool { let world = self.entity.world.load(); let block_pos = self.entity.block_pos.load().down(); let entity_pos = self.entity.pos.load(); @@ -691,7 +678,7 @@ impl LivingEntity { // FIXME: it seems the java server checks all blocks around with a raycast and check if miss or hit, // then added to a collision checker to handle in the tick handler for pos in pos_iter { - let block = world.get_block(&pos).await; + let block = world.get_block(&pos); if Self::PREVENT_AREA_FALL_DAMAGE_BLOCKS.contains(&block) { let block_center = Vector3::new( @@ -728,7 +715,7 @@ impl LivingEntity { } } - pub async fn swing_hand(&self) { + pub fn swing_hand(&self) { // TODO: radius self.entity .world @@ -736,8 +723,7 @@ impl LivingEntity { .broadcast_packet_all(&CEntityAnimation::new( self.entity_id().into(), Animation::SwingMainArm, - )) - .await; + )); } async fn tick_movement<'a>(&'a self, server: &'a Server, caller: &'a Arc) { @@ -839,7 +825,6 @@ impl LivingEntity { let slipperiness = f64::from( self.entity .get_block_with_y_offset(0.500_001) - .await .1 .slipperiness, ); @@ -989,7 +974,6 @@ impl LivingEntity { .world .load() .check_fluid_collision(self.entity.bounding_box.load().shift(velo)) - .await { velo.y = 0.3; @@ -1023,7 +1007,7 @@ impl LivingEntity { // let world = self.entity.world.read().await; - // let (block, state) = world.get_block_and_state(&pos).await; + // let (block, state) = world.get_block_and_state(&pos); // let name = block.properties(state.id).map(|props| props.name()); @@ -1045,7 +1029,7 @@ impl LivingEntity { // pos.0.y -= 1; - // let (down_block, down_state) = world.get_block_and_state(&pos).await; + // let (down_block, down_state) = world.get_block_and_state(&pos); // let is_ladder = down_block // .properties(down_state.id) @@ -1157,7 +1141,7 @@ impl LivingEntity { async fn get_jump_velocity(&self, mut strength: f64) -> f64 { strength *= self.get_attribute_value(&Attributes::JUMP_STRENGTH); - strength *= f64::from(self.entity.get_jump_velocity_multiplier().await); + strength *= f64::from(self.entity.get_jump_velocity_multiplier()); if let Some(effect) = self.get_effect(&StatusEffect::JUMP_BOOST).await { strength += 0.1 * f64::from(effect.amplifier + 1); } @@ -1175,16 +1159,14 @@ impl LivingEntity { let fall_distance = self.fall_distance.swap(0.0); if fall_distance <= 0.0 || dont_damage - || self.should_prevent_fall_damage().await - || self.should_prevent_fall_damage_in_area().await + || self.should_prevent_fall_damage() + || self.should_prevent_fall_damage_in_area() || self.is_immune_to_fall_damage() { return; } let world = self.entity.world.load(); - let block = world - .get_block(&self.entity.get_pos_with_y_offset(0.2).await.0) - .await; + let block = world.get_block(&self.entity.get_pos_with_y_offset(0.2).0); let pumpkin_block = world.block_registry.get_pumpkin_block(block.id); if let Some(pumpkin_block) = pumpkin_block { pumpkin_block @@ -1198,8 +1180,8 @@ impl LivingEntity { self.handle_fall_damage(&*caller, fall_distance, 1.0).await; } } else if height_difference < 0.0 { - let new_fall_distance = if !self.should_prevent_fall_damage().await - && !self.should_prevent_fall_damage_in_area().await + let new_fall_distance = if !self.should_prevent_fall_damage() + && !self.should_prevent_fall_damage_in_area() { let distance = self.fall_distance.load(); distance - (height_difference as f32) @@ -1229,8 +1211,7 @@ impl LivingEntity { let check_damage = self.damage(caller, damage, DamageType::FALL).await; // Fall if check_damage { self.entity - .play_sound(Self::get_fall_sound(fall_distance as i32)) - .await; + .play_sound(Self::get_fall_sound(fall_distance as i32)); } } } @@ -1307,9 +1288,7 @@ impl LivingEntity { self.jumping.store(false, Relaxed); // Plays the death sound - world - .send_entity_status(&self.entity, EntityStatus::Death) - .await; + world.send_entity_status(&self.entity, EntityStatus::Death); let params = LootContextParameters { killed_by_player: cause.map(|c| c.get_entity().entity_type == &EntityType::PLAYER), ..Default::default() @@ -1449,7 +1428,7 @@ impl LivingEntity { let current_health = self.health.load(); let max_health = self.get_max_health(); if current_health < max_health && current_health > 0.0 { - self.heal(1.0).await; + self.heal(1.0); } } else if effect_type == &StatusEffect::POISON { let current_health = self.health.load(); @@ -1511,12 +1490,11 @@ impl LivingEntity { // Clear the stack and use the totem of undying if stack.get_data_component::().is_some() { stack.clear(); - self.set_health(1.0).await; + self.set_health(1.0); self.entity .world .load() - .send_entity_status(&self.entity, EntityStatus::ProtectedFromDeath) - .await; + .send_entity_status(&self.entity, EntityStatus::ProtectedFromDeath); // Set Absorption, Regeneration, and Fire Resistance effects self.add_effect(Effect { @@ -1604,9 +1582,7 @@ impl LivingEntity { // Broadcast break status before clearing the slot. if slot_result == pumpkin_data::item_stack::DamageResult::Broken { let world = self.entity.world.load(); - world - .send_entity_status(&self.entity, super::equipment_break_status(&slot)) - .await; + world.send_entity_status(&self.entity, super::equipment_break_status(&slot)); } equipment_updates.push((slot.clone(), updated_stack.clone())); if let Some(player) = caller.get_player() { @@ -1621,7 +1597,7 @@ impl LivingEntity { } if !equipment_updates.is_empty() { - self.send_equipment_changes(&equipment_updates).await; + self.send_equipment_changes(&equipment_updates); } } @@ -1670,17 +1646,15 @@ impl LivingEntity { // Restore to maximum health for this entity type let max_health = self.get_max_health(); - self.set_health(max_health).await; + self.set_health(max_health); // Clear any absorption self.absorption.store(0.0); // Send health metadata - self.entity - .send_meta_data(&[Metadata::new( - TrackedData::HEALTH_ID, - MetaDataType::FLOAT, - max_health, - )]) - .await; + self.entity.send_meta_data(&[Metadata::new( + TrackedData::HEALTH_ID, + MetaDataType::FLOAT, + max_health, + )]); self.reset_effects_and_attributes().await; @@ -1756,8 +1730,7 @@ impl LivingEntity { center, &world, Uuid::new_v4(), - ) - .await; + ); silver.get_entity().set_pos(center); silver.get_entity().velocity.store(Vector3::new(dx, dy, dz)); @@ -1765,9 +1738,7 @@ impl LivingEntity { world.spawn_entity(silver).await; // Play sound - world - .play_sound(Sound::EntitySilverfishHurt, SoundCategory::Players, ¢er) - .await; + world.play_sound(Sound::EntitySilverfishHurt, SoundCategory::Players, ¢er); } } } @@ -1950,9 +1921,7 @@ impl EntityBase for LivingEntity { source_to_player.y = 0.0; if source_to_player.dot(&look_vec) < 0.0 { - world - .play_sound(Sound::ItemShieldBlock, SoundCategory::Players, &player_pos) - .await; + world.play_sound(Sound::ItemShieldBlock, SoundCategory::Players, &player_pos); if let Some(attacker_player) = cause.and_then(|c| c.get_player()) { let held_item = attacker_player.inventory().held_item(); @@ -1976,12 +1945,10 @@ impl EntityBase for LivingEntity { .await; self.clear_active_hand().await; - world - .broadcast_packet_all(&CEntityStatus::new( - self.entity.entity_id, - 30, - )) - .await; + world.broadcast_packet_all(&CEntityStatus::new( + self.entity.entity_id, + 30, + )); } } } @@ -2000,19 +1967,17 @@ impl EntityBase for LivingEntity { let durability_damage = (amount / 1.0).floor().max(1.0) as i32; if stack.damage_item(durability_damage) == DamageResult::Broken { - world - .send_entity_status( - &self.entity, - crate::entity::equipment_break_status(&slot), - ) - .await; + world.send_entity_status( + &self.entity, + crate::entity::equipment_break_status(&slot), + ); *stack = ItemStack::EMPTY.clone(); let broken_stack = stack.clone(); drop(stack); drop(stack_arc); drop(equipment_lock); - self.send_equipment_changes(&[(slot, broken_stack)]).await; + self.send_equipment_changes(&[(slot, broken_stack)]); self.clear_active_hand().await; } } @@ -2048,32 +2013,26 @@ impl EntityBase for LivingEntity { (src.z - tgt.z).atan2(src.x - tgt.x).to_degrees() as f32 - self.entity.yaw.load() }); - world - .broadcast_packet_all(&CHurtAnimation::new(entity_id, hurt_yaw)) - .await; + world.broadcast_packet_all(&CHurtAnimation::new(entity_id, hurt_yaw)); } - world - .broadcast_packet_all(&CDamageEvent::new( - self.entity.entity_id.into(), - damage_type.id.into(), - source.map(|e| e.get_entity().entity_id.into()), - cause.map(|e| e.get_entity().entity_id.into()), - position, - )) - .await; + world.broadcast_packet_all(&CDamageEvent::new( + self.entity.entity_id.into(), + damage_type.id.into(), + source.map(|e| e.get_entity().entity_id.into()), + cause.map(|e| e.get_entity().entity_id.into()), + position, + )); // Try to spawn infested silverfish self.try_spawn_infested_silverfish().await; if play_sound { - world - .play_sound( - self.hurt_sound(), - SoundCategory::Players, - &self.entity.pos.load(), - ) - .await; + world.play_sound( + self.hurt_sound(), + SoundCategory::Players, + &self.entity.pos.load(), + ); if let Some(source) = source { let source_pos = source.get_entity().pos.load(); @@ -2081,7 +2040,7 @@ impl EntityBase for LivingEntity { let dx = source_pos.x - target_pos.x; let dz = source_pos.z - target_pos.z; self.entity.apply_knockback(0.4, dx, dz); - self.entity.send_velocity().await; + self.entity.send_velocity(); } } @@ -2112,7 +2071,7 @@ impl EntityBase for LivingEntity { let new_health = self.health.load() - remaining; let clamped_health = new_health.max(0.0).min(max_h); if remaining > 0.0 { - self.set_health(clamped_health).await; + self.set_health(clamped_health); // Track attacker for RevengeGoal (only after confirming damage) if let Some(attacker) = cause.or(source) { @@ -2179,22 +2138,19 @@ impl EntityBase for LivingEntity { let is_player = player.is_some(); if !is_player { - self.entity.send_pos_rot().await; + self.entity.send_pos_rot(); } // Fetch supporting blocks for players or other entities - let supporting_pos = if let Some(player) = caller.get_player() { - // Handles player movement and detection along block edges - player.get_supporting_block_pos().await - } else { - // Fast physics-based supporting block detection for server entities - self.entity.get_supporting_block_pos() - }; + let supporting_pos = caller.get_player().map_or_else( + || self.entity.get_supporting_block_pos(), + super::player::Player::get_supporting_block_pos, + ); // Notify the block under the entity each tick if a supporting block position is found if let Some(supporting) = supporting_pos { let world = self.entity.world.load(); - let (block, state) = world.get_block_and_state(&supporting).await; + let (block, state) = world.get_block_and_state(&supporting); world .block_registry @@ -2211,8 +2167,7 @@ impl EntityBase for LivingEntity { // Check slightly below supporting_pos for additional supporting blocks (blocks under carpets and the like) if !block.is_solid() { let below_supporting = supporting.down(); - let (below_block, below_state) = - world.get_block_and_state(&below_supporting).await; + let (below_block, below_state) = world.get_block_and_state(&below_supporting); // If block is not air, notify it as well world @@ -2413,8 +2368,7 @@ impl EntityBase for LivingEntity { self.entity .world .load() - .send_entity_status(&self.entity, EntityStatus::Death) - .await; + .send_entity_status(&self.entity, EntityStatus::Death); self.entity.remove().await; } } diff --git a/pumpkin/src/entity/mob/bat.rs b/pumpkin/src/entity/mob/bat.rs index 9faa73a56..693b38dbc 100644 --- a/pumpkin/src/entity/mob/bat.rs +++ b/pumpkin/src/entity/mob/bat.rs @@ -28,7 +28,7 @@ pub struct BatEntity { } impl BatEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let bat = Self { mob_entity, @@ -38,28 +38,24 @@ impl BatEntity { }; let mob_arc = Arc::new(bat); - mob_arc.set_roosting_metadata(true).await; + Self::set_roosting_metadata(true); mob_arc } - pub async fn check_bat_spawn_rules(world: &World, pos: &BlockPos) -> bool { - if pos.0.y - >= world - .get_heightmap_height(ChunkHeightmapType::WorldSurface, pos.0.x, pos.0.z) - .await + pub fn check_bat_spawn_rules(world: &World, pos: &BlockPos) -> bool { + if pos.0.y >= world.get_heightmap_height(ChunkHeightmapType::WorldSurface, pos.0.x, pos.0.z) { return false; } if rand::random_bool(1.0) { return false; } - if world.get_max_local_raw_brightness(pos).await > rand::random_range(0..4) { + if world.get_max_local_raw_brightness_sync(pos) > rand::random_range(0..4) { return false; } if world .get_block(pos) - .await .has_tag(&tag::Block::MINECRAFT_BATS_SPAWNABLE_ON) { return false; @@ -72,13 +68,12 @@ impl BatEntity { self.roosting.load(Relaxed) } - async fn set_roosting(&self, roosting: bool) { + fn set_roosting(&self, roosting: bool) { self.roosting.store(roosting, Relaxed); - self.set_roosting_metadata(roosting).await; + Self::set_roosting_metadata(roosting); } - #[expect(clippy::unused_async)] - async fn set_roosting_metadata(&self, _roosting: bool) { + const fn set_roosting_metadata(_roosting: bool) { // TODO // let flags: u8 = if roosting { ROOSTING_FLAG } else { 0 }; // self.mob_entity @@ -107,7 +102,7 @@ impl NBTStorage for BatEntity { self.mob_entity.living_entity.read_nbt_non_mut(nbt).await; let flags = nbt.get_byte("BatFlags").unwrap_or(0) as u8; let roosting = (flags & ROOSTING_FLAG) != 0; - self.set_roosting(roosting).await; + self.set_roosting(roosting); }) } } @@ -129,11 +124,11 @@ impl Mob for BatEntity { if chance <= 0 { self.ambient_sound_chance .store(MIN_AMBIENT_SOUND_DELAY, Relaxed); - entity.play_sound(Sound::EntityBatAmbient).await; + entity.play_sound(Sound::EntityBatAmbient); } if self.is_roosting() { - let above_state = world.get_block_state(&above_pos).await; + let above_state = world.get_block_state(&above_pos); if above_state.is_solid_block() { let rotate_head = { let mut rng = rand::rng(); @@ -149,16 +144,16 @@ impl Mob for BatEntity { .get_closest_player(pos, CLOSE_PLAYER_DISTANCE) .is_some() { - self.set_roosting(false).await; + self.set_roosting(false); } } else { - self.set_roosting(false).await; + self.set_roosting(false); } } else { let mut hanging_pos = self.hanging_position.lock().await; if let Some(hp) = *hanging_pos { - let hp_state = world.get_block_state(&hp).await; + let hp_state = world.get_block_state(&hp); if !hp_state.is_air() || hp.0.y <= world.dimension.min_y { *hanging_pos = None; } @@ -190,7 +185,7 @@ impl Mob for BatEntity { if should_pick_new { // Pre-validate: only accept targets in air (avoids water, lava, hazards) if let Some(target) = new_target { - let target_state = world.get_block_state(&target).await; + let target_state = world.get_block_state(&target); if target_state.is_air() && target.0.y > world.dimension.min_y { *hanging_pos = Some(target); } else { @@ -222,9 +217,9 @@ impl Mob for BatEntity { drop(hanging_pos); if try_roost { - let above_state = world.get_block_state(&above_pos).await; + let above_state = world.get_block_state(&above_pos); if above_state.is_solid_block() { - self.set_roosting(true).await; + self.set_roosting(true); } } } @@ -258,7 +253,7 @@ impl Mob for BatEntity { ) -> EntityBaseFuture<'a, ()> { Box::pin(async move { if self.is_roosting() { - self.set_roosting(false).await; + self.set_roosting(false); } }) } diff --git a/pumpkin/src/entity/mob/blaze.rs b/pumpkin/src/entity/mob/blaze.rs index ff720eab4..e8e9b71db 100644 --- a/pumpkin/src/entity/mob/blaze.rs +++ b/pumpkin/src/entity/mob/blaze.rs @@ -16,7 +16,7 @@ pub struct BlazeEntity { } impl BlazeEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let entity = Arc::new(MobEntity::new(entity)); let zombie = Self { entity }; let mob_arc = Arc::new(zombie); @@ -25,8 +25,8 @@ impl BlazeEntity { Arc::downgrade(&mob_arc) }; { - let mut goal_selector = mob_arc.entity.goals_selector.lock().await; - let mut target_selector = mob_arc.entity.target_selector.lock().await; + let mut goal_selector = mob_arc.entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.entity.target_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); diff --git a/pumpkin/src/entity/mob/breeze.rs b/pumpkin/src/entity/mob/breeze.rs index 8938e3ac4..f121d8b1e 100644 --- a/pumpkin/src/entity/mob/breeze.rs +++ b/pumpkin/src/entity/mob/breeze.rs @@ -16,7 +16,7 @@ pub struct BreezeEntity { } impl BreezeEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let breeze = Self { mob_entity }; let mob_arc = Arc::new(breeze); @@ -26,7 +26,7 @@ impl BreezeEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(5, Box::new(WanderAroundGoal::new(1.0))); @@ -36,7 +36,7 @@ impl BreezeEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/cave_spider.rs b/pumpkin/src/entity/mob/cave_spider.rs index 7a5a5dbb4..1e585bbd4 100644 --- a/pumpkin/src/entity/mob/cave_spider.rs +++ b/pumpkin/src/entity/mob/cave_spider.rs @@ -10,8 +10,8 @@ pub struct CaveSpiderEntity { } impl CaveSpiderEntity { - pub async fn new(entity: Entity) -> Arc { - let spider = SpiderEntity::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let spider = SpiderEntity::new(entity); Arc::new(Self { spider }) } } diff --git a/pumpkin/src/entity/mob/creaking.rs b/pumpkin/src/entity/mob/creaking.rs index 66f36d4d9..ec06ab899 100644 --- a/pumpkin/src/entity/mob/creaking.rs +++ b/pumpkin/src/entity/mob/creaking.rs @@ -17,7 +17,7 @@ pub struct CreakingEntity { } impl CreakingEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let creaking = Self { mob_entity }; let mob_arc = Arc::new(creaking); @@ -27,7 +27,7 @@ impl CreakingEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl CreakingEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/creeper.rs b/pumpkin/src/entity/mob/creeper.rs index 30847e224..f6c2e36d7 100644 --- a/pumpkin/src/entity/mob/creeper.rs +++ b/pumpkin/src/entity/mob/creeper.rs @@ -41,7 +41,7 @@ pub struct CreeperEntity { } impl CreeperEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let entity = Self { mob_entity, @@ -60,8 +60,8 @@ impl CreeperEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); goal_selector.add_goal(1, Box::new(SwimGoal::default())); goal_selector.add_goal(2, Box::new(CreeperIgniteGoal::new(mob_arc.clone()))); @@ -84,7 +84,7 @@ impl CreeperEntity { mob_arc } - pub async fn set_fuse_speed(&self, speed: i32) { + pub fn set_fuse_speed(&self, speed: i32) { self.fuse_speed.store(speed, Ordering::Relaxed); self.mob_entity .living_entity @@ -93,8 +93,7 @@ impl CreeperEntity { TrackedData::FUSE_ID, MetaDataType::INTEGER, VarInt(speed), - )]) - .await; + )]); } async fn explode(&self) { @@ -169,7 +168,7 @@ impl Mob for CreeperEntity { ); if self.ignited.load(Ordering::Relaxed) { - self.set_fuse_speed(1).await; + self.set_fuse_speed(1); } let fuse_speed = self.fuse_speed.load(Ordering::Relaxed); @@ -177,15 +176,13 @@ impl Mob for CreeperEntity { if fuse_speed > 0 && current == 0 { let world = entity.world.load(); - world - .play_sound_fine( - Sound::EntityCreeperPrimed, - SoundCategory::Hostile, - &entity.pos.load(), - 1.0, - 0.5, - ) - .await; + world.play_sound_fine( + Sound::EntityCreeperPrimed, + SoundCategory::Hostile, + &entity.pos.load(), + 1.0, + 0.5, + ); } let fuse_time = self.fuse_time.load(Ordering::Relaxed); @@ -213,24 +210,20 @@ impl Mob for CreeperEntity { let world = entity.world.load(); let pos = entity.pos.load(); - world - .play_sound_fine( - Sound::ItemFlintandsteelUse, - SoundCategory::Hostile, - &pos, - 1.0, - rand::random::() * 0.4 + 0.8, - ) - .await; + world.play_sound_fine( + Sound::ItemFlintandsteelUse, + SoundCategory::Hostile, + &pos, + 1.0, + rand::random::() * 0.4 + 0.8, + ); self.ignited.store(true, Ordering::Relaxed); - entity - .send_meta_data(&[Metadata::new( - TrackedData::IS_IGNITED, - MetaDataType::BOOLEAN, - true, - )]) - .await; + entity.send_meta_data(&[Metadata::new( + TrackedData::IS_IGNITED, + MetaDataType::BOOLEAN, + true, + )]); if player.gamemode.load() != pumpkin_util::GameMode::Creative { // TODO: Handle DamageResult::Broken to broadcast item break and update player slot. diff --git a/pumpkin/src/entity/mob/elder_guardian.rs b/pumpkin/src/entity/mob/elder_guardian.rs index 48f90cb3b..3693d76c6 100644 --- a/pumpkin/src/entity/mob/elder_guardian.rs +++ b/pumpkin/src/entity/mob/elder_guardian.rs @@ -16,7 +16,7 @@ pub struct ElderGuardianEntity { } impl ElderGuardianEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let guardian = Self { mob_entity }; let mob_arc = Arc::new(guardian); @@ -26,7 +26,7 @@ impl ElderGuardianEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(WanderAroundGoal::new(1.0))); @@ -36,7 +36,7 @@ impl ElderGuardianEntity { ); goal_selector.add_goal(6, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/enderman.rs b/pumpkin/src/entity/mob/enderman.rs index 0144d17dd..e43ab2797 100644 --- a/pumpkin/src/entity/mob/enderman.rs +++ b/pumpkin/src/entity/mob/enderman.rs @@ -68,7 +68,7 @@ pub struct EndermanEntity { } impl EndermanEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let entity = Self { mob_entity, @@ -83,14 +83,14 @@ impl EndermanEntity { Arc::downgrade(&mob_arc) }; - let mut navigator = mob_arc.mob_entity.navigator.lock().await; + let mut navigator = mob_arc.mob_entity.navigator.lock().unwrap(); navigator.set_mob_dimensions(0.6, 2.9); navigator.set_pathfinding_malus(PathType::Water, -1.0); drop(navigator); { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(ChasePlayerGoal::new(mob_arc.clone()))); @@ -115,7 +115,7 @@ impl EndermanEntity { mob_arc } - pub async fn teleport_randomly(&self) -> bool { + pub fn teleport_randomly(&self) -> bool { let entity = &self.mob_entity.living_entity.entity; let pos = entity.pos.load(); let (x, y, z) = { @@ -127,10 +127,10 @@ impl EndermanEntity { ) }; - self.teleport_to(x, y, z).await + self.teleport_to(x, y, z) } - pub async fn teleport_towards(&self, target: &dyn EntityBase) -> bool { + pub fn teleport_towards(&self, target: &dyn EntityBase) -> bool { let entity = &self.mob_entity.living_entity.entity; let pos = entity.pos.load(); let target_pos = target.get_entity().pos.load(); @@ -156,10 +156,10 @@ impl EndermanEntity { ) }; - self.teleport_to(x, y, z).await + self.teleport_to(x, y, z) } - pub async fn teleport_to(&self, x: f64, y: f64, z: f64) -> bool { + pub fn teleport_to(&self, x: f64, y: f64, z: f64) -> bool { let entity = &self.mob_entity.living_entity.entity; let origin = entity.pos.load(); let world = entity.world.load(); @@ -174,7 +174,7 @@ impl EndermanEntity { let mut found_ground = false; loop { let below_pos = BlockPos::new(block_x, block_y - 1, block_z); - let below_state = world.get_block_state(&below_pos).await; + let below_state = world.get_block_state(&below_pos); if below_state.is_solid() { found_ground = true; break; @@ -191,7 +191,7 @@ impl EndermanEntity { } let dest_pos = BlockPos::new(block_x, block_y, block_z); - let dest_fluid = world.get_fluid(&dest_pos).await; + let dest_fluid = world.get_fluid(&dest_pos); if dest_fluid.has_tag(&tag::Fluid::MINECRAFT_WATER) { return false; } @@ -202,41 +202,35 @@ impl EndermanEntity { Vector3::new(x - half_width, target_y, z - half_width), Vector3::new(x + half_width, target_y + height, z + half_width), ); - if !world.is_space_empty(bb).await { + if !world.is_space_empty(bb) { return false; } let new_pos = Vector3::new(x, target_y, z); for pos in &[origin, new_pos] { - world - .spawn_particle( - *pos, - Vector3::new(0.0, 0.0, 0.0), - 0.0, - 128, - Particle::Portal, - ) - .await; - world - .play_sound(Sound::EntityEndermanTeleport, SoundCategory::Hostile, pos) - .await; + world.spawn_particle( + *pos, + Vector3::new(0.0, 0.0, 0.0), + 0.0, + 128, + Particle::Portal, + ); + world.play_sound(Sound::EntityEndermanTeleport, SoundCategory::Hostile, pos); } entity.set_pos(new_pos); - world - .broadcast_packet_all(&CEntityPositionSync::new( - entity.entity_id.into(), - new_pos, - Vector3::new(0.0, 0.0, 0.0), - entity.yaw.load(), - entity.pitch.load(), - entity.on_ground.load(Ordering::Relaxed), - )) - .await; + world.broadcast_packet_all(&CEntityPositionSync::new( + entity.entity_id.into(), + new_pos, + Vector3::new(0.0, 0.0, 0.0), + entity.yaw.load(), + entity.pitch.load(), + entity.on_ground.load(Ordering::Relaxed), + )); - self.mob_entity.navigator.lock().await.stop(); + self.mob_entity.navigator.lock().unwrap().stop(); true } @@ -247,7 +241,7 @@ impl EndermanEntity { drop(mob_target); if target.is_some() { - self.set_angry(true).await; + self.set_angry(true); // Use attribute modifier instead of direct speed arithmetic if !self.speed_boosted.swap(true, Ordering::Relaxed) { let living = &self.mob_entity.living_entity; @@ -268,8 +262,8 @@ impl EndermanEntity { .await; } } else { - self.set_angry(false).await; - self.set_provoked(false).await; + self.set_angry(false); + self.set_provoked(false); if self.speed_boosted.swap(false, Ordering::Relaxed) { let living = &self.mob_entity.living_entity; @@ -286,7 +280,7 @@ impl EndermanEntity { } } - pub async fn set_angry(&self, angry: bool) { + pub fn set_angry(&self, angry: bool) { self.angry.store(angry, Ordering::Relaxed); self.mob_entity .living_entity @@ -295,15 +289,14 @@ impl EndermanEntity { TrackedData::CREEPY, MetaDataType::BOOLEAN, angry, - )]) - .await; + )]); } pub fn is_angry(&self) -> bool { self.angry.load(Ordering::Relaxed) } - pub async fn set_provoked(&self, provoked: bool) { + pub fn set_provoked(&self, provoked: bool) { self.provoked.store(provoked, Ordering::Relaxed); self.mob_entity .living_entity @@ -312,11 +305,10 @@ impl EndermanEntity { TrackedData::STARED_AT, MetaDataType::BOOLEAN, provoked, - )]) - .await; + )]); } - pub async fn set_carried_block(&self, block_state: Option) { + pub fn set_carried_block(&self, block_state: Option) { self.carried_block.store(block_state); let value = block_state.map_or(VarInt(0), |id| VarInt(id as i32)); self.mob_entity @@ -326,8 +318,7 @@ impl EndermanEntity { TrackedData::CARRY_STATE, MetaDataType::OPTIONAL_BLOCK_STATE, value, - )]) - .await; + )]); } pub fn get_carried_block(&self) -> Option { @@ -389,7 +380,7 @@ impl EndermanEntity { let world = entity.world.load(); world .raycast(enderman_eye_pos, player_eye_pos, async |block_pos, w| { - let state = w.get_block_state(block_pos).await; + let state = w.get_block_state(block_pos); state.is_solid() }) .await @@ -411,7 +402,7 @@ impl NBTStorage for EndermanEntity { Box::pin(async { self.mob_entity.living_entity.read_nbt_non_mut(nbt).await; if let Some(block_state) = nbt.get_int("carriedBlockState") { - self.set_carried_block(Some(block_state as u16)).await; + self.set_carried_block(Some(block_state as u16)); } }) } @@ -460,7 +451,7 @@ impl Mob for EndermanEntity { Box::pin(async move { if is_projectile { for _ in 0..64 { - if self.teleport_randomly().await { + if self.teleport_randomly() { return false; } } @@ -480,7 +471,7 @@ impl Mob for EndermanEntity { } let should_teleport = self.get_random().random_range(0..10) != 0; if should_teleport { - self.teleport_randomly().await; + self.teleport_randomly(); } }) } diff --git a/pumpkin/src/entity/mob/endermite.rs b/pumpkin/src/entity/mob/endermite.rs index 68aac38fa..b804b31cb 100644 --- a/pumpkin/src/entity/mob/endermite.rs +++ b/pumpkin/src/entity/mob/endermite.rs @@ -17,7 +17,7 @@ pub struct EndermiteEntity { } impl EndermiteEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let endermite = Self { mob_entity }; let mob_arc = Arc::new(endermite); @@ -27,7 +27,7 @@ impl EndermiteEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl EndermiteEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/evoker.rs b/pumpkin/src/entity/mob/evoker.rs index 3d8d9a3c9..09842c8f0 100644 --- a/pumpkin/src/entity/mob/evoker.rs +++ b/pumpkin/src/entity/mob/evoker.rs @@ -16,7 +16,7 @@ pub struct EvokerEntity { } impl EvokerEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let evoker = Self { mob_entity }; let mob_arc = Arc::new(evoker); @@ -26,7 +26,7 @@ impl EvokerEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); // Evokers have complex spell AI, but for now basic movement @@ -37,7 +37,7 @@ impl EvokerEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/ghast.rs b/pumpkin/src/entity/mob/ghast.rs index 1462e58be..2ceb817f7 100644 --- a/pumpkin/src/entity/mob/ghast.rs +++ b/pumpkin/src/entity/mob/ghast.rs @@ -14,7 +14,7 @@ pub struct GhastEntity { } impl GhastEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let ghast = Self { mob_entity, @@ -29,7 +29,7 @@ impl GhastEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(7, Box::new(GhastLookGoal::new(mob_weak.clone()))); }; @@ -94,7 +94,7 @@ impl Goal for GhastLookGoal { let target_pos = target.get_entity().pos.load(); if mob_pos.squared_distance_to_vec(&target_pos) < 4096.0 { - let mut look_control = mob_entity.look_control.lock().await; + let mut look_control = mob_entity.look_control.lock().unwrap(); look_control.look_at(mob, target_pos.x, target_pos.y, target_pos.z); } } else { diff --git a/pumpkin/src/entity/mob/giant.rs b/pumpkin/src/entity/mob/giant.rs index 52e5a427f..0776b5d16 100644 --- a/pumpkin/src/entity/mob/giant.rs +++ b/pumpkin/src/entity/mob/giant.rs @@ -16,20 +16,20 @@ pub struct GiantEntity { } impl GiantEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let giant = Self { mob_entity }; let mob_arc = Arc::new(giant); { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(2, Box::new(MeleeAttackGoal::new(1.0, true))); goal_selector.add_goal(5, Box::new(WanderAroundGoal::new(1.0))); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/guardian.rs b/pumpkin/src/entity/mob/guardian.rs index ba867d038..3a67ecd3b 100644 --- a/pumpkin/src/entity/mob/guardian.rs +++ b/pumpkin/src/entity/mob/guardian.rs @@ -16,7 +16,7 @@ pub struct GuardianEntity { } impl GuardianEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let guardian = Self { mob_entity }; let mob_arc = Arc::new(guardian); @@ -26,7 +26,7 @@ impl GuardianEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(WanderAroundGoal::new(1.0))); @@ -36,7 +36,7 @@ impl GuardianEntity { ); goal_selector.add_goal(6, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/hoglin.rs b/pumpkin/src/entity/mob/hoglin.rs index bfb48b58f..32138ada1 100644 --- a/pumpkin/src/entity/mob/hoglin.rs +++ b/pumpkin/src/entity/mob/hoglin.rs @@ -17,7 +17,7 @@ pub struct HoglinEntity { } impl HoglinEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let hoglin = Self { mob_entity }; let mob_arc = Arc::new(hoglin); @@ -27,7 +27,7 @@ impl HoglinEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl HoglinEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/illusioner.rs b/pumpkin/src/entity/mob/illusioner.rs index 79a49c535..9e9f7d22c 100644 --- a/pumpkin/src/entity/mob/illusioner.rs +++ b/pumpkin/src/entity/mob/illusioner.rs @@ -16,7 +16,7 @@ pub struct IllusionerEntity { } impl IllusionerEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let illusioner = Self { mob_entity }; let mob_arc = Arc::new(illusioner); @@ -26,7 +26,7 @@ impl IllusionerEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(5, Box::new(WanderAroundGoal::new(1.0))); @@ -36,7 +36,7 @@ impl IllusionerEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/magma_cube.rs b/pumpkin/src/entity/mob/magma_cube.rs index 106bf2216..0a3d068f4 100644 --- a/pumpkin/src/entity/mob/magma_cube.rs +++ b/pumpkin/src/entity/mob/magma_cube.rs @@ -10,8 +10,8 @@ pub struct MagmaCubeEntity { } impl MagmaCubeEntity { - pub async fn new(entity: Entity) -> Arc { - let slime = SlimeEntity::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let slime = SlimeEntity::new(entity); Arc::new(Self { slime }) } } diff --git a/pumpkin/src/entity/mob/mod.rs b/pumpkin/src/entity/mob/mod.rs index ca541bb90..26aa701e0 100644 --- a/pumpkin/src/entity/mob/mod.rs +++ b/pumpkin/src/entity/mob/mod.rs @@ -25,7 +25,6 @@ use std::pin::Pin; use std::sync::Arc; use std::sync::atomic::Ordering::Relaxed; use std::sync::atomic::{AtomicI32, AtomicU8, Ordering}; -use tokio::sync::Mutex; use uuid::Uuid; pub mod bat; @@ -64,11 +63,11 @@ pub mod zombified_piglin; pub struct MobEntity { pub living_entity: LivingEntity, - pub goals_selector: Mutex, - pub target_selector: Mutex, - pub navigator: Mutex, - pub target: Mutex>>, - pub look_control: Mutex, + pub goals_selector: std::sync::Mutex, + pub target_selector: std::sync::Mutex, + pub navigator: std::sync::Mutex, + pub target: tokio::sync::Mutex>>, + pub look_control: std::sync::Mutex, pub position_target: AtomicCell, pub position_target_range: AtomicI32, pub love_ticks: AtomicI32, @@ -90,11 +89,11 @@ impl MobEntity { pub fn new(entity: Entity) -> Self { Self { living_entity: LivingEntity::new(entity), - goals_selector: Mutex::new(GoalSelector::default()), - target_selector: Mutex::new(GoalSelector::default()), - navigator: Mutex::new(Navigator::default()), - target: Mutex::new(None), - look_control: Mutex::new(LookControl::default()), + goals_selector: std::sync::Mutex::new(GoalSelector::default()), + target_selector: std::sync::Mutex::new(GoalSelector::default()), + navigator: std::sync::Mutex::new(Navigator::default()), + target: tokio::sync::Mutex::new(None), + look_control: std::sync::Mutex::new(LookControl::default()), position_target: AtomicCell::new(BlockPos::ZERO), position_target_range: AtomicI32::new(-1), love_ticks: AtomicI32::new(0), @@ -120,11 +119,11 @@ impl MobEntity { } } - pub async fn set_attacking(&self, attacking: bool) { - self.set_mob_flag(Self::ATTACKING_FLAG, attacking).await; + pub fn set_attacking(&self, attacking: bool) { + self.set_mob_flag(Self::ATTACKING_FLAG, attacking); } - async fn set_mob_flag(&self, flag: u8, value: bool) { + fn set_mob_flag(&self, flag: u8, value: bool) { let old_b = self.mob_flags.load(Ordering::Relaxed); let new_b = if value { old_b | flag } else { old_b & !flag }; @@ -132,14 +131,11 @@ impl MobEntity { if new_b != old_b { self.mob_flags.store(new_b, Ordering::Relaxed); - self.living_entity - .entity - .send_meta_data(&[Metadata::new( - TrackedData::MOB_FLAGS_ID, - MetaDataType::BYTE, - new_b, - )]) - .await; + self.living_entity.entity.send_meta_data(&[Metadata::new( + TrackedData::MOB_FLAGS_ID, + MetaDataType::BYTE, + new_b, + )]); } } @@ -187,8 +183,8 @@ impl MobEntity { true } - pub async fn is_dark_enough_to_spawn(world: &World, pos: &BlockPos) -> bool { - let sky_light = world.get_sky_light_level(pos).await; + pub fn is_dark_enough_to_spawn(world: &World, pos: &BlockPos, is_thundering: bool) -> bool { + let sky_light = world.get_sky_light_level_sync(pos); if sky_light > rand::random_range(0..32) { return false; } @@ -196,12 +192,12 @@ impl MobEntity { let dimension = &world.dimension; let block_light_limit = dimension.monster_spawn_block_light_limit; - let block_light = world.get_block_light_level(pos).await.unwrap(); + let block_light = world.get_block_light_level_sync(pos).unwrap(); if block_light_limit < 15 && block_light > block_light_limit { return false; } - let current_brightness = if world.is_thundering().await { + let current_brightness = if is_thundering { (sky_light - 10).max(block_light) } else { sky_light.max(block_light) @@ -212,12 +208,12 @@ impl MobEntity { current_brightness <= dimension.monster_spawn_light_level.get(&mut random) as u8 } - pub async fn check_monster_spawn_rules(world: &World, pos: &BlockPos) -> bool { + pub fn check_monster_spawn_rules(world: &World, pos: &BlockPos, is_thundering: bool) -> bool { if world.level_info.load().difficulty == Difficulty::Peaceful { return false; } - if !Self::is_dark_enough_to_spawn(world, pos).await { + if !Self::is_dark_enough_to_spawn(world, pos, is_thundering) { return false; } @@ -328,9 +324,7 @@ impl MobEntity { } let pos = entity.pos.load(); - let top_y = world - .get_top_block(Vector2::new(pos.x as i32, pos.z as i32)) - .await; + let top_y = world.get_top_block(Vector2::new(pos.x as i32, pos.z as i32)); if (entity.get_eye_y() as i32) < top_y { return false; } @@ -463,39 +457,56 @@ impl EntityBase for T { self.mob_tick(caller).await; - // AI runs before physics (vanilla order: goals → navigator → look → physics) let age = mob_entity.living_entity.entity.age.load(Relaxed); - if (age + mob_entity.living_entity.entity.entity_id) % 2 != 0 && age > 1 { - mob_entity - .target_selector - .lock() - .await - .tick_goals(self, false) - .await; - mob_entity - .goals_selector - .lock() - .await - .tick_goals(self, false) - .await; + let entity_id = mob_entity.living_entity.entity.entity_id; + + // 1. "Take" selectors out of the mutexes + let mut target_selector = { + let mut guard = mob_entity.target_selector.lock().unwrap(); + std::mem::take(&mut *guard) + }; + let mut goals_selector = { + let mut guard = mob_entity.goals_selector.lock().unwrap(); + std::mem::take(&mut *guard) + }; + + // 2. Perform AI logic (No locks held, so .await is safe!) + if (age + entity_id) % 2 != 0 && age > 1 { + target_selector.tick_goals(self, false).await; + goals_selector.tick_goals(self, false).await; } else { - mob_entity.target_selector.lock().await.tick(self).await; - mob_entity.goals_selector.lock().await.tick(self).await; + target_selector.tick(self).await; + goals_selector.tick(self).await; } - let mut navigator = mob_entity.navigator.lock().await; - navigator.tick(&mob_entity.living_entity).await; - drop(navigator); + // 3. "Put back" selectors + { + *mob_entity.target_selector.lock().unwrap() = target_selector; + *mob_entity.goals_selector.lock().unwrap() = goals_selector; + }; - let mut look_control = mob_entity.look_control.lock().await; - look_control.tick(self); - drop(look_control); + // 4. Repeat for Navigator + let mut navigator = { + let mut guard = mob_entity.navigator.lock().unwrap(); + std::mem::take(&mut *guard) + }; + + navigator.tick(&mob_entity.living_entity).await; + + { + *mob_entity.navigator.lock().unwrap() = navigator; + }; + + // Look Control is synchronous, so we can just use a normal block + { + let mut look_control = mob_entity.look_control.lock().unwrap(); + look_control.tick(self); + }; mob_entity.living_entity.tick(caller, server).await; - self.post_tick().await; - // Send rotation packets after look_control finalizes head_yaw and pitch + // --- Packet logic remains the same --- let entity = &mob_entity.living_entity.entity; let yaw = (entity.yaw.load() * 256.0 / 360.0).rem_euclid(256.0) as u8; let pitch = (entity.pitch.load() * 256.0 / 360.0).rem_euclid(256.0) as u8; @@ -507,23 +518,19 @@ impl EntityBase for T { if yaw.abs_diff(last_yaw) >= 1 || pitch.abs_diff(last_pitch) >= 1 { let world = entity.world.load(); - world - .broadcast_packet_all(&CUpdateEntityRot::new( - entity.entity_id.into(), - yaw, - pitch, - entity.on_ground.load(Relaxed), - )) - .await; + world.broadcast_packet_all(&CUpdateEntityRot::new( + entity.entity_id.into(), + yaw, + pitch, + entity.on_ground.load(Relaxed), + )); mob_entity.last_sent_yaw.store(yaw, Relaxed); mob_entity.last_sent_pitch.store(pitch, Relaxed); } if head_yaw.abs_diff(last_head_yaw) >= 1 { let world = entity.world.load(); - world - .broadcast_packet_all(&CHeadRot::new(entity.entity_id.into(), head_yaw)) - .await; + world.broadcast_packet_all(&CHeadRot::new(entity.entity_id.into(), head_yaw)); mob_entity.last_sent_head_yaw.store(head_yaw, Relaxed); } }) @@ -656,7 +663,7 @@ pub trait PathAwareEntity: Mob + Send + Sync { fn is_navigation<'a>(&'a self) -> Pin + Send + 'a>> { Box::pin(async { - let navigator = self.get_mob_entity().navigator.lock().await; + let navigator = self.get_mob_entity().navigator.lock().unwrap(); !navigator.is_idle() }) } diff --git a/pumpkin/src/entity/mob/phantom.rs b/pumpkin/src/entity/mob/phantom.rs index 463ab18b0..5e72f510c 100644 --- a/pumpkin/src/entity/mob/phantom.rs +++ b/pumpkin/src/entity/mob/phantom.rs @@ -13,7 +13,7 @@ pub struct PhantomEntity { } impl PhantomEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let phantom = Self { mob_entity }; let mob_arc = Arc::new(phantom); @@ -23,7 +23,7 @@ impl PhantomEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); // TODO: PhantomCircleAroundAnchorGoal, PhantomSweepAttackGoal goal_selector.add_goal( diff --git a/pumpkin/src/entity/mob/piglin.rs b/pumpkin/src/entity/mob/piglin.rs index a7f2c69b0..a0dc14b6f 100644 --- a/pumpkin/src/entity/mob/piglin.rs +++ b/pumpkin/src/entity/mob/piglin.rs @@ -17,7 +17,7 @@ pub struct PiglinEntity { } impl PiglinEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let piglin = Self { mob_entity }; let mob_arc = Arc::new(piglin); @@ -27,7 +27,7 @@ impl PiglinEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); // Piglins use crossbows or swords, but for now we give them melee @@ -39,7 +39,7 @@ impl PiglinEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/piglin_brute.rs b/pumpkin/src/entity/mob/piglin_brute.rs index efa3b3078..2a7f291e8 100644 --- a/pumpkin/src/entity/mob/piglin_brute.rs +++ b/pumpkin/src/entity/mob/piglin_brute.rs @@ -17,7 +17,7 @@ pub struct PiglinBruteEntity { } impl PiglinBruteEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let piglin = Self { mob_entity }; let mob_arc = Arc::new(piglin); @@ -27,7 +27,7 @@ impl PiglinBruteEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(2, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl PiglinBruteEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/pillager.rs b/pumpkin/src/entity/mob/pillager.rs index aa4dca959..8c3b9dce6 100644 --- a/pumpkin/src/entity/mob/pillager.rs +++ b/pumpkin/src/entity/mob/pillager.rs @@ -17,7 +17,7 @@ pub struct PillagerEntity { } impl PillagerEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let pillager = Self { mob_entity }; let mob_arc = Arc::new(pillager); @@ -27,7 +27,7 @@ impl PillagerEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); // Pillagers use crossbows, but for now we give them melee @@ -39,7 +39,7 @@ impl PillagerEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/ravager.rs b/pumpkin/src/entity/mob/ravager.rs index 8bdc99c46..aa075095f 100644 --- a/pumpkin/src/entity/mob/ravager.rs +++ b/pumpkin/src/entity/mob/ravager.rs @@ -17,7 +17,7 @@ pub struct RavagerEntity { } impl RavagerEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let ravager = Self { mob_entity }; let mob_arc = Arc::new(ravager); @@ -27,7 +27,7 @@ impl RavagerEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl RavagerEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/shulker.rs b/pumpkin/src/entity/mob/shulker.rs index 267748011..ab450dcba 100644 --- a/pumpkin/src/entity/mob/shulker.rs +++ b/pumpkin/src/entity/mob/shulker.rs @@ -64,7 +64,7 @@ pub struct ShulkerEntity { } impl ShulkerEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let shulker = Self { mob_entity, @@ -81,8 +81,8 @@ impl ShulkerEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); goal_selector.add_goal( 1, @@ -107,60 +107,52 @@ impl ShulkerEntity { .unwrap_or(DEFAULT_ATTACH_FACE) } - async fn set_attach_face(&self, face: BlockDirection) { + fn set_attach_face(&self, face: BlockDirection) { self.attach_face.store(face as u8, Ordering::Relaxed); let entity = &self.mob_entity.living_entity.entity; - entity - .send_meta_data(&[Metadata::new( - TrackedData::ATTACH_FACE_ID, - MetaDataType::DIRECTION, - VarInt(face as i32), - )]) - .await; + entity.send_meta_data(&[Metadata::new( + TrackedData::ATTACH_FACE_ID, + MetaDataType::DIRECTION, + VarInt(face as i32), + )]); } pub fn get_raw_peek(&self) -> u8 { self.peek_amount.load(Ordering::Relaxed) } - pub async fn set_raw_peek(&self, amount: u8) { + pub fn set_raw_peek(&self, amount: u8) { let entity = &self.mob_entity.living_entity.entity; let world = entity.world.load(); let pos = entity.pos.load(); if amount == 0 { // Closed from open state - world - .play_sound_fine( - Sound::EntityShulkerClose, - SoundCategory::Hostile, - &pos, - 1.0, - 1.0, - ) - .await; + world.play_sound_fine( + Sound::EntityShulkerClose, + SoundCategory::Hostile, + &pos, + 1.0, + 1.0, + ); } else if self.peek_amount.load(Ordering::Relaxed) == 0 { // Opened from closed state - world - .play_sound_fine( - Sound::EntityShulkerOpen, - SoundCategory::Hostile, - &pos, - 1.0, - 1.0, - ) - .await; + world.play_sound_fine( + Sound::EntityShulkerOpen, + SoundCategory::Hostile, + &pos, + 1.0, + 1.0, + ); } self.peek_amount.store(amount, Ordering::Relaxed); - entity - .send_meta_data(&[Metadata::new( - TrackedData::PEEK_ID, - MetaDataType::BYTE, - amount, - )]) - .await; + entity.send_meta_data(&[Metadata::new( + TrackedData::PEEK_ID, + MetaDataType::BYTE, + amount, + )]); } pub fn is_closed(&self) -> bool { @@ -190,12 +182,12 @@ impl ShulkerEntity { /// Returns `Some(direction)` if the neighbour block in that direction from /// `pos` is solid (the shulker can attach there). - async fn find_attachable_face(&self, pos: &BlockPos) -> Option { + fn find_attachable_face(&self, pos: &BlockPos) -> Option { let entity = &self.mob_entity.living_entity.entity; let world = entity.world.load(); for dir in BlockDirection::all() { let neighbour = pos.offset_direction(dir); - let state = world.get_block_state(&neighbour).await; + let state = world.get_block_state(&neighbour); if state.is_solid() { return Some(dir); } @@ -205,27 +197,27 @@ impl ShulkerEntity { /// Check whether the shulker can stay where it is. /// The block at `pos` must be free (air) and the block in the `face` direction from `pos` must be solid. - async fn can_stay_at(&self, pos: &BlockPos, face: BlockDirection) -> bool { + fn can_stay_at(&self, pos: &BlockPos, face: BlockDirection) -> bool { let entity = &self.mob_entity.living_entity.entity; let world = entity.world.load(); // Shulker's own block must not be occupied - let own_state = world.get_block_state(pos).await; + let own_state = world.get_block_state(pos); if !own_state.is_air() { return false; } // The block the shulker is attached to must still be solid let neighbour = pos.offset_direction(face); - let state = world.get_block_state(&neighbour).await; + let state = world.get_block_state(&neighbour); state.is_solid() } /// Try to find a new attachment point, cascading to a random teleport. async fn find_new_attachment(&self) { let pos = self.mob_entity.living_entity.entity.block_pos.load(); - if let Some(dir) = self.find_attachable_face(&pos).await { - self.set_attach_face(dir).await; + if let Some(dir) = self.find_attachable_face(&pos) { + self.set_attach_face(dir); } else { self.teleport_somewhere().await; } @@ -257,46 +249,42 @@ impl ShulkerEntity { let candidate = BlockPos::new(base_pos.0.x + dx, base_pos.0.y + dy, base_pos.0.z + dz); // Target block must be air and there must be an attachable adjacent solid face. - let candidate_state = world.get_block_state(&candidate).await; + let candidate_state = world.get_block_state(&candidate); if !candidate_state.is_air() { continue; } - if let Some(dir) = self.find_attachable_face(&candidate).await { + if let Some(dir) = self.find_attachable_face(&candidate) { let new_pos = Vector3::new( f64::from(candidate.0.x) + 0.5, f64::from(candidate.0.y), f64::from(candidate.0.z) + 0.5, ); - self.set_attach_face(dir).await; + self.set_attach_face(dir); entity.set_pos(new_pos); - world - .broadcast_packet_all(&CEntityPositionSync::new( - entity.entity_id.into(), - new_pos, - Vector3::new(0.0, 0.0, 0.0), - entity.yaw.load(), - entity.pitch.load(), - entity.on_ground.load(Ordering::Relaxed), - )) - .await; + world.broadcast_packet_all(&CEntityPositionSync::new( + entity.entity_id.into(), + new_pos, + Vector3::new(0.0, 0.0, 0.0), + entity.yaw.load(), + entity.pitch.load(), + entity.on_ground.load(Ordering::Relaxed), + )); entity.last_sent_pos.store(new_pos); - world - .play_sound_fine( - Sound::EntityShulkerTeleport, - SoundCategory::Hostile, - &new_pos, - 1.0, - 1.0, - ) - .await; + world.play_sound_fine( + Sound::EntityShulkerTeleport, + SoundCategory::Hostile, + &new_pos, + 1.0, + 1.0, + ); // Close the shulker and drop the current target after teleport. - self.set_raw_peek(0).await; + self.set_raw_peek(0); self.mob_entity.target.lock().await.take(); return true; @@ -370,7 +358,7 @@ impl Mob for ShulkerEntity { // Ensure the current attachment face still has a solid block behind it. let pos = entity.block_pos.load(); let face = self.get_attach_face(); - if !self.can_stay_at(&pos, face).await { + if !self.can_stay_at(&pos, face) { self.find_new_attachment().await; } }) @@ -452,13 +440,13 @@ impl Goal for ShulkerAttackGoal { fn start<'a>(&'a mut self, _mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async move { self.attack_cooldown.store(20, Ordering::Relaxed); - self.shulker.set_raw_peek(100).await; + self.shulker.set_raw_peek(100); }) } fn stop<'a>(&'a mut self, _mob: &'a dyn Mob) -> GoalFuture<'a, ()> { Box::pin(async move { - self.shulker.set_raw_peek(0).await; + self.shulker.set_raw_peek(0); }) } @@ -514,15 +502,13 @@ impl Goal for ShulkerAttackGoal { // Shoot sound (random pitch) let pitch = 1.0 + (mob.get_random().random::() - mob.get_random().random::()) * 0.2; - world - .play_sound_fine( - Sound::EntityShulkerShoot, - SoundCategory::Hostile, - &shulker_pos, - 2.0, - pitch, - ) - .await; + world.play_sound_fine( + Sound::EntityShulkerShoot, + SoundCategory::Hostile, + &shulker_pos, + 2.0, + pitch, + ); } }) } @@ -554,7 +540,7 @@ impl Goal for ShulkerPeekGoal { } let pos = mob.get_mob_entity().living_entity.entity.block_pos.load(); let face = self.shulker.get_attach_face(); - self.shulker.can_stay_at(&pos, face).await + self.shulker.can_stay_at(&pos, face) }) } @@ -569,7 +555,7 @@ impl Goal for ShulkerPeekGoal { Box::pin(async move { let duration = 20 * (1 + mob.get_random().random_range(0..3)); self.peek_time.store(duration, Ordering::Relaxed); - self.shulker.set_raw_peek(30).await; + self.shulker.set_raw_peek(30); }) } @@ -577,7 +563,7 @@ impl Goal for ShulkerPeekGoal { Box::pin(async move { let has_target = self.shulker.mob_entity.target.lock().await.is_some(); if !has_target { - self.shulker.set_raw_peek(0).await; + self.shulker.set_raw_peek(0); } }) } diff --git a/pumpkin/src/entity/mob/silverfish.rs b/pumpkin/src/entity/mob/silverfish.rs index bb0c9923e..198afbbf7 100644 --- a/pumpkin/src/entity/mob/silverfish.rs +++ b/pumpkin/src/entity/mob/silverfish.rs @@ -17,7 +17,7 @@ pub struct SilverfishEntity { } impl SilverfishEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let entity = Arc::new(MobEntity::new(entity)); let silverfish = Self { entity }; let mob_arc = Arc::new(silverfish); @@ -27,8 +27,8 @@ impl SilverfishEntity { }; { - let mut goal_selector = mob_arc.entity.goals_selector.lock().await; - let mut target_selector = mob_arc.entity.target_selector.lock().await; + let mut goal_selector = mob_arc.entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.entity.target_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(MeleeAttackGoal::new(1.0, false))); diff --git a/pumpkin/src/entity/mob/skeleton/bogged.rs b/pumpkin/src/entity/mob/skeleton/bogged.rs index 56d89e4f9..243a45025 100644 --- a/pumpkin/src/entity/mob/skeleton/bogged.rs +++ b/pumpkin/src/entity/mob/skeleton/bogged.rs @@ -9,8 +9,8 @@ pub struct BoggedSkeletonEntity { } impl BoggedSkeletonEntity { - pub async fn new(entity: Entity) -> Arc { - let entity = SkeletonEntityBase::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let entity = SkeletonEntityBase::new(entity); let bogged = Self { entity }; Arc::new(bogged) } diff --git a/pumpkin/src/entity/mob/skeleton/mod.rs b/pumpkin/src/entity/mob/skeleton/mod.rs index 2d115beca..249c420a8 100644 --- a/pumpkin/src/entity/mob/skeleton/mod.rs +++ b/pumpkin/src/entity/mob/skeleton/mod.rs @@ -25,7 +25,7 @@ pub struct SkeletonEntityBase { } impl SkeletonEntityBase { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let mob = Self { mob_entity }; let mob_arc = Arc::new(mob); @@ -34,17 +34,17 @@ impl SkeletonEntityBase { Arc::downgrade(&mob_arc) }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(2, Box::new(MeleeAttackGoal::new(1.2, false))); - goal_selector.add_goal(5, Box::new(WanderAroundGoal::new(1.0))); + goal_selector.add_goal(7, Box::new(WanderAroundGoal::new(1.0))); goal_selector.add_goal( - 6, + 8, LookAtEntityGoal::with_default(mob_weak, &EntityType::PLAYER, 8.0), ); - goal_selector.add_goal(6, Box::new(RandomLookAroundGoal::default())); + goal_selector.add_goal(8, Box::new(RandomLookAroundGoal::default())); target_selector.add_goal(1, Box::new(RevengeGoal::new(true))); target_selector.add_goal( diff --git a/pumpkin/src/entity/mob/skeleton/parched.rs b/pumpkin/src/entity/mob/skeleton/parched.rs index 851b16788..85e411711 100644 --- a/pumpkin/src/entity/mob/skeleton/parched.rs +++ b/pumpkin/src/entity/mob/skeleton/parched.rs @@ -10,8 +10,8 @@ pub struct ParchedSkeletonEntity { } impl ParchedSkeletonEntity { - pub async fn new(entity: Entity) -> Arc { - let entity = SkeletonEntityBase::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let entity = SkeletonEntityBase::new(entity); let parched = Self { entity }; Arc::new(parched) } diff --git a/pumpkin/src/entity/mob/skeleton/skeleton.rs b/pumpkin/src/entity/mob/skeleton/skeleton.rs index 8b1532f6c..8ab127352 100644 --- a/pumpkin/src/entity/mob/skeleton/skeleton.rs +++ b/pumpkin/src/entity/mob/skeleton/skeleton.rs @@ -10,8 +10,8 @@ pub struct SkeletonEntity { } impl SkeletonEntity { - pub async fn new(entity: Entity) -> Arc { - let entity = SkeletonEntityBase::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let entity = SkeletonEntityBase::new(entity); let skeleton = Self { entity }; Arc::new(skeleton) } diff --git a/pumpkin/src/entity/mob/skeleton/stray.rs b/pumpkin/src/entity/mob/skeleton/stray.rs index 0c6014ef5..a466140dc 100644 --- a/pumpkin/src/entity/mob/skeleton/stray.rs +++ b/pumpkin/src/entity/mob/skeleton/stray.rs @@ -10,8 +10,8 @@ pub struct StraySkeletonEntity { } impl StraySkeletonEntity { - pub async fn new(entity: Entity) -> Arc { - let entity = SkeletonEntityBase::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let entity = SkeletonEntityBase::new(entity); let stray = Self { entity }; Arc::new(stray) } diff --git a/pumpkin/src/entity/mob/skeleton/wither.rs b/pumpkin/src/entity/mob/skeleton/wither.rs index 9368f3f94..753b0d543 100644 --- a/pumpkin/src/entity/mob/skeleton/wither.rs +++ b/pumpkin/src/entity/mob/skeleton/wither.rs @@ -10,10 +10,10 @@ pub struct WitherSkeletonEntity { } impl WitherSkeletonEntity { - pub async fn new(entity: Entity) -> Arc { - let entity = SkeletonEntityBase::new(entity).await; - let zombie = Self { entity }; - Arc::new(zombie) + pub fn new(entity: Entity) -> Arc { + let entity = SkeletonEntityBase::new(entity); + let skeleton = Self { entity }; + Arc::new(skeleton) } } diff --git a/pumpkin/src/entity/mob/slime.rs b/pumpkin/src/entity/mob/slime.rs index cab155fc9..ed6ecf267 100644 --- a/pumpkin/src/entity/mob/slime.rs +++ b/pumpkin/src/entity/mob/slime.rs @@ -19,7 +19,7 @@ pub struct SlimeEntity { } impl SlimeEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let slime = Self { entity: Arc::new(mob_entity), @@ -31,8 +31,8 @@ impl SlimeEntity { }; { - let mut goal_selector = mob_arc.entity.goals_selector.lock().await; - let mut target_selector = mob_arc.entity.target_selector.lock().await; + let mut goal_selector = mob_arc.entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.entity.target_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(5, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/mob/spider.rs b/pumpkin/src/entity/mob/spider.rs index 0e7092073..d59dc6d46 100644 --- a/pumpkin/src/entity/mob/spider.rs +++ b/pumpkin/src/entity/mob/spider.rs @@ -17,7 +17,7 @@ pub struct SpiderEntity { } impl SpiderEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let spider = Self { mob_entity }; let mob_arc = Arc::new(spider); @@ -27,8 +27,8 @@ impl SpiderEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); goal_selector.add_goal(1, Box::new(SwimGoal::default())); // TODO: SpiderAttackGoal for jumping diff --git a/pumpkin/src/entity/mob/vex.rs b/pumpkin/src/entity/mob/vex.rs index f62fdb95c..14b4c0034 100644 --- a/pumpkin/src/entity/mob/vex.rs +++ b/pumpkin/src/entity/mob/vex.rs @@ -17,7 +17,7 @@ pub struct VexEntity { } impl VexEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let vex = Self { mob_entity }; let mob_arc = Arc::new(vex); @@ -27,7 +27,7 @@ impl VexEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl VexEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/vindicator.rs b/pumpkin/src/entity/mob/vindicator.rs index b575f8a9d..1ad14c0d4 100644 --- a/pumpkin/src/entity/mob/vindicator.rs +++ b/pumpkin/src/entity/mob/vindicator.rs @@ -17,7 +17,7 @@ pub struct VindicatorEntity { } impl VindicatorEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let vindicator = Self { mob_entity }; let mob_arc = Arc::new(vindicator); @@ -27,7 +27,7 @@ impl VindicatorEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(2, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl VindicatorEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/warden.rs b/pumpkin/src/entity/mob/warden.rs index 0b7e2fbf4..649055149 100644 --- a/pumpkin/src/entity/mob/warden.rs +++ b/pumpkin/src/entity/mob/warden.rs @@ -17,7 +17,7 @@ pub struct WardenEntity { } impl WardenEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let warden = Self { mob_entity }; let mob_arc = Arc::new(warden); @@ -27,7 +27,7 @@ impl WardenEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl WardenEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/witch.rs b/pumpkin/src/entity/mob/witch.rs index 643b3a85d..4c378716c 100644 --- a/pumpkin/src/entity/mob/witch.rs +++ b/pumpkin/src/entity/mob/witch.rs @@ -17,7 +17,7 @@ pub struct WitchEntity { } impl WitchEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let witch = Self { mob_entity }; let mob_arc = Arc::new(witch); @@ -27,8 +27,8 @@ impl WitchEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); goal_selector.add_goal(1, Box::new(SwimGoal::default())); // TODO: WitchAttackGoal (potions) diff --git a/pumpkin/src/entity/mob/zoglin.rs b/pumpkin/src/entity/mob/zoglin.rs index 510746fd1..fc636880f 100644 --- a/pumpkin/src/entity/mob/zoglin.rs +++ b/pumpkin/src/entity/mob/zoglin.rs @@ -17,7 +17,7 @@ pub struct ZoglinEntity { } impl ZoglinEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let zoglin = Self { mob_entity }; let mob_arc = Arc::new(zoglin); @@ -27,7 +27,7 @@ impl ZoglinEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(4, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -38,7 +38,7 @@ impl ZoglinEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); target_selector.add_goal( 1, ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true), diff --git a/pumpkin/src/entity/mob/zombie/drowned.rs b/pumpkin/src/entity/mob/zombie/drowned.rs index da5b11de2..d5a7c3c77 100644 --- a/pumpkin/src/entity/mob/zombie/drowned.rs +++ b/pumpkin/src/entity/mob/zombie/drowned.rs @@ -11,13 +11,13 @@ pub struct DrownedEntity { } impl DrownedEntity { - pub async fn new(entity: Entity) -> Arc { - let entity = ZombieEntityBase::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let entity = ZombieEntityBase::new(entity); let zombie = Self { entity }; let mob_arc = Arc::new(zombie); // Fix duplicated since already in ZombieEntity::new() { - //let mut target_selector = mob_arc.entity.mob_entity.target_selector.lock().await; + //let mut target_selector = mob_arc.entity.mob_entity.target_selector.lock().unwrap(); // TODO // target_selector.add_goal( diff --git a/pumpkin/src/entity/mob/zombie/husk.rs b/pumpkin/src/entity/mob/zombie/husk.rs index bc6b94d10..84197ed30 100644 --- a/pumpkin/src/entity/mob/zombie/husk.rs +++ b/pumpkin/src/entity/mob/zombie/husk.rs @@ -11,8 +11,8 @@ pub struct HuskEntity { } impl HuskEntity { - pub async fn new(entity: Entity) -> Arc { - let entity = ZombieEntityBase::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let entity = ZombieEntityBase::new(entity); let zombie = Self { entity }; Arc::new(zombie) } diff --git a/pumpkin/src/entity/mob/zombie/mod.rs b/pumpkin/src/entity/mob/zombie/mod.rs index c185b2c61..5dbffe9c8 100644 --- a/pumpkin/src/entity/mob/zombie/mod.rs +++ b/pumpkin/src/entity/mob/zombie/mod.rs @@ -24,7 +24,7 @@ pub struct ZombieEntityBase { } impl ZombieEntityBase { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let zombie = Self { mob_entity }; let mob_arc = Arc::new(zombie); @@ -34,8 +34,8 @@ impl ZombieEntityBase { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(2, ZombieAttackGoal::new(1.0, false)); diff --git a/pumpkin/src/entity/mob/zombie/zombie.rs b/pumpkin/src/entity/mob/zombie/zombie.rs index 1e992c06b..ceda73285 100644 --- a/pumpkin/src/entity/mob/zombie/zombie.rs +++ b/pumpkin/src/entity/mob/zombie/zombie.rs @@ -1,6 +1,6 @@ -use crate::entity::NBTStorage; use crate::entity::mob::zombie::ZombieEntityBase; use crate::entity::mob::{Mob, MobEntity}; +use crate::entity::{Entity, NBTStorage}; use std::sync::Arc; pub struct ZombieEntity { @@ -8,8 +8,8 @@ pub struct ZombieEntity { } impl ZombieEntity { - pub async fn new(entity: crate::entity::Entity) -> Arc { - let entity = ZombieEntityBase::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let entity = ZombieEntityBase::new(entity); let zombie = Self { entity }; Arc::new(zombie) } diff --git a/pumpkin/src/entity/mob/zombie/zombie_villager.rs b/pumpkin/src/entity/mob/zombie/zombie_villager.rs index e5597524f..2373bc313 100644 --- a/pumpkin/src/entity/mob/zombie/zombie_villager.rs +++ b/pumpkin/src/entity/mob/zombie/zombie_villager.rs @@ -8,8 +8,8 @@ pub struct ZombieVillagerEntity { } impl ZombieVillagerEntity { - pub async fn new(entity: Entity) -> Arc { - let mob_entity = ZombieEntityBase::new(entity).await; + pub fn new(entity: Entity) -> Arc { + let mob_entity = ZombieEntityBase::new(entity); let zombie = Self { mob_entity }; Arc::new(zombie) } diff --git a/pumpkin/src/entity/mob/zombified_piglin.rs b/pumpkin/src/entity/mob/zombified_piglin.rs index cd9e72a73..79ebc0763 100644 --- a/pumpkin/src/entity/mob/zombified_piglin.rs +++ b/pumpkin/src/entity/mob/zombified_piglin.rs @@ -16,7 +16,7 @@ pub struct ZombifiedPiglinEntity { } impl ZombifiedPiglinEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let piglin = Self { mob_entity }; let mob_arc = Arc::new(piglin); @@ -26,7 +26,7 @@ impl ZombifiedPiglinEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(2, Box::new(MeleeAttackGoal::new(1.0, true))); @@ -37,7 +37,7 @@ impl ZombifiedPiglinEntity { ); goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default())); - let _target_selector = mob_arc.mob_entity.target_selector.lock().await; + let _target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); // Zombified piglins are neutral by default (only attack if hit), // but for now we give it ActiveTargetGoal for players to make them hostile // (or we can leave it empty for neutral behavior). diff --git a/pumpkin/src/entity/mod.rs b/pumpkin/src/entity/mod.rs index 105783ce1..2dee70fa0 100644 --- a/pumpkin/src/entity/mod.rs +++ b/pumpkin/src/entity/mod.rs @@ -160,13 +160,11 @@ pub trait EntityBase: Send + Sync + NBTStorage + std::any::Any { let is_baby = entity.age.load(Ordering::Relaxed) < 0; if is_baby { - entity - .send_meta_data(&[Metadata::new( - TrackedData::BABY_ID, - MetaDataType::BOOLEAN, - true, - )]) - .await; + entity.send_meta_data(&[Metadata::new( + TrackedData::BABY_ID, + MetaDataType::BOOLEAN, + true, + )]); } }) } @@ -183,9 +181,7 @@ pub trait EntityBase: Send + Sync + NBTStorage + std::any::Any { Self: 'static, { Box::pin(async move { - self.get_entity() - .teleport(position, yaw, pitch, world) - .await; + self.get_entity().teleport(position, yaw, pitch, world); }) } @@ -653,13 +649,13 @@ impl Entity { } } - pub async fn add_velocity(&self, velocity: Vector3) { - self.set_velocity(self.velocity.load() + velocity).await; + pub fn add_velocity(&self, velocity: Vector3) { + self.set_velocity(self.velocity.load() + velocity); } - pub async fn set_velocity(&self, velocity: Vector3) { + pub fn set_velocity(&self, velocity: Vector3) { self.velocity.store(velocity); - self.send_velocity().await; + self.send_velocity(); } /// Updates the world reference for this entity. @@ -675,36 +671,31 @@ impl Entity { } /// Sets a custom name for the entity, typically used with nametags - pub async fn set_custom_name(&self, name: TextComponent) { + pub fn set_custom_name(&self, name: TextComponent) { self.custom_name.store(Arc::new(Some(name.clone()))); self.send_meta_data(&[Metadata::new( TrackedData::CUSTOM_NAME, MetaDataType::OPTIONAL_TEXT_COMPONENT, Some(name), - )]) - .await; + )]); } - pub async fn set_custom_name_visible(&self, visible: bool) { + pub fn set_custom_name_visible(&self, visible: bool) { self.custom_name_visible.store(visible, Ordering::Relaxed); self.send_meta_data(&[Metadata::new( TrackedData::CUSTOM_NAME_VISIBLE, MetaDataType::BOOLEAN, visible, - )]) - .await; + )]); } - pub async fn send_velocity(&self) { + pub fn send_velocity(&self) { let velocity = self.velocity.load(); let chunk_pos = self.chunk_pos.load(); - self.world - .load() - .broadcast_to_chunk( - chunk_pos, - &CEntityVelocity::new(self.entity_id.into(), velocity), - ) - .await; + self.world.load().broadcast_to_chunk( + chunk_pos, + &CEntityVelocity::new(self.entity_id.into(), velocity), + ); } #[must_use] @@ -788,7 +779,7 @@ impl Entity { self.yaw.store(yaw); } - pub async fn send_rotation(&self) { + pub fn send_rotation(&self) { let yaw = self.yaw.load(); let pitch = self.pitch.load(); let chunk_pos = self.chunk_pos.load(); @@ -805,23 +796,20 @@ impl Entity { self.last_sent_yaw.store(yaw, Relaxed); self.last_sent_pitch.store(pitch, Relaxed); - self.world - .load() - .broadcast_to_chunk( - chunk_pos, - &CUpdateEntityRot::new( - self.entity_id.into(), - yaw, - pitch, - self.on_ground.load(Relaxed), - ), - ) - .await; + self.world.load().broadcast_to_chunk( + chunk_pos, + &CUpdateEntityRot::new( + self.entity_id.into(), + yaw, + pitch, + self.on_ground.load(Relaxed), + ), + ); - self.send_head_rot(yaw).await; + self.send_head_rot(yaw); } - pub async fn send_head_rot(&self, head_yaw: u8) { + pub fn send_head_rot(&self, head_yaw: u8) { let chunk_pos = self.chunk_pos.load(); if head_yaw == self.last_sent_head_yaw.load(Relaxed) { return; @@ -830,8 +818,7 @@ impl Entity { self.world .load() - .broadcast_to_chunk(chunk_pos, &CHeadRot::new(self.entity_id.into(), head_yaw)) - .await; + .broadcast_to_chunk(chunk_pos, &CHeadRot::new(self.entity_id.into(), head_yaw)); } fn default_portal_cooldown(&self) -> u32 { @@ -1015,14 +1002,14 @@ impl Entity { #[expect(dead_code)] fn tick_block_underneath(_caller: &Arc) { - // let world = self.world.read().await; + // let world = self.world.read(); - // let (pos, block, state) = self.get_block_with_y_offset(0.2).await; + // let (pos, block, state) = self.get_block_with_y_offset(0.2); // world // .block_registry // .on_stepped_on(&world, caller.as_ref(), pos, block, state) - // .await; + // ; // TODO: Add this to on_stepped_on @@ -1032,7 +1019,7 @@ impl Entity { if self.on_ground.load(Ordering::SeqCst) { - let (_pos, block, state) = self.get_block_with_y_offset(0.2).await; + let (_pos, block, state) = self.get_block_with_y_offset(0.2); if let Some(live) = living { @@ -1050,7 +1037,7 @@ impl Entity { { - let _ = live.damage(1.0, DamageType::CAMPFIRE).await; + let _ = live.damage(1.0, DamageType::CAMPFIRE); } @@ -1062,7 +1049,7 @@ impl Entity { if block == Block::MAGMA_BLOCK { - let _ = live.damage(1.0, DamageType::HOT_FLOOR).await; + let _ = live.damage(1.0, DamageType::HOT_FLOOR); } @@ -1093,7 +1080,7 @@ impl Entity { let world = self.world.load(); for pos in BlockPos::iterate(min, max) { - let (block, state) = world.get_block_and_state(&pos).await; + let (block, state) = world.get_block_and_state(&pos); if state.is_air() { continue; } @@ -1142,7 +1129,7 @@ impl Entity { suffocating } - pub async fn send_pos_rot(&self) { + pub fn send_pos_rot(&self) { let old = self.last_sent_pos.load(); let new = self.pos.load(); let chunk_pos = self.chunk_pos.load(); @@ -1174,46 +1161,37 @@ impl Entity { // Dynamically pick the most efficient packet if pos_changed && rot_changed { - self.world - .load() - .broadcast_to_chunk( - chunk_pos, - &CUpdateEntityPosRot::new( - self.entity_id.into(), - Vector3::new(converted.x, converted.y, converted.z), - yaw, - pitch, - self.on_ground.load(Relaxed), - ), - ) - .await; + self.world.load().broadcast_to_chunk( + chunk_pos, + &CUpdateEntityPosRot::new( + self.entity_id.into(), + Vector3::new(converted.x, converted.y, converted.z), + yaw, + pitch, + self.on_ground.load(Relaxed), + ), + ); } else if pos_changed { - self.world - .load() - .broadcast_to_chunk( - chunk_pos, - &CUpdateEntityPos::new( - self.entity_id.into(), - Vector3::new(converted.x, converted.y, converted.z), - self.on_ground.load(Relaxed), - ), - ) - .await; + self.world.load().broadcast_to_chunk( + chunk_pos, + &CUpdateEntityPos::new( + self.entity_id.into(), + Vector3::new(converted.x, converted.y, converted.z), + self.on_ground.load(Relaxed), + ), + ); } else if rot_changed { - self.world - .load() - .broadcast_to_chunk( - chunk_pos, - &CUpdateEntityRot::new( - self.entity_id.into(), - yaw, - pitch, - self.on_ground.load(Relaxed), - ), - ) - .await; + self.world.load().broadcast_to_chunk( + chunk_pos, + &CUpdateEntityRot::new( + self.entity_id.into(), + yaw, + pitch, + self.on_ground.load(Relaxed), + ), + ); } - self.send_head_rot(yaw).await; + self.send_head_rot(yaw); } pub fn update_last_pos(&self) -> Vector3 { @@ -1224,7 +1202,7 @@ impl Entity { old } - pub async fn send_pos(&self) { + pub fn send_pos(&self) { let old = self.last_sent_pos.load(); let new = self.pos.load(); let chunk_pos = self.chunk_pos.load(); @@ -1242,17 +1220,14 @@ impl Entity { self.last_sent_pos.store(new); - self.world - .load() - .broadcast_to_chunk( - chunk_pos, - &CUpdateEntityPos::new( - self.entity_id.into(), - Vector3::new(converted.x, converted.y, converted.z), - self.on_ground.load(Relaxed), - ), - ) - .await; + self.world.load().broadcast_to_chunk( + chunk_pos, + &CUpdateEntityPos::new( + self.entity_id.into(), + Vector3::new(converted.x, converted.y, converted.z), + self.on_ground.load(Relaxed), + ), + ); } // updateWaterState() in yarn @@ -1292,7 +1267,7 @@ impl Entity { for z in min.0.z..=max.0.z { let pos = BlockPos::new(x, y, z); - let (fluid, state) = world.get_fluid_and_fluid_state(&pos).await; + let (fluid, state) = world.get_fluid_and_fluid_state(&pos); if fluid.id != Fluid::EMPTY.id { let marginal_height = @@ -1313,7 +1288,7 @@ impl Entity { continue; } - let mut fluid_velo = world.get_fluid_velocity(pos, fluid, state).await; + let mut fluid_velo = world.get_fluid_velocity(pos, fluid, state); if fluid_height[i] < 0.4 { fluid_velo = fluid_velo * fluid_height[i]; @@ -1408,7 +1383,7 @@ impl Entity { } } - async fn get_pos_with_y_offset( + fn get_pos_with_y_offset( &self, offset: f64, ) -> ( @@ -1418,11 +1393,7 @@ impl Entity { ) { if let Some(mut supporting_block) = self.supporting_block_pos.load() { if offset > 1.0e-5 { - let (block, state) = self - .world - .load() - .get_block_and_state(&supporting_block) - .await; + let (block, state) = self.world.load().get_block_and_state(&supporting_block); // if let Some(props) = block.properties(state.id) { // let name = props.; @@ -1453,16 +1424,16 @@ impl Entity { (block_pos, None, None) } - async fn get_block_with_y_offset( + fn get_block_with_y_offset( &self, offset: f64, ) -> (BlockPos, &'static Block, &'static BlockState) { - let (pos, block, state) = self.get_pos_with_y_offset(offset).await; + let (pos, block, state) = self.get_pos_with_y_offset(offset); if let (Some(b), Some(s)) = (block, state) { (pos, b, s) } else { - let (b, s) = self.world.load().get_block_and_state(&pos).await; + let (b, s) = self.world.load().get_block_and_state(&pos); (pos, b, s) } @@ -1505,32 +1476,30 @@ impl Entity { } #[expect(clippy::float_cmp)] - async fn get_velocity_multiplier(&self) -> f32 { - let block = self.world.load().get_block(&self.block_pos.load()).await; + fn get_velocity_multiplier(&self) -> f32 { + let block = self.world.load().get_block(&self.block_pos.load()); let multiplier = block.velocity_multiplier; if multiplier != 1.0 || block == &Block::WATER || block == &Block::BUBBLE_COLUMN { multiplier } else { - let (_pos, block, _state) = self.get_block_with_y_offset(0.500_001).await; + let (_pos, block, _state) = self.get_block_with_y_offset(0.500_001); block.velocity_multiplier } } #[expect(clippy::float_cmp)] - async fn get_jump_velocity_multiplier(&self) -> f32 { + fn get_jump_velocity_multiplier(&self) -> f32 { let f = self .world .load() .get_block(&self.block_pos.load()) - .await .jump_velocity_multiplier; let g = self .get_block_with_y_offset(0.500_001) - .await .1 .jump_velocity_multiplier; @@ -1573,7 +1542,7 @@ impl Entity { self.move_pos(final_move); - let velocity_multiplier = f64::from(self.get_velocity_multiplier().await); + let velocity_multiplier = f64::from(self.get_velocity_multiplier()); self.velocity.store(final_move * velocity_multiplier); @@ -1590,7 +1559,7 @@ impl Entity { if motion.y != final_move.y { let world = self.world.load(); - let block = self.get_block_with_y_offset(0.2).await.1; + let block = self.get_block_with_y_offset(0.2).1; world .block_registry .update_entity_movement_after_fall_on(block, caller.as_ref()) @@ -1598,7 +1567,7 @@ impl Entity { } } - pub async fn push_out_of_blocks(&self, center_pos: Vector3) { + pub fn push_out_of_blocks(&self, center_pos: Vector3) { let block_pos = BlockPos::floored_v(center_pos); let delta = center_pos.sub(&block_pos.0.to_f64()); @@ -1618,7 +1587,6 @@ impl Entity { .world .load() .get_block_state(&block_pos.offset(offset)) - .await .is_full_cube() { continue; @@ -1715,9 +1683,8 @@ impl Entity { dest_result.calculate_exit_position(relative_pos, &dimensions) }, ); - let final_pos = dest_result - .find_open_position(&dest_world, base_pos, &dimensions) - .await; + let final_pos = + dest_result.find_open_position(&dest_world, base_pos, &dimensions); let yaw = dest_result.calculate_teleport_yaw(current_yaw, source_axis); (final_pos, Some(yaw)) } else if let Some((build_pos, axis, is_fallback)) = @@ -1737,9 +1704,8 @@ impl Entity { height: 3, }; let center_pos = new_portal.get_teleport_position(); - let final_pos = new_portal - .find_open_position(&dest_world, center_pos, &dimensions) - .await; + let final_pos = + new_portal.find_open_position(&dest_world, center_pos, &dimensions); let yaw = new_portal.calculate_teleport_yaw(current_yaw, source_axis); (final_pos, Some(yaw)) } else { @@ -1843,9 +1809,7 @@ impl Entity { &world, &pos, pumpkin_data::block_properties::HorizontalAxis::X, - ) - .await - && portal.was_already_valid() + ) && portal.was_already_valid() { new_manager.set_source_portal(SourcePortalInfo { lower_corner: portal.lower_corner(), @@ -1857,9 +1821,7 @@ impl Entity { &world, &pos, pumpkin_data::block_properties::HorizontalAxis::Z, - ) - .await - && portal.was_already_valid() + ) && portal.was_already_valid() { new_manager.set_source_portal(SourcePortalInfo { lower_corner: portal.lower_corner(), @@ -1974,8 +1936,7 @@ impl Entity { TrackedData::TICKS_FROZEN, MetaDataType::INTEGER, VarInt(new_frozen_ticks), - )]) - .await; + )]); } // Vanilla parity: full-freeze damage is tick-phase based. @@ -2222,8 +2183,7 @@ impl Entity { TrackedData::SHARED_FLAGS_ID, MetaDataType::BYTE, new_je_flags, - )]) - .await; + )]); if let Some(bedrock_flag) = flag.to_bedrock() { let (key, index) = if bedrock_flag >= 64 { @@ -2284,14 +2244,13 @@ impl Entity { } /// Plays sound at this entity's position with the entity's sound category - pub async fn play_sound(&self, sound: Sound) { + pub fn play_sound(&self, sound: Sound) { self.world .load() - .play_sound(sound, SoundCategory::Neutral, &self.pos.load()) - .await; + .play_sound(sound, SoundCategory::Neutral, &self.pos.load()); } - pub async fn send_meta_data(&self, meta: &[Metadata]) { + pub fn send_meta_data(&self, meta: &[Metadata]) { let world = self.world.load(); let chunk_pos = self.chunk_pos.load(); for player in world.players.load().iter() { @@ -2306,25 +2265,20 @@ impl Entity { m.write(&mut buf, &client.version.load()).unwrap(); } buf.put_u8(255); - player - .client - .enqueue_packet(&CSetEntityMetadata::new(self.entity_id.into(), buf.into())) - .await; + player.client.try_enqueue_packet(&CSetEntityMetadata::new( + self.entity_id.into(), + buf.into(), + )); } } } } - pub async fn set_pose(&self, pose: EntityPose) { + pub fn set_pose(&self, pose: EntityPose) { let dimension = Self::get_entity_dimensions(pose); let position = self.pos.load(); let aabb = BoundingBox::new_from_pos(position.x, position.y, position.z, &dimension); - if self - .world - .load() - .is_space_empty(aabb.contract_all(1.0E-7)) - .await - { + if self.world.load().is_space_empty(aabb.contract_all(1.0E-7)) { self.pose.store(pose); let dimension = Self::get_entity_dimensions(pose); self.bounding_box.store(aabb); @@ -2334,8 +2288,7 @@ impl Entity { TrackedData::POSE, MetaDataType::ENTITY_POSE, VarInt(pose), - )]) - .await; + )]); } } @@ -2396,7 +2349,7 @@ impl Entity { for y in blockpos.0.y..=blockpos1.0.y { for z in blockpos.0.z..=blockpos1.0.z { let pos = BlockPos::new(x, y, z); - let (block, state) = world.get_block_and_state(&pos).await; + let (block, state) = world.get_block_and_state(&pos); let block_outlines = state.get_block_outline_shapes(); if state.outline_shapes.is_empty() { @@ -2404,7 +2357,7 @@ impl Entity { .block_registry .on_entity_collision(block, &world, entity, &pos, state, server) .await; - let fluid = world.get_fluid(&pos).await; + let fluid = world.get_fluid(&pos); world .block_registry .on_entity_collision_fluid(fluid, entity) @@ -2418,7 +2371,7 @@ impl Entity { .block_registry .on_entity_collision(block, &world, entity, &pos, state, server) .await; - let fluid = world.get_fluid(&pos).await; + let fluid = world.get_fluid(&pos); world .block_registry .on_entity_collision_fluid(fluid, entity) @@ -2431,7 +2384,7 @@ impl Entity { } } - async fn teleport( + fn teleport( &self, position: Vector3, yaw: Option, @@ -2459,20 +2412,17 @@ impl Entity { .store((pitch * 256.0 / 360.0).rem_euclid(256.0) as u8, Relaxed); } let chunk_pos = self.chunk_pos.load(); - self.world - .load() - .broadcast_to_chunk( - chunk_pos, - &CEntityPositionSync::new( - self.entity_id.into(), - position, - Vector3::new(0.0, 0.0, 0.0), - yaw.unwrap_or(self.yaw.load()), - pitch.unwrap_or(self.pitch.load()), - self.on_ground.load(Ordering::SeqCst), - ), - ) - .await; + self.world.load().broadcast_to_chunk( + chunk_pos, + &CEntityPositionSync::new( + self.entity_id.into(), + position, + Vector3::new(0.0, 0.0, 0.0), + yaw.unwrap_or(self.yaw.load()), + pitch.unwrap_or(self.pitch.load()), + self.on_ground.load(Ordering::SeqCst), + ), + ); } pub fn get_eye_pos(&self) -> Vector3 { @@ -2523,12 +2473,10 @@ impl Entity { let world = self.world.load(); let chunk_pos = self.chunk_pos.load(); - world - .broadcast_to_chunk( - chunk_pos, - &CSetPassengers::new(VarInt(self.entity_id), &passenger_ids), - ) - .await; + world.broadcast_to_chunk( + chunk_pos, + &CSetPassengers::new(VarInt(self.entity_id), &passenger_ids), + ); } #[allow(clippy::too_many_lines)] @@ -2589,17 +2537,13 @@ impl Entity { let passengers_packet = CSetPassengers::new(VarInt(self.entity_id), &passenger_ids); if let Some(player) = passenger.get_player() { player.client.enqueue_packet(&passengers_packet).await; - world - .broadcast_to_chunk_except( - chunk_pos, - &[player.living_entity.entity.entity_uuid], - &passengers_packet, - ) - .await; + world.broadcast_to_chunk_except( + chunk_pos, + &[player.living_entity.entity.entity_uuid], + &passengers_packet, + ); } else { - world - .broadcast_to_chunk(chunk_pos, &passengers_packet) - .await; + world.broadcast_to_chunk(chunk_pos, &passengers_packet); } // Calculate dismount offset (vanilla getPassengerDismountOffset) @@ -2626,7 +2570,7 @@ impl Entity { target_z.floor() as i32, )); - let below_state_id = world.get_block_state_id(&below_pos).await; + let below_state_id = world.get_block_state_id(&below_pos); // Vanilla: isWater checks specifically for water fluid, not any fluid let is_water = Fluid::from_state_id(below_state_id) .is_some_and(|f| f.id == Fluid::WATER.id || f.id == Fluid::FLOWING_WATER.id); @@ -2640,7 +2584,7 @@ impl Entity { // Vanilla tries two Y levels: at vehicle top and one block below let mut candidates = Vec::new(); for pos in [&block_pos, &below_pos] { - let height = world.get_dismount_height(pos).await; + let height = world.get_dismount_height(pos); // Vanilla: canDismountInBlock = !height.is_infinite() && height < 1.0 if height.is_finite() && height < 1.0 { candidates.push(Vector3::new( @@ -2663,7 +2607,7 @@ impl Entity { for candidate in &candidates { let bbox = BoundingBox::new_from_pos(candidate.x, candidate.y, candidate.z, &dims); - if world.is_space_empty(bbox).await { + if world.is_space_empty(bbox) { found = Some((*candidate, pose)); break 'outer; } @@ -2672,7 +2616,7 @@ impl Entity { if let Some((pos, pose)) = found { if pose != EntityPose::Standing { - passenger_entity.set_pose(pose).await; + passenger_entity.set_pose(pose); } pos } else { @@ -2716,12 +2660,10 @@ impl Entity { } else { // No passenger was removed, still need to broadcast the passenger list let world = self.world.load(); - world - .broadcast_to_chunk( - chunk_pos, - &CSetPassengers::new(VarInt(self.entity_id), &passenger_ids), - ) - .await; + world.broadcast_to_chunk( + chunk_pos, + &CSetPassengers::new(VarInt(self.entity_id), &passenger_ids), + ); } } @@ -2871,7 +2813,7 @@ impl EntityBase for Entity { let block_pos = self.block_pos.load(); if self.last_biome_update_pos.load() != block_pos { let world = self.world.load(); - let biome = world.level.get_rough_biome(&block_pos).await; + let biome = world.level.get_rough_biome(&block_pos); self.current_biome.store(Arc::new(biome)); self.last_biome_update_pos.store(block_pos); } @@ -2921,9 +2863,7 @@ impl EntityBase for Entity { ) -> TeleportFuture { // TODO: handle world change Box::pin(async move { - self.get_entity() - .teleport(position, yaw, pitch, world) - .await; + self.get_entity().teleport(position, yaw, pitch, world); }) } diff --git a/pumpkin/src/entity/passive/allay.rs b/pumpkin/src/entity/passive/allay.rs index 8b5cff350..3ab4d0d5e 100644 --- a/pumpkin/src/entity/passive/allay.rs +++ b/pumpkin/src/entity/passive/allay.rs @@ -19,7 +19,7 @@ pub struct AllayEntity { } impl AllayEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let allay = Self { mob_entity }; let mob_arc = Arc::new(allay); @@ -29,7 +29,7 @@ impl AllayEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/armadillo.rs b/pumpkin/src/entity/passive/armadillo.rs index a3f30048a..6e8a624e2 100644 --- a/pumpkin/src/entity/passive/armadillo.rs +++ b/pumpkin/src/entity/passive/armadillo.rs @@ -19,7 +19,7 @@ pub struct ArmadilloEntity { } impl ArmadilloEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let armadillo = Self { mob_entity }; let mob_arc = Arc::new(armadillo); @@ -29,7 +29,7 @@ impl ArmadilloEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/axolotl.rs b/pumpkin/src/entity/passive/axolotl.rs index 897301d18..162faadc5 100644 --- a/pumpkin/src/entity/passive/axolotl.rs +++ b/pumpkin/src/entity/passive/axolotl.rs @@ -19,7 +19,7 @@ pub struct AxolotlEntity { } impl AxolotlEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let axolotl = Self { mob_entity }; let mob_arc = Arc::new(axolotl); @@ -29,7 +29,7 @@ impl AxolotlEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/bee.rs b/pumpkin/src/entity/passive/bee.rs index ef20a4f64..733024d2c 100644 --- a/pumpkin/src/entity/passive/bee.rs +++ b/pumpkin/src/entity/passive/bee.rs @@ -19,7 +19,7 @@ pub struct BeeEntity { } impl BeeEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let bee = Self { mob_entity }; let mob_arc = Arc::new(bee); @@ -29,7 +29,7 @@ impl BeeEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/camel.rs b/pumpkin/src/entity/passive/camel.rs index da63bbe71..f297a1ea1 100644 --- a/pumpkin/src/entity/passive/camel.rs +++ b/pumpkin/src/entity/passive/camel.rs @@ -19,7 +19,7 @@ pub struct CamelEntity { } impl CamelEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let camel = Self { mob_entity }; let mob_arc = Arc::new(camel); @@ -29,7 +29,7 @@ impl CamelEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/cat.rs b/pumpkin/src/entity/passive/cat.rs index 96ccd9567..118cfe8c3 100644 --- a/pumpkin/src/entity/passive/cat.rs +++ b/pumpkin/src/entity/passive/cat.rs @@ -22,7 +22,7 @@ pub struct CatEntity { } impl CatEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let cat = Self { mob_entity }; let mob_arc = Arc::new(cat); @@ -32,7 +32,7 @@ impl CatEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(1, Box::new(SwimGoal::default())); goal_selector.add_goal(1, EscapeDangerGoal::new(1.5)); diff --git a/pumpkin/src/entity/passive/chicken.rs b/pumpkin/src/entity/passive/chicken.rs index 95c544f2e..78e5f337f 100644 --- a/pumpkin/src/entity/passive/chicken.rs +++ b/pumpkin/src/entity/passive/chicken.rs @@ -40,7 +40,7 @@ pub struct ChickenEntity { } impl ChickenEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let egg_lay_time = rand::rng().random_range(6000..12000); let chicken = Self { @@ -54,7 +54,7 @@ impl ChickenEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, EscapeDangerGoal::new(1.4)); @@ -126,22 +126,18 @@ impl Mob for ChickenEntity { let world = entity.world.load(); let pos = entity.pos.load(); - world - .spawn_particle( - pos + Vector3::new(0.0, f64::from(entity.height()), 0.0), - Vector3::new(0.5, 0.5, 0.5), - 1.0, - 7, - Particle::Heart, - ) - .await; - world - .play_sound( - Sound::EntityChickenAmbient, - SoundCategory::Neutral, - &entity.pos.load(), - ) - .await; + world.spawn_particle( + pos + Vector3::new(0.0, f64::from(entity.height()), 0.0), + Vector3::new(0.5, 0.5, 0.5), + 1.0, + 7, + Particle::Heart, + ); + world.play_sound( + Sound::EntityChickenAmbient, + SoundCategory::Neutral, + &entity.pos.load(), + ); return true; } false diff --git a/pumpkin/src/entity/passive/cod.rs b/pumpkin/src/entity/passive/cod.rs index db85f1d20..07f732853 100644 --- a/pumpkin/src/entity/passive/cod.rs +++ b/pumpkin/src/entity/passive/cod.rs @@ -19,7 +19,7 @@ pub struct CodEntity { } impl CodEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let cod = Self { mob_entity }; let mob_arc = Arc::new(cod); @@ -29,7 +29,7 @@ impl CodEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/cow.rs b/pumpkin/src/entity/passive/cow.rs index 5b8a6a2b2..e43585697 100644 --- a/pumpkin/src/entity/passive/cow.rs +++ b/pumpkin/src/entity/passive/cow.rs @@ -28,7 +28,7 @@ pub struct CowEntity { } impl CowEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let cow = Self { mob_entity }; let mob_arc = Arc::new(cow); @@ -38,7 +38,7 @@ impl CowEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, EscapeDangerGoal::new(2.0)); @@ -87,22 +87,18 @@ impl Mob for CowEntity { let world = entity.world.load(); let pos = entity.pos.load(); - world - .spawn_particle( - pos + Vector3::new(0.0, f64::from(entity.height()), 0.0), - Vector3::new(0.5, 0.5, 0.5), - 1.0, - 7, - Particle::Heart, - ) - .await; - world - .play_sound( - Sound::EntityCowAmbient, - SoundCategory::Neutral, - &entity.pos.load(), - ) - .await; + world.spawn_particle( + pos + Vector3::new(0.0, f64::from(entity.height()), 0.0), + Vector3::new(0.5, 0.5, 0.5), + 1.0, + 7, + Particle::Heart, + ); + world.play_sound( + Sound::EntityCowAmbient, + SoundCategory::Neutral, + &entity.pos.load(), + ); return true; } false diff --git a/pumpkin/src/entity/passive/dolphin.rs b/pumpkin/src/entity/passive/dolphin.rs index 4f95e3019..3a25512c8 100644 --- a/pumpkin/src/entity/passive/dolphin.rs +++ b/pumpkin/src/entity/passive/dolphin.rs @@ -19,7 +19,7 @@ pub struct DolphinEntity { } impl DolphinEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let dolphin = Self { mob_entity }; let mob_arc = Arc::new(dolphin); @@ -29,7 +29,7 @@ impl DolphinEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/donkey.rs b/pumpkin/src/entity/passive/donkey.rs index 68ab1e610..fd7693933 100644 --- a/pumpkin/src/entity/passive/donkey.rs +++ b/pumpkin/src/entity/passive/donkey.rs @@ -19,7 +19,7 @@ pub struct DonkeyEntity { } impl DonkeyEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let donkey = Self { mob_entity }; let mob_arc = Arc::new(donkey); @@ -29,7 +29,7 @@ impl DonkeyEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(0.7))); diff --git a/pumpkin/src/entity/passive/fox.rs b/pumpkin/src/entity/passive/fox.rs index 7bf84c234..78bc16f72 100644 --- a/pumpkin/src/entity/passive/fox.rs +++ b/pumpkin/src/entity/passive/fox.rs @@ -22,7 +22,7 @@ pub struct FoxEntity { } impl FoxEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let fox = Self { mob_entity }; let mob_arc = Arc::new(fox); @@ -32,7 +32,7 @@ impl FoxEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, EscapeDangerGoal::new(1.5)); diff --git a/pumpkin/src/entity/passive/frog.rs b/pumpkin/src/entity/passive/frog.rs index 49667147e..607cc729e 100644 --- a/pumpkin/src/entity/passive/frog.rs +++ b/pumpkin/src/entity/passive/frog.rs @@ -19,7 +19,7 @@ pub struct FrogEntity { } impl FrogEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let frog = Self { mob_entity }; let mob_arc = Arc::new(frog); @@ -29,7 +29,7 @@ impl FrogEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/glow_squid.rs b/pumpkin/src/entity/passive/glow_squid.rs index c071e2549..6f447dfa8 100644 --- a/pumpkin/src/entity/passive/glow_squid.rs +++ b/pumpkin/src/entity/passive/glow_squid.rs @@ -19,7 +19,7 @@ pub struct GlowSquidEntity { } impl GlowSquidEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let glow_squid = Self { mob_entity }; let mob_arc = Arc::new(glow_squid); @@ -29,7 +29,7 @@ impl GlowSquidEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/goat.rs b/pumpkin/src/entity/passive/goat.rs index 00c3da39f..d2538717a 100644 --- a/pumpkin/src/entity/passive/goat.rs +++ b/pumpkin/src/entity/passive/goat.rs @@ -19,7 +19,7 @@ pub struct GoatEntity { } impl GoatEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let goat = Self { mob_entity }; let mob_arc = Arc::new(goat); @@ -29,7 +29,7 @@ impl GoatEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/horse.rs b/pumpkin/src/entity/passive/horse.rs index 8c50a4757..3dd3e0e91 100644 --- a/pumpkin/src/entity/passive/horse.rs +++ b/pumpkin/src/entity/passive/horse.rs @@ -19,7 +19,7 @@ pub struct HorseEntity { } impl HorseEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let horse = Self { mob_entity }; let mob_arc = Arc::new(horse); @@ -29,7 +29,7 @@ impl HorseEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(0.7))); diff --git a/pumpkin/src/entity/passive/iron_golem.rs b/pumpkin/src/entity/passive/iron_golem.rs index 63d34e2b0..22c198e0b 100644 --- a/pumpkin/src/entity/passive/iron_golem.rs +++ b/pumpkin/src/entity/passive/iron_golem.rs @@ -21,7 +21,7 @@ pub struct IronGolemEntity { } impl IronGolemEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let iron_golem = Self { mob_entity }; let mob_arc = Arc::new(iron_golem); @@ -31,8 +31,8 @@ impl IronGolemEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); goal_selector.add_goal(1, Box::new(MeleeAttackGoal::new(1.0, true))); goal_selector.add_goal(6, Box::new(WanderAroundGoal::new(0.6))); diff --git a/pumpkin/src/entity/passive/llama.rs b/pumpkin/src/entity/passive/llama.rs index 30faa1e32..df50b4a91 100644 --- a/pumpkin/src/entity/passive/llama.rs +++ b/pumpkin/src/entity/passive/llama.rs @@ -19,7 +19,7 @@ pub struct LlamaEntity { } impl LlamaEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let llama = Self { mob_entity }; let mob_arc = Arc::new(llama); @@ -29,7 +29,7 @@ impl LlamaEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(0.7))); diff --git a/pumpkin/src/entity/passive/mooshroom.rs b/pumpkin/src/entity/passive/mooshroom.rs index f5b769c0d..ac9030dd1 100644 --- a/pumpkin/src/entity/passive/mooshroom.rs +++ b/pumpkin/src/entity/passive/mooshroom.rs @@ -19,7 +19,7 @@ pub struct MooshroomEntity { } impl MooshroomEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let mooshroom = Self { mob_entity }; let mob_arc = Arc::new(mooshroom); @@ -29,7 +29,7 @@ impl MooshroomEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/mule.rs b/pumpkin/src/entity/passive/mule.rs index db0f745bb..81b8d7e0e 100644 --- a/pumpkin/src/entity/passive/mule.rs +++ b/pumpkin/src/entity/passive/mule.rs @@ -19,7 +19,7 @@ pub struct MuleEntity { } impl MuleEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let mule = Self { mob_entity }; let mob_arc = Arc::new(mule); @@ -29,7 +29,7 @@ impl MuleEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(0.7))); diff --git a/pumpkin/src/entity/passive/ocelot.rs b/pumpkin/src/entity/passive/ocelot.rs index 808ef095c..701e3e0cb 100644 --- a/pumpkin/src/entity/passive/ocelot.rs +++ b/pumpkin/src/entity/passive/ocelot.rs @@ -19,7 +19,7 @@ pub struct OcelotEntity { } impl OcelotEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let ocelot = Self { mob_entity }; let mob_arc = Arc::new(ocelot); @@ -29,7 +29,7 @@ impl OcelotEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/panda.rs b/pumpkin/src/entity/passive/panda.rs index f9c15d308..bbe2248e1 100644 --- a/pumpkin/src/entity/passive/panda.rs +++ b/pumpkin/src/entity/passive/panda.rs @@ -19,7 +19,7 @@ pub struct PandaEntity { } impl PandaEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let panda = Self { mob_entity }; let mob_arc = Arc::new(panda); @@ -29,7 +29,7 @@ impl PandaEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/parrot.rs b/pumpkin/src/entity/passive/parrot.rs index a0ad27342..e2a34ffdd 100644 --- a/pumpkin/src/entity/passive/parrot.rs +++ b/pumpkin/src/entity/passive/parrot.rs @@ -19,7 +19,7 @@ pub struct ParrotEntity { } impl ParrotEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let parrot = Self { mob_entity }; let mob_arc = Arc::new(parrot); @@ -29,7 +29,7 @@ impl ParrotEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/pig.rs b/pumpkin/src/entity/passive/pig.rs index 56b2a529b..eeddee5ba 100644 --- a/pumpkin/src/entity/passive/pig.rs +++ b/pumpkin/src/entity/passive/pig.rs @@ -33,7 +33,7 @@ pub struct PigEntity { } impl PigEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let pig = Self { mob_entity }; let mob_arc = Arc::new(pig); @@ -43,7 +43,7 @@ impl PigEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, EscapeDangerGoal::new(1.25)); @@ -92,22 +92,18 @@ impl Mob for PigEntity { let world = entity.world.load(); let pos = entity.pos.load(); - world - .spawn_particle( - pos + Vector3::new(0.0, f64::from(entity.height()), 0.0), - Vector3::new(0.5, 0.5, 0.5), - 1.0, - 7, - Particle::Heart, - ) - .await; - world - .play_sound( - Sound::EntityPigAmbient, - SoundCategory::Neutral, - &entity.pos.load(), - ) - .await; + world.spawn_particle( + pos + Vector3::new(0.0, f64::from(entity.height()), 0.0), + Vector3::new(0.5, 0.5, 0.5), + 1.0, + 7, + Particle::Heart, + ); + world.play_sound( + Sound::EntityPigAmbient, + SoundCategory::Neutral, + &entity.pos.load(), + ); return true; } false diff --git a/pumpkin/src/entity/passive/polar_bear.rs b/pumpkin/src/entity/passive/polar_bear.rs index 76a6d4b66..684cb8619 100644 --- a/pumpkin/src/entity/passive/polar_bear.rs +++ b/pumpkin/src/entity/passive/polar_bear.rs @@ -19,7 +19,7 @@ pub struct PolarBearEntity { } impl PolarBearEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let polar_bear = Self { mob_entity }; let mob_arc = Arc::new(polar_bear); @@ -29,7 +29,7 @@ impl PolarBearEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); @@ -39,7 +39,7 @@ impl PolarBearEntity { ); goal_selector.add_goal(3, Box::new(RandomLookAroundGoal::default())); - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); // Polar bears are neutral but aggressive towards foxes target_selector.add_goal( 1, diff --git a/pumpkin/src/entity/passive/pufferfish.rs b/pumpkin/src/entity/passive/pufferfish.rs index 56b12930f..4cfd6c02d 100644 --- a/pumpkin/src/entity/passive/pufferfish.rs +++ b/pumpkin/src/entity/passive/pufferfish.rs @@ -19,7 +19,7 @@ pub struct PufferfishEntity { } impl PufferfishEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let pufferfish = Self { mob_entity }; let mob_arc = Arc::new(pufferfish); @@ -29,7 +29,7 @@ impl PufferfishEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/rabbit.rs b/pumpkin/src/entity/passive/rabbit.rs index af3682743..9170694d6 100644 --- a/pumpkin/src/entity/passive/rabbit.rs +++ b/pumpkin/src/entity/passive/rabbit.rs @@ -19,7 +19,7 @@ pub struct RabbitEntity { } impl RabbitEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let rabbit = Self { mob_entity }; let mob_arc = Arc::new(rabbit); @@ -29,7 +29,7 @@ impl RabbitEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(1, Box::new(SwimGoal::default())); goal_selector.add_goal(1, EscapeDangerGoal::new(2.2)); diff --git a/pumpkin/src/entity/passive/salmon.rs b/pumpkin/src/entity/passive/salmon.rs index db0f9f00e..740b9933d 100644 --- a/pumpkin/src/entity/passive/salmon.rs +++ b/pumpkin/src/entity/passive/salmon.rs @@ -16,7 +16,7 @@ pub struct SalmonEntity { } impl SalmonEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let salmon = Self { mob_entity }; let mob_arc = Arc::new(salmon); @@ -26,7 +26,7 @@ impl SalmonEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/sheep.rs b/pumpkin/src/entity/passive/sheep.rs index 669d158fb..a90ef4352 100644 --- a/pumpkin/src/entity/passive/sheep.rs +++ b/pumpkin/src/entity/passive/sheep.rs @@ -34,7 +34,7 @@ pub struct SheepEntity { } impl SheepEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let sheep = Self { mob_entity, @@ -47,7 +47,7 @@ impl SheepEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, EscapeDangerGoal::new(1.25)); @@ -78,7 +78,7 @@ impl SheepEntity { (self.get_packed_byte() & 0x10) != 0 } - async fn set_packed_and_sync(&self, byte: u8) { + fn set_packed_and_sync(&self, byte: u8) { self.color_and_sheared.store(byte, Ordering::Relaxed); self.mob_entity .living_entity @@ -87,22 +87,21 @@ impl SheepEntity { TrackedData::WOOL_ID, MetaDataType::BYTE, byte as i8, - )]) - .await; + )]); } - pub async fn set_color(&self, color: u8) { + pub fn set_color(&self, color: u8) { let byte = (self.get_packed_byte() & 0xF0) | (color & 0x0F); - self.set_packed_and_sync(byte).await; + self.set_packed_and_sync(byte); } - pub async fn set_sheared(&self, sheared: bool) { + pub fn set_sheared(&self, sheared: bool) { let byte = if sheared { self.get_packed_byte() | 0x10 } else { self.get_packed_byte() & !0x10 }; - self.set_packed_and_sync(byte).await; + self.set_packed_and_sync(byte); } } @@ -137,7 +136,7 @@ impl Mob for SheepEntity { fn on_eating_grass(&self) -> EntityBaseFuture<'_, ()> { Box::pin(async { - self.set_sheared(false).await; + self.set_sheared(false); }) } @@ -156,22 +155,18 @@ impl Mob for SheepEntity { let world = entity.world.load(); let pos = entity.pos.load(); - world - .spawn_particle( - pos + Vector3::new(0.0, f64::from(entity.height()), 0.0), - Vector3::new(0.5, 0.5, 0.5), - 1.0, - 7, - Particle::Heart, - ) - .await; - world - .play_sound( - Sound::EntitySheepAmbient, - SoundCategory::Neutral, - &entity.pos.load(), - ) - .await; + world.spawn_particle( + pos + Vector3::new(0.0, f64::from(entity.height()), 0.0), + Vector3::new(0.5, 0.5, 0.5), + 1.0, + 7, + Particle::Heart, + ); + world.play_sound( + Sound::EntitySheepAmbient, + SoundCategory::Neutral, + &entity.pos.load(), + ); return true; } false diff --git a/pumpkin/src/entity/passive/skeleton_horse.rs b/pumpkin/src/entity/passive/skeleton_horse.rs index 2c4a79f64..656c3451a 100644 --- a/pumpkin/src/entity/passive/skeleton_horse.rs +++ b/pumpkin/src/entity/passive/skeleton_horse.rs @@ -16,7 +16,7 @@ pub struct SkeletonHorseEntity { } impl SkeletonHorseEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let horse = Self { mob_entity }; let mob_arc = Arc::new(horse); @@ -26,7 +26,7 @@ impl SkeletonHorseEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(0.7))); diff --git a/pumpkin/src/entity/passive/sniffer.rs b/pumpkin/src/entity/passive/sniffer.rs index 26e6b2ca4..d7cf1ad9b 100644 --- a/pumpkin/src/entity/passive/sniffer.rs +++ b/pumpkin/src/entity/passive/sniffer.rs @@ -16,7 +16,7 @@ pub struct SnifferEntity { } impl SnifferEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let sniffer = Self { mob_entity }; let mob_arc = Arc::new(sniffer); @@ -26,7 +26,7 @@ impl SnifferEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/snow_golem.rs b/pumpkin/src/entity/passive/snow_golem.rs index d7ef87a04..7f52ac008 100644 --- a/pumpkin/src/entity/passive/snow_golem.rs +++ b/pumpkin/src/entity/passive/snow_golem.rs @@ -16,7 +16,7 @@ pub struct SnowGolemEntity { } impl SnowGolemEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let snow_golem = Self { mob_entity }; let mob_arc = Arc::new(snow_golem); @@ -26,8 +26,8 @@ impl SnowGolemEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; - let mut target_selector = mob_arc.mob_entity.target_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); + let mut target_selector = mob_arc.mob_entity.target_selector.lock().unwrap(); // TODO: SnowballAttackGoal goal_selector.add_goal(5, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/squid.rs b/pumpkin/src/entity/passive/squid.rs index 10bdf1562..fd45a1e48 100644 --- a/pumpkin/src/entity/passive/squid.rs +++ b/pumpkin/src/entity/passive/squid.rs @@ -16,7 +16,7 @@ pub struct SquidEntity { } impl SquidEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let squid = Self { mob_entity }; let mob_arc = Arc::new(squid); @@ -26,7 +26,7 @@ impl SquidEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); // Squids don't have WanderAroundGoal in vanilla (they use custom movement), diff --git a/pumpkin/src/entity/passive/strider.rs b/pumpkin/src/entity/passive/strider.rs index ccb58fe9f..62ee3cc29 100644 --- a/pumpkin/src/entity/passive/strider.rs +++ b/pumpkin/src/entity/passive/strider.rs @@ -16,7 +16,7 @@ pub struct StriderEntity { } impl StriderEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let strider = Self { mob_entity }; let mob_arc = Arc::new(strider); @@ -26,7 +26,7 @@ impl StriderEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/tadpole.rs b/pumpkin/src/entity/passive/tadpole.rs index 0bc087b22..a7e00ed1c 100644 --- a/pumpkin/src/entity/passive/tadpole.rs +++ b/pumpkin/src/entity/passive/tadpole.rs @@ -16,7 +16,7 @@ pub struct TadpoleEntity { } impl TadpoleEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let tadpole = Self { mob_entity }; let mob_arc = Arc::new(tadpole); @@ -26,7 +26,7 @@ impl TadpoleEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/trader_llama.rs b/pumpkin/src/entity/passive/trader_llama.rs index 57980d13c..523695571 100644 --- a/pumpkin/src/entity/passive/trader_llama.rs +++ b/pumpkin/src/entity/passive/trader_llama.rs @@ -16,7 +16,7 @@ pub struct TraderLlamaEntity { } impl TraderLlamaEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let llama = Self { mob_entity }; let mob_arc = Arc::new(llama); @@ -26,7 +26,7 @@ impl TraderLlamaEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(0.7))); diff --git a/pumpkin/src/entity/passive/tropical_fish.rs b/pumpkin/src/entity/passive/tropical_fish.rs index 91f956153..cb6398fc3 100644 --- a/pumpkin/src/entity/passive/tropical_fish.rs +++ b/pumpkin/src/entity/passive/tropical_fish.rs @@ -16,7 +16,7 @@ pub struct TropicalFishEntity { } impl TropicalFishEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let tropical_fish = Self { mob_entity }; let mob_arc = Arc::new(tropical_fish); @@ -26,7 +26,7 @@ impl TropicalFishEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); diff --git a/pumpkin/src/entity/passive/turtle.rs b/pumpkin/src/entity/passive/turtle.rs index 93987018c..13df77549 100644 --- a/pumpkin/src/entity/passive/turtle.rs +++ b/pumpkin/src/entity/passive/turtle.rs @@ -18,7 +18,7 @@ pub struct TurtleEntity { } impl TurtleEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let turtle = Self { mob_entity }; let mob_arc = Arc::new(turtle); @@ -28,7 +28,7 @@ impl TurtleEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(1, Box::new(SwimGoal::default())); goal_selector.add_goal(2, BreedGoal::new(1.0)); diff --git a/pumpkin/src/entity/passive/villager/mod.rs b/pumpkin/src/entity/passive/villager/mod.rs index aa349ae3f..08395f27e 100644 --- a/pumpkin/src/entity/passive/villager/mod.rs +++ b/pumpkin/src/entity/passive/villager/mod.rs @@ -12,8 +12,7 @@ use pumpkin_inventory::screen_handler::{ BoxFuture, InventoryPlayer, ScreenHandlerFactory, SharedScreenHandler, }; use pumpkin_nbt::compound::NbtCompound; -use pumpkin_protocol::codec::var_int::VarInt; -use pumpkin_protocol::java::client::play::{CMerchantOffers, Metadata}; +use pumpkin_protocol::java::client::play::Metadata; use pumpkin_util::text::TextComponent; use pumpkin_world::inventory::SimpleInventory; use tokio::sync::Mutex; @@ -45,12 +44,10 @@ pub struct VillagerEntity { pub inventory: Arc>>>>, pub merchant_inventory: Arc, pub offers: Mutex>, - pub self_arc: Mutex>>, } impl VillagerEntity { - #[expect(clippy::too_many_lines)] - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let villager_data = VillagerData { r#type: VillagerType::Plains, @@ -74,17 +71,15 @@ impl VillagerEntity { inventory, merchant_inventory: Arc::new(SimpleInventory::new(3)), offers: Mutex::new(Vec::new()), - self_arc: Mutex::new(None), }; let mob_arc = Arc::new(villager); - *mob_arc.self_arc.lock().await = Some(Arc::downgrade(&mob_arc)); let mob_weak: Weak = { let mob_arc: Arc = mob_arc.clone(); Arc::downgrade(&mob_arc) }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); // Villagers avoid threats @@ -149,14 +144,11 @@ impl VillagerEntity { }; // Send initial metadata - mob_arc - .get_entity() - .send_meta_data(&[Metadata::new( - TrackedData::VILLAGER_DATA, - MetaDataType::VILLAGER_DATA, - villager_data, - )]) - .await; + mob_arc.get_entity().send_meta_data(&[Metadata::new( + TrackedData::VILLAGER_DATA, + MetaDataType::VILLAGER_DATA, + villager_data, + )]); mob_arc } @@ -204,18 +196,16 @@ impl VillagerEntity { let mut villager_data = self.villager_data.lock().await; let old_profession = villager_data.profession; *villager_data = data; - self.get_entity() - .send_meta_data(&[Metadata::new( - TrackedData::VILLAGER_DATA, - MetaDataType::VILLAGER_DATA, - data, - )]) - .await; + self.get_entity().send_meta_data(&[Metadata::new( + TrackedData::VILLAGER_DATA, + MetaDataType::VILLAGER_DATA, + data, + )]); if old_profession != data.profession { self.generate_trades(data.profession, data.level).await; if let Some(sound) = data.profession.work_sound() { - self.get_entity().play_sound(sound).await; + self.get_entity().play_sound(sound); } } } @@ -257,38 +247,32 @@ impl VillagerEntity { } } - pub async fn set_unhappy(&self) { + pub fn set_unhappy(&self) { let entity = self.get_entity(); entity .world .load() - .send_entity_status(entity, pumpkin_data::entity::EntityStatus::VillagerAngry) - .await; - entity - .play_sound(pumpkin_data::sound::Sound::EntityVillagerNo) - .await; + .send_entity_status(entity, pumpkin_data::entity::EntityStatus::VillagerAngry); + entity.play_sound(pumpkin_data::sound::Sound::EntityVillagerNo); } - pub async fn open_trading_screen(&self, player: &Arc) { - let self_weak = self.self_arc.lock().await; - if let Some(self_arc) = self_weak.as_ref().and_then(std::sync::Weak::upgrade) { - player.open_handled_screen(&*self_arc, None).await; + pub const fn open_trading_screen(&self, _player: &Arc) { + // let self_weak = self.self_arc.lock().await; + // if let Some(self_arc) = self_weak.as_ref().and_then(std::sync::Weak::upgrade) { + // player.open_handled_screen(&*self_arc, None); - let offers = self.offers.lock().await; - let villager_data = self.villager_data.lock().await; + // let offers = self.offers.lock().await; + // let villager_data = self.villager_data.lock().await; - player - .client - .enqueue_packet(&CMerchantOffers::new( - player.screen_handler_sync_id.load(Ordering::Relaxed).into(), - offers.clone(), - VarInt(villager_data.level), - VarInt(self.xp.load(Ordering::Relaxed)), - true, - true, - )) - .await; - } + // player.client.enqueue_packet(&CMerchantOffers::new( + // player.screen_handler_sync_id.load(Ordering::Relaxed).into(), + // offers.clone(), + // VarInt(villager_data.level), + // VarInt(self.xp.load(Ordering::Relaxed)), + // true, + // true, + // )); + // } } } @@ -471,18 +455,18 @@ impl Mob for VillagerEntity { let player = player.clone(); Box::pin(async move { if self.get_entity().age.load(Ordering::Relaxed) < 0 { - self.set_unhappy().await; + self.set_unhappy(); return true; } let offers = self.offers.lock().await; if offers.is_empty() { - self.set_unhappy().await; + self.set_unhappy(); return true; } drop(offers); - self.open_trading_screen(&player).await; + self.open_trading_screen(&player); true }) diff --git a/pumpkin/src/entity/passive/wandering_trader.rs b/pumpkin/src/entity/passive/wandering_trader.rs index 2fd3ef78f..9264b1675 100644 --- a/pumpkin/src/entity/passive/wandering_trader.rs +++ b/pumpkin/src/entity/passive/wandering_trader.rs @@ -16,7 +16,7 @@ pub struct WanderingTraderEntity { } impl WanderingTraderEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let trader = Self { mob_entity }; let mob_arc = Arc::new(trader); @@ -26,7 +26,7 @@ impl WanderingTraderEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(0.6))); diff --git a/pumpkin/src/entity/passive/wolf.rs b/pumpkin/src/entity/passive/wolf.rs index b0c3b73ec..a410f3411 100644 --- a/pumpkin/src/entity/passive/wolf.rs +++ b/pumpkin/src/entity/passive/wolf.rs @@ -18,7 +18,7 @@ pub struct WolfEntity { } impl WolfEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let wolf = Self { mob_entity }; let mob_arc = Arc::new(wolf); @@ -28,7 +28,7 @@ impl WolfEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(1, Box::new(SwimGoal::default())); // goal_selector.add_goal(2, SitGoal::new(mob_arc.clone())); diff --git a/pumpkin/src/entity/passive/zombie_horse.rs b/pumpkin/src/entity/passive/zombie_horse.rs index 4c64bdd2d..c72a65e6d 100644 --- a/pumpkin/src/entity/passive/zombie_horse.rs +++ b/pumpkin/src/entity/passive/zombie_horse.rs @@ -16,7 +16,7 @@ pub struct ZombieHorseEntity { } impl ZombieHorseEntity { - pub async fn new(entity: Entity) -> Arc { + pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let horse = Self { mob_entity }; let mob_arc = Arc::new(horse); @@ -26,7 +26,7 @@ impl ZombieHorseEntity { }; { - let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await; + let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().unwrap(); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(0.7))); diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 057160def..9a3e2e75f 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -688,15 +688,13 @@ impl Player { *self.display_name.lock().await = display_name.clone(); // Update the tab list for everyone let world = self.world(); - world - .broadcast_packet_all(&CPlayerInfoUpdate::new( - PlayerInfoFlags::UPDATE_DISPLAY_NAME.bits(), - &[pumpkin_protocol::java::client::play::Player { - uuid: self.gameprofile.id, - actions: &[PlayerAction::UpdateDisplayName(display_name.as_ref())], - }], - )) - .await; + world.broadcast_packet_all(&CPlayerInfoUpdate::new( + PlayerInfoFlags::UPDATE_DISPLAY_NAME.bits(), + &[pumpkin_protocol::java::client::play::Player { + uuid: self.gameprofile.id, + actions: &[PlayerAction::UpdateDisplayName(display_name.as_ref())], + }], + )); } pub async fn get_tab_list_name(&self) -> Option { @@ -706,57 +704,49 @@ impl Player { pub async fn set_tab_list_name(&self, name: Option) { *self.tab_list_name.lock().await = name.clone(); let world = self.world(); - world - .broadcast_packet_all(&CPlayerInfoUpdate::new( - PlayerInfoFlags::UPDATE_DISPLAY_NAME.bits(), - &[pumpkin_protocol::java::client::play::Player { - uuid: self.gameprofile.id, - actions: &[PlayerAction::UpdateDisplayName(name.as_ref())], - }], - )) - .await; + world.broadcast_packet_all(&CPlayerInfoUpdate::new( + PlayerInfoFlags::UPDATE_DISPLAY_NAME.bits(), + &[pumpkin_protocol::java::client::play::Player { + uuid: self.gameprofile.id, + actions: &[PlayerAction::UpdateDisplayName(name.as_ref())], + }], + )); } - pub async fn set_tab_list_order(&self, order: i32) { + pub fn set_tab_list_order(&self, order: i32) { self.tab_list_order.store(order, Ordering::Relaxed); let world = self.world(); - world - .broadcast_packet_all(&CPlayerInfoUpdate::new( - PlayerInfoFlags::UPDATE_LIST_PRIORITY.bits(), - &[pumpkin_protocol::java::client::play::Player { - uuid: self.gameprofile.id, - actions: &[PlayerAction::UpdateListOrder(VarInt(order))], - }], - )) - .await; + world.broadcast_packet_all(&CPlayerInfoUpdate::new( + PlayerInfoFlags::UPDATE_LIST_PRIORITY.bits(), + &[pumpkin_protocol::java::client::play::Player { + uuid: self.gameprofile.id, + actions: &[PlayerAction::UpdateListOrder(VarInt(order))], + }], + )); } - pub async fn set_tab_list_latency(&self, latency: i32) { + pub fn set_tab_list_latency(&self, latency: i32) { self.tab_list_latency.store(latency, Ordering::Relaxed); let world = self.world(); - world - .broadcast_packet_all(&CPlayerInfoUpdate::new( - PlayerInfoFlags::UPDATE_LATENCY.bits(), - &[pumpkin_protocol::java::client::play::Player { - uuid: self.gameprofile.id, - actions: &[PlayerAction::UpdateLatency(VarInt(latency))], - }], - )) - .await; + world.broadcast_packet_all(&CPlayerInfoUpdate::new( + PlayerInfoFlags::UPDATE_LATENCY.bits(), + &[pumpkin_protocol::java::client::play::Player { + uuid: self.gameprofile.id, + actions: &[PlayerAction::UpdateLatency(VarInt(latency))], + }], + )); } - pub async fn set_tab_list_listed(&self, listed: bool) { + pub fn set_tab_list_listed(&self, listed: bool) { self.tab_list_listed.store(listed, Ordering::Relaxed); let world = self.world(); - world - .broadcast_packet_all(&CPlayerInfoUpdate::new( - PlayerInfoFlags::UPDATE_LISTED.bits(), - &[pumpkin_protocol::java::client::play::Player { - uuid: self.gameprofile.id, - actions: &[PlayerAction::UpdateListed(listed)], - }], - )) - .await; + world.broadcast_packet_all(&CPlayerInfoUpdate::new( + PlayerInfoFlags::UPDATE_LISTED.bits(), + &[pumpkin_protocol::java::client::play::Player { + uuid: self.gameprofile.id, + actions: &[PlayerAction::UpdateListed(listed)], + }], + )); } /// Spawns a task associated with this player-client. All tasks spawned with this method are awaited @@ -920,13 +910,11 @@ impl Player { ) .await { - world - .play_sound( - Sound::EntityPlayerAttackNodamage, - SoundCategory::Players, - &self.living_entity.entity.pos.load(), - ) - .await; + world.play_sound( + Sound::EntityPlayerAttackNodamage, + SoundCategory::Players, + &self.living_entity.entity.pos.load(), + ); return; } @@ -945,17 +933,15 @@ impl Player { if is_mace_smash { let fall_distance = self.living_entity.fall_distance.load(); self.living_entity.fall_distance.store(0.0); - world - .play_sound( - if fall_distance > 5.0 { - Sound::ItemMaceSmashGroundHeavy - } else { - Sound::ItemMaceSmashGround - }, - SoundCategory::Players, - &pos, - ) - .await; + world.play_sound( + if fall_distance > 5.0 { + Sound::ItemMaceSmashGroundHeavy + } else { + Sound::ItemMaceSmashGround + }, + SoundCategory::Players, + &pos, + ); } player_attack_sound(&pos, &world, attack_type).await; @@ -977,7 +963,7 @@ impl Player { match attack_type { AttackType::Knockback => knockback_strength += 1.0, AttackType::Sweeping => { - combat::spawn_sweep_particle(attacker_entity, &world, &pos).await; + combat::spawn_sweep_particle(attacker_entity, &world, &pos); let mut sweep_damage = 1.0; if let Some(enchantments) = item_stack @@ -1061,12 +1047,10 @@ impl Player { if slot_index == self.inventory.get_selected_slot() as usize { self.living_entity - .send_equipment_changes(&[(EquipmentSlot::MAIN_HAND, stack)]) - .await; + .send_equipment_changes(&[(EquipmentSlot::MAIN_HAND, stack)]); } else if slot_index == PlayerInventory::OFF_HAND_SLOT { self.living_entity - .send_equipment_changes(&[(EquipmentSlot::OFF_HAND, stack)]) - .await; + .send_equipment_changes(&[(EquipmentSlot::OFF_HAND, stack)]); } } @@ -1106,12 +1090,10 @@ impl Player { // Send the break status before clearing the slot so the client can // use the item texture for break particles. if result == pumpkin_data::item_stack::DamageResult::Broken { - self.world() - .send_entity_status( - &self.living_entity.entity, - super::equipment_break_status(slot), - ) - .await; + self.world().send_entity_status( + &self.living_entity.entity, + super::equipment_break_status(slot), + ); } self.enqueue_slot_set_packet(&CSetPlayerInventory::new( @@ -1121,8 +1103,7 @@ impl Player { .await; self.living_entity - .send_equipment_changes(&[(slot.clone(), updated_stack)]) - .await; + .send_equipment_changes(&[(slot.clone(), updated_stack)]); return true; } @@ -1218,13 +1199,13 @@ impl Player { let respawn_point = respawn_guard.as_ref()?; let world = self.world(); let pos = &respawn_point.position; - let (block, state_id) = world.get_block_and_state_id(pos).await; + let (block, state_id) = world.get_block_and_state_id(pos); // If force is set (from /spawnpoint command), validate position is safe if respawn_point.force { // For forced spawn, check if both the block and block above allow mob spawn - let block_state = world.get_block_state(pos).await; - let above_state = world.get_block_state(&pos.up()).await; + let block_state = world.get_block_state(pos); + let above_state = world.get_block_state(&pos.up()); // Check if blocks are passable (non-solid or air) let block_safe = block_state.is_air() || !block_state.is_solid(); @@ -1258,7 +1239,7 @@ impl Player { // Try positions around the bed based on facing direction // Vanilla tries multiple offset patterns; we use a simplified version if let Some(spawn_pos) = - Self::find_bed_spawn_position(&world, pos, facing, respawn_point.yaw).await + Self::find_bed_spawn_position(&world, pos, facing, respawn_point.yaw) { return Some(CalculatedRespawnPoint { position: spawn_pos, @@ -1281,7 +1262,7 @@ impl Player { } // Try positions around the anchor - if let Some(spawn_pos) = Self::find_anchor_spawn_position(&world, pos).await { + if let Some(spawn_pos) = Self::find_anchor_spawn_position(&world, pos) { // Decrement charges after successful respawn position found let new_charges = charges - 1; let mut new_props = anchor_props; @@ -1310,7 +1291,7 @@ impl Player { /// Find a valid spawn position around a bed. /// Vanilla uses a complex algorithm based on bed facing direction. /// We use a simplified version that tries cardinal directions first. - async fn find_bed_spawn_position( + fn find_bed_spawn_position( world: &Arc, bed_pos: &BlockPos, facing: HorizontalFacing, @@ -1326,7 +1307,7 @@ impl Player { bed_pos.0.z + dz, )); - if let Some(pos) = Self::find_respawn_pos(world, &check_pos).await { + if let Some(pos) = Self::find_respawn_pos(world, &check_pos) { return Some(pos); } @@ -1336,13 +1317,13 @@ impl Player { bed_pos.0.y - 1, bed_pos.0.z + dz, )); - if let Some(pos) = Self::find_respawn_pos(world, &check_pos_down).await { + if let Some(pos) = Self::find_respawn_pos(world, &check_pos_down) { return Some(pos); } } // Try on the bed itself as last resort - if let Some(pos) = Self::find_respawn_pos(world, bed_pos).await { + if let Some(pos) = Self::find_respawn_pos(world, bed_pos) { return Some(pos); } @@ -1377,7 +1358,7 @@ impl Player { } /// Find a valid spawn position around a respawn anchor. - async fn find_anchor_spawn_position( + fn find_anchor_spawn_position( world: &Arc, anchor_pos: &BlockPos, ) -> Option> { @@ -1402,7 +1383,7 @@ impl Player { anchor_pos.0.z + dz, )); - if let Some(pos) = Self::find_respawn_pos(world, &check_pos).await { + if let Some(pos) = Self::find_respawn_pos(world, &check_pos) { return Some(pos); } } @@ -1410,26 +1391,23 @@ impl Player { // Also try directly above the anchor let above_pos = anchor_pos.up(); - Self::find_respawn_pos(world, &above_pos).await + Self::find_respawn_pos(world, &above_pos) } /// Check if a position is valid for respawning (vanilla Dismounting.findRespawnPos logic). /// Returns the spawn position if valid, None otherwise. - async fn find_respawn_pos( - world: &Arc, - pos: &BlockPos, - ) -> Option> { - let state = world.get_block_state(pos).await; - let below_state = world.get_block_state(&pos.down()).await; + fn find_respawn_pos(world: &Arc, pos: &BlockPos) -> Option> { + let state = world.get_block_state(pos); + let below_state = world.get_block_state(&pos.down()); // Check if block at position is invalid for spawn (e.g., inside solid block) - let block = world.get_block(pos).await; + let block = world.get_block(pos); if block.has_tag(&tag::Block::MINECRAFT_INVALID_SPAWN_INSIDE) { return None; } // Check if block above is also invalid - let above_block = world.get_block(&pos.up()).await; + let above_block = world.get_block(&pos.up()); if above_block.has_tag(&tag::Block::MINECRAFT_INVALID_SPAWN_INSIDE) { return None; } @@ -1460,28 +1438,26 @@ impl Player { ); // Check if the space is empty (no block collisions) - if !world.is_space_empty(player_box).await { + if !world.is_space_empty(player_box) { return None; } Some(spawn_pos) } - pub async fn sleep(&self, bed_head_pos: BlockPos) { + pub fn sleep(&self, bed_head_pos: BlockPos) { // TODO: Stop riding - self.get_entity().set_pose(EntityPose::Sleeping).await; + self.get_entity().set_pose(EntityPose::Sleeping); self.living_entity .entity .set_pos(bed_head_pos.to_f64().add_raw(0.5, 0.6875, 0.5)); - self.get_entity() - .send_meta_data(&[Metadata::new( - TrackedData::SLEEPING_POS_ID, - MetaDataType::OPTIONAL_BLOCK_POS, - Some(bed_head_pos), - )]) - .await; - self.get_entity().set_velocity(Vector3::default()).await; + self.get_entity().send_meta_data(&[Metadata::new( + TrackedData::SLEEPING_POS_ID, + MetaDataType::OPTIONAL_BLOCK_POS, + Some(bed_head_pos), + )]); + self.get_entity().set_velocity(Vector3::default()); self.sleeping_since.store(Some(0)); } @@ -1533,7 +1509,7 @@ impl Player { false } - async fn can_fit_pose(&self, pose: EntityPose) -> bool { + fn can_fit_pose(&self, pose: EntityPose) -> bool { let entity = self.get_entity(); let dimensions = Entity::get_entity_dimensions(pose); let position = entity.pos.load(); @@ -1542,12 +1518,11 @@ impl Player { .world .load() .is_space_empty(aabb.contract_all(1.0E-7)) - .await } pub async fn update_player_pose(&self) { let entity = self.get_entity(); - if !self.can_fit_pose(EntityPose::Swimming).await { + if !self.can_fit_pose(EntityPose::Swimming) { return; } @@ -1568,17 +1543,17 @@ impl Player { let new_pose = if self.gamemode.load() == GameMode::Spectator || entity.has_vehicle().await - || self.can_fit_pose(desired_pose).await + || self.can_fit_pose(desired_pose) { desired_pose - } else if self.can_fit_pose(EntityPose::Crouching).await { + } else if self.can_fit_pose(EntityPose::Crouching) { EntityPose::Crouching } else { EntityPose::Swimming }; if entity.pose.load() != new_pose { - entity.set_pose(new_pose).await; + entity.set_pose(new_pose); } } @@ -1590,30 +1565,22 @@ impl Player { return; }; - let (bed, bed_state) = world.get_block_and_state_id(&respawn_point.position).await; + let (bed, bed_state) = world.get_block_and_state_id(&respawn_point.position); BedBlock::set_occupied(false, &world, bed, &respawn_point.position, bed_state).await; - self.living_entity - .entity - .set_pose(EntityPose::Standing) - .await; + self.living_entity.entity.set_pose(EntityPose::Standing); self.living_entity.entity.set_pos(self.position()); - self.living_entity - .entity - .send_meta_data(&[Metadata::new( - TrackedData::SLEEPING_POS_ID, - MetaDataType::OPTIONAL_BLOCK_POS, - None::, - )]) - .await; + self.living_entity.entity.send_meta_data(&[Metadata::new( + TrackedData::SLEEPING_POS_ID, + MetaDataType::OPTIONAL_BLOCK_POS, + None::, + )]); let chunk_pos = self.living_entity.entity.chunk_pos.load(); - world - .broadcast_to_chunk( - chunk_pos, - &CEntityAnimation::new(self.entity_id().into(), Animation::LeaveBed), - ) - .await; + world.broadcast_to_chunk( + chunk_pos, + &CEntityAnimation::new(self.entity_id().into(), Animation::LeaveBed), + ); self.sleeping_since.store(None); } @@ -1669,7 +1636,7 @@ impl Player { } } - pub async fn spawn_particle( + pub fn spawn_particle( &self, position: Vector3, offset: Vector3, @@ -1677,18 +1644,16 @@ impl Player { particle_count: i32, particle: Particle, ) { - self.client - .enqueue_packet(&CParticle::new( - false, - false, - position, - offset, - max_speed, - particle_count, - VarInt(particle as i32), - &[], - )) - .await; + self.client.try_enqueue_packet(&CParticle::new( + false, + false, + position, + offset, + max_speed, + particle_count, + VarInt(particle as i32), + &[], + )); } pub async fn play_sound( @@ -1844,7 +1809,7 @@ impl Player { if self.mining.load(Ordering::Relaxed) { let pos = self.mining_pos.lock().await; let world = self.world(); - let state = world.get_block_state(&pos).await; + let state = world.get_block_state(&pos); // Is the block broken? if state.is_air() { world @@ -2123,7 +2088,7 @@ impl Player { } /// Updates the client of the player's current permission level. - pub async fn send_permission_lvl_update(&self) { + pub fn send_permission_lvl_update(&self) { let status = match self.permission_lvl.load() { PermissionLvl::Zero => EntityStatus::PermissionLevelAll, PermissionLvl::One => EntityStatus::PermissionLevelModerators, @@ -2132,8 +2097,7 @@ impl Player { PermissionLvl::Four => EntityStatus::PermissionLevelOwners, }; self.world() - .send_entity_status(&self.living_entity.entity, status) - .await; + .send_entity_status(&self.living_entity.entity, status); } /// Sets the player's difficulty level. @@ -2156,7 +2120,7 @@ impl Player { command_dispatcher: &CommandDispatcher, ) { self.permission_lvl.store(lvl); - self.send_permission_lvl_update().await; + self.send_permission_lvl_update(); if let ClientPlatform::Bedrock(_) = &self.client { client_suggestions::send_bedrock_commands_packet(self, server, command_dispatcher) @@ -2274,7 +2238,7 @@ impl Player { 1, )).await; - self.send_permission_lvl_update().await; + self.send_permission_lvl_update(); player.clone().request_teleport(position, yaw, pitch).await; player.living_entity.entity.last_pos.store(position); @@ -2378,7 +2342,7 @@ impl Player { } pub async fn heal(&self, additional_health: f32) { - self.living_entity.heal(additional_health).await; + self.living_entity.heal(additional_health); self.send_health().await; } @@ -2432,7 +2396,7 @@ impl Player { } pub async fn set_health(&self, health: f32) { - self.living_entity.set_health(health).await; + self.living_entity.set_health(health); self.send_health().await; } @@ -2581,7 +2545,7 @@ impl Player { } // Reset air supply & drowning ticks on death - self.breath_manager.reset(self).await; + self.breath_manager.reset(self); self.client .send_packet_now(&CCombatDeath::new(self.entity_id().into(), &death_msg)) @@ -2652,8 +2616,7 @@ impl Player { uuid: self.gameprofile.id, actions: &[PlayerAction::UpdateGameMode((gamemode as i32).into())], }], - )) - .await; + )); match &self.client { crate::net::ClientPlatform::Java(client) => { @@ -2685,23 +2648,20 @@ impl Player { } /// Send the player's skin layers and used hand to all players. - pub async fn send_client_information(&self) { + pub fn send_client_information(&self) { let config = self.config.load(); - self.living_entity - .entity - .send_meta_data(&[ - Metadata::new( - TrackedData::PLAYER_MODE_CUSTOMISATION, - MetaDataType::BYTE, - config.skin_parts, - ), - // Metadata::new( - // TrackedData::DATA_MAIN_ARM_ID, - // MetaDataType::ARM, - // VarInt(config.main_hand as u8 as i32), - // ), - ]) - .await; + self.living_entity.entity.send_meta_data(&[ + Metadata::new( + TrackedData::PLAYER_MODE_CUSTOMISATION, + MetaDataType::BYTE, + config.skin_parts, + ), + // Metadata::new( + // TrackedData::DATA_MAIN_ARM_ID, + // MetaDataType::ARM, + // VarInt(config.main_hand as u8 as i32), + // ), + ]); } pub async fn can_harvest(&self, state: &BlockState, block: &'static Block) -> bool { @@ -2809,8 +2769,9 @@ impl Player { ); // TODO: Merge stacks together - let item_entity = - Arc::new(ItemEntity::new_with_velocity(entity, item_stack, velocity, 40).await); + let item_entity = Arc::new(ItemEntity::new_with_velocity( + entity, item_stack, velocity, 40, + )); self.world().spawn_entity(item_entity).await; } @@ -2852,7 +2813,7 @@ impl Player { (EquipmentSlot::MAIN_HAND, main_hand_item), (EquipmentSlot::OFF_HAND, off_hand_item), ]; - self.living_entity.send_equipment_changes(equipment).await; + self.living_entity.send_equipment_changes(equipment); // todo this.player.stopUsingItem(); } @@ -2913,7 +2874,7 @@ impl Player { let map_id = map_id_comp.id; if let Some(map_data_arc) = server.map_manager.get_map(map_id) { let mut map_data = map_data_arc.lock().await; - map_data.update(self).await; + map_data.update(self); let tick_count = self.tick_counter.load(Ordering::Relaxed); if map_data.dirty || tick_count % 10 == 0 { @@ -3191,8 +3152,7 @@ impl Player { .await; self.living_entity - .send_equipment_changes(&[(equipment_slot, updated_stack)]) - .await; + .send_equipment_changes(&[(equipment_slot, updated_stack)]); xp } @@ -3613,7 +3573,7 @@ impl Player { } /// Swing the hand of the player - pub async fn swing_hand(&self, hand: Hand, all: bool) { + pub fn swing_hand(&self, hand: Hand, all: bool) { let world = self.world(); let entity_id = VarInt(self.entity_id()); let chunk_pos = self.living_entity.entity.chunk_pos.load(); @@ -3625,11 +3585,9 @@ impl Player { let packet = CEntityAnimation::new(entity_id, animation); if all { - world.broadcast_to_chunk(chunk_pos, &packet).await; + world.broadcast_to_chunk(chunk_pos, &packet); } else { - world - .broadcast_to_chunk_except(chunk_pos, &[self.get_entity().entity_uuid], &packet) - .await; + world.broadcast_to_chunk_except(chunk_pos, &[self.get_entity().entity_uuid], &packet); } } @@ -3704,7 +3662,7 @@ impl Player { } /// Returns the main non-air `BlockPos` underneath the player. - pub async fn get_supporting_block_pos(&self) -> Option { + pub fn get_supporting_block_pos(&self) -> Option { let entity = self.get_entity(); let entity_pos = entity.pos.load(); let aabb = entity.bounding_box.load(); @@ -3724,7 +3682,7 @@ impl Player { // Iterate through candidates for pos in BlockPos::iterate(min_pos, max_pos) { - let (_, state) = world.get_block_and_state(&pos).await; + let (_, state) = world.get_block_and_state(&pos); // Only consider physical blocks if state.is_air() { @@ -3773,7 +3731,7 @@ impl Player { entity_pos.z.floor() as i32, ); - let state = world.get_block_state(&fallback_pos).await; + let state = world.get_block_state(&fallback_pos); (!state.is_air()).then_some(fallback_pos) } @@ -4121,7 +4079,7 @@ impl EntityBase for Player { entity.on_ground.load(Ordering::SeqCst), ) ) - .await; + ; } }} } else { @@ -4560,28 +4518,24 @@ impl InventoryPlayer for Player { ) -> PlayerFuture<'a, ()> { Box::pin(async move { let chunk_pos = self.living_entity.entity.chunk_pos.load(); - self.world() - .broadcast_to_chunk_except( - chunk_pos, - &[self.get_entity().entity_uuid], - &CSetEquipment::new( - self.entity_id().into(), - vec![( - slot.discriminant(), - ItemStackSerializer::from(stack.clone()), - )], - ), - ) - .await; + self.world().broadcast_to_chunk_except( + chunk_pos, + &[self.get_entity().entity_uuid], + &CSetEquipment::new( + self.entity_id().into(), + vec![( + slot.discriminant(), + ItemStackSerializer::from(stack.clone()), + )], + ), + ); if let Some(equippable) = stack.get_data_component::() { - self.world() - .play_sound_event( - equippable.equip_sound.clone(), - SoundCategory::Players, - &self.position(), - ) - .await; + self.world().play_sound_event( + &equippable.equip_sound, + SoundCategory::Players, + &self.position(), + ); } }) } diff --git a/pumpkin/src/entity/projectile/arrow.rs b/pumpkin/src/entity/projectile/arrow.rs index 906784670..f38a6d136 100644 --- a/pumpkin/src/entity/projectile/arrow.rs +++ b/pumpkin/src/entity/projectile/arrow.rs @@ -88,11 +88,11 @@ impl ArrowEntity { } } - pub async fn new_shot(entity: Entity, shooter: &Entity, pickup: ArrowPickup) -> Self { + pub fn new_shot(entity: Entity, shooter: &Entity, pickup: ArrowPickup) -> Self { let mut owner_pos = shooter.pos.load(); owner_pos.y = owner_pos.y + f64::from(shooter.entity_dimension.load().eye_height) - 0.1; entity.pos.store(owner_pos); - entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)).await; + entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); Self { entity, @@ -246,20 +246,18 @@ impl EntityBase for ArrowEntity { // Spawn critical particle trail while arrow is flying and critical if self.is_critical.load(Ordering::Relaxed) { - world - .spawn_particle( - entity.pos.load(), - Vector3::new(0.0f32, 0.0f32, 0.0f32), - 0.0, - 1, - Particle::Crit, - ) - .await; + world.spawn_particle( + entity.pos.load(), + Vector3::new(0.0f32, 0.0f32, 0.0f32), + 0.0, + 1, + Particle::Crit, + ); } // Broadcast velocity update let packet = CEntityVelocity::new(entity.entity_id.into(), velocity); - world.broadcast_packet_all(&packet).await; + world.broadcast_packet_all(&packet); // Check for collisions using raycasting let search_box = BoundingBox::new( @@ -370,7 +368,7 @@ impl EntityBase for ArrowEntity { 1.0, 0.0, ); - world.broadcast_packet_all(&sound_packet).await; + world.broadcast_packet_all(&sound_packet); // Reset critical flag self.is_critical.store(false, Ordering::Relaxed); @@ -406,7 +404,7 @@ impl EntityBase for ArrowEntity { 1.0, 0.0, ); - world.broadcast_packet_all(&sound_packet).await; + world.broadcast_packet_all(&sound_packet); } // Check pierce level diff --git a/pumpkin/src/entity/projectile/egg.rs b/pumpkin/src/entity/projectile/egg.rs index a61368638..398476777 100644 --- a/pumpkin/src/entity/projectile/egg.rs +++ b/pumpkin/src/entity/projectile/egg.rs @@ -28,9 +28,9 @@ pub struct EggEntity { } impl EggEntity { - pub async fn new(entity: Entity) -> Self { + pub fn new(entity: Entity) -> Self { // Default velocity slightly upward for thrown egg - entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)).await; + entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); let thrown = ThrownItemEntity { entity, owner_id: None, @@ -44,13 +44,10 @@ impl EggEntity { } } - pub async fn new_shot(entity: Entity, shooter: &Entity) -> Self { + pub fn new_shot(entity: Entity, shooter: &Entity) -> Self { let thrown = ThrownItemEntity::new(entity, shooter); // Default slight upward velocity - thrown - .entity - .set_velocity(Vector3::new(0.0, 0.1, 0.0)) - .await; + thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); Self { thrown, @@ -74,13 +71,11 @@ impl EntityBase for EggEntity { let stack = self.item_stack.read().await; // Sync the item stack so the client renders the correct color/variant - entity - .send_meta_data(&[Metadata::new( - TrackedData::ITEM_STACK, - MetaDataType::ITEM_STACK, - &ItemStackSerializer::from(stack.clone()), - )]) - .await; + entity.send_meta_data(&[Metadata::new( + TrackedData::ITEM_STACK, + MetaDataType::ITEM_STACK, + &ItemStackSerializer::from(stack.clone()), + )]); }) } @@ -114,9 +109,7 @@ impl EntityBase for EggEntity { let spawn_pos = hit_pos.add(&normal.multiply(0.5, 0.5, 0.5)); // Play egg break particles - world - .send_entity_status(self.get_entity(), EntityStatus::Death) - .await; + world.send_entity_status(self.get_entity(), EntityStatus::Death); // Decide spawn count per probabilities: // r == 0 -> spawn 4 (1/256) @@ -154,7 +147,7 @@ impl EntityBase for EggEntity { let spawn_pos_clone = spawn_pos; // Read the stack stored in set_item_stack - //let stack = self.item_stack.lock().await; + //let stack = self.item_stack.lock().unwrap(); // TODO: Map the item ID to the chicken variant // let variant = match stack.item.id { @@ -166,8 +159,7 @@ impl EntityBase for EggEntity { tokio::spawn(async move { for _ in 0..to_spawn { let mob = - from_type(hatching_type, spawn_pos_clone, &world_clone, Uuid::new_v4()) - .await; + from_type(hatching_type, spawn_pos_clone, &world_clone, Uuid::new_v4()); let yaw = rand::random::() * 360.0; let new_entity = mob.get_entity(); diff --git a/pumpkin/src/entity/projectile/ender_pearl.rs b/pumpkin/src/entity/projectile/ender_pearl.rs index 66567721a..4992d88f4 100644 --- a/pumpkin/src/entity/projectile/ender_pearl.rs +++ b/pumpkin/src/entity/projectile/ender_pearl.rs @@ -15,8 +15,8 @@ pub struct EnderPearlEntity { } impl EnderPearlEntity { - pub async fn new(entity: Entity) -> Self { - entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)).await; + pub fn new(entity: Entity) -> Self { + entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); let thrown = ThrownItemEntity { entity, @@ -28,12 +28,9 @@ impl EnderPearlEntity { Self { thrown } } - pub async fn new_shot(entity: Entity, shooter: &Entity) -> Self { + pub fn new_shot(entity: Entity, shooter: &Entity) -> Self { let thrown = ThrownItemEntity::new(entity, shooter); - thrown - .entity - .set_velocity(Vector3::new(0.0, 0.1, 0.0)) - .await; + thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); Self { thrown } } } @@ -84,15 +81,13 @@ impl EntityBase for EnderPearlEntity { rand::random::() - 0.5, ); - world - .spawn_particle( - hit_pos.add(&offset), - Vector3::new(speed.x as f32, speed.y as f32, speed.z as f32), - 1.0, - 1, - Particle::Portal, - ) - .await; + world.spawn_particle( + hit_pos.add(&offset), + Vector3::new(speed.x as f32, speed.y as f32, speed.z as f32), + 1.0, + 1, + Particle::Portal, + ); } if let Some(owner_id) = self.thrown.owner_id @@ -113,13 +108,11 @@ impl EntityBase for EnderPearlEntity { .await; // Play teleport sound at new position - world - .play_sound( - Sound::EntityPlayerTeleport, - SoundCategory::Players, - &teleport_pos, - ) - .await; + world.play_sound( + Sound::EntityPlayerTeleport, + SoundCategory::Players, + &teleport_pos, + ); // Deal 5 damage to owner owner @@ -131,7 +124,7 @@ impl EntityBase for EnderPearlEntity { .await; } - world.send_entity_status(entity, EntityStatus::Death).await; + world.send_entity_status(entity, EntityStatus::Death); }) } } diff --git a/pumpkin/src/entity/projectile/eye_of_ender.rs b/pumpkin/src/entity/projectile/eye_of_ender.rs index 72743eb29..d79cc7986 100644 --- a/pumpkin/src/entity/projectile/eye_of_ender.rs +++ b/pumpkin/src/entity/projectile/eye_of_ender.rs @@ -144,12 +144,12 @@ impl EntityBase for EyeOfEnder { } entity.set_pos(new_pos); - entity.send_pos_rot().await; + entity.send_pos_rot(); // Tick lifetime and handle expiry. let life = self.life.fetch_add(1, Ordering::Relaxed) + 1; if life > MAX_LIFE { - entity.play_sound(Sound::EntityEnderEyeDeath).await; + entity.play_sound(Sound::EntityEnderEyeDeath); entity.remove().await; if self.survive_after_death.load(Ordering::Relaxed) { @@ -157,18 +157,14 @@ impl EntityBase for EyeOfEnder { let item_stack = self.item_stack.lock().await.clone(); let world = entity.world.load(); let entity = Entity::new(world.clone(), new_pos, &EntityType::ITEM); - let item_entity = Arc::new(ItemEntity::new(entity, item_stack).await); + let item_entity = Arc::new(ItemEntity::new(entity, item_stack)); world.spawn_entity(item_entity).await; } else { - entity - .world - .load() - .sync_world_event( - WorldEvent::ParticlesEyeOfEnderDeath, - new_pos.to_block_pos(), - 0, - ) - .await; + entity.world.load().sync_world_event( + WorldEvent::ParticlesEyeOfEnderDeath, + new_pos.to_block_pos(), + 0, + ); } } }) @@ -176,13 +172,11 @@ impl EntityBase for EyeOfEnder { fn init_data_tracker(&self) -> EntityBaseFuture<'_, ()> { Box::pin(async { - self.entity - .send_meta_data(&[Metadata::new( - TrackedData::ITEM, - MetaDataType::ITEM_STACK, - &ItemStackSerializer::from(self.item_stack.lock().await.clone()), - )]) - .await; + self.entity.send_meta_data(&[Metadata::new( + TrackedData::ITEM, + MetaDataType::ITEM_STACK, + &ItemStackSerializer::from(self.item_stack.lock().await.clone()), + )]); }) } diff --git a/pumpkin/src/entity/projectile/firework_rocket.rs b/pumpkin/src/entity/projectile/firework_rocket.rs index 19fe32427..bc3591e82 100644 --- a/pumpkin/src/entity/projectile/firework_rocket.rs +++ b/pumpkin/src/entity/projectile/firework_rocket.rs @@ -23,16 +23,14 @@ pub struct FireworkRocketEntity { } impl FireworkRocketEntity { - pub async fn new(entity: Entity) -> Self { + pub fn new(entity: Entity) -> Self { let mut random = RandomGenerator::Xoroshiro(Xoroshiro::from_seed(get_seed())); - entity - .set_velocity(Vector3::new( - random.next_triangular(0.0, 0.002_297), - 0.05, - random.next_triangular(0.0, 0.002_297), - )) - .await; + entity.set_velocity(Vector3::new( + random.next_triangular(0.0, 0.002_297), + 0.05, + random.next_triangular(0.0, 0.002_297), + )); Self { entity: ThrownItemEntity { entity, @@ -48,20 +46,17 @@ impl FireworkRocketEntity { } } - pub async fn new_shot(entity: Entity, shooter: &Entity) -> Self { + pub fn new_shot(entity: Entity, shooter: &Entity) -> Self { let mut random = RandomGenerator::Xoroshiro(Xoroshiro::from_seed(get_seed())); // Set random initial velocity // Set on the inner entity after constructing ThrownItemEntity let thrown = ThrownItemEntity::new(entity, shooter); - thrown - .entity - .set_velocity(Vector3::new( - random.next_triangular(0.0, 0.002_297), - 0.05, - random.next_triangular(0.0, 0.002_297), - )) - .await; + thrown.entity.set_velocity(Vector3::new( + random.next_triangular(0.0, 0.002_297), + 0.05, + random.next_triangular(0.0, 0.002_297), + )); // Set random life let rocket = Self { @@ -73,24 +68,18 @@ impl FireworkRocketEntity { }; // Set shooter metadata - rocket - .entity - .entity - .send_meta_data(&[Metadata::new( - TrackedData::ATTACHED_TO_TARGET, - MetaDataType::OPTIONAL_INT, - OptionalInt(Some(shooter.entity_id)), - )]) - .await; + rocket.entity.entity.send_meta_data(&[Metadata::new( + TrackedData::ATTACHED_TO_TARGET, + MetaDataType::OPTIONAL_INT, + OptionalInt(Some(shooter.entity_id)), + )]); rocket } pub async fn explode_and_remove(&self, world: &World) { let entity = self.get_entity(); - world - .send_entity_status(entity, EntityStatus::FireworksExplode) - .await; + world.send_entity_status(entity, EntityStatus::FireworksExplode); // TODO: Explode/colors @@ -126,10 +115,10 @@ impl EntityBase for FireworkRocketEntity { let new_shooter_vel = shooter_vel + (rotation * 0.1 + (rotation * 1.5 - shooter_vel) * 0.5); - shooter.set_velocity(new_shooter_vel).await; + shooter.set_velocity(new_shooter_vel); entity.set_pos(shooter.pos.load()); - entity.set_velocity(new_shooter_vel).await; + entity.set_velocity(new_shooter_vel); } } } else { @@ -137,7 +126,7 @@ impl EntityBase for FireworkRocketEntity { velocity.x *= 1.15; velocity.z *= 1.15; velocity.y += 0.04; - entity.set_velocity(velocity).await; + entity.set_velocity(velocity); } // Increment life and check for explosion diff --git a/pumpkin/src/entity/projectile/fishing_bobber.rs b/pumpkin/src/entity/projectile/fishing_bobber.rs index 1922ed0ad..8d6930dae 100644 --- a/pumpkin/src/entity/projectile/fishing_bobber.rs +++ b/pumpkin/src/entity/projectile/fishing_bobber.rs @@ -47,7 +47,7 @@ impl FishingBobberEntity { } } - pub async fn reel_in(&self, player: &Player) -> i32 { + pub fn reel_in(&self, player: &Player) -> i32 { let world = self.entity.world.load(); let hooked_id = self.hooked_entity_id.load(Ordering::Relaxed); @@ -61,7 +61,7 @@ impl FishingBobberEntity { delta .multiply(0.1, 0.1, 0.1) .add_raw(0.0, delta.length().sqrt() * 0.08, 0.0); - hooked.get_entity().add_velocity(motion).await; + hooked.get_entity().add_velocity(motion); return 1; } @@ -72,13 +72,11 @@ impl FishingBobberEntity { let _item_stack = ItemStack::new(1, &Item::COD); // player.inventory().add_item(item_stack).await; // Need public add_item - world - .play_sound( - Sound::EntityExperienceOrbPickup, - SoundCategory::Neutral, - &player.position(), - ) - .await; + world.play_sound( + Sound::EntityExperienceOrbPickup, + SoundCategory::Neutral, + &player.position(), + ); return 1; } @@ -120,15 +118,13 @@ impl FishingBobberEntity { if bite > 0 { self.bite_countdown.store(bite - 1, Ordering::Relaxed); if bite % 5 == 0 { - world - .spawn_particle( - entity.pos.load(), - Vector3::new(0.1f32, 0.1f32, 0.1f32), - 0.0, - 5, - pumpkin_data::particle::Particle::Bubble, - ) - .await; + world.spawn_particle( + entity.pos.load(), + Vector3::new(0.1f32, 0.1f32, 0.1f32), + 0.0, + 5, + pumpkin_data::particle::Particle::Bubble, + ); } } else { let wait = self.wait_countdown.load(Ordering::Relaxed); @@ -140,13 +136,11 @@ impl FishingBobberEntity { self.wait_countdown .store(rand::random::().abs() % 600 + 100, Ordering::Relaxed); - world - .play_sound( - Sound::EntityFishingBobberSplash, - SoundCategory::Neutral, - &entity.pos.load(), - ) - .await; + world.play_sound( + Sound::EntityFishingBobberSplash, + SoundCategory::Neutral, + &entity.pos.load(), + ); } } } else { @@ -205,13 +199,11 @@ impl FishingBobberEntity { if ebb.intersects(&search_box) { self.hooked_entity_id .store(cand.get_entity().entity_id, Ordering::Relaxed); - entity - .send_meta_data(&[Metadata::new( - TrackedData::HOOKED_ENTITY, - MetaDataType::INT, - cand.get_entity().entity_id + 1, - )]) - .await; + entity.send_meta_data(&[Metadata::new( + TrackedData::HOOKED_ENTITY, + MetaDataType::INT, + cand.get_entity().entity_id + 1, + )]); return; } } diff --git a/pumpkin/src/entity/projectile/lingering_potion.rs b/pumpkin/src/entity/projectile/lingering_potion.rs index 0ae274297..8119c5079 100644 --- a/pumpkin/src/entity/projectile/lingering_potion.rs +++ b/pumpkin/src/entity/projectile/lingering_potion.rs @@ -20,8 +20,8 @@ pub struct LingeringPotionEntity { } impl LingeringPotionEntity { - pub async fn new(entity: Entity) -> Self { - entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)).await; + pub fn new(entity: Entity) -> Self { + entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); let thrown = ThrownItemEntity { entity, owner_id: None, @@ -38,12 +38,9 @@ impl LingeringPotionEntity { } } - pub async fn new_shot(entity: Entity, shooter: &Entity) -> Self { + pub fn new_shot(entity: Entity, shooter: &Entity) -> Self { let thrown = ThrownItemEntity::new(entity, shooter); - thrown - .entity - .set_velocity(Vector3::new(0.0, 0.1, 0.0)) - .await; + thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); Self { thrown, item_stack: RwLock::new(ItemStack::new( @@ -68,15 +65,13 @@ impl EntityBase for LingeringPotionEntity { let stack = self.item_stack.read().await; // Sync the item stack so the client renders the correct potion type - entity - .send_meta_data(&[pumpkin_protocol::java::client::play::Metadata::new( - pumpkin_data::tracked_data::TrackedData::ITEM_STACK, - pumpkin_data::meta_data_type::MetaDataType::ITEM_STACK, - &pumpkin_protocol::codec::item_stack_seralizer::ItemStackSerializer::from( - stack.clone(), - ), - )]) - .await; + entity.send_meta_data(&[pumpkin_protocol::java::client::play::Metadata::new( + pumpkin_data::tracked_data::TrackedData::ITEM_STACK, + pumpkin_data::meta_data_type::MetaDataType::ITEM_STACK, + &pumpkin_protocol::codec::item_stack_seralizer::ItemStackSerializer::from( + stack.clone(), + ), + )]); }) } @@ -114,9 +109,7 @@ impl EntityBase for LingeringPotionEntity { extinguish_fire_if_water_potion(&world, hit_pos, &stack).await; // Play impact particles - world - .send_entity_status(self.get_entity(), EntityStatus::Death) - .await; + world.send_entity_status(self.get_entity(), EntityStatus::Death); // Read stored item stack and compute potion effects let stack = self.item_stack.read().await.clone(); @@ -177,9 +170,7 @@ impl EntityBase for LingeringPotionEntity { hit_pos.y.floor() as i32, hit_pos.z.floor() as i32, )); - world - .broadcast_packet_all(&CWorldEvent::new(event_id, block_pos, color, false)) - .await; + world.broadcast_packet_all(&CWorldEvent::new(event_id, block_pos, color, false)); // Spawn and configure an `AreaEffectCloud` entity let cloud_entity = crate::entity::Entity::from_uuid( diff --git a/pumpkin/src/entity/projectile/mod.rs b/pumpkin/src/entity/projectile/mod.rs index b1db14a8d..8864c2fc5 100644 --- a/pumpkin/src/entity/projectile/mod.rs +++ b/pumpkin/src/entity/projectile/mod.rs @@ -138,7 +138,7 @@ impl ThrownItemEntity { // Send updated velocity to clients let packet = CEntityVelocity::new(entity.entity_id.into(), velocity); - world.broadcast_packet_all(&packet).await; + world.broadcast_packet_all(&packet); // Calculate search box for collisions let search_box = BoundingBox::new( diff --git a/pumpkin/src/entity/projectile/shulker_bullet.rs b/pumpkin/src/entity/projectile/shulker_bullet.rs index 5c52110ad..7ada4b068 100644 --- a/pumpkin/src/entity/projectile/shulker_bullet.rs +++ b/pumpkin/src/entity/projectile/shulker_bullet.rs @@ -308,29 +308,24 @@ impl EntityBase for ShulkerBulletEntity { let entity = &self.entity; let world = entity.world.load(); let pos = entity.pos.load(); - world - .play_sound_fine( - Sound::EntityShulkerBulletHit, - SoundCategory::Hostile, - &pos, - 1.0, - 1.0, - ) - .await; - world - .spawn_particle( - pos, - Vector3::new(0.2, 0.2, 0.2), - 0.0, - 2, - Particle::Explosion, - ) - .await; + world.play_sound_fine( + Sound::EntityShulkerBulletHit, + SoundCategory::Hostile, + &pos, + 1.0, + 1.0, + ); + world.spawn_particle( + pos, + Vector3::new(0.2, 0.2, 0.2), + 0.0, + 2, + Particle::Explosion, + ); entity.remove().await; true }) } - #[allow(clippy::too_many_lines)] fn tick<'a>( &'a self, @@ -349,24 +344,20 @@ impl EntityBase for ShulkerBulletEntity { let entity = &self.entity; let world = entity.world.load(); let pos = entity.pos.load(); - world - .play_sound_fine( - Sound::EntityShulkerBulletHit, - SoundCategory::Hostile, - &pos, - 1.0, - 1.0, - ) - .await; - world - .spawn_particle( - pos, - Vector3::new(0.2, 0.2, 0.2), - 0.0, - 2, - Particle::Explosion, - ) - .await; + world.play_sound_fine( + Sound::EntityShulkerBulletHit, + SoundCategory::Hostile, + &pos, + 1.0, + 1.0, + ); + world.spawn_particle( + pos, + Vector3::new(0.2, 0.2, 0.2), + 0.0, + 2, + Particle::Explosion, + ); entity.remove().await; } return; @@ -435,44 +426,36 @@ impl EntityBase for ShulkerBulletEntity { entity.set_pos(new_pos); // Broadcast position and velocity - world - .broadcast_packet_all(&CEntityPositionSync::new( - entity.entity_id.into(), - new_pos, - vel, - entity.yaw.load(), - entity.pitch.load(), - false, - )) - .await; - world - .broadcast_packet_all(&CEntityVelocity::new(entity.entity_id.into(), vel)) - .await; + world.broadcast_packet_all(&CEntityPositionSync::new( + entity.entity_id.into(), + new_pos, + vel, + entity.yaw.load(), + entity.pitch.load(), + false, + )); + world.broadcast_packet_all(&CEntityVelocity::new(entity.entity_id.into(), vel)); // Check for block collisions let new_bp = entity.block_pos.load(); - let state = world.get_block_state(&new_bp).await; + let state = world.get_block_state(&new_bp); if !state.is_air() && state.is_solid() { if !self.has_hit.swap(true, Ordering::SeqCst) { let pos = entity.pos.load(); - world - .play_sound_fine( - Sound::EntityShulkerBulletHit, - SoundCategory::Hostile, - &pos, - 1.0, - 1.0, - ) - .await; - world - .spawn_particle( - pos, - Vector3::new(0.2, 0.2, 0.2), - 0.0, - 2, - Particle::Explosion, - ) - .await; + world.play_sound_fine( + Sound::EntityShulkerBulletHit, + SoundCategory::Hostile, + &pos, + 1.0, + 1.0, + ); + world.spawn_particle( + pos, + Vector3::new(0.2, 0.2, 0.2), + 0.0, + 2, + Particle::Explosion, + ); entity.remove().await; } return; @@ -545,15 +528,13 @@ impl EntityBase for ShulkerBulletEntity { } let pos = entity.pos.load(); - world - .spawn_particle( - pos, - Vector3::new(0.2, 0.2, 0.2), - 0.0, - 2, - Particle::Explosion, - ) - .await; + world.spawn_particle( + pos, + Vector3::new(0.2, 0.2, 0.2), + 0.0, + 2, + Particle::Explosion, + ); entity.remove().await; break; } diff --git a/pumpkin/src/entity/projectile/snowball.rs b/pumpkin/src/entity/projectile/snowball.rs index 42dc0e83c..1944ee6c4 100644 --- a/pumpkin/src/entity/projectile/snowball.rs +++ b/pumpkin/src/entity/projectile/snowball.rs @@ -15,9 +15,9 @@ pub struct SnowballEntity { } impl SnowballEntity { - pub async fn new(entity: Entity) -> Self { + pub fn new(entity: Entity) -> Self { // Keep the velocity initialization - entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)).await; + entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); // Initialize without owner let thrown = ThrownItemEntity { @@ -30,12 +30,9 @@ impl SnowballEntity { Self { thrown } } - pub async fn new_shot(entity: Entity, shooter: &Entity) -> Self { + pub fn new_shot(entity: Entity, shooter: &Entity) -> Self { let thrown = ThrownItemEntity::new(entity, shooter); - thrown - .entity - .set_velocity(Vector3::new(0.0, 0.1, 0.0)) - .await; + thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); Self { thrown } } } @@ -72,9 +69,7 @@ impl EntityBase for SnowballEntity { let world = self.get_entity().world.load(); // Always send particle status regardless of what was hit - world - .send_entity_status(self.get_entity(), EntityStatus::Death) - .await; + world.send_entity_status(self.get_entity(), EntityStatus::Death); // Handle entity-specific damage if let ProjectileHit::Entity { ref entity, .. } = hit { diff --git a/pumpkin/src/entity/projectile/splash_potion.rs b/pumpkin/src/entity/projectile/splash_potion.rs index bb1e35238..b48e8e666 100644 --- a/pumpkin/src/entity/projectile/splash_potion.rs +++ b/pumpkin/src/entity/projectile/splash_potion.rs @@ -20,8 +20,8 @@ pub struct SplashPotionEntity { } impl SplashPotionEntity { - pub async fn new(entity: Entity) -> Self { - entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)).await; + pub fn new(entity: Entity) -> Self { + entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); let thrown = ThrownItemEntity { entity, owner_id: None, @@ -35,12 +35,9 @@ impl SplashPotionEntity { } } - pub async fn new_shot(entity: Entity, shooter: &Entity) -> Self { + pub fn new_shot(entity: Entity, shooter: &Entity) -> Self { let thrown = ThrownItemEntity::new(entity, shooter); - thrown - .entity - .set_velocity(Vector3::new(0.0, 0.1, 0.0)) - .await; + thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0)); Self { thrown, item_stack: RwLock::new(ItemStack::new(1, &pumpkin_data::item::Item::SPLASH_POTION)), @@ -82,10 +79,10 @@ async fn extinguish_fire(world: &Arc, hit_pos: Vector3 p.y.floor() as i32, p.z.floor() as i32, )); - let state_id = world.get_block_state_id(&pos).await; + let state_id = world.get_block_state_id(&pos); let raw_block_id = Block::get_raw_id_from_state_id(state_id); if raw_block_id == fire_id || raw_block_id == soul_fire_id { - let _ = world + world .set_block_state(&pos, air_state_id, BlockFlags::NOTIFY_ALL) .await; } @@ -109,15 +106,13 @@ impl EntityBase for SplashPotionEntity { let stack = self.item_stack.read().await; // Sync the item stack - entity - .send_meta_data(&[pumpkin_protocol::java::client::play::Metadata::new( - pumpkin_data::tracked_data::TrackedData::ITEM_STACK, - pumpkin_data::meta_data_type::MetaDataType::ITEM_STACK, - &pumpkin_protocol::codec::item_stack_seralizer::ItemStackSerializer::from( - stack.clone(), - ), - )]) - .await; + entity.send_meta_data(&[pumpkin_protocol::java::client::play::Metadata::new( + pumpkin_data::tracked_data::TrackedData::ITEM_STACK, + pumpkin_data::meta_data_type::MetaDataType::ITEM_STACK, + &pumpkin_protocol::codec::item_stack_seralizer::ItemStackSerializer::from( + stack.clone(), + ), + )]); }) } @@ -211,9 +206,7 @@ impl EntityBase for SplashPotionEntity { hit_pos.y.floor() as i32, hit_pos.z.floor() as i32, )); - world - .broadcast_packet_all(&CWorldEvent::new(event_id, block_pos, color, false)) - .await; + world.broadcast_packet_all(&CWorldEvent::new(event_id, block_pos, color, false)); // If no effects, just splash (like water bottles) if effects.is_empty() { diff --git a/pumpkin/src/entity/tnt.rs b/pumpkin/src/entity/tnt.rs index b53d98da4..a47a31f38 100644 --- a/pumpkin/src/entity/tnt.rs +++ b/pumpkin/src/entity/tnt.rs @@ -55,8 +55,8 @@ impl EntityBase for TNTEntity { } if entity.velocity_dirty.swap(false, Ordering::SeqCst) { - entity.send_pos_rot().await; - entity.send_velocity().await; + entity.send_pos_rot(); + entity.send_velocity(); } // FIX: Prevent fuse underflow (vanilla parity) @@ -83,23 +83,20 @@ impl EntityBase for TNTEntity { let pos: f64 = rand::random::() * TAU; self.entity - .set_velocity(Vector3::new(-pos.sin() * 0.02, 0.2, -pos.cos() * 0.02)) - .await; + .set_velocity(Vector3::new(-pos.sin() * 0.02, 0.2, -pos.cos() * 0.02)); - self.entity - .send_meta_data(&[ - Metadata::new( - TrackedData::FUSE_ID, - MetaDataType::INTEGER, - VarInt(self.fuse.load(Relaxed) as i32), - ), - Metadata::new( - TrackedData::BLOCK_STATE_ID, - MetaDataType::BLOCK_STATE, - VarInt(i32::from(Block::TNT.default_state.id)), - ), - ]) - .await; + self.entity.send_meta_data(&[ + Metadata::new( + TrackedData::FUSE_ID, + MetaDataType::INTEGER, + VarInt(self.fuse.load(Relaxed) as i32), + ), + Metadata::new( + TrackedData::BLOCK_STATE_ID, + MetaDataType::BLOCK_STATE, + VarInt(i32::from(Block::TNT.default_state.id)), + ), + ]); }) } diff --git a/pumpkin/src/entity/type.rs b/pumpkin/src/entity/type.rs index 0181b273d..27170ff30 100644 --- a/pumpkin/src/entity/type.rs +++ b/pumpkin/src/entity/type.rs @@ -116,7 +116,7 @@ use pumpkin_data::item_stack::ItemStack; use std::sync::atomic::AtomicBool; #[expect(clippy::too_many_lines)] -pub async fn from_type( +pub fn from_type( entity_type: &'static EntityType, position: Vector3, world: &Arc, @@ -126,94 +126,94 @@ pub async fn from_type( let mob: Arc = match entity_type.id { // Zombie - id if id == EntityType::ZOMBIE.id => ZombieEntity::new(entity).await, - id if id == EntityType::DROWNED.id => DrownedEntity::new(entity).await, - id if id == EntityType::HUSK.id => HuskEntity::new(entity).await, - id if id == EntityType::ZOMBIE_VILLAGER.id => ZombieVillagerEntity::new(entity).await, - id if id == EntityType::ZOMBIFIED_PIGLIN.id => ZombifiedPiglinEntity::new(entity).await, + id if id == EntityType::ZOMBIE.id => ZombieEntity::new(entity), + id if id == EntityType::DROWNED.id => DrownedEntity::new(entity), + id if id == EntityType::HUSK.id => HuskEntity::new(entity), + id if id == EntityType::ZOMBIE_VILLAGER.id => ZombieVillagerEntity::new(entity), + id if id == EntityType::ZOMBIFIED_PIGLIN.id => ZombifiedPiglinEntity::new(entity), // Skeleton - id if id == EntityType::SKELETON.id => SkeletonEntity::new(entity).await, - id if id == EntityType::BOGGED.id => BoggedSkeletonEntity::new(entity).await, - id if id == EntityType::PARCHED.id => ParchedSkeletonEntity::new(entity).await, - id if id == EntityType::WITHER_SKELETON.id => WitherSkeletonEntity::new(entity).await, - id if id == EntityType::STRAY.id => StraySkeletonEntity::new(entity).await, + id if id == EntityType::SKELETON.id => SkeletonEntity::new(entity), + id if id == EntityType::BOGGED.id => BoggedSkeletonEntity::new(entity), + id if id == EntityType::PARCHED.id => ParchedSkeletonEntity::new(entity), + id if id == EntityType::WITHER_SKELETON.id => WitherSkeletonEntity::new(entity), + id if id == EntityType::STRAY.id => StraySkeletonEntity::new(entity), - id if id == EntityType::BAT.id => BatEntity::new(entity).await, - id if id == EntityType::CREEPER.id => CreeperEntity::new(entity).await, - id if id == EntityType::ENDERMAN.id => EndermanEntity::new(entity).await, + id if id == EntityType::BAT.id => BatEntity::new(entity), + id if id == EntityType::CREEPER.id => CreeperEntity::new(entity), + id if id == EntityType::ENDERMAN.id => EndermanEntity::new(entity), - id if id == EntityType::BLAZE.id => BlazeEntity::new(entity).await, - id if id == EntityType::SPIDER.id => SpiderEntity::new(entity).await, - id if id == EntityType::CAVE_SPIDER.id => CaveSpiderEntity::new(entity).await, - id if id == EntityType::GHAST.id => GhastEntity::new(entity).await, - id if id == EntityType::MAGMA_CUBE.id => MagmaCubeEntity::new(entity).await, - id if id == EntityType::PHANTOM.id => PhantomEntity::new(entity).await, - id if id == EntityType::WITCH.id => WitchEntity::new(entity).await, - id if id == EntityType::PIGLIN.id => PiglinEntity::new(entity).await, - id if id == EntityType::PIGLIN_BRUTE.id => PiglinBruteEntity::new(entity).await, - id if id == EntityType::PILLAGER.id => PillagerEntity::new(entity).await, - id if id == EntityType::VINDICATOR.id => VindicatorEntity::new(entity).await, - id if id == EntityType::EVOKER.id => EvokerEntity::new(entity).await, - id if id == EntityType::RAVAGER.id => RavagerEntity::new(entity).await, - id if id == EntityType::GUARDIAN.id => GuardianEntity::new(entity).await, - id if id == EntityType::ELDER_GUARDIAN.id => ElderGuardianEntity::new(entity).await, - id if id == EntityType::WARDEN.id => WardenEntity::new(entity).await, - id if id == EntityType::HOGLIN.id => HoglinEntity::new(entity).await, - id if id == EntityType::ZOGLIN.id => ZoglinEntity::new(entity).await, - id if id == EntityType::BREEZE.id => BreezeEntity::new(entity).await, - id if id == EntityType::CREAKING.id => CreakingEntity::new(entity).await, - id if id == EntityType::ILLUSIONER.id => IllusionerEntity::new(entity).await, - id if id == EntityType::VEX.id => VexEntity::new(entity).await, - id if id == EntityType::ENDERMITE.id => EndermiteEntity::new(entity).await, - id if id == EntityType::GIANT.id => GiantEntity::new(entity).await, + id if id == EntityType::BLAZE.id => BlazeEntity::new(entity), + id if id == EntityType::SPIDER.id => SpiderEntity::new(entity), + id if id == EntityType::CAVE_SPIDER.id => CaveSpiderEntity::new(entity), + id if id == EntityType::GHAST.id => GhastEntity::new(entity), + id if id == EntityType::MAGMA_CUBE.id => MagmaCubeEntity::new(entity), + id if id == EntityType::PHANTOM.id => PhantomEntity::new(entity), + id if id == EntityType::WITCH.id => WitchEntity::new(entity), + id if id == EntityType::PIGLIN.id => PiglinEntity::new(entity), + id if id == EntityType::PIGLIN_BRUTE.id => PiglinBruteEntity::new(entity), + id if id == EntityType::PILLAGER.id => PillagerEntity::new(entity), + id if id == EntityType::VINDICATOR.id => VindicatorEntity::new(entity), + id if id == EntityType::EVOKER.id => EvokerEntity::new(entity), + id if id == EntityType::RAVAGER.id => RavagerEntity::new(entity), + id if id == EntityType::GUARDIAN.id => GuardianEntity::new(entity), + id if id == EntityType::ELDER_GUARDIAN.id => ElderGuardianEntity::new(entity), + id if id == EntityType::WARDEN.id => WardenEntity::new(entity), + id if id == EntityType::HOGLIN.id => HoglinEntity::new(entity), + id if id == EntityType::ZOGLIN.id => ZoglinEntity::new(entity), + id if id == EntityType::BREEZE.id => BreezeEntity::new(entity), + id if id == EntityType::CREAKING.id => CreakingEntity::new(entity), + id if id == EntityType::ILLUSIONER.id => IllusionerEntity::new(entity), + id if id == EntityType::VEX.id => VexEntity::new(entity), + id if id == EntityType::ENDERMITE.id => EndermiteEntity::new(entity), + id if id == EntityType::GIANT.id => GiantEntity::new(entity), - id if id == EntityType::CAT.id => CatEntity::new(entity).await, - id if id == EntityType::CHICKEN.id => ChickenEntity::new(entity).await, - id if id == EntityType::COW.id => CowEntity::new(entity).await, - id if id == EntityType::PIG.id => PigEntity::new(entity).await, - id if id == EntityType::SHEEP.id => SheepEntity::new(entity).await, - id if id == EntityType::WOLF.id => WolfEntity::new(entity).await, - id if id == EntityType::FOX.id => FoxEntity::new(entity).await, - id if id == EntityType::RABBIT.id => RabbitEntity::new(entity).await, - id if id == EntityType::TURTLE.id => TurtleEntity::new(entity).await, - id if id == EntityType::VILLAGER.id => VillagerEntity::new(entity).await, - id if id == EntityType::SQUID.id => SquidEntity::new(entity).await, - id if id == EntityType::HORSE.id => HorseEntity::new(entity).await, - id if id == EntityType::DONKEY.id => DonkeyEntity::new(entity).await, - id if id == EntityType::MULE.id => MuleEntity::new(entity).await, - id if id == EntityType::ZOMBIE_HORSE.id => ZombieHorseEntity::new(entity).await, - id if id == EntityType::SKELETON_HORSE.id => SkeletonHorseEntity::new(entity).await, - id if id == EntityType::LLAMA.id => LlamaEntity::new(entity).await, - id if id == EntityType::TRADER_LLAMA.id => TraderLlamaEntity::new(entity).await, - id if id == EntityType::WANDERING_TRADER.id => WanderingTraderEntity::new(entity).await, - id if id == EntityType::ALLAY.id => AllayEntity::new(entity).await, - id if id == EntityType::ARMADILLO.id => ArmadilloEntity::new(entity).await, - id if id == EntityType::AXOLOTL.id => AxolotlEntity::new(entity).await, - id if id == EntityType::BEE.id => BeeEntity::new(entity).await, - id if id == EntityType::CAMEL.id => CamelEntity::new(entity).await, - id if id == EntityType::FROG.id => FrogEntity::new(entity).await, - id if id == EntityType::GOAT.id => GoatEntity::new(entity).await, - id if id == EntityType::MOOSHROOM.id => MooshroomEntity::new(entity).await, - id if id == EntityType::OCELOT.id => OcelotEntity::new(entity).await, - id if id == EntityType::PANDA.id => PandaEntity::new(entity).await, - id if id == EntityType::PARROT.id => ParrotEntity::new(entity).await, - id if id == EntityType::POLAR_BEAR.id => PolarBearEntity::new(entity).await, - id if id == EntityType::SNIFFER.id => SnifferEntity::new(entity).await, - id if id == EntityType::STRIDER.id => StriderEntity::new(entity).await, - id if id == EntityType::GLOW_SQUID.id => GlowSquidEntity::new(entity).await, - id if id == EntityType::COD.id => CodEntity::new(entity).await, - id if id == EntityType::SALMON.id => SalmonEntity::new(entity).await, - id if id == EntityType::PUFFERFISH.id => PufferfishEntity::new(entity).await, - id if id == EntityType::TROPICAL_FISH.id => TropicalFishEntity::new(entity).await, - id if id == EntityType::TADPOLE.id => TadpoleEntity::new(entity).await, - id if id == EntityType::DOLPHIN.id => DolphinEntity::new(entity).await, + id if id == EntityType::CAT.id => CatEntity::new(entity), + id if id == EntityType::CHICKEN.id => ChickenEntity::new(entity), + id if id == EntityType::COW.id => CowEntity::new(entity), + id if id == EntityType::PIG.id => PigEntity::new(entity), + id if id == EntityType::SHEEP.id => SheepEntity::new(entity), + id if id == EntityType::WOLF.id => WolfEntity::new(entity), + id if id == EntityType::FOX.id => FoxEntity::new(entity), + id if id == EntityType::RABBIT.id => RabbitEntity::new(entity), + id if id == EntityType::TURTLE.id => TurtleEntity::new(entity), + id if id == EntityType::VILLAGER.id => VillagerEntity::new(entity), + id if id == EntityType::SQUID.id => SquidEntity::new(entity), + id if id == EntityType::HORSE.id => HorseEntity::new(entity), + id if id == EntityType::DONKEY.id => DonkeyEntity::new(entity), + id if id == EntityType::MULE.id => MuleEntity::new(entity), + id if id == EntityType::ZOMBIE_HORSE.id => ZombieHorseEntity::new(entity), + id if id == EntityType::SKELETON_HORSE.id => SkeletonHorseEntity::new(entity), + id if id == EntityType::LLAMA.id => LlamaEntity::new(entity), + id if id == EntityType::TRADER_LLAMA.id => TraderLlamaEntity::new(entity), + id if id == EntityType::WANDERING_TRADER.id => WanderingTraderEntity::new(entity), + id if id == EntityType::ALLAY.id => AllayEntity::new(entity), + id if id == EntityType::ARMADILLO.id => ArmadilloEntity::new(entity), + id if id == EntityType::AXOLOTL.id => AxolotlEntity::new(entity), + id if id == EntityType::BEE.id => BeeEntity::new(entity), + id if id == EntityType::CAMEL.id => CamelEntity::new(entity), + id if id == EntityType::FROG.id => FrogEntity::new(entity), + id if id == EntityType::GOAT.id => GoatEntity::new(entity), + id if id == EntityType::MOOSHROOM.id => MooshroomEntity::new(entity), + id if id == EntityType::OCELOT.id => OcelotEntity::new(entity), + id if id == EntityType::PANDA.id => PandaEntity::new(entity), + id if id == EntityType::PARROT.id => ParrotEntity::new(entity), + id if id == EntityType::POLAR_BEAR.id => PolarBearEntity::new(entity), + id if id == EntityType::SNIFFER.id => SnifferEntity::new(entity), + id if id == EntityType::STRIDER.id => StriderEntity::new(entity), + id if id == EntityType::GLOW_SQUID.id => GlowSquidEntity::new(entity), + id if id == EntityType::COD.id => CodEntity::new(entity), + id if id == EntityType::SALMON.id => SalmonEntity::new(entity), + id if id == EntityType::PUFFERFISH.id => PufferfishEntity::new(entity), + id if id == EntityType::TROPICAL_FISH.id => TropicalFishEntity::new(entity), + id if id == EntityType::TADPOLE.id => TadpoleEntity::new(entity), + id if id == EntityType::DOLPHIN.id => DolphinEntity::new(entity), - id if id == EntityType::SNOW_GOLEM.id => SnowGolemEntity::new(entity).await, - id if id == EntityType::IRON_GOLEM.id => IronGolemEntity::new(entity).await, + id if id == EntityType::SNOW_GOLEM.id => SnowGolemEntity::new(entity), + id if id == EntityType::IRON_GOLEM.id => IronGolemEntity::new(entity), - id if id == EntityType::WITHER.id => WitherEntity::new(entity).await, - id if id == EntityType::ENDER_DRAGON.id => EnderDragonEntity::new(entity).await, + id if id == EntityType::WITHER.id => WitherEntity::new(entity), + id if id == EntityType::ENDER_DRAGON.id => EnderDragonEntity::new(entity), id if id == EntityType::AREA_EFFECT_CLOUD.id => { crate::entity::area_effect_cloud::AreaEffectCloudEntity::new(entity) @@ -221,12 +221,12 @@ pub async fn from_type( id if id == EntityType::ARMOR_STAND.id => Arc::new(ArmorStandEntity::new(entity)), id if id == EntityType::PAINTING.id => Arc::new(PaintingEntity::new(entity)), id if id == EntityType::END_CRYSTAL.id => Arc::new(EndCrystalEntity::new(entity)), - id if id == EntityType::ENDER_PEARL.id => Arc::new(EnderPearlEntity::new(entity).await), - id if id == EntityType::SNOWBALL.id => Arc::new(SnowballEntity::new(entity).await), - id if id == EntityType::EGG.id => Arc::new(EggEntity::new(entity).await), - id if id == EntityType::SILVERFISH.id => SilverfishEntity::new(entity).await, - id if id == EntityType::SLIME.id => SlimeEntity::new(entity).await, - id if id == EntityType::SHULKER.id => ShulkerEntity::new(entity).await, + id if id == EntityType::ENDER_PEARL.id => Arc::new(EnderPearlEntity::new(entity)), + id if id == EntityType::SNOWBALL.id => Arc::new(SnowballEntity::new(entity)), + id if id == EntityType::EGG.id => Arc::new(EggEntity::new(entity)), + id if id == EntityType::SILVERFISH.id => SilverfishEntity::new(entity), + id if id == EntityType::SLIME.id => SlimeEntity::new(entity), + id if id == EntityType::SHULKER.id => ShulkerEntity::new(entity), id if id == EntityType::SHULKER_BULLET.id => { // Shulker bullets are normally spawned by ShulkerEntity directly; // when loaded from the world we create a no-target bullet at the given position. @@ -238,7 +238,7 @@ pub async fn from_type( id if id == EntityType::EXPERIENCE_ORB.id => Arc::new(ExperienceOrbEntity::new(entity, 1)), id if id == EntityType::TNT.id => Arc::new(TNTEntity::new(entity, 4.0, 80)), id if id == EntityType::ITEM.id => { - Arc::new(ItemEntity::new(entity, ItemStack::new(1, &Item::AIR)).await) + Arc::new(ItemEntity::new(entity, ItemStack::new(1, &Item::AIR))) } id if id == EntityType::ARROW.id => Arc::new(ArrowEntity::new(entity, None)), id if id == EntityType::SPECTRAL_ARROW.id => Arc::new(ArrowEntity::new(entity, None)), @@ -262,13 +262,9 @@ pub async fn from_type( }; Arc::new(WindChargeEntity::new(thrown)) } - id if id == EntityType::FIREWORK_ROCKET.id => { - Arc::new(FireworkRocketEntity::new(entity).await) - } - id if id == EntityType::SPLASH_POTION.id => Arc::new(SplashPotionEntity::new(entity).await), - id if id == EntityType::LINGERING_POTION.id => { - Arc::new(LingeringPotionEntity::new(entity).await) - } + id if id == EntityType::FIREWORK_ROCKET.id => Arc::new(FireworkRocketEntity::new(entity)), + id if id == EntityType::SPLASH_POTION.id => Arc::new(SplashPotionEntity::new(entity)), + id if id == EntityType::LINGERING_POTION.id => Arc::new(LingeringPotionEntity::new(entity)), id if id == EntityType::EYE_OF_ENDER.id => Arc::new(EyeOfEnder::new(entity)), id if id == EntityType::ACACIA_BOAT.id || id == EntityType::ACACIA_CHEST_BOAT.id @@ -306,10 +302,11 @@ pub async fn from_type( mob } -pub async fn check_spawn_rules( +pub fn check_spawn_rules( entity_type: &'static EntityType, world: &World, pos: &BlockPos, + is_thundering: bool, ) -> bool { let id = entity_type.id; @@ -334,10 +331,10 @@ pub async fn check_spawn_rules( || id == EntityType::VINDICATOR.id || id == EntityType::WARDEN.id { - return mob::MobEntity::check_monster_spawn_rules(world, pos).await; + return mob::MobEntity::check_monster_spawn_rules(world, pos, is_thundering); } if id == EntityType::BAT.id { - return bat::BatEntity::check_bat_spawn_rules(world, pos).await; + return bat::BatEntity::check_bat_spawn_rules(world, pos); } // TODO diff --git a/pumpkin/src/entity/vehicle/boat.rs b/pumpkin/src/entity/vehicle/boat.rs index 41f873d4c..c27092a2c 100644 --- a/pumpkin/src/entity/vehicle/boat.rs +++ b/pumpkin/src/entity/vehicle/boat.rs @@ -39,40 +39,34 @@ impl BoatEntity { } } - pub async fn set_paddles(&self, left: bool, right: bool) { + pub fn set_paddles(&self, left: bool, right: bool) { self.left_paddle_moving.store(left, Ordering::Relaxed); self.right_paddle_moving.store(right, Ordering::Relaxed); - self.entity - .send_meta_data(&[ - Metadata::new(TrackedData::ID_PADDLE_LEFT, MetaDataType::BOOLEAN, left), - Metadata::new(TrackedData::ID_PADDLE_RIGHT, MetaDataType::BOOLEAN, right), - ]) - .await; + self.entity.send_meta_data(&[ + Metadata::new(TrackedData::ID_PADDLE_LEFT, MetaDataType::BOOLEAN, left), + Metadata::new(TrackedData::ID_PADDLE_RIGHT, MetaDataType::BOOLEAN, right), + ]); } - async fn send_wobble_metadata(&self) { - self.entity - .send_meta_data(&[ - Metadata::new( - TrackedData::ID_HURT, - MetaDataType::INTEGER, - VarInt(self.damage_wobble_ticks.load(Ordering::Relaxed)), - ), - Metadata::new( - TrackedData::ID_HURTDIR, - MetaDataType::INTEGER, - VarInt(self.damage_wobble_side.load(Ordering::Relaxed)), - ), - ]) - .await; - self.entity - .send_meta_data(&[Metadata::new( - TrackedData::ID_DAMAGE, - MetaDataType::FLOAT, - self.damage_wobble_strength.load(), - )]) - .await; + fn send_wobble_metadata(&self) { + self.entity.send_meta_data(&[ + Metadata::new( + TrackedData::ID_HURT, + MetaDataType::INTEGER, + VarInt(self.damage_wobble_ticks.load(Ordering::Relaxed)), + ), + Metadata::new( + TrackedData::ID_HURTDIR, + MetaDataType::INTEGER, + VarInt(self.damage_wobble_side.load(Ordering::Relaxed)), + ), + ]); + self.entity.send_meta_data(&[Metadata::new( + TrackedData::ID_DAMAGE, + MetaDataType::FLOAT, + self.damage_wobble_strength.load(), + )]); } async fn kill_and_drop_self(&self) { @@ -129,7 +123,7 @@ impl EntityBase for BoatEntity { fn init_data_tracker(&self) -> EntityBaseFuture<'_, ()> { Box::pin(async move { - self.send_wobble_metadata().await; + self.send_wobble_metadata(); }) } @@ -165,7 +159,7 @@ impl EntityBase for BoatEntity { let new_strength = current_strength + amount * 10.0; self.damage_wobble_strength.store(new_strength); - self.send_wobble_metadata().await; + self.send_wobble_metadata(); let is_creative = source .and_then(|s| s.get_player()) @@ -224,7 +218,7 @@ impl EntityBase for BoatEntity { fn set_paddle_state(&self, left: bool, right: bool) -> EntityBaseFuture<'_, ()> { Box::pin(async move { - self.set_paddles(left, right).await; + self.set_paddles(left, right); }) } diff --git a/pumpkin/src/item/items/armor_stand.rs b/pumpkin/src/item/items/armor_stand.rs index c373d35a9..4b7d85c82 100644 --- a/pumpkin/src/item/items/armor_stand.rs +++ b/pumpkin/src/item/items/armor_stand.rs @@ -71,7 +71,7 @@ impl ItemBehaviour for ArmorStandItem { ), ); - if world.is_space_empty(bounding_box).await + if world.is_space_empty(bounding_box) && world.get_entities_at_box(&bounding_box).is_empty() { let (player_yaw, _) = player.rotation(); @@ -81,13 +81,11 @@ impl ItemBehaviour for ArmorStandItem { entity.set_rotation(rotation, 0.0); - world - .play_sound( - Sound::EntityArmorStandPlace, - SoundCategory::Blocks, - &entity.pos.load(), - ) - .await; + world.play_sound( + Sound::EntityArmorStandPlace, + SoundCategory::Blocks, + &entity.pos.load(), + ); let armor_stand = ArmorStandEntity::new(entity); diff --git a/pumpkin/src/item/items/axe.rs b/pumpkin/src/item/items/axe.rs index 2bd931bb3..220650ea5 100644 --- a/pumpkin/src/item/items/axe.rs +++ b/pumpkin/src/item/items/axe.rs @@ -43,7 +43,7 @@ impl ItemBehaviour for AxeItem { let changed = if replacement_block != 0 { let new_block = &Block::from_id(replacement_block); let new_state_id = if block.has_tag(&tag::Block::MINECRAFT_LOGS) { - let log_information = world.get_block_state_id(&location).await; + let log_information = world.get_block_state_id(&location); let log_props = PaleOakWoodLikeProperties::from_state_id(log_information, block); // create new properties for the new log. @@ -59,7 +59,7 @@ impl ItemBehaviour for AxeItem { // Let's check if It's a door else if block.has_tag(&tag::Block::MINECRAFT_DOORS) { // get block state of the old log. - let door_information = world.get_block_state_id(&location).await; + let door_information = world.get_block_state_id(&location); // get the log properties let door_props = OakDoorLikeProperties::from_state_id(door_information, block); // create new properties for the new log. diff --git a/pumpkin/src/item/items/boat.rs b/pumpkin/src/item/items/boat.rs index e852eecd7..2bb1566ed 100644 --- a/pumpkin/src/item/items/boat.rs +++ b/pumpkin/src/item/items/boat.rs @@ -96,7 +96,7 @@ impl ItemBehaviour for BoatItem { // Vanilla: raycast with FluidHandling.ANY - stops on water/lava surface or solid blocks let checker = async |pos: &BlockPos, world_inner: &Arc| { - let state_id = world_inner.get_block_state_id(pos).await; + let state_id = world_inner.get_block_state_id(pos); // Air doesn't stop the raycast if state_id == Block::AIR.id { @@ -158,7 +158,7 @@ impl ItemBehaviour for BoatItem { let boat_box = BoundingBox::new_from_pos(hit_vec.x, hit_vec.y, hit_vec.z, &dimensions); // Vanilla: if (!world.isSpaceEmpty(lv7, lv7.getBoundingBox())) return FAIL - if !world.is_space_empty(boat_box).await { + if !world.is_space_empty(boat_box) { return; } diff --git a/pumpkin/src/item/items/bow.rs b/pumpkin/src/item/items/bow.rs index 36165ac43..cecce4b5f 100644 --- a/pumpkin/src/item/items/bow.rs +++ b/pumpkin/src/item/items/bow.rs @@ -147,7 +147,7 @@ impl BowItem { ArrowPickup::Allowed }; - let arrow = ArrowEntity::new_shot(arrow_entity, &player.living_entity.entity, pickup).await; + let arrow = ArrowEntity::new_shot(arrow_entity, &player.living_entity.entity, pickup); // Set velocity based on player's look direction and power let yaw = player.living_entity.entity.yaw.load(); @@ -174,6 +174,6 @@ impl BowItem { sound_pitch, 0.0, ); - world.broadcast_packet_all(&sound_packet).await; + world.broadcast_packet_all(&sound_packet); } } diff --git a/pumpkin/src/item/items/bucket.rs b/pumpkin/src/item/items/bucket.rs index ad1d478b4..8a8632379 100644 --- a/pumpkin/src/item/items/bucket.rs +++ b/pumpkin/src/item/items/bucket.rs @@ -124,7 +124,7 @@ async fn try_pickup_bucket_item( block_pos: BlockPos, direction: BlockDirection, ) -> Option<&'static Item> { - let (block, state) = world.get_block_and_state_id(&block_pos).await; + let (block, state) = world.get_block_and_state_id(&block_pos); if block == &Block::POWDER_SNOW { world @@ -167,7 +167,7 @@ async fn try_pickup_bucket_item( } let target_pos = block_pos.offset(direction.to_offset()); - let (block, state) = world.get_block_and_state_id(&target_pos).await; + let (block, state) = world.get_block_and_state_id(&target_pos); if waterlogged_check(block, state).is_some() { let state_id = set_waterlogged(block, state, false); world @@ -188,16 +188,14 @@ fn should_evaporate_in_nether(item: &Item, world: &World) -> bool { && world.dimension == Dimension::THE_NETHER } -async fn play_bucket_evaporation(world: &Arc, player: &Player) { - world - .play_sound_raw( - Sound::BlockFireExtinguish as u16, - SoundCategory::Blocks, - &player.position(), - 0.5, - (rand::random::() - rand::random::()).mul_add(0.8, 2.6), - ) - .await; +fn play_bucket_evaporation(world: &Arc, player: &Player) { + world.play_sound_raw( + Sound::BlockFireExtinguish as u16, + SoundCategory::Blocks, + &player.position(), + 0.5, + (rand::random::() - rand::random::()).mul_add(0.8, 2.6), + ); } async fn try_place_powder_snow( @@ -205,13 +203,13 @@ async fn try_place_powder_snow( pos: BlockPos, direction: BlockDirection, ) -> bool { - let state = world.get_block_state(&pos).await; + let state = world.get_block_state(&pos); let target_pos = if state.replaceable() { pos } else { pos.offset(direction.to_offset()) }; - let target_state = world.get_block_state(&target_pos).await; + let target_state = world.get_block_state(&target_pos); if !target_state.is_air() && !target_state.is_liquid() && !target_state.replaceable() { return false; } @@ -231,7 +229,7 @@ async fn try_place_filled_bucket( pos: BlockPos, direction: BlockDirection, ) -> bool { - let (block, state) = world.get_block_and_state(&pos).await; + let (block, state) = world.get_block_and_state(&pos); if item.id == Item::POWDER_SNOW_BUCKET.id { return try_place_powder_snow(world, pos, direction).await; } @@ -248,7 +246,7 @@ async fn try_place_filled_bucket( } let target_pos = pos.offset(direction.to_offset()); - let (block, state) = world.get_block_and_state(&target_pos).await; + let (block, state) = world.get_block_and_state(&target_pos); if waterlogged_check(block, state.id).is_some() { if item.id == Item::LAVA_BUCKET.id { @@ -293,7 +291,7 @@ impl ItemBehaviour for EmptyBucketItem { let (start_pos, end_pos) = get_start_and_end_pos(player); let checker = async |pos: &BlockPos, world_inner: &Arc| { - let state_id = world_inner.get_block_state_id(pos).await; + let state_id = world_inner.get_block_state_id(pos); let block = Block::from_state_id(state_id); @@ -334,7 +332,7 @@ impl ItemBehaviour for FilledBucketItem { let world = player.world(); let (start_pos, end_pos) = get_start_and_end_pos(player); let checker = async |pos: &BlockPos, world_inner: &Arc| { - let state_id = world_inner.get_block_state_id(pos).await; + let state_id = world_inner.get_block_state_id(pos); if Fluid::from_state_id(state_id).is_some() { return false; } @@ -346,7 +344,7 @@ impl ItemBehaviour for FilledBucketItem { }; if should_evaporate_in_nether(item, &world) { - play_bucket_evaporation(&world, player).await; + play_bucket_evaporation(&world, player); return; } if !try_place_filled_bucket(&world, item, pos, direction).await { diff --git a/pumpkin/src/item/items/crossbow.rs b/pumpkin/src/item/items/crossbow.rs index e532abee2..7ee961b41 100644 --- a/pumpkin/src/item/items/crossbow.rs +++ b/pumpkin/src/item/items/crossbow.rs @@ -103,14 +103,11 @@ impl ItemBehaviour for CrossbowItem { player.consume_arrow(slot).await; } - player - .world() - .play_sound( - Sound::ItemCrossbowLoadingEnd, - SoundCategory::Players, - &player.position(), - ) - .await; + player.world().play_sound( + Sound::ItemCrossbowLoadingEnd, + SoundCategory::Players, + &player.position(), + ); } } player.living_entity.clear_active_hand().await; @@ -145,13 +142,11 @@ impl CrossbowItem { }); let world = player.world(); - world - .play_sound( - Sound::ItemCrossbowShoot, - SoundCategory::Players, - &player.position(), - ) - .await; + world.play_sound( + Sound::ItemCrossbowShoot, + SoundCategory::Players, + &player.position(), + ); let yaw = player.living_entity.entity.yaw.load(); let pitch = player.living_entity.entity.pitch.load(); @@ -173,8 +168,7 @@ impl CrossbowItem { }; let arrow = - ArrowEntity::new_shot(arrow_entity, &player.living_entity.entity, pickup) - .await; + ArrowEntity::new_shot(arrow_entity, &player.living_entity.entity, pickup); arrow.set_velocity_from_rotation(pitch, t_yaw, 0.0, 3.15, 1.0); let arrow_arc: Arc = Arc::new(arrow); world.spawn_entity(arrow_arc).await; diff --git a/pumpkin/src/item/items/dye.rs b/pumpkin/src/item/items/dye.rs index d9d7cd585..c07427f3f 100644 --- a/pumpkin/src/item/items/dye.rs +++ b/pumpkin/src/item/items/dye.rs @@ -44,13 +44,11 @@ impl DyeItem { text.set_color(dye_color); args.world.update_block_entity(block_entity).await; - args.world - .play_block_sound( - pumpkin_data::sound::Sound::ItemDyeUse, - pumpkin_data::sound::SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + pumpkin_data::sound::Sound::ItemDyeUse, + pumpkin_data::sound::SoundCategory::Blocks, + *args.position, + ); BlockActionResult::Success } } diff --git a/pumpkin/src/item/items/egg.rs b/pumpkin/src/item/items/egg.rs index c538e4712..48b6fd834 100644 --- a/pumpkin/src/item/items/egg.rs +++ b/pumpkin/src/item/items/egg.rs @@ -29,19 +29,17 @@ impl ItemBehaviour for EggItem { Box::pin(async move { let position = player.position(); let world = player.world(); - world - .play_sound( - Sound::EntityEggThrow, - pumpkin_data::sound::SoundCategory::Players, - &position, - ) - .await; + world.play_sound( + Sound::EntityEggThrow, + pumpkin_data::sound::SoundCategory::Players, + &position, + ); // Capture the held item stack and pass it to the thrown egg entity let item_stack: ItemStack = player.inventory.held_item().lock().await.clone(); let entity = Entity::new(world.clone(), position, &EntityType::EGG); - let egg = EggEntity::new_shot(entity, &player.living_entity.entity).await; + let egg = EggEntity::new_shot(entity, &player.living_entity.entity); // Propagate the item stack so clients show correct variant egg.set_item_stack(item_stack.clone()).await; diff --git a/pumpkin/src/item/items/end_crystal.rs b/pumpkin/src/item/items/end_crystal.rs index b1a5006d7..d4ba129ef 100644 --- a/pumpkin/src/item/items/end_crystal.rs +++ b/pumpkin/src/item/items/end_crystal.rs @@ -35,7 +35,7 @@ impl ItemBehaviour for EndCrystalItem { ) -> Pin + Send + 'a>> { Box::pin(async move { let world = player.world(); - let block = world.get_block(&location).await; + let block = world.get_block(&location); if block != &Block::OBSIDIAN && block != &Block::BEDROCK { return; } @@ -43,7 +43,7 @@ impl ItemBehaviour for EndCrystalItem { let location = location.up(); let location_vec = location.0.to_f64(); - if !world.get_block_state(&location).await.is_air() + if !world.get_block_state(&location).is_air() || !world .get_entities_at_box(&BoundingBox::new( Vector3::new(location_vec.x, location_vec.y, location_vec.z), @@ -57,7 +57,7 @@ impl ItemBehaviour for EndCrystalItem { let entity = Entity::new(world.clone(), location.to_f64(), &EntityType::END_CRYSTAL); let end_crystal = Arc::new(EndCrystalEntity::new(entity)); world.spawn_entity(end_crystal.clone()).await; - end_crystal.set_show_bottom(false).await; + end_crystal.set_show_bottom(false); item.decrement_unless_creative(player.gamemode.load(), 1); }) } diff --git a/pumpkin/src/item/items/ender_eye.rs b/pumpkin/src/item/items/ender_eye.rs index 9986f2e12..b2ff39421 100644 --- a/pumpkin/src/item/items/ender_eye.rs +++ b/pumpkin/src/item/items/ender_eye.rs @@ -46,7 +46,7 @@ impl ItemBehaviour for EnderEyeItem { } let world = player.world(); - let state_id = world.get_block_state_id(&location).await; + let state_id = world.get_block_state_id(&location); // Skip if the frame already holds an eye. let props_raw = block.properties(state_id).unwrap().to_props(); @@ -65,9 +65,7 @@ impl ItemBehaviour for EnderEyeItem { .set_block_state(&location, new_state_id, BlockFlags::empty()) .await; - world - .sync_world_event(WorldEvent::EndPortalFrameFill, location, 0) - .await; + world.sync_world_event(WorldEvent::EndPortalFrameFill, location, 0); // Try to complete the portal. EndPortal::get_new_portal(&world, location).await; @@ -87,10 +85,10 @@ impl ItemBehaviour for EnderEyeItem { let (start_pos, end_pos) = self.get_start_and_end_pos(player); let checker = async |pos: &BlockPos, w: &Arc| { - w.get_block_state_id(pos).await != Block::AIR.default_state.id + w.get_block_state_id(pos) != Block::AIR.default_state.id }; if let Some((hit_pos, _)) = world.raycast(start_pos, end_pos, checker).await - && world.get_block(&hit_pos).await == &Block::END_PORTAL_FRAME + && world.get_block(&hit_pos) == &Block::END_PORTAL_FRAME { return; } @@ -122,15 +120,13 @@ impl ItemBehaviour for EnderEyeItem { world.spawn_entity(eye).await; let pitch = 0.33f32 + rand::random::() * (0.5 - 0.33); - world - .play_sound_fine( - Sound::EntityEnderEyeLaunch, - SoundCategory::Neutral, - &spawn_pos, - 1.0, - pitch, - ) - .await; + world.play_sound_fine( + Sound::EntityEnderEyeLaunch, + SoundCategory::Neutral, + &spawn_pos, + 1.0, + pitch, + ); player.inventory.held_item().lock().await.decrement(1); }) diff --git a/pumpkin/src/item/items/ender_pearl.rs b/pumpkin/src/item/items/ender_pearl.rs index 5cb52f73c..1d3c97c30 100644 --- a/pumpkin/src/item/items/ender_pearl.rs +++ b/pumpkin/src/item/items/ender_pearl.rs @@ -28,16 +28,14 @@ impl ItemBehaviour for EnderPearlItem { Box::pin(async move { let position = player.position(); let world = player.world(); - world - .play_sound( - Sound::EntityEnderPearlThrow, - pumpkin_data::sound::SoundCategory::Neutral, - &position, - ) - .await; + world.play_sound( + Sound::EntityEnderPearlThrow, + pumpkin_data::sound::SoundCategory::Neutral, + &position, + ); let entity = Entity::new(world.clone(), position, &EntityType::ENDER_PEARL); - let pearl = EnderPearlEntity::new_shot(entity, &player.living_entity.entity).await; + let pearl = EnderPearlEntity::new_shot(entity, &player.living_entity.entity); let yaw = player.living_entity.entity.yaw.load(); let pitch = player.living_entity.entity.pitch.load(); pearl.thrown.set_velocity_from( diff --git a/pumpkin/src/item/items/firework_rocket.rs b/pumpkin/src/item/items/firework_rocket.rs index 5453d8a3d..59dc65252 100644 --- a/pumpkin/src/item/items/firework_rocket.rs +++ b/pumpkin/src/item/items/firework_rocket.rs @@ -45,7 +45,7 @@ impl ItemBehaviour for FireworkRocketItem { ), &EntityType::FIREWORK_ROCKET, ); - let entity = FireworkRocketEntity::new(entity).await; + let entity = FireworkRocketEntity::new(entity); world.spawn_entity(Arc::new(entity)).await; }) } @@ -63,7 +63,7 @@ impl ItemBehaviour for FireworkRocketItem { player.get_entity().pos.load(), &EntityType::FIREWORK_ROCKET, ); - let entity = FireworkRocketEntity::new_shot(entity, player.get_entity()).await; + let entity = FireworkRocketEntity::new_shot(entity, player.get_entity()); world.spawn_entity(Arc::new(entity)).await; } }) diff --git a/pumpkin/src/item/items/fishing_rod.rs b/pumpkin/src/item/items/fishing_rod.rs index 332d2ff8d..fee5566d7 100644 --- a/pumpkin/src/item/items/fishing_rod.rs +++ b/pumpkin/src/item/items/fishing_rod.rs @@ -32,13 +32,11 @@ impl ItemBehaviour for FishingRodItem { if bobber_id == -1 { // Cast - world - .play_sound( - Sound::EntityFishingBobberThrow, - SoundCategory::Neutral, - &player.position(), - ) - .await; + world.play_sound( + Sound::EntityFishingBobberThrow, + SoundCategory::Neutral, + &player.position(), + ); let bobber_entity = Entity::new( world.clone(), @@ -65,20 +63,18 @@ impl ItemBehaviour for FishingRodItem { if let Some(bobber) = bobber_base.cast_any().downcast_ref::() { - let _result = bobber.reel_in(player).await; + let _result = bobber.reel_in(player); // TODO: give items } bobber_base.get_entity().remove().await; } player.fishing_bobber.store(-1, Ordering::Relaxed); - world - .play_sound( - Sound::EntityFishingBobberRetrieve, - SoundCategory::Neutral, - &player.position(), - ) - .await; + world.play_sound( + Sound::EntityFishingBobberRetrieve, + SoundCategory::Neutral, + &player.position(), + ); } }) } diff --git a/pumpkin/src/item/items/glowing_ink_sac.rs b/pumpkin/src/item/items/glowing_ink_sac.rs index c836921ea..30b484493 100644 --- a/pumpkin/src/item/items/glowing_ink_sac.rs +++ b/pumpkin/src/item/items/glowing_ink_sac.rs @@ -36,13 +36,11 @@ impl GlowingInkSacItem { } args.world.update_block_entity(block_entity).await; - args.world - .play_block_sound( - pumpkin_data::sound::Sound::ItemGlowInkSacUse, - pumpkin_data::sound::SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + pumpkin_data::sound::Sound::ItemGlowInkSacUse, + pumpkin_data::sound::SoundCategory::Blocks, + *args.position, + ); BlockActionResult::Success } } diff --git a/pumpkin/src/item/items/hoe.rs b/pumpkin/src/item/items/hoe.rs index ac2eb8df1..4253dd11f 100644 --- a/pumpkin/src/item/items/hoe.rs +++ b/pumpkin/src/item/items/hoe.rs @@ -57,7 +57,7 @@ impl ItemBehaviour for HoeItem { if (block == &Block::GRASS_BLOCK || block == &Block::DIRT_PATH || block == &Block::DIRT) - && world.get_block_state(&location.up()).await.is_air() + && world.get_block_state(&location.up()).is_air() { future_block = &Block::FARMLAND; changed = true; @@ -89,9 +89,10 @@ impl ItemBehaviour for HoeItem { }; let entity = Entity::new(world.clone(), location, &EntityType::ITEM); // TODO: Merge stacks together - let item_entity = Arc::new( - ItemEntity::new(entity, ItemStack::new(1, &Item::HANGING_ROOTS)).await, - ); + let item_entity = Arc::new(ItemEntity::new( + entity, + ItemStack::new(1, &Item::HANGING_ROOTS), + )); world.spawn_entity(item_entity).await; } diff --git a/pumpkin/src/item/items/honeycomb.rs b/pumpkin/src/item/items/honeycomb.rs index b2abaa739..8aa2c34df 100644 --- a/pumpkin/src/item/items/honeycomb.rs +++ b/pumpkin/src/item/items/honeycomb.rs @@ -56,7 +56,7 @@ impl ItemBehaviour for HoneyCombItem { && block.has_tag(&tag::Block::MINECRAFT_DOORS) { // get block state of the old log. - let door_information = world.get_block_state_id(&location).await; + let door_information = world.get_block_state_id(&location); // get the log properties let door_props = OakDoorLikeProperties::from_state_id(door_information, block); // create new properties for the new log. @@ -96,8 +96,7 @@ impl HoneyCombItem { args.world.update_block_entity(block_entity).await; args.world - .sync_world_event(WorldEvent::ParticlesAndSoundWaxOn, *args.position, 0) - .await; + .sync_world_event(WorldEvent::ParticlesAndSoundWaxOn, *args.position, 0); BlockActionResult::Success } diff --git a/pumpkin/src/item/items/ignite/fire_charge.rs b/pumpkin/src/item/items/ignite/fire_charge.rs index 12c009e14..c7519402c 100644 --- a/pumpkin/src/item/items/ignite/fire_charge.rs +++ b/pumpkin/src/item/items/ignite/fire_charge.rs @@ -43,9 +43,7 @@ impl ItemBehaviour for FireChargeItem { .set_block_state(&pos, new_state_id, BlockFlags::NOTIFY_ALL) .await; - world - .play_block_sound(Sound::ItemFirechargeUse, SoundCategory::Blocks, pos) - .await; + world.play_block_sound(Sound::ItemFirechargeUse, SoundCategory::Blocks, pos); }, player, location, diff --git a/pumpkin/src/item/items/ignite/ignition.rs b/pumpkin/src/item/items/ignite/ignition.rs index 68793d310..0e32ea157 100644 --- a/pumpkin/src/item/items/ignite/ignition.rs +++ b/pumpkin/src/item/items/ignite/ignition.rs @@ -24,22 +24,20 @@ impl Ignition { let world = player.world(); let pos = location.offset(face.to_offset()); - if world.get_fluid(&location).await.name != Fluid::EMPTY.name { + if world.get_fluid(&location).name != Fluid::EMPTY.name { return false; } - let fire_block = FireBlockBase::get_fire_type(&world, &pos).await; + let fire_block = FireBlockBase::get_fire_type(&world, &pos); - let state_id = world.get_block_state_id(&location).await; + let state_id = world.get_block_state_id(&location); if let Some(new_state_id) = can_be_lit(block, state_id) { ignite_logic(world.clone(), location, new_state_id).await; return true; } - let state_id = FireBlock - .get_state_for_position(&world, &fire_block, &pos) - .await; - if FireBlockBase::can_place_at(&world, &pos).await { + let state_id = FireBlock.get_state_for_position(&world, &fire_block, &pos); + if FireBlockBase::can_place_at(&world, &pos) { ignite_logic(world.clone(), pos, state_id).await; return true; } diff --git a/pumpkin/src/item/items/ink_sac.rs b/pumpkin/src/item/items/ink_sac.rs index 448195e5c..d89496a65 100644 --- a/pumpkin/src/item/items/ink_sac.rs +++ b/pumpkin/src/item/items/ink_sac.rs @@ -36,13 +36,11 @@ impl InkSacItem { } args.world.update_block_entity(block_entity).await; - args.world - .play_block_sound( - pumpkin_data::sound::Sound::ItemInkSacUse, - pumpkin_data::sound::SoundCategory::Blocks, - *args.position, - ) - .await; + args.world.play_block_sound( + pumpkin_data::sound::Sound::ItemInkSacUse, + pumpkin_data::sound::SoundCategory::Blocks, + *args.position, + ); BlockActionResult::Success } } diff --git a/pumpkin/src/item/items/minecart.rs b/pumpkin/src/item/items/minecart.rs index 9c40e4966..ef73fe92c 100644 --- a/pumpkin/src/item/items/minecart.rs +++ b/pumpkin/src/item/items/minecart.rs @@ -64,7 +64,7 @@ impl ItemBehaviour for MinecartItem { if !block.has_tag(&tag::Block::MINECRAFT_RAILS) { return; } - let state_id = world.get_block_state_id(&location).await; + let state_id = world.get_block_state_id(&location); let is_ascending = if PoweredRailLikeProperties::handles_block_id(block.id) { PoweredRailLikeProperties::from_state_id(state_id, block) .shape diff --git a/pumpkin/src/item/items/name_tag.rs b/pumpkin/src/item/items/name_tag.rs index 149a20bc8..fea30c738 100644 --- a/pumpkin/src/item/items/name_tag.rs +++ b/pumpkin/src/item/items/name_tag.rs @@ -30,9 +30,7 @@ impl ItemBehaviour for NameTagItem { && let Some(name) = item.get_data_component::() { // TODO - entity - .set_custom_name(TextComponent::text(name.name.clone())) - .await; + entity.set_custom_name(TextComponent::text(name.name.clone())); item.decrement_unless_creative(player.gamemode.load(), 1); } }) diff --git a/pumpkin/src/item/items/potions.rs b/pumpkin/src/item/items/potions.rs index dc165241e..80a6f2d81 100644 --- a/pumpkin/src/item/items/potions.rs +++ b/pumpkin/src/item/items/potions.rs @@ -60,15 +60,13 @@ impl ItemBehaviour for SplashPotionItem { Box::pin(async move { let position = player.position(); let world = player.world(); - world - .play_sound( - Sound::EntityWitchThrow, - pumpkin_data::sound::SoundCategory::Neutral, - &position, - ) - .await; + world.play_sound( + Sound::EntityWitchThrow, + pumpkin_data::sound::SoundCategory::Neutral, + &position, + ); let entity = Entity::new(world.clone(), position, &EntityType::SPLASH_POTION); - let splash = SplashPotionEntity::new_shot(entity, &player.living_entity.entity).await; + let splash = SplashPotionEntity::new_shot(entity, &player.living_entity.entity); // Copy the held item stack data into the projectile let main = player.inventory.held_item(); @@ -136,15 +134,13 @@ impl ItemBehaviour for LingeringPotionItem { Box::pin(async move { let position = player.position(); let world = player.world(); - world - .play_sound( - Sound::EntityWitchThrow, - pumpkin_data::sound::SoundCategory::Neutral, - &position, - ) - .await; + world.play_sound( + Sound::EntityWitchThrow, + pumpkin_data::sound::SoundCategory::Neutral, + &position, + ); let entity = Entity::new(world.clone(), position, &EntityType::LINGERING_POTION); - let ling = LingeringPotionEntity::new_shot(entity, &player.living_entity.entity).await; + let ling = LingeringPotionEntity::new_shot(entity, &player.living_entity.entity); // Copy the held item stack data into the projectile let main = player.inventory.held_item(); diff --git a/pumpkin/src/item/items/shovel.rs b/pumpkin/src/item/items/shovel.rs index e59d3e846..13a995d91 100644 --- a/pumpkin/src/item/items/shovel.rs +++ b/pumpkin/src/item/items/shovel.rs @@ -44,7 +44,7 @@ impl ItemBehaviour for ShovelItem { || block == &Block::PODZOL || block == &Block::MYCELIUM) && face != BlockDirection::Down - && world.get_block_state(&location.up()).await.is_air() + && world.get_block_state(&location.up()).is_air() { world .set_block_state( @@ -59,13 +59,11 @@ impl ItemBehaviour for ShovelItem { }; if block == &Block::CAMPFIRE || block == &Block::SOUL_CAMPFIRE { let mut campfire_props = CampfireLikeProperties::from_state_id( - world.get_block_state(&location).await.id, + world.get_block_state(&location).id, block, ); if campfire_props.lit { - world - .sync_world_event(WorldEvent::SoundExtinguishFire, location, 0) - .await; + world.sync_world_event(WorldEvent::SoundExtinguishFire, location, 0); campfire_props.lit = false; world diff --git a/pumpkin/src/item/items/snowball.rs b/pumpkin/src/item/items/snowball.rs index 391053737..b75f0c1de 100644 --- a/pumpkin/src/item/items/snowball.rs +++ b/pumpkin/src/item/items/snowball.rs @@ -28,15 +28,13 @@ impl ItemBehaviour for SnowBallItem { Box::pin(async move { let position = player.position(); let world = player.world(); - world - .play_sound( - Sound::EntitySnowballThrow, - pumpkin_data::sound::SoundCategory::Neutral, - &position, - ) - .await; + world.play_sound( + Sound::EntitySnowballThrow, + pumpkin_data::sound::SoundCategory::Neutral, + &position, + ); let entity = Entity::new(world.clone(), position, &EntityType::SNOWBALL); - let snowball = SnowballEntity::new_shot(entity, &player.living_entity.entity).await; + let snowball = SnowballEntity::new_shot(entity, &player.living_entity.entity); let yaw = player.living_entity.entity.yaw.load(); let pitch = player.living_entity.entity.pitch.load(); snowball.thrown.set_velocity_from( diff --git a/pumpkin/src/item/items/spawn_egg.rs b/pumpkin/src/item/items/spawn_egg.rs index d61a03c02..aa8db8fa2 100644 --- a/pumpkin/src/item/items/spawn_egg.rs +++ b/pumpkin/src/item/items/spawn_egg.rs @@ -36,7 +36,7 @@ impl ItemBehaviour for SpawnEggItem { if let Some(entity_type) = entity_from_egg(item.item.id) { let world = player.world(); - if let Some(block_entity) = player.world().get_block_entity(&location).await + if let Some(block_entity) = player.world().get_block_entity(&location) && let Some(spawner) = block_entity .as_any() .downcast_ref::() @@ -55,7 +55,7 @@ impl ItemBehaviour for SpawnEggItem { // Create rotation like Vanilla let yaw = wrap_degrees(rand::random::() * 360.0) % 360.0; - let mob = from_type(entity_type, pos, &world, Uuid::new_v4()).await; + let mob = from_type(entity_type, pos, &world, Uuid::new_v4()); // Set the rotation mob.get_entity().set_rotation(yaw, 0.0); diff --git a/pumpkin/src/item/items/wind_charge.rs b/pumpkin/src/item/items/wind_charge.rs index 26e1ca803..411d50ec1 100644 --- a/pumpkin/src/item/items/wind_charge.rs +++ b/pumpkin/src/item/items/wind_charge.rs @@ -33,13 +33,11 @@ impl ItemBehaviour for WindChargeItem { // TODO: Implement Cooldown to throw the item - world - .play_sound( - Sound::EntityWindChargeThrow, - pumpkin_data::sound::SoundCategory::Neutral, - &position, - ) - .await; + world.play_sound( + Sound::EntityWindChargeThrow, + pumpkin_data::sound::SoundCategory::Neutral, + &position, + ); let entity = Entity::new(world.clone(), position, &EntityType::WIND_CHARGE); diff --git a/pumpkin/src/item/potion.rs b/pumpkin/src/item/potion.rs index adb46d129..3df45b6df 100644 --- a/pumpkin/src/item/potion.rs +++ b/pumpkin/src/item/potion.rs @@ -137,7 +137,7 @@ impl PotionContents { // Apply instant effects logic directly as they don't tick if effect_type.id == pumpkin_data::effect::StatusEffect::INSTANT_HEALTH.id { let amount = (4 * ((amplifier as i32) + 1)) as f32 * instant_scale; - target.heal(amount).await; + target.heal(amount); } else if effect_type.id == pumpkin_data::effect::StatusEffect::INSTANT_DAMAGE.id { let amount = (6 * ((amplifier as i32) + 1)) as f32 * instant_scale; diff --git a/pumpkin/src/net/bedrock/mod.rs b/pumpkin/src/net/bedrock/mod.rs index 38181fbb3..9c2e87ecb 100644 --- a/pumpkin/src/net/bedrock/mod.rs +++ b/pumpkin/src/net/bedrock/mod.rs @@ -264,6 +264,25 @@ impl BedrockClient { } } + pub fn try_enqueue_packet_data(&self, packet_data: Bytes) { + if let Err(err) = self.outgoing_packet_queue_send.try_send(packet_data) { + match err { + tokio::sync::mpsc::error::TrySendError::Full(_) => { + debug!( + "Failed to add packet to the outgoing packet queue for client: channel full" + ); + } + tokio::sync::mpsc::error::TrySendError::Closed(_) => { + if !self.is_closed() { + error!( + "Failed to add packet to the outgoing packet queue for client: channel closed" + ); + } + } + } + } + } + pub fn write_raw_packet( packet: &P, mut write: impl Write, diff --git a/pumpkin/src/net/bedrock/play.rs b/pumpkin/src/net/bedrock/play.rs index 3c8ae3aba..a7e9fae72 100644 --- a/pumpkin/src/net/bedrock/play.rs +++ b/pumpkin/src/net/bedrock/play.rs @@ -304,7 +304,7 @@ impl BedrockClient { let entity = &player.living_entity.entity; let world = entity.world.load_full(); - let (block, state) = world.get_block_and_state(&location).await; + let (block, state) = world.get_block_and_state(&location); if player.gamemode.load() == GameMode::Creative { let new_state = world @@ -326,7 +326,7 @@ impl BedrockClient { let speed = crate::block::calc_block_breaking(player, state, block).await; if speed >= 1.0 { - let broken_state = world.get_block_state(&location).await; + let broken_state = world.get_block_state(&location); let new_state = world .break_block( &location, diff --git a/pumpkin/src/net/java/mod.rs b/pumpkin/src/net/java/mod.rs index f04371d6a..1da96bfbf 100644 --- a/pumpkin/src/net/java/mod.rs +++ b/pumpkin/src/net/java/mod.rs @@ -272,6 +272,13 @@ impl JavaClient { self.enqueue_packet_data(buf.into()).await; } + pub fn try_enqueue_packet(&self, packet: &P) { + let mut buf = Vec::new(); + let writer = &mut buf; + self.write_packet(packet, writer).unwrap(); + self.try_enqueue_packet_data(buf.into()); + } + /// Queues a clientbound packet to be sent to the connected client. Queued chunks are sent /// in-order to the client /// @@ -294,6 +301,30 @@ impl JavaClient { } } + pub fn try_enqueue_packet_data(&self, packet_data: Bytes) { + if let Err(err) = self + .outgoing_packet_queue_send + .try_send(OutgoingPacket::normal(packet_data)) + { + match err { + tokio::sync::mpsc::error::TrySendError::Full(_) => { + debug!( + "Failed to add packet to the outgoing packet queue for client {}: channel full", + self.id + ); + } + tokio::sync::mpsc::error::TrySendError::Closed(_) => { + if !self.close_token.is_cancelled() { + error!( + "Failed to add packet to the outgoing packet queue for client {}: channel closed", + self.id + ); + } + } + } + } + } + pub async fn await_close_interrupt(&self) { self.close_token.cancelled().await; } diff --git a/pumpkin/src/net/java/play.rs b/pumpkin/src/net/java/play.rs index 99c07eac5..543d9ecf7 100644 --- a/pumpkin/src/net/java/play.rs +++ b/pumpkin/src/net/java/play.rs @@ -281,9 +281,7 @@ impl JavaClient { } /// Returns whether syncing the position was needed - #[expect(clippy::too_many_arguments)] - async fn sync_position( - &self, + fn sync_position( player: &Arc, world: &World, pos: Vector3, @@ -300,19 +298,17 @@ impl JavaClient { return false; } // Sync position with all other players. - world - .broadcast_packet_except( - &[player.gameprofile.id], - &CEntityPositionSync::new( - entity_id.into(), - pos, - Vector3::new(0.0, 0.0, 0.0), - yaw, - pitch, - on_ground, - ), - ) - .await; + world.broadcast_packet_except( + &[player.gameprofile.id], + &CEntityPositionSync::new( + entity_id.into(), + pos, + Vector3::new(0.0, 0.0, 0.0), + yaw, + pitch, + on_ground, + ), + ); true } @@ -374,7 +370,7 @@ impl JavaClient { let world = &player.world(); // TODO: Warn when player moves to quickly - if !self.sync_position(player, world, pos, last_pos, entity.yaw.load(), entity.pitch.load(), packet.collision & FLAG_ON_GROUND != 0).await { + if !Self::sync_position(player, world, pos, last_pos, entity.yaw.load(), entity.pitch.load(), packet.collision & FLAG_ON_GROUND != 0) { // Send the new position to all other players. world .broadcast_packet_except( @@ -389,7 +385,7 @@ impl JavaClient { packet.collision & FLAG_ON_GROUND != 0, ), ) - .await; + ; } // Only process fall damage if player is alive @@ -497,9 +493,8 @@ impl JavaClient { let world = entity.world.load_full(); // TODO: Warn when player moves to quickly - if !self - .sync_position(player, &world, pos, last_pos, yaw, pitch, (packet.collision & FLAG_ON_GROUND) != 0) - .await + if !Self:: + sync_position(player, &world, pos, last_pos, yaw, pitch, (packet.collision & FLAG_ON_GROUND) != 0) { // Send the new position to all other players. world @@ -517,7 +512,7 @@ impl JavaClient { (packet.collision & FLAG_ON_GROUND) != 0, ), ) - .await; + ; } world @@ -525,7 +520,7 @@ impl JavaClient { &[player.gameprofile.id], &CHeadRot::new(entity_id.into(), yaw as u8), ) - .await; + ; // Only process fall damage if player is alive if !player.abilities.lock().await.flying && player.living_entity.health.load() > 0.0 @@ -601,13 +596,9 @@ impl JavaClient { let world = entity.world.load_full(); let packet = CUpdateEntityRot::new(entity_id.into(), yaw as u8, pitch as u8, rotation.ground); - world - .broadcast_packet_except(&[player.gameprofile.id], &packet) - .await; + world.broadcast_packet_except(&[player.gameprofile.id], &packet); let packet = CHeadRot::new(entity_id.into(), yaw as u8); - world - .broadcast_packet_except(&[player.gameprofile.id], &packet) - .await; + world.broadcast_packet_except(&[player.gameprofile.id], &packet); } pub async fn handle_chat_command( @@ -669,7 +660,7 @@ impl JavaClient { } let world = player.world(); - let block = world.get_block(&pick_item.pos).await; + let block = world.get_block(&pick_item.pos); if block.item_id == 0 { // Invalid block id (blocks such as tall seagrass) @@ -723,7 +714,7 @@ impl JavaClient { return; } let pos = command.pos; - if let Some(block_entity) = player.world().get_block_entity(&pos).await { + if let Some(block_entity) = player.world().get_block_entity(&pos) { if block_entity.resource_location() != CommandBlockEntity::ID { warn!("Client tried to change Command block but not Command block entity found"); return; @@ -735,8 +726,8 @@ impl JavaClient { return; }; - let block = player.world().get_block(&pos).await; - let old_state_id = player.world().get_block_state_id(&pos).await; + let block = player.world().get_block(&pos); + let old_state_id = player.world().get_block_state_id(&pos); let mut props = CommandBlockLikeProperties::from_state_id(old_state_id, block); let block_type = match command_block_mode { @@ -1239,7 +1230,7 @@ impl JavaClient { .eye_position() .add(&(Vector3::rotation_vector(f64::from(pitch), f64::from(yaw)) * 4.5)), async |pos, world| { - let block = world.get_block(pos).await; + let block = world.get_block(pos); block != &Block::AIR && block != &Block::WATER && block != &Block::LAVA }, ) @@ -1249,7 +1240,7 @@ impl JavaClient { PlayerInteractEvent::new( player, InteractAction::LeftClickBlock, - player.world().get_block(&hit_pos).await, + player.world().get_block(&hit_pos), Some(hit_pos), ) } else { @@ -1262,7 +1253,7 @@ impl JavaClient { server; event; 'after: { - player.swing_hand(hand, false).await; + player.swing_hand(hand, false); } }} } @@ -1429,20 +1420,18 @@ impl JavaClient { session.key_signature.clone(), ); - server - .broadcast_packet_all(&CPlayerInfoUpdate::new( - 0x02, - &[pumpkin_protocol::java::client::play::Player { - uuid: player.gameprofile.id, - actions: &[PlayerAction::InitializeChat(Some(InitChat { - session_id: session.session_id, - expires_at: session.expires_at, - public_key: session.public_key.clone(), - signature: session.key_signature.clone(), - }))], - }], - )) - .await; + server.broadcast_packet_all(&CPlayerInfoUpdate::new( + 0x02, + &[pumpkin_protocol::java::client::play::Player { + uuid: player.gameprofile.id, + actions: &[PlayerAction::InitializeChat(Some(InitChat { + session_id: session.session_id, + expires_at: session.expires_at, + public_key: session.public_key.clone(), + signature: session.key_signature.clone(), + }))], + }], + )); } /// Runs vanilla checks for a valid player session @@ -1561,7 +1550,7 @@ impl JavaClient { "Player {} ({}) updated their skin.", player.gameprofile.name, self.id, ); - player.send_client_information().await; + player.send_client_information(); } } else { self.kick(TextComponent::text("Invalid hand or chat type")) @@ -1646,13 +1635,11 @@ impl JavaClient { return; } if config.protect_creative && player_victim.gamemode.load() == GameMode::Creative { - world - .play_sound( - Sound::EntityPlayerAttackNodamage, - SoundCategory::Players, - &player_victim.position(), - ) - .await; + world.play_sound( + Sound::EntityPlayerAttackNodamage, + SoundCategory::Players, + &player_victim.position(), + ); return; } } @@ -1727,7 +1714,7 @@ impl JavaClient { SoundCategory::Players, &player_victim.position(), ) - .await; + ; return; } } @@ -1792,7 +1779,7 @@ impl JavaClient { let position = player_action.position; let entity = &player.living_entity.entity; let world = entity.world.load_full(); - let (block, state) = world.get_block_and_state(&position).await; + let (block, state) = world.get_block_and_state(&position); let inventory = player.inventory(); let held = inventory.held_item(); @@ -1838,7 +1825,7 @@ impl JavaClient { let speed = block::calc_block_breaking(player, state, block).await; // Instant break if speed >= 1.0 { - let broken_state = world.get_block_state(&position).await; + let broken_state = world.get_block_state(&position); let new_state = world .break_block( &position, @@ -1903,7 +1890,7 @@ impl JavaClient { player.mining.store(false, Ordering::Relaxed); world.set_block_breaking(entity, location, -1).await; - let (block, state) = world.get_block_and_state(&location).await; + let (block, state) = world.get_block_and_state(&location); let block_drop = player.gamemode.load() != GameMode::Creative && player.can_harvest(state, block).await; @@ -1984,7 +1971,7 @@ impl JavaClient { } async fn sync_block_state_to_client(&self, world: &World, position: BlockPos) { - let synced_state_id = world.get_block_state_id(&position).await; + let synced_state_id = world.get_block_state_id(&position); self.send_packet_now(&CBlockUpdate::new( position, VarInt(i32::from(synced_state_id)), @@ -2074,7 +2061,7 @@ impl JavaClient { let entity = &player.living_entity.entity; let world = entity.world.load_full(); - let block = world.get_block(&position).await; + let block = world.get_block(&position); let sneaking = player.living_entity.entity.sneaking.load(Ordering::Relaxed); @@ -2096,7 +2083,7 @@ impl JavaClient { // TODO: Trigger ANY_BLOCK_USE Criteria if matches!(result, BlockActionResult::SuccessServer) { - player.swing_hand(hand, true).await; + player.swing_hand(hand, true); } return Ok(()); } @@ -2154,8 +2141,7 @@ impl JavaClient { }; player .world() - .send_entity_status(&player.living_entity.entity, equipment_break_status(slot)) - .await; + .send_entity_status(&player.living_entity.entity, equipment_break_status(slot)); } if !after.are_equal(&before) { @@ -2219,7 +2205,7 @@ impl JavaClient { pub async fn handle_sign_update(&self, player: &Player, sign_data: SUpdateSign) { let world = player.living_entity.entity.world.load_full(); - let Some(block_entity) = world.get_block_entity(&sign_data.location).await else { + let Some(block_entity) = world.get_block_entity(&sign_data.location) else { return; }; let Some(sign_entity) = block_entity.as_any().downcast_ref::() else { @@ -2278,7 +2264,7 @@ impl JavaClient { * 4.5), ), async |pos, world| { - let block = world.get_block(pos).await; + let block = world.get_block(pos); block != &Block::AIR && block != &Block::WATER && block != &Block::LAVA }, ) @@ -2288,7 +2274,7 @@ impl JavaClient { PlayerInteractEvent::new( player, InteractAction::RightClickBlock, - player.world().get_block(&hit_pos).await, + player.world().get_block(&hit_pos), Some(hit_pos), ) } else { @@ -2433,7 +2419,7 @@ impl JavaClient { inv.set_selected_slot(slot); let stack = inv.held_item().lock().await.clone(); let equipment = &[(EquipmentSlot::MAIN_HAND, stack)]; - player.living_entity.send_equipment_changes(equipment).await; + player.living_entity.send_equipment_changes(equipment); } pub async fn handle_set_creative_slot( @@ -2480,7 +2466,7 @@ impl JavaClient { let slot = packet.slot - 36; if player.inventory().get_selected_slot() == slot as u8 { let equipment = &[(EquipmentSlot::MAIN_HAND, item_stack.clone())]; - player.living_entity.send_equipment_changes(equipment).await; + player.living_entity.send_equipment_changes(equipment); } } } @@ -2652,8 +2638,7 @@ impl JavaClient { return Err(BlockPlacingError::BlockOutOfWorld); } - let (clicked_block, clicked_block_state) = - world.get_block_and_state(&clicked_block_pos).await; + let (clicked_block, clicked_block_state) = world.get_block_and_state(&clicked_block_pos); let replace_clicked_block = if clicked_block == block { world @@ -2667,7 +2652,6 @@ impl JavaClient { &use_item_on, player, ) - .await .then_some(BlockIsReplacing::Itself(clicked_block_state.id)) } else if clicked_block_state.replaceable() { if clicked_block == &Block::WATER { @@ -2686,8 +2670,7 @@ impl JavaClient { (clicked_block_pos, face, replacing) } else { let block_pos = BlockPos(location.0 + face.to_offset()); - let (previous_block, previous_block_state) = - world.get_block_and_state(&block_pos).await; + let (previous_block, previous_block_state) = world.get_block_and_state(&block_pos); let replace_previous_block = if previous_block == block { world @@ -2701,7 +2684,6 @@ impl JavaClient { &use_item_on, player, ) - .await .then_some(BlockIsReplacing::Itself(previous_block_state.id)) } else { previous_block_state.replaceable().then(|| { @@ -2726,21 +2708,17 @@ impl JavaClient { } }; - if !server - .block_registry - .can_place_at( - Some(server), - Some(&*world), - &*world, - Some(player), - block, - block.default_state, - &final_block_pos, - Some(final_face), - Some(&use_item_on), - ) - .await - { + if !server.block_registry.can_place_at( + Some(server), + Some(&*world), + &*world, + Some(player), + block, + block.default_state, + &final_block_pos, + Some(final_face), + Some(&use_item_on), + ) { return Ok(false); } diff --git a/pumpkin/src/net/mod.rs b/pumpkin/src/net/mod.rs index b08118437..c8a81b06e 100644 --- a/pumpkin/src/net/mod.rs +++ b/pumpkin/src/net/mod.rs @@ -13,7 +13,7 @@ use bytes::Bytes; use pumpkin_data::translation; use pumpkin_protocol::{ClientPacket, Property}; -use pumpkin_util::{Hand, ProfileAction, text::TextComponent}; +use pumpkin_util::{Hand, ProfileAction, text::TextComponent, version::MinecraftVersion}; use serde::Deserialize; use sha1::Digest; use sha2::Sha256; @@ -127,6 +127,21 @@ impl ClientPlatform { } } + pub fn version(&self) -> MinecraftVersion { + match self { + Self::Java(java) => java.version.load(), + // TODO + Self::Bedrock(_) => MinecraftVersion::V_1_21_7, + } + } + + pub fn try_enqueue_packet_data(&self, packet_data: Bytes) { + match self { + Self::Java(java) => java.try_enqueue_packet_data(packet_data), + Self::Bedrock(bedrock) => bedrock.try_enqueue_packet_data(packet_data), + } + } + pub async fn await_close_interrupt(&self) { match self { Self::Java(java) => java.await_close_interrupt().await, @@ -152,6 +167,13 @@ impl ClientPlatform { } } + pub fn try_enqueue_packet(&self, packet: &P) { + match self { + Self::Java(java) => java.try_enqueue_packet(packet), + Self::Bedrock(_) => (), + } + } + pub async fn send_packet_now(&self, packet: &P) { match self { Self::Java(java) => java.send_packet_now(packet).await, diff --git a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/entity.rs b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/entity.rs index b6de49e9f..c9558b546 100644 --- a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/entity.rs +++ b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/entity.rs @@ -443,7 +443,7 @@ impl HostEntity for PluginHostState { let pos = *pos; let world = w.clone(); async move { - let block = world.get_block_state(&pos).await; + let block = world.get_block_state(&pos); !block.is_air() } }, diff --git a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/player.rs b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/player.rs index b2fa84c40..ebd8f174f 100644 --- a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/player.rs +++ b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/player.rs @@ -371,7 +371,7 @@ impl pumpkin::plugin::player::HostPlayer for PluginHostState { order: i32, ) -> wasmtime::Result<()> { let player = player_from_resource(self, &player)?; - player.set_tab_list_order(order).await; + player.set_tab_list_order(order); Ok(()) } @@ -381,7 +381,7 @@ impl pumpkin::plugin::player::HostPlayer for PluginHostState { latency: i32, ) -> wasmtime::Result<()> { let player = player_from_resource(self, &player)?; - player.set_tab_list_latency(latency).await; + player.set_tab_list_latency(latency); Ok(()) } @@ -391,7 +391,7 @@ impl pumpkin::plugin::player::HostPlayer for PluginHostState { listed: bool, ) -> wasmtime::Result<()> { let player = player_from_resource(self, &player)?; - player.set_tab_list_listed(listed).await; + player.set_tab_list_listed(listed); Ok(()) } @@ -870,7 +870,7 @@ impl pumpkin::plugin::player::HostPlayer for PluginHostState { config.skin_parts = mask; player.config.store(Arc::new(config)); }; - player.send_client_information().await; + player.send_client_information(); Ok(()) } diff --git a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/scoreboard.rs b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/scoreboard.rs index 86f5f9131..82b34e661 100644 --- a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/scoreboard.rs +++ b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/scoreboard.rs @@ -47,8 +47,7 @@ impl scoreboard::HostScoreboard for PluginHostState { .scoreboard .lock() .await - .add_objective(&world, objective) - .await; + .add_objective(&world, objective); Ok(()) } @@ -62,8 +61,7 @@ impl scoreboard::HostScoreboard for PluginHostState { .scoreboard .lock() .await - .remove_objective(&world, &name) - .await; + .remove_objective(&world, &name); Ok(()) } @@ -126,11 +124,9 @@ impl scoreboard::HostScoreboard for PluginHostState { } }; - world - .broadcast_packet_all( - &pumpkin_protocol::java::client::play::CDisplayObjective::new(slot, objective_name), - ) - .await; + world.broadcast_packet_all( + &pumpkin_protocol::java::client::play::CDisplayObjective::new(slot, objective_name), + ); Ok(()) } @@ -149,12 +145,7 @@ impl scoreboard::HostScoreboard for PluginHostState { None, None, ); - world - .scoreboard - .lock() - .await - .update_score(&world, score) - .await; + world.scoreboard.lock().await.update_score(&world, score); Ok(()) } @@ -169,8 +160,7 @@ impl scoreboard::HostScoreboard for PluginHostState { .scoreboard .lock() .await - .remove_score(&world, &entity_name, &objective_name) - .await; + .remove_score(&world, &entity_name, &objective_name); Ok(()) } @@ -182,7 +172,7 @@ impl scoreboard::HostScoreboard for PluginHostState { ) -> wasmtime::Result<()> { let world = self.get_scoreboard_res(&res)?.provider.clone(); let team = map_team_settings(name, &settings, self)?; - world.scoreboard.lock().await.add_team(&world, team).await; + world.scoreboard.lock().await.add_team(&world, team); Ok(()) } @@ -192,12 +182,7 @@ impl scoreboard::HostScoreboard for PluginHostState { name: String, ) -> wasmtime::Result<()> { let world = self.get_scoreboard_res(&res)?.provider.clone(); - world - .scoreboard - .lock() - .await - .remove_team(&world, &name) - .await; + world.scoreboard.lock().await.remove_team(&world, &name); Ok(()) } @@ -209,12 +194,7 @@ impl scoreboard::HostScoreboard for PluginHostState { ) -> wasmtime::Result<()> { let world = self.get_scoreboard_res(&res)?.provider.clone(); let team = map_team_settings(name, &settings, self)?; - world - .scoreboard - .lock() - .await - .update_team(&world, team) - .await; + world.scoreboard.lock().await.update_team(&world, team); Ok(()) } @@ -229,8 +209,7 @@ impl scoreboard::HostScoreboard for PluginHostState { .scoreboard .lock() .await - .add_player_to_team(&world, &team_name, player_name) - .await; + .add_player_to_team(&world, &team_name, player_name); Ok(()) } @@ -245,8 +224,7 @@ impl scoreboard::HostScoreboard for PluginHostState { .scoreboard .lock() .await - .remove_player_from_team(&world, &team_name, &player_name) - .await; + .remove_player_from_team(&world, &team_name, &player_name); Ok(()) } diff --git a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/world.rs b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/world.rs index f0b469f3c..ce18aa760 100644 --- a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/world.rs +++ b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/world.rs @@ -1,6 +1,7 @@ use pumpkin_data::BlockDirection as InternalBlockDirection; use pumpkin_data::block_state::PistonBehavior; use pumpkin_util::math::position::BlockPos; +use pumpkin_world::chunk::ChunkHeightmapType; use pumpkin_world::world::BlockFlags; use std::sync::Arc; use wasmtime::component::Resource; @@ -67,7 +68,7 @@ impl pumpkin::plugin::world::HostWorld for PluginHostState { ) -> wasmtime::Result { let world_ref = self.get_world_res(&world)?; let internal_pos = BlockPos::new(pos.x, pos.y, pos.z); - Ok(world_ref.provider.get_block_state_id(&internal_pos).await) + Ok(world_ref.provider.get_block_state_id(&internal_pos)) } async fn get_block_state( @@ -77,7 +78,7 @@ impl pumpkin::plugin::world::HostWorld for PluginHostState { ) -> wasmtime::Result { let world_ref = self.get_world_res(&world)?; let internal_pos = BlockPos::new(pos.x, pos.y, pos.z); - let state = world_ref.provider.get_block_state(&internal_pos).await; + let state = world_ref.provider.get_block_state(&internal_pos); Ok(WitBlockState { id: state.id, @@ -177,8 +178,7 @@ impl pumpkin::plugin::world::HostWorld for PluginHostState { Ok(self .get_world_res(&world)? .provider - .get_top_block(pumpkin_util::math::vector2::Vector2::new(x, z)) - .await) + .get_top_block(pumpkin_util::math::vector2::Vector2::new(x, z))) } async fn get_motion_blocking_height( @@ -187,11 +187,11 @@ impl pumpkin::plugin::world::HostWorld for PluginHostState { x: i32, z: i32, ) -> wasmtime::Result { - Ok(self - .get_world_res(&world)? - .provider - .get_motion_blocking_height(x, z) - .await) + Ok(self.get_world_res(&world)?.provider.get_heightmap_height( + ChunkHeightmapType::MotionBlocking, + x, + z, + )) } async fn is_raining(&mut self, world: Resource) -> wasmtime::Result { @@ -231,8 +231,7 @@ impl pumpkin::plugin::world::HostWorld for PluginHostState { let msg = self.get_text_provider(&message)?; self.get_world_res(&world)? .provider - .broadcast_system_message(&msg, overlay) - .await; + .broadcast_system_message(&msg, overlay); Ok(()) } @@ -291,16 +290,13 @@ impl pumpkin::plugin::world::HostWorld for PluginHostState { } }; - world_ref - .provider - .play_sound_raw( - sound_data as u16, - internal_category, - &pumpkin_util::math::vector3::Vector3::new(pos.0, pos.1, pos.2), - volume, - pitch, - ) - .await; + world_ref.provider.play_sound_raw( + sound_data as u16, + internal_category, + &pumpkin_util::math::vector3::Vector3::new(pos.0, pos.1, pos.2), + volume, + pitch, + ); Ok(()) } @@ -318,20 +314,17 @@ impl pumpkin::plugin::world::HostWorld for PluginHostState { let particle_data = pumpkin_data::particle::Particle::from_name(&particle_name) .ok_or_else(|| wasmtime::Error::msg(format!("Unknown particle: {particle_name}")))?; - world_ref - .provider - .spawn_particle( - pumpkin_util::math::vector3::Vector3::new(pos.0, pos.1, pos.2), - pumpkin_util::math::vector3::Vector3::new( - offset.0 as f32, - offset.1 as f32, - offset.2 as f32, - ), - max_speed, - count, - particle_data, - ) - .await; + world_ref.provider.spawn_particle( + pumpkin_util::math::vector3::Vector3::new(pos.0, pos.1, pos.2), + pumpkin_util::math::vector3::Vector3::new( + offset.0 as f32, + offset.1 as f32, + offset.2 as f32, + ), + max_speed, + count, + particle_data, + ); Ok(()) } diff --git a/pumpkin/src/server/mod.rs b/pumpkin/src/server/mod.rs index 29d3fe29d..99b9ec70c 100644 --- a/pumpkin/src/server/mod.rs +++ b/pumpkin/src/server/mod.rs @@ -288,10 +288,7 @@ impl Server { ); let level = into_level(dim.clone(), &config, path, seed, Some(pool)); let world = Arc::new(World::load(level.clone(), l_info, dim, registry, weak)); - let portal: Arc = Arc::new(WorldPortal( - world.clone(), - tokio::runtime::Handle::current(), - )); + let portal: Arc = Arc::new(WorldPortal(world.clone())); level.world_portal.store(Arc::new(Some(portal))); world }) @@ -392,10 +389,7 @@ impl Server { ); let world: World = World::load(level.clone(), l_info, dimension, registry, weak); let world = Arc::new(world); - let portal: Arc = Arc::new(WorldPortal( - world.clone(), - tokio::runtime::Handle::current(), - )); + let portal: Arc = Arc::new(WorldPortal(world.clone())); level.world_portal.store(Arc::new(Some(portal))); server.worlds.rcu(|worlds| { let mut new_worlds = (**worlds).clone(); @@ -560,9 +554,9 @@ impl Server { /// # Arguments /// /// * `packet`: A reference to the packet to be broadcast. The packet must implement the `ClientPacket` trait. - pub async fn broadcast_packet_all(&self, packet: &P) { + pub fn broadcast_packet_all(&self, packet: &P) { for world in self.worlds.load().iter() { - world.broadcast_packet_all(packet).await; + world.broadcast_packet_all(packet); } } @@ -622,7 +616,7 @@ impl Server { /// # Note /// /// This function does not handle the actual mob spawn options update, which is a TODO item for future implementation. - pub async fn set_difficulty(&self, difficulty: Difficulty, force_update: bool) { + pub fn set_difficulty(&self, difficulty: Difficulty, force_update: bool) { let current_info = self.level_info.load(); if current_info.difficulty_locked && !force_update { return; @@ -644,8 +638,7 @@ impl Server { world.set_difficulty(difficulty); } - self.broadcast_packet_all(&CChangeDifficulty::new(difficulty as u8, locked)) - .await; + self.broadcast_packet_all(&CChangeDifficulty::new(difficulty as u8, locked)); } /// Searches for a player by their username across all worlds. diff --git a/pumpkin/src/server/tick_rate_manager.rs b/pumpkin/src/server/tick_rate_manager.rs index 986bbe30e..1e3fa975a 100644 --- a/pumpkin/src/server/tick_rate_manager.rs +++ b/pumpkin/src/server/tick_rate_manager.rs @@ -79,41 +79,41 @@ impl ServerTickRateManager { self.frozen_ticks_to_run.load(Ordering::Relaxed) > 0 } - pub async fn set_tick_rate(&self, server: &Server, rate: f32) { + pub fn set_tick_rate(&self, server: &Server, rate: f32) { self.tickrate.store(rate.max(1.0)); self.nanoseconds_per_tick.store( (NANOSECONDS_PER_SECOND as f64 / f64::from(self.tickrate.load())) as i64, Ordering::Relaxed, ); // server.on_tick_rate_changed(); // Might need this hook if autosave interval depends on it - self.update_state_to_clients(server).await; + self.update_state_to_clients(server); } - pub async fn set_frozen(&self, server: &Server, frozen: bool) { + pub fn set_frozen(&self, server: &Server, frozen: bool) { self.is_frozen.store(frozen, Ordering::Relaxed); - self.update_state_to_clients(server).await; + self.update_state_to_clients(server); } - pub async fn step_game_if_paused(&self, server: &Server, ticks: i32) -> bool { + pub fn step_game_if_paused(&self, server: &Server, ticks: i32) -> bool { if !self.is_frozen() { return false; } self.frozen_ticks_to_run.store(ticks, Ordering::Relaxed); - self.update_step_ticks(server).await; + self.update_step_ticks(server); true } - pub async fn stop_stepping(&self, server: &Server) -> bool { + pub fn stop_stepping(&self, server: &Server) -> bool { if self.is_stepping_forward() { self.frozen_ticks_to_run.store(0, Ordering::Relaxed); - self.update_step_ticks(server).await; + self.update_step_ticks(server); true } else { false } } - pub async fn request_game_to_sprint(&self, server: &Server, ticks: i64) -> bool { + pub fn request_game_to_sprint(&self, server: &Server, ticks: i64) -> bool { let was_sprinting = self.is_sprinting(); self.sprint_time_spend.store(0, Ordering::Relaxed); self.scheduled_current_sprint_ticks @@ -121,13 +121,13 @@ impl ServerTickRateManager { self.remaining_sprint_ticks.store(ticks, Ordering::Relaxed); self.previous_is_frozen .store(self.is_frozen(), Ordering::Relaxed); - self.set_frozen(server, false).await; + self.set_frozen(server, false); was_sprinting } - pub async fn stop_sprinting(&self, server: &Server) -> bool { + pub fn stop_sprinting(&self, server: &Server) -> bool { if self.is_sprinting() { - self.finish_tick_sprint(server).await; + self.finish_tick_sprint(server); true } else { false @@ -150,7 +150,7 @@ impl ServerTickRateManager { self.remaining_sprint_ticks.fetch_sub(1, Ordering::Relaxed) == 1 } - pub async fn finish_tick_sprint(&self, server: &Server) { + pub fn finish_tick_sprint(&self, server: &Server) { let total_sprinted_ticks = self.scheduled_current_sprint_ticks.load(Ordering::Relaxed) - self.remaining_sprint_ticks.load(Ordering::Relaxed); let time_spent_nanos = self.sprint_time_spend.load(Ordering::Relaxed); @@ -185,35 +185,28 @@ impl ServerTickRateManager { .color_named(NamedColor::Gray); // Send as a system chat message, which does not add a sender prefix. - server - .broadcast_packet_all(&CSystemChatMessage::new(&final_report, false)) - .await; + server.broadcast_packet_all(&CSystemChatMessage::new(&final_report, false)); // Reset state after sending the report self.scheduled_current_sprint_ticks .store(0, Ordering::Relaxed); self.sprint_time_spend.store(0, Ordering::Relaxed); self.remaining_sprint_ticks.store(0, Ordering::Relaxed); - self.set_frozen(server, self.previous_is_frozen.load(Ordering::Relaxed)) - .await; + self.set_frozen(server, self.previous_is_frozen.load(Ordering::Relaxed)); // server.on_tick_rate_changed(); } - async fn update_state_to_clients(&self, server: &Server) { - server - .broadcast_packet_all(&CTickingState::new( - self.tickrate.load(), - self.is_frozen.load(Ordering::Relaxed), - )) - .await; + fn update_state_to_clients(&self, server: &Server) { + server.broadcast_packet_all(&CTickingState::new( + self.tickrate.load(), + self.is_frozen.load(Ordering::Relaxed), + )); } - async fn update_step_ticks(&self, server: &Server) { - server - .broadcast_packet_all(&CTickingStep::new( - self.frozen_ticks_to_run.load(Ordering::Relaxed).into(), - )) - .await; + fn update_step_ticks(&self, server: &Server) { + server.broadcast_packet_all(&CTickingStep::new( + self.frozen_ticks_to_run.load(Ordering::Relaxed).into(), + )); } pub async fn update_joining_player(&self, player: &Player) { player diff --git a/pumpkin/src/server/ticker.rs b/pumpkin/src/server/ticker.rs index 9a69c5fd2..89a153555 100644 --- a/pumpkin/src/server/ticker.rs +++ b/pumpkin/src/server/ticker.rs @@ -22,7 +22,7 @@ impl Ticker { server.tick().await; if manager.end_sprint_tick_work() { - manager.finish_tick_sprint(server).await; + manager.finish_tick_sprint(server); } } else { server.tick().await; diff --git a/pumpkin/src/world/border.rs b/pumpkin/src/world/border.rs index 18d2fbf8b..adab97ec2 100644 --- a/pumpkin/src/world/border.rs +++ b/pumpkin/src/world/border.rs @@ -59,56 +59,45 @@ impl Worldborder { .await; } - pub async fn set_center(&mut self, world: &World, x: f64, z: f64) { + pub fn set_center(&mut self, world: &World, x: f64, z: f64) { self.center_x = x; self.center_z = z; - world - .broadcast_packet_all(&CSetBorderCenter::new(self.center_x, self.center_z)) - .await; + world.broadcast_packet_all(&CSetBorderCenter::new(self.center_x, self.center_z)); } - pub async fn set_diameter(&mut self, world: &World, diameter: f64, speed: Option) { + pub fn set_diameter(&mut self, world: &World, diameter: f64, speed: Option) { self.old_diameter = self.new_diameter; self.new_diameter = diameter; match speed { Some(speed) => { - world - .broadcast_packet_all(&CSetBorderLerpSize::new( - self.old_diameter, - self.new_diameter, - speed.into(), - )) - .await; + world.broadcast_packet_all(&CSetBorderLerpSize::new( + self.old_diameter, + self.new_diameter, + speed.into(), + )); } None => { - world - .broadcast_packet_all(&CSetBorderSize::new(self.new_diameter)) - .await; + world.broadcast_packet_all(&CSetBorderSize::new(self.new_diameter)); } } } - pub async fn add_diameter(&mut self, world: &World, offset: f64, speed: Option) { - self.set_diameter(world, self.new_diameter + offset, speed) - .await; + pub fn add_diameter(&mut self, world: &World, offset: f64, speed: Option) { + self.set_diameter(world, self.new_diameter + offset, speed); } - pub async fn set_warning_delay(&mut self, world: &World, delay: i32) { + pub fn set_warning_delay(&mut self, world: &World, delay: i32) { self.warning_time = delay; - world - .broadcast_packet_all(&CSetBorderWarningDelay::new(self.warning_time.into())) - .await; + world.broadcast_packet_all(&CSetBorderWarningDelay::new(self.warning_time.into())); } - pub async fn set_warning_distance(&mut self, world: &World, distance: i32) { + pub fn set_warning_distance(&mut self, world: &World, distance: i32) { self.warning_blocks = distance; - world - .broadcast_packet_all(&CSetBorderWarningDistance::new(self.warning_blocks.into())) - .await; + world.broadcast_packet_all(&CSetBorderWarningDistance::new(self.warning_blocks.into())); } #[must_use] diff --git a/pumpkin/src/world/dragon_fight.rs b/pumpkin/src/world/dragon_fight.rs index 88750b5ef..4cc9c2892 100644 --- a/pumpkin/src/world/dragon_fight.rs +++ b/pumpkin/src/world/dragon_fight.rs @@ -204,7 +204,7 @@ impl DragonFight { async fn scan_state(&mut self, world: &Arc) { info!("Scanning End fight state..."); - let has_active_portal = self.has_active_exit_portal(world).await; + let has_active_portal = Self::has_active_exit_portal(world); if has_active_portal { info!("Exit portal found – dragon has been killed previously."); @@ -259,13 +259,13 @@ impl DragonFight { /// Checks whether a `END_PORTAL` block exists within an 8-chunk radius /// of the origin, matching vanilla's `hasActiveExitPortal`. - async fn has_active_exit_portal(&self, world: &Arc) -> bool { + fn has_active_exit_portal(world: &Arc) -> bool { for cx in -8i32..=8 { for cz in -8i32..=8 { let bx = cx * 16; let bz = cz * 16; for y in 30i32..=80 { - if world.get_block(&BlockPos::new(bx, y, bz)).await == &Block::END_PORTAL { + if world.get_block(&BlockPos::new(bx, y, bz)) == &Block::END_PORTAL { return true; } } @@ -299,8 +299,7 @@ impl DragonFight { let uuid = Uuid::new_v4(); let position = Vector3::new(0.5, DRAGON_SPAWN_Y, 0.5); let dragon = - crate::entity::r#type::from_type(&EntityType::ENDER_DRAGON, position, world, uuid) - .await; + crate::entity::r#type::from_type(&EntityType::ENDER_DRAGON, position, world, uuid); world.spawn_entity(dragon).await; self.dragon_uuid = Some(uuid); @@ -363,7 +362,7 @@ impl DragonFight { } // Spawn a new end gateway. - self.spawn_new_gateway(world).await; + self.spawn_new_gateway(world); self.previously_killed = true; self.dragon_killed = true; @@ -466,7 +465,7 @@ impl DragonFight { for dx in -4i32..=4 { for dz in -4i32..=4 { let pos = BlockPos::new(loc.0.x + dx, loc.0.y + dy, loc.0.z + dz); - let block = world.get_block(&pos).await; + let block = world.get_block(&pos); if block == &Block::BEDROCK || block == &Block::END_PORTAL { world .set_block_state( @@ -537,7 +536,7 @@ impl DragonFight { /// Spawn the next end gateway, consuming one index from `pending_gateways`. /// Matches vanilla `spawnNewGateway`. - async fn spawn_new_gateway(&mut self, world: &Arc) { + fn spawn_new_gateway(&mut self, world: &Arc) { let Some(idx) = self.pending_gateways.pop() else { return; }; @@ -547,9 +546,7 @@ impl DragonFight { let z = (GATEWAY_DISTANCE * angle.sin()).floor() as i32; let pos = BlockPos::new(x, GATEWAY_Y, z); - world - .sync_world_event(WorldEvent::AnimationEndGatewaySpawn, pos, 0) - .await; + world.sync_world_event(WorldEvent::AnimationEndGatewaySpawn, pos, 0); info!("Spawned end gateway #{} at {:?}.", idx, pos); } @@ -575,7 +572,7 @@ impl DragonFight { // Find the top of the spike by scanning down from y=115 for bedrock. let mut crystal_y = 78i32; for y in (70..=115i32).rev() { - if world.get_block(&BlockPos::new(cx, y, cz)).await == &Block::BEDROCK { + if world.get_block(&BlockPos::new(cx, y, cz)) == &Block::BEDROCK { crystal_y = y + 1; break; } @@ -587,7 +584,7 @@ impl DragonFight { &EntityType::END_CRYSTAL, ); let crystal = Arc::new(EndCrystalEntity::new(entity)); - crystal.set_show_bottom(true).await; + crystal.set_show_bottom(true); world.spawn_entity(crystal).await; } info!("Spawned end crystals on spike tops."); @@ -600,10 +597,10 @@ impl DragonFight { pub async fn spawn_exit_portal(&mut self, world: &Arc, active: bool) { // Determine location once and cache it. if self.portal_location.is_none() { - let top_y = world.get_top_block(Vector2::new(0, 0)).await; + let top_y = world.get_top_block(Vector2::new(0, 0)); let mut portal_y = top_y; while portal_y > 63 { - if world.get_block(&BlockPos::new(0, portal_y, 0)).await != &Block::BEDROCK { + if world.get_block(&BlockPos::new(0, portal_y, 0)) != &Block::BEDROCK { break; } portal_y -= 1; diff --git a/pumpkin/src/world/explosion.rs b/pumpkin/src/world/explosion.rs index 8abf2f4a1..b0f13bcac 100644 --- a/pumpkin/src/world/explosion.rs +++ b/pumpkin/src/world/explosion.rs @@ -23,7 +23,7 @@ impl Explosion { Self { power, pos } } - async fn get_blocks_to_destroy( + fn get_blocks_to_destroy( &self, world: &World, ) -> FxHashMap { @@ -53,8 +53,8 @@ impl Explosion { let mut h = self.power * random_val.mul_add(0.6, 0.7); while h > 0.0 { let block_pos = BlockPos::floored(pos_x, pos_y, pos_z); - let (block, state) = world.get_block_and_state(&block_pos).await; - let (_, fluid_state) = world.get_fluid_and_fluid_state(&block_pos).await; + let (block, state) = world.get_block_and_state(&block_pos); + let (_, fluid_state) = world.get_fluid_and_fluid_state(&block_pos); // if !world.is_in_build_limit(&block_pos) { // // Pass by reference @@ -146,7 +146,7 @@ impl Explosion { let knockback_multiplier = (1.0 - distance) * exposure * (1.0 - knockback_resistance); let knockback = direction * knockback_multiplier; - entity.add_velocity(knockback).await; + entity.add_velocity(knockback); } } @@ -185,7 +185,7 @@ impl Explosion { if world .raycast(vec3d, *explosion_pos, async |pos, world_ref| { - let state = world_ref.get_block_state(pos).await; + let state = world_ref.get_block_state(pos); !state.is_air() && !state.collision_shapes.is_empty() }) .await @@ -211,7 +211,7 @@ impl Explosion { /// Returns the removed block count pub async fn explode(&self, world: &Arc) -> u32 { - let blocks = self.get_blocks_to_destroy(world).await; + let blocks = self.get_blocks_to_destroy(world); self.damage_entities(world).await; for (pos, (block, state)) in &blocks { world.set_block_state(pos, 0, BlockFlags::NOTIFY_ALL).await; diff --git a/pumpkin/src/world/map.rs b/pumpkin/src/world/map.rs index dfcd0a14d..ac523a2ac 100644 --- a/pumpkin/src/world/map.rs +++ b/pumpkin/src/world/map.rs @@ -79,7 +79,7 @@ impl MapData { } } - pub async fn update(&mut self, player: &Player) { + pub fn update(&mut self, player: &Player) { let world = player.world(); let scale = 1 << self.scale; let center_x = self.center_x; @@ -109,10 +109,8 @@ impl MapData { let world_x = (img_x as i32 - 64) * scale + center_x; let world_z = (img_z as i32 - 64) * scale + center_z; - let top_y = world.get_top_block(Vector2::new(world_x, world_z)).await; - let block = world - .get_block(&BlockPos::new(world_x, top_y, world_z)) - .await; + let top_y = world.get_top_block(Vector2::new(world_x, world_z)); + let block = world.get_block(&BlockPos::new(world_x, top_y, world_z)); let color_base = block.map_color; diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index c325cc0ec..7436693a2 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -4,14 +4,12 @@ use pumpkin_data::chunk::Biome; use pumpkin_protocol::bedrock::client::level_event::{CLevelEvent, LevelEvent}; use pumpkin_protocol::codec::data_component::data_to_proto_sound; use pumpkin_world::generation::proto_chunk::GenerationCache; -use std::pin::Pin; use std::sync::atomic::Ordering::Relaxed; use std::sync::{Arc, Weak}; use std::{ collections::{BTreeMap, HashMap}, sync::atomic::Ordering, }; -use tokio::runtime::Handle; use tracing::{debug, error, info, trace, warn}; pub mod chunker; @@ -375,33 +373,23 @@ impl World { } /// Sends an entity status update to all players tracking the specified entity. - pub async fn send_entity_status(&self, entity: &Entity, status: EntityStatus) { + pub fn send_entity_status(&self, entity: &Entity, status: EntityStatus) { let chunk_pos = entity.chunk_pos.load(); self.broadcast_to_chunk( chunk_pos, &CEntityStatus::new(entity.entity_id, status as i8), - ) - .await; + ); } - pub async fn send_remove_mob_effect( - &self, - entity: &Entity, - effect_type: &'static StatusEffect, - ) { + pub fn send_remove_mob_effect(&self, entity: &Entity, effect_type: &'static StatusEffect) { let chunk_pos = entity.chunk_pos.load(); self.broadcast_to_chunk( chunk_pos, &CRemoveMobEffect::new(entity.entity_id.into(), VarInt(i32::from(effect_type.id))), - ) - .await; + ); } - pub async fn send_add_mob_effect( - &self, - entity: &Entity, - effect: &pumpkin_data::potion::Effect, - ) { + pub fn send_add_mob_effect(&self, entity: &Entity, effect: &pumpkin_data::potion::Effect) { // TODO: only nearby let mut flags: i8 = 0; if effect.ambient { @@ -420,8 +408,7 @@ impl World { VarInt(i32::from(effect.amplifier)), VarInt(effect.duration), flags, - )) - .await; + )); } pub fn set_difficulty(&self, difficulty: Difficulty) { @@ -447,7 +434,7 @@ impl World { }; for event in events { - let block = self.get_block(&event.pos).await; // TODO + let block = self.get_block(&event.pos); if !self .block_registry .on_synced_block_event(block, self, &event.pos, event.r#type, event.data) @@ -464,8 +451,7 @@ impl World { event.data, VarInt(i32::from(block.id)), ), - ) - .await; + ); } } @@ -485,7 +471,7 @@ impl World { recipients_by_version } - async fn broadcast_java_grouped( + fn broadcast_java_grouped( packet: &P, recipients_by_version: BTreeMap>, ) { @@ -504,7 +490,7 @@ impl World { }; for recipient in recipients { - recipient.enqueue_packet_data(packet_data.clone()).await; + recipient.try_enqueue_packet_data(packet_data.clone()); } } } @@ -515,15 +501,33 @@ impl World { /// Sends the specified packet to every player currently logged in to the world. /// /// **Note:** This function acquires a lock on the `current_players` map, ensuring thread safety. - pub async fn broadcast_packet_all(&self, packet: &P) { + pub fn broadcast_packet_all(&self, packet: &P) { let players = self.players.load(); let recipients_by_version = Self::collect_java_recipients_by_version(players.iter()); - Self::broadcast_java_grouped(packet, recipients_by_version).await; + Self::broadcast_java_grouped(packet, recipients_by_version); } - pub async fn broadcast_system_message(&self, message: &TextComponent, overlay: bool) { + pub fn broadcast_packet_all_sync(&self, packet: &P) { + let players = self.players.load(); + for player in players.iter() { + match &player.client { + ClientPlatform::Java(java) => { + if let Ok(data) = + JavaClient::serialize_packet_for_version(packet, java.version.load()) + { + java.try_enqueue_packet_data(data); + } + } + ClientPlatform::Bedrock(_) => { + // TODO + } + } + } + } + + pub fn broadcast_system_message(&self, message: &TextComponent, overlay: bool) { let packet = CSystemChatMessage::new(message, overlay); - self.broadcast_packet_all(&packet).await; + self.broadcast_packet_all(&packet); } pub async fn broadcast_message( @@ -556,7 +560,7 @@ impl World { } } - Self::broadcast_java_grouped(je_packet, je_recipients_by_version).await; + Self::broadcast_java_grouped(je_packet, je_recipients_by_version); for recipient in be_recipients { recipient.send_game_packet(be_packet).await; @@ -619,21 +623,17 @@ impl World { /// Sends the specified packet to every player currently logged in to the world, excluding the players listed in the `except` parameter. /// /// **Note:** This function acquires a lock on the `current_players` map, ensuring thread safety. - pub async fn broadcast_packet_except( - &self, - except: &[uuid::Uuid], - packet: &P, - ) { + pub fn broadcast_packet_except(&self, except: &[uuid::Uuid], packet: &P) { let players = self.players.load(); let recipients_by_version = Self::collect_java_recipients_by_version( players .iter() .filter(|candidate| !except.contains(&candidate.gameprofile.id)), ); - Self::broadcast_java_grouped(packet, recipients_by_version).await; + Self::broadcast_java_grouped(packet, recipients_by_version); } - pub async fn spawn_particle( + pub fn spawn_particle( &self, position: Vector3, offset: Vector3, @@ -642,20 +642,17 @@ impl World { particle: Particle, ) { for player in self.players.load().iter() { - player - .spawn_particle(position, offset, max_speed, particle_count, particle) - .await; + player.spawn_particle(position, offset, max_speed, particle_count, particle); } } - pub async fn play_sound(&self, sound: Sound, category: SoundCategory, position: &Vector3) { - self.play_sound_raw(sound as u16, category, position, 1.0, 1.0) - .await; + pub fn play_sound(&self, sound: Sound, category: SoundCategory, position: &Vector3) { + self.play_sound_raw(sound as u16, category, position, 1.0, 1.0); } - pub async fn play_sound_event( + pub fn play_sound_event( &self, - sound: pumpkin_data::data_component_impl::IdOr< + sound: &pumpkin_data::data_component_impl::IdOr< pumpkin_data::data_component_impl::SoundEvent, >, category: SoundCategory, @@ -663,17 +660,17 @@ impl World { ) { let seed = rng().random::(); let packet = CSoundEffect::new( - data_to_proto_sound(&sound), + data_to_proto_sound(sound), category, position, 1.0, 1.0, seed, ); - self.broadcast_packet_all(&packet).await; + self.broadcast_packet_all(&packet); } - pub async fn play_sound_fine( + pub fn play_sound_fine( &self, sound: Sound, category: SoundCategory, @@ -681,22 +678,20 @@ impl World { volume: f32, pitch: f32, ) { - self.play_sound_raw(sound as u16, category, position, volume, pitch) - .await; + self.play_sound_raw(sound as u16, category, position, volume, pitch); } - pub async fn play_sound_expect( + pub fn play_sound_expect( &self, player: &Player, sound: Sound, category: SoundCategory, position: &Vector3, ) { - self.play_sound_raw_expect(player, sound as u16, category, position, 1.0, 1.0) - .await; + self.play_sound_raw_expect(player, sound as u16, category, position, 1.0, 1.0); } - pub async fn play_sound_raw( + pub fn play_sound_raw( &self, sound_id: u16, category: SoundCategory, @@ -719,10 +714,10 @@ impl World { }); let recipients_by_version = Self::collect_java_recipients_by_version(recipients); - Self::broadcast_java_grouped(&packet, recipients_by_version).await; + Self::broadcast_java_grouped(&packet, recipients_by_version); } - pub async fn play_sound_raw_expect( + pub fn play_sound_raw_expect( &self, player: &Player, sound_id: u16, @@ -749,24 +744,19 @@ impl World { }); let recipients_by_version = Self::collect_java_recipients_by_version(recipients); - Self::broadcast_java_grouped(&packet, recipients_by_version).await; + Self::broadcast_java_grouped(&packet, recipients_by_version); } - pub async fn play_block_sound( - &self, - sound: Sound, - category: SoundCategory, - position: BlockPos, - ) { + pub fn play_block_sound(&self, sound: Sound, category: SoundCategory, position: BlockPos) { let new_vec = Vector3::new( f64::from(position.0.x) + 0.5, f64::from(position.0.y) + 0.5, f64::from(position.0.z) + 0.5, ); - self.play_sound(sound, category, &new_vec).await; + self.play_sound(sound, category, &new_vec); } - pub async fn play_block_sound_expect( + pub fn play_block_sound_expect( &self, player: &Player, sound: Sound, @@ -778,8 +768,7 @@ impl World { f64::from(position.0.y) + 0.5, f64::from(position.0.z) + 0.5, ); - self.play_sound_expect(player, sound, category, &new_vec) - .await; + self.play_sound_expect(player, sound, category, &new_vec); } #[expect(clippy::too_many_lines)] @@ -933,11 +922,9 @@ impl World { self.broadcast_to_chunk( chunk_pos, &CBlockUpdate::new(block_pos, i32::from(block_state_id).into()), - ) - .await; + ); } else { - self.broadcast_to_chunk(chunk_pos, &CMultiBlockUpdate::new(&updates)) - .await; + self.broadcast_to_chunk(chunk_pos, &CMultiBlockUpdate::new(&updates)); } } } @@ -982,7 +969,7 @@ impl World { }; let mut weather = self.weather.lock().await; - weather.tick_weather(self).await; + weather.tick_weather(self); if self.should_skip_night() && is_night { let mut level_time = self.level_time.lock().await; @@ -996,7 +983,7 @@ impl World { } if weather.weather_cycle_enabled && (weather.raining || weather.thundering) { - weather.reset_weather_cycle(self).await; + weather.reset_weather_cycle(self); } } else if world_age % 20 == 0 { let level_time = self.level_time.lock().await; @@ -1008,7 +995,7 @@ impl World { let active_chunks = self.active_chunks.load(); let tick_data = self.level.get_tick_data(&active_chunks); for scheduled_tick in tick_data.block_ticks { - let block = self.get_block(&scheduled_tick.position).await; + let block = self.get_block(&scheduled_tick.position); if let Some(pumpkin_block) = self.block_registry.get_pumpkin_block(block.id) { pumpkin_block .on_scheduled_tick(OnScheduledTickArgs { @@ -1020,7 +1007,7 @@ impl World { } } for scheduled_tick in tick_data.fluid_ticks { - let fluid = self.get_fluid(&scheduled_tick.position).await; + let fluid = self.get_fluid(&scheduled_tick.position); if let Some(pumpkin_fluid) = self.block_registry.get_pumpkin_fluid(fluid.id) { pumpkin_fluid .on_scheduled_tick(self, fluid, &scheduled_tick.position) @@ -1031,11 +1018,11 @@ impl World { for scheduled_tick in tick_data.random_ticks { let (block, fluid) = match (scheduled_tick.tick_block, scheduled_tick.tick_fluid) { (true, true) => { - let (block, fluid) = self.get_block_and_fluid(&scheduled_tick.position).await; + let (block, fluid) = self.get_block_and_fluid(&scheduled_tick.position); (Some(block), Some(fluid)) } - (true, false) => (Some(self.get_block(&scheduled_tick.position).await), None), - (false, true) => (None, Some(self.get_fluid(&scheduled_tick.position).await)), + (true, false) => (Some(self.get_block(&scheduled_tick.position)), None), + (false, true) => (None, Some(self.get_fluid(&scheduled_tick.position))), (false, false) => (None, None), }; @@ -1113,7 +1100,7 @@ impl World { while spawn_tasks.join_next().await.is_some() {} } - pub async fn get_fluid_collisions(self: &Arc, bounding_box: BoundingBox) -> Vec<&Fluid> { + pub fn get_fluid_collisions(self: &Arc, bounding_box: BoundingBox) -> Vec<&Fluid> { let mut collisions = Vec::new(); let min = bounding_box.min_block_pos(); @@ -1125,7 +1112,7 @@ impl World { for z in min.0.z..=max.0.z { let pos = BlockPos::new(x, y, z); - let (fluid, state) = self.get_fluid_and_fluid_state(&pos).await; + let (fluid, state) = self.get_fluid_and_fluid_state(&pos); if fluid.id != Fluid::EMPTY.id { let height = f64::from(state.height); @@ -1141,7 +1128,7 @@ impl World { collisions } - pub async fn check_fluid_collision(self: &Arc, bounding_box: BoundingBox) -> bool { + pub fn check_fluid_collision(self: &Arc, bounding_box: BoundingBox) -> bool { let min = bounding_box.min_block_pos(); let max = bounding_box.max_block_pos(); @@ -1151,7 +1138,7 @@ impl World { for z in min.0.z..=max.0.z { let pos = BlockPos::new(x, y, z); - let (fluid, state) = self.get_fluid_and_fluid_state(&pos).await; + let (fluid, state) = self.get_fluid_and_fluid_state(&pos); if fluid.id != Fluid::EMPTY.id { let height = f64::from(state.height); @@ -1168,7 +1155,7 @@ impl World { } // FlowableFluid.getVelocity() - pub async fn get_fluid_velocity( + pub fn get_fluid_velocity( &self, pos0: BlockPos, fluid0: &Fluid, @@ -1183,7 +1170,7 @@ impl World { let pos = pos0.offset(offset); - let block_state_id = self.get_block_state_id(&pos).await; + let block_state_id = self.get_block_state_id(&pos); let fluid = Fluid::from_state_id(block_state_id).unwrap_or(&Fluid::EMPTY); @@ -1198,7 +1185,7 @@ impl World { if !blocks_movement { let down_pos = pos.down(); - let (down_fluid, down_state) = self.get_fluid_and_fluid_state(&down_pos).await; + let (down_fluid, down_state) = self.get_fluid_and_fluid_state(&down_pos); if down_fluid.matches_type(fluid0) { amplitude = f64::from(state0.height - down_state.height) + 0.888_888_9; @@ -1228,8 +1215,8 @@ impl World { for dir in BlockDirection::horizontal() { let pos = pos0.offset(dir.to_offset()); - if self.is_flow_blocked(fluid0.id, pos, dir).await - || self.is_flow_blocked(fluid0.id, pos.up(), dir).await + if self.is_flow_blocked(fluid0.id, pos, dir) + || self.is_flow_blocked(fluid0.id, pos.up(), dir) { if velo.length_squared() != 0.0 { velo = velo.normalize(); @@ -1251,13 +1238,8 @@ impl World { // FlowableFluid.isFlowBlocked() - async fn is_flow_blocked( - &self, - fluid0_id: u16, - pos: BlockPos, - direction: BlockDirection, - ) -> bool { - let id = self.get_block_state_id(&pos).await; + fn is_flow_blocked(&self, fluid0_id: u16, pos: BlockPos, direction: BlockDirection) -> bool { + let id = self.get_block_state_id(&pos); let fluid = Fluid::from_state_id(id).unwrap_or(&Fluid::EMPTY); @@ -1363,7 +1345,7 @@ impl World { let pos_iter = BlockPos::iterate(min, max); for pos in pos_iter { - let state = self.get_block_state(&pos).await; + let state = self.get_block_state(&pos); if state.is_air() { continue; @@ -1401,12 +1383,12 @@ impl World { (collisions, positions) } - pub async fn is_space_empty(&self, bounding_box: BoundingBox) -> bool { + pub fn is_space_empty(&self, bounding_box: BoundingBox) -> bool { let min = bounding_box.min_block_pos(); let max = bounding_box.max_block_pos(); for pos in BlockPos::iterate(min, max) { - let state = self.get_block_state(&pos).await; + let state = self.get_block_state(&pos); let collided = Self::check_collision(&bounding_box, pos, state, false, |_| ()); if collided { @@ -1419,8 +1401,8 @@ impl World { /// Vanilla's `BlockView.getDismountHeight()`. /// Returns the Y surface height for dismounting at the given block position, /// or `f64::NEG_INFINITY` if no valid surface exists. - pub async fn get_dismount_height(&self, pos: &BlockPos) -> f64 { - let state = self.get_block_state(pos).await; + pub fn get_dismount_height(&self, pos: &BlockPos) -> f64 { + let state = self.get_block_state(pos); let max_y = state .get_block_collision_shapes() .map(|s| s.max.y) @@ -1430,7 +1412,7 @@ impl World { } // No collision at pos — check block below let below = BlockPos(Vector3::new(pos.0.x, pos.0.y - 1, pos.0.z)); - let below_state = self.get_block_state(&below).await; + let below_state = self.get_block_state(&below); let below_max_y = below_state .get_block_collision_shapes() .map(|s| s.max.y) @@ -1479,8 +1461,7 @@ impl World { // TODO biome.getPrecipitationAt(pos, this.getSeaLevel()) == Biome.Precipitation.RAIN // TODO this.getCurrentDifficultyAt(blockPos); if rng().random::() < 0.0675 - && self.get_block(&random_pos.to_block_pos().down()).await - != &Block::LIGHTNING_ROD + && self.get_block(&random_pos.to_block_pos().down()) != &Block::LIGHTNING_ROD { let entity = Entity::new( self.clone(), @@ -1502,7 +1483,17 @@ impl World { return; } // TODO this.level.canSpawnEntitiesInChunk(chunkPos) - spawn_for_chunk(self, chunk_pos, chunk, spawn_state, spawn_list).await; + let entities = spawn_for_chunk( + self, + chunk_pos, + chunk, + spawn_state, + spawn_list, + is_thundering, + ); + for entity in entities { + self.spawn_entity(entity).await; + } } pub async fn get_world_age(&self) -> i64 { @@ -1527,9 +1518,7 @@ impl World { let mut weather = self.weather.lock().await; if weather.raining != raining { let thunder = weather.thundering; - weather - .set_weather_parameters(self, 0, 0, raining, thunder) - .await; + weather.set_weather_parameters(self, 0, 0, raining, thunder); } } @@ -1541,17 +1530,15 @@ impl World { let mut weather = self.weather.lock().await; if weather.thundering != thundering { let raining = weather.raining; - weather - .set_weather_parameters(self, 0, 0, raining, thundering) - .await; + weather.set_weather_parameters(self, 0, 0, raining, thundering); } } /// Gets the y position of the first non air block from the top down - pub async fn get_top_block(&self, position: Vector2) -> i32 { + pub fn get_top_block(&self, position: Vector2) -> i32 { for y in (self.dimension.min_y..self.dimension.height).rev() { let pos = BlockPos::new(position.x, y, position.y); - let block = self.get_block_state(&pos).await; + let block = self.get_block_state(&pos); if block.is_air() { continue; } @@ -1560,36 +1547,17 @@ impl World { self.dimension.min_y } - /// Gets the `MOTION_BLOCKING` heightmap value for a given XZ position. - pub async fn get_motion_blocking_height(&self, x: i32, z: i32) -> i32 { + pub fn get_heightmap_height(&self, height_map: ChunkHeightmapType, x: i32, z: i32) -> i32 { let chunk_pos = Vector2::new(x >> 4, z >> 4); self.level - .get_or_fetch_chunk(chunk_pos, |chunk| { - chunk - .heightmap - .lock() - .unwrap() - .get(MotionBlocking, x, z, self.min_y) - }) - .await - } - - pub async fn get_heightmap_height( - &self, - height_map: ChunkHeightmapType, - x: i32, - z: i32, - ) -> i32 { - let chunk_pos = Vector2::new(x >> 4, z >> 4); - self.level - .get_or_fetch_chunk(chunk_pos, |chunk| { + .read_chunk_sync(&chunk_pos, |chunk| { chunk .heightmap .lock() .unwrap() .get(height_map, x, z, self.min_y) }) - .await + .unwrap_or(self.min_y) } #[allow(clippy::too_many_lines)] @@ -1610,7 +1578,7 @@ impl World { (position, yaw, pitch) } else { let spawn_position = Vector2::new(level_info.spawn_x, level_info.spawn_z); - let pos_y = self.get_top_block(spawn_position).await + 1; // +1 to spawn on top of the block + let pos_y = self.get_top_block(spawn_position) + 1; // +1 to spawn on top of the block let position = Vector3::new( f64::from(level_info.spawn_x) + 0.5, @@ -1924,7 +1892,7 @@ impl World { server.tick_rate_manager.update_joining_player(player).await; // Permissions, i.e. the commands a player may use. - player.send_permission_lvl_update().await; + player.send_permission_lvl_update(); // Difficulty of the world player.send_difficulty_update().await; @@ -1948,7 +1916,7 @@ impl World { } else { let info = &self.level_info.load(); let spawn_position = Vector2::new(info.spawn_x, info.spawn_z); - let pos_y = self.get_top_block(spawn_position).await + 1; // +1 to spawn on top of the block + let pos_y = self.get_top_block(spawn_position) + 1; // +1 to spawn on top of the block let position = Vector3::new( f64::from(info.spawn_x) + 0.5, @@ -1989,8 +1957,7 @@ impl World { PlayerAction::UpdateListOrder(VarInt(0)), ], }], - )) - .await; + )); // If the player has a custom tab_list_name, send an update for it if let Some(tab_list_name) = player.get_tab_list_name().await { @@ -2000,8 +1967,7 @@ impl World { uuid: gameprofile.id, actions: &[PlayerAction::UpdateDisplayName(Some(&tab_list_name))], }], - )) - .await; + )); } // Here, we send all the infos of players who already joined. let mut players_tab_list_names = Vec::new(); @@ -2101,8 +2067,7 @@ impl World { 0.into(), velocity, ), - ) - .await; + ); // Spawn players for our client. let id = player.gameprofile.id; @@ -2184,7 +2149,7 @@ impl World { .await; } } - player.send_client_information().await; + player.send_client_information(); player.send_abilities_update().await; @@ -2251,9 +2216,9 @@ impl World { .await; } - // if let Some(bossbars) = self..lock().await.get_player_bars(&player.gameprofile.id) { + // if let Some(bossbars) = self..lock().get_player_bars(&player.gameprofile.id) { // for bossbar in bossbars { - // player.send_bossbar(bossbar).await; + // player.send_bossbar(bossbar); // } // } @@ -2287,8 +2252,7 @@ impl World { let event = server.plugin_manager.fire(event).await; if !event.cancelled { - self.broadcast_system_message(&event.join_message, false) - .await; + self.broadcast_system_message(&event.join_message, false); // TODO: Switch to structured logging, e.g. info!(player = %name, "connected") info!("{}", event.join_message.to_pretty_console()); } @@ -2316,8 +2280,7 @@ impl World { chunk_pos, &[from.get_entity().entity_uuid], &CSetEquipment::new(from.entity_id().into(), equipment), - ) - .await; + ); } pub async fn send_world_info( @@ -2354,10 +2317,9 @@ impl World { 0.into(), Vector3::new(0.0, 0.0, 0.0), ), - ) - .await; + ); - player.send_client_information().await; + player.send_client_information(); chunker::update_position(player).await; // Update commands @@ -2439,7 +2401,7 @@ impl World { // FIXME: This spawn position calculation is incorrect. Should use vanilla's // proper spawn position calculation (see #1381). The y-level calculation // needs to account for spawn radius and find a safe spawn position. - let top = self.get_top_block(Vector2::new(spawn_x, spawn_z)).await; + let top = self.get_top_block(Vector2::new(spawn_x, spawn_z)); ( Vector3::new( @@ -2507,7 +2469,7 @@ impl World { ); // FIXME: This spawn position calculation is incorrect. Should use vanilla's // proper spawn position calculation (see #1381). - let top = self.get_top_block(Vector2::new(spawn_x, spawn_z)).await; + let top = self.get_top_block(Vector2::new(spawn_x, spawn_z)); let fallback_pos = Vector3::new( f64::from(spawn_x) + 0.5, (top + 1).into(), @@ -2556,7 +2518,7 @@ impl World { player.living_entity.reset_state().await; - player.send_permission_lvl_update().await; + player.send_permission_lvl_update(); player.hunger_manager.restart(); @@ -2689,8 +2651,7 @@ impl World { }; // Pos is zero since it will read from nbt let entity = - from_type(entity_type, Vector3::new(0.0, 0.0, 0.0), &world, *uuid) - .await; + from_type(entity_type, Vector3::new(0.0, 0.0, 0.0), &world, *uuid); entity.read_nbt_non_mut(entity_nbt).await; let base_entity = entity.get_entity(); @@ -2739,8 +2700,7 @@ impl World { continue; }; // Pos is zero since it will read from nbt - let entity = - from_type(entity_type, Vector3::new(0.0, 0.0, 0.0), &world, *uuid).await; + let entity = from_type(entity_type, Vector3::new(0.0, 0.0, 0.0), &world, *uuid); entity.read_nbt_non_mut(entity_nbt).await; let base_entity = entity.get_entity(); player @@ -3129,10 +3089,8 @@ impl World { }); if let Some(ref player) = removed_player { let uuid = player.gameprofile.id; - self.broadcast_packet_all(&CRemovePlayerInfo::new(&[uuid])) - .await; - self.broadcast_packet_all(&CRemoveEntities::new(&[player.entity_id().into()])) - .await; + self.broadcast_packet_all(&CRemovePlayerInfo::new(&[uuid])); + self.broadcast_packet_all(&CRemoveEntities::new(&[player.entity_id().into()])); if fire_event { let msg_comp = TextComponent::translate_cross( @@ -3162,13 +3120,24 @@ impl World { removed_player } + pub fn spawn_entity_non_save(&self, entity: &Arc) { + let base_entity = entity.get_entity(); + let chunk_pos = base_entity.chunk_pos.load(); + self.broadcast_to_chunk(chunk_pos, &base_entity.create_spawn_packet()); + self.spawn_state.load().add_entity(self, entity.as_ref()); + + self.entities.rcu(|current_entities| { + let mut new_entities = (**current_entities).clone(); + new_entities.push(entity.clone()); + new_entities + }); + } + pub async fn spawn_entity(&self, entity: Arc) { let base_entity = entity.get_entity(); let chunk_pos = base_entity.chunk_pos.load(); - self.broadcast_to_chunk(chunk_pos, &base_entity.create_spawn_packet()) - .await; + self.broadcast_to_chunk(chunk_pos, &base_entity.create_spawn_packet()); entity.init_data_tracker().await; - self.add_entity_silent(entity).await; } @@ -3206,8 +3175,7 @@ impl World { self.broadcast_to_chunk( chunk_pos, &CRemoveEntities::new(&[base_entity.entity_id.into()]), - ) - .await; + ); self.remove_entity_data(base_entity).await; } @@ -3311,7 +3279,7 @@ impl World { // WorldChunk.java line 305-314 if is_new_block && old_block.default_state.block_entity_type != u16::MAX - && let Some(entity) = self.get_block_entity(position).await + && let Some(entity) = self.get_block_entity(position) { entity.on_block_replaced(self.clone(), *position).await; self.remove_block_entity(position).await; @@ -3342,7 +3310,7 @@ impl World { block_moved, ) .await; - let new_fluid = self.get_fluid(position).await; + let new_fluid = self.get_fluid(position); self.block_registry .on_placed_fluid( self, @@ -3356,7 +3324,7 @@ impl World { } // Ig they do this cause it could be modified in chunkPos.setBlockState? - if self.get_block_state_id(position).await == block_state_id { + if self.get_block_state_id(position) == block_state_id { if flags.contains(BlockFlags::NOTIFY_LISTENERS) { // Mob AI update } @@ -3409,6 +3377,28 @@ impl World { replaced_block_state_id } + pub fn is_thundering_sync(&self) -> bool { + self.weather.blocking_lock().thundering + } + + pub fn get_block_light_level_sync(&self, position: &BlockPos) -> Option { + self.level + .light_engine + .get_block_light_level_sync(&self.level, position) + } + + pub fn get_sky_light_level_sync(&self, position: &BlockPos) -> u8 { + self.level + .light_engine + .get_sky_light_level_sync(&self.level, position) + } + + pub fn get_max_local_raw_brightness_sync(&self, pos: &BlockPos) -> u8 { + let sky_light = self.get_sky_light_level_sync(pos); + let block_light = self.get_block_light_level_sync(pos).unwrap_or(0); + sky_light.max(block_light) // TODO: getSkyDarken + } + pub async fn get_max_local_raw_brightness(&self, pos: &BlockPos) -> u8 { let sky_light = self.get_sky_light_level(pos).await; let block_light = self.get_block_light_level(pos).await.unwrap(); @@ -3468,7 +3458,7 @@ impl World { cause: Option>, flags: BlockFlags, ) -> Option { - let (broken_block, broken_block_state) = self.get_block_and_state_id(position).await; + let (broken_block, broken_block_state) = self.get_block_and_state_id(position); if is_air(broken_block_state) { return None; } @@ -3533,10 +3523,9 @@ impl World { chunk_pos, &[player.living_entity.entity.entity_uuid], &particles_packet, - ) - .await; + ); } - None => self.broadcast_to_chunk(chunk_pos, &particles_packet).await, + None => self.broadcast_to_chunk(chunk_pos, &particles_packet), } } @@ -3574,7 +3563,7 @@ impl World { }; let entity = Entity::new(self.clone(), spawn_pos, &EntityType::ITEM); - let item_entity = Arc::new(ItemEntity::new(entity, stack).await); + let item_entity = Arc::new(ItemEntity::new(entity, stack)); self.spawn_entity(item_entity).await; } @@ -3620,19 +3609,18 @@ impl World { ); let entity = Entity::new(self.clone(), Vector3::new(x, y, z), &EntityType::ITEM); - let entity = Arc::new(ItemEntity::new_with_velocity(entity, item, velocity, 10).await); + let entity = Arc::new(ItemEntity::new_with_velocity(entity, item, velocity, 10)); self.spawn_entity(entity).await; } } /* End ItemScatterer.java */ - pub async fn sync_world_event(&self, world_event: WorldEvent, position: BlockPos, data: i32) { + pub fn sync_world_event(&self, world_event: WorldEvent, position: BlockPos, data: i32) { let chunk_pos = position.chunk_position(); self.broadcast_to_chunk( chunk_pos, &CWorldEvent::new(world_event as i32, position, data, false), - ) - .await; + ); } #[must_use] pub fn is_valid(dest: BlockPos) -> bool { @@ -3664,9 +3652,9 @@ impl World { self.dimension.min_y + self.dimension.height - 1 } /// Gets a `Block` from the block registry. Returns `Block::AIR` if the block was not found. - pub async fn get_block(&self, position: &BlockPos) -> &'static Block { - let id = self.get_block_state_id(position).await; - Block::from_state_id(id) + pub fn get_block(&self, position: &BlockPos) -> &'static Block { + self.get_block_state_id_if_loaded(position) + .map_or(&Block::AIR, Block::from_state_id) } #[must_use] @@ -3693,8 +3681,8 @@ impl World { self.get_block_state_id_if_loaded(position).is_some() } - pub async fn get_fluid(&self, position: &BlockPos) -> &'static pumpkin_data::fluid::Fluid { - let id = self.get_block_state_id(position).await; + pub fn get_fluid(&self, position: &BlockPos) -> &'static pumpkin_data::fluid::Fluid { + let id = self.get_block_state_id(position); let fluid = Fluid::from_state_id(id).ok_or(&Fluid::EMPTY); if let Ok(fluid) = fluid { return fluid.to_flowing(); @@ -3718,14 +3706,14 @@ impl World { .unwrap_or(&Fluid::EMPTY) } - pub async fn get_block_and_fluid( + pub fn get_block_and_fluid( &self, position: &BlockPos, ) -> ( &'static pumpkin_data::Block, &'static pumpkin_data::fluid::Fluid, ) { - let id = self.get_block_state_id(position).await; + let id = self.get_block_state_id(position); let block = Block::from_state_id(id); let fluid = Fluid::from_state_id(id) @@ -3752,11 +3740,11 @@ impl World { (block, fluid) } - pub async fn get_fluid_and_fluid_state( + pub fn get_fluid_and_fluid_state( &self, position: &BlockPos, ) -> (&'static Fluid, &'static FluidState) { - let id = self.get_block_state_id(position).await; + let id = self.get_block_state_id(position); let Some(raw_fluid) = Fluid::from_state_id(id) else { let block = Block::from_state_id(id); @@ -3783,28 +3771,29 @@ impl World { (fluid, state) } - pub async fn get_block_state_id(&self, position: &BlockPos) -> BlockStateId { - self.level.get_block_state(position).await.0 + pub fn get_block_state_id(&self, position: &BlockPos) -> BlockStateId { + self.get_block_state_id_if_loaded(position) + .unwrap_or(Block::AIR.default_state.id) } /// Gets the `BlockState` from the block registry. Returns Air if the block state was not found. - pub async fn get_block_state(&self, position: &BlockPos) -> &'static BlockState { - let id = self.get_block_state_id(position).await; + pub fn get_block_state(&self, position: &BlockPos) -> &'static BlockState { + let id = self.get_block_state_id(position); BlockState::from_id(id) } /// Gets the Block + Block state from the Block Registry, Returns Air if the Block state has not been found - pub async fn get_block_and_state( + pub fn get_block_and_state( &self, position: &BlockPos, ) -> (&'static Block, &'static BlockState) { - let id = self.get_block_state_id(position).await; + let id = self.get_block_state_id(position); BlockState::from_id_with_block(id) } /// Gets the Block + state id from the Block Registry, Returns Air if the Block state has not been found - pub async fn get_block_and_state_id(&self, position: &BlockPos) -> (&'static Block, u16) { - let id = self.get_block_state_id(position).await; + pub fn get_block_and_state_id(&self, position: &BlockPos) -> (&'static Block, u16) { + let id = self.get_block_state_id(position); (Block::from_state_id(id), id) } @@ -3814,14 +3803,14 @@ impl World { block_pos: &BlockPos, except: Option, ) { - let source_block = self.get_block(block_pos).await; + let source_block = self.get_block(block_pos); for direction in BlockDirection::update_order() { if except.is_some_and(|d| d == direction) { continue; } let neighbor_pos = block_pos.offset(direction.to_offset()); - let (neighbor_block, neighbor_fluid) = self.get_block_and_fluid(&neighbor_pos).await; + let (neighbor_block, neighbor_fluid) = self.get_block_and_fluid(&neighbor_pos); if let Some(neighbor_pumpkin_block) = self.block_registry.get_pumpkin_block(neighbor_block.id) @@ -3852,7 +3841,7 @@ impl World { neighbor_block_pos: &BlockPos, source_block: &Block, ) { - let neighbor_block = self.get_block(neighbor_block_pos).await; + let neighbor_block = self.get_block(neighbor_block_pos); if let Some(neighbor_pumpkin_block) = self.block_registry.get_pumpkin_block(neighbor_block.id) @@ -3878,7 +3867,7 @@ impl World { let block = Block::from_state_id(state_id); for direction in BlockDirection::all() { let neighbor_pos = pos.offset(direction.to_offset()); - let neighbor_state_id = self.get_block_state_id(&neighbor_pos).await; + let neighbor_state_id = self.get_block_state_id(&neighbor_pos); current_state_id = self .block_registry .get_state_for_neighbor_update( @@ -3901,7 +3890,7 @@ impl World { direction: BlockDirection, flags: BlockFlags, ) { - let (block, block_state_id) = self.get_block_and_state_id(block_pos).await; + let (block, block_state_id) = self.get_block_and_state_id(block_pos); if flags.contains(BlockFlags::SKIP_REDSTONE_WIRE_STATE_REPLACEMENT) && *block == Block::REDSTONE_WIRE @@ -3910,7 +3899,7 @@ impl World { } let neighbor_pos = block_pos.offset(direction.to_offset()); - let neighbor_state_id = self.get_block_state_id(&neighbor_pos).await; + let neighbor_state_id = self.get_block_state_id(&neighbor_pos); let new_state_id = self .block_registry @@ -3934,8 +3923,7 @@ impl World { } } - #[expect(clippy::unused_async)] - pub async fn get_block_entity(&self, block_pos: &BlockPos) -> Option> { + pub fn get_block_entity(&self, block_pos: &BlockPos) -> Option> { self.block_entities .get(block_pos) .map(|e| e.value().clone()) @@ -3956,8 +3944,7 @@ impl World { VarInt(block_entity.get_id() as i32), bytes.into_boxed_slice(), ), - ) - .await; + ); } self.block_entities.insert(block_pos, block_entity.clone()); @@ -3993,8 +3980,7 @@ impl World { VarInt(block_entity.get_id() as i32), bytes.into_boxed_slice(), ), - ) - .await; + ); } self.level .get_or_fetch_chunk(chunk_pos, |chunk| { @@ -4062,13 +4048,13 @@ impl World { } } - async fn ray_outline_check( + fn ray_outline_check( &self, block_pos: &BlockPos, from: Vector3, to: Vector3, ) -> (bool, Option) { - let state = self.get_block_state(block_pos).await; + let state = self.get_block_state(block_pos); if state.outline_shapes.is_empty() { return (true, None); @@ -4105,7 +4091,7 @@ impl World { let mut block = BlockPos::floored(from.x, from.y, from.z); - let (collision, direction) = self.ray_outline_check(&block, from, to).await; + let (collision, direction) = self.ray_outline_check(&block, from, to); if let Some(dir) = direction && collision { @@ -4187,7 +4173,7 @@ impl World { }; if hit_check(&block, self).await { - let (collision, direction) = self.ray_outline_check(&block, from, to).await; + let (collision, direction) = self.ray_outline_check(&block, from, to); if collision { if let Some(dir) = direction { return Some((block, dir)); @@ -4202,7 +4188,7 @@ impl World { /// Broadcasts a packet to all players who currently have the target chunk loaded. /// This uses highly optimized Chebyshev distance math (Chunk Grid) instead of floating point distance checks. - pub async fn broadcast_to_chunk(&self, chunk_pos: Vector2, packet: &P) { + pub fn broadcast_to_chunk(&self, chunk_pos: Vector2, packet: &P) { let players = self.players.load(); let recipients = players.iter().filter(|p| { @@ -4214,11 +4200,11 @@ impl World { }); let recipients_by_version = Self::collect_java_recipients_by_version(recipients); - Self::broadcast_java_grouped(packet, recipients_by_version).await; + Self::broadcast_java_grouped(packet, recipients_by_version); } /// Broadcasts a packet to chunk watchers, excluding specific players. - pub async fn broadcast_to_chunk_except( + pub fn broadcast_to_chunk_except( &self, chunk_pos: Vector2, except: &[uuid::Uuid], @@ -4237,7 +4223,7 @@ impl World { }); let recipients_by_version = Self::collect_java_recipients_by_version(recipients); - Self::broadcast_java_grouped(packet, recipients_by_version).await; + Self::broadcast_java_grouped(packet, recipients_by_version); } pub async fn broadcast_to_chunk_except_editioned( @@ -4270,7 +4256,7 @@ impl World { let je_recipients_by_version = Self::collect_java_recipients_by_version(java_recipients.into_iter()); - Self::broadcast_java_grouped(je_packet, je_recipients_by_version).await; + Self::broadcast_java_grouped(je_packet, je_recipients_by_version); for recipient in bedrock_recipients { recipient.send_game_packet(be_packet).await; @@ -4279,35 +4265,29 @@ impl World { } impl BlockAccessor for World { - fn get_block<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { Self::get_block(self, position).await }) + fn get_block(&self, position: &BlockPos) -> &'static Block { + self.get_block_state_id_if_loaded(position) + .map_or(&Block::AIR, Block::from_state_id) } - fn get_block_state<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { Self::get_block_state(self, position).await }) + fn get_block_state(&self, position: &BlockPos) -> &'static BlockState { + self.get_block_state_id_if_loaded(position) + .map_or(Block::AIR.default_state, BlockState::from_id) } - fn get_block_state_id<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { Self::get_block_state_id(self, position).await }) + fn get_block_state_id(&self, position: &BlockPos) -> BlockStateId { + self.get_block_state_id_if_loaded(position) + .unwrap_or(Block::AIR.default_state.id) } - fn get_block_and_state<'a>( - &'a self, - position: &'a BlockPos, - ) -> Pin + Send + 'a>> { - Box::pin(async move { self.get_block_and_state(position).await }) + fn get_block_and_state(&self, position: &BlockPos) -> (&'static Block, &'static BlockState) { + let id = self + .get_block_state_id_if_loaded(position) + .unwrap_or(Block::AIR.default_state.id); + BlockState::from_id_with_block(id) } } -pub struct WorldPortal(pub Arc, pub Handle); +pub struct WorldPortal(pub Arc); // Pure Beauty :cap: impl WorldPortalExt for WorldPortal { @@ -4318,24 +4298,17 @@ impl WorldPortalExt for WorldPortal { block_accessor: &dyn BlockAccessor, block_pos: &BlockPos, ) -> bool { - let handle = &self.1; - - handle.block_on(async move { - self.0 - .block_registry - .can_place_at( - None, - None, - block_accessor, - None, - block, - state, - block_pos, - None, - None, - ) - .await - }) + self.0.block_registry.can_place_at( + None, + None, + block_accessor, + None, + block, + state, + block_pos, + None, + None, + ) } fn spawn_mobs_for_chunk_generation( @@ -4345,13 +4318,6 @@ impl WorldPortalExt for WorldPortal { chunk_x: i32, chunk_z: i32, ) { - let handle = &self.1; - - handle.block_on(async move { - natural_spawner::spawn_mobs_for_chunk_generation( - &self.0, cache, biome, chunk_x, chunk_z, - ) - .await; - }); + natural_spawner::spawn_mobs_for_chunk_generation(&self.0, cache, biome, chunk_x, chunk_z); } } diff --git a/pumpkin/src/world/natural_spawner.rs b/pumpkin/src/world/natural_spawner.rs index ddcda8d72..9f6683f00 100644 --- a/pumpkin/src/world/natural_spawner.rs +++ b/pumpkin/src/world/natural_spawner.rs @@ -10,7 +10,6 @@ use pumpkin_data::tag::Fluid::{MINECRAFT_LAVA, MINECRAFT_WATER}; use pumpkin_data::tag::Taggable; use pumpkin_data::tag::WorldgenBiome::MINECRAFT_REDUCE_WATER_AMBIENT_SPAWNS; use pumpkin_data::{Block, BlockDirection, BlockState}; -use pumpkin_nbt::compound::NbtCompound; use pumpkin_util::GameMode; use pumpkin_util::math::boundingbox::{BoundingBox, EntityDimensions}; use pumpkin_util::math::get_section_cord; @@ -19,7 +18,6 @@ use pumpkin_util::math::vector2::Vector2; use pumpkin_util::math::vector3::Vector3; use pumpkin_util::random::xoroshiro128::Xoroshiro; use pumpkin_util::random::{RandomImpl, get_seed}; -use pumpkin_world::chunk::io::Dirtiable; use pumpkin_world::chunk::{ChunkData, ChunkHeightmapType}; use pumpkin_world::generation::proto_chunk::GenerationCache; use rand::seq::IndexedRandom; @@ -377,14 +375,14 @@ impl SpawnState { self.local_mob_cap_calculator .can_spawn(category, world, chunk_pos) } - pub async fn can_spawn( + pub fn can_spawn( &self, entity_type: &'static EntityType, pos: &BlockPos, world: &Arc, ) -> bool { // TODO get biome - let biome = world.level.get_rough_biome(pos).await; + let biome = world.level.get_rough_biome(pos); biome .spawn_costs .get(entity_type.resource_name) @@ -402,7 +400,7 @@ impl SpawnState { }, ) } - pub async fn after_spawn( + pub fn after_spawn( &self, entity_type: &'static EntityType, pos: &BlockPos, @@ -417,16 +415,14 @@ impl SpawnState { None }; - let charge = if let Some(charge) = charge { - charge - } else { + let charge = charge.unwrap_or_else(|| { // TODO get biome - let biome = world.level.get_rough_biome(pos).await; + let biome = world.level.get_rough_biome(pos); biome .spawn_costs .get(entity_type.resource_name) .map_or(0., |cost| cost.charge) - }; + }); self.spawn_potential.add_charge(pos, charge); self.mob_category_counts.add(entity_type.category); @@ -468,23 +464,32 @@ pub fn get_filtered_spawning_categories( ret } -pub async fn spawn_for_chunk( +pub fn spawn_for_chunk( world: &Arc, chunk_pos: Vector2, chunk: &Arc, spawn_state: &SpawnState, spawn_list: &Vec<&'static MobCategory>, -) { + is_thundering: bool, +) -> Vec> { // debug!("spawn for chunk {:?}", chunk_pos); + let mut entities = Vec::new(); for category in spawn_list { if spawn_state.can_spawn_for_category_local(world, category, chunk_pos) { let random_pos = get_random_pos_within(world.min_y, &chunk_pos, chunk); if random_pos.0.y > world.min_y { - spawn_category_for_position(category, world, random_pos, &chunk_pos, spawn_state) - .await; + entities.extend(spawn_category_for_position( + category, + world, + random_pos, + &chunk_pos, + spawn_state, + is_thundering, + )); } } } + entities } pub fn get_random_pos_within( min_y: i32, @@ -505,7 +510,7 @@ pub fn get_random_pos_within( BlockPos::new(x, y, z) } -pub async fn spawn_mobs_for_chunk_generation( +pub fn spawn_mobs_for_chunk_generation( world: &Arc, cache: &mut dyn GenerationCache, biome: &'static Biome, @@ -560,11 +565,11 @@ pub async fn spawn_mobs_for_chunk_generation( f64::from(pos.0.z) + 0.5, ); - let entity = from_type(entity_type, spawn_pos_f64, world, Uuid::new_v4()).await; + let entity = from_type(entity_type, spawn_pos_f64, world, Uuid::new_v4()); entity .get_entity() .set_rotation(rand::random::() * 360., 0.); - world.spawn_entity(entity).await; + world.spawn_entity_non_save(&entity); success = true; } @@ -625,13 +630,14 @@ pub fn get_top_non_colliding_pos( adjust_spawn_position_cache(cache, pos, entity_type) } -pub async fn spawn_category_for_position( +pub fn spawn_category_for_position( category: &'static MobCategory, world: &Arc, pos: BlockPos, chunk_pos: &Vector2, spawn_state: &SpawnState, -) { + is_thundering: bool, +) -> Vec> { let mut batch_buffer = vec![]; let mut spawn_cluster_size = 0; let player_positions: Vec<_> = world.players.load().iter().map(|p| p.position()).collect(); @@ -650,7 +656,7 @@ pub async fn spawn_category_for_position( let mut new_pos = BlockPos::new(new_x, pos.0.y, new_z); if current_spawner.is_none() { - let Some(spawner) = get_random_spawn_mob_at(world, category, &new_pos).await else { + let Some(spawner) = get_random_spawn_mob_at(world, category, &new_pos) else { break 'spawn_loop; }; current_spawner = Some(spawner); @@ -661,7 +667,7 @@ pub async fn spawn_category_for_position( let entity_type = &EntityType::from_name(spawner.r#type.strip_prefix("minecraft:").unwrap()).unwrap(); - new_pos = adjust_spawn_position(world, new_pos, entity_type).await; + new_pos = adjust_spawn_position(world, new_pos, entity_type); let spawn_pos_f64 = Vector3::new( f64::from(new_pos.0.x) + 0.5, @@ -681,25 +687,24 @@ pub async fn spawn_category_for_position( category, entity_type, player_distance, - ) - .await - { + is_thundering, + ) { inc += 1; continue; } - if !spawn_state.can_spawn(entity_type, &new_pos, world).await { + if !spawn_state.can_spawn(entity_type, &new_pos, world) { inc += 1; continue; } - let entity = from_type(entity_type, spawn_pos_f64, world, Uuid::new_v4()).await; + let entity = from_type(entity_type, spawn_pos_f64, world, Uuid::new_v4()); entity .get_entity() .set_rotation(rng().random::() * 360., 0.); spawn_cluster_size += 1; batch_buffer.push(entity); - spawn_state.after_spawn(entity_type, &new_pos, world).await; + spawn_state.after_spawn(entity_type, &new_pos, world); if spawn_cluster_size >= entity_type.limit_per_chunk { break 'group_loop; } @@ -707,48 +712,7 @@ pub async fn spawn_category_for_position( inc += 1; } } - - // Spawn in batch - if !batch_buffer.is_empty() { - let mut prepared_data = Vec::with_capacity(batch_buffer.len()); - - for entity in &batch_buffer { - entity.init_data_tracker().await; - let base_entity = entity.get_entity(); - let packet = base_entity.create_spawn_packet(); - let mut nbt = NbtCompound::new(); - entity.write_nbt(&mut nbt).await; - // Keep the entity reference here so we don't have to "find" it later - prepared_data.push((base_entity.entity_uuid, nbt, packet, entity.clone())); - } - - let chunk_handle = world.level.get_entity_chunk(*chunk_pos).await; - let mut data = chunk_handle.data.lock().await; - - for (uuid, nbt, _, _) in &prepared_data { - data.insert(*uuid, nbt.clone()); - } - drop(data); - chunk_handle.mark_dirty(true); - - world.entities.rcu(|current_entities| { - let mut new_entities = (**current_entities).clone(); - - for (uuid, _, _, entity_ref) in &prepared_data { - if !new_entities - .iter() - .any(|e| e.get_entity().entity_uuid == *uuid) - { - new_entities.push(entity_ref.clone()); - } - } - new_entities - }); - - for (_, _, packet, _) in prepared_data { - world.broadcast_packet_all(&packet).await; - } - } + batch_buffer } #[must_use] @@ -784,13 +748,13 @@ pub fn is_right_distance_to_player_and_spawn_point( } #[must_use] -pub async fn get_random_spawn_mob_at( +pub fn get_random_spawn_mob_at( world: &Arc, category: &'static MobCategory, block_pos: &BlockPos, ) -> Option<&'static Spawner> { // TODO Holder holder = level.getBiome(pos); - let biome = world.level.get_rough_biome(block_pos).await; + let biome = world.level.get_rough_biome(block_pos); if category == &MobCategory::WATER_AMBIENT && biome.has_tag(&MINECRAFT_REDUCE_WATER_AMBIENT_SPAWNS) && rng().random::() < 0.98f32 @@ -816,12 +780,13 @@ pub async fn get_random_spawn_mob_at( } } -pub async fn is_valid_spawn_position_for_type( +pub fn is_valid_spawn_position_for_type( world: &Arc, block_pos: &BlockPos, category: &'static MobCategory, entity_type: &'static EntityType, distance: f64, + is_thundering: bool, ) -> bool { // TODO !SpawnPlacements.checkSpawnRules(entityType, level, EntitySpawnReason.NATURAL, pos, level.random) if category == &MobCategory::MISC { @@ -837,48 +802,44 @@ pub async fn is_valid_spawn_position_for_type( if !entity_type.summonable { return false; } - if !is_spawn_position_ok(world, block_pos, entity_type).await { + if !is_spawn_position_ok(world, block_pos, entity_type) { return false; } - if !check_spawn_rules(entity_type, world, block_pos).await { + if !check_spawn_rules(entity_type, world, block_pos, is_thundering) { return false; } // TODO: we should use getSpawnBox, but this is only modified for slimes and magma slimes - if !world - .is_space_empty(BoundingBox::new_from_pos( - f64::from(block_pos.0.x) + 0.5, - f64::from(block_pos.0.y), - f64::from(block_pos.0.z) + 0.5, - &EntityDimensions { - width: entity_type.dimension[0], - height: entity_type.dimension[1], - eye_height: entity_type.eye_height, - }, - )) - .await - { + if !world.is_space_empty(BoundingBox::new_from_pos( + f64::from(block_pos.0.x) + 0.5, + f64::from(block_pos.0.y), + f64::from(block_pos.0.z) + 0.5, + &EntityDimensions { + width: entity_type.dimension[0], + height: entity_type.dimension[1], + eye_height: entity_type.eye_height, + }, + )) { return false; } true } -pub async fn is_spawn_position_ok( +pub fn is_spawn_position_ok( world: &Arc, block_pos: &BlockPos, entity_type: &'static EntityType, ) -> bool { match entity_type.spawn_restriction.location { - SpawnLocation::InLava => world.get_fluid(block_pos).await.has_tag(&MINECRAFT_LAVA), + SpawnLocation::InLava => world.get_fluid(block_pos).has_tag(&MINECRAFT_LAVA), SpawnLocation::InWater => { // TODO !level.getBlockState(blockPos).isRedstoneConductor(level, blockPos) - let above_state = world.get_block_state(&block_pos.up()).await; - world.get_fluid(block_pos).await.has_tag(&MINECRAFT_WATER) - && !above_state.is_full_cube() + let above_state = world.get_block_state(&block_pos.up()); + world.get_fluid(block_pos).has_tag(&MINECRAFT_WATER) && !above_state.is_full_cube() } SpawnLocation::OnGround => { - let down = world.get_block_state(&block_pos.down()).await; - let up = world.get_block_state(&block_pos.up()).await; - let cur = world.get_block_state(block_pos).await; + let down = world.get_block_state(&block_pos.down()); + let up = world.get_block_state(&block_pos.up()); + let cur = world.get_block_state(block_pos); // TODO: blockState.allowsSpawning let is_valid_spawn_below = down.is_side_solid(BlockDirection::Up) && down.luminance < 14; @@ -956,7 +917,7 @@ pub fn adjust_spawn_position_cache( pos } -pub async fn adjust_spawn_position( +pub fn adjust_spawn_position( world: &World, pos: BlockPos, entity_type: &'static EntityType, @@ -966,7 +927,7 @@ pub async fn adjust_spawn_position( SpawnLocation::OnGround ) { let below = pos.down(); - let state = world.get_block_state(&below).await; + let state = world.get_block_state(&below); // Approximation of isPathfindable(LAND) if !state.is_full_cube() && !state.is_liquid() { return below; diff --git a/pumpkin/src/world/portal/end.rs b/pumpkin/src/world/portal/end.rs index a45003348..9b9af788e 100644 --- a/pumpkin/src/world/portal/end.rs +++ b/pumpkin/src/world/portal/end.rs @@ -16,15 +16,15 @@ impl EndPortal { pub async fn get_new_portal(world: &Arc, pos: BlockPos) { let mid_pos = Self::get_mid_pos(world, pos); - if let Some(mid_pos) = mid_pos.await - && Self::is_valid_portal(world, mid_pos).await + if let Some(mid_pos) = mid_pos + && Self::is_valid_portal(world, mid_pos) { Self::create_portal(world, mid_pos).await; } } - async fn get_mid_pos(world: &World, pos: BlockPos) -> Option { - let (block, state) = world.get_block_and_state_id(&pos).await; + fn get_mid_pos(world: &World, pos: BlockPos) -> Option { + let (block, state) = world.get_block_and_state_id(&pos); if block != &Self::FRAME_BLOCK { return None; } @@ -34,8 +34,8 @@ impl EndPortal { let left_pos = pos.offset_dir(facing_dir.rotate_clockwise().to_offset(), 1); let right_pos = pos.offset_dir(facing_dir.rotate_counter_clockwise().to_offset(), 1); - let left_block = world.get_block(&left_pos).await; - let right_block = world.get_block(&right_pos).await; + let left_block = world.get_block(&left_pos); + let right_block = world.get_block(&right_pos); let offset = match (left_block.id, right_block.id) { (Self::FRAME_BLOCK_ID, Self::FRAME_BLOCK_ID) => 0, // Middle block @@ -50,16 +50,16 @@ impl EndPortal { ) } - async fn is_valid_portal(world: &World, pos: BlockPos) -> bool { + fn is_valid_portal(world: &World, pos: BlockPos) -> bool { for dir in BlockDirection::horizontal() { let facing = dir.to_horizontal_facing().unwrap(); let mid_pos = pos.offset_dir(dir.to_offset(), 2); let left_pos = mid_pos.offset_dir(facing.rotate_clockwise().to_offset(), 1); let right_pos = mid_pos.offset_dir(facing.rotate_counter_clockwise().to_offset(), 1); - let (mid_block, mid_state) = world.get_block_and_state_id(&mid_pos).await; - let (left_block, left_state) = world.get_block_and_state_id(&left_pos).await; - let (right_block, right_state) = world.get_block_and_state_id(&right_pos).await; + let (mid_block, mid_state) = world.get_block_and_state_id(&mid_pos); + let (left_block, left_state) = world.get_block_and_state_id(&left_pos); + let (right_block, right_state) = world.get_block_and_state_id(&right_pos); if left_block.id != Self::FRAME_BLOCK_ID || mid_block.id != Self::FRAME_BLOCK_ID diff --git a/pumpkin/src/world/portal/nether.rs b/pumpkin/src/world/portal/nether.rs index e59bd97e7..8d358961d 100644 --- a/pumpkin/src/world/portal/nether.rs +++ b/pumpkin/src/world/portal/nether.rs @@ -8,7 +8,7 @@ use pumpkin_data::{ tag::Taggable, }; use pumpkin_util::math::{boundingbox::EntityDimensions, position::BlockPos, vector3::Vector3}; -use pumpkin_world::world::BlockFlags; +use pumpkin_world::{chunk::ChunkHeightmapType, world::BlockFlags}; use crate::world::World; @@ -142,7 +142,7 @@ impl PortalSearchResult { } } - pub async fn find_open_position( + pub fn find_open_position( &self, world: &Arc, fallback: Vector3, @@ -165,7 +165,7 @@ impl PortalSearchResult { let mut dz = -search_radius; while dz <= search_radius { let test_pos = Vector3::new(check_pos.x + dx, check_pos.y, check_pos.z + dz); - if self.is_position_clear(world, test_pos, dimensions).await { + if Self::is_position_clear(world, test_pos, dimensions) { let dist = dx * dx + dz * dz; if dist < best_dist { best_dist = dist; @@ -180,8 +180,7 @@ impl PortalSearchResult { best_pos } - async fn is_position_clear( - &self, + fn is_position_clear( world: &Arc, center: Vector3, dimensions: &EntityDimensions, @@ -202,7 +201,7 @@ impl PortalSearchResult { for y in min_y..=max_y { for z in min_z..=max_z { let block_pos = BlockPos(Vector3::new(x, y, z)); - let state = world.get_block_state(&block_pos).await; + let state = world.get_block_state(&block_pos); if state.is_solid_block() { return false; } @@ -286,12 +285,12 @@ impl NetherPortal { } } - pub async fn get_new_portal( + pub fn get_new_portal( world: &World, pos: &BlockPos, first_axis: HorizontalAxis, ) -> Option { - if let Some(portal) = Self::get_on_axis(world, pos, first_axis).await + if let Some(portal) = Self::get_on_axis(world, pos, first_axis) && portal.is_valid() && portal.found_portal_blocks == 0 { @@ -302,7 +301,7 @@ impl NetherPortal { } else { HorizontalAxis::X }; - if let Some(portal) = Self::get_on_axis(world, pos, next_axis).await + if let Some(portal) = Self::get_on_axis(world, pos, next_axis) && portal.is_valid() && portal.found_portal_blocks == 0 { @@ -311,20 +310,19 @@ impl NetherPortal { None } - pub async fn get_on_axis(world: &World, pos: &BlockPos, axis: HorizontalAxis) -> Option { + pub fn get_on_axis(world: &World, pos: &BlockPos, axis: HorizontalAxis) -> Option { let direction = if axis == HorizontalAxis::X { BlockDirection::West } else { BlockDirection::South }; - let cornor = Self::get_lower_cornor(world, direction, pos).await?; - let width = Self::get_width(world, &cornor, &direction).await; + let cornor = Self::get_lower_cornor(world, direction, pos)?; + let width = Self::get_width(world, &cornor, direction); if !(Self::MIN_WIDTH..=Self::MAX_WIDTH).contains(&width) { return None; } let mut found_portal_blocks = 0; - let height = - Self::get_height(world, &cornor, &direction, width, &mut found_portal_blocks).await?; + let height = Self::get_height(world, &cornor, direction, width, &mut found_portal_blocks)?; Some(Self { axis, found_portal_blocks, @@ -335,7 +333,7 @@ impl NetherPortal { }) } - async fn get_lower_cornor( + fn get_lower_cornor( world: &World, direction: BlockDirection, pos: &BlockPos, @@ -343,36 +341,36 @@ impl NetherPortal { let limit_y = pos.0.y - Self::MAX_HEIGHT as i32; let mut pos = *pos; while pos.0.y > limit_y { - let (block, state) = world.get_block_and_state(&pos.down()).await; + let (block, state) = world.get_block_and_state(&pos.down()); if !Self::valid_state_inside_portal(block, state) { break; } pos = pos.down(); } let neg_dir = direction.opposite(); - let width = (Self::get_width(world, &pos, &neg_dir).await as i32) - 1; + let width = (Self::get_width(world, &pos, neg_dir) as i32) - 1; if width < 0 { return None; } Some(pos.offset_dir(neg_dir.to_offset(), width)) } - async fn get_width( + fn get_width( world: &World, original_lower_corner: &BlockPos, - negative_dir: &BlockDirection, + negative_dir: BlockDirection, ) -> u32 { let mut lower_corner; for i in 0..=Self::MAX_WIDTH { lower_corner = original_lower_corner.offset_dir(negative_dir.to_offset(), i as i32); - let (block, block_state) = world.get_block_and_state(&lower_corner).await; + let (block, block_state) = world.get_block_and_state(&lower_corner); if !Self::valid_state_inside_portal(block, block_state) { if &Self::FRAME_BLOCK != block { break; } return i; } - let block = world.get_block(&lower_corner.down()).await; + let block = world.get_block(&lower_corner.down()); if &Self::FRAME_BLOCK != block { break; } @@ -380,10 +378,10 @@ impl NetherPortal { 0 } - async fn get_height( + fn get_height( world: &World, lower_corner: &BlockPos, - negative_dir: &BlockDirection, + negative_dir: BlockDirection, width: u32, found_portal_blocks: &mut u32, ) -> Option { @@ -393,21 +391,19 @@ impl NetherPortal { negative_dir, width, found_portal_blocks, - ) - .await; + ); if !(Self::MIN_HEIGHT..=Self::MAX_HEIGHT).contains(&height) || !Self::is_horizontal_frame_valid(world, lower_corner, negative_dir, width, height) - .await { return None; } Some(height) } - async fn get_potential_height( + fn get_potential_height( world: &World, lower_corner: &BlockPos, - negative_dir: &BlockDirection, + negative_dir: BlockDirection, width: u32, found_portal_blocks: &mut u32, ) -> u32 { @@ -415,14 +411,14 @@ impl NetherPortal { let mut pos = lower_corner .offset_dir(BlockDirection::Up.to_offset(), i) .offset_dir(negative_dir.to_offset(), -1); - if world.get_block(&pos).await != &Self::FRAME_BLOCK { + if world.get_block(&pos) != &Self::FRAME_BLOCK { return i as u32; } pos = lower_corner .offset_dir(BlockDirection::Up.to_offset(), i) .offset_dir(negative_dir.to_offset(), width as i32); - if world.get_block(&pos).await != &Self::FRAME_BLOCK { + if world.get_block(&pos) != &Self::FRAME_BLOCK { return i as u32; } @@ -430,7 +426,7 @@ impl NetherPortal { pos = lower_corner .offset_dir(BlockDirection::Up.to_offset(), i) .offset_dir(negative_dir.to_offset(), j as i32); - let (block, block_state) = world.get_block_and_state(&pos).await; + let (block, block_state) = world.get_block_and_state(&pos); if !Self::valid_state_inside_portal(block, block_state) { return i as u32; } @@ -442,10 +438,10 @@ impl NetherPortal { 21 } - async fn is_horizontal_frame_valid( + fn is_horizontal_frame_valid( world: &World, lower_corner: &BlockPos, - dir: &BlockDirection, + dir: BlockDirection, width: u32, height: u32, ) -> bool { @@ -454,7 +450,7 @@ impl NetherPortal { pos = lower_corner .offset_dir(BlockDirection::Up.to_offset(), height as i32) .offset_dir(dir.to_offset(), i as i32); - if &Self::FRAME_BLOCK != world.get_block(&pos).await { + if &Self::FRAME_BLOCK != world.get_block(&pos) { return false; } } @@ -503,12 +499,12 @@ impl NetherPortal { continue; } - if world.get_block(&pos).await != &Block::NETHER_PORTAL { + if world.get_block(&pos) != &Block::NETHER_PORTAL { continue; } for axis in [HorizontalAxis::X, HorizontalAxis::Z] { - if let Some(portal) = Self::get_on_axis(world, &pos, axis).await + if let Some(portal) = Self::get_on_axis(world, &pos, axis) && portal.was_already_valid() { // Use POI position for distance calculation (matches vanilla behavior) @@ -583,19 +579,23 @@ impl NetherPortal { continue; } - let heightmap_y = world.get_motion_blocking_height(check_x, check_z).await; + let heightmap_y = world.get_heightmap_height( + ChunkHeightmapType::MotionBlocking, + check_x, + check_z, + ); let start_y = heightmap_y.min(top_y_limit); let mut y = start_y; while y >= min_y { let pos = BlockPos(Vector3::new(check_x, y, check_z)); - let state = world.get_block_state(&pos).await; + let state = world.get_block_state(&pos); if Self::is_valid_portal_air(state) { let mut bottom_y = y; while bottom_y > min_y { let below = BlockPos(Vector3::new(check_x, bottom_y - 1, check_z)); - let below_state = world.get_block_state(&below).await; + let below_state = world.get_block_state(&below); if !Self::is_valid_portal_air(below_state) { break; } @@ -607,8 +607,7 @@ impl NetherPortal { let floor_pos = BlockPos(Vector3::new(check_x, bottom_y, check_z)); for check_axis in [HorizontalAxis::X, HorizontalAxis::Z] { - if Self::is_valid_portal_pos(world, floor_pos, check_axis, 0).await - { + if Self::is_valid_portal_pos(world, floor_pos, check_axis, 0) { let dist = f64::from(target_pos.0.squared_distance_to( floor_pos.0.x, floor_pos.0.y, @@ -617,11 +616,9 @@ impl NetherPortal { let is_ideal = Self::is_valid_portal_pos(world, floor_pos, check_axis, -1) - .await && Self::is_valid_portal_pos( world, floor_pos, check_axis, 1, - ) - .await; + ); if is_ideal { if ideal_pos.is_none() @@ -672,7 +669,7 @@ impl NetherPortal { state.replaceable() && !state.is_liquid() } - async fn is_valid_portal_pos( + fn is_valid_portal_pos( world: &Arc, floor_pos: BlockPos, axis: HorizontalAxis, @@ -696,7 +693,7 @@ impl NetherPortal { .offset_dir(perpendicular.to_offset(), perpendicular_offset) .offset_dir(BlockDirection::Up.to_offset(), height); - let state = world.get_block_state(&pos).await; + let state = world.get_block_state(&pos); if height < 0 { if !state.is_solid_block() { diff --git a/pumpkin/src/world/scoreboard.rs b/pumpkin/src/world/scoreboard.rs index c44506cfc..682ee216c 100644 --- a/pumpkin/src/world/scoreboard.rs +++ b/pumpkin/src/world/scoreboard.rs @@ -22,7 +22,7 @@ pub struct Scoreboard { } impl Scoreboard { - pub async fn add_objective(&mut self, world: &World, objective: ScoreboardObjective<'static>) { + pub fn add_objective(&mut self, world: &World, objective: ScoreboardObjective<'static>) { if self.objectives.contains_key(objective.name) { warn!( "Tried to create an objective which already exists: {}", @@ -30,26 +30,22 @@ impl Scoreboard { ); return; } - world - .broadcast_packet_all(&CUpdateObjectives::new( - objective.name.to_string(), - pumpkin_protocol::java::client::play::Mode::Add, - objective.display_name.clone(), - objective.render_type, - objective.number_format.clone(), - )) - .await; - world - .broadcast_packet_all(&CDisplayObjective::new( - ScoreboardDisplaySlot::Sidebar, - objective.name.to_string(), - )) - .await; + world.broadcast_packet_all(&CUpdateObjectives::new( + objective.name.to_string(), + pumpkin_protocol::java::client::play::Mode::Add, + objective.display_name.clone(), + objective.render_type, + objective.number_format.clone(), + )); + world.broadcast_packet_all(&CDisplayObjective::new( + ScoreboardDisplaySlot::Sidebar, + objective.name.to_string(), + )); self.objectives .insert(objective.name.to_string(), objective); } - pub async fn remove_objective(&mut self, world: &World, name: &str) { + pub fn remove_objective(&mut self, world: &World, name: &str) { if !self.objectives.contains_key(name) { warn!( "Tried to remove an objective which does not exist: {}", @@ -57,20 +53,18 @@ impl Scoreboard { ); return; } - world - .broadcast_packet_all(&CUpdateObjectives::new( - name.to_string(), - pumpkin_protocol::java::client::play::Mode::Remove, - TextComponent::empty(), - pumpkin_protocol::java::client::play::RenderType::Integer, - None, - )) - .await; + world.broadcast_packet_all(&CUpdateObjectives::new( + name.to_string(), + pumpkin_protocol::java::client::play::Mode::Remove, + TextComponent::empty(), + pumpkin_protocol::java::client::play::RenderType::Integer, + None, + )); self.objectives.remove(name); self.scores.remove(name); } - pub async fn update_score(&mut self, world: &World, score: ScoreboardScore<'static>) { + pub fn update_score(&mut self, world: &World, score: ScoreboardScore<'static>) { if !self.objectives.contains_key(score.objective_name) { warn!( "Tried to place a score into an objective which does not exist: {}", @@ -78,15 +72,13 @@ impl Scoreboard { ); return; } - world - .broadcast_packet_all(&CUpdateScore::new( - score.entity_name.to_string(), - score.objective_name.to_string(), - score.value, - score.display_name.clone(), - score.number_format.clone(), - )) - .await; + world.broadcast_packet_all(&CUpdateScore::new( + score.entity_name.to_string(), + score.objective_name.to_string(), + score.value, + score.display_name.clone(), + score.number_format.clone(), + )); self.scores .entry(score.objective_name.to_string()) @@ -94,20 +86,18 @@ impl Scoreboard { .insert(score.entity_name.to_string(), score); } - pub async fn remove_score(&mut self, world: &World, entity_name: &str, objective_name: &str) { - world - .broadcast_packet_all(&CUpdateScore::new_remove( - entity_name.to_string(), - objective_name.to_string(), - )) - .await; + pub fn remove_score(&mut self, world: &World, entity_name: &str, objective_name: &str) { + world.broadcast_packet_all(&CUpdateScore::new_remove( + entity_name.to_string(), + objective_name.to_string(), + )); if let Some(objective_scores) = self.scores.get_mut(objective_name) { objective_scores.remove(entity_name); } } - pub async fn add_team(&mut self, world: &World, team: Team) { + pub fn add_team(&mut self, world: &World, team: Team) { if self.teams.contains_key(&team.name) { warn!( "Tried to create Team which does already exist, {}", @@ -126,19 +116,17 @@ impl Scoreboard { player_suffix: &team.player_suffix, }; - world - .broadcast_packet_all(&CSetPlayerTeam { - team_name: team.name.clone(), - method: TeamMethod::Create, - parameters: Some(parameters), - players: team.players.clone(), - }) - .await; + world.broadcast_packet_all(&CSetPlayerTeam { + team_name: team.name.clone(), + method: TeamMethod::Create, + parameters: Some(parameters), + players: team.players.clone(), + }); self.teams.insert(team.name.clone(), team); } - pub async fn update_team(&mut self, world: &World, team: Team) { + pub fn update_team(&mut self, world: &World, team: Team) { if !self.teams.contains_key(&team.name) { warn!("Tried to update Team which does not exist, {}", team.name); return; @@ -154,37 +142,33 @@ impl Scoreboard { player_suffix: &team.player_suffix, }; - world - .broadcast_packet_all(&CSetPlayerTeam { - team_name: team.name.clone(), - method: TeamMethod::Update, - parameters: Some(parameters), - players: Vec::new(), - }) - .await; + world.broadcast_packet_all(&CSetPlayerTeam { + team_name: team.name.clone(), + method: TeamMethod::Update, + parameters: Some(parameters), + players: Vec::new(), + }); self.teams.insert(team.name.clone(), team); } - pub async fn remove_team(&mut self, world: &World, name: &str) { + pub fn remove_team(&mut self, world: &World, name: &str) { if !self.teams.contains_key(name) { warn!("Tried to remove Team which does not exist, {}", name); return; } - world - .broadcast_packet_all(&CSetPlayerTeam { - team_name: name.to_string(), - method: TeamMethod::Remove, - parameters: None, - players: Vec::new(), - }) - .await; + world.broadcast_packet_all(&CSetPlayerTeam { + team_name: name.to_string(), + method: TeamMethod::Remove, + parameters: None, + players: Vec::new(), + }); self.teams.remove(name); } - pub async fn add_player_to_team(&mut self, world: &World, team_name: &str, player: String) { + pub fn add_player_to_team(&mut self, world: &World, team_name: &str, player: String) { let Some(team) = self.teams.get_mut(team_name) else { warn!( "Tried to add player to Team which does not exist, {}", @@ -197,19 +181,17 @@ impl Scoreboard { return; } - world - .broadcast_packet_all(&CSetPlayerTeam { - team_name: team_name.to_string(), - method: TeamMethod::AddPlayers, - parameters: None, - players: vec![player.clone()], - }) - .await; + world.broadcast_packet_all(&CSetPlayerTeam { + team_name: team_name.to_string(), + method: TeamMethod::AddPlayers, + parameters: None, + players: vec![player.clone()], + }); team.players.push(player); } - pub async fn remove_player_from_team(&mut self, world: &World, team_name: &str, player: &str) { + pub fn remove_player_from_team(&mut self, world: &World, team_name: &str, player: &str) { let Some(team) = self.teams.get_mut(team_name) else { warn!( "Tried to remove player from Team which does not exist, {}", @@ -222,14 +204,12 @@ impl Scoreboard { return; } - world - .broadcast_packet_all(&CSetPlayerTeam { - team_name: team_name.to_string(), - method: TeamMethod::RemovePlayers, - parameters: None, - players: vec![player.to_string()], - }) - .await; + world.broadcast_packet_all(&CSetPlayerTeam { + team_name: team_name.to_string(), + method: TeamMethod::RemovePlayers, + parameters: None, + players: vec![player.to_string()], + }); team.players.retain(|p| p != player); } diff --git a/pumpkin/src/world/weather.rs b/pumpkin/src/world/weather.rs index f68c2a0d3..da3e06a49 100644 --- a/pumpkin/src/world/weather.rs +++ b/pumpkin/src/world/weather.rs @@ -52,7 +52,7 @@ impl Weather { } } - pub async fn set_weather_parameters( + pub fn set_weather_parameters( &mut self, world: &World, clear_time: i32, @@ -70,18 +70,14 @@ impl Weather { if was_raining != raining { if was_raining { - world - .broadcast_packet_all(&CGameEvent::new(GameEvent::EndRaining, 0.0)) - .await; + world.broadcast_packet_all(&CGameEvent::new(GameEvent::EndRaining, 0.0)); } else { - world - .broadcast_packet_all(&CGameEvent::new(GameEvent::BeginRaining, 0.0)) - .await; + world.broadcast_packet_all(&CGameEvent::new(GameEvent::BeginRaining, 0.0)); } } } - pub async fn tick_weather(&mut self, world: &World) { + pub fn tick_weather(&mut self, world: &World) { if !self.weather_cycle_enabled { self.advance_weather_cycle(); } @@ -104,21 +100,17 @@ impl Weather { // Broadcast level changes if needed if (self.old_rain_level - self.rain_level).abs() > f32::EPSILON { - world - .broadcast_packet_all(&CGameEvent::new( - GameEvent::RainLevelChange, - self.rain_level, - )) - .await; + world.broadcast_packet_all(&CGameEvent::new( + GameEvent::RainLevelChange, + self.rain_level, + )); } if (self.old_thunder_level - self.thunder_level).abs() > f32::EPSILON { - world - .broadcast_packet_all(&CGameEvent::new( - GameEvent::ThunderLevelChange, - self.thunder_level, - )) - .await; + world.broadcast_packet_all(&CGameEvent::new( + GameEvent::ThunderLevelChange, + self.thunder_level, + )); } } @@ -158,8 +150,8 @@ impl Weather { } } - pub async fn reset_weather_cycle(&mut self, world: &World) { - self.set_weather_parameters(world, 0, 0, false, false).await; + pub fn reset_weather_cycle(&mut self, world: &World) { + self.set_weather_parameters(world, 0, 0, false, false); } }