Skip to content

Commit e6e378e

Browse files
committed
ice fill puzzle
1 parent 929a905 commit e6e378e

File tree

22 files changed

+658
-244
lines changed

22 files changed

+658
-244
lines changed

server/src/constants/sounds.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@ use bytes::BytesMut;
33

44
#[derive(Debug, Copy, Clone)]
55
pub enum Sound {
6+
RandomWoodClick,
67
EnderDragonHit,
78
RandomExplode,
89
GhastFireball,
910
ZombieRemedy,
1011
FireIgnite,
1112
DonkeyHit,
13+
NoteHarp,
1214
NoteHat,
1315
}
1416

1517
impl Sound {
1618
fn get_sound(&self) -> &'static str {
1719
match self {
20+
Sound::RandomWoodClick => "random.wood_click",
1821
Sound::EnderDragonHit => "mob.enderdragon.hit",
1922
Sound::RandomExplode => "random.explode",
2023
Sound::GhastFireball => "mob.ghast.fireball",
2124
Sound::ZombieRemedy => "mob.zombie.remedy",
2225
Sound::FireIgnite => "fire.ignite",
2326
Sound::DonkeyHit => "mob.horse.donkey.hit",
27+
Sound::NoteHarp => "note.harp",
2428
Sound::NoteHat => "note.hat",
2529
}
2630
}

server/src/entity/components/entity_appearance.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::entity::entity_metadata::{EntityMetadata, PlayerMetadata};
44
use crate::network::binary::var_int::VarInt;
55
use crate::network::packets::packet_buffer::PacketBuffer;
66
use crate::network::protocol::play::clientbound::{DestroyEntites, EntityRotate, EntityTeleport, EntityYawRotate, PlayerData, PlayerListItem, SpawnMob, SpawnPlayer};
7-
use crate::{GameProfile, GameProfileProperty, Player, WorldExtension};
7+
use crate::{GameProfile, GameProfileProperty, Player, World, WorldExtension};
88
use bevy_ecs::component::Mutable;
99
use bevy_ecs::prelude::Component;
1010
use fstr::FString;
@@ -13,6 +13,8 @@ use uuid::Uuid;
1313

1414
pub trait EntityAppearance<W: WorldExtension + 'static>: Component<Mutability = Mutable> + Sized {
1515

16+
fn init(&self, _world: &mut World<W>) {}
17+
1618
fn enter_player_view(&self, entity: &MinecraftEntity<W>, player: &mut Player<W::Player>);
1719

1820
fn leave_player_view(&self, entity: &MinecraftEntity<W>, player: &mut Player<W::Player>);
@@ -162,4 +164,17 @@ fn update_position<W : WorldExtension>(entity: &MinecraftEntity<W>, buffer: &mut
162164
entity_id: entity.id,
163165
yaw: entity.yaw,
164166
});
167+
}
168+
169+
#[derive(Component)]
170+
pub struct NoAppearance;
171+
172+
impl<W: WorldExtension + 'static> EntityAppearance<W> for NoAppearance {
173+
fn enter_player_view(&self, _: &MinecraftEntity<W>, _: &mut Player<W::Player>) {}
174+
175+
fn leave_player_view(&self, _: &MinecraftEntity<W>, _: &mut Player<W::Player>) {}
176+
177+
fn update_position(&self, _: &MinecraftEntity<W>, _: &mut PacketBuffer) {}
178+
179+
fn destroy(&self, _: &MinecraftEntity<W>, _: &mut DestroyEntites) {}
165180
}

server/src/entity/entity_metadata.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,8 @@ entity_metadata_serializable! {
2929
13 => pub is_villager: bool = false,
3030
},
3131
Bat {
32+
0 => pub flags: u8 = 0,
3233
16 => pub hanging: bool = false,
3334
}
3435
}
35-
}
36-
37-
38-
// entity_metadata_serializable! {
39-
// pub enum ObjectMetadata {
40-
// FallingBlock {
41-
//
42-
// }
43-
// }
44-
// }
36+
}

