Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

  • 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

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.

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.