mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-31 08:22:33 +00:00
fix: placing blocks on composters (#1358)
* fix: properly check if composter interaction causes level change * chore: clippy and formatting * refactor: early return instead of handled * fix: composter consumes items
This commit is contained in:
@@ -16,6 +16,7 @@ use pumpkin_data::{
|
||||
item::Item,
|
||||
world::WorldEvent,
|
||||
};
|
||||
use pumpkin_inventory::screen_handler::InventoryPlayer;
|
||||
use pumpkin_macros::pumpkin_block;
|
||||
use pumpkin_util::math::position::BlockPos;
|
||||
use pumpkin_world::{BlockStateId, item::ItemStack, tick::TickPriority, world::BlockFlags};
|
||||
@@ -46,15 +47,29 @@ impl BlockBehaviour for ComposterBlock {
|
||||
let state_id = args.world.get_block_state_id(args.position).await;
|
||||
let props = ComposterLikeProperties::from_state_id(state_id, args.block);
|
||||
let level = props.get_level();
|
||||
|
||||
// Check if the composter is full
|
||||
if level == 8 {
|
||||
self.clear_composter(args.world, args.position, state_id, args.block)
|
||||
.await;
|
||||
return BlockActionResult::Consume;
|
||||
}
|
||||
if level < 7
|
||||
&& let Some(chance) =
|
||||
get_composter_increase_chance_from_item_id(args.item_stack.lock().await.item.id)
|
||||
&& (level == 0 || rand::rng().random_bool(f64::from(chance)))
|
||||
{
|
||||
|
||||
let mut item_stack = args.item_stack.lock().await;
|
||||
let item_id = item_stack.item.id;
|
||||
|
||||
// Check if the item is consumable by the composter
|
||||
let Some(chance) = get_composter_increase_chance_from_item_id(item_id) else {
|
||||
return BlockActionResult::Pass;
|
||||
};
|
||||
|
||||
// Consume one item from the stack (if in survival mode)
|
||||
if !args.player.has_infinite_materials() {
|
||||
item_stack.decrement(1);
|
||||
}
|
||||
|
||||
// Determine if the composter level should increase
|
||||
if level < 7 && (level == 0 || rand::rng().random_bool(f64::from(chance))) {
|
||||
self.update_level_composter(
|
||||
args.world,
|
||||
args.position,
|
||||
@@ -67,6 +82,8 @@ impl BlockBehaviour for ComposterBlock {
|
||||
.sync_world_event(WorldEvent::ComposterUsed, *args.position, 1)
|
||||
.await;
|
||||
}
|
||||
|
||||
// Consume the item
|
||||
BlockActionResult::Consume
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user