#CustomBee PDC not working right

1 messages · Page 1 of 1 (latest)

tame grail
#
    @EventHandler
    public void join(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        ServerLevel world = ((CraftWorld) player.getLocation().getWorld()).getHandle();
        CustomBee customBee = new CustomBee(player.getLocation(), ColorUtil.color("Bee"), true);
        world.tryAddFreshEntityWithPassengers(customBee);

        testbee.setBeeUUID(customBee.getBukkitEntity(), customBee.getBukkitEntity().getUniqueId());
        Bukkit.broadcastMessage(testbee.getBeeUUID(customBee.getBukkitEntity()) + "");
    }

    public static String toNbtString(Entity bukkitEntity) {
        CompoundTag tag = new CompoundTag();
        ((CraftEntity) bukkitEntity).getHandle().save(tag);
        return tag.getAsString();
    }

The above is how im setting the PDC on my entity. The broadcast gives me the correct value. I have events for when a bee enters and exits a hive below

    @EventHandler
    public void EnterHive(EntityEnterBlockEvent event) {
        if (event.getBlock().getType().equals(Material.BEEHIVE)) {
            if(event.getEntity().getCustomName() != null & event.getEntity().getCustomName().equalsIgnoreCase("Bee")) {
                Bukkit.getLogger().info("IN: " + toNbtString(event.getEntity()));
            }
        }
    }

    @EventHandler
    public void creatureSpawn(CreatureSpawnEvent event) {
        if(event.getEntity().getType().equals(EntityType.BEE)) {
            if(event.getEntity().getCustomName() != null & event.getEntity().getCustomName().equalsIgnoreCase("Bee")) {
                Bukkit.getLogger().info("OUT: " + toNbtString(event.getEntity()));
            }
        }
    }

For some reason my custom PDC value is never included in this list

#
    public void setBeeUUID(Bee bee, UUID uuid) {
        NamespacedKey beeUUIDKey = new NamespacedKey(this, "bee-uuid");
        bee.getPersistentDataContainer().set(beeUUIDKey, PersistentDataType.STRING, uuid.toString());
    }

    public UUID getBeeUUID(Bee bee) {
        NamespacedKey beeUUIDKey = new NamespacedKey(this, "bee-uuid");

        if(bee.getPersistentDataContainer().has(beeUUIDKey, PersistentDataType.STRING)) {
            return UUID.fromString(Objects.requireNonNull(bee.getPersistentDataContainer().get(beeUUIDKey, PersistentDataType.STRING)));
        }

        return null;
    }
#

Getter and setter for the PDC

#

Nowhere does it include the bee-uuid key I made

untold yew
#

NMS's toNbtString doesn't save PDC

#

You need to use CraftEntity#storeBukkitValues(CompundTag) method

#

@tame grail

tame grail
#

weird..

#

it was working for @weak skiff

#

he made the function

untold yew
#

ok nvm saveWithoutId saves that stuff

tame grail
#

So I do or dont need savewithoutid

untold yew
#

uhh

#

if you ever call CustomBee#getBukkitEntity()

tame grail
#

I do

untold yew
#

It will create the bukkitentity

tame grail
#

is that good or bad

#

I would assume that if I set the pdc of the bukkit entity

#

then get the bukkit entity later..it should still have the value.

untold yew
#

try calling getBukkitEntity on the constructor

tame grail
#

I dont get why I gotta do all this hocus pocus for something that should be siimple heh

#

Tried with savewithoutid, still didnt save

#

well

#

it didnt output with the nbt

#

but if I get it from the pdc it works until it enters the hive.

#
[18:39:24] [Server thread/INFO]: OUT: null
[18:39:29] [Server thread/INFO]: IN: 2ad804e0-7c51-4009-bde3-b9d78e2a2aea
[18:39:53] [Server thread/INFO]: IN: null
[18:40:50] [Server thread/INFO]: OUT: null
>
#

the null in is just a random bee in the world entering

#

but the null out is the same bee that had a value going in, then losing its value.

untold yew
#

oh that's trippy

tame grail
#

yeppp...

#

the pdc gets completely wiped the second it enters the hive.

untold yew
#

there's a method for removing tags but pdc shouldn't be part of it

tame grail
#

🤷‍♂️

#

I dont get it.

#

PDC isnt very P

untold yew
#

check nbt tags

#

most tags get wiped within the beehive

#

Specifically

#

private static final List<String> IGNORED_BEE_TAGS = Arrays.asList("Air", "ArmorDropChances", "ArmorItems", "Brain", "CanPickUpLoot", "DeathTime", "FallDistance", "FallFlying", "Fire", "HandDropChances", "HandItems", "HurtByTimestamp", "HurtTime", "LeftHanded", "Motion", "NoGravity", "OnGround", "PortalCooldown", "Pos", "Rotation", "CannotEnterHiveTicks", "TicksSincePollination", "CropsGrownSincePollination", "HivePos", "Passengers", "Leash", "UUID");

