Java Code Examples for net.minecraft.server.MinecraftServer#getWorld()

The following examples show how to use net.minecraft.server.MinecraftServer#getWorld() . 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: EntityPlayerMPFake.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlayerEntity player)
{
    player.getServer().getPlayerManager().remove(player);
    player.networkHandler.disconnect(new TranslatableText("multiplayer.disconnect.duplicate_login"));
    ServerWorld worldIn = server.getWorld(player.dimension);
    ServerPlayerInteractionManager interactionManagerIn = new ServerPlayerInteractionManager(worldIn);
    GameProfile gameprofile = player.getGameProfile();
    EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, interactionManagerIn, true);
    server.getPlayerManager().onPlayerConnect(new NetworkManagerFake(NetworkSide.SERVERBOUND), playerShadow);

    playerShadow.setHealth(player.getHealth());
    playerShadow.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.yaw, player.pitch);
    interactionManagerIn.setGameMode(player.interactionManager.getGameMode());
    ((ServerPlayerEntityInterface) playerShadow).getActionPack().copyFrom(((ServerPlayerEntityInterface) player).getActionPack());
    playerShadow.stepHeight = 0.6F;
    playerShadow.dataTracker.set(PLAYER_MODEL_PARTS, player.getDataTracker().get(PLAYER_MODEL_PARTS));


    server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(playerShadow, (byte) (player.headYaw * 256 / 360)), playerShadow.dimension);
    server.getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, playerShadow));
    player.getServerWorld().getChunkManager().updateCameraPosition(playerShadow);
    return playerShadow;
}
 
Example 2
Source File: GTCommandTeleporter.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: TeleportUtil.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 File: CommandSignals.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
private boolean debug(MinecraftServer server, ICommandSender sender, String[] args){
    World overworld = server.getWorld(0);
    if(args.length < 2) {
        sender.sendMessage(new TextComponentString("Trains loaded: " + RailNetworkManager.getServerInstance().getState().getTrainStream().filter(x -> !((MCTrain)x).getCarts().isEmpty()).count()));
        return true;
    } else {
        int z = Integer.parseInt(args[1]);
        for(int i = 0; i < 10000; i++) {
            EntityMinecartEmpty cart = new EntityMinecartEmpty(overworld, i, 64, z);
            cart.forceSpawn = true;
            boolean success = overworld.spawnEntity(cart);
            if(i % 1000 == 0) {
                sender.sendMessage(new TextComponentString("Spawned " + i + " / 100.000"));
            }
        }
        return true;
    }
}
 
Example 5
Source File: TargetData.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean isTargetBlockUnchanged()
{
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    if (server == null)
    {
        return false;
    }

    World world = server.getWorld(this.dimension);
    if (world == null)
    {
        return false;
    }

    IBlockState iBlockState = world.getBlockState(this.pos);
    Block block = iBlockState.getBlock();
    ResourceLocation rl = ForgeRegistries.BLOCKS.getKey(block);
    int meta = block.getMetaFromState(iBlockState);

    // The target block unique name and metadata matches what we have stored
    return this.blockMeta == meta && rl != null && this.blockName.equals(rl.toString());
}
 
Example 6
Source File: BlockTofuPortal.java    From TofuCraftReload with MIT License 5 votes vote down vote up
/**
 * Called When an Entity Collided with the Block
 */

@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {

    if (!entityIn.isRiding() && !entityIn.isBeingRidden() && entityIn.isNonBoss()) {
        MinecraftServer server = worldIn.getMinecraftServer();
        if (server != null && entityIn.timeUntilPortal <= 0) {
            PlayerList playerList = server.getPlayerList();
            int i = entityIn.dimension == DimensionType.OVERWORLD.getId() ?
                    TofuMain.TOFU_DIMENSION.getId() : DimensionType.OVERWORLD.getId();
            TofuTeleporter teleporter = new TofuTeleporter(server.getWorld(i));
            entityIn.timeUntilPortal = 100;

            if (entityIn instanceof EntityPlayerMP) {
                playerList.transferPlayerToDimension((EntityPlayerMP) entityIn, i, teleporter);
            } else {
                int origin = entityIn.dimension;
                entityIn.dimension = i;
                worldIn.removeEntityDangerously(entityIn);
                entityIn.isDead = false;
                playerList.transferEntityToWorld(entityIn, origin, server.getWorld(origin), server.getWorld(i),
                        teleporter);

            }


        } else
            entityIn.timeUntilPortal = Math.max(entityIn.getPortalCooldown(), 100);
    }

}
 