server/src/network/packets/packet_serialize.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,18 @@ impl PacketSerializable for f64 {
118118
}
119119
}
120120

121-
impl PacketSerializable for &[u8] {
121+
impl<T: PacketSerializable> PacketSerializable for &[T] {
122122
fn write_size(&self) -> usize {
123-
self.len()
123+
let mut write_size = 0;
124+
for entry in self.iter() {
125+
write_size += entry.write_size()
126+
}
127+
write_size
124128
}
125129
fn write(&self, buf: &mut BytesMut) {
126-
buf.put_slice(self)
130+
for entry in self.iter() {
131+
entry.write(buf)
132+
}
127133
}
128134
}
129135

server/src/network/protocol/play/clientbound.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ register_packets! {
6161
// BlockBreakAnimation = 0x25;
6262
// ChunkDataBulk = 0x26;
6363
// Explosion = 0x27;
64-
// Effect = 0x28;
64+
Effect = 0x28;
6565
SoundEffect = 0x29;
66-
Particles = 0x2a;
66+
Particles<'_> = 0x2a;
6767
// ChangeGameState = 0x2b;
6868
// SpawnGlobalEntity = 0x2c;
6969
OpenWindow = 0x2d;
@@ -367,6 +367,15 @@ packet_serializable! {
367367
}
368368
}
369369

370+
packet_serializable! {
371+
pub struct Effect {
372+
pub effect_id: i32,
373+
pub position: IVec3 => &BlockPosition(self.position),
374+
pub data: i32,
375+
pub disable_relative_volume: bool,
376+
}
377+
}
378+
370379
packet_serializable! {
371380
pub struct SoundEffect {
372381
pub sound: Sound,
@@ -379,15 +388,14 @@ packet_serializable! {
379388
}
380389

381390
packet_serializable! {
382-
pub struct Particles {
391+
pub struct Particles<'a> {
383392
pub particle: Particle,
384393
pub long_distance: bool,
385394
pub position: Vec3,
386395
pub offset: Vec3,
387396
pub speed: f32,
388397
pub count: i32,
389-
// maybe figure out args,
390-
// not sure if we'll ever need them
398+
pub arguments: &'a [VarInt]
391399
}
392400
}
393401

server/src/types/aabb.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ impl AABB {
1919
max,
2020
}
2121
}
22+
23+
pub fn new_safe(a: DVec3, b: DVec3) -> Self {
24+
Self {
25+
min: a.min(b),
26+
max: a.max(b),
27+
}
28+
}
2229

2330
pub const fn intersects(&self, other: &AABB) -> bool {
2431
self.min.x <= other.max.x && self.max.x >= other.min.x &&

server/src/world/world.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ impl<W: WorldExtension + 'static> World<W> {
6565
pub fn write_global_packet<P : IdentifiedPacket + PacketSerializable>(&mut self, packet: &P) {
6666
self.global_packet_buffer.write_packet(packet)
6767
}
68+
69+
pub fn write_local_packet<P : IdentifiedPacket + PacketSerializable>(
70+
&mut self,
71+
position: DVec3,
72+
packet: &P,
73+
) {
74+
let chunk_x = (position.x.floor() as i32) >> 4;
75+
let chunk_z = (position.z.floor() as i32) >> 4;
76+
77+
if let Some(chunk) = self.chunk_grid.get_chunk_mut(chunk_x, chunk_z) {
78+
chunk.packet_buffer.write_packet(packet)
79+
}
80+
}
6881

6982
pub fn spawn_player(
7083
&mut self,
@@ -158,7 +171,9 @@ impl<W: WorldExtension + 'static> World<W> {
158171
yaw,
159172
pitch
160173
);
161-
174+
175+
appearance.init(self);
176+
162177
// kinda scuffed ngl
163178
self.entities.register_appearance_update::<T>();
164179

@@ -184,6 +199,17 @@ impl<W: WorldExtension + 'static> World<W> {
184199
}
185200

186201
pub fn spawn_particle(&mut self, particle: Particle, position: Vec3, offset: Vec3, count: i32) {
202+
self.spawn_particle_with_args(particle, position, offset, count, Vec::new());
203+
}
204+
205+
pub fn spawn_particle_with_args(
206+
&mut self,
207+
particle: Particle,
208+
position: Vec3,
209+
offset: Vec3,
210+
count: i32,
211+
arguments: Vec<VarInt>
212+
) {
187213
let chunk_x = (position.x.floor() as i32) >> 4;
188214
let chunk_z = (position.z.floor() as i32) >> 4;
189215

@@ -195,24 +221,20 @@ impl<W: WorldExtension + 'static> World<W> {
195221
offset,
196222
speed: 0.0,
197223
count,
224+
arguments: &arguments
198225
})
199226
}
200227
}
201228

