Skip to content

Commit 1393c76

Browse files
committed
Merge from origin/main
2 parents 5d5a0f2 + 6ba2f22 commit 1393c76

File tree

6 files changed

+58
-19
lines changed

6 files changed

+58
-19
lines changed

src/dungeon/room/room.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,8 @@ impl Room {
126126

127127
let mut num: u8 = 0;
128128
for i in 0..4 {
129+
num <<= 1;
129130
num |= doors_opt[i] as u8;
130-
if i < 3 {
131-
num <<= 1;
132-
}
133131
}
134132

135133
// println!("{:04b} {:?}", num, doors_opt);
@@ -316,7 +314,15 @@ impl Room {
316314

317315
world.set_block_at(block, corner.x + bp.x, y, corner.z + bp.z);
318316
}
317+
}
318+
319+
pub fn get_world_pos(&self, room_pos: &BlockPos) -> BlockPos {
320+
let corner = self.get_corner_pos();
319321

322+
room_pos.clone()
323+
.rotate(self.rotation)
324+
.add_x(corner.x)
325+
.add_z(corner.z)
320326
}
321327
}
322328

src/main.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ mod utils;
66
use crate::dungeon::door::DoorType;
77
use crate::dungeon::dungeon::Dungeon;
88
use crate::dungeon::dungeon_state::DungeonState;
9-
use crate::dungeon::room::room_data::RoomData;
9+
use crate::dungeon::room::room_data::{RoomData, RoomType};
1010
use crate::net::internal_packets::{MainThreadMessage, NetworkThreadMessage};
1111
use crate::net::packets::packet_buffer::PacketBuffer;
1212
use crate::net::protocol::play::clientbound;
1313
use crate::net::protocol::play::clientbound::AddEffect;
1414
use crate::net::run_network::run_network_thread;
1515
use crate::net::var_int::VarInt;
16+
use crate::server::block::block_position::BlockPos;
1617
use crate::server::block::blocks::Blocks;
1718
use crate::server::chunk::chunk::Chunk;
1819
use crate::server::chunk::chunk_grid::{for_each_diff, ChunkDiff};
@@ -95,6 +96,8 @@ async fn main() -> Result<()> {
9596
.split("\n")
9697
.collect::<Vec<&str>>();
9798

99+
// Check if a custom dungeon str has been given via cli args
100+
98101
// let dungeon_str = "080809010400100211121300101415161304171418161300191403161304191905160600919999113099910991099909090099999919990929999999099999999009";
99102

100103
let dungeon_str = match args.len() {
@@ -108,10 +111,10 @@ async fn main() -> Result<()> {
108111

109112
let rng_seed: u64 = rand::random(); // using a second seed for rng enables the same layout to have randomized rooms. Maybe should be included in the dungeon seed string?
110113
// let rng_seed: u64 = 12946977352813673410;
111-
114+
112115
println!("Rng Seed: {}", rng_seed);
113116
SeededRng::set_seed(rng_seed);
114-
117+
115118
let dungeon = Dungeon::from_string(dungeon_str, &room_data_storage)?;
116119
let mut server = Server::initialize_with_dungeon(network_tx, dungeon);
117120
server.world.server = &mut server;
@@ -129,8 +132,20 @@ async fn main() -> Result<()> {
129132
let dungeon = &server.dungeon;
130133

131134
for room in &dungeon.rooms {
135+
let room = room.borrow();
132136
// println!("Room: {:?} type={:?} rotation={:?} shape={:?} corner={:?}", room.segments, room.room_data.room_type, room.rotation, room.room_data.shape, room.get_corner_pos());
133-
room.borrow().load_into_world(&mut server.world);
137+
room.load_into_world(&mut server.world);
138+
139+
// Set the spawn point to be inside of the spawn room
140+
if room.room_data.room_type == RoomType::Entrance {
141+
server.world.set_spawn_point(
142+
room.get_world_pos(&BlockPos {
143+
x: 15,
144+
y: 72,
145+
z: 18
146+
})
147+
);
148+
}
134149
}
135150

136151
for door in &dungeon.doors {
@@ -347,7 +362,7 @@ async fn main() -> Result<()> {
347362

348363
sidebar_lines.push_str("§emc.hypixel.net");
349364
player.sidebar.write_update(sidebar_lines, &mut player.packet_buffer);
350-
365+
351366
if player.ticks_existed % 60 == 0 {
352367
player.write_packet(&AddEffect {
353368
entity_id: VarInt(player.entity_id),

src/server/block/block_position.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ impl BlockPos {
9191
z: self.z + other.z
9292
}
9393
}
94+
95+
pub fn subtract(&self, other: &BlockPos) -> Self {
96+
Self {
97+
x: self.x - other.x,
98+
y: self.y - other.y,
99+
z: self.z - other.z
100+
}
101+
}
102+
103+
pub fn as_vec3f(&self) -> DVec3 {
104+
DVec3 {
105+
x: self.x as f64,
106+
y: self.y as f64,
107+
z: self.z as f64
108+
}
109+
}
94110
}
95111

96112
const XZ_BITS: i32 = 26;

src/server/server.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::server::items::Item;
77
use crate::server::player::attribute::{Attribute, AttributeMap, AttributeModifier};
88
use crate::server::player::inventory::ItemSlot;
99
use crate::server::player::player::Player;
10-
use crate::server::utils::dvec3::DVec3;
1110
use crate::server::utils::player_list::footer::footer;
1211
use crate::server::utils::player_list::header::header;
1312
use crate::server::utils::tasks::Task;
@@ -50,17 +49,13 @@ impl Server {
5049
MainThreadMessage::NewPlayer { client_id, profile } => {
5150
println!("added player with id {client_id}");
5251

53-
let spawn_point = DVec3 {
54-
x: 20.0,
55-
y: 69.0,
56-
z: 20.0,
57-
};
52+
let spawn_pos = self.world.spawn_point.as_vec3f();
5853

5954
let mut player = Player::new(
6055
self,
6156
client_id,
6257
profile,
63-
spawn_point,
58+
spawn_pos,
6459
);
6560
println!("player entity id: {}", player.entity_id);
6661

src/server/utils/nbt/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pub mod serialize;
22
pub mod deserialize;
3-
pub mod nbt;
4-
3+
pub mod nbt;

src/server/world.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub struct World {
3636
// pub commands: Vec<Command>
3737

3838
// pub player_info: PlayerList,
39+
pub spawn_point: BlockPos,
3940
}
4041

4142
impl World {
@@ -52,9 +53,12 @@ impl World {
5253
next_entity_id: 1, // might have to start at 1
5354
players: HashMap::new(),
5455
entities: HashMap::new(),
56+
spawn_point: BlockPos {
57+
x: 20,
58+
y: 69,
59+
z: 20,
60+
},
5561
entities_for_removal: VecDeque::new(),
56-
57-
// commands: Vec::new()
5862
}
5963
}
6064

@@ -167,6 +171,10 @@ impl World {
167171
self.chunk_grid.get_block_at(x, y, z)
168172
}
169173

174+
pub fn set_spawn_point(&mut self, new_spawn: BlockPos) {
175+
self.spawn_point = new_spawn;
176+
}
177+
170178
pub fn fill_blocks(&mut self, block: Blocks, start: BlockPos, end: BlockPos) {
171179
iterate_blocks(start, end, |x, y, z| {
172180
self.set_block_at(block, x, y, z)

0 commit comments

Comments
 (0)