tame grail
#

yeah but it shouldnt wipe my custom one

untold yew
#

hm

tame grail
#
[18:47:19] [Server thread/INFO]: IN: {AbsorptionAmount:0.0f,Age:-23496,AgeLocked:0b,Air:300s,AngerTime:0,ArmorDropChances:[0.085f,0.085f,0.085f,0.085f],ArmorItems:[{},{},{},{}],Attributes:[{Base:0.30000001192092896d,Name:"minecraft:generic.movement_speed"},{Base:10.0d,Name:"minecraft:generic.max_health"}],Brain:{memories:{}},Bukkit.Aware:1b,Bukkit.updateLevel:2,CanPickUpLoot:0b,CannotEnterHiveTicks:0,CropsGrownSincePollination:0,CustomName:'{"extra":[{"text":"Bee"}],"text":""}',CustomNameVisible:1b,DeathTime:0s,FallDistance:0.0f,FallFlying:0b,Fire:-1s,FlowerPos:{X:205,Y:-60,Z:-496},ForcedAge:0,Glowing:1b,HandDropChances:[0.085f,0.085f],HandItems:[{},{}],HasNectar:1b,HasStung:0b,Health:10.0f,HivePos:{X:206,Y:-60,Z:-492},HurtByTimestamp:0,HurtTime:0s,InLove:0,Invulnerable:0b,LeftHanded:0b,Motion:[0.034341133299390654d,-0.11716998101844606d,0.0965369799458191d],NoGravity:1b,OnGround:0b,PersistenceRequired:0b,PortalCooldown:0,Pos:[205.77152768444543d,-59.41981236616803d,-493.24421954445285d],Rotation:[317.978f,0.0f],Spigot.ticksLived:505,TicksSincePollination:0,UUID:[I;1834084787,771443132,-1761275711,257207896],WorldUUIDLeast:-5526025201707824336L,WorldUUIDMost:4772959422628644230L}
#

This is when it enters

#

so apparently the value is never even set inside the nbt?

untold yew
#

odd

tame grail
#

what is

untold yew
#

try checking the removal reason

#

specifically RemovalReason#shouldSave

tame grail
untold yew
#

Entity#removalReason

#

these internals are a bit painful

tame grail
#

removalReason on the entityenterblockevent...?

untold yew
#

nms

tame grail
#

im 110% lost

#

why am I checking it if its not being removed or whatever

#

like

#

just chuck it in the middle of code somewhere? or

untold yew
#

the removal cause influences whether nbt is saved or not

tame grail
#

So I need to set the removalreason?

#
Caused by: java.lang.NoSuchMethodError: 'net.minecraft.world.entity.Entity$RemovalReason com.squallz.testbee.CustomBee.dv()'
        at com.squallz.testbee.CustomBeeListener.join(CustomBeeListener.java:50) ~[?:?]
#
    @EventHandler
    public void join(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        ServerLevel world = ((CraftWorld) player.getLocation().getWorld()).getHandle();
        CustomBee customBee = new CustomBee(player.getLocation(), ColorUtil.color("Bee"), true);
        world.tryAddFreshEntityWithPassengers(customBee);

        testbee.setBeeUUID(customBee.getBukkitEntity(), customBee.getBukkitEntity().getUniqueId());
        Bukkit.broadcastMessage("" + customBee.getRemovalReason().shouldSave());
        Bukkit.broadcastMessage(testbee.getBeeUUID(customBee.getBukkitEntity()) + "");
    }
untold yew
#

are you using mappings different to your server 👀

tame grail
#

Uhhhhhhh

#

shouldnt be

#

havent had any issues before

#

im using mojang mappings

#

Do normal entities not have removal reasons?

#

it only shows as an option for my custombee

tame grail
#

@weak skiff How were you able to store custom stuff in the nbt data

#

it doesnt do it for me.

tame grail
#

😦

tame grail
#
package com.squallz.testbee;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftBee;

import java.util.UUID;

public class CustomBee extends Bee {
    private String beeName;
    private CraftBee bukkitEntity;
    private UUID originalBeeUUID;

    public CustomBee(Location location, String beeName, Boolean isBaby) {
        super(EntityType.BEE, ((CraftWorld) location.getWorld()).getHandle());
        this.setCanPickUpLoot(false);
        this.setPos(location.getX(), location.getY(), location.getZ());
        getBukkitEntity().setCustomName(ColorUtil.color(beeName));
        getBukkitEntity().setCustomNameVisible(true);
        getBukkitEntity().setPersistent(true);
        getBukkitEntity().setGlowing(true);
        if(isBaby) {
            getBukkitEntity().setBaby();
        }
    }

    public CustomBee(EntityType entityType, Level level) {
        super(EntityType.BEE, level);
    }

    public String getBeeName() {
        return this.beeName;
    }

    public void setBeeName(String beeName) {
        this.beeName = beeName;
    }