202229
pub fn play_sound_at(&mut self, sound: Sound, volume: f32, pitch: f32, position: DVec3) {
203-
let chunk_x = (position.x.floor() as i32) >> 4;
204-
let chunk_z = (position.z.floor() as i32) >> 4;
205-
206-
if let Some(chunk) = self.chunk_grid.get_chunk_mut(chunk_x, chunk_z) {
207-
chunk.packet_buffer.write_packet(&SoundEffect {
208-
sound,
209-
pos_x: position.x,
210-
pos_y: position.y,
211-
pos_z: position.z,
212-
volume,
213-
pitch,
214-
})
215-
}
230+
self.write_local_packet(position, &SoundEffect {
231+
sound,
232+
pos_x: position.x,
233+
pos_y: position.y,
234+
pos_z: position.z,
235+
volume,
236+
pitch,
237+
});
216238
}
217239

218240
pub fn remove_player(&mut self, client_id: ClientId) {

src/dungeon/door/door.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use crate::dungeon::door::door_entity::DoorEntity;
21
use crate::dungeon::dungeon::Dungeon;
2+
use crate::dungeon::entities::block_appearance::BlockAppearance;
3+
use crate::dungeon::entities::moving_block_behaviour::MovingBlockBehaviour;
34
use crate::dungeon::seeded_rng::seeded_rng;
4-
use glam::{ivec3, DVec3, IVec3};
5+
use glam::{dvec3, ivec3, IVec3};
56
use rand::prelude::IndexedRandom;
67
use server::block::block_parameter::{Axis, BlockColor};
78
use server::block::rotatable::Rotate;
89
use server::block::Block;
910
use server::utils::hasher::deterministic_hasher::DeterministicHashMap;
10-
use server::world::chunk::chunk_grid::ChunkGrid;
11+
use server::world::chunk::chunk_grid::{iterate_blocks, ChunkGrid};
1112
use server::World;
1213

1314
#[derive(Hash, Eq, PartialEq)]
@@ -145,18 +146,27 @@ impl Door {
145146
}
146147

147148
self.is_open = true;
148-
149-
world.chunk_grid.fill_blocks(
150-
Block::Barrier,
149+
150+
iterate_blocks(
151151
ivec3(self.x - 1, 69, self.z - 1),
152152
ivec3(self.x + 1, 72, self.z + 1),
153+
|x, y, z| {
154+
world.spawn_entity(
155+
dvec3(x as f64 + 0.5, y as f64, z as f64 + 0.5),
156+
0.0,
157+
0.0,
158+
BlockAppearance {
159+
block: self.get_block(),
160+
},
161+
MovingBlockBehaviour {
162+
block: ivec3(x, y, z),
163+
total_ticks: 20,
164+
difference: -0.25,
165+
}
166+
);
167+
world.chunk_grid.set_block_at(Block::Barrier, x, y, z);
168+
}
153169
);
154-
155-
DoorEntity::spawn_into_world(
156-
world,
157-
DVec3::new(self.x as f64 - 1.0, 69.0, self.z as f64 - 1.0),
158-
self.get_block()
159-
)
160170
}
161171

162172
// inner bit of door, blocks abilities

0 commit comments

Comments
 (0)