From 6c2049e1f6f830e2c23adbb9349ea50ca8a6b534 Mon Sep 17 00:00:00 2001 From: Logan <37521985+LoJoSho@users.noreply.github.com> Date: Sun, 7 Sep 2025 21:34:53 -0500 Subject: [PATCH] feat: add generic invisible entity bundled packet (cherry picked from commit 90f6a2a3f2cdc1cc1e6d4580f50aab608130b33a) --- .../hibiscuscommons/nms/NMSPackets.java | 2 ++ .../nms/v1_20_R4/NMSPackets.java | 19 +++++++++++++++++ .../nms/v1_21_R1/NMSPackets.java | 21 +++++++++++++++++-- .../nms/v1_21_R2/NMSPackets.java | 21 +++++++++++++++++-- .../nms/v1_21_R3/NMSPackets.java | 19 +++++++++++++++++ .../nms/v1_21_R4/NMSPackets.java | 19 +++++++++++++++++ .../nms/v1_21_R5/NMSPackets.java | 19 +++++++++++++++++ 7 files changed, 116 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSPackets.java b/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSPackets.java index 4fdd474..c7c6e01 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSPackets.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSPackets.java @@ -102,5 +102,7 @@ public interface NMSPackets { // The mask here is for is the armorstand is on fire or not. void sendInvisibleArmorstand(int entityId, Location location, UUID uuid, byte mask, List sendTo); + void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo); + Object createMountPacket(int entityId, int[] passengerIds); } diff --git a/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPackets.java b/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPackets.java index 69c143f..ea5a734 100644 --- a/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPackets.java +++ b/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPackets.java @@ -58,6 +58,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. private static ServerLevel level = MinecraftServer.getServer().overworld(); private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects + private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") @@ -508,4 +509,22 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); for (Player p : sendTo) sendPacket(p, bundlePacket); } + + @Override + public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { + net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + float yaw = location.getYaw(); + float pitch = location.getPitch(); + Vec3 velocity = Vec3.ZERO; + float headYaw = 0f; + + final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); + final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); + + ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); + sendPacket(sendTo, bundlePacket); + } } diff --git a/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPackets.java b/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPackets.java index d8e043f..6447cc3 100644 --- a/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPackets.java +++ b/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPackets.java @@ -1,7 +1,6 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R1; import com.google.common.collect.ImmutableList; -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; @@ -10,7 +9,6 @@ import com.mojang.serialization.JsonOps; import io.papermc.paper.adventure.PaperAdventure; import it.unimi.dsi.fastutil.ints.IntList; import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; -import me.lojosho.hibiscuscommons.nms.v1_21_R1.NMSCommon; import me.lojosho.hibiscuscommons.util.AdventureUtils; import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.kyori.adventure.text.Component; @@ -60,6 +58,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. private static ServerLevel level = MinecraftServer.getServer().overworld(); private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects + private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") @@ -510,4 +509,22 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); for (Player p : sendTo) sendPacket(p, bundlePacket); } + + @Override + public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { + net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + float yaw = location.getYaw(); + float pitch = location.getPitch(); + Vec3 velocity = Vec3.ZERO; + float headYaw = 0f; + + final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); + final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); + + ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); + sendPacket(sendTo, bundlePacket); + } } diff --git a/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPackets.java b/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPackets.java index 7d9ffc6..05a3757 100644 --- a/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPackets.java +++ b/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPackets.java @@ -1,7 +1,6 @@ package me.lojosho.hibiscuscommons.nms.v1_21_R2; import com.google.common.collect.ImmutableList; -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; @@ -10,7 +9,6 @@ import com.mojang.serialization.JsonOps; import io.papermc.paper.adventure.PaperAdventure; import it.unimi.dsi.fastutil.ints.IntList; import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; -import me.lojosho.hibiscuscommons.nms.v1_21_R2.NMSCommon; import me.lojosho.hibiscuscommons.util.AdventureUtils; import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.kyori.adventure.text.Component; @@ -61,6 +59,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. private static ServerLevel level = MinecraftServer.getServer().overworld(); private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects + private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") @@ -508,4 +507,22 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); for (Player p : sendTo) sendPacket(p, bundlePacket); } + + @Override + public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { + net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + float yaw = location.getYaw(); + float pitch = location.getPitch(); + Vec3 velocity = Vec3.ZERO; + float headYaw = 0f; + + final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); + final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); + + ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); + sendPacket(sendTo, bundlePacket); + } } diff --git a/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPackets.java b/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPackets.java index dc537aa..758c3f3 100644 --- a/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPackets.java +++ b/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPackets.java @@ -61,6 +61,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. private static ServerLevel level = MinecraftServer.getServer().overworld(); private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects + private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") @@ -544,4 +545,22 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); for (Player p : sendTo) sendPacket(p, bundlePacket); } + + @Override + public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { + net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + float yaw = location.getYaw(); + float pitch = location.getPitch(); + Vec3 velocity = Vec3.ZERO; + float headYaw = 0f; + + final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); + final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); + + ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); + sendPacket(sendTo, bundlePacket); + } } diff --git a/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPackets.java b/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPackets.java index 8073da9..bd485b3 100644 --- a/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPackets.java +++ b/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPackets.java @@ -61,6 +61,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. private static ServerLevel level = MinecraftServer.getServer().overworld(); private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects + private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") @@ -544,4 +545,22 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); for (Player p : sendTo) sendPacket(p, bundlePacket); } + + @Override + public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { + net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + float yaw = location.getYaw(); + float pitch = location.getPitch(); + Vec3 velocity = Vec3.ZERO; + float headYaw = 0f; + + final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); + final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); + + ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); + sendPacket(sendTo, bundlePacket); + } } diff --git a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java index 4fa132d..f1d3c0a 100644 --- a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java +++ b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java @@ -58,6 +58,7 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. private static ServerLevel level = MinecraftServer.getServer().overworld(); private static final Map CLOUD_EFFECT_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20, 8, 0f); // For cloud effects + private static final Map GENERIC_INVISIBLE_DATA_VALUES = Map.of(0, (byte) 0x20); // For most entities if you just need genericaly invisible private static Entity fakeNmsEntity = new ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, level); @Override @SuppressWarnings("unchecked") @@ -542,4 +543,22 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); for (Player p : sendTo) sendPacket(p, bundlePacket); } + + @Override + public void sendInvisibleEntity(int entityId, EntityType type, Location location, UUID uuid, List sendTo) { + net.minecraft.world.entity.EntityType nmsEntityType = CraftEntityType.bukkitToMinecraft(type); + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + float yaw = location.getYaw(); + float pitch = location.getPitch(); + Vec3 velocity = Vec3.ZERO; + float headYaw = 0f; + + final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket(entityId, uuid, x, y, z, yaw, pitch, nmsEntityType, 0, velocity, headYaw); + final ClientboundSetEntityDataPacket dataPacket = getSharedEntityPacket(entityId, GENERIC_INVISIBLE_DATA_VALUES); + + ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(List.of(spawnPacket, dataPacket)); + sendPacket(sendTo, bundlePacket); + } }