Skip to content

Commit 6ba2f22

Browse files
authored
Merge pull request #8 from Big-Dungeons/bloom
Bloom
2 parents b352f82 + 6bd0d0a commit 6ba2f22

File tree

7 files changed

+84
-13
lines changed

7 files changed

+84
-13
lines changed

src/dungeon/room/room.rs

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

112112
let mut num: u8 = 0;
113113
for i in 0..4 {
114+
num <<= 1;
114115
num |= doors_opt[i] as u8;
115-
if i < 3 {
116-
num <<= 1;
117-
}
118116
}
119117

120118
// println!("{:04b} {:?}", num, doors_opt);
@@ -307,7 +305,15 @@ impl Room {
307305

308306
world.set_block_at(block, corner.x + bp.x, y, corner.z + bp.z);
309307
}
308+
}
309+
310+
pub fn get_world_pos(&self, room_pos: &BlockPos) -> BlockPos {
311+
let corner = self.get_corner_pos();
310312

313+
room_pos.clone()
314+
.rotate(self.rotation)
315+
.add_x(corner.x)
316+
.add_z(corner.z)
311317
}
312318
}
313319

src/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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::dungeon::room::secrets;
1111
use crate::dungeon::room::secrets::SecretType::WitherEssence;
1212
use crate::dungeon::room::secrets::{DungeonSecret, SecretType};
@@ -97,7 +97,8 @@ async fn main() -> Result<()> {
9797
let dungeon_strings = include_str!("dungeon_storage/dungeons.txt")
9898
.split("\n")
9999
.collect::<Vec<&str>>();
100-
100+
101+
// Check if a custom dungeon str has been given via cli args
101102
let dungeon_str = match args.len() {
102103
0..=1 => {
103104
let mut rng = rand::rng();
@@ -127,6 +128,17 @@ async fn main() -> Result<()> {
127128
for room in &dungeon.rooms {
128129
// println!("Room: {:?} type={:?} rotation={:?} shape={:?} corner={:?}", room.segments, room.room_data.room_type, room.rotation, room.room_data.shape, room.get_corner_pos());
129130
room.load_into_world(&mut server.world);
131+
132+
// Set the spawn point to be inside of the spawn room
133+
if room.room_data.room_type == RoomType::Entrance {
134+
server.world.set_spawn_point(
135+
room.get_world_pos(&BlockPos {
136+
x: 15,
137+
y: 72,
138+
z: 18
139+
})
140+
);
141+
}
130142
}
131143

132144
for door in &dungeon.doors {

src/server/block/block_pos.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ impl BlockPos {
8989
z: self.z + other.z
9090
}
9191
}
92+
93+
pub fn subtract(&self, other: &BlockPos) -> Self {
94+
Self {
95+
x: self.x - other.x,
96+
y: self.y - other.y,
97+
z: self.z - other.z
98+
}
99+
}
100+
101+
pub fn as_vec3f(&self) -> DVec3 {
102+
DVec3 {
103+
x: self.x as f64,
104+
y: self.y as f64,
105+
z: self.z as f64
106+
}
107+
}
92108
}
93109

94110
impl PacketWrite for BlockPos {

src/server/items/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub enum Item {
1818
AspectOfTheVoid,
1919
DiamondPickaxe,
2020
SpiritSceptre,
21+
SpeedBoots,
2122
}
2223

2324
impl Item {
@@ -122,6 +123,30 @@ impl Item {
122123
metadata: 0,
123124
tag_compound: None,
124125
},
126+
Item::SpeedBoots => ItemStack {
127+
item: 301,
128+
stack_size: 1,
129+
metadata: 0,
130+
tag_compound: Some(NBT::with_nodes(vec![
131+
NBT::compound("display", vec![
132+
NBT::int("color", 0),
133+
NBT::string("Name", "§bSpeedy Boots"),
134+
NBT::list_from_string("Lore", indoc! {r#"
135+
Why don't these work ):
136+
"#}),
137+
]),
138+
NBT::list("AttributeModifiers", TAG_COMPOUND_ID, vec![
139+
NBTNode::Compound(vec![
140+
NBT::string("Name", "generic.movementSpeed"),
141+
NBT::string("AttributeName", "generic.movementSpeed"),
142+
NBT::double("Amount", 0.4),
143+
NBT::int("Operation", 0),
144+
NBT::long("UUIDLeast", 121742),
145+
NBT::long("UUIDMost", 38678),
146+
]),
147+
])
148+
])),
149+
}
125150
};
126151
if let Some(ref mut tag) = stack.tag_compound {
127152
tag.nodes.push(NBT::byte("Unbreakable", 1));

src/server/server.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ impl Server {
4444
MainThreadMessage::NewPlayer { client_id, username } => {
4545
println!("added player with id {client_id}");
4646

47-
let spawn_point = DVec3 {
48-
x: 20.0,
49-
y: 69.0,
50-
z: 20.0,
51-
};
47+
let spawn_pos = self.world.spawn_point.as_vec3f();
5248

5349
let mut player = Player::new(
5450
self,
@@ -57,7 +53,7 @@ impl Server {
5753
GameProfile {
5854
username
5955
},
60-
spawn_point,
56+
spawn_pos,
6157
);
6258
println!("player entity id: {}", player.entity_id);
6359

src/server/utils/nbt/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ impl NBT {
5656
pub fn long(name: &str, value: i64) -> (String, NBTNode) {
5757
(name.to_string(), NBTNode::Long(value))
5858
}
59+
60+
pub fn float(name: &str, value: f32) -> (String, NBTNode) {
61+
(name.to_string(), NBTNode::Float(value))
62+
}
63+
64+
pub fn double(name: &str, value: f64) -> (String, NBTNode) {
65+
(name.to_string(), NBTNode::Double(value))
66+
}
5967

6068
/// takes a string,
6169
/// splits it into lines and creates a list nbt node representing strings.

src/server/world.rs

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

3939
// pub player_info: PlayerList,
40+
pub spawn_point: BlockPos,
4041
}
4142

4243
impl World {
@@ -53,9 +54,12 @@ impl World {
5354
next_entity_id: 1, // might have to start at 1
5455
players: HashMap::new(),
5556
entities: HashMap::new(),
57+
spawn_point: BlockPos {
58+
x: 20,
59+
y: 69,
60+
z: 20,
61+
},
5662
entities_for_removal: VecDeque::new(),
57-
58-
// commands: Vec::new()
5963
}
6064
}
6165

@@ -147,6 +151,10 @@ impl World {
147151
self.chunk_grid.get_block_at(x, y, z)
148152
}
149153

154+
pub fn set_spawn_point(&mut self, new_spawn: BlockPos) {
155+
self.spawn_point = new_spawn;
156+
}
157+
150158
pub fn fill_blocks(&mut self, block: Blocks, start: BlockPos, end: BlockPos) {
151159
// should probably use a multi block change instead,
152160
// however it only applies to one chunk,

0 commit comments

Comments
 (0)