add climbing and stuffsies

master
Tymon 1 year ago
parent 23d5b42863
commit 5c3141d7e6

@ -15,7 +15,10 @@ use valence::entity::player::PlayerEntityBundle;
use valence::packet::WritePacket;
use valence::prelude::*;
use valence_protocol::packet::s2c::play::synchronize_tags::Tag;
use valence_protocol::packet::s2c::play::synchronize_tags::TagGroup;
use valence_protocol::packet::s2c::play::ChunkRenderDistanceCenterS2c;
use valence_protocol::packet::s2c::play::SynchronizeTagsS2c;
use valence_protocol::var_int::VarInt;
use valence_protocol::Encode;
@ -90,6 +93,7 @@ fn init_clients(
for (_pos, entity, uuid, mut client, mut game_mode, username, mut has_respawn_screen) in
&mut new_clients
{
// initialize client
has_respawn_screen.0 = true;
*game_mode = GameMode::Creative;
commands.entity(entity).insert(PlayerEntityBundle {
@ -103,17 +107,34 @@ fn init_clients(
..Default::default()
});
// send packet that magically fixes chunks
// TODO: make this configurable as different maps will have different chunks we need to force load
client.write_packet(&ChunkRenderDistanceCenterS2c {
chunk_x: VarInt(-14),
chunk_z: VarInt(17),
});
// send block tags packet
client.write_packet(&SynchronizeTagsS2c {
tags: vec![TagGroup {
kind: ident!("block").into(),
tags: vec![Tag {
name: ident!("climbable").into(),
entries: vec![VarInt(316), VarInt(195)],
}],
}],
});
// send server brand
let mut buf = Vec::new();
"Valence".encode(&mut buf).unwrap();
client.send_custom_payload(ident!("brand"), &buf);
// add player to count
PLAYER_COUNT.fetch_add(1, Ordering::SeqCst);
tracing::info!("{username} joined the game");
}
}
@ -124,7 +145,7 @@ pub fn despawn_disconnected_clients(
for entity in disconnected_clients.iter() {
if let Some(mut entity) = commands.get_entity(entity) {
entity.insert(Despawned);
PLAYER_COUNT.fetch_sub(1, Ordering::SeqCst);
}
PLAYER_COUNT.fetch_sub(1, Ordering::SeqCst);
}
}

@ -6,7 +6,6 @@ use valence::{
prelude::{event::PlayerMove, *},
};
static PLAYER_HEIGHT_HISTORY: Lazy<Mutex<HashMap<i32, f64>>> =
Lazy::new(|| Mutex::new(HashMap::new()));
@ -37,12 +36,11 @@ pub fn fall_damage(
}
}
pub fn death(mut healths: Query<(&mut Client, &mut Health), Changed<Health>>) {
for (mut client, health) in &mut healths {
dbg!(health.0);
pub fn death(mut healths: Query<(&mut Client, &Health, &Username), Changed<Health>>) {
for (mut client, health, username) in &mut healths {
if health.0 <= 0.0 {
tracing::debug!("Trying to kill player");
client.kill(None, "L bozo");
tracing::debug!("Trying to kill player {}", username);
client.kill(None, format!("{} fell from a high place.", username));
}
}
}

@ -1,6 +1,3 @@
/* pub fn tnt(
mut commands: Commands,
mut clients: Query<(&mut Inventory, &GameMode, &PlayerInventoryState)>,

@ -36,43 +36,5 @@ pub fn setup(
tracing::info!("Successfully loaded world!");
/* tracing::info!("Filling chests...");
for chunk in instance.chunks() {
for x in 0..16 {
for y in 0..256 {
for z in 0..16 {
let block = chunk.1.block(x, y, z);
if block.state() == BlockState::CHEST {
tracing::debug!(
"found chest: chunk ({},{}), offset ({}, {}, {}), calculated world pos ({}, {}, {})",
chunk.0.x,
chunk.0.z,
x as i32,
y as i32,
z as i32,
(chunk.0.x * 16) + x as i32,
y as i32 + 49,
(chunk.0.z * 16) + z as i32
);
let mut inventory = Inventory::new(InventoryKind::Generic9x3);
inventory.set_slot(0, ItemStack::new(ItemKind::IronSword, 1, None));
let chest = Chest {
inventory,
block_pos: BlockPos::new(
(chunk.0.x - 1) * 16 + x as i32,
y as i32 + 49,
(chunk.0.z + 1) * 16 + z as i32,
),
};
commands.spawn(chest);
}
}
}
}
}
tracing::info!("Filled all (found) chests!"); */
commands.spawn(instance);
}

Loading…
Cancel
Save