From a6070ef5cc1324418c2ba53681e10c28d5ee3bcd Mon Sep 17 00:00:00 2001 From: Tofaa <82680183+Tofaa2@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:29:23 +0400 Subject: [PATCH] some more methods for entities --- .../entitylib/wrapper/WrapperEntity.java | 9 ++++ .../wrapper/WrapperLivingEntity.java | 52 +++++++++++++++++++ 2 files changed, 61 insertions(+) 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 a844400..31177c2 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java @@ -11,6 +11,7 @@ import me.tofaa.entitylib.TrackedEntity; import me.tofaa.entitylib.meta.EntityMeta; import me.tofaa.entitylib.meta.types.ObjectData; import me.tofaa.entitylib.tick.Tickable; +import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -158,6 +159,14 @@ public class WrapperEntity implements Tickable, TrackedEntity { } } + public void sendMessageToViewers(Component message) { + sendPacketToViewers(new WrapperPlayServerSystemChatMessage(false, message)); + } + + public void sendActionbarToViewers(Component message) { + sendPacketToViewers(new WrapperPlayServerSystemChatMessage(true, message)); + } + protected WrapperPlayServerSpawnEntity createSpawnPacket() { return new WrapperPlayServerSpawnEntity( entityId, diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java index 1e6d69e..26fa8e2 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java @@ -1,10 +1,14 @@ package me.tofaa.entitylib.wrapper; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; +import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; import com.github.retrooper.packetevents.protocol.player.HumanoidArm; +import com.github.retrooper.packetevents.protocol.potion.PotionType; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect; import me.tofaa.entitylib.meta.EntityMeta; import me.tofaa.entitylib.meta.types.LivingEntityMeta; +import org.jetbrains.annotations.Nullable; import java.util.UUID; @@ -23,6 +27,54 @@ public class WrapperLivingEntity extends WrapperEntity{ equipment.refresh(); } + /** + * Adds a potion effect to the entity. + * EntityLib will not keep track of the potions you give or what you do with them, + * this simply sends the packet to the viewers of the entity. + * @param type The type of the potion effect {@link com.github.retrooper.packetevents.protocol.potion.PotionTypes} + * @param amplifier The amplifier of the potion effect. The notchian client displays the number as (amplifier + 1) + * @param duration The duration of the potion effect in ticks, if set to -1 the client will display the effect as infinite + * @param flags The bit flags of the potion effect see: https://wiki.vg/Protocol#Entity_Effect + * @param hasFactorData Whether the potion effect has factor data + * @param factorData The factor data of the potion effect, if hasFactorData is false this will be ignored + */ + public void addPotionEffect( + PotionType type, + int amplifier, + int duration, + byte flags, + boolean hasFactorData, + @Nullable NBTCompound factorData + ) { + sendPacketToViewers( + new WrapperPlayServerEntityEffect( + getEntityId(), + type, + amplifier, + duration, + flags + ) + ); + } + + /** + * Adds a potion effect to the entity. + * EntityLib will not keep track of the potions you give or what you do with them, + * this simply sends the packet to the viewers of the entity. + * @param type The type of the potion effect {@link com.github.retrooper.packetevents.protocol.potion.PotionTypes} + * @param amplifier The amplifier of the potion effect. The notchian client displays the number as (amplifier + 1) + * @param duration The duration of the potion effect in ticks, if set to -1 the client will display the effect as infinite + * @param flags The bit flags of the potion effect see: https://wiki.vg/Protocol#Entity_Effect + */ + public void addPotionEffect( + PotionType type, + int amplifier, + int duration, + byte flags + ) { + addPotionEffect(type, amplifier, duration, flags, false, null); + } + public void playCriticalHitAnimation() { sendAnimation(WrapperPlayServerEntityAnimation.EntityAnimationType.CRITICAL_HIT); }