Search in sources :

Example 66 with WorldServer

use of net.minecraft.world.WorldServer in project Engine by VoltzEngine-Project.

the class MassRegistry method getMass.

@Override
public double getMass(World world, int x, int y, int z) {
    double mass;
    if (world != null) {
        //Checks if the chunk is loaded
        if (world instanceof WorldServer) {
            ChunkProviderServer providerServer = ((WorldServer) world).theChunkProviderServer;
            if (!providerServer.chunkExists(x >> 4, z >> 4)) {
                return -1;
            }
        }
        Block block = world.getBlock(x, y, z);
        int meta = world.getBlockMetadata(x, y, z);
        TileEntity tile = world.getTileEntity(x, y, z);
        if (tile instanceof IHasMass) {
            mass = ((IHasMass) tile).getMass();
            if (mass >= 0) {
                return mass;
            }
        }
        mass = getMass(block, meta);
        return mass >= 0 ? mass : getMass(block);
    }
    return -1;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IHasMass(com.builtbroken.mc.api.IHasMass) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Block(net.minecraft.block.Block) WorldServer(net.minecraft.world.WorldServer)

Example 67 with WorldServer

use of net.minecraft.world.WorldServer in project VanillaTeleporter by dyeo.

the class TeleporterUtility method transferPlayerToDimension.

/**
	 * Transfers a player to a different dimension and location, as if they were being teleported by a dimension portal
	 */
private static boolean transferPlayerToDimension(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension) {
    MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
    WorldServer srcWorld = minecraftServer.worldServerForDimension(player.dimension);
    WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);
    if (dstWorld != null) {
        // fire player change dimension event and check that action is valid before continuing
        if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimension))
            return false;
        // (hard) set the player's dimension to the destination dimension
        player.dimension = dimension;
        // send a player respawn packet to the destination dimension so the player respawns there
        player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
        // remove the original player entity
        srcWorld.removeEntity(player);
        // make sure the player isn't dead (removeEntity sets player as dead)
        player.isDead = false;
        PlayerList playerList = player.mcServer.getPlayerList();
        // set player's location (net server handler)
        setPlayerPosition(player, posX, posY, posZ, yaw, pitch);
        // spawn the player in the new world
        dstWorld.spawnEntity(player);
        // update the entity (do not force)
        dstWorld.updateEntityWithOptionalForce(player, false);
        // set the player's world to the new world
        player.setWorld(dstWorld);
        // add the player into the appropriate player list
        playerList.preparePlayer(player, srcWorld);
        // set item in world manager's world to the same as the player
        player.interactionManager.setWorld(dstWorld);
        // update time and weather for the player so that it's the same as the world
        playerList.updateTimeAndWeatherForPlayer(player, dstWorld);
        // sync the player's inventory
        playerList.syncPlayerInventory(player);
        // add no experience (syncs experience)
        player.addExperience(0);
        // update player's health
        player.setPlayerHealthUpdated();
        // fire the dimension changed event so that minecraft swithces dimensions properly
        FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, srcWorld.provider.getDimension(), dstWorld.provider.getDimension());
        return true;
    } else {
        return false;
    }
}
Also used : PlayerList(net.minecraft.server.management.PlayerList) WorldServer(net.minecraft.world.WorldServer) SPacketRespawn(net.minecraft.network.play.server.SPacketRespawn) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

WorldServer (net.minecraft.world.WorldServer)67 BlockPos (net.minecraft.util.math.BlockPos)24 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 IBlockState (net.minecraft.block.state.IBlockState)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 Entity (net.minecraft.entity.Entity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 World (net.minecraft.world.World)8 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)8 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)7 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)7 Nullable (javax.annotation.Nullable)6 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)5 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)5 StructureSpawnContext (ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)5 Collectors (java.util.stream.Collectors)5 Block (net.minecraft.block.Block)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 Chunk (net.minecraft.world.chunk.Chunk)4 ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)4