Java Code Examples for net.minecraft.entity.player.EntityPlayer#setPositionAndUpdate()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#setPositionAndUpdate() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Called when the block is right clicked by a player.
 */
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (world.isRemote || !(playerIn instanceof EntityPlayerMP))
    {
        return true;
    }
    else
    {
        EntityPlayerMP entityplayermp = (EntityPlayerMP)playerIn;

        if (entityplayermp.connection.getNetworkManager().isChannelOpen() && entityplayermp.world == world && !entityplayermp.isPlayerSleeping())
        {
            
         if (playerIn.isRiding())
         {
         	playerIn.dismountRidingEntity();
         }

         playerIn.setPositionAndUpdate(world.rand.nextDouble()*2000000D-1000000D, 2550D, world.rand.nextDouble()*2000000D-1000000D);
         
        }
        return true;
    }
}
 
Example 2
public static void teleportToDimension(EntityPlayer player, int dimension, double x, double y, double z) {
	int oldDimension = player.getEntityWorld().provider.getDimension();
	EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player;
	MinecraftServer server = player.getEntityWorld().getMinecraftServer();
	WorldServer worldServer = server.getWorld(dimension);
	player.addExperienceLevel(0);
	if (worldServer == null || worldServer.getMinecraftServer() == null) { // Dimension doesn't exist
		throw new IllegalArgumentException("Dimension: " + dimension + " doesn't exist!");
	}
	worldServer.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, dimension, new GTCommandTeleporter(worldServer, x, y, z));
	player.setPositionAndUpdate(x, y, z);
	if (oldDimension == 1) {
		// For some reason teleporting out of the end does weird things.
		player.setPositionAndUpdate(x, y, z);
		worldServer.spawnEntity(player);
		worldServer.updateEntityWithOptionalForce(player, false);
	}
}
 
Example 3
public static void teleportToDimension(EntityPlayer player, int dimension, double x, double y, double z) {
	if (!(player instanceof EntityPlayerMP)) return;
	int oldDimension = player.world.provider.getDimension();
	EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player;
	MinecraftServer server = ((EntityPlayerMP) player).world.getMinecraftServer();
	if (server == null) return;
	WorldServer worldServer = server.getWorld(dimension);
	player.addExperienceLevel(0);

	if (worldServer.getMinecraftServer() == null) return;

	worldServer.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, dimension, new CustomTeleporter(worldServer, x, y, z));
	player.setPositionAndUpdate(x, y, z);
	if (oldDimension == 1) {
		// For some reason teleporting out of the end does weird things.
		player.setPositionAndUpdate(x, y, z);
		worldServer.spawnEntity(player);
		worldServer.updateEntityWithOptionalForce(player, false);
	}
}
 
Example 4
Source Project: ForgeHax   File: StepMod.java    License: MIT License 5 votes vote down vote up
private void unstep(EntityPlayer player) {
  AxisAlignedBB range = player.getEntityBoundingBox().expand(0, -stepHeight.get(), 0)
      .contract(0, player.height, 0);
  
  if (!player.world.collidesWithAnyBlock(range)) {
    return;
  }
  
  List<AxisAlignedBB> collisionBoxes = player.world.getCollisionBoxes(player, range);
  AtomicReference<Double> newY = new AtomicReference<>(0D);
  collisionBoxes.forEach(box -> newY.set(Math.max(newY.get(), box.maxY)));
  player.setPositionAndUpdate(player.posX, newY.get(), player.posZ);
}
 
Example 5
public static void teleportPlayerLocal( EntityPlayer player, String portalID )
{
    PortalLocation location = (portalID != null) ?
        PortalRegistry.PortalRegistry.getPortal( portalID ) :
        null;

    if( location != null )
    {
        double xPos = ((double)location.m_x1 + location.m_x2 + 1) / 2;
        double yPos = (double) Math.min(location.m_y1, location.m_y2) + 1;
        double zPos = ((double)location.m_z1 + location.m_z2 + 1) / 2;
        if( location.m_dimensionID == player.dimension )
        {
            player.timeUntilPortal = 40;
            player.setPositionAndUpdate( xPos, yPos, zPos );
        }
        else if( player instanceof EntityPlayerMP )
        {
            player.timeUntilPortal = 40;
            MinecraftServer.getServer().getConfigurationManager().transferPlayerToDimension(
                (EntityPlayerMP)player,
                location.m_dimensionID,
                new QuantumTeleporter(
                    MinecraftServer.getServer().worldServerForDimension( location.m_dimensionID ),
                    xPos, yPos, zPos
                )
            );
        }
    }
}
 
Example 6
public static void setPlayerPosition(EntityPlayer player, Pose position) {
	player.setPositionAndUpdate(position.getX(), position.getY(),
			position.getZ());
	Chunk chunk = player.getEntityWorld().getChunkFromBlockCoords(
			(int) position.getX(), (int) position.getZ());
}