From 35111c0149024926397c36036457df273571cfef Mon Sep 17 00:00:00 2001 From: Felipe Paschoal Bergamo <64669985+felipepasc@users.noreply.github.com> Date: Tue, 1 Apr 2025 11:25:33 -0300 Subject: [PATCH] fix(wrapper): streamline potion effect handling and packet creation --- .../entitylib/wrapper/WrapperEntity.java | 8 ++--- .../wrapper/WrapperEntityPotionEffect.java | 31 +++++++++++-------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java index ed5c58c..eb65d0c 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java @@ -93,9 +93,7 @@ public class WrapperEntity implements Tickable { if (this instanceof WrapperLivingEntity) { WrapperLivingEntity wrapperLivingEntity = (WrapperLivingEntity) this; - wrapperLivingEntity.createSpawnPackets().forEach(packetWrapper -> { - sendPacket(uuid, packetWrapper); - }); + wrapperLivingEntity.createSpawnPackets().forEach(packetWrapper -> sendPacket(uuid, packetWrapper)); } this.parent = parent; @@ -219,9 +217,7 @@ public class WrapperEntity implements Tickable { if (this instanceof WrapperLivingEntity) { WrapperLivingEntity wrapperLivingEntity = (WrapperLivingEntity) this; - wrapperLivingEntity.createSpawnPackets().forEach(packetWrapper -> { - sendPacket(uuid, packetWrapper); - }); + wrapperLivingEntity.createSpawnPackets().forEach(packetWrapper -> sendPacket(uuid, packetWrapper)); } } diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityPotionEffect.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityPotionEffect.java index f6c123f..50a2705 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityPotionEffect.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityPotionEffect.java @@ -40,15 +40,11 @@ public class WrapperEntityPotionEffect implements Tickable { boolean showIcons, @Nullable NBTCompound factorData ) { - this.effects.put(type, new WrapperPotionEffect( - type, - amplifier, - duration, - ambient, - visible, - showIcons, - factorData - )); + WrapperPotionEffect effect = new WrapperPotionEffect(type, amplifier, duration, ambient, visible, showIcons, factorData); + + this.effects.put(type, effect); + + this.entity.sendPacketToViewers(createEffectPacket(effect)); } /** @@ -149,16 +145,25 @@ public class WrapperEntityPotionEffect implements Tickable { remainingDuration = Math.max(duration - elapsedTicks, 0); } - WrapperPlayServerEntityEffect wrapperPlayServerEntityEffect = new WrapperPlayServerEntityEffect(0, null, 0, 0, (byte) 0); + int flags = 0; + + flags |= ambient ? 1 : 0; // Bit 0 para ambient + flags |= visible ? (1 << 1) : 0; // Bit 1 para visible + flags |= icons ? (1 << 2) : 0; // Bit 2 para icons + + WrapperPlayServerEntityEffect wrapperPlayServerEntityEffect = new WrapperPlayServerEntityEffect( + 0, + null, + 0, + 0, + (byte) flags + ); wrapperPlayServerEntityEffect.setEntityId(this.entity.getEntityId()); wrapperPlayServerEntityEffect.setPotionType(potionType); wrapperPlayServerEntityEffect.setEffectAmplifier(amplifier); wrapperPlayServerEntityEffect.setEffectDurationTicks(remainingDuration); wrapperPlayServerEntityEffect.setFactorData(factorData); - wrapperPlayServerEntityEffect.setAmbient(ambient); - wrapperPlayServerEntityEffect.setVisible(visible); - wrapperPlayServerEntityEffect.setShowIcon(icons); return wrapperPlayServerEntityEffect; }