thexaero / open-parties-and-claims

Minecraft mod that adds chunk claims and player parties
https://www.curseforge.com/minecraft/mc-mods/open-parties-and-claims
Other
33 stars 14 forks source link

Possibility to explicitly allow players to interact with seats on Create contraptions #486

Open Noire86 opened 2 weeks ago

Noire86 commented 2 weeks ago

Hello! I`ve found, that it is impossible to explicitly allow players to interact ONLY with Create contraption seat (e.g Train from server-claimed metro system).

If I do allow to interact with create:carriage_contraption - players can now grief the trains` schedule or intercept train controls. When the interaction with train entity is prohibited - train schedule is secured, but players can not embark onto the train, and may fall out due to server ping or whatever reasons. I think it is vital to Create trains to embark players in place in order to sync the movement of the player and train contraption.

Is it (technically) possible to allow to interact with specific part of contraptions like seats?

Thanks in advance.

thexaero commented 2 weeks ago

It could get annoying to try to implement something like this. I'd probably have to disable the general entity protection for trains and protect every individual train interaction type other than with seats. Which means I'll have to keep track of every new type of interaction added to Create in the future, and no longer support many modded interaction types by default. Alternatively, OPAC could try to predict and check whether every condition is met for an entity interaction to "have to" be a seat interaction, with its own ray trace and everything, but it shares similar issues of having to keep up with Create code changes and supporting less mods.

Noire86 commented 2 weeks ago

Thanks, a very comprehensive response. I guess we have to ask Create authors to add specific seat embarking packet (similar to train controls packet) to be able to seamlessly implement OPAC protection for this.

Noire86 commented 2 weeks ago

What is interesting for me - is the mechanism of determining a tile entity inside a carriage contraption, and how create allows us to open chests and more on a moving train. At first, I thought it was a kind of entity -> tile-entity redirection of interacting actions. But looking through code with a glance - didn't help :(

thexaero commented 2 weeks ago

If I remember correctly, the contraptions are basically their own "worlds". When you interact with one, I think it converts your position and rotation into the contraption's "world's" space and raytraces for blocks the same way it would in a regular world. They could actually allow all blocks to work inside contraptions, I'm not too sure why only specific hard-coded interactions are allowed. It's most likely for performance reasons though.

Noire86 commented 2 weeks ago

Maybe we can do something from another perspective? The only thing that is basically needed to be protected - is a conductor and its schedule. I tried conductor from Steam and rails, and somehow, it bypasses the strict chunk access to contraption. On the other side, the blaze burner conductor is protected by OPAC. Maybe it is possible to target only conductor entity?

Noire86 commented 2 weeks ago

It seems that any entity sat as a conductor to train bypasses the chunk protection. I used parrot as train operator, and I can freely grant a train schedule to it, bypassing the OPAC.

thexaero commented 2 weeks ago

It seems that any entity sat as a conductor to train bypasses the chunk protection. I used parrot as train operator, and I can freely grant a train schedule to it, bypassing the OPAC.

Are you sure you didn't disable the protection for those entities?

I decided to take a look at the contraption protection code again and realized that Create is using a custom packet for that, not regular entity interaction. And the packet contains the local coordinates of the block inside the contraption. So it actually shouldn't be too difficult to separate protection for seats, surprisingly.

thexaero commented 2 weeks ago

As for interacting with conductors, I think I might have missed another custom packet there. Please create a separate issue on the tracker, if you can confirm that the conductor entities are protected from other interactions.

thexaero commented 2 weeks ago

So it actually shouldn't be too difficult to separate protection for seats, surprisingly.

To explain this a little further. I basically forgot that in-contraption block interactions don't work through normal entity interaction, so I don't have to disable protection for that, so none of the problems I was worried about matter.

Noire86 commented 2 weeks ago

Great news! Will be patiently waiting for new builds. I will also create a separate issue for conductors and conductor entities.

Noire86 commented 2 weeks ago

Just to keep you informed, new issue have been created: https://github.com/thexaero/open-parties-and-claims/issues/487