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

Only use convert spawners tagged by the give command #3963

Merged
merged 3 commits into from
May 28, 2021

Conversation

JRoy
Copy link
Member

@JRoy JRoy commented Feb 7, 2021

Marks all spawners made by EssentialsX with a special PDC tag that denotes if we should run "spawnerconvert" operations on it.

Tested on 1.8.8 & 1.16.5

Fixes #3811

@JRoy JRoy added the type: bugfix PRs that fix bugs in EssentialsX. label Feb 7, 2021
@JRoy JRoy added this to the 2.19.0 milestone Feb 7, 2021
@JRoy JRoy force-pushed the feature/fixup-spawner-places branch from 6834515 to bd673ec Compare February 7, 2021 16:57
Copy link
Member

@pop4959 pop4959 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this code and (quite shockingly) this breaks the spawner convert feature. There's definitely a better way to go about fixing this.

I can explain this feature briefly since you're unfamiliar with it. In essence, it converts spawners being placed to their intended types when using Essentials commands to create them. It's probably easiest if I just give some example commands to reproduce the expected behavior.

If you run /i zombiespawner you get a "zombie Spawner" (not sure why the z is lower case, that's probably a separate bug as in older versions it was upper). Upon placement, the spawner is "converted" to a zombie spawner. With this code nuked, that no longer works properly and you get left with a pig spawner.

This worked properly in older versions of Minecraft, but from brief testing this clearly doesn't work well with vanilla spawners. If you use the vanilla equivalent command, /minecraft:give @p minecraft:spawner{BlockEntityTag:{SpawnData:{id:"minecraft:zombie"},SpawnPotentials:[{Entity:{id:"minecraft:zombie"},Weight:1}]}} 64, and place the spawner, you get a pig spawner because Essentials overreaches and tries to convert this instead of leaving it alone. PS: for the above command you will also need to be OP and in creative mode due to MC-105216.

Clearly this feature still needs an overhaul because it's not OK for it to do that. Ideally spawners made in Essentials should be the only ones touched by spawner conversion, and vanilla ones are left alone. This could probably be done by attaching a custom tag to the item stack on creation and checking for that before setting the spawned type (and of course, ignoring any that do not have the tag).

@JRoy
Copy link
Member Author

JRoy commented Feb 22, 2021

@pop4959 am now using an enchantment as a way to differentiate between EssX spawners and normal ones. This is the best solution due to PersistentDataContainer being a 1.14 thing

@JRoy JRoy requested a review from pop4959 February 22, 2021 23:02
@pop4959
Copy link
Member

pop4959 commented Feb 25, 2021

To be honest that's a solution I'd not have thought of, but I still have some worries about using enchantments here, given that they're not really intended for storing data. On top of that, it seems likely to me that there can easily be some unnecessary plugin conflicts created by this, since quite a few plugins touch enchantments.

The best solution in my opinion would be to leave the existing legacy handler as-is, and use PDC on the versions that support it. Of course that means that older versions would not receive the improvement, but these versions are not a priority and should not force us to use workarounds that create further maintenance burden.

@JRoy
Copy link
Member Author

JRoy commented Feb 25, 2021

On top of that, it seems likely to me that there can easily be some unnecessary plugin conflicts created by this, since quite a few plugins touch enchantments.

The only possible plugin conflicts would be extremely rare and only in 1.8-1.12 as starting with 1.13 it uses a plugin namespaced key.

The best solution in my opinion would be to leave the existing legacy handler as-is, and use PDC on the versions that support it. Of course that means that older versions would not receive the improvement, but these versions are not a priority and should not force us to use workarounds that create further maintenance burden.

I apply the same logic to the reason in favor of this fix

@pop4959
Copy link
Member

pop4959 commented Feb 25, 2021

Just was concerned because I'm not familiar with any other plugins handling metadata that way. If we're absolutely sure this won't cause problems or have any other side effects, then it might be OK. I'll try to take a closer look later this week.

@JRoy
Copy link
Member Author

JRoy commented Feb 25, 2021

Just was concerned because I'm not familiar with any other plugins handling metadata that way. If we're absolutely sure this won't cause problems or have any other side effects, then it might be OK. I'll try to take a closer look later this week.

Yeah no problem. Basically the only way this can conflict is with the id based enchantment registration which only occurs on 1.8 thru 1.12. I picked an offset which is good enough and no other plugins should occupy considering that barely any plugins register enchantments in the first place, I'd say we're fine. As for side effects there are none I can find.

@JRoy
Copy link
Member Author

JRoy commented May 10, 2021

Marking as draft as this pends providers from #4143

@JRoy JRoy marked this pull request as draft May 10, 2021 21:10
mdcfe pushed a commit that referenced this pull request May 28, 2021
This PR itself does nothing on its own but creates the underlying backbone I need to make a less hacky solution in #3963 lmfao.

This PR creates a provider which uses NBT on 1.8.8-1.13 to mimic the exact structure of a PersistentDataContainer on 1.14+ which will allow us make any possible upgrades (which don't die from the lack of DFU on >1.13) work as expected. Additionally, this does not use reflection on modern Minecraft versions and thus will not need to be maintained/updated on MC version updates.

In the future, we will need to find a way to store data on tile entities (signs namely) so that we are able to store UUIDs on signs for future plans, but for now ItemStacks work to fix our spawner issues.
@mdcfe
Copy link
Member

mdcfe commented May 28, 2021

#4143 has now been merged - will review when marked ready

@JRoy JRoy force-pushed the feature/fixup-spawner-places branch from 1787820 to 04e3639 Compare May 28, 2021 17:47
@JRoy JRoy marked this pull request as ready for review May 28, 2021 17:48
@JRoy JRoy changed the title Fix some spawners being overwritten with garbage data Only use convert spawners tagged by the give command May 28, 2021
@JRoy JRoy enabled auto-merge (squash) May 28, 2021 18:14
@JRoy JRoy disabled auto-merge May 28, 2021 18:29
@JRoy JRoy enabled auto-merge (squash) May 28, 2021 18:29
@JRoy JRoy dismissed pop4959’s stale review May 28, 2021 18:29

outdated

@JRoy JRoy merged commit a009b2f into EssentialsX:2.x May 28, 2021
@JRoy JRoy deleted the feature/fixup-spawner-places branch May 28, 2021 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bugfix PRs that fix bugs in EssentialsX.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Essentials seems to reset the spawners' values and only keeps them from pigs
3 participants