Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public final class DisplayEntityGroup implements Serializable{
private final ArrayList<DisplayEntity> displayEntities = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class GroupSpawnSettings {
/**
* Set the teleportation duration for all display entities that will be spawned from {@link DisplayEntityGroup#spawn(Location, GroupSpawnedEvent.SpawnReason, GroupSpawnSettings)}.
* This has no effect on Interaction entities.
* @param teleportationDuration how long display entities should interpolate when teleporting, in ticks
* @param teleportationDuration how long display entities should interpolate when teleporting or changing their looking direction, in ticks
* @return this
*/
public GroupSpawnSettings setTeleportationDuration(int teleportationDuration) {
Expand Down Expand Up @@ -163,7 +163,12 @@ boolean applyVisibility(PacketDisplayEntityPart part, Player player){
}
}

boolean applyAttributes(PacketDisplayEntityPart part){
/**
* Apply this {@link GroupSpawnSettings} properties to a {@link PacketDisplayEntityPart}. This should generally not be used
* @param part the {@link PacketDisplayEntityPart}
*/
public void applyAttributes(PacketDisplayEntityPart part){
if (part == null) return;
if (part.isDisplay()){
//Teleport Duration
part.attributeContainer.setAttribute(DisplayAttributes.TELEPORTATION_DURATION, teleportationDuration);
Expand Down Expand Up @@ -204,11 +209,15 @@ boolean applyAttributes(PacketDisplayEntityPart part){
}
}
}
return true;
}


void apply(Display display){
/**
* Apply this {@link GroupSpawnSettings} properties to a {@link Display} entity. This should generally not be used
* @param display a display entity
*/
public void apply(Display display){
if (display == null) return;
//Determine Visibility
if (!visibleByDefault){
display.setVisibleByDefault(false);
Expand Down Expand Up @@ -271,7 +280,12 @@ void apply(Display display){
display.setPersistent(persistentByDefault);
}

void apply(Interaction interaction){
/**
* Apply this {@link GroupSpawnSettings} properties to an {@link Interaction} entity. This should generally not be used
* @param interaction an interaction entity
*/
public void apply(Interaction interaction){
if (interaction == null) return;
//Determine Visibility
if (!visibleByDefault || hideInteractions){
interaction.setVisibleByDefault(false);
Expand All @@ -295,7 +309,12 @@ void apply(Interaction interaction){
interaction.setPersistent(persistentByDefault);
}

void apply(Mannequin mannequin){
/**
* Apply this {@link GroupSpawnSettings} properties to an {@link Mannequin} entity. This should generally not be used
* @param mannequin a mannequin entity
*/
public void apply(Mannequin mannequin){
if (mannequin == null) return;
//Determine Visibility
if (!visibleByDefault){
mannequin.setVisibleByDefault(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import net.donnypz.displayentityutils.managers.holders.AsyncGroupHolder;
import net.donnypz.displayentityutils.utils.*;
import net.donnypz.displayentityutils.utils.DisplayEntities.machine.DisplayStateMachine;
import net.donnypz.displayentityutils.utils.bdengine.convert.file.BDEModel;
import net.donnypz.displayentityutils.utils.controller.DisplayControllerManager;
import net.donnypz.displayentityutils.utils.packet.DisplayAttributeMap;
import net.donnypz.displayentityutils.utils.packet.PacketAttributeContainer;
import net.donnypz.displayentityutils.utils.packet.attributes.DisplayAttributes;
import net.donnypz.displayentityutils.utils.version.folia.Scheduler;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Transformation;
Expand All @@ -44,6 +43,32 @@ public class PacketDisplayEntityGroup extends ActiveGroup<PacketDisplayEntityPar
boolean isPlaced;


@ApiStatus.Internal
public PacketDisplayEntityGroup(@NotNull BDEModel model, @NotNull Location spawnLoc, @NotNull GroupSpawnSettings settings){
updateChunkAndWorld(spawnLoc);
PacketDisplayEntityPart masterPart = new PacketAttributeContainer()
.setAttribute(DisplayAttributes.BlockDisplay.BLOCK_STATE, Material.AIR.createBlockData())
.createPart(SpawnedDisplayEntityPart.PartType.BLOCK_DISPLAY, spawnLoc);

masterPart.isMaster = true;
settings.applyAttributes(masterPart);
this.addPartSilent(masterPart);
passengerIds = new int[0];
model.addEntities(this, spawnLoc, settings);

if (settings.playSpawnAnimation){
this.playSpawnAnimation();
}
this.setAutoShow(settings);


if (DisplayConfig.autoCulling()){
float widthCullingAdder = DisplayConfig.widthCullingAdder();
float heightCullingAdder = DisplayConfig.heightCullingAdder();
this.autoCull(widthCullingAdder, heightCullingAdder);
}
}

PacketDisplayEntityGroup(String tag){
this.tag = tag;
}
Expand Down Expand Up @@ -215,6 +240,23 @@ public void addPart(@NotNull PacketDisplayEntityPart part){
updatePassengerIds(part.getEntityId(), true);
}

void addPartSilent(PacketDisplayEntityPart part){
if (groupParts.get(part.partUUID) == part) return;

if (part.partUUID == null){
do{
part.partUUID = UUID.randomUUID(); //for parts in old models that do not contain pdc data / part uuids AND new ungrouped parts
} while(groupParts.containsKey(part.partUUID));
}

if (part.isMaster) masterPart = part;
groupParts.put(part.partUUID, part);
part.group = this;
if (this.autoShow){
part.showToPlayers(getTrackingPlayers(), GroupSpawnedEvent.SpawnReason.INTERNAL);
}
}

/**
* {@inheritDoc}
* This will create a {@link PacketDisplayEntityPart} representative of the entity
Expand All @@ -227,29 +269,12 @@ public void addPart(@NotNull PacketDisplayEntityPart part){
return part;
}

void addPartSilent(PacketDisplayEntityPart part){
if (groupParts.get(part.partUUID) == part) return;

if (part.partUUID == null){
do{
part.partUUID = UUID.randomUUID(); //for parts in old models that do not contain pdc data / part uuids AND new ungrouped parts
} while(groupParts.containsKey(part.partUUID));
}

if (part.isMaster) masterPart = part;
groupParts.put(part.partUUID, part);
part.group = this;
if (this.autoShow){
part.showToPlayers(getTrackingPlayers(), GroupSpawnedEvent.SpawnReason.INTERNAL);
}
}

void updatePassengerIds(int passengerId, boolean add){
if (passengerIds == null) return;
int[] ids;
if (add){
ids = new int[passengerIds.length+1];
for (int i = 0; i < ids.length; i++){
for (int i = 0; i < passengerIds.length; i++){
int id = passengerIds[i];
if (id == passengerId) return;
ids[i] = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,13 @@ public SpawnedDisplayEntityGroup clone(@NotNull Location location, @NotNull Grou
}

public PacketDisplayEntityGroup toPacket(@NotNull Location location, boolean playSpawnAnimation, boolean autoShow, boolean persistent){
return toPacket(location, new GroupSpawnSettings()
.playSpawnAnimation(playSpawnAnimation)
.visibleByDefault(autoShow, null)
.persistentByDefault(persistent));
}

public PacketDisplayEntityGroup toPacket(@NotNull Location location, GroupSpawnSettings settings){
//Reset pivot to 0 yaw
float groupYaw = getLocation().getYaw();
HashSet<ActivePart> resettedParts = new HashSet<>();
Expand All @@ -1186,14 +1193,12 @@ public PacketDisplayEntityGroup toPacket(@NotNull Location location, boolean pla
location.setYaw(0);

PacketDisplayEntityGroup packetGroup;
if (persistent){
packetGroup = DisplayGroupManager.addPersistentPacketGroup(location, savedGroup, autoShow, GroupSpawnedEvent.SpawnReason.INTERNAL);
if (settings.persistentByDefault){
packetGroup = DisplayGroupManager
.addPersistentPacketGroup(location, savedGroup, settings, GroupSpawnedEvent.SpawnReason.INTERNAL);
}
else{
packetGroup = savedGroup.createPacketGroup(location, GroupSpawnedEvent.SpawnReason.INTERNAL,
new GroupSpawnSettings()
.visibleByDefault(autoShow, null)
.playSpawnAnimation(playSpawnAnimation));
packetGroup = savedGroup.createPacketGroup(location, GroupSpawnedEvent.SpawnReason.INTERNAL, settings);
}

//Restore pivot
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package net.donnypz.displayentityutils.utils.bdengine.convert.file;

import net.donnypz.displayentityutils.utils.DisplayEntities.GroupSpawnSettings;
import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityGroup;
import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityPart;
import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityPart;
import net.donnypz.displayentityutils.utils.packet.PacketAttributeContainer;
import net.donnypz.displayentityutils.utils.packet.attributes.DisplayAttributes;
import net.donnypz.displayentityutils.utils.version.VersionUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.BlockDisplay;
Expand All @@ -25,8 +32,16 @@ class BDEBlockDisplay extends BDEDisplay<BlockDisplay>{
}
}

@Override
PacketDisplayEntityPart createPart(Location spawnLocation) {
return new PacketAttributeContainer()
.setAttribute(DisplayAttributes.BlockDisplay.BLOCK_STATE, blockData != null ? blockData : Material.AIR.createBlockData())
.createPart(SpawnedDisplayEntityPart.PartType.BLOCK_DISPLAY, spawnLocation);
}

@Override
void apply(BlockDisplay display) {
if (blockData != null) display.setBlock(blockData);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.donnypz.displayentityutils.utils.bdengine.convert.file;

import net.donnypz.displayentityutils.utils.DisplayEntities.GroupSpawnSettings;
import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityGroup;
import org.bukkit.Location;
import org.bukkit.entity.BlockDisplay;

Expand Down Expand Up @@ -47,9 +49,16 @@ class BDECollection extends BDEObject{
}

@Override
void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection) {
void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection, GroupSpawnSettings settings) {
for (BDEObject obj : children){
obj.spawn(spawnLoc, parent, this);
obj.spawn(spawnLoc, parent, this, settings);
}
}

@Override
void spawnPacket(Location spawnLoc, PacketDisplayEntityGroup packetGroup, BDECollection parentCollection, GroupSpawnSettings settings) {
for (BDEObject obj : children){
obj.spawnPacket(spawnLoc, packetGroup, this, settings);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.donnypz.displayentityutils.utils.bdengine.convert.file;

import net.donnypz.displayentityutils.utils.DisplayEntities.GroupSpawnSettings;
import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityGroup;
import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityPart;
import net.donnypz.displayentityutils.utils.DisplayUtils;
import org.bukkit.Location;
import org.bukkit.entity.BlockDisplay;
Expand All @@ -23,19 +26,38 @@ abstract class BDEDisplay<T extends Display> extends BDEObject{

abstract void apply(T display);

abstract PacketDisplayEntityPart createPart(Location spawnLocation);

@Override
void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection){
void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection, GroupSpawnSettings settings){
Display display = spawnLoc.getWorld().spawn(spawnLoc, displayClass, d -> {
d.setBrightness(new Display.Brightness(brightness[0], brightness[1]));
settings.apply(d);
d.setTransformationMatrix(transformationMatrix);
d.setPersistent(false);

if (!parentCollection.isMaster){
DisplayUtils.addTags(d, parentCollection.upperCollections);
DisplayUtils.addTag(d, parentCollection.name);
}
apply(d);

});
parent.addPassenger(display);
}

@Override
void spawnPacket(Location spawnLoc, PacketDisplayEntityGroup packetGroup, BDECollection parentCollection, GroupSpawnSettings settings){
PacketDisplayEntityPart part = createPart(spawnLoc);

part.setBrightness(new Display.Brightness(brightness[0], brightness[1]));
settings.applyAttributes(part);
part.setTransformationMatrix(transformationMatrix);

if (!parentCollection.isMaster){
part.addTags(parentCollection.upperCollections);
part.addTag(parentCollection.name);
}

packetGroup.addPart(part);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.destroystokyo.paper.profile.PlayerProfile;
import com.destroystokyo.paper.profile.ProfileProperty;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityPart;
import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityPart;
import net.donnypz.displayentityutils.utils.packet.PacketAttributeContainer;
import net.donnypz.displayentityutils.utils.packet.attributes.DisplayAttributes;
import org.bukkit.*;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
Expand Down Expand Up @@ -34,6 +35,19 @@ class BDEItemDisplay extends BDEDisplay<ItemDisplay> {

@Override
void apply(ItemDisplay display) {
display.setItemStack(getItem());
display.setItemDisplayTransform(transform);
}

@Override
PacketDisplayEntityPart createPart(Location spawnLocation) {
return new PacketAttributeContainer()
.setAttribute(DisplayAttributes.ItemDisplay.ITEMSTACK, getItem())
.setAttribute(DisplayAttributes.ItemDisplay.ITEM_DISPLAY_TRANSFORM, transform)
.createPart(SpawnedDisplayEntityPart.PartType.ITEM_DISPLAY, spawnLocation);
}

private ItemStack getItem(){
Material material = Registry.MATERIAL.get(NamespacedKey.minecraft(name.toLowerCase()));
if (material != null){
ItemStack item = new ItemStack(material);
Expand All @@ -46,11 +60,10 @@ void apply(ItemDisplay display) {
meta.setPlayerProfile(profile);
item.setItemMeta(meta);
}
display.setItemStack(item);
return item;
}
else{
display.setItemStack(ItemStack.empty());
return ItemStack.empty();
}
display.setItemDisplayTransform(transform);
}
}
Loading
Loading