#Custom Snowball Entity data?
1 messages · Page 1 of 1 (latest)
You can apply metadata to a snowball.
You can use its persistent data container
To the item or to the entity that i spawn?
Metadata would be for the entity. The PDC value would be for the ItemStack.
use it for both
metadata is unreliable and should be distanced from at all cost in principle
it's transient in such an arbitrary way sadly
I'm guessing metadata is when i also setmeta to my item for custom names?
no
That would be NBT?
That’s ItemMeta.
Ah
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/metadata/Metadatable.html this is what shadowmaster is talking about
declaration: package: org.bukkit.metadata, interface: Metadatable
but the implementation is deplorably fragile
hmm
like its just one big map and when entities are considered invalid the values will just unload
Ah that sucks
so use instead https://hub.spigotmc.org/javadocs/spigot/org/bukkit/persistence/PersistentDataHolder.html
declaration: package: org.bukkit.persistence, interface: PersistentDataHolder
which uses nbt
but thats not a big deal in general
So how might i add a custom tag that i can use to do things with the snowball later?
Cause all i see in the pdh thing you sent is to get the data containter
container*
I think the PDC requires the use of NamespacedKeys. So you could make one of those and use it later.
Or initialize it in a class and use it as needed.
var pdc = entity.getPersistentDataContainer();
var pdc = itemMeta.getPersistentDataContainer();
var key = new NamespacedKey(pluginInstance, "KeyName");
//set, remember for itemMeta you need to use itemStack.setItemMeta(itemMeta) afterwards
pdc.set(key,PersistentDataType.BYTE,Byte.valueOf((byte)1));
boolean isFlagged = pdc.getOrDefault(key,PersistentDataType.BYTE,Byte.valueOf((byte)0)) == 1;
or sth
it was some months age since I truly touched spigot
but thats the fundamentals
I am still confused...
I thought that you needed to set the PDC values before you set the ItemMeta since it’s part of the ItemMeta class?
yes exactly
In your example you set it before you add the PDC. 😛
?
//set, remember for itemMeta you need to use itemStack.setItemMeta(itemMeta) afterwards
But right under that you are setting a value to it. Would that update on the item even though you already set the ItemMeta?
I never set the item meta back in that example
hence the comment
but yes itemmetas are just snapshots
So... How would i set a tag as though i used /tag?
oh thats scoreboard
but just
entity.addScoreboardTag(string)
and you also got removeScoreboardTag
Yeah that stuff, but i want to apply the tag to the snowball and then have each snowball have it's own timer (so they don't all trigger on the same tick) and then say explode after 20 ticks or something
Does the entity have to be spawned btw?
Or can i make the entity with the tag then spawn it?
How might i do that?
Cause this doesn't error but i'm not sure how to get past it:
Snowball snowball = player.getWorld().spawn(player.getEyeLocation(), Snowball.class);```
With the spawn thing i assume i could go
Snowball snowball = player.getWorld().spawn(player.getEyeLocation(), Snowball.class, false, snowball.addScoreboardTag("String stuff"));```
But i don't think that would work
cause well snowball isn't defined yet
I guess spawn then do snowball.addScoreboardTag(string) after?
no
oh
false, ent -> ent.addScoreboardTag("String stuff")
ah
its a consumer, so a bit special but ye
there are some great tutorials on functional interfaces if you wanna learn that
maybe
Now i just have to figure out how to make the tagged snowballs have their own timer then do something after that timer
perhaps store time stamps in the form of longs
by namely using System::currentTimeMillis
I could just use the snowball life time right?
something along the lines of
if snowball lifetime = 20 do stuff
The only thing is i'm used to looping things (cause i mainly coded python) and so i'm not sure how the snowball would know when it's lifetime is at 20 since i'm not checking on a loop
compare absolute time as I mentioned
But how would i compare that on a loop and not just once when my interact event is over?
I know but i'm not sure what else to call it
what exactly are you trying to do with these snowballs
When i use a snowball with a custom itemstack stuff (which i already have made and working) I wish for the event to throw a custom snowball with a tag like "shield" or something, and then after 1 second the snowball spawns in a small wall and gets rid of the snowball
But i don't want all snowballs to do that so i can do different stuff with different itemstacks that are all using snowballs
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
take a look at that :3
basically scheduling code execution in bukkit
ah
in py you'd probably use a thread along with time.sleep or sth
hm
So if i had 2 snowballs spawned at once would the second one wait for the other to finish?
and then executed on the main thread when the right tick fires
nah
Bukkit.getScheduler().runTaskLater(plugin,() -> {
},20L);
code inside that runs on the server thread after 20 ticks
Ah
okay so... Do i need to implement scheduler like i do listener?
also if so does that mean i need a new class for this and can't put it in the same class as my event?
the only thing that can effectively change its execution is if the tps is lower, or if the server unprecedentedly shutdowns
Ah
👍
its just an anonymous function that you pass
similar to pythons lambda
but can be multiline in java
I think i have managed to confuse myself again
cause bukkit is red
Because it can't resolve the symbol
BukkitScheduler is fine though
🤦 I probably need to pass plugin to the method
BukkitScheduler scheduler = plugin.getServer().getScheduler(); this works?
yes
How do i run code on the tagged entities?
well.. Execute code at tagged entities location then remove the entity
also what is the 20L * 30L mean in terms of time?
ah nvm
20 is the ticks and then the 30 is turning the ticks into seconds
So i can just put 20 for 1 second
(i'll be back later, i'm gonna eat then go play outside for a bit)
(back-ish)