Example 7
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public IFluidHandler getLinkedTank(ItemStack stack)
{
    TargetData targetData = this.getLinkedTankTargetData(stack);
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();

    if (targetData != null && server != null)
    {
        World world = server.getWorld(targetData.dimension);

        if (world != null)
        {
            // Force load the target chunk where the tank is located with a 30 second unload delay.
            if (ChunkLoading.getInstance().loadChunkForcedWithModTicket(targetData.dimension,
                    targetData.pos.getX() >> 4, targetData.pos.getZ() >> 4, 30))
            {
                TileEntity te = world.getTileEntity(targetData.pos);

                if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetData.facing))
                {
                    return te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetData.facing);
                }
            }
        }
    }

    return null;
}
 
Example 8
Source File: EntityPlayerMPFake.java    From fabric-carpet with MIT License 4 votes vote down vote up
public static EntityPlayerMPFake createFake(String username, MinecraftServer server, double d0, double d1, double d2, double yaw, double pitch, DimensionType dimension, GameMode gamemode)
{
    //prolly half of that crap is not necessary, but it works
    ServerWorld worldIn = server.getWorld(dimension);
    ServerPlayerInteractionManager interactionManagerIn = new ServerPlayerInteractionManager(worldIn);
    GameProfile gameprofile = server.getUserCache().findByName(username);
    if (gameprofile == null)
    {
        return null;
    }
    if (gameprofile.getProperties().containsKey("textures"))
    {
        gameprofile = SkullBlockEntity.loadProperties(gameprofile);
    }
    EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, interactionManagerIn, false);
    instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(d0, d1, d2, (float) yaw, (float) pitch);
    server.getPlayerManager().onPlayerConnect(new NetworkManagerFake(NetworkSide.SERVERBOUND), instance);
    if (instance.dimension != dimension) //player was logged in in a different dimension
    {
        ServerWorld old_world = server.getWorld(instance.dimension);
        instance.dimension = dimension;
        old_world.removePlayer(instance);
        instance.removed = false;
        //worldIn.spawnEntity(instance);
        instance.setWorld(worldIn);
        server.getPlayerManager().sendWorldInfo(instance, worldIn);
        instance.networkHandler.requestTeleport(d0, d1, d2, (float) yaw, (float) pitch);
        instance.interactionManager.setWorld(worldIn);
        worldIn.onPlayerChangeDimension(instance);
    }
    instance.setHealth(20.0F);
    instance.removed = false;
    instance.networkHandler.requestTeleport(d0, d1, d2, (float) yaw, (float) pitch);
    instance.stepHeight = 0.6F;
    interactionManagerIn.setGameMode(gamemode);
    server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), instance.dimension);
    server.getPlayerManager().sendToDimension(new EntityPositionS2CPacket(instance), instance.dimension);
    instance.getServerWorld().getChunkManager().updateCameraPosition(instance);
    instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
    return instance;
}
 
