-
Notifications
You must be signed in to change notification settings - Fork 6
Create Packet Entities and Packet Groups
Jay edited this page Oct 22, 2025
·
8 revisions
- Packet Entities can be internally (automatically) tracked by DisplayEntityUtils
- Packet Entities are typically removed from the player's client when the player disconnects or changes worlds. DEU's internal tracking offers a workaround for this vanilla behavior
- Use the
PacketAttributeContainer#createPartas shown below to use internal tracking,
//Building a 2.0 Scale Block Display Grass Block
PacketAttributeContainer container = new PacketAttributeContainer(); //Used to hold/supply entity attributes and used to build entities
container.setAttribute(DisplayAttributes.Transform.SCALE, new Vector3f(2f)) //Set scale to 2.0
.setAttribute(DisplayAttributes.BlockDisplay.BLOCK_STATE, BlockType.GRASS_BLOCK.createBlockData()) //Set Block Display's Block
.setAttribute(DisplayAttributes.BRIGHTNESS, new Display.Brightness(15, 15)) //Set the brightness
//Create the part (with internal tracking)
PacketDisplayEntityPart part = container.createPart(PartType.BLOCK_DISPLAY, spawnLocation);
//Player Visibility
part.showToPlayer(player, GroupSpawnedEvent.SpawnReason.CUSTOM); //Begin internal tracking of this part
part.hideFromPlayer(player); //Stop internal tracking of this part
//Entities can also be sent to players by using the method below,
//but the entity will not be internally tracked by DisplayEntityUtils
//The same container can be used to hold the entity's data and to send data changes
container.sendEntity(PartType.BLOCK_DISPLAY, player, spawnLocation);PacketAttributeContainer container = new PacketAttributeContainer();
container.setAttribute(DisplayAttributes.Interaction.WIDTH, 2f)
.setAttribute(DisplayAttributes.Interaction.HEIGHT, 5f)
.setAttribute(DisplayAttributes.Interaction.RESPONSIVE, true);
//Creates a packet based interaction entity, with internal entity tracking for the players it is sent to
PacketDisplayEntityPart interactionPart = container.createPart(PartType.INTERACTION, spawnLocation);DEUUser user = DEUUser.getOrCreateUser(player);
PacketDisplayEntityPart part = yourMethodToGetAPacketDisplayEntityPart();
//Get whether a user is tracking the given part
boolean isTracking = part.isTrackedBy(player);
Collection<UUID> viewers = part.getViewers(); //Get a UUID collection of all players who are tracking the part
Collection<Player> players = part.getTrackingPlayers(); //Get a Player Collection of all players who are tracking the part//Create a packet based model that works similarly to a SpawnedDisplayEntityGroup, just with packet based parts
DisplayEntityGroup savedGroup = yourMethodToGetADisplayEntityGroup();
boolean playSpawnAnimation = false;
PacketDisplayEntityGroup packetGroup = savedGroup.createPacketGroup(spawnLocation, playSpawnAnimation);
//Player Visibility
packetGroup.showToPlayer(player, GroupSpawnedEvent.SpawnReason.CUSTOM); //Begin internal tracking of all parts in this group
packetGroup.hideFromPlayer(player); //Stop internal tracking of all parts in this group
//Automatically Show to Players
packetGroup.setAutoShow(true);//Sending data changes from a part, to all viewers of part
part.setAttribute(DisplayAttributes.GLOWING, false); //Sets the glowing attribute of this part to false for all players tracking the part
//Send many data changes from a part, to all viewers of part
//This is more optimal over setting a single attribute multiple times
DisplayAttributeMap map = new DisplayAttributeMap();
map.add(DisplayAttributes.Shadow.RADIUS, 32f)
.add(DisplayAttributes.Shadow.STRENGTH, 1f);
part.setAttribtues(map); //Send the attributes of the map to all players tracking the part
PacketAttributeContainer container = new PacketAttributeContainer();
container.setAttribute(DisplayAttributes.GLOWING, false);
//Send the attribute update to a specific player
int entityId = part.getEntityId(); //The entityId can be the id of any entity that can have the given attribute(s) applied
container.sendAttributes(player, entityId);
//Set and send the given attribute at the same time
container.setAndSendAttribute(DisplayAttributes.BILLBOARD, Display.Billboard.CENTER, entityId, player);