Posted June 19, 20169 yr I'm looking for a way to check if a player uses any sort of teleportation, since with this code, people can't "move" out of my borders, they can however, teleport. I was wondering if I can force survival on those who may try to teleport out of the borders. Here's the code: package com.troelsen.buildingarea; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.WorldSettings.GameType; import java.awt.*; public class EventHandlerCommon { @SubscribeEvent public void tickEvent(PlayerTickEvent event) { Rectangle rec1 = new Rectangle(-10, -10, 20, 20); // constructor er (x, z, width, height) Rectangle rec2 = new Rectangle(-15, -15, 30, 30); Point playerPos = new Point((int)event.player.posX, (int)event.player.posZ); // Hvis man er inden for den yderste rectangle, og uden for den inderste if (event.player.capabilities.isCreativeMode && rec2.contains(playerPos) && !rec1.contains(playerPos)) { event.player.setGameType(GameType.SURVIVAL); } } } Thanks in advance Troelsen
June 19, 20169 yr There's no event fired for player teleportation. You could attach an IExtendedEntityProperties implementation (or a Capability in 1.8.9+) to EntityPlayer that stores whether they were in the borders the previous tick. If they were in the borders last tick but they're not this tick, set them to survival mode. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 19, 20169 yr Author There's no event fired for player teleportation. You could attach an IExtendedEntityProperties implementation (or a Capability in 1.8.9+) to EntityPlayer that stores whether they were in the borders the previous tick. If they were in the borders last tick but they're not this tick, set them to survival mode. Thank you for the quick response! I thought of checking for the last tick as well, and I also tried. However player.lastTickPosX/Z doesn't seem to work as I thought it would public class EventHandlerCommon { @SubscribeEvent public void tickEvent(PlayerTickEvent event) { Rectangle rec1 = new Rectangle(-10, -10, 20, 20); // constructor er (x, z, width, height) Rectangle rec2 = new Rectangle(-12, -12, 24, 24); Point playerPos = new Point((int)event.player.posX, (int)event.player.posZ); Point playerPose = new Point((int)event.player.lastTickPosX, (int)event.player.lastTickPosZ); // Hvis man er inden for den yderste rectangle, og uden for den inderste if (event.player.capabilities.isCreativeMode && rec2.contains(playerPos) && !rec1.contains(playerPos)) { event.player.setGameType(GameType.SURVIVAL); } else if (rec2.contains(playerPose) && !rec1.contains(playerPose)) { event.player.setGameType(GameType.SURVIVAL); } } } There's no errors in my code, it does however not change the gamemode once teleported
June 19, 20169 yr Try setting a breakpoint and stepping through the method in a debugger. Is the previous tick position accurate after teleporting? Is the current position accurate? Something I just remembered: All subclasses of TickEvent are fired twice per tick of their corresponding system, once with Phase.START and once with Phase.END . Make sure you check the Phase to avoid running your code twice per tick. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 20, 20169 yr Author Try setting a breakpoint and stepping through the method in a debugger. Is the previous tick position accurate after teleporting? Is the current position accurate? Something I just remembered: All subclasses of TickEvent are fired twice per tick of their corresponding system, once with Phase.START and once with Phase.END . Make sure you check the Phase to avoid running your code twice per tick. Hai Choonster! I got working by making an IExtendedEntityProperties as you told me to. Thanks again for your help!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.