-
Notifications
You must be signed in to change notification settings - Fork 418
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 ALLOW_PLAYER_CHANGE_WORLD #4104
add ALLOW_PLAYER_CHANGE_WORLD #4104
Conversation
@@ -64,6 +64,16 @@ public void onInitialize() { | |||
LOGGER.info("Entity {} Killed: {}", entity, killed); | |||
}); | |||
|
|||
ServerEntityWorldChangeEvents.ALLOW_PLAYER_CHANGE_WORLD.register((player, origin, destination) -> { | |||
if (player.getStackInHand(Hand.MAIN_HAND).getItem() == Items.END_ROD) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
if (player.getStackInHand(Hand.MAIN_HAND).getItem() == Items.END_ROD) { | |
if (player.getMainHandStack().isOf(Items.END_ROD)) { |
*/ | ||
public static final Event<AllowPlayerChange> ALLOW_PLAYER_CHANGE_WORLD = EventFactory.createArrayBacked(AllowPlayerChange.class, callbacks -> (player, origin, destination) -> { | ||
for (AllowPlayerChange callback : callbacks) { | ||
if (!callback.allowChangeWorld(player, origin, destination)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkstyle will fail:
if (!callback.allowChangeWorld(player, origin, destination)){ | |
if (!callback.allowChangeWorld(player, origin, destination)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
1fd397d
to
e36f266
Compare
@@ -75,6 +88,19 @@ public interface AfterEntityChange { | |||
void afterChangeWorld(Entity originalEntity, Entity newEntity, ServerWorld origin, ServerWorld destination); | |||
} | |||
|
|||
@FunctionalInterface | |||
public interface AllowPlayerChange { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be limited to just players, other entities are allowed to use portals.
I think its also worth looking at 1.21.2 as I know they changed a lot of this teleportation code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this event is currently only used to restrict players when crossing dimensions; other entities are not affected. I believe there are very few scenarios where restricting entities from crossing dimensions would be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, I will read through 1.21.2 as soon as possible, and I may be able to provide feedback by tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed the relevant source code for 24w39a, and there are not many changes regarding the dimension-crossing code. Through testing, I can assure you that this event works correctly in the latest version as well.
Big concern with this PR. Say you block a teleport from a mod but that mod still sends the packets relating to teleporting. Won’t that cause issues and weird states in the game? For example, if you block the teleportTo in Bumblezone, my other packets will still be sent. https://github.com/TelepathicGrunt/Bumblezone/blob/2dc4c2034f1d9caf52cbe4c798754721b4895039/common/src/main/java/com/telepathicgrunt/the_bumblezone/entities/teleportation/BzWorldSavedData.java#L314 This is probably gonna cause major problems for the client and possibly other people as well |
Hi, thanks for the PR unfortunately I think doing this well requires quite a lot of work, teleportation is really complex. Some things that you will likely need to take into account:
The first thing to do is to likely define a clear set of requirements/use cases, this likely requires looking at what existing mods do. |
I'm really sorry, but I've decided to give up on this. Anyone else is welcome to continue trying. |
ALLOW_PLAYER_CHANGE_WORLD: Called when the player's dimension changes to check if the player is allowed to cross dimensions.
solve issue:
#3294 (comment)