Java Code Examples for net.minecraft.world.Teleporter#PortalPosition

The following examples show how to use net.minecraft.world.Teleporter#PortalPosition . 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 check out the related API usage on the sidebar.
Example 1
Source File: TeleporterPaths.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * called periodically to remove out-of-date portal locations from the cache list. Argument par1 is a
 * WorldServer.getTotalWorldTime() value.
 */
@Override
public void removeStalePortalLocations(long worldTime)
{
	if (worldTime % 100L == 0L)
	{
		long i = worldTime - 600L;
		ObjectIterator<Teleporter.PortalPosition> objectiterator = this.destinationCoordinateCache.values().iterator();

		while (objectiterator.hasNext())
		{
			Teleporter.PortalPosition teleporter$portalposition = (Teleporter.PortalPosition)objectiterator.next();

			if (teleporter$portalposition == null || teleporter$portalposition.lastUpdateTime < i)
			{
				objectiterator.remove();
			}
		}
	}
}
 
Example 2
Source File: TeleporterPaths.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean placeInExistingPortal(Entity entityIn, float rotationYaw)
{
	boolean flag = true;
	int playerX = MathHelper.floor(entityIn.posX);
	int playerZ = MathHelper.floor(entityIn.posZ);
	boolean shouldAddPortalPosition = true;
	boolean foundPortal = false;
	BlockPos object = new BlockPos(entityIn);
	long k = ChunkPos.asLong(playerX, playerZ);

	IslandMap islandMap = Core.getMapForWorld(worldServerInstance, entityIn.getPosition());
	Center closest = islandMap.getClosestCenter(new Point((playerX*8) % 4096,(playerZ*8) % 4096));
	//Check if we already have a portal position cached here
	if (this.destinationCoordinateCache.containsKey(k))
	{
		Teleporter.PortalPosition portalposition = (Teleporter.PortalPosition)this.destinationCoordinateCache.get(k);
		object = portalposition;
		portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime();
		shouldAddPortalPosition = false;
	}
	else //If not then we do a simple search for the closest portal block
	{
		object = this.findPortal(new BlockPos(entityIn));
	}

	//If we found a portal location then we need to move the player to it
	if (object != null)
	{
		if (shouldAddPortalPosition)
		{
			this.destinationCoordinateCache.put(k, new Teleporter.PortalPosition((BlockPos)object, this.worldServerInstance.getTotalWorldTime()));
			//this.destinationCoordinateKeys.add(Long.valueOf(k));
		}

		EnumFacing enumfacing = null;
		BlockPos pos = object;
		PortalAttribute attr = (PortalAttribute) closest.getAttribute(Attribute.Portal);

		if(this.checkRoomForPlayer(pos.north()))
			pos = pos.north();
		else if(this.checkRoomForPlayer(pos.south()))
			pos = pos.south();
		else if(this.checkRoomForPlayer(pos.east()))
			pos = pos.east();
		else if(this.checkRoomForPlayer(pos.west()))
			pos = pos.west();

		entityIn.setLocationAndAngles(pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, rotationYaw, entityIn.rotationPitch);
		return true;
	}
	else
	{
		return false;
	}
}