Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added potion effects #551

Closed
wants to merge 40 commits into from
Closed

Conversation

SelfMadeSystem
Copy link
Contributor

@SelfMadeSystem SelfMadeSystem commented Oct 9, 2023

Objective

  • Potion effects aren't supported by valence yet.
  • You can send a packet to tell the client about a potion effect, but the server still has no idea what they are
Example code ```rs

pub fn add_potion_effect(mut clients: Query<&mut Client>, mut events: EventReader) {
for event in events.iter() {
if event.state == SneakState::Start {
if let Ok(mut client) = clients.get_mut(event.client) {
client.write_packet(&EntityStatusEffectS2c {
entity_id: VarInt(0),
effect_id: VarInt(22),
amplifier: 0,
duration: VarInt(600),
flags: entity_status_effect_s2c::Flags::new()
.with_show_particles(true)
.with_show_icon(true),
factor_codec: None,
});
}
}
}
}```

  • Closes Potion Effects #401
  • Also, when the potion effect expires, we need to tell the client that their potion effect is no longer. Right now, with sending a packet, the effect doesn't get removed when it goes down to 00:00.

Solution

I want to add the necessary components and stuff to facilitate potion effects.

Note: I'm still somewhat new to rust and very new to bevy, so please lmk if I can improve anything or if I should do anything differently. Thanks!

To do:

  • Extractor
  • ActiveStatusEffects component to handle the actual status effect applied to the mc entity
  • Add ActiveStatusEffects component to all entities.
  • Make a plugin to handle potion effects
    • Decrease tick count
    • Remove effect (& tell client) when tick count is 0
    • Make the effects do stuff
      • Particles
      • Tell client
      • Glowing/invisible
      • Health, damage, heal. See Damaging entities + death #556
        • Instant health/damage
        • Regen/poison/wither
      • Absorption (???)
      • EntityAttributes. See Add EntityAttributes #555
        • Speed/Slowness
        • Haste/Mining fatigue
        • Strengh/Weakness
        • Health boost
        • Luck/Unluck
  • Add tests
  • Add example

Playground

Current playground
use valence::client::despawn_disconnected_clients;
use valence::entity::active_status_effects::{ActiveStatusEffect, ActiveStatusEffects};
use valence::entity::status_effects::StatusEffect;
use valence::log::LogPlugin;
use valence::network::ConnectionMode;
use valence::prelude::*;

#[allow(unused_imports)]
use crate::extras::*;

const SPAWN_Y: i32 = 64;

pub fn build_app(app: &mut App) {
    app.insert_resource(NetworkSettings {
        connection_mode: ConnectionMode::Offline,
        ..Default::default()
    })
    .add_plugins(DefaultPlugins.build().disable::<LogPlugin>())
    .add_systems(Startup, setup)
    .add_systems(EventLoopUpdate, add_potion_effect)
    .add_systems(Update, (init_clients, despawn_disconnected_clients))
    .run();
}

fn setup(
    mut commands: Commands,
    server: Res<Server>,
    biomes: Res<BiomeRegistry>,
    dimensions: Res<DimensionTypeRegistry>,
) {
    let mut layer = LayerBundle::new(ident!("overworld"), &dimensions, &biomes, &server);

    for z in -5..5 {
        for x in -5..5 {
            layer.chunk.insert_chunk([x, z], UnloadedChunk::new());
        }
    }

    for z in -25..25 {
        for x in -25..25 {
            layer
                .chunk
                .set_block([x, SPAWN_Y, z], BlockState::GRASS_BLOCK);
        }
    }

    commands.spawn(layer);
}

fn init_clients(
    mut clients: Query<
        (
            &mut EntityLayerId,
            &mut VisibleChunkLayer,
            &mut VisibleEntityLayers,
            &mut Position,
            &mut GameMode,
        ),
        Added<Client>,
    >,
    layers: Query<Entity, (With<ChunkLayer>, With<EntityLayer>)>,
) {
    for (
        mut layer_id,
        mut visible_chunk_layer,
        mut visible_entity_layers,
        mut pos,
        mut game_mode,
    ) in &mut clients
    {
        let layer = layers.single();

        layer_id.0 = layer;
        visible_chunk_layer.0 = layer;
        visible_entity_layers.0.insert(layer);
        pos.set([0.0, SPAWN_Y as f64 + 1.0, 0.0]);
        *game_mode = GameMode::Survival;
    }
}