Example 9
Source File: BlockTeleportRail.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
private void teleport(EntityMinecart cart, MCPos destination){
    if(cart instanceof EntityMinecartContainer) {
        ((EntityMinecartContainer)cart).dropContentsWhenDead = false;
    }

    int dimensionIn = destination.getDimID();
    BlockPos destPos = destination.getPos();
    if(!ForgeHooks.onTravelToDimension(cart, destination.getDimID())) return;

    MinecraftServer minecraftserver = cart.getServer();
    int i = cart.dimension;
    WorldServer worldserver = minecraftserver.getWorld(i);
    WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn);
    cart.dimension = dimensionIn;

    /*if (i == 1 && dimensionIn == 1)
    {
        worldserver1 = minecraftserver.getWorld(0);
        this.dimension = 0;
    }*/

    cart.world.removeEntity(cart);
    cart.isDead = false;
    BlockPos blockpos = destination.getPos();

    /* double moveFactor = worldserver.provider.getMovementFactor() / worldserver1.provider.getMovementFactor();
    double d0 = MathHelper.clamp(this.posX * moveFactor, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
    double d1 = MathHelper.clamp(this.posZ * moveFactor, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
    double d2 = 8.0D;*/

    cart.moveToBlockPosAndAngles(destPos, 90.0F, 0.0F);
    /*Teleporter teleporter = worldserver1.getDefaultTeleporter();
    teleporter.placeInExistingPortal(this, f);
    blockpos = new BlockPos(this);*/

    worldserver.updateEntityWithOptionalForce(cart, false);
    Entity entity = EntityList.newEntity(cart.getClass(), worldserver1);

    if(entity != null) {
        copyDataFromOld(entity, cart);

        entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw, entity.rotationPitch);

        IBlockState state = destination.getLoadedBlockState();
        if(state.getBlock() == ModBlocks.TELEPORT_RAIL) { //If the destination is a teleport track, use its rail direction to push the cart the right direction
            EnumFacing teleportDir = getTeleportDirection(state);
            double speed = 0.2;
            entity.motionX = teleportDir.getFrontOffsetX() * speed;
            entity.motionY = teleportDir.getFrontOffsetY() * speed;
            entity.motionZ = teleportDir.getFrontOffsetZ() * speed;
        } else {
            entity.motionX = entity.motionY = entity.motionZ = 0;
        }

        boolean flag = entity.forceSpawn;
        entity.forceSpawn = true;
        worldserver1.spawnEntity(entity);
        entity.forceSpawn = flag;
        worldserver1.updateEntityWithOptionalForce(entity, false);
    }

    cart.isDead = true;
    worldserver.resetUpdateEntityTick();
    worldserver1.resetUpdateEntityTick();
}
 
Example 10
Source File: EntityElevatorCapsule.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Nullable
public Entity changeDimension(int dimensionIn, double posX, double y, double posZ)
{
	if (!this.world.isRemote && !this.isDead)
	{
		List<Entity> passengers = getPassengers();

		if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, dimensionIn)) return null;
		this.world.profiler.startSection("changeDimension");
		MinecraftServer minecraftserver = this.getServer();
		int i = this.dimension;
		WorldServer worldserver = minecraftserver.getWorld(i);
		WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn);
		this.dimension = dimensionIn;

		if (i == 1 && dimensionIn == 1)
		{
			worldserver1 = minecraftserver.getWorld(0);
			this.dimension = 0;
		}

		this.world.removeEntity(this);
		this.isDead = false;
		this.world.profiler.startSection("reposition");
		BlockPos blockpos;


		double d0 = this.posX;
		double d1 = this.posZ;
		double d2 = 8.0D;


		d0 = MathHelper.clamp(d0 * 8.0D, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
		d1 = MathHelper.clamp(d1 * 8.0D, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);


		d0 = (double)MathHelper.clamp((int)d0, -29999872, 29999872);
		d1 = (double)MathHelper.clamp((int)d1, -29999872, 29999872);
		float f = this.rotationYaw;
		this.setLocationAndAngles(d0, this.posY, d1, 90.0F, 0.0F);
		Teleporter teleporter = new TeleporterNoPortal(worldserver1);
		teleporter.placeInExistingPortal(this, f);


		worldserver.updateEntityWithOptionalForce(this, false);
		this.world.profiler.endStartSection("reloading");
		Entity entity = EntityList.newEntity(this.getClass(), worldserver1);

		if (entity != null)
		{

			this.moveToBlockPosAndAngles(new BlockPos(posX, y, posZ), entity.rotationYaw, entity.rotationPitch);
			((EntityElevatorCapsule)entity).copyDataFromOld(this);

			entity.forceSpawn = true;
			worldserver1.spawnEntity(entity);
			worldserver1.updateEntityWithOptionalForce(entity, true);

			int timeOffset = 1;
			for(Entity e : passengers) {
				//Fix that darn random crash?
				worldserver.resetUpdateEntityTick();
				worldserver1.resetUpdateEntityTick();
				//Transfer the player if applicable

				//Need to handle our own removal to avoid race condition where player is mounted on client on the old entity but is already mounted to the new one on server
				//PacketHandler.sendToPlayer(new PacketEntity(this, (byte)PacketType.DISMOUNTCLIENT.ordinal()), (EntityPlayer) e);

				PlanetEventHandler.addDelayedTransition(worldserver.getTotalWorldTime(), new TransitionEntity(worldserver.getTotalWorldTime(), e, dimensionIn, new BlockPos(posX + 16, y, posZ), entity));

				//minecraftserver.getPlayerList().transferPlayerToDimension((EntityPlayerMP)e, dimensionIn, teleporter);

				//e.setLocationAndAngles(posX, Configuration.orbit, posZ, this.rotationYaw, this.rotationPitch);

				//e.startRiding(entity);


				//e.playerNetServerHandler.sendPacket(new SPacketRespawn(e.dimension, e.world.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), ((EntityPlayerMP)e).interactionManager.getGameType()));
				//((WorldServer)startWorld).getPlayerManager().removePlayer(player);

			}
		}

		this.isDead = true;
		this.world.profiler.endSection();
		worldserver.resetUpdateEntityTick();
		worldserver1.resetUpdateEntityTick();
		this.world.profiler.endSection();
		return entity;
	}
	else
	{
		return null;
	}
}
 
