this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 223 lines 6.1 kB view raw
1#![allow(clippy::type_complexity)] 2 3use std::fmt; 4 5use valence::prelude::*; 6 7const SPAWN_Y: i32 = 64; 8 9pub fn main() { 10 App::new() 11 .add_plugins(DefaultPlugins) 12 .add_systems(Startup, setup) 13 .add_systems( 14 Update, 15 (init_clients, despawn_disconnected_clients, manage_particles), 16 ) 17 .run(); 18} 19 20#[derive(Resource)] 21struct ParticleVec(Vec<Particle>); 22 23fn setup( 24 mut commands: Commands, 25 server: Res<Server>, 26 dimensions: Res<DimensionTypeRegistry>, 27 biomes: Res<BiomeRegistry>, 28) { 29 let mut layer = LayerBundle::new(ident!("overworld"), &dimensions, &biomes, &server); 30 31 for z in -5..5 { 32 for x in -5..5 { 33 layer.chunk.insert_chunk([x, z], UnloadedChunk::new()); 34 } 35 } 36 37 layer.chunk.set_block([0, SPAWN_Y, 0], BlockState::BEDROCK); 38 39 commands.spawn(layer); 40 41 commands.insert_resource(ParticleVec(create_particle_vec())); 42} 43 44fn init_clients( 45 mut clients: Query< 46 ( 47 &mut EntityLayerId, 48 &mut VisibleChunkLayer, 49 &mut VisibleEntityLayers, 50 &mut Position, 51 &mut GameMode, 52 ), 53 Added<Client>, 54 >, 55 layers: Query<Entity, (With<ChunkLayer>, With<EntityLayer>)>, 56) { 57 for ( 58 mut layer_id, 59 mut visible_chunk_layer, 60 mut visible_entity_layers, 61 mut pos, 62 mut game_mode, 63 ) in &mut clients 64 { 65 let layer = layers.single(); 66 67 layer_id.0 = layer; 68 visible_chunk_layer.0 = layer; 69 visible_entity_layers.0.insert(layer); 70 pos.set([0.0, f64::from(SPAWN_Y) + 1.0, 0.0]); 71 *game_mode = GameMode::Creative; 72 } 73} 74 75fn manage_particles( 76 particles: Res<ParticleVec>, 77 server: Res<Server>, 78 mut layers: Query<&mut ChunkLayer>, 79 mut particle_idx: Local<usize>, 80) { 81 if server.current_tick() % 10 != 0 { 82 return; 83 } 84 85 let particle = &particles.0[*particle_idx]; 86 87 *particle_idx = (*particle_idx + 1) % particles.0.len(); 88 89 let name = dbg_name(particle); 90 91 let pos = [0.5, f64::from(SPAWN_Y) + 2.0, 5.0]; 92 let offset = [0.5, 0.5, 0.5]; 93 94 let mut layer = layers.single_mut(); 95 96 layer.play_particle(particle, true, pos, offset, 0.1, 100); 97 layer.set_action_bar(name.bold()); 98} 99 100fn dbg_name(dbg: &impl fmt::Debug) -> String { 101 let string = format!("{dbg:?}"); 102 103 string 104 .split_once(|ch: char| !ch.is_ascii_alphabetic()) 105 .map(|(fst, _)| fst.to_owned()) 106 .unwrap_or(string) 107} 108 109fn create_particle_vec() -> Vec<Particle> { 110 vec![ 111 Particle::AmbientEntityEffect, 112 Particle::AngryVillager, 113 Particle::Block(BlockState::OAK_PLANKS), 114 Particle::BlockMarker(BlockState::GOLD_BLOCK), 115 Particle::Bubble, 116 Particle::Cloud, 117 Particle::Crit, 118 Particle::DamageIndicator, 119 Particle::DragonBreath, 120 Particle::DrippingLava, 121 Particle::FallingLava, 122 Particle::LandingLava, 123 Particle::DrippingWater, 124 Particle::FallingWater, 125 Particle::Dust { 126 rgb: Vec3::new(1.0, 1.0, 0.0), 127 scale: 2.0, 128 }, 129 Particle::DustColorTransition { 130 from_rgb: Vec3::new(1.0, 0.0, 0.0), 131 scale: 2.0, 132 to_rgb: Vec3::new(0.0, 1.0, 0.0), 133 }, 134 Particle::Effect, 135 Particle::ElderGuardian, 136 Particle::EnchantedHit, 137 Particle::Enchant, 138 Particle::EndRod, 139 Particle::EntityEffect, 140 Particle::ExplosionEmitter, 141 Particle::Explosion, 142 Particle::SonicBoom, 143 Particle::FallingDust(BlockState::RED_SAND), 144 Particle::Firework, 145 Particle::Fishing, 146 Particle::Flame, 147 Particle::CherryLeaves, 148 Particle::SculkSoul, 149 Particle::SculkCharge { roll: 1.0 }, 150 Particle::SculkChargePop, 151 Particle::SoulFireFlame, 152 Particle::Soul, 153 Particle::Flash, 154 Particle::HappyVillager, 155 Particle::Composter, 156 Particle::Heart, 157 Particle::InstantEffect, 158 Particle::Item(ItemStack::EMPTY), 159 Particle::Item(ItemStack::new(ItemKind::IronPickaxe, 1, None)), 160 Particle::VibrationBlock { 161 block_pos: [0, SPAWN_Y, 0].into(), 162 ticks: 50, 163 }, 164 Particle::VibrationEntity { 165 entity_id: 0, 166 entity_eye_height: 1.0, 167 ticks: 50, 168 }, 169 Particle::ItemSlime, 170 Particle::ItemSnowball, 171 Particle::LargeSmoke, 172 Particle::Lava, 173 Particle::Mycelium, 174 Particle::Note, 175 Particle::Poof, 176 Particle::Portal, 177 Particle::Rain, 178 Particle::Smoke, 179 Particle::Sneeze, 180 Particle::Spit, 181 Particle::SquidInk, 182 Particle::SweepAttack, 183 Particle::TotemOfUndying, 184 Particle::Underwater, 185 Particle::Splash, 186 Particle::Witch, 187 Particle::BubblePop, 188 Particle::CurrentDown, 189 Particle::BubbleColumnUp, 190 Particle::Nautilus, 191 Particle::Dolphin, 192 Particle::CampfireCosySmoke, 193 Particle::CampfireSignalSmoke, 194 Particle::DrippingHoney, 195 Particle::FallingHoney, 196 Particle::LandingHoney, 197 Particle::FallingNectar, 198 Particle::FallingSporeBlossom, 199 Particle::Ash, 200 Particle::CrimsonSpore, 201 Particle::WarpedSpore, 202 Particle::SporeBlossomAir, 203 Particle::DrippingObsidianTear, 204 Particle::FallingObsidianTear, 205 Particle::LandingObsidianTear, 206 Particle::ReversePortal, 207 Particle::WhiteAsh, 208 Particle::SmallFlame, 209 Particle::Snowflake, 210 Particle::DrippingDripstoneLava, 211 Particle::FallingDripstoneLava, 212 Particle::DrippingDripstoneWater, 213 Particle::FallingDripstoneWater, 214 Particle::GlowSquidInk, 215 Particle::Glow, 216 Particle::WaxOn, 217 Particle::WaxOff, 218 Particle::ElectricSpark, 219 Particle::Scrape, 220 Particle::Shriek { delay: 0 }, 221 Particle::EggCrack, 222 ] 223}