pub fn add_potion_effect(
    mut clients: Query<&mut ActiveStatusEffects>,
    mut events: EventReader<SneakEvent>,
) {
    for event in events.iter() {
        if event.state == SneakState::Start {
            if let Ok(mut status) = clients.get_mut(event.client) {
                status.add(
                    ActiveStatusEffect::from_effect(StatusEffect::Wither)
                        .with_amplifier(2)
                        .with_duration(200),
                );
            }
        }
    }
}

Copy link
Collaborator

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your proposed API: This is something that should be a component, or set of components, that would go on the same entity as a player or any other entity. Minecraft entities other than players can have effects. In other words, this shouldn't go on the Client component.

crates/valence_generated/build/effect.rs Outdated Show resolved Hide resolved
@SelfMadeSystem
Copy link
Contributor Author

SelfMadeSystem commented Oct 9, 2023

Regarding your proposed API: This is something that should be a component, or set of components, that would go on the same entity as a player or any other entity. Minecraft entities other than players can have effects. In other words, this shouldn't go on the Client component.

Thanks for the feedback! Seems like a good idea. I'm still not fully familiar with the ECS and I still need some time to adapt to it. I'll see how other stuff is implemented, and I'll see what I can do.

@JackCrumpLeys
Copy link
Contributor

JackCrumpLeys commented Oct 9, 2023

Regarding your proposed API: This is something that should be a component, or set of components, that would go on the same entity as a player or any other entity. Minecraft entities other than players can have effects. In other words, this shouldn't go on the Client component.

Thanks for the feedback! Seems like a good idea. I'm still not fully familiar with the ECS and I still need some time to adapt to it. I'll see how other stuff is implemented, and I'll see what I can do.

