TheMrJezza / HorseTpWithMe

A Bukkit Plugin that allows the simple teleportation of Rideable LivingEntities in Minecraft.
MIT License
14 stars 6 forks source link

1.17 & 1.18 compatibility #7

Open lokka30 opened 2 years ago

lokka30 commented 2 years ago

Do you think a list of procedures required to make 1.17 and 1.18 compatible should be added here?

TheMrJezza commented 2 years ago

It's complicated. I fully agree that a list would be the absolute best course of action, however, I'm terrible with organisation - the overdue updates are evidence of this. I'm writing this reply before opening IntelliJ, therefore I cannot provide a complete response.

I'll reply again in a little while.

Edit: Actually, I think I should start with updating the repo with the current code, complete or not.

lokka30 commented 2 years ago

You could do it on a development branch (dev) instead of master :) that will allow contributions but not affect the code that people will assume is stable. I don't like doing detailed lists, but general 'areas that need working on' helps me a lot with my projects. If there's any way I can help out, please let me know 😄

TheMrJezza commented 2 years ago

Dev Branch Added. Feel free to look through and try to make sense of things. It's just bare bones, the PermManager class is just a quick port of the original-original PermissionManager class from the first release of the plugin (with permissions). It's broken as and isn't used anywhere currently.

TheMrJezza commented 2 years ago

The biggest hurdle is writing / sending the Spawn packets. Sometimes the client wont draw the teleported vehicle entity (Disappearing), other times the teleport is such a short distance that the vehicle remains within the client view distance, which means the vehicle won't teleport, rather it will quickly move (client side). Both the quick move and the disappearing can be resolved by sending a Spawn Packet to the client. The type of spawn packet depends on the vehicle...

lokka30 commented 2 years ago

Are these bugs with the server software that HTPWM is left to patch?

TheMrJezza commented 2 years ago

It isn't exactly a bug. And the issue is very much client side. The client isn't designed to accept instantaneous teleports of entities. Previous Versions of HorseTpWithMe (including the current released version) have an ugly delay between the player teleporting and the vehicle teleporting.

PacketPlayOutSpawnEntity pack = new PacketPlayOutSpawnEntity(((CraftEntity) vehicle).getHandle());

PacketPlayOutEntityMetadata metadata = new PacketPlayOutEntityMetadata(vehicle.getEntityId(), ((CraftEntity) vehicle).getHandle().ai(), true);

((CraftPlayer) passengers.get(0)).getHandle().b.a(pack); ((CraftPlayer) passengers.get(0)).getHandle().b.a(metadata);

Pretty much, that NMS fixes 95% of the issues. But there are still a few more packets you need to manually send. For example, if you teleport a pig with a saddle, the pig will teleport just fine, but the saddle wont be visible to the client. Moving away from the pig so it goes outside the client view distance fixes the problem.

TheMrJezza commented 2 years ago

By "instantaneous teleport", I'm talking about the client receiving an entity spawn packet whilst also teleporting. I suspect the spawn packet is ready to be sent before the player has actually teleported. Won't know for sure until I do some packet listening.

TheMrJezza commented 2 years ago

final net.minecraft.world.entity.Entity handle = ((CraftEntity) vehicle).getHandle();

sendPackets(rider, new PacketPlayOutSpawnEntity(handle), new PacketPlayOutEntityMetadata(vehicle.getEntityId(), handle.ai(), true) ); if (handle instanceof EntityLiving living) sendPackets(rider, new PacketPlayOutUpdateAttributes(vehicle.getEntityId(), living.ep().b()));

That's done it. Unfortunately, it's NMS. I'm going to try and adapt it to ProtocolLib, or something.

TheMrJezza commented 2 years ago

The plugin is now in a usable state for 1.18 or 1.17 depending on which NMS class is used to compile. Excluding the configurable messages, everything seems to be working over in the Dev Branch.

lokka30 commented 2 years ago

Hi Jez, would you like me to do some testing? Which branch should I compile?

TheMrJezza commented 2 years ago

The weeks leading up to Easter are the busiest in my job, I've needed to work extra hours as of late and I haven't been able to allocate time to plugin development. When I finish work today I can finally relax for a few days and hopefully get some development work done.

With that said, only compile the dev branch. Until I make an official release on Spigot, the main branch wont be updated.

lokka30 commented 2 years ago

The weeks leading up to Easter are the busiest in my job, I've needed to work extra hours as of late and I haven't been able to allocate time to plugin development. When I finish work today I can finally relax for a few days and hopefully get some development work done.

No worries! Such is why I am happy to help, as HTPWM is free and open source :)

With that said, only compile the dev branch. Until I make an official release on Spigot, the main branch wont be updated.

Sweet, I'm very familiar with this system.

NotAlexNoyle commented 2 years ago

Using the dev branch, horse armor does not get teleported as it did in the old version.

TheMrJezza commented 2 years ago

It does, its just a graphical glitch. You see, there is a packet that must be sent in order to correctly tell the client about health, armour, jump strength, chest contents, speed etc.. and other stats.

As of 1.18, spigot uses mojang mappings for nms code, which by design makes it a giant pain in the arse to maintain. "You should use the API" they say... doesn't help when Minecraft's protocol isn't reliably abstracted.

The if the problem is solved by leaving the server then logging back in, then it's just a client-side glitch. We'll fix it.

TheMrJezza commented 2 years ago

https://github.com/TheMrJezza/HorseTpWithMe/commit/1e4c60253aafeb993178521479750493302861ef

Entity Equipment should now be fixed. (Including Horse Armour). To test it out, you'll have to build your own Jar from the source. I won't be uploading a release until tomorrow.

Edit: https://github.com/TheMrJezza/HorseTpWithMe/releases/tag/EquipmentPatch Built a Jar.

NotAlexNoyle commented 2 years ago

That version fixes the issue. Thanks!