mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
fix: boss bars & effects (#1766)
* fix: integer overflow & infinite effects * fix: bossbar encoding * fix formatting
This commit is contained in:
@@ -7,6 +7,7 @@ use color::Color;
|
||||
use colored::Colorize;
|
||||
use core::str;
|
||||
use hover::HoverEvent;
|
||||
use pumpkin_nbt::serializer::Serializer;
|
||||
use serde::de::{Error, MapAccess, SeqAccess, Visitor};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use std::borrow::Cow;
|
||||
@@ -445,7 +446,11 @@ impl TextComponent {
|
||||
pub fn encode(&self) -> Box<[u8]> {
|
||||
let mut buf = Vec::new();
|
||||
// TODO: Properly handle errors
|
||||
pumpkin_nbt::serializer::to_bytes_unnamed(&self, &mut buf)
|
||||
let mut serializer = Serializer::new(&mut buf, None);
|
||||
self.0
|
||||
.clone()
|
||||
.to_translated()
|
||||
.serialize(&mut serializer)
|
||||
.expect("Failed to serialize text component NBT for encode");
|
||||
|
||||
buf.into_boxed_slice()
|
||||
|
||||
@@ -437,7 +437,7 @@ impl LivingEntity {
|
||||
Operation::AddMultipliedBase => ModifierOperation::MultiplyBase,
|
||||
Operation::AddMultipliedTotal => ModifierOperation::MultiplyTotal,
|
||||
};
|
||||
let scaled_amount = m.base_value * f64::from(effect.amplifier + 1);
|
||||
let scaled_amount = m.base_value * (f64::from(effect.amplifier) + 1.);
|
||||
let mod_inst = Modifier {
|
||||
id: uuid,
|
||||
amount: scaled_amount,
|
||||
@@ -1328,7 +1328,8 @@ impl LivingEntity {
|
||||
{
|
||||
let mut effects = self.active_effects.lock().await;
|
||||
for effect in effects.values_mut() {
|
||||
if effect.duration <= 0 {
|
||||
// A duration below 0 means the effect is infinite
|
||||
if effect.duration == 0 {
|
||||
effects_to_remove.push(effect.effect_type);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2395,7 +2395,6 @@ impl Player {
|
||||
}
|
||||
|
||||
pub async fn add_effect(&self, effect: Effect) {
|
||||
self.send_effect(effect.clone()).await;
|
||||
self.living_entity.add_effect(effect).await;
|
||||
}
|
||||
|
||||
@@ -2406,6 +2405,10 @@ impl Player {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a clientside only effect to the player.
|
||||
* It won't be tracked on the server.
|
||||
*/
|
||||
pub async fn send_effect(&self, effect: Effect) {
|
||||
let mut flag: i8 = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user