NeoForge
NeoForge copied to clipboard
EntityTeleportEvent has no way to tell which dimension target will be teleported to
Suppose that I marked a "restricted area" and disallowed anyone to entering this area by any means. Which means I do not want players to teleport into this area. Consider the following snippet:
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onTeleport(EntityTeleportEvent event) {
var targetBlockPos = BlockPos.containing(event.getTargetX(), event.getTargetY(), event.getTargetZ());
if (/* Teleport target is in the restricted area*/) {
event.setCanceled(true);
actor.sendSystemMessage(Component.literal("Refuse to teleport you into restricted area"));
}
}
The above code should work for the said purpose. However, I can see at least two cases where it won't work well:
- The said area is in The Nether; a player attempts to
/execute in minecraft:nether run tp @p <x> <y> <z>from overworld. - The said area is in The Nether, and (conveniently) there is a nether portal nearby; a player attempts to trespass the restricted area by throwing an Ender Pearl through the portal
For case 2, I understand that I can specifically subscribe to EntityTeleportEvent$EnderPearl, and retrieve the correct dimension via pearlEntity.
For case 1, however - I do not have any information about which dimension I am being teleported to.
Would it be possible to either
- Have a "target dimension" in
EntityTeleportEvent, or - Provide extra context in
EntityTeleportEvent$TeleportCommand?