Create Packet-Based Entities

Creating a Packet-Based Entity (PacketDisplayEntityPart)

//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
PacketDisplayEntityPart part = container.createPart(PartType.BLOCK_DISPLAY, spawnLocation);

//Player Visibility
part.showToPlayer(player, GroupSpawnedEvent.SpawnReason.CUSTOM);
part.hideFromPlayer(player);

//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);

Interaction Entity Example

Entity Tracking

Sending Data Changes

Last updated