Exemplo n.º 1
0
  public static void initDimension(int dim) {
    WorldServer overworld = getWorld(0);
    if (overworld == null) {
      throw new RuntimeException("Cannot Hotload Dim: Overworld is not Loaded!");
    }
    try {
      DimensionManager.getProviderType(dim);
    } catch (Exception e) {
      System.err.println("Cannot Hotload Dim: " + e.getMessage());
      return; // If a provider hasn't been registered then we can't hotload the dim
    }
    MinecraftServer mcServer = overworld.getMinecraftServer();
    ISaveHandler savehandler = overworld.getSaveHandler();
    WorldSettings worldSettings = new WorldSettings(overworld.getWorldInfo());

    WorldServer world =
        (dim == 0
            ? overworld
            : new WorldServerMulti(
                mcServer,
                savehandler,
                overworld.getWorldInfo().getWorldName(),
                dim,
                worldSettings,
                overworld,
                mcServer.theProfiler));
    world.addWorldAccess(new WorldManager(mcServer, world));
    MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world));
    if (!mcServer.isSinglePlayer()) {
      world.getWorldInfo().setGameType(mcServer.getGameType());
    }

    mcServer.func_147139_a(mcServer.func_147135_j());
  }
  /** Retrieve a space station data entry, creating if necessary (with provided data) */
  public static SpaceStationWorldData getStationData(
      World world,
      int stationID,
      int homeID,
      int providerIdDynamic,
      int providerIdStatic,
      EntityPlayer player) {
    int providerType = DimensionManager.getProviderType(stationID);

    boolean foundMatch = false;

    // Loop through all registered satellites, checking for a provider ID match. If none is found,
    // this method is
    // being called on an incorrect
    for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
      if (satellite.getDimensionIdStatic() == providerType
          || satellite.getDimensionID() == providerType) {
        foundMatch = true;
        break;
      }
    }

    if (!foundMatch) {
      return null;
    } else {
      final String stationIdentifier = SpaceStationWorldData.getSpaceStationID(stationID);
      SpaceStationWorldData stationData =
          (SpaceStationWorldData)
              world.loadItemData(SpaceStationWorldData.class, stationIdentifier);

      if (stationData == null) {
        stationData = new SpaceStationWorldData(stationIdentifier);
        world.setItemData(stationIdentifier, stationData);
        stationData.dataCompound = new NBTTagCompound();

        if (player != null) {
          stationData.owner = player.getGameProfile().getName().replace(".", "");
        }

        stationData.spaceStationName = "Station: " + stationData.owner;

        if (player != null) {
          stationData.allowedPlayers.add(player.getGameProfile().getName());
        }

        if (homeID == -1) {
          throw new RuntimeException("Space station being created on bad home planet ID!");
        } else {
          stationData.homePlanet = homeID;
        }

        if (providerIdDynamic == -1 || providerIdStatic == -1) {
          throw new RuntimeException("Space station being created on bad provider IDs!");
        } else {
          stationData.dimensionIdDynamic = providerIdDynamic;
          stationData.dimensionIdStatic = providerIdStatic;
        }

        stationData.markDirty();
      }

      if (stationData.getSpaceStationName().replace(" ", "").isEmpty()) {
        stationData.setSpaceStationName("Station: " + stationData.owner);
        stationData.markDirty();
      }

      return stationData;
    }
  }
  private static Entity sendEntityToWorld(
      Entity entity, int newDimension, Vector3 newPos, Facing3 newLook) {
    MinecraftServer server = MinecraftServer.getServer();
    Entity currentEntity = entity;
    if (entity.dimension != newDimension) {
      if (entity instanceof EntityPlayerMP) {
        EntityPlayerMP player = (EntityPlayerMP) entity;
        ServerConfigurationManager scm = server.getConfigurationManager();
        int oldDimension = player.dimension;
        player.dimension = newDimension;
        WorldServer oldWorld = server.worldServerForDimension(oldDimension);
        WorldServer newWorld = server.worldServerForDimension(newDimension);

        DimensionRegisterMessage packet =
            new DimensionRegisterMessage(
                newDimension, DimensionManager.getProviderType(newDimension));
        LCRuntime.runtime.network().getPreferredPipe().sendForgeMessageTo(packet, player);

        player.closeScreen();
        player.playerNetServerHandler.sendPacket(
            new S07PacketRespawn(
                player.dimension,
                player.worldObj.difficultySetting,
                newWorld.getWorldInfo().getTerrainType(),
                player.theItemInWorldManager.getGameType()));
        oldWorld.removePlayerEntityDangerously(player);
        player.isDead = false;
        player.setLocationAndAngles(
            newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch);
        newWorld.spawnEntityInWorld(player);
        player.setWorld(newWorld);
        scm.func_72375_a(player, oldWorld);
        player.playerNetServerHandler.setPlayerLocation(
            newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch);
        player.theItemInWorldManager.setWorld(newWorld);
        scm.updateTimeAndWeatherForPlayer(player, newWorld);
        scm.syncPlayerInventory(player);
        Iterator<?> var6 = player.getActivePotionEffects().iterator();
        while (var6.hasNext())
          player.playerNetServerHandler.sendPacket(
              new S1DPacketEntityEffect(player.getEntityId(), (PotionEffect) var6.next()));
        player.playerNetServerHandler.sendPacket(
            new S1FPacketSetExperience(
                player.experience, player.experienceTotal, player.experienceLevel));
      } else {
        int oldDimension = entity.dimension;
        WorldServer oldWorld = server.worldServerForDimension(oldDimension);
        WorldServer newWorld = server.worldServerForDimension(newDimension);
        entity.dimension = newDimension;

        entity.worldObj.removeEntity(entity);
        entity.isDead = false;
        server
            .getConfigurationManager()
            .transferEntityToWorld(entity, oldDimension, oldWorld, newWorld);
        currentEntity = EntityList.createEntityByName(EntityList.getEntityString(entity), newWorld);

        if (currentEntity != null) {
          currentEntity.copyDataFrom(entity, true);
          currentEntity.setLocationAndAngles(
              newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch);
          newWorld.spawnEntityInWorld(currentEntity);
        }

        entity.isDead = true;
        oldWorld.resetUpdateEntityTick();
        newWorld.resetUpdateEntityTick();
      }
    } else {
      currentEntity.setLocationAndAngles(
          newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch);
      if (currentEntity instanceof EntityPlayerMP) {
        EntityPlayerMP mpEnt = (EntityPlayerMP) currentEntity;
        mpEnt.rotationYaw = (float) newLook.yaw;
        mpEnt.setPositionAndUpdate(newPos.x, newPos.y, newPos.z);
        mpEnt.worldObj.updateEntityWithOptionalForce(entity, false);
      }
    }
    return currentEntity;
  }