I would put this potion component on every Living Entity (https://valence.rs/rustdoc/valence/entity/living/struct.LivingEntity.html). Lib users should be able to add it to anything with a entity id.

Copy link

@ethanwater ethanwater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i recommend checking out https://github.com/WangTingZheng/mcp940/tree/master/bin/minecraft/net/minecraft/potion to see how minecraft 1.12 handled the potion system across entities ;)

@github-actions
Copy link

It looks like this pull request changed the workspace structure. Please replace assets/depgraph.svg with the following text:

depgraph.svg (Don't forget the trailing newline)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.43.0 (0)
 -->
<!-- Title: %3 Pages: 1 -->
<svg width="1480pt" height="620pt"
 viewBox="0.00 0.00 1479.50 620.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 616)">
<title>%3</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-616 1475.5,-616 1475.5,4 -4,4"/>
<!-- 0 -->
<g id="node1" class="node">
<title>0</title>
<polygon fill="none" stroke="black" points="573,-612 478,-612 478,-576 573,-576 573,-612"/>
<text text-anchor="middle" x="525.5" y="-590.3" font-family="Times,serif" font-size="14.00">java_string</text>
</g>
<!-- 1 -->
<g id="node2" class="node">
<title>1</title>
<polygon fill="none" stroke="black" points="173,-468 0,-468 0,-432 173,-432 173,-468"/>
<text text-anchor="middle" x="86.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_advancement</text>
</g>
<!-- 2 -->
<g id="node3" class="node">
<title>2</title>
<polygon fill="none" stroke="black" points="781,-396 658,-396 658,-360 781,-360 781,-396"/>
<text text-anchor="middle" x="719.5" y="-374.3" font-family="Times,serif" font-size="14.00">valence_server</text>
</g>
<!-- 1&#45;&gt;2 -->
<g id="edge1" class="edge">
<title>1&#45;&gt;2</title>
<path fill="none" stroke="black" d="M173.06,-433.36C176.24,-432.88 179.4,-432.43 182.5,-432 348.43,-409.15 544.53,-392.37 647.71,-384.32"/>
<polygon fill="black" stroke="black" points="648.01,-387.81 657.71,-383.55 647.47,-380.83 648.01,-387.81"/>
</g>
<!-- 3 -->
<g id="node4" class="node">
<title>3</title>
<polygon fill="none" stroke="black" points="707,-324 588,-324 588,-288 707,-288 707,-324"/>
<text text-anchor="middle" x="647.5" y="-302.3" font-family="Times,serif" font-size="14.00">valence_entity</text>
</g>
<!-- 2&#45;&gt;3 -->
<g id="edge2" class="edge">
<title>2&#45;&gt;3</title>
<path fill="none" stroke="black" d="M701.7,-359.7C692.9,-351.14 682.12,-340.66 672.5,-331.3"/>
<polygon fill="black" stroke="black" points="674.7,-328.57 665.09,-324.1 669.82,-333.58 674.7,-328.57"/>
</g>
<!-- 12 -->
<g id="node5" class="node">
<title>12</title>
<polygon fill="none" stroke="black" points="859.5,-324 725.5,-324 725.5,-288 859.5,-288 859.5,-324"/>
<text text-anchor="middle" x="792.5" y="-302.3" font-family="Times,serif" font-size="14.00">valence_registry</text>
</g>
<!-- 2&#45;&gt;12 -->
<g id="edge3" class="edge">
<title>2&#45;&gt;12</title>
<path fill="none" stroke="black" d="M737.54,-359.7C746.56,-351.05 757.62,-340.45 767.44,-331.03"/>
<polygon fill="black" stroke="black" points="769.87,-333.55 774.66,-324.1 765.02,-328.5 769.87,-333.55"/>
</g>
<!-- 11 -->
<g id="node6" class="node">
<title>11</title>
<polygon fill="none" stroke="black" points="814.5,-252 624.5,-252 624.5,-216 814.5,-216 814.5,-252"/>
<text text-anchor="middle" x="719.5" y="-230.3" font-family="Times,serif" font-size="14.00">valence_server_common</text>
</g>
<!-- 3&#45;&gt;11 -->
<g id="edge4" class="edge">
<title>3&#45;&gt;11</title>
<path fill="none" stroke="black" d="M665.3,-287.7C674.1,-279.14 684.88,-268.66 694.5,-259.3"/>
<polygon fill="black" stroke="black" points="697.18,-261.58 701.91,-252.1 692.3,-256.57 697.18,-261.58"/>
</g>
<!-- 12&#45;&gt;11 -->
<g id="edge12" class="edge">
<title>12&#45;&gt;11</title>
<path fill="none" stroke="black" d="M774.46,-287.7C765.44,-279.05 754.38,-268.45 744.56,-259.03"/>
<polygon fill="black" stroke="black" points="746.98,-256.5 737.34,-252.1 742.13,-261.55 746.98,-256.5"/>
</g>
<!-- 7 -->
<g id="node10" class="node">
<title>7</title>
<polygon fill="none" stroke="black" points="636.5,-180 500.5,-180 500.5,-144 636.5,-144 636.5,-180"/>
<text text-anchor="middle" x="568.5" y="-158.3" font-family="Times,serif" font-size="14.00">valence_protocol</text>
</g>
<!-- 11&#45;&gt;7 -->
<g id="edge11" class="edge">
<title>11&#45;&gt;7</title>
<path fill="none" stroke="black" d="M682.56,-215.88C662.01,-206.35 636.25,-194.41 614.41,-184.28"/>
<polygon fill="black" stroke="black" points="615.86,-181.1 605.32,-180.07 612.92,-187.45 615.86,-181.1"/>
</g>
<!-- 4 -->
<g id="node7" class="node">
<title>4</title>
<polygon fill="none" stroke="black" points="628.5,-36 514.5,-36 514.5,0 628.5,0 628.5,-36"/>
<text text-anchor="middle" x="571.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_ident</text>
</g>
<!-- 5 -->
<g id="node8" class="node">
<title>5</title>
<polygon fill="none" stroke="black" points="496.5,-36 382.5,-36 382.5,0 496.5,0 496.5,-36"/>
<text text-anchor="middle" x="439.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_math</text>
</g>
<!-- 6 -->
<g id="node9" class="node">
<title>6</title>
<polygon fill="none" stroke="black" points="748,-36 647,-36 647,0 748,0 748,-36"/>
<text text-anchor="middle" x="697.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_nbt</text>
</g>
<!-- 8 -->
<g id="node11" class="node">
<title>8</title>
<polygon fill="none" stroke="black" points="570.5,-108 420.5,-108 420.5,-72 570.5,-72 570.5,-108"/>
<text text-anchor="middle" x="495.5" y="-86.3" font-family="Times,serif" font-size="14.00">valence_generated</text>
</g>
<!-- 7&#45;&gt;8 -->
<g id="edge5" class="edge">
<title>7&#45;&gt;8</title>
<path fill="none" stroke="black" d="M550.46,-143.7C541.44,-135.05 530.38,-124.45 520.56,-115.03"/>
<polygon fill="black" stroke="black" points="522.98,-112.5 513.34,-108.1 518.13,-117.55 522.98,-112.5"/>
</g>
<!-- 10 -->
<g id="node12" class="node">
<title>10</title>
<polygon fill="none" stroke="black" points="694.5,-108 588.5,-108 588.5,-72 694.5,-72 694.5,-108"/>
<text text-anchor="middle" x="641.5" y="-86.3" font-family="Times,serif" font-size="14.00">valence_text</text>
</g>
<!-- 7&#45;&gt;10 -->
<g id="edge6" class="edge">
<title>7&#45;&gt;10</title>
<path fill="none" stroke="black" d="M586.54,-143.7C595.56,-135.05 606.62,-124.45 616.44,-115.03"/>
<polygon fill="black" stroke="black" points="618.87,-117.55 623.66,-108.1 614.02,-112.5 618.87,-117.55"/>
</g>
<!-- 8&#45;&gt;4 -->
<g id="edge7" class="edge">
<title>8&#45;&gt;4</title>
<path fill="none" stroke="black" d="M514.29,-71.7C523.67,-63.05 535.18,-52.45 545.41,-43.03"/>
<polygon fill="black" stroke="black" points="547.95,-45.45 552.93,-36.1 543.2,-40.3 547.95,-45.45"/>
</g>
<!-- 8&#45;&gt;5 -->
<g id="edge8" class="edge">
<title>8&#45;&gt;5</title>
<path fill="none" stroke="black" d="M481.66,-71.7C475.01,-63.39 466.92,-53.28 459.61,-44.14"/>
<polygon fill="black" stroke="black" points="462.16,-41.73 453.18,-36.1 456.7,-46.1 462.16,-41.73"/>
</g>
<!-- 10&#45;&gt;4 -->
<g id="edge9" class="edge">
<title>10&#45;&gt;4</title>
<path fill="none" stroke="black" d="M624.2,-71.7C615.64,-63.14 605.16,-52.66 595.8,-43.3"/>
<polygon fill="black" stroke="black" points="598.15,-40.7 588.6,-36.1 593.2,-45.65 598.15,-40.7"/>
</g>
<!-- 10&#45;&gt;6 -->
<g id="edge10" class="edge">
<title>10&#45;&gt;6</title>
<path fill="none" stroke="black" d="M655.34,-71.7C661.99,-63.39 670.08,-53.28 677.39,-44.14"/>
<polygon fill="black" stroke="black" points="680.3,-46.1 683.82,-36.1 674.84,-41.73 680.3,-46.1"/>
</g>
<!-- 9 -->
<g id="node13" class="node">
<title>9</title>
<polygon fill="none" stroke="black" points="1004.5,-612 852.5,-612 852.5,-576 1004.5,-576 1004.5,-612"/>
<text text-anchor="middle" x="928.5" y="-590.3" font-family="Times,serif" font-size="14.00">valence_build_utils</text>
</g>
<!-- 13 -->
<g id="node14" class="node">
<title>13</title>
<polygon fill="none" stroke="black" points="303.5,-468 191.5,-468 191.5,-432 303.5,-432 303.5,-468"/>
<text text-anchor="middle" x="247.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_anvil</text>
</g>
<!-- 13&#45;&gt;2 -->
<g id="edge13" class="edge">
<title>13&#45;&gt;2</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M303.77,-433.82C306.71,-433.17 309.64,-432.56 312.5,-432 428.87,-409.3 565.89,-393.72 647.57,-385.59"/>
<polygon fill="black" stroke="black" points="648.13,-389.05 657.74,-384.59 647.45,-382.09 648.13,-389.05"/>
</g>
<!-- 14 -->
<g id="node15" class="node">
<title>14</title>
<polygon fill="none" stroke="black" points="461.5,-468 321.5,-468 321.5,-432 461.5,-432 461.5,-468"/>
<text text-anchor="middle" x="391.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_boss_bar</text>
</g>
<!-- 14&#45;&gt;2 -->
<g id="edge14" class="edge">
<title>14&#45;&gt;2</title>
<path fill="none" stroke="black" d="M461.71,-433.88C464.68,-433.25 467.62,-432.62 470.5,-432 530.24,-419.21 598.06,-404.78 647.82,-394.21"/>
<polygon fill="black" stroke="black" points="648.78,-397.59 657.84,-392.08 647.33,-390.74 648.78,-397.59"/>
</g>
<!-- 15 -->
<g id="node16" class="node">
<title>15</title>
<polygon fill="none" stroke="black" points="625.5,-468 479.5,-468 479.5,-432 625.5,-432 625.5,-468"/>
<text text-anchor="middle" x="552.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_inventory</text>
</g>
<!-- 15&#45;&gt;2 -->
<g id="edge15" class="edge">
<title>15&#45;&gt;2</title>
<path fill="none" stroke="black" d="M593.35,-431.88C616.28,-422.26 645.08,-410.19 669.37,-400.01"/>
<polygon fill="black" stroke="black" points="670.91,-403.16 678.78,-396.07 668.2,-396.71 670.91,-403.16"/>
</g>
<!-- 16 -->
<g id="node17" class="node">
<title>16</title>
<polygon fill="none" stroke="black" points="1457.5,-396 1349.5,-396 1349.5,-360 1457.5,-360 1457.5,-396"/>
<text text-anchor="middle" x="1403.5" y="-374.3" font-family="Times,serif" font-size="14.00">valence_lang</text>
</g>
<!-- 17 -->
<g id="node18" class="node">
<title>17</title>
<polygon fill="none" stroke="black" points="1471.5,-468 1335.5,-468 1335.5,-432 1471.5,-432 1471.5,-468"/>
<text text-anchor="middle" x="1403.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_network</text>
</g>
<!-- 17&#45;&gt;2 -->
<g id="edge16" class="edge">
<title>17&#45;&gt;2</title>
<path fill="none" stroke="black" d="M1335.15,-433.43C1332.24,-432.91 1329.34,-432.44 1326.5,-432 1134.42,-402.54 905.44,-388.07 791.43,-382.24"/>
<polygon fill="black" stroke="black" points="791.59,-378.75 781.42,-381.74 791.23,-385.74 791.59,-378.75"/>
</g>
<!-- 17&#45;&gt;16 -->
<g id="edge17" class="edge">
<title>17&#45;&gt;16</title>
<path fill="none" stroke="black" d="M1403.5,-431.7C1403.5,-423.98 1403.5,-414.71 1403.5,-406.11"/>
<polygon fill="black" stroke="black" points="1407,-406.1 1403.5,-396.1 1400,-406.1 1407,-406.1"/>
</g>
<!-- 18 -->
<g id="node19" class="node">
<title>18</title>
<polygon fill="none" stroke="black" points="795.5,-468 643.5,-468 643.5,-432 795.5,-432 795.5,-468"/>
<text text-anchor="middle" x="719.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_player_list</text>
</g>
<!-- 18&#45;&gt;2 -->
<g id="edge18" class="edge">
<title>18&#45;&gt;2</title>
<path fill="none" stroke="black" d="M719.5,-431.7C719.5,-423.98 719.5,-414.71 719.5,-406.11"/>
<polygon fill="black" stroke="black" points="723,-406.1 719.5,-396.1 716,-406.1 723,-406.1"/>
</g>
<!-- 19 -->
<g id="node20" class="node">
<title>19</title>
<polygon fill="none" stroke="black" points="971,-468 814,-468 814,-432 971,-432 971,-468"/>
<text text-anchor="middle" x="892.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_scoreboard</text>
</g>
<!-- 19&#45;&gt;2 -->
<g id="edge19" class="edge">
<title>19&#45;&gt;2</title>
<path fill="none" stroke="black" d="M850.18,-431.88C826.32,-422.22 796.33,-410.09 771.1,-399.88"/>
<polygon fill="black" stroke="black" points="772.27,-396.57 761.68,-396.07 769.64,-403.06 772.27,-396.57"/>
</g>
<!-- 20 -->
<g id="node21" class="node">
<title>20</title>
<polygon fill="none" stroke="black" points="1148,-612 1023,-612 1023,-576 1148,-576 1148,-612"/>
<text text-anchor="middle" x="1085.5" y="-590.3" font-family="Times,serif" font-size="14.00">valence_spatial</text>
</g>
<!-- 21 -->
<g id="node22" class="node">
<title>21</title>
<polygon fill="none" stroke="black" points="1125.5,-468 989.5,-468 989.5,-432 1125.5,-432 1125.5,-468"/>
<text text-anchor="middle" x="1057.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_weather</text>
</g>
<!-- 21&#45;&gt;2 -->
<g id="edge20" class="edge">
<title>21&#45;&gt;2</title>
<path fill="none" stroke="black" d="M989.49,-433.92C986.45,-433.27 983.45,-432.62 980.5,-432 916.55,-418.45 843.62,-403.7 791.14,-393.21"/>
<polygon fill="black" stroke="black" points="791.75,-389.76 781.26,-391.23 790.38,-396.63 791.75,-389.76"/>
</g>
<!-- 22 -->
<g id="node23" class="node">
<title>22</title>
<polygon fill="none" stroke="black" points="1317,-468 1144,-468 1144,-432 1317,-432 1317,-468"/>
<text text-anchor="middle" x="1230.5" y="-446.3" font-family="Times,serif" font-size="14.00">valence_world_border</text>
</g>
<!-- 22&#45;&gt;2 -->
<g id="edge21" class="edge">
<title>22&#45;&gt;2</title>
<path fill="none" stroke="black" d="M1143.92,-433.47C1140.75,-432.96 1137.6,-432.47 1134.5,-432 1014.39,-413.71 874.06,-396.69 791.21,-387.09"/>
<polygon fill="black" stroke="black" points="791.49,-383.6 781.15,-385.93 790.69,-390.56 791.49,-383.6"/>
</g>
<!-- 23 -->
<g id="node24" class="node">
<title>23</title>
<polygon fill="none" stroke="black" points="718,-612 591,-612 591,-576 718,-576 718,-612"/>
<text text-anchor="middle" x="654.5" y="-590.3" font-family="Times,serif" font-size="14.00">dump_schedule</text>
</g>
<!-- 24 -->
<g id="node25" class="node">
<title>24</title>
<polygon fill="none" stroke="black" points="755,-540 684,-540 684,-504 755,-504 755,-540"/>
<text text-anchor="middle" x="719.5" y="-518.3" font-family="Times,serif" font-size="14.00">valence</text>
</g>
<!-- 23&#45;&gt;24 -->
<g id="edge22" class="edge">
<title>23&#45;&gt;24</title>
<path fill="none" stroke="black" d="M670.57,-575.7C678.44,-567.22 688.06,-556.86 696.67,-547.58"/>
<polygon fill="black" stroke="black" points="699.38,-549.81 703.62,-540.1 694.25,-545.05 699.38,-549.81"/>
</g>
<!-- 24&#45;&gt;1 -->
<g id="edge23" class="edge">
<title>24&#45;&gt;1</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M683.89,-518.44C599.09,-512.13 378.38,-494.52 183.21,-468.03"/>
<polygon fill="black" stroke="black" points="183.44,-464.53 173.06,-466.64 182.49,-471.47 183.44,-464.53"/>
</g>
<!-- 24&#45;&gt;13 -->
<g id="edge24" class="edge">
<title>24&#45;&gt;13</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M683.87,-517.89C614.46,-511.5 456.18,-495.32 313.98,-468.16"/>
<polygon fill="black" stroke="black" points="314.25,-464.64 303.77,-466.18 312.92,-471.52 314.25,-464.64"/>
</g>
<!-- 24&#45;&gt;14 -->
<g id="edge25" class="edge">
<title>24&#45;&gt;14</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M683.62,-513.39C637.12,-503.52 553.23,-485.7 471.64,-468.24"/>
<polygon fill="black" stroke="black" points="472.22,-464.79 461.71,-466.12 470.76,-471.63 472.22,-464.79"/>
</g>
<!-- 24&#45;&gt;15 -->
<g id="edge26" class="edge">
<title>24&#45;&gt;15</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M683.67,-505.98C660.03,-496.07 628.72,-482.95 602.61,-472.01"/>
<polygon fill="black" stroke="black" points="603.83,-468.72 593.26,-468.08 601.13,-475.18 603.83,-468.72"/>
</g>
<!-- 24&#45;&gt;17 -->
<g id="edge27" class="edge">
<title>24&#45;&gt;17</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M755.27,-519.51C847.89,-515.29 1103.22,-501.46 1324.95,-468.12"/>
<polygon fill="black" stroke="black" points="1325.79,-471.54 1335.15,-466.57 1324.74,-464.62 1325.79,-471.54"/>
</g>
<!-- 24&#45;&gt;18 -->
<g id="edge28" class="edge">
<title>24&#45;&gt;18</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M719.5,-503.7C719.5,-495.98 719.5,-486.71 719.5,-478.11"/>
<polygon fill="black" stroke="black" points="723,-478.1 719.5,-468.1 716,-478.1 723,-478.1"/>
</g>
<!-- 24&#45;&gt;19 -->
<g id="edge29" class="edge">
<title>24&#45;&gt;19</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M755.35,-506.5C780.05,-496.5 813.25,-483.06 840.81,-471.92"/>
<polygon fill="black" stroke="black" points="842.34,-475.07 850.3,-468.08 839.71,-468.58 842.34,-475.07"/>
</g>
<!-- 24&#45;&gt;21 -->
<g id="edge30" class="edge">
<title>24&#45;&gt;21</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M755,-513.99C803.39,-504.39 893.02,-486.46 979.51,-468.19"/>
<polygon fill="black" stroke="black" points="980.43,-471.57 989.49,-466.08 978.99,-464.73 980.43,-471.57"/>
</g>
<!-- 24&#45;&gt;22 -->
<g id="edge31" class="edge">
<title>24&#45;&gt;22</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M755.11,-517.04C825.37,-509.1 987,-490.2 1133.83,-468.06"/>
<polygon fill="black" stroke="black" points="1134.56,-471.49 1143.92,-466.53 1133.51,-464.57 1134.56,-471.49"/>
</g>
<!-- 25 -->
<g id="node26" class="node">
<title>25</title>
<polygon fill="none" stroke="black" points="513,-252 376,-252 376,-216 513,-216 513,-252"/>
<text text-anchor="middle" x="444.5" y="-230.3" font-family="Times,serif" font-size="14.00">packet_inspector</text>
</g>
<!-- 25&#45;&gt;7 -->
<g id="edge32" class="edge">
<title>25&#45;&gt;7</title>
<path fill="none" stroke="black" d="M474.83,-215.88C491.2,-206.64 511.58,-195.13 529.15,-185.21"/>
<polygon fill="black" stroke="black" points="531.06,-188.15 538.05,-180.19 527.62,-182.06 531.06,-188.15"/>
</g>
<!-- 26 -->
<g id="node27" class="node">
<title>26</title>
<polygon fill="none" stroke="black" points="834.5,-612 736.5,-612 736.5,-576 834.5,-576 834.5,-612"/>
<text text-anchor="middle" x="785.5" y="-590.3" font-family="Times,serif" font-size="14.00">playground</text>
</g>
<!-- 26&#45;&gt;24 -->
<g id="edge33" class="edge">
<title>26&#45;&gt;24</title>
<path fill="none" stroke="black" d="M769.19,-575.7C761.19,-567.22 751.43,-556.86 742.68,-547.58"/>
<polygon fill="black" stroke="black" points="745.03,-544.98 735.63,-540.1 739.94,-549.78 745.03,-544.98"/>
</g>
<!-- 27 -->
<g id="node28" class="node">
<title>27</title>
<polygon fill="none" stroke="black" points="606,-252 531,-252 531,-216 606,-216 606,-252"/>
<text text-anchor="middle" x="568.5" y="-230.3" font-family="Times,serif" font-size="14.00">stresser</text>
</g>
<!-- 27&#45;&gt;7 -->
<g id="edge34" class="edge">
<title>27&#45;&gt;7</title>
<path fill="none" stroke="black" d="M568.5,-215.7C568.5,-207.98 568.5,-198.71 568.5,-190.11"/>
<polygon fill="black" stroke="black" points="572,-190.1 568.5,-180.1 565,-190.1 572,-190.1"/>
</g>
</g>
</svg>

For reference, here is a diff against the old depgraph.svg:

diff --git a/assets/depgraph.svg b/assets/depgraph.svg
index 8bb16f7..d47568e 100644
--- a/assets/depgraph.svg
+++ b/assets/depgraph.svg
@@ -90,20 +90,20 @@
 <!-- 4 -->
 <g id="node7" class="node">
 <title>4</title>
-<polygon fill="none" stroke="black" points="496.5,-36 382.5,-36 382.5,0 496.5,0 496.5,-36"/>
-<text text-anchor="middle" x="439.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_math</text>
+<polygon fill="none" stroke="black" points="628.5,-36 514.5,-36 514.5,0 628.5,0 628.5,-36"/>
+<text text-anchor="middle" x="571.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_ident</text>
 </g>
 <!-- 5 -->
 <g id="node8" class="node">
 <title>5</title>
-<polygon fill="none" stroke="black" points="748,-36 647,-36 647,0 748,0 748,-36"/>
-<text text-anchor="middle" x="697.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_nbt</text>
+<polygon fill="none" stroke="black" points="496.5,-36 382.5,-36 382.5,0 496.5,0 496.5,-36"/>
+<text text-anchor="middle" x="439.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_math</text>
 </g>
 <!-- 6 -->
 <g id="node9" class="node">
 <title>6</title>
-<polygon fill="none" stroke="black" points="628.5,-36 514.5,-36 514.5,0 628.5,0 628.5,-36"/>
-<text text-anchor="middle" x="571.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_ident</text>
+<polygon fill="none" stroke="black" points="748,-36 647,-36 647,0 748,0 748,-36"/>
+<text text-anchor="middle" x="697.5" y="-14.3" font-family="Times,serif" font-size="14.00">valence_nbt</text>
 </g>
 <!-- 8 -->
 <g id="node11" class="node">
@@ -132,26 +132,26 @@
 <!-- 8&#45;&gt;4 -->
 <g id="edge7" class="edge">
 <title>8&#45;&gt;4</title>
-<path fill="none" stroke="black" d="M481.66,-71.7C475.01,-63.39 466.92,-53.28 459.61,-44.14"/>
-<polygon fill="black" stroke="black" points="462.16,-41.73 453.18,-36.1 456.7,-46.1 462.16,-41.73"/>
-</g>
-<!-- 8&#45;&gt;6 -->
-<g id="edge8" class="edge">
-<title>8&#45;&gt;6</title>
 <path fill="none" stroke="black" d="M514.29,-71.7C523.67,-63.05 535.18,-52.45 545.41,-43.03"/>
 <polygon fill="black" stroke="black" points="547.95,-45.45 552.93,-36.1 543.2,-40.3 547.95,-45.45"/>
 </g>
-<!-- 10&#45;&gt;5 -->
+<!-- 8&#45;&gt;5 -->
+<g id="edge8" class="edge">
+<title>8&#45;&gt;5</title>
+<path fill="none" stroke="black" d="M481.66,-71.7C475.01,-63.39 466.92,-53.28 459.61,-44.14"/>
+<polygon fill="black" stroke="black" points="462.16,-41.73 453.18,-36.1 456.7,-46.1 462.16,-41.73"/>
+</g>
+<!-- 10&#45;&gt;4 -->
 <g id="edge9" class="edge">
-<title>10&#45;&gt;5</title>
-<path fill="none" stroke="black" d="M655.34,-71.7C661.99,-63.39 670.08,-53.28 677.39,-44.14"/>
-<polygon fill="black" stroke="black" points="680.3,-46.1 683.82,-36.1 674.84,-41.73 680.3,-46.1"/>
+<title>10&#45;&gt;4</title>
+<path fill="none" stroke="black" d="M624.2,-71.7C615.64,-63.14 605.16,-52.66 595.8,-43.3"/>
+<polygon fill="black" stroke="black" points="598.15,-40.7 588.6,-36.1 593.2,-45.65 598.15,-40.7"/>
 </g>
 <!-- 10&#45;&gt;6 -->
 <g id="edge10" class="edge">
 <title>10&#45;&gt;6</title>
-<path fill="none" stroke="black" d="M624.2,-71.7C615.64,-63.14 605.16,-52.66 595.8,-43.3"/>
-<polygon fill="black" stroke="black" points="598.15,-40.7 588.6,-36.1 593.2,-45.65 598.15,-40.7"/>
+<path fill="none" stroke="black" d="M655.34,-71.7C661.99,-63.39 670.08,-53.28 677.39,-44.14"/>
+<polygon fill="black" stroke="black" points="680.3,-46.1 683.82,-36.1 674.84,-41.73 680.3,-46.1"/>
 </g>
 <!-- 9 -->
 <g id="node13" class="node">

Copy link
Contributor

@JackCrumpLeys JackCrumpLeys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at your code. it looks pretty good.
You will want to get all Effects in a entity layer and send it to all clients viewing that layer.

crates/valence_entity/src/active_status_effects.rs Outdated Show resolved Hide resolved
crates/valence_entity/src/active_status_effects.rs Outdated Show resolved Hide resolved
crates/valence_entity/src/active_status_effects.rs Outdated Show resolved Hide resolved
crates/valence_entity/src/active_status_effects.rs Outdated Show resolved Hide resolved

fn create_packet(effect: &ActiveStatusEffect) -> EntityStatusEffectS2c {
EntityStatusEffectS2c {
entity_id: VarInt(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you not taking entity id as a parameter? Does zero mean self? if I understand correctly every client in the same entity layer should receive the status effects of all entities in that layer. I understand if this is WIP disregard me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other parts of the code across Valence, the ID of the player is 0. The server always seems to tell the client that it's 0. That's just what I'm following. If I make it be the entity id, then the client doesn't seem to think that it has any effect and thus nothing happens.

crates/valence_entity/src/active_status_effects.rs Outdated Show resolved Hide resolved
crates/valence_entity/src/active_status_effects.rs Outdated Show resolved Hide resolved
crates/valence_server/src/status_effect.rs Outdated Show resolved Hide resolved
/// replaced.
///
/// [`EventLoopPostUpdate`]: https://docs.rs/valence_server/0.2.0-alpha.1+mc.1.20.1/valence_server/event_loop/struct.EventLoopPostUpdate.html
pub fn add(&mut self, effect: ActiveStatusEffect) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not check in active_effects and new_effects here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym?

&mut self.active_effects
}

fn remove_new_from_active(&mut self) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not needed if you take my other suggestion.

@rj00a rj00a self-requested a review October 11, 2023 12:38
This was referenced Oct 12, 2023
@SelfMadeSystem SelfMadeSystem deleted the branch valence-rs:main October 12, 2023 16:15
@SelfMadeSystem SelfMadeSystem deleted the main branch October 12, 2023 16:15
@SelfMadeSystem
Copy link
Contributor Author

I closed this because I wanted to rename the branch and I can't change branch in pull request. I'll open a new PR

@SelfMadeSystem SelfMadeSystem mentioned this pull request Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potion Effects
4 participants