fix stop command
This commit is contained in:
parent
6c4eb88dd3
commit
f63034e3a1
@ -1,9 +1 @@
|
||||
pub mod entity_registry;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum FacingDirection {
|
||||
North,
|
||||
South,
|
||||
East,
|
||||
West,
|
||||
}
|
||||
|
||||
@ -88,11 +88,9 @@ impl Level {
|
||||
|
||||
pub async fn save(&self) {
|
||||
log::info!("Saving level...");
|
||||
// lets first save all chunks
|
||||
for chunk in self.loaded_chunks.iter() {
|
||||
let chunk = chunk.read().await;
|
||||
self.clean_chunk(&chunk.position).await;
|
||||
}
|
||||
|
||||
// chunks are automatically saved when all players get removed
|
||||
|
||||
// then lets save the world info
|
||||
self.world_info_writer
|
||||
.write_world_info(self.level_info.clone(), &self.level_folder)
|
||||
|
||||
@ -3,12 +3,9 @@ use std::{collections::HashMap, sync::Arc};
|
||||
use async_trait::async_trait;
|
||||
use pumpkin_protocol::server::play::SUseItemOn;
|
||||
use pumpkin_util::math::position::BlockPos;
|
||||
use pumpkin_world::{
|
||||
block::{
|
||||
block_registry::{Block, BLOCKS},
|
||||
BlockFace,
|
||||
},
|
||||
entity::FacingDirection,
|
||||
use pumpkin_world::block::{
|
||||
block_registry::{Block, BLOCKS},
|
||||
BlockFace,
|
||||
};
|
||||
|
||||
use crate::world::World;
|
||||
@ -24,7 +21,7 @@ pub trait BlockBehavior: Send + Sync {
|
||||
face: &BlockFace,
|
||||
block_pos: &BlockPos,
|
||||
use_item_on: &SUseItemOn,
|
||||
player_direction: &FacingDirection,
|
||||
player_direction: &Direction,
|
||||
) -> u16;
|
||||
async fn is_updateable(
|
||||
&self,
|
||||
@ -39,6 +36,7 @@ pub trait BlockBehavior: Send + Sync {
|
||||
pub enum BlockProperty {
|
||||
Waterlogged(bool),
|
||||
Facing(Direction),
|
||||
Powered(bool),
|
||||
SlabType(SlabPosition),
|
||||
StairShape(StairShape),
|
||||
Half(BlockHalf), // Add other properties as needed
|
||||
@ -66,7 +64,7 @@ pub enum StairShape {
|
||||
OuterRight,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Direction {
|
||||
North,
|
||||
South,
|
||||
@ -110,7 +108,7 @@ impl BlockPropertiesManager {
|
||||
face: &BlockFace,
|
||||
block_pos: &BlockPos,
|
||||
use_item_on: &SUseItemOn,
|
||||
player_direction: &FacingDirection,
|
||||
player_direction: &Direction,
|
||||
) -> u16 {
|
||||
if let Some(behaviour) = self.properties_registry.get(&block.id) {
|
||||
return behaviour
|
||||
|
||||
@ -5,11 +5,11 @@ use std::{
|
||||
|
||||
use pumpkin_protocol::server::play::SUseItemOn;
|
||||
use pumpkin_util::math::position::BlockPos;
|
||||
use pumpkin_world::block::block_registry::Block;
|
||||
use pumpkin_world::block::{block_registry::Property, BlockFace};
|
||||
use pumpkin_world::{block::block_registry::Block, entity::FacingDirection};
|
||||
|
||||
use crate::{
|
||||
block::block_properties_manager::{get_property_key, BlockBehavior, BlockProperty},
|
||||
block::block_properties_manager::{get_property_key, BlockBehavior, BlockProperty, Direction},
|
||||
world::World,
|
||||
};
|
||||
|
||||
@ -75,21 +75,21 @@ impl SlabBehavior {
|
||||
pub fn evalute_property_type(
|
||||
block: &Block,
|
||||
clicked_block: &Block,
|
||||
face: BlockFace,
|
||||
face: &BlockFace,
|
||||
use_item_on: &SUseItemOn,
|
||||
) -> String {
|
||||
if block.id == clicked_block.id && face == BlockFace::Top {
|
||||
if block.id == clicked_block.id && face == &BlockFace::Top {
|
||||
return format!("{}{}", "type", "double");
|
||||
}
|
||||
|
||||
if face == BlockFace::Top {
|
||||
if face == &BlockFace::Top {
|
||||
return format!("{}{}", "type", "bottom");
|
||||
}
|
||||
|
||||
if face == BlockFace::North
|
||||
|| face == BlockFace::South
|
||||
|| face == BlockFace::West
|
||||
|| face == BlockFace::East
|
||||
if face == &BlockFace::North
|
||||
|| face == &BlockFace::South
|
||||
|| face == &BlockFace::West
|
||||
|| face == &BlockFace::East
|
||||
{
|
||||
let y_pos = use_item_on.cursor_pos.y;
|
||||
if y_pos > 0.5 {
|
||||
@ -119,7 +119,7 @@ impl BlockBehavior for SlabBehavior {
|
||||
face: &BlockFace,
|
||||
block_pos: &BlockPos,
|
||||
use_item_on: &SUseItemOn,
|
||||
_player_direction: &FacingDirection,
|
||||
_player_direction: &Direction,
|
||||
) -> u16 {
|
||||
let clicked_block = world.get_block(block_pos).await.unwrap();
|
||||
let mut hmap_key: Vec<String> = Vec::with_capacity(block.properties.len());
|
||||
@ -129,7 +129,7 @@ impl BlockBehavior for SlabBehavior {
|
||||
let state = match get_property_key(property.name.as_str()).expect("Property not found")
|
||||
{
|
||||
BlockProperty::SlabType(_) => {
|
||||
Self::evalute_property_type(block, clicked_block, *face, use_item_on)
|
||||
Self::evalute_property_type(block, clicked_block, face, use_item_on)
|
||||
}
|
||||
BlockProperty::Waterlogged(false) => Self::evalute_property_waterlogged(block),
|
||||
_ => panic!("Property not found"),
|
||||
|
||||
@ -6,13 +6,10 @@ use std::{
|
||||
use pumpkin_protocol::server::play::SUseItemOn;
|
||||
use pumpkin_util::math::{position::BlockPos, vector3::Vector3};
|
||||
use pumpkin_world::block::block_registry::Block;
|
||||
use pumpkin_world::{
|
||||
block::{block_registry::Property, BlockFace},
|
||||
entity::FacingDirection,
|
||||
};
|
||||
use pumpkin_world::block::{block_registry::Property, BlockFace};
|
||||
|
||||
use crate::{
|
||||
block::block_properties_manager::{get_property_key, BlockBehavior, BlockProperty},
|
||||
block::block_properties_manager::{get_property_key, BlockBehavior, BlockProperty, Direction},
|
||||
world::World,
|
||||
};
|
||||
|
||||
@ -85,11 +82,11 @@ impl StairBehavior {
|
||||
}
|
||||
|
||||
fn calculate_positions(
|
||||
player_direction: FacingDirection,
|
||||
block_pos: BlockPos,
|
||||
player_direction: &Direction,
|
||||
block_pos: &BlockPos,
|
||||
) -> (BlockPos, BlockPos) {
|
||||
match player_direction {
|
||||
FacingDirection::North => (
|
||||
Direction::North => (
|
||||
BlockPos(Vector3::new(
|
||||
block_pos.0.x,
|
||||
block_pos.0.y,
|
||||
@ -101,7 +98,7 @@ impl StairBehavior {
|
||||
block_pos.0.z + 1,
|
||||
)),
|
||||
),
|
||||
FacingDirection::South => (
|
||||
Direction::South => (
|
||||
BlockPos(Vector3::new(
|
||||
block_pos.0.x,
|
||||
block_pos.0.y,
|
||||
@ -113,7 +110,7 @@ impl StairBehavior {
|
||||
block_pos.0.z - 1,
|
||||
)),
|
||||
),
|
||||
FacingDirection::East => (
|
||||
Direction::East => (
|
||||
BlockPos(Vector3::new(
|
||||
block_pos.0.x + 1,
|
||||
block_pos.0.y,
|
||||
@ -125,7 +122,7 @@ impl StairBehavior {
|
||||
block_pos.0.z,
|
||||
)),
|
||||
),
|
||||
FacingDirection::West => (
|
||||
Direction::West => (
|
||||
BlockPos(Vector3::new(
|
||||
block_pos.0.x - 1,
|
||||
block_pos.0.y,
|
||||
@ -145,11 +142,11 @@ impl StairBehavior {
|
||||
block_pos: &BlockPos,
|
||||
face: &BlockFace,
|
||||
use_item_on: &SUseItemOn,
|
||||
player_direction: &FacingDirection,
|
||||
player_direction: &Direction,
|
||||
) -> String {
|
||||
let block_half = Self::evaluate_property_half(*face, use_item_on);
|
||||
let block_half = Self::evaluate_property_half(face, use_item_on);
|
||||
let (front_block_pos, back_block_pos) =
|
||||
Self::calculate_positions(*player_direction, *block_pos);
|
||||
Self::calculate_positions(player_direction, block_pos);
|
||||
|
||||
let front_block_and_state = world.get_block_and_block_state(&front_block_pos).await;
|
||||
let back_block_and_state = world.get_block_and_block_state(&back_block_pos).await;
|
||||
@ -169,18 +166,18 @@ impl StairBehavior {
|
||||
let is_facing_south = properties.contains(&"facingsouth".to_owned());
|
||||
let is_facing_east = properties.contains(&"facingeast".to_owned());
|
||||
|
||||
if (is_facing_north && *player_direction == FacingDirection::West)
|
||||
|| (is_facing_west && *player_direction == FacingDirection::South)
|
||||
|| (is_facing_south && *player_direction == FacingDirection::East)
|
||||
|| (is_facing_east && *player_direction == FacingDirection::North)
|
||||
if (is_facing_north && *player_direction == Direction::West)
|
||||
|| (is_facing_west && *player_direction == Direction::South)
|
||||
|| (is_facing_south && *player_direction == Direction::East)
|
||||
|| (is_facing_east && *player_direction == Direction::North)
|
||||
{
|
||||
return "shapeouter_right".to_owned();
|
||||
}
|
||||
|
||||
if (is_facing_north && *player_direction == FacingDirection::East)
|
||||
|| (is_facing_west && *player_direction == FacingDirection::North)
|
||||
|| (is_facing_south && *player_direction == FacingDirection::West)
|
||||
|| (is_facing_east && *player_direction == FacingDirection::South)
|
||||
if (is_facing_north && *player_direction == Direction::East)
|
||||
|| (is_facing_west && *player_direction == Direction::North)
|
||||
|| (is_facing_south && *player_direction == Direction::West)
|
||||
|| (is_facing_east && *player_direction == Direction::South)
|
||||
{
|
||||
return "shapeouter_left".to_owned();
|
||||
}
|
||||
@ -210,18 +207,18 @@ impl StairBehavior {
|
||||
let is_facing_south = properties.contains(&"facingsouth".to_owned());
|
||||
let is_facing_east = properties.contains(&"facingeast".to_owned());
|
||||
|
||||
if (is_facing_north && *player_direction == FacingDirection::West)
|
||||
|| (is_facing_west && *player_direction == FacingDirection::South)
|
||||
|| (is_facing_south && *player_direction == FacingDirection::East)
|
||||
|| (is_facing_east && *player_direction == FacingDirection::North)
|
||||
if (is_facing_north && *player_direction == Direction::West)
|
||||
|| (is_facing_west && *player_direction == Direction::South)
|
||||
|| (is_facing_south && *player_direction == Direction::East)
|
||||
|| (is_facing_east && *player_direction == Direction::North)
|
||||
{
|
||||
return "shapeinner_right".to_owned();
|
||||
}
|
||||
|
||||
if (is_facing_north && *player_direction == FacingDirection::East)
|
||||
|| (is_facing_west && *player_direction == FacingDirection::North)
|
||||
|| (is_facing_south && *player_direction == FacingDirection::West)
|
||||
|| (is_facing_east && *player_direction == FacingDirection::South)
|
||||
if (is_facing_north && *player_direction == Direction::East)
|
||||
|| (is_facing_west && *player_direction == Direction::North)
|
||||
|| (is_facing_south && *player_direction == Direction::West)
|
||||
|| (is_facing_east && *player_direction == Direction::South)
|
||||
{
|
||||
return "shapeinner_left".to_owned();
|
||||
}
|
||||
@ -250,24 +247,24 @@ impl StairBehavior {
|
||||
format!("{}{}", "waterlogged", "false")
|
||||
}
|
||||
|
||||
pub fn evaluate_property_facing(face: BlockFace, player_direction: FacingDirection) -> String {
|
||||
pub fn evaluate_property_facing(face: &BlockFace, player_direction: &Direction) -> String {
|
||||
let facing = match face {
|
||||
BlockFace::North => "south",
|
||||
BlockFace::South => "north",
|
||||
BlockFace::East => "west",
|
||||
BlockFace::West => "east",
|
||||
BlockFace::Top | BlockFace::Bottom => match player_direction {
|
||||
FacingDirection::North => "north",
|
||||
FacingDirection::South => "south",
|
||||
FacingDirection::East => "east",
|
||||
FacingDirection::West => "west",
|
||||
Direction::North => "north",
|
||||
Direction::South => "south",
|
||||
Direction::East => "east",
|
||||
Direction::West => "west",
|
||||
},
|
||||
};
|
||||
|
||||
format!("facing{facing}")
|
||||
}
|
||||
|
||||
pub fn evaluate_property_half(face: BlockFace, use_item_on: &SUseItemOn) -> String {
|
||||
pub fn evaluate_property_half(face: &BlockFace, use_item_on: &SUseItemOn) -> String {
|
||||
match face {
|
||||
BlockFace::Top => format!("{}{}", "half", "bottom"),
|
||||
BlockFace::Bottom => format!("{}{}", "half", "top"),
|
||||
@ -292,7 +289,7 @@ impl BlockBehavior for StairBehavior {
|
||||
face: &BlockFace,
|
||||
block_pos: &BlockPos,
|
||||
use_item_on: &SUseItemOn,
|
||||
player_direction: &FacingDirection,
|
||||
player_direction: &Direction,
|
||||
) -> u16 {
|
||||
let mut hmap_key: Vec<String> = Vec::with_capacity(block.properties.len());
|
||||
let stair_behaviour = Self::get();
|
||||
@ -300,10 +297,8 @@ impl BlockBehavior for StairBehavior {
|
||||
for property in &block.properties {
|
||||
let state = match get_property_key(property.name.as_str()).expect("Property not found")
|
||||
{
|
||||
BlockProperty::Facing(_) => {
|
||||
Self::evaluate_property_facing(*face, *player_direction)
|
||||
}
|
||||
BlockProperty::Half(_) => Self::evaluate_property_half(*face, use_item_on),
|
||||
BlockProperty::Facing(_) => Self::evaluate_property_facing(face, player_direction),
|
||||
BlockProperty::Half(_) => Self::evaluate_property_half(face, use_item_on),
|
||||
BlockProperty::StairShape(_) => {
|
||||
Self::evaluate_property_shape(
|
||||
world,
|
||||
@ -315,7 +310,7 @@ impl BlockBehavior for StairBehavior {
|
||||
.await
|
||||
}
|
||||
BlockProperty::Waterlogged(_) => Self::evaluate_property_waterlogged(block),
|
||||
BlockProperty::SlabType(_) => panic!("SlabType BlockProperty invalid for Stairs"),
|
||||
_ => panic!("BlockProperty invalid for Stairs"),
|
||||
};
|
||||
hmap_key.push(state);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ use std::num::NonZeroU8;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::block::block_manager::BlockActionResult;
|
||||
use crate::block::block_properties_manager::Direction;
|
||||
use crate::entity::mob;
|
||||
use crate::net::PlayerConfig;
|
||||
use crate::{
|
||||
@ -43,7 +44,6 @@ use pumpkin_util::{
|
||||
};
|
||||
use pumpkin_world::block::block_registry::get_block_collision_shapes;
|
||||
use pumpkin_world::block::block_registry::Block;
|
||||
use pumpkin_world::entity::FacingDirection;
|
||||
use pumpkin_world::item::item_registry::get_item_by_id;
|
||||
use pumpkin_world::item::ItemStack;
|
||||
use pumpkin_world::{
|
||||
@ -1145,15 +1145,15 @@ impl Player {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn get_player_direction(&self) -> FacingDirection {
|
||||
fn get_player_direction(&self) -> Direction {
|
||||
let adjusted_yaw = (self.living_entity.entity.yaw.load() % 360.0 + 360.0) % 360.0; // Normalize yaw to [0, 360)
|
||||
|
||||
match adjusted_yaw {
|
||||
0.0..=45.0 | 315.0..=360.0 => FacingDirection::South,
|
||||
45.0..=135.0 => FacingDirection::West,
|
||||
135.0..=225.0 => FacingDirection::North,
|
||||
225.0..=315.0 => FacingDirection::East,
|
||||
_ => FacingDirection::South, // Default case, should not occur
|
||||
0.0..=45.0 | 315.0..=360.0 => Direction::South,
|
||||
45.0..=135.0 => Direction::West,
|
||||
135.0..=225.0 => Direction::North,
|
||||
225.0..=315.0 => Direction::East,
|
||||
_ => Direction::South, // Default case, should not occur
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user