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

Hello, i'm back from so far to mod on minecraft ( 1.6.4 ... on bukkit ) SO FAR.

I'm writting a similar version of my bukkit plugin with forge for 1.11.2 ( forge-1.11.2-13.20.1.2530-mdk ).

So one of the main thing of my mod is about one way teleport for player ( with a custom item and rightclick / leftclick event ) on single player, survival no cheat.

 

package com.kporal.lau.events;

import com.kporal.lau.init.ItemsInit;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class OnPlayerInteract {
	
	@SubscribeEvent ( priority = EventPriority.HIGH )
	public void onPlayerRightClick( PlayerInteractEvent.RightClickBlock e ) {
		
		EntityPlayer p = e.getEntityPlayer();
		
		if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) {
			
			p.setSpawnPoint( e.getPos(), true );
			p.sendStatusMessage( new TextComponentString( TextFormatting.RED + "#LAU:" + TextFormatting.WHITE + " Teleport point set at " + e.getPos() ), true );
		}
	}
	
	@SubscribeEvent ( priority = EventPriority.HIGH )
	public void onPlayerLeftClick( PlayerInteractEvent.LeftClickEmpty e ) {
		
		EntityPlayer p = e.getEntityPlayer();
		
		if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) {
			
			BlockPos c = p.getBedLocation( p.dimension );
			//p.sendStatusMessage( new TextComponentString( TextFormatting.RED + "#LAU:" + TextFormatting.WHITE + " Telporting to " + c ), true );
			
			//c = p.getLookVec().
			//p.capabilities.allowFlying = true;
			//p.velocityChanged = true;
			//p.setPositionAndUpdate( c.getX(), c.getY(), c.getZ() );
			//net.minecraftforge.event.entity.living.EnderTeleportEvent tp = new net.minecraftforge.event.entity.living.EnderTeleportEvent(p, c.getX(), c.getY(), c.getZ(), 0);
	        //if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(tp)) return;
			//p.attemptTeleport( c.getX(), c.getY(), c.getZ() );
			
			//(( EntityPlayerMP ) p).connection.setPlayerLocation( c.getX(), c.getY(), c.getZ(), p.rotationYaw, p.rotationPitch );
			//p.velocityChanged = false;
			//p.capabilities.allowFlying = false;
			
			
			//p.setGameType( GameType.CREATIVE );
			
			//if( !p.world.isRemote ) {
				//(( EntityPlayerMP ) p).connection.setPlayerLocation( c.getX(), c.getY(), c.getZ() + 1, p.rotationYaw, p.rotationPitch );
				//(( EntityPlayerMP ) p).respawnPlayer();
			//}
			
			//p.respawnPlayer();
			//p.capabilities.isCreativeMode = true;
			//p.setPositionAndUpdate( c.getX(), c.getY(), c.getZ() + 1 );
			//p.capabilities.isCreativeMode = false;
			//p.setGameType( GameType.SURVIVAL );
			
			//p.getServer().getCommandManager().executeCommand( p.getServer(), "tp " + c.getX() + " " + c.getY() + " " + c.getZ() );
			//p.getServer().getCommandManager().
			//p.getEntityWorld().getMinecraftServer().getCommandManager().executeCommand( p.getServer(), "/tp " + c.getX() + " " + c.getY() + " " + c.getZ() );
			
			p.sendStatusMessage( new TextComponentString( p.getEntityWorld().getMinecraftServer() + " " + p.getServer() + " " + p.getEntityWorld() ), true );
			
			//MinecraftServer.getCommandManager().executeCommand( p, "/tp 0 0 0");
			
		}
	}
}

 

Like you can see, i've tryed a lot of method to teleport the player, but nothing work or getting "player moved wrongly" every time, so rather than trying to do something weird in my code, i simply try a send a /tp command but ...

I think ... my error is here : p.getEntityWorld().getMinecraftServer() / p.getServer(), where each time return a null pointer, i'm stuck 2 day i'm trying to teleport my little boy without succes, if anyone can help me ... thank a lot !

Edited by Kporal
Editing title as solved

  • Author

This way work but only in singleplayer with cheat allowed ... :

@SubscribeEvent ( priority = EventPriority.HIGH )
public void onPlayerLeftClick( PlayerInteractEvent.LeftClickEmpty e ) {
	
	EntityPlayer p = e.getEntityPlayer();
	
	if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) {
		
		BlockPos c = p.getBedLocation( p.dimension );
		double px = c.getX() + 0.5;
		double py = c.getY();
		double pz = c.getZ() + 0.5;
		Minecraft.getMinecraft().player.sendChatMessage( "/tp " + px + " " + py + " " + pz );
		
	}
}

So i would like to be able to teleport, in singleplayer but also in MP ( i know how to proceed for MP ), but keeping stuck at how teleport the player without cheat enabled with command ( from server no client to bypass cheat mode )

  • Author

Ok, i've made some mistake ... now it work without cheat mode enabled ( should work too in MP ) :

package com.kporal.lau.events;

import com.kporal.lau.init.ItemsInit;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class OnPlayerInteract {
	
	@SubscribeEvent ( priority = EventPriority.HIGH )
	public void onPlayerRightClick( PlayerInteractEvent.RightClickBlock e ) {
		
		EntityPlayer p = e.getEntityPlayer();
		
		if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) {

			p.setSpawnPoint( e.getPos(), true );
			p.sendStatusMessage( new TextComponentString( TextFormatting.RED + "#LAU:" + TextFormatting.WHITE + " Teleport point set at " + e.getPos() ), true );
		}
	}
	
	@SubscribeEvent ( priority = EventPriority.HIGH )
	public void onPlayerLeftClick( PlayerInteractEvent.LeftClickEmpty e ) {
		
		EntityPlayer p = e.getEntityPlayer();
		
		if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) {
			
			BlockPos c = p.getBedLocation( p.dimension );
			double px = c.getX() + 0.5;
			double py = c.getY() + 1;
			double pz = c.getZ() + 0.5;
			
			MinecraftServer s = FMLCommonHandler.instance().getMinecraftServerInstance();
			s.getCommandManager().executeCommand( s, "/tp " + p.getName() + " " + px + " " + py + " " + pz );
			p.sendStatusMessage( new TextComponentString( TextFormatting.RED + "#LAU:" + TextFormatting.WHITE + " Telporting to " + c ), true );
		}
	}
}

Hope this can help someone else :)

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.