#(snwcreations) targetable command can't stop NPCs from being targeted

1 messages · Page 1 of 1 (latest)

ocean reef
#

Another interesting issue I just found. I'm working on creating a villager NPC with my customized code. I turned targetable for NPC by accident and then a zombie started attacking it.
But when I typed targetable command again the zombie still keep attacking the NPC. I'll had to despawn it and then respawn it so zombie will lose target.

Is this work as expected?
Log there: https://paste.denizenscript.com/View/127631
NPC saves: https://paste.denizenscript.com/View/127632

void sirenBOT
#

(snwcreations) targetable command can't stop NPCs from being targeted

void sirenBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.

marble isle
ocean reef
#

I think it is possible to track entities targeting it.

marble isle
#

Oh you want to track? Hmm might be a lot of memory requirements

#

I'd prefer to iterate nearby entities

ocean reef
#

I just think it is weird so I made this post, if it is not a bug then I can also accept it as it does not affect my project

marble isle
south gulchBOT
#
Changed to Bug

Thread is now a Bug thread. This indicates a core code bug that a developer must resolved, not an error message or other support topic. Please do not misuse the Bug label. Use </helpthread:1028674284870180883> to switch the thread back to a normal help thread if you are not 100% confident it is a code bug.

ocean reef
#

We can just track UUIDs and then search them again while we need to stop them from targeting

#

If they are unloaded then that's good as they are no longer able to target entities

#

And this could be adapted by adding an option and marking it a workaround so users could choice if they really need this fix

ocean reef
#

some mobs have longer track distance but some is not

#

So that is why I suggest tracking by us because we can do this by listening on target events

#

and tracking events will be better while there is a lot of entities around NPC as only entities which want to target NPC will fire an event

#

I'm just unsure if the target events is available since 1.8 for compat (as this thought is unnecessary but should consider)

#

okay it is available even since 1.7.10

ocean reef
#

I've written an initial patch for it and now im testing it

#

I'll make a PR if it succeeded but still have something to discuss

#

As I don't know if entities which is being unloaded will have EntityTargetEvent with null targets fired

#

good, my patch works

#

Unfortunately I had stored Mob instances to a list so I could retrieve it when we need to clear targets, but I don't want memory leaks caused by unloaded Mob instances so I was just thinking about if there is some way I could do graceful cleanups

#

So any ideas? I'm making PR.

#

Oh unused import inside but I'll clean it when I'm available as I'm closing my computer and go outside

#

I'll keep Discord online as I had nothing to do but I could only chat on my phone for now

marble isle
#

@ocean reef I'll do a proper GitHub review in an hour or so but I think the key should go into npc.metadata enum or maybe even a trait, and use Bukkit.getEntity(uuid) to get the mob

ocean reef
#

Unfortuantely there is no way to retrieve entities through World instance with only UUIDs

marble isle
#

Well I guess Server

ocean reef
#

Oh I don't know that. I'll check it on my schedule.

#

Oh cool it exists

#

I'll edit it. scheduled.

ocean reef
marble isle
#

I wonder if it makes more sense as a trait then its self contained

ocean reef
#

I agree it should be self contained

#

But I don't think it should be a trait

#

a metadata is ok

#

as it is never updated by itself but only outside events

ocean reef
#

ah I'm free now

#

Moved the PR logic towards UUID-based storage but still wanted to know where should we put the storage, I think the metadata key I use should not be exposed as it is implementation-specific thing (IDK will someone implement Citizens API by himself)

#

and it could be just a metadata

marble isle
ocean reef
#

uh also fine as trait can have hard-typed objects

#

okay I'll turn it into a trait. wait a min

#

done

marble isle
#

@ocean reef how does PlayerMoveEvent work?

ocean reef
upbeat iglooBOT
ocean reef
#

When accepting movement packets it got fired

marble isle
#

I see

#

if a plugin teleports a player does it cause PlayerMoveEvent?

ocean reef
#

looking at paper source

#

yes but it is fired by CB impl of Player.teleport

#

as plugins can pass custom reasons to it

#

a bit unrelated to this, I'll rename the added trait if we had discussed a proper name for it

ocean reef
#

and I was thinking that user devs may also need to do clearTargets manually if they changes the targetable metadata, should we consider a solution for this? May we do this for them automatically or just keep it as-is?

marble isle
ocean reef
#

I prefer the first one but I want to keep direct changes to metadata also function as what I did in this PR so I'll need something as callback

#

But I had no idea on designing that

#

it will be tricky to add if (metadata == TARGETABLE && !newValue) to setMetadata methods

ocean reef
#

that is what I did in /npc targetable

#

if we had changed the targetable status to false then I'll call clearTargets there

#

But I want to inline this call into setMetadata

#

but it is not a good design as it breaks principle of single responsibility in software designing

#

so still thinking about alternatives

#

or I'll give it up

#

actually I currently had no idea on this so I need help

ocean reef
#

fine I give it up

#

but I'll leave this open as I think it is not an end for this but I'll have to sleep for now

marble isle
#

can make it all a trait if you want

ocean reef
#

okay I get up after a short rest. and I think you're right. so I think it is early to merge that PR as doing so will need to rename the trait again, I'm willing to rename it to TargetableTrait and add other logic related to it, but I'm afraid I'll break userdev plugins as I regard the main module as an API (should I drop this opinion?)

#

and also I want to make the changes to targetable metadata be eqivalent to the change to targetable trait and then deprecate the metadata.
We may do this by a per-tick basis in trait but may not reflect changes from metadata value immediately as it will have a 1 tick delay.

ocean reef
#

I'll apply these changes I've said and make another PR.

#

scheduled at the noon

ocean reef
#

did that but not fully solved yet, as I don't know if the userdevs will still want to use targetable metadata and how they modify that, persist or not?

#

uh really tough

marble isle
#

Sorry i made some cleanup changes which I need to push first

ocean reef
#

that is ok

#

is there any conflict?

marble isle
ocean reef
#

fine, feel free to push and I'll handle it

marble isle
#

@ocean reef I pushed just now

ocean reef
#

pulling

#

uh totally make the PR broken, I'll have to restart the patch

#

done sync

#

ready to continue discussion

ocean reef
#

so the only issue I had no idea is that IDK how check if a NPC metadata value is persist, as I don't have access to MetadataValue.persist field

#

because of that I can't handle legacy calls gracefully

marble isle
#

@ocean reef hmm, although I like temporary metadata, just make it all persistent for now

ocean reef
#

what I think is that targetable trait only save the targetable state but also targeters temporarily

marble isle
ocean reef
#

yes and I hope my codes on it are right

ocean reef
#

as I hope their code works as before so that's why I still thinking on that

#

I really cares backwards compat

marble isle
#

@ocean reef I care as well, but it's just been a new minecraft and citizens version so now is a good time

ocean reef
#

you mean just drop that, even without deprecating that metadata for some time first?

marble isle
#

we don't have as many API users to be that extreme with API breakage

ocean reef
#

okay... I'll remove the legacy handler for now

#

done, so PR is out of draft state now

#

the targetable metadata enum should be removed once the PR is merged

#

and after that this thread could be closed

ocean reef
#

umm you may need to do cleanup again for that as IDK why IntelliJ sorts imports in such a way

ocean reef
#

PR was merged but it is out of initial state so I'll close this thread after doing test on it

ocean reef
#

ummm the cleanup change is incorrect

#

correcting that

#

can't test right now as newer API breaks art enum so I can't compile the plugin, working on backwards compat

south gulchBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@ocean reef

ocean reef
#

running test

#

finally fixed. ty