Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dispenserSpawnEntity event (1.19.4) #10669

Open
wants to merge 2 commits into
base: ver/1.19.4
Choose a base branch
from

Conversation

DerToaster98
Copy link

@DerToaster98 DerToaster98 commented May 6, 2024

Adds a cancellable event that gets fired whenever a dispenser would spawn a entity (mainly useful for projectiles and primed tnt).

Workarounds for this would involve cancelling the entire event per item stack which in my opinion is not the best solution. Another workaround would be to use ASM or similar to manually adjust the source code. Or one could use NMS to manually override the dispense behaviors, which would be more effort over all though.

EDIT: Realized i made this on the 1.19.4 branch, will make a new PR for the master one

@DerToaster98 DerToaster98 requested a review from a team as a code owner May 6, 2024 10:38
@DerToaster98 DerToaster98 changed the title Add dispenserSpawnEntity event Add dispenserSpawnEntity event (1.19.4) May 6, 2024
@NonSwag
Copy link
Contributor

NonSwag commented May 6, 2024

I think a new event for that would be unnecessary
The item dispense event is enough in my opinion
You can easily check whether an item is a spawn egg or a projectile or any other kind of entity when dispensed

@DerToaster98
Copy link
Author

DerToaster98 commented May 6, 2024

Yes, i could do that, but i will only have access to exactly the item using that approach. And for what i want to do i need access to the entity created when dispensed and the dispenser itself. Correct me if i'm wrong, but ItemDispenseEvent only gives access to the item.

And i would need to replicate the entire logic for entity spawning through dispensed items (e.g. eggs, tnt, arrow and so on) for it to be accurate.

The other way that i'm aware of is using ASM or mixins or similar to achieve this or to use NMS and to re-register all the dispenseBehaviors with altered code.

EDIT: Access to the dispenser is given in the ItemDispenseEvent. Yet that doesn't change anything about the jankiness of that solution.

@NonSwag
Copy link
Contributor

NonSwag commented May 6, 2024

you could listen to the entity spawn event caused by dispensers

@DerToaster98
Copy link
Author

Iirc there is just an entity spawn event, no? Haven't seen one specific for dispensers. And iirc the entity spawn event lacks a "reason" or context what spawned the entity or am i missing something here?

@notTamion
Copy link
Contributor

notTamion commented May 6, 2024

i didn't look at the implementation of this so i am not sure if this is possible but perhaps you could expand on the BlockDispenseEvent by adding a getEntity or something similar

EDIT: also you can just relocate the current pr to the master branch you don't to create a new one

@NonSwag
Copy link
Contributor

NonSwag commented May 6, 2024

Iirc there is just an entity spawn event, no? Haven't seen one specific for dispensers. And iirc the entity spawn event lacks a "reason" or context what spawned the entity or am i missing something here?

Entit#getEntitySpawnReason
image

@DerToaster98
Copy link
Author

DerToaster98 commented May 6, 2024

ok, that gets me the reason, but for what i want to do i need to have access to the dispenser too. And having to scan every of the 8/14 blocks around the entity is not an option

@DerToaster98
Copy link
Author

i didn't look at the implementation of this so i am not sure if this is possible but perhaps you could expand on the BlockDispenseEvent by adding a getEntity or something similar

EDIT: also you can just relocate the current pr to the master branch you don't to create a new one

Hm, good idea

@Machine-Maker
Copy link
Member

I think this duplicates a lot of what is proposed in #7377.

@DerToaster98
Copy link
Author

DerToaster98 commented May 6, 2024

I think this duplicates a lot of what is proposed in #7377.

Looks like it. Will still keep this open though, cause the PR you mentioned hasn't been touched in quite some time.

EDIT: Wait, according to the description it doesn't fire when projectiles are being fired from dispensers?
EDIT 2: Haven't looked in detail but for what i want i need access to the dispenser BE that fired the projectile or spawned the tnt, not having it doesn't help me here.

@NonSwag
Copy link
Contributor

NonSwag commented May 7, 2024

The idea of adding an entity to the existing dispense event is actually pretty good.
It could return a nonnull entity in every case because the item entity could also be returned.

@Machine-Maker
Copy link
Member

Machine-Maker commented May 13, 2024

EDIT 2: Haven't looked in detail but for what i want i need access to the dispenser BE that fired the projectile or spawned the tnt, not having it doesn't help me here.

The projectile source is on the Projectile entity with https://jd.papermc.io/paper/1.20.6/org/bukkit/projectiles/BlockProjectileSource.html.

@DerToaster98
Copy link
Author

EDIT 2: Haven't looked in detail but for what i want i need access to the dispenser BE that fired the projectile or spawned the tnt, not having it doesn't help me here.

The projectile source is on the Projectile entity with https://jd.papermc.io/paper/1.20.6/org/bukkit/projectiles/BlockProjectileSource.html.

Interesting, i will take a look, thanks!

@DerToaster98
Copy link
Author

EDIT 2: Haven't looked in detail but for what i want i need access to the dispenser BE that fired the projectile or spawned the tnt, not having it doesn't help me here.

The projectile source is on the Projectile entity with https://jd.papermc.io/paper/1.20.6/org/bukkit/projectiles/BlockProjectileSource.html.

Ok, took a look, I can use that for any projectile, but i still need something for the tnt being dispensed. I know of workarounds but using those is not an option. Guess I'll adjust my solution here and wait for the (probably unlikely) case that it will be merged. Otherwise I need to find a way to compile the jar on my own.

@Machine-Maker
Copy link
Member

Ok, took a look, I can use that for any projectile, but i still need something for the tnt being dispensed.

Yes, the mentioned PR does add an event for handling TNT which can't have a projectile source as its not a projectile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Awaiting review
Development

Successfully merging this pull request may close these issues.

None yet

4 participants