    @Override
    public final CraftBee getBukkitEntity() {
        if (this.bukkitEntity == null) {
            this.bukkitEntity = new CraftBee(this.level.getCraftServer(), this);
        }

        return this.bukkitEntity;
    }

    @Override
    public boolean save(CompoundTag nbt) {
        boolean returnVal = super.save(nbt);

        nbt.putString("bee-uuid", uuid.toString());

        return returnVal;
    }

    @Override
    public void load(CompoundTag nbt) {
        super.load(nbt);

        String beeUUID = nbt.getString("bee-uuid");

        this.originalBeeUUID = UUID.fromString(beeUUID);
    }

    public UUID getOriginalBeeUUID() {
        return this.originalBeeUUID;
    }
}

heres my latest custombee

#

@untold yew

#
[22:55:21] [Server thread/INFO]: IN: {AbsorptionAmount:0.0f,Age:0,AgeLocked:0b,Air:300s,AngerTime:0,ArmorDropChances:[0.085f,0.085f,0.085f,0.085f],ArmorItems:[{},{},{},{}],Attributes:[{Base:0.30000001192092896d,Name:"minecraft:generic.movement_speed"},{Base:10.0d,Name:"minecraft:generic.max_health"}],Brain:{memories:{}},Bukkit.Aware:1b,Bukkit.updateLevel:2,CanPickUpLoot:0b,CannotEnterHiveTicks:0,CropsGrownSincePollination:0,CustomName:'{"extra":[{"text":"Bee"}],"text":""}',CustomNameVisible:1b,DeathTime:0s,FallDistance:0.0f,FallFlying:0b,Fire:-1s,FlowerPos:{X:134,Y:-60,Z:-399},ForcedAge:0,Glowing:1b,HandDropChances:[0.085f,0.085f],HandItems:[{},{}],HasNectar:1b,HasStung:0b,Health:7.0f,HivePos:{X:136,Y:-60,Z:-403},HurtByTimestamp:0,HurtTime:0s,InLove:0,Invulnerable:0b,LeftHanded:0b,Motion:[0.0614533440481778d,-0.1230388898662513d,-0.08962973336701233d],NoGravity:1b,OnGround:0b,PersistenceRequired:0b,PortalCooldown:0,Pos:[135.93009861546128d,-59.45264107018402d,-400.82406470228705d],Rotation:[219.45749f,0.0f],Spigot.ticksLived:266449,TicksSincePollination:0,UUID:[I;-1865840631,-708819875,-1397807131,-2123765309],WorldUUIDLeast:-5526025201707824336L,WorldUUIDMost:4772959422628644230L}
[22:56:01] [Server thread/INFO]: OUT: {AbsorptionAmount:0.0f,Age:-23399,AgeLocked:0b,Air:300s,AngerTime:0,ArmorDropChances:[0.085f,0.085f,0.085f,0.085f],ArmorItems:[{},{},{},{}],Attributes:[{Base:0.30000001192092896d,Name:"minecraft:generic.movement_speed"},{Base:10.0d,Name:"minecraft:generic.max_health"}],Brain:{memories:{}},Bukkit.Aware:1b,Bukkit.updateLevel:2,CanPickUpLoot:0b,CannotEnterHiveTicks:0,CropsGrownSincePollination:0,CustomName:'{"extra":[{"text":"Bee"}],"text":""}',CustomNameVisible:1b,DeathTime:0s,FallDistance:0.0f,FallFlying:0b,Fire:0s,FlowerPos:{X:205,Y:-60,Z:-496},ForcedAge:0,Glowing:1b,HandDropChances:[0.085f,0.085f],HandItems:[{},{}],HasNectar:1b,HasStung:0b,Health:10.0f,HivePos:{X:206,Y:-60,Z:-492},HurtByTimestamp:0,HurtTime:0s,InLove:0,Invulnerable:0b,LeftHanded:0b,Motion:[0.0d,0.0d,0.0d],NoGravity:1b,OnGround:0b,PersistenceRequired:0b,PortalCooldown:0,Pos:[205.77500000298022d,-59.650000005960464d,-491.5d],Rotation:[0.0f,0.0f],Spigot.ticksLived:602,TicksSincePollination:0,UUID:[I;-1164535118,-497661241,-1298590821,-767009541],WorldUUIDLeast:-5526025201707824336L,WorldUUIDMost:4772959422628644230L}
>
#

neither of them have my custom tag, either or exit

untold yew
#

override saveWithoutId and apply the same similar code

tame grail
#

is it a boolean?

#

with a compoundtag arg?

#

like the load

#
    @Override
    public CompoundTag saveWithoutId(CompoundTag nbt) {
        nbt.putString("bee-uuid", uuid.toString());

        CompoundTag tag = super.saveWithoutId(nbt);
        
        return tag;
    }
#

heres my best guess lol

#

How close am I?

#

OMG IT SAVED

#

HOLY FUCK

#

OMG