Example 11
Source File: TeleportEntity.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static Entity teleportEntityToDimension(Entity entity, double x, double y, double z, int dimDst)
{
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    WorldServer worldDst = server.getWorld(dimDst);

    teleportInProgress = true;

    if (worldDst == null || ForgeHooks.onTravelToDimension(entity, dimDst) == false)
    {
        teleportInProgress = false;
        return null;
    }

    teleportInProgress = false;

    // Load the chunk first
    int chunkX = (int) Math.floor(x / 16D);
    int chunkZ = (int) Math.floor(z / 16D);
    ChunkLoading.getInstance().loadChunkForcedWithModTicket(dimDst, chunkX, chunkZ, 10);

    if (entity instanceof EntityPlayerMP)
    {
        EntityPlayerMP player = (EntityPlayerMP) entity;
        World worldOld = player.getEntityWorld();
        DummyTeleporter teleporter = new DummyTeleporter(worldDst);

        player.setLocationAndAngles(x, y, z, player.rotationYaw, player.rotationPitch);
        server.getPlayerList().transferPlayerToDimension(player, dimDst, teleporter);

        // Teleporting FROM The End, remove the boss bar that would otherwise get stuck on
        if (worldOld.provider instanceof WorldProviderEnd)
        {
            removeDragonBossBarHack(player, (WorldProviderEnd) worldOld.provider);
        }

        player.setPositionAndUpdate(x, y, z);
        worldDst.updateEntityWithOptionalForce(player, false);
        player.addExperienceLevel(0);
        player.setPlayerHealthUpdated();
        // TODO update food level?
    }
    else
    {
        WorldServer worldSrc = (WorldServer) entity.getEntityWorld();

        // FIXME ugly special case to prevent the chest minecart etc from duping items
        if (entity instanceof EntityMinecartContainer)
        {
            ((EntityMinecartContainer) entity).setDropItemsWhenDead(false);
        }

        Entity entityNew = EntityList.newEntity(entity.getClass(), worldDst);

        if (entityNew != null)
        {
            EntityUtils.copyDataFromOld(entityNew, entity);
            entityNew.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch);

            boolean flag = entityNew.forceSpawn;
            entityNew.forceSpawn = true;
            worldDst.spawnEntity(entityNew);
            entityNew.forceSpawn = flag;

            worldDst.updateEntityWithOptionalForce(entityNew, false);
            entity.isDead = true;

            worldSrc.removeEntity(entity);
            worldSrc.updateEntityWithOptionalForce(entity, false);

            worldSrc.resetUpdateEntityTick();
            worldDst.resetUpdateEntityTick();
        }

        entity = entityNew;
    }

    return entity;
}
 
Example 12
Source File: BlockTofuPortal.java    From TofuCraftReload with MIT License 2 votes vote down vote up
@SuppressWarnings("unused")
private boolean changeDim(EntityPlayer playerIn) {

    MinecraftServer server = playerIn.world.getMinecraftServer();

    if (server != null) {

        PlayerList playerList = server.getPlayerList();

        int i = playerIn.dimension == DimensionType.OVERWORLD.getId() ? TofuMain.TOFU_DIMENSION.getId() :

                DimensionType.OVERWORLD.getId();


        Teleporter teleporter = new TofuTeleporter(server.getWorld(i));


        if (playerIn instanceof EntityPlayerMP) {

            playerList.transferPlayerToDimension((EntityPlayerMP) playerIn, i, teleporter);

        } else {

            int origin = playerIn.dimension;

            playerIn.dimension = i;

            playerIn.world.removeEntityDangerously(playerIn);

            playerIn.isDead = false;

            playerList.transferEntityToWorld(playerIn, origin, server.getWorld(origin), server.getWorld(i),

                    teleporter);

        }

    }

    return true;

}