fix(wrapper): streamline potion effect handling and packet creation

This commit is contained in:
Felipe Paschoal Bergamo 2025-04-01 11:25:33 -03:00
parent 0868a75617
commit 35111c0149
2 changed files with 20 additions and 19 deletions

View file

@ -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));
}
}

View file

@ -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;
}