mirror of
https://github.com/zyllian/classics.git
synced 2025-01-18 03:32:41 -08:00
make fluids turn each other into stone, fixes #56
This commit is contained in:
parent
56c758f79c
commit
3f5a869f78
2 changed files with 45 additions and 15 deletions
|
@ -7,11 +7,17 @@ use crate::player::PlayerType;
|
|||
/// the level of custom blocks supported by the server
|
||||
pub const CUSTOM_BLOCKS_SUPPORT_LEVEL: u8 = 1;
|
||||
|
||||
pub const ID_STONE: u8 = 0x01;
|
||||
pub const ID_WATER_FLOWING: u8 = 0x08;
|
||||
pub const ID_WATER_STATIONARY: u8 = 0x09;
|
||||
pub const ID_LAVA_FLOWING: u8 = 0x0a;
|
||||
pub const ID_LAVA_STATIONARY: u8 = 0x0b;
|
||||
|
||||
/// information about all blocks implemented
|
||||
pub static BLOCK_INFO: LazyLock<BTreeMap<u8, BlockInfo>> = LazyLock::new(|| {
|
||||
[
|
||||
(0x00, BlockInfo::new("air").block_type(BlockType::NonSolid)),
|
||||
(0x01, BlockInfo::new("stone")),
|
||||
(ID_STONE, BlockInfo::new("stone")),
|
||||
(0x02, BlockInfo::new("grass")),
|
||||
(0x03, BlockInfo::new("dirt")),
|
||||
(0x04, BlockInfo::new("cobblestone")),
|
||||
|
@ -25,7 +31,7 @@ pub static BLOCK_INFO: LazyLock<BTreeMap<u8, BlockInfo>> = LazyLock::new(|| {
|
|||
BlockInfo::new("bedrock").perm(PlayerType::Moderator, PlayerType::Moderator),
|
||||
),
|
||||
(
|
||||
0x08,
|
||||
ID_WATER_FLOWING,
|
||||
BlockInfo::new("water_flowing")
|
||||
.block_type(BlockType::FluidFlowing {
|
||||
stationary: 0x09,
|
||||
|
@ -34,13 +40,13 @@ pub static BLOCK_INFO: LazyLock<BTreeMap<u8, BlockInfo>> = LazyLock::new(|| {
|
|||
.perm(PlayerType::Moderator, PlayerType::Normal),
|
||||
),
|
||||
(
|
||||
0x09,
|
||||
ID_WATER_STATIONARY,
|
||||
BlockInfo::new("water_stationary")
|
||||
.block_type(BlockType::FluidStationary { moving: 0x08 })
|
||||
.perm(PlayerType::Moderator, PlayerType::Normal),
|
||||
),
|
||||
(
|
||||
0x0a,
|
||||
ID_LAVA_FLOWING,
|
||||
BlockInfo::new("lava_flowing")
|
||||
.block_type(BlockType::FluidFlowing {
|
||||
stationary: 0x0b,
|
||||
|
@ -49,7 +55,7 @@ pub static BLOCK_INFO: LazyLock<BTreeMap<u8, BlockInfo>> = LazyLock::new(|| {
|
|||
.perm(PlayerType::Moderator, PlayerType::Normal),
|
||||
),
|
||||
(
|
||||
0x0b,
|
||||
ID_LAVA_STATIONARY,
|
||||
BlockInfo::new("lava_stationary")
|
||||
.block_type(BlockType::FluidStationary { moving: 0x0a })
|
||||
.perm(PlayerType::Moderator, PlayerType::Normal),
|
||||
|
|
|
@ -8,7 +8,10 @@ use tokio::{net::TcpListener, sync::RwLock};
|
|||
use crate::{
|
||||
error::GeneralError,
|
||||
level::{
|
||||
block::{BlockType, BLOCK_INFO},
|
||||
block::{
|
||||
BlockType, BLOCK_INFO, ID_LAVA_FLOWING, ID_LAVA_STATIONARY, ID_STONE, ID_WATER_FLOWING,
|
||||
ID_WATER_STATIONARY,
|
||||
},
|
||||
BlockUpdate, Level,
|
||||
},
|
||||
packet::server::ServerPacket,
|
||||
|
@ -207,18 +210,39 @@ fn tick(data: &mut ServerData, tick: usize) {
|
|||
};
|
||||
level.updates.push(update);
|
||||
for (nx, ny, nz) in neighbors_minus_up(level, x, y, z) {
|
||||
let block_at = BLOCK_INFO
|
||||
.get(&level.get_block(nx, ny, nz))
|
||||
.expect("missing block");
|
||||
let update = if matches!(block_at.block_type, BlockType::NonSolid) {
|
||||
level.awaiting_update.insert(level.index(nx, ny, nz));
|
||||
BlockUpdate {
|
||||
index: level.index(nx, ny, nz),
|
||||
let id = level.get_block(nx, ny, nz);
|
||||
let block_at = BLOCK_INFO.get(&id).expect("missing block");
|
||||
let index = level.index(nx, ny, nz);
|
||||
let update = match block_at.block_type {
|
||||
BlockType::NonSolid => BlockUpdate {
|
||||
index,
|
||||
block: block_id,
|
||||
},
|
||||
BlockType::FluidFlowing { .. } | BlockType::FluidStationary { .. } => {
|
||||
let turn_to_stone = match block_id {
|
||||
ID_WATER_FLOWING | ID_WATER_STATIONARY => {
|
||||
id == ID_LAVA_FLOWING || id == ID_LAVA_STATIONARY
|
||||
}
|
||||
ID_LAVA_FLOWING | ID_LAVA_STATIONARY => {
|
||||
id == ID_WATER_FLOWING || id == ID_WATER_STATIONARY
|
||||
}
|
||||
_ => panic!(
|
||||
"unimplemented fluid interactions for fluid: {}",
|
||||
block.str_id
|
||||
),
|
||||
};
|
||||
if turn_to_stone {
|
||||
BlockUpdate {
|
||||
index,
|
||||
block: ID_STONE,
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
_ => continue,
|
||||
};
|
||||
level.awaiting_update.insert(index);
|
||||
level.updates.